Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
enhance configuration handling (#5439)
Browse files Browse the repository at this point in the history
* enhance configuration handling

* enhance configuration handling

* enhance configuration handling

* add space
  • Loading branch information
cgagnaire authored and kduret committed Jul 12, 2017
1 parent 92cfb9c commit b261fb5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
11 changes: 6 additions & 5 deletions bin/centreon-partitioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,24 @@
}

/* Create partitioned tables */
$database = new CentreonDB('centstorage', 3, false);
$centreonDb = new CentreonDB('centreon');
$centstorageDb = new CentreonDB('centstorage', 3, false);
$partEngine = new PartEngine();

if (!$partEngine->isCompatible($database)) {
if (!$partEngine->isCompatible($centstorageDb)) {
exitProcess(PROCESS_ID, 1, "[".date(DATE_RFC822)."] CRITICAL: MySQL server is not compatible with partitioning. MySQL version must be greater or equal to 5.1\n");
}

echo "[" . date(DATE_RFC822) . "] PARTITIONING STARTED\n";

try {
$configFile = _CENTREON_PATH_ . '/config/partition.d/partitioning-' . $table . '.xml';
$config = new Config($database, $configFile);
$config = new Config($centstorageDb, $configFile, $centreonDb);
$mysqlTable = $config->getTable($table);
if ($partEngine->isPartitioned($mysqlTable, $database)) {
if ($partEngine->isPartitioned($mysqlTable, $centstorageDb)) {
throw new \Exception("Table " . $table . " is already partitioned\n");
}
$partEngine->migrate($mysqlTable, $database);
$partEngine->migrate($mysqlTable, $centstorageDb);
} catch (\Exception $e) {
echo "[" . date(DATE_RFC822) . "] " . $e->getMessage();
echo "[" . date(DATE_RFC822) . "] PARTITIONING EXITED\n";
Expand Down
11 changes: 6 additions & 5 deletions cron/centreon-partitioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
echo "[" . date(DATE_RFC822) . "] PARTITIONING STARTED\n";

/* Create partitioned tables */
$database = new CentreonDB('centstorage', 3, false);
$centreonDb = new CentreonDB('centreon');
$centstorageDb = new CentreonDB('centstorage', 3, false);
$partEngine = new PartEngine();

if (!$partEngine->isCompatible($database)) {
if (!$partEngine->isCompatible($centstorageDb)) {
exitProcess(PROCESS_ID, 1, "[".date(DATE_RFC822)."] CRITICAL: MySQL server is not compatible with partitionning. MySQL version must be greater or equal to 5.1\n");
}

Expand All @@ -60,10 +61,10 @@

try {
foreach ($tables as $table) {
$config = new Config($database, _CENTREON_PATH_ . '/config/partition.d/partitioning-' . $table . '.xml');
$config = new Config($centstorageDb, _CENTREON_PATH_ . '/config/partition.d/partitioning-' . $table . '.xml', $centreonDb);
$mysqlTable = $config->getTable($table);
if ($partEngine->isPartitioned($mysqlTable, $database)) {
$partEngine->updateParts($mysqlTable, $database);
if ($partEngine->isPartitioned($mysqlTable, $centstorageDb)) {
$partEngine->updateParts($mysqlTable, $centstorageDb);
}
}
} catch (\Exception $e) {
Expand Down
22 changes: 13 additions & 9 deletions www/class/centreon-partition/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ class Config
public $XMLfile;
private $defaultConfiguration;
public $tables;
public $db;
public $centstorageDb;
private $centreonDb;

/**
* Class constructor
*
* @param CentreonDB $db the centreon database
* @param string $file the xml file name
* @param CentreonDB $centstorageDb the centstorage database
* @param string $file the xml file name
* @param CentreonDB $centreonDb the centreon database
*/
public function __construct($db, $file)
public function __construct($centstorageDb, $file, $centreonDb)
{
$this->XMLFile = $file;
$this->db = $db;
$this->centstorageDb = $centstorageDb;
$this->centreonDb = $centreonDb;
$this->tables = array();
$this->loadCentreonDefaultConfiguration();
$this->parseXML($this->XMLFile);
}

Expand All @@ -72,10 +76,10 @@ public function loadCentreonDefaultConfiguration()
$queryOptions = 'SELECT `opt`.`key`, `opt`.`value` ' .
'FROM `options` opt ' .
'WHERE `opt`.`key` IN (' .
'`partitioning_backup_directory`, `partitioning_backup_format`, ' .
'`partitioning_retention`, `partitioning_retention_forward`' .
"'partitioning_backup_directory', 'partitioning_backup_format', " .
"'partitioning_retention', 'partitioning_retention_forward'" .
')';
$res = $this->db->query($queryOptions);
$res = $this->centreonDb->query($queryOptions);

if (\PEAR::isError($res)) {
throw new \Exception("Can't load default configuration for Centreon Partitioning");
Expand All @@ -101,7 +105,7 @@ public function parseXML($xmlfile)
$node = new SimpleXMLElement(file_get_contents($xmlfile));
foreach ($node->table as $table_config) {
$table = new MysqlTable(
$this->db,
$this->centstorageDb,
(string) $table_config["name"],
(string) dbcstg
);
Expand Down

0 comments on commit b261fb5

Please sign in to comment.