diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 8b8ad1a9570..289e04f4b69 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -1016,6 +1016,7 @@ label.outofbandmanagement.driver=Driver label.outofbandmanagement.disable=Disable Out-of-band Management label.outofbandmanagement.enable=Enable Out-of-band Management label.outofbandmanagement.password=Password +label.outofbandmanagement.reenterpassword=Re-enter Password label.outofbandmanagement.port=Port label.outofbandmanagement.username=Username message.outofbandmanagement.changepassword=Change Out-of-band Management password diff --git a/server/src/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java b/server/src/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java index bb099c89085..ca65ef7d192 100644 --- a/server/src/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java +++ b/server/src/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java @@ -31,7 +31,6 @@ import com.cloud.host.dao.HostDao; import com.cloud.org.Cluster; import com.cloud.utils.component.Manager; import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallback; import com.cloud.utils.db.TransactionStatus; @@ -87,7 +86,6 @@ public class OutOfBandManagementServiceImpl extends ManagerBase implements OutOf private final Map outOfBandManagementDriversMap = new HashMap(); private static final String OOBM_ENABLED_DETAIL = "outOfBandManagementEnabled"; - private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_HOST = 120; private static Cache hostAlertCache; private static ExecutorService backgroundSyncBlockingExecutor; @@ -435,59 +433,46 @@ public class OutOfBandManagementServiceImpl extends ManagerBase implements OutOf if (Strings.isNullOrEmpty(newPassword)) { throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as provided new-password is null or empty for the host %s.", host.getUuid())); } - GlobalLock outOfBandManagementHostLock = GlobalLock.getInternLock(getOutOfBandManagementHostLock(host.getId())); - try { - if (outOfBandManagementHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_HOST)) { - try { - final OutOfBandManagement outOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId()); - final ImmutableMap options = getOptions(outOfBandManagementConfig); - if (!(options.containsKey(OutOfBandManagement.Option.PASSWORD) && !Strings.isNullOrEmpty(options.get(OutOfBandManagement.Option.PASSWORD)))) { - throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as we've no previously configured password for the host %s.", host.getUuid())); - } - final OutOfBandManagementDriver driver = getDriver(outOfBandManagementConfig); - - final OutOfBandManagementDriverChangePasswordCommand cmd = new OutOfBandManagementDriverChangePasswordCommand(options, ActionTimeout.valueIn(host.getClusterId()), newPassword); - final OutOfBandManagementDriverResponse driverResponse; - try { - driverResponse = driver.execute(cmd); - } catch (Exception e) { - LOG.error("Out-of-band management change password failed due to driver error: " + e.getMessage()); - throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) due to driver error: %s", host.getUuid(), e.getMessage())); - } - - if (!driverResponse.isSuccess()) { - throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) with error: %s", host.getUuid(), driverResponse.getError())); - } - - final boolean updatedConfigResult = Transaction.execute(new TransactionCallback() { - @Override - public Boolean doInTransaction(TransactionStatus status) { - OutOfBandManagement updatedOutOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId()); - updatedOutOfBandManagementConfig.setPassword(newPassword); - return outOfBandManagementDao.update(updatedOutOfBandManagementConfig.getId(), (OutOfBandManagementVO) updatedOutOfBandManagementConfig); - } - }); - - if (!updatedConfigResult) { - LOG.error(String.format("Succeeded to change out-of-band management password but failed to updated in database the new password:%s for the host id:%d", newPassword, host.getId())); - } - - final OutOfBandManagementResponse response = new OutOfBandManagementResponse(); - response.setSuccess(updatedConfigResult && driverResponse.isSuccess()); - response.setResultDescription(driverResponse.getResult()); - response.setId(host.getUuid()); - return response; - } finally { - outOfBandManagementHostLock.unlock(); - } - } else { - LOG.error("Unable to acquire synchronization lock to change out-of-band management password for host id: " + host.getId()); - throw new CloudRuntimeException(String.format("Unable to acquire lock to change out-of-band management password for host (%s), please try after some time.", host.getUuid())); - } - } finally { - outOfBandManagementHostLock.releaseRef(); + final OutOfBandManagement outOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId()); + final ImmutableMap options = getOptions(outOfBandManagementConfig); + if (!(options.containsKey(OutOfBandManagement.Option.PASSWORD) && !Strings.isNullOrEmpty(options.get(OutOfBandManagement.Option.PASSWORD)))) { + throw new CloudRuntimeException(String.format("Cannot change out-of-band management password as we've no previously configured password for the host %s.", host.getUuid())); } + final OutOfBandManagementDriver driver = getDriver(outOfBandManagementConfig); + final OutOfBandManagementDriverChangePasswordCommand changePasswordCmd = new OutOfBandManagementDriverChangePasswordCommand(options, ActionTimeout.valueIn(host.getClusterId()), newPassword); + + final boolean changePasswordResult = Transaction.execute(new TransactionCallback() { + @Override + public Boolean doInTransaction(TransactionStatus status) { + final OutOfBandManagement updatedOutOfBandManagementConfig = outOfBandManagementDao.findByHost(host.getId()); + updatedOutOfBandManagementConfig.setPassword(newPassword); + boolean result = outOfBandManagementDao.update(updatedOutOfBandManagementConfig.getId(), (OutOfBandManagementVO) updatedOutOfBandManagementConfig); + + if (!result) { + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) in the database.", host.getUuid())); + } + + final OutOfBandManagementDriverResponse driverResponse; + try { + driverResponse = driver.execute(changePasswordCmd); + } catch (Exception e) { + LOG.error("Out-of-band management change password failed due to driver error: " + e.getMessage()); + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) due to driver error: %s", host.getUuid(), e.getMessage())); + } + + if (!driverResponse.isSuccess()) { + throw new CloudRuntimeException(String.format("Failed to change out-of-band management password for host (%s) with error: %s", host.getUuid(), driverResponse.getError())); + } + + return result && driverResponse.isSuccess(); + } + }); + + final OutOfBandManagementResponse response = new OutOfBandManagementResponse(); + response.setSuccess(changePasswordResult ); + response.setId(host.getUuid()); + return response; } @Override diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp index b0642997d2d..c15dae2ebdf 100644 --- a/ui/dictionary.jsp +++ b/ui/dictionary.jsp @@ -999,6 +999,7 @@ dictionary = { 'label.outofbandmanagement.disable': '', 'label.outofbandmanagement.enable': '', 'label.outofbandmanagement.password': '', +'label.outofbandmanagement.reenterpassword': '', 'label.outofbandmanagement.port': '', 'label.outofbandmanagement.timeout': '', 'label.outofbandmanagement.username': '', diff --git a/ui/scripts/system.js b/ui/scripts/system.js index 2eef6b1908d..7ffacd088f1 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -16814,10 +16814,21 @@ required: false }, }, + reenterpassword: { + label: 'label.outofbandmanagement.reenterpassword', + isPassword: true, + validation: { + required: false + } + }, } }, action: function (args) { var data = args.data; + if (data.password != data.reenterpassword) { + args.response.error("Passwords do not match"); + return; + } data.hostid = args.context.hosts[0].id; $.ajax({ url: createURL('changeOutOfBandManagementPassword'),