Shmuel Leib Melamud has uploaded a new change for review. Change subject: restapi: Remove VM pool if no VMs can be created ......................................................................
restapi: Remove VM pool if no VMs can be created If VM pool is created via REST API and one of VM parameters is incorrect, the VM Pool is created, but VM creation fails. In this case VM pool is also removed, because VM pool without VMs shouldn't exist. Change-Id: I36b137a905ea1364255af2bcdb11b27ed5198342 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1202129 Signed-off-by: Shmuel Melamud <smela...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolWithVmsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties 3 files changed, 18 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/39336/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolWithVmsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolWithVmsCommand.java index 642708a..1c1824a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolWithVmsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmPoolWithVmsCommand.java @@ -61,12 +61,17 @@ protected Guid getPoolId() { VmPool vmPool = getVmPool(); - getDbFacade().getVmPoolDao().save(vmPool); + getVmPoolDAO().save(vmPool); return vmPool.getVmPoolId(); } @Override + protected void onNoVmsAdded(Guid poolId) { + getVmPoolDAO().remove(poolId); + } + + @Override public AuditLogType getAuditLogTypeValue() { if (isAddVmsSucceded()) { return AuditLogType.USER_ADD_VM_POOL_WITH_VMS; diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java index 9b47802..50a254f 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java @@ -63,6 +63,7 @@ private Map<Guid, List<DiskImage>> storageToDisksMap; private Map<Guid, StorageDomain> destStorages = new HashMap<>(); private boolean addVmsSucceeded = true; + private boolean vmsAdded = false; private NameForVmInPoolGenerator nameForVmInPoolGenerator; /** @@ -137,6 +138,8 @@ getReturnValue().setCanDoAction(isAddVmsSucceded()); setSucceeded(isAddVmsSucceded()); VmTemplateHandler.unlockVmTemplate(getParameters().getVmStaticData().getVmtGuid()); + if (!isVmsAdded()) + onNoVmsAdded(poolId); getCompensationContext().resetCompensation(); } @@ -162,6 +165,7 @@ } else { // Succeed on that , reset subsequentFailedAttempts. subsequentFailedAttempts = 0; + vmsAdded = true; } // if subsequent attempts failure exceeds configuration value , abort the loop. if (subsequentFailedAttempts == vmPoolMaxSubsequentFailures) { @@ -170,6 +174,9 @@ break; } } + } + + protected void onNoVmsAdded(Guid poolId) { } private String generateUniqueVmName() { @@ -422,6 +429,10 @@ return addVmsSucceeded; } + public boolean isVmsAdded() { + return vmsAdded; + } + protected boolean setAndValidateDiskProfiles() { if (diskInfoDestinationMap != null && !diskInfoDestinationMap.isEmpty()) { Map<DiskImage, Guid> map = new HashMap<>(); diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index 230c342..7613765 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -17,7 +17,7 @@ USER_ADD_VM_POOL=VM Pool ${VmPoolName} was created by ${UserName}. USER_ADD_VM_POOL_FAILED=Failed to create VM Pool ${VmPoolName} (User: ${UserName}). USER_ADD_VM_POOL_WITH_VMS=VM Pool ${VmPoolName} (containing ${VmsCount} VMs) was created by ${UserName}. -USER_ADD_VM_POOL_WITH_VMS_FAILED=Failed to create VM Pool ${VmPoolName}(User: ${UserName}). +USER_ADD_VM_POOL_WITH_VMS_FAILED=Failed to create VM Pool ${VmPoolName} (User: ${UserName}). USER_ADD_VM_POOL_WITH_VMS_ADD_VDS_FAILED=Pool ${VmPoolName} Created, but some Vms failed to create (User: ${UserName}). USER_ADD_VM_TEMPLATE=Creation of Template ${VmTemplateName} from VM ${VmName} was initiated by ${UserName}. USER_ADD_VM_TEMPLATE_FINISHED_SUCCESS=Creation of Template ${VmTemplateName} from VM ${VmName} has been completed. -- To view, visit https://gerrit.ovirt.org/39336 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I36b137a905ea1364255af2bcdb11b27ed5198342 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shmuel Leib Melamud <smela...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches