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

enh(core): better manage exceptions and upgrade failure #8234

Merged
merged 20 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lang/es_ES.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -3231,14 +3231,19 @@ msgid "You seem to be having trouble with your upgrade."
msgstr "Parece que hay un problema con tu actualización."

#: centreon-web/www/install/step_upgrade/step4.php:70
msgid "You may refer to the line that causes problem in order to find out more about the issue."
msgid "You may refer to the line in the specified file in order to correct the issue."
msgstr "Puede consultar la línea que es problemática para obtener más información sobre el incidente."

#: centreon-web/www/install/step_upgrade/step4.php:71
#, php-format
msgid "The SQL files are located in %s"
msgstr "Los archivos SQL se encuentran en %s"

#: centreon-web/www/install/step_upgrade/step4.php:87
#, php-format
msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details"
msgstr ""

#: centreon-web/www/install/step_upgrade/step4.php:72
msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed."
msgstr ""
Expand Down
7 changes: 6 additions & 1 deletion lang/pt_BR.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11996,14 +11996,19 @@ msgid "You seem to be having trouble with your upgrade."
msgstr "Parece que você esta tendo problemas com sua atualização."

#: centreon-web/www/install/step_upgrade/step4.php:70
msgid "You may refer to the line that causes problem in order to find out more about the issue."
msgid "You may refer to the line in the specified file in order to correct the issue."
msgstr "Você deve verificar a linha que esta causando o problema para poder-mos encontrar uma resolução para este caso."

#: centreon-web/www/install/step_upgrade/step4.php:71
#, php-format
msgid "The SQL files are located in %s"
msgstr "Os arquivos SQL estão localizados em %s"

#: centreon-web/www/install/step_upgrade/step4.php:87
#, php-format
msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details"
msgstr ""

#: centreon-web/www/install/step_upgrade/step4.php:72
msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed."
msgstr ""
Expand Down
7 changes: 6 additions & 1 deletion lang/pt_PT.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11997,14 +11997,19 @@ msgid "You seem to be having trouble with your upgrade."
msgstr "Parece que você esta tendo problemas com sua atualização."

#: centreon-web/www/install/step_upgrade/step4.php:70
msgid "You may refer to the line that causes problem in order to find out more about the issue."
msgid "You may refer to the line in the specified file in order to correct the issue."
msgstr "Você deve verificar a linha que esta causando o problema para poder-mos encontrar uma resolução para este caso."

#: centreon-web/www/install/step_upgrade/step4.php:71
#, php-format
msgid "The SQL files are located in %s"
msgstr "Os ficheiros SQL estão localizados em %s"

#: centreon-web/www/install/step_upgrade/step4.php:87
#, php-format
msgid "Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details"
msgstr ""

#: centreon-web/www/install/step_upgrade/step4.php:72
msgid "But do not edit the SQL files unless you know what you are doing.Refresh this page when the problem is fixed."
msgstr ""
Expand Down
2 changes: 2 additions & 0 deletions www/class/centreonLog.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __construct($uid, $pearDB)
$this->errorType[1] = $this->path . "/login.log";
$this->errorType[2] = $this->path . "/sql-error.log";
$this->errorType[3] = $this->path . "/ldap.log";
$this->errorType[4] = $this->path . "/upgrade.log";
}

/*
Expand Down Expand Up @@ -146,6 +147,7 @@ public function __construct($customLogs = array())
$this->errorType[1] = $this->path . "/login.log";
$this->errorType[2] = $this->path . "/sql-error.log";
$this->errorType[3] = $this->path . "/ldap.log";
$this->errorType[4] = $this->path . "/upgrade.log";

foreach ($customLogs as $key => $value) {
if (!preg_match('@' . $this->path . '@', $value)) {
Expand Down
113 changes: 76 additions & 37 deletions www/install/php/Update-20.04.0-beta.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@
include_once __DIR__ . "/../../class/centreonLog.class.php";
$centreonLog = new CentreonLog();

try {
$pearDB->query(
"UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` =''"
);
} catch (\PDOException $e) {
$centreonLog->insertLog(
2,
"UPGRADE : 19.10.2 Unable to set default contact_autologin_key"
);
}
//error specific content
$versionOfTheUpgrade = 'UPGRADE - 20.04.0-beta.1 : ';
sc979 marked this conversation as resolved.
Show resolved Hide resolved
$errorMessage = '';


// Move broker xml files to json format
/**
* Queries needing exception management and rollback if failing
*/
try {
$pearDB->beginTransaction();
/*
* Move broker xml files to json format
*/
$errorMessage = "Unable to replace broker configuration from xml format to json format";
$result = $pearDB->query(
"SELECT config_id, config_filename
FROM cfg_centreonbroker"
Expand All @@ -48,21 +47,20 @@
$configFilenames = [];
while ($row = $result->fetch()) {
$fileName = str_replace('.xml', '.json', $row['config_filename']);

// saving data for next engine module modifications
$configFilenames[$row['config_filename']] = $fileName;

$statement->bindValue(':value', $fileName, \PDO::PARAM_STR);
$statement->bindValue(':id', $row['config_id'], \PDO::PARAM_INT);

$statement->execute();
}
} catch (\PDOException $e) {
$centreonLog->insertLog(
2,
"UPGRADE : 20.04.0-beta.1 Unable to move broker configuration from xml format to json format"
);
throw new \PDOException($e);
}

// Move engine module xml files to json format
try {
/*
* Move engine module xml files to json format
*/
$errorMessage = "Unable to replace engine's broker modules configuration from xml to json format";
$result = $pearDB->query(
"SELECT bk_mod_id, broker_module
FROM cfg_nagios_broker_module"
Expand All @@ -80,47 +78,88 @@
}
$statement->bindValue(':value', $fileName, \PDO::PARAM_STR);
$statement->bindValue(':id', $row['bk_mod_id'], \PDO::PARAM_INT);

$statement->execute();
}
} catch (\PDOException $e) {
$centreonLog->insertLog(
2,
"UPGRADE : 20.04.0-beta.1 Unable to move engine's broker modules configuration from xml to json format"
);
throw new \PDOException($e);
}


// Change broker sql output form
/*
* Change broker sql output form
*/
// set common error message on failure
$partialErrorMessage = $errorMessage;

try {
// reorganise existing input form
$errorMessage = $partialErrorMessage . " - While trying to update 'cb_type_field_relation' table data";
$pearDB->query(
"UPDATE cb_type_field_relation AS A INNER JOIN cb_type_field_relation AS B ON A.cb_type_id = B.cb_type_id
SET A.`order_display` = 8
WHERE B.`cb_field_id` = (SELECT f.cb_field_id FROM cb_field f WHERE f.fieldname = 'buffering_timeout')"
);

// add new connections_count input
$errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_field' table new values";
$pearDB->query(
"INSERT INTO `cb_field` (`fieldname`, `displayname`, `description`, `fieldtype`, `external`)
VALUES ('connections_count', 'Number of connection to the database', 'Usually cpus/2', 'int', NULL)"
);

// add relation
$errorMessage = $partialErrorMessage . " - While trying to insert in 'cb_type_field_relation' table new values";
$pearDB->query(
"INSERT INTO `cb_type_field_relation` (`cb_type_id`, `cb_field_id`, `is_required`, `order_display`, `jshook_name`, `jshook_arguments`)
"INSERT INTO `cb_type_field_relation` (
`cb_type_id`,
`cb_field_id`,
`is_required`,
`order_display`,
`jshook_name`,
`jshook_arguments`
)
VALUES (
(SELECT `cb_type_id` FROM `cb_type` WHERE `type_shortname` = 'sql'),
(SELECT `cb_field_id` FROM `cb_field` WHERE `fieldname` = 'connections_count'),
0, 7, 'countConnections', '{\"target\": \"connections_count\"}'
0,
7,
'countConnections',
'{\"target\": \"connections_count\"}'
)"
);

} catch (\PDOException $e) {
$pearDB->commit();
$errorMessage = "";
} catch (\Exception $e) {
$pearDB->rollBack();
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
" - Code : " . (int)$e->getCode() .
" - Error : " . $e->getMessage() .
" - Trace : " . $e->getTraceAsString()
);
throw new \Exception($versionOfTheUpgrade . $errorMessage, (int)$e->getCode(), $e);
}

/**
* Queries which don't need rollback and won't throw an exception
*/
try {
/*
* replace autologin keys using NULL instead of empty string
*/
$pearDB->query("UPDATE `contact` SET `contact_autologin_key` = NULL WHERE `contact_autologin_key` = ''");
} catch (\Exception $e) {
$errorMessage = "Unable to set default contact_autologin_key.";
$centreonLog->insertLog(
4,
$versionOfTheUpgrade . $errorMessage .
" - Code : " . (int)$e->getCode() .
" - Error : " . $e->getMessage() .
" - Trace : " . $e->getTraceAsString()
);
}

if (empty($errorMessage)) {
$centreonLog->insertLog(
2,
"UPGRADE : 20.04.0-beta.1 Unable to change sql broker form"
4,
$versionOfTheUpgrade . " - Successful Update"
);
throw new \PDOException($e);
}
11 changes: 8 additions & 3 deletions www/install/step_upgrade/step4.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@
</table>";

$troubleshootTxt1 = _('You seem to be having trouble with your upgrade.');
$troubleshootTxt2 = _('You may refer to the line that causes problem in order to find out more about the issue.');
$troubleshootTxt3 = sprintf(_('The SQL files are located in %s'), _CENTREON_PATH_ . 'www/install/sql/');
$troubleshootTxt1bis = sprintf(
_("Please check the \"upgrade.log\" and the \"sql-error.log\" located in \"%s\" for more details"),
_CENTREON_LOG_
);
$troubleshootTxt2 = _('You may refer to the line in the specified file in order to correct the issue.');
$troubleshootTxt3 = sprintf(_('The SQL files are located in "%s"'), _CENTREON_PATH_ . 'www/install/sql/');
$troubleshootTxt4 = _('But do not edit the SQL files unless you know what you are doing.'
. 'Refresh this page when the problem is fixed.');
$contents .= sprintf(
'<br/><p id="troubleshoot" style="display:none;">%s<br/>%s<br/>%s<br/>%s</p>',
'<br/><p id="troubleshoot" style="display:none;">%s<br/><br/>%s<br/>%s<br/><br/>%s<br/>%s</p>',
$troubleshootTxt1,
$troubleshootTxt1bis,
$troubleshootTxt2,
$troubleshootTxt3,
$troubleshootTxt4
Expand Down