diff options
author | Yoshie Muranaka <yoshiemuranaka@gmail.com> | 2019-06-21 09:19:32 -0500 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2019-06-26 18:04:43 +0000 |
commit | afcfda7b93704b41c0da3b0634e96f12fd9f91aa (patch) | |
tree | d68c84db66331a390d098c3fafdef70e65e81ba8 /app | |
parent | c86ce3c9c7736ef199d885596b6fc745c7d8c86e (diff) | |
download | phosphor-webui-afcfda7b93704b41c0da3b0634e96f12fd9f91aa.tar.gz phosphor-webui-afcfda7b93704b41c0da3b0634e96f12fd9f91aa.zip |
Fix cold reboot error
Cold reboot will check the host status by referring to the
server_state property in the dataService instead of making
API requests to check host/chassis status.
TODO: Refactor other power control options to follow a
similar pattern.
Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I74b1b78fa39caee514fbaea8492c8a5ad6f8145b
Diffstat (limited to 'app')
-rw-r--r-- | app/common/services/constants.js | 11 | ||||
-rw-r--r-- | app/server-control/controllers/power-operations-controller.js | 58 |
2 files changed, 48 insertions, 21 deletions
diff --git a/app/common/services/constants.js b/app/common/services/constants.js index e1839f5..dd1012c 100644 --- a/app/common/services/constants.js +++ b/app/common/services/constants.js @@ -91,11 +91,12 @@ window.angular && (function(angular) { POWER_OP: 5000, }, TIMEOUT: { - ACTIVATION: 1000 * 60 * 10, // 10 mins - DOWNLOAD_IMAGE: 1000 * 60 * 2, // 2 mins - CHASSIS_OFF: 1000 * 60 * 5, // 5 mins - HOST_ON: 1000 * 60 * 5, // 5 mins - HOST_OFF: 1000 * 60 * 5, // 5 mins + ACTIVATION: 1000 * 60 * 10, // 10 mins + DOWNLOAD_IMAGE: 1000 * 60 * 2, // 2 mins + CHASSIS_OFF: 1000 * 60 * 5, // 5 mins + HOST_ON: 1000 * 60 * 5, // 5 mins + HOST_OFF: 1000 * 60 * 5, // 5 mins + HOST_OFF_IMMEDIATE: 1000 * 60 * 2 // 2 mins }, MESSAGES: { POLL: { diff --git a/app/server-control/controllers/power-operations-controller.js b/app/server-control/controllers/power-operations-controller.js index 2030b4d..9713d21 100644 --- a/app/server-control/controllers/power-operations-controller.js +++ b/app/server-control/controllers/power-operations-controller.js @@ -28,6 +28,33 @@ window.angular && (function(angular) { var pollChassisStatusTimer = undefined; var pollStartTime = null; + /** + * Checks the host status provided by the dataService using an + * interval timer + * @param {string} statusType : host status type to check for + * @param {number} timeout : timeout limit + * @param {string} error : error message + * @returns {Promise} : returns a deferred promise that will be fulfilled + * if the status is met or be rejected if the timeout is reached + */ + var checkHostStatus = (statusType, timeout, error = 'Time out.') => { + const deferred = $q.defer(); + const start = new Date(); + const checkHostStatusInverval = $interval(() => { + let now = new Date(); + let timePassed = now.getTime() - start.getTime(); + if (timePassed > timeout) { + deferred.reject(error); + $interval.cancel(checkHostStatusInverval); + } + if (dataService.server_state === statusType) { + deferred.resolve(); + $interval.cancel(checkHostStatusInverval); + } + }, Constants.POLL_INTERVALS.POWER_OP); + return deferred.promise; + }; + APIUtils.getLastPowerTime() .then( function(data) { @@ -129,29 +156,28 @@ window.angular && (function(angular) { $scope.loading = true; dataService.setUnreachableState(); APIUtils.chassisPowerOff() - .then(function(state) { - return state; - }) - .then(function(lastState) { - pollStartTime = new Date(); - return pollChassisStatusTillOff(); + .then(function() { + return checkHostStatus( + Constants.HOST_STATE_TEXT.off, + Constants.TIMEOUT.HOST_OFF_IMMEDIATE, + Constants.MESSAGES.POLL.HOST_OFF_TIMEOUT); }) - .then(function(chassisState) { - return APIUtils.hostPowerOn().then(function(hostState) { - return hostState; - }); + .then(function() { + return APIUtils.hostPowerOn(); }) - .then(function(hostState) { - return APIUtils.pollHostStatusTillOn(); - }) - .then(function(state) { - $scope.loading = false; + .then(function() { + return checkHostStatus( + Constants.HOST_STATE_TEXT.on, Constants.TIMEOUT.HOST_ON, + Constants.MESSAGES.POLL.HOST_ON_TIMEOUT); }) .catch(function(error) { + console.log(error); toastService.error( Constants.MESSAGES.POWER_OP.COLD_REBOOT_FAILED); + }) + .finally(function() { $scope.loading = false; - }); + }) }; $scope.coldRebootConfirm = function() { if ($scope.confirm) { |