diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index 83261b999e3..ab68b614142 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -3987,6 +3987,11 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe // get all the hosts in this cluster final List hosts = _resourceMgr.listAllHostsInCluster(command.getClusterId()); + String userNameWithoutSpaces = StringUtils.deleteWhitespace(command.getUsername()); + if (StringUtils.isBlank(userNameWithoutSpaces)) { + throw new InvalidParameterValueException("Username should be non empty string"); + } + Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { @@ -3996,7 +4001,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } // update password for this host final DetailVO nv = _detailsDao.findDetail(h.getId(), ApiConstants.USERNAME); - if (nv.getValue().equals(command.getUsername())) { + if (nv == null) { + final DetailVO nvu = new DetailVO(h.getId(), ApiConstants.USERNAME, userNameWithoutSpaces); + _detailsDao.persist(nvu); + final DetailVO nvp = new DetailVO(h.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(command.getPassword())); + _detailsDao.persist(nvp); + } else if (nv.getValue().equals(userNameWithoutSpaces)) { final DetailVO nvp = _detailsDao.findDetail(h.getId(), ApiConstants.PASSWORD); nvp.setValue(DBEncryptionUtil.encrypt(command.getPassword())); _detailsDao.persist(nvp); @@ -4044,6 +4054,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe if (!supportedHypervisors.contains(host.getHypervisorType())) { throw new InvalidParameterValueException("This operation is not supported for this hypervisor type"); } + + String userNameWithoutSpaces = StringUtils.deleteWhitespace(cmd.getUsername()); + if (StringUtils.isBlank(userNameWithoutSpaces)) { + throw new InvalidParameterValueException("Username should be non empty string"); + } + Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { @@ -4052,7 +4068,12 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } // update password for this host final DetailVO nv = _detailsDao.findDetail(host.getId(), ApiConstants.USERNAME); - if (nv.getValue().equals(cmd.getUsername())) { + if (nv == null) { + final DetailVO nvu = new DetailVO(host.getId(), ApiConstants.USERNAME, userNameWithoutSpaces); + _detailsDao.persist(nvu); + final DetailVO nvp = new DetailVO(host.getId(), ApiConstants.PASSWORD, DBEncryptionUtil.encrypt(cmd.getPassword())); + _detailsDao.persist(nvp); + } else if (nv.getValue().equals(userNameWithoutSpaces)) { final DetailVO nvp = _detailsDao.findDetail(host.getId(), ApiConstants.PASSWORD); nvp.setValue(DBEncryptionUtil.encrypt(cmd.getPassword())); _detailsDao.persist(nvp); diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 1eb72e2a24c..f46367835ee 100755 --- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -465,7 +465,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement } SnapshotInfo snapshotInfo = this.snapshotFactory.getSnapshot(snapshotId, store); snapshotInfo = (SnapshotInfo)store.create(snapshotInfo); - SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId(), store.getRole()); + SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshot.getId()); snapshotOnPrimaryStore.setState(ObjectInDataStoreStateMachine.State.Ready); snapshotOnPrimaryStore.setInstallPath(vmSnapshot.getName()); _snapshotStoreDao.update(snapshotOnPrimaryStore.getId(), snapshotOnPrimaryStore); diff --git a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java index 2eeb617622c..c9bb44af696 100755 --- a/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java +++ b/server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerTest.java @@ -316,7 +316,7 @@ public class SnapshotManagerTest { when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(null); when(snapshotFactory.getSnapshot(nullable(Long.class), nullable(DataStore.class))).thenReturn(snapshotInfoMock); when(storeMock.create(snapshotInfoMock)).thenReturn(snapshotInfoMock); - when(snapshotStoreDao.findBySnapshot(nullable(Long.class), nullable(DataStoreRole.class))).thenReturn(snapshotStoreMock); + when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock); when(snapshotStoreDao.update(nullable(Long.class), nullable(SnapshotDataStoreVO.class))).thenReturn(true); when(_snapshotDao.update(nullable(Long.class), nullable(SnapshotVO.class))).thenReturn(true); when(vmMock.getAccountId()).thenReturn(2L); @@ -333,7 +333,7 @@ public class SnapshotManagerTest { when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); when(_vmSnapshotDao.findById(nullable(Long.class))).thenReturn(vmSnapshotMock); when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock); - when(snapshotStoreDao.findBySnapshot(nullable(Long.class), nullable(DataStoreRole.class))).thenReturn(snapshotStoreMock); + when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock); when(snapshotStoreMock.getInstallPath()).thenReturn("VM_SNAPSHOT_NAME"); when(vmSnapshotMock.getName()).thenReturn("VM_SNAPSHOT_NAME"); Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);