Michael Kublin has uploaded a new change for review. Change subject: engine: Remove IsValidVDSCommand (Preporation for removing global lock on SPM ops) ......................................................................
engine: Remove IsValidVDSCommand (Preporation for removing global lock on SPM ops) The following patch will remove IsValidVDSCommand. The following command was used in order to check if pool is up and we have spm. First of all the using of command at canDoaction is wrong, a simple check for status of pool or status of domain should be enought. But the most exciting part is that the following command can trigger SPM election and it is done with out any synchronization, so we can easilly have couple spm elections simenteniously. The code at IsValidVDSCommand was getCurrentIrsProxyData().getIsValid(), which is actually code at IrsProxyData: getIrsProxy() != null, where getIrsProxy() is elect SPM if we have not one. Change-Id: I73c0fa0fd66f2f14132594a0b0450a7ecd7cf166 Signed-off-by: Michael Kublin <mkub...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/IsoDomainListSyncronizer.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageDomainCommand.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java D backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IsValidVDSCommand.java 14 files changed, 73 insertions(+), 159 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/9097/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java index 04c3692..3ad10ba 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java @@ -454,7 +454,7 @@ boolean checkTemplateLock = getParameters().getParentCommand() == VdcActionType.AddVmPoolWithVms ? false : true; - returnValue = verifyAddVM(reasons, storagePoolId, vmPriority); + returnValue = verifyAddVM(reasons, vmPriority); if (returnValue && !getParameters().getDontCheckTemplateImages()) { for (storage_domains storage : destStorages.values()) { @@ -468,11 +468,9 @@ return returnValue; } - protected boolean verifyAddVM(List<String> reasons, Guid storagePoolId, int vmPriority) { + protected boolean verifyAddVM(List<String> reasons, int vmPriority) { return VmHandler.VerifyAddVm(reasons, getVmInterfaces().size(), - getVmTemplate(), - storagePoolId, vmPriority); } 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 be834c2..078cd5d 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 @@ -22,6 +22,7 @@ import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.StorageDomainType; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VmOsType; import org.ovirt.engine.core.common.businessentities.VmStatic; @@ -33,8 +34,6 @@ import org.ovirt.engine.core.common.job.StepEnum; import org.ovirt.engine.core.common.queries.IsVmWithSameNameExistParameters; import org.ovirt.engine.core.common.queries.VdcQueryType; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.VdcBllMessages; @@ -182,10 +181,6 @@ @Override protected boolean canDoAction() { - if (!super.canDoAction()) { - return false; - } - VDSGroup grp = getVdsGroupDAO().get(getParameters().getVmPool().getvds_group_id()); if (grp == null) { addCanDoActionMessage(VdcBllMessages.VDS_CLUSTER_IS_NOT_VALID); @@ -203,18 +198,15 @@ addCanDoActionMessage(VdcBllMessages.VM_POOL_CANNOT_CREATE_DUPLICATE_NAME); return false; } - - if (!((Boolean) runVdsCommand(VDSCommandType.IsValid, - new IrsBaseVDSCommandParameters(grp.getstorage_pool_id().getValue())).getReturnValue()) - .booleanValue()) { - addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND); - return false; - } - - if (!verifyAddVM(grp.getstorage_pool_id().getValue())) { - return false; - } setStoragePoolId(grp.getstorage_pool_id().getValue()); + + if (getStoragePool() == null || getStoragePool().getstatus() != StoragePoolStatus.Up) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND); + } + + if (!verifyAddVM()) { + return false; + } if (!ensureDestinationImageMap()) { return false; @@ -257,13 +249,11 @@ version.toString()); } - protected boolean verifyAddVM(Guid storagePoolId) { + protected boolean verifyAddVM() { return VmHandler.VerifyAddVm (getReturnValue().getCanDoActionMessages(), getParameters().getVmsCount() * getVmNetworkInterfaceDAO().getAllForTemplate(getVmTemplateId()).size(), - getVmTemplate(), - storagePoolId, getParameters().getVmStaticData().getpriority()); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java index fd5f4bc..95f028d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImagesHandler.java @@ -24,6 +24,7 @@ import org.ovirt.engine.core.common.businessentities.LUNs; import org.ovirt.engine.core.common.businessentities.LunDisk; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.StorageType; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; @@ -34,6 +35,7 @@ import org.ovirt.engine.core.common.businessentities.image_storage_domain_map; import org.ovirt.engine.core.common.businessentities.storage_domain_static; import org.ovirt.engine.core.common.businessentities.storage_domains; +import org.ovirt.engine.core.common.businessentities.storage_pool; import org.ovirt.engine.core.common.businessentities.storage_server_connections; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; @@ -449,14 +451,14 @@ boolean checkStorageDomain, boolean checkIsValid, Collection diskImageList) { - boolean returnValue = true; - boolean isValid = checkIsValid - && ((Boolean) Backend.getInstance().getResourceManager() - .RunVdsCommand(VDSCommandType.IsValid, new IrsBaseVDSCommandParameters(storagePoolId)) - .getReturnValue()).booleanValue(); - if (checkIsValid && !isValid) { - returnValue = false; - ListUtils.nullSafeAdd(messages, VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND.toString()); + boolean returnValue = true;; + if (checkIsValid) { + storage_pool pool = DbFacade.getInstance().getStoragePoolDao().get( + storagePoolId); + if (pool == null || pool.getstatus() != StoragePoolStatus.Up) { + returnValue = false; + ListUtils.nullSafeAdd(messages, VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND.toString()); + } } List<DiskImage> images = getImages(vm, diskImageList); @@ -471,7 +473,7 @@ returnValue = false; ListUtils.nullSafeAdd(messages, VdcBllMessages.ACTION_TYPE_FAILED_VM_IN_PREVIEW.toString()); } - if (returnValue && isValid) { + if (returnValue && checkIsValid) { if (images.size() > 0) { returnValue = returnValue && checkDiskImages(messages, diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/IsoDomainListSyncronizer.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/IsoDomainListSyncronizer.java index dde438f..9138b5f 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/IsoDomainListSyncronizer.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/IsoDomainListSyncronizer.java @@ -237,27 +237,15 @@ Guid storagePoolId, FileTypeExtension fileTypeExt) { boolean refreshSucceeded = false; - - // Check validation of storage pool and SPM. - Boolean isValid = (Boolean) (Backend - .getInstance() - .getResourceManager() - .RunVdsCommand(VDSCommandType.IsValid, - new IrsBaseVDSCommandParameters(storagePoolId)).getReturnValue()); - - log.debugFormat("Validation of Storage pool id {0} returned {1}.", storagePoolId, isValid ? "valid" - : "not valid"); // Setting the indication to the indication whether the storage pool is valid. - boolean updateFromVDSMSucceeded = isValid; + boolean updateFromVDSMSucceeded = true; // If the SPM and the storage pool are valid, try to refresh the Iso list by fetching it from the SPM. - if (isValid) { - if (fileTypeExt == FileTypeExtension.ISO) { - updateFromVDSMSucceeded = updateIsoListFromVDSM(storagePoolId, storageDomainId); - } else if (fileTypeExt == FileTypeExtension.Floppy) { - updateFromVDSMSucceeded = - updateFloppyListFromVDSM(storagePoolId, storageDomainId) && updateFromVDSMSucceeded; - } + if (fileTypeExt == FileTypeExtension.ISO) { + updateFromVDSMSucceeded = updateIsoListFromVDSM(storagePoolId, storageDomainId); + } else if (fileTypeExt == FileTypeExtension.Floppy) { + updateFromVDSMSucceeded = + updateFloppyListFromVDSM(storagePoolId, storageDomainId) && updateFromVDSMSucceeded; } // Log if the refresh succeeded or add the storage domain to the problematic list. diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java index 9d2c021..bbaa3a8 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java @@ -17,12 +17,11 @@ import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.action.VmTemplateParametersBase; import org.ovirt.engine.core.common.businessentities.DiskImage; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.common.businessentities.storage_domain_static; import org.ovirt.engine.core.common.locks.LockingGroup; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; @@ -75,13 +74,7 @@ } // check storage pool valid - if (template.getstorage_pool_id() != null && !Guid.Empty.equals(template.getstorage_pool_id()) - && !((Boolean) Backend - .getInstance() - .getResourceManager() - .RunVdsCommand(VDSCommandType.IsValid, - new IrsBaseVDSCommandParameters(template.getstorage_pool_id().getValue())) - .getReturnValue()).booleanValue()) { + if (getStoragePool() == null || getStoragePool().getstatus() != StoragePoolStatus.Up) { addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND); return false; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java index 94867dc..26225ff 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java @@ -31,8 +31,6 @@ import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.common.validation.group.UpdateEntity; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.DateTime; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.VdcBllMessages; @@ -79,14 +77,15 @@ getVmStaticDAO().update(newVmStatic); updateVmPayload(); VmDeviceUtils.updateVmDevices(getParameters(), oldVm); - if (((Boolean) runVdsCommand(VDSCommandType.IsValid, - new IrsBaseVDSCommandParameters(getVm().getstorage_pool_id())).getReturnValue())) { - // Set the VM to null, to fetch it again from the DB ,instead from the cache. - // We want to get the VM current data that was updated to the DB. - setVm(null); + // Set the VM to null, to fetch it again from the DB ,instead from the cache. + // We want to get the VM current data that was updated to the DB. + setVm(null); + try { updateVmInSpm(getVm().getstorage_pool_id(), - new ArrayList<VM>(Arrays.asList(new VM[] { getVm() }))); + Arrays.asList(getVm())); + } catch (Exception e) { + // DO nothing } setSucceeded(true); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java index ac4edaf..1cd346a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java @@ -21,13 +21,11 @@ import org.ovirt.engine.core.common.businessentities.VmNetworkInterface; import org.ovirt.engine.core.common.businessentities.VmOsType; import org.ovirt.engine.core.common.businessentities.VmStatic; -import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.utils.VmValidationUtils; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.Guid; @@ -100,14 +98,10 @@ * The reasons. * @param nicsCount * How many vNICs need to be allocated. - * @param vmTemplate - * The vm template id. * @return */ public static boolean VerifyAddVm(List<String> reasons, int nicsCount, - VmTemplate vmTemplate, - Guid storagePoolId, int vmPriority) { boolean returnValue = true; if (MacPoolManager.getInstance().getavailableMacsCount() < nicsCount) { @@ -115,20 +109,8 @@ reasons.add(VdcBllMessages.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES.toString()); } returnValue = false; - } else { - boolean isValid = ((Boolean) Backend.getInstance().getResourceManager() - .RunVdsCommand(VDSCommandType.IsValid, new IrsBaseVDSCommandParameters(storagePoolId)) - .getReturnValue()).booleanValue(); - if (isValid) { - if (!VmTemplateCommand.IsVmPriorityValueLegal(vmPriority, reasons)) { - returnValue = false; - } - } else { - if (reasons != null) { - reasons.add(VdcBllMessages.IMAGE_REPOSITORY_NOT_FOUND.toString()); - } - returnValue = false; - } + } else if (!VmTemplateCommand.IsVmPriorityValueLegal(vmPriority, reasons)) { + returnValue = false; } return returnValue; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageDomainCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageDomainCommand.java index fb8ff7b..7e223d2 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageDomainCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateStorageDomainCommand.java @@ -7,9 +7,9 @@ import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.StorageDomainManagementParameter; import org.ovirt.engine.core.common.businessentities.StorageDomainStatus; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.storage_domain_static; import org.ovirt.engine.core.common.validation.group.UpdateEntity; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.SetStorageDomainDescriptionVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.dal.VdcBllMessages; @@ -57,12 +57,7 @@ if (returnValue && _storageDomainNameChanged && getStoragePool() != null - && !((Boolean) Backend - .getInstance() - .getResourceManager() - .RunVdsCommand(VDSCommandType.IsValid, - new IrsBaseVDSCommandParameters(getStoragePool().getId())).getReturnValue()) - .booleanValue()) { + && getStoragePool().getstatus() != StoragePoolStatus.Up) { addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_IMAGE_REPOSITORY_NOT_FOUND); returnValue = false; } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java index fff8188..536e4f1 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java @@ -468,7 +468,7 @@ } private static void mockVerifyAddVM(AddVmCommand<?> cmd) { - doReturn(true).when(cmd).verifyAddVM(anyListOf(String.class), any(Guid.class), anyInt()); + doReturn(true).when(cmd).verifyAddVM(anyListOf(String.class), anyInt()); } private void mockConfig() { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java index e421535..0add939 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java @@ -22,6 +22,7 @@ import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.StorageDomainStatus; import org.ovirt.engine.core.common.businessentities.StorageDomainType; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; @@ -30,6 +31,7 @@ import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.common.businessentities.storage_domains; +import org.ovirt.engine.core.common.businessentities.storage_pool; import org.ovirt.engine.core.common.businessentities.vm_pools; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend; @@ -41,6 +43,7 @@ import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dao.DiskImageDAO; import org.ovirt.engine.core.dao.StorageDomainDAO; +import org.ovirt.engine.core.dao.StoragePoolDAO; import org.ovirt.engine.core.dao.VdsGroupDAO; import org.ovirt.engine.core.dao.VmNetworkInterfaceDAO; import org.ovirt.engine.core.dao.VmPoolDAO; @@ -72,6 +75,7 @@ protected static int VM_COUNT = 5; protected static int DISK_SIZE = 100000; protected VmTemplate vmTemplate; + protected storage_pool storage_pool; protected List<storage_domains> storageDomainsList; @Mock @@ -91,6 +95,9 @@ @Mock protected VmPoolDAO vmPoolDAO; + + @Mock + protected StoragePoolDAO storagePoolDAO; @Mock protected VmTemplateDAO vmTemplateDAO; @@ -121,11 +128,10 @@ command = createCommand(); doReturn(true).when(command).areTemplateImagesInStorageReady(any(Guid.class)); doReturn(true).when(command).isMemorySizeLegal(any(Version.class)); - doReturn(true).when(command).verifyAddVM(any(Guid.class)); + doReturn(true).when(command).verifyAddVM(); } private void mockVds() { - mockIsValidVdsCommand(); mockGetImageDomainsListVdsCommand(100, 100); } @@ -134,12 +140,7 @@ vmPools = mockVmPools(); vdsGroup = mockVdsGroup(); vmTemplate = mockVmTemplate(); - } - - private void mockIsValidVdsCommand() { - VDSReturnValue returnValue = new VDSReturnValue(); - returnValue.setReturnValue(Boolean.TRUE); - doReturn(returnValue).when(command).runVdsCommand(eq(VDSCommandType.IsValid), any(VDSParametersBase.class)); + storage_pool = mockStoragePool(); } protected void mockGetImageDomainsListVdsCommand(int availableDiskSizeFirstDomain, @@ -164,6 +165,11 @@ private void mockVMPoolDAO() { doReturn(vmPoolDAO).when(command).getVmPoolDAO(); + } + + private void mockStoragePoolDAO() { + doReturn(storagePoolDAO).when(command).getStoragePoolDAO(); + when(storagePoolDAO.get(storagePoolId)).thenReturn(storage_pool); } private void mockVMTemplateDAO() { @@ -261,6 +267,16 @@ return template; } + /** + * Mock Storage Pool + */ + private storage_pool mockStoragePool() { + storage_pool storage_pool = new storage_pool(); + storage_pool.setstatus(StoragePoolStatus.Up); + + return storage_pool; + } + private static void setDiskList(VmTemplate vmTemplate) { for (DiskImage diskImage : getDiskImageList()) { vmTemplate.getDiskList().add(diskImage); @@ -324,5 +340,6 @@ mockVMPoolDAO(); mockVMTemplateDAO(); mockVmNetworkInterfaceDao(); + mockStoragePoolDAO(); } } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java index 04e435d..5899d1e 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java @@ -3,7 +3,6 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -33,9 +32,6 @@ import org.ovirt.engine.core.common.businessentities.storage_domains; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; -import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBaseMockUtils; @@ -94,7 +90,6 @@ mockBackend(); mockDaos(); mockVm(); - mockIsValidVdsCommand(); } protected void mockBackend() { @@ -140,16 +135,6 @@ mockSnapshot = new Snapshot(); mockSnapshot.setType(SnapshotType.STATELESS); when(snapshotDao.get(any(Guid.class))).thenReturn(mockSnapshot); - } - - /** - * Returns image is valid. - */ - private void mockIsValidVdsCommand() { - VDSReturnValue returnValue = new VDSReturnValue(); - returnValue.setReturnValue(Boolean.TRUE); - when(backend.getResourceManager().RunVdsCommand(eq(VDSCommandType.IsValid), - any(IrsBaseVDSCommandParameters.class))).thenReturn(returnValue); } private void initSpyCommand() { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java index 9d34fd1..9944788 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java @@ -71,7 +71,6 @@ CreateSnapshot("org.ovirt.engine.core.vdsbroker.irsbroker"), MergeSnapshots("org.ovirt.engine.core.vdsbroker.irsbroker"), SetImageDescription("org.ovirt.engine.core.vdsbroker.irsbroker"), - IsValid("org.ovirt.engine.core.vdsbroker.irsbroker"), IsoPrefix("org.ovirt.engine.core.vdsbroker.irsbroker"), IsoDirectory("org.ovirt.engine.core.vdsbroker.irsbroker"), ResetIrs("org.ovirt.engine.core.vdsbroker.irsbroker"), diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java index f3b46da..a5b8c05 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java @@ -499,7 +499,7 @@ setmCurrentIrsHost(vds.gethost_name()); } - public boolean Failover() { + public boolean failover() { setmIrsProxy(null); setmCurrentIrsHost(null); boolean performFailover = false; @@ -518,17 +518,17 @@ } else { performFailover = true; } - } catch (java.lang.Exception ex) { + } catch (Exception ex) { // try to failover to another host if failed to get spm // status or stop spm // (in case mCurrentVdsId has wrong id for some reason) - log.errorFormat("Could not get spm status on host {0} for spmStop.", getmCurrentIrsHost()); + log.errorFormat("Could not get spm status on host {0} for spmStop.", mCurrentVdsId); performFailover = true; } } if (performFailover) { - log.infoFormat("Irs placed on server {0} failed. Proceed Failover", getmCurrentIrsHost()); + log.infoFormat("Irs placed on server {0} failed. Proceed Failover", mCurrentVdsId); mTriedVdssList.add(mCurrentVdsId); return true; } else { @@ -1009,10 +1009,6 @@ public String getIsoDirectory() { String tempVar = getmCurrentIrsHost(); return String.format("\\\\%1$s\\CD", ((tempVar != null) ? tempVar : gethostFromVds())); - } - - public boolean getIsValid() { - return getIrsProxy() != null; } public boolean getIsValidWithoutSpmStart() { @@ -1550,7 +1546,7 @@ private void failover() { if ((getParameters().getIgnoreFailoverLimit() || _failoverCounter < Config .<Integer> GetValue(ConfigValues.SpmCommandFailOverRetries) - 1) - && getCurrentIrsProxyData().getHasVdssForSpmSelection() && getCurrentIrsProxyData().Failover()) { + && getCurrentIrsProxyData().getHasVdssForSpmSelection() && getCurrentIrsProxyData().failover()) { _failoverCounter++; ExecuteCommand(); } else { diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IsValidVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IsValidVDSCommand.java deleted file mode 100644 index 07b687e..0000000 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IsValidVDSCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.ovirt.engine.core.vdsbroker.irsbroker; - -import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; -import org.ovirt.engine.core.common.businessentities.storage_pool; -import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; - -public class IsValidVDSCommand<P extends IrsBaseVDSCommandParameters> extends IrsBrokerCommand<P> { - public IsValidVDSCommand(P parameters) { - super(parameters); - } - - @Override - protected void ExecuteVDSCommand() { - storage_pool storagePool = DbFacade.getInstance().getStoragePoolDao().get( - getParameters().getStoragePoolId()); - try { - getVDSReturnValue().setReturnValue( - storagePool != null && storagePool.getstatus() == StoragePoolStatus.Up - && getCurrentIrsProxyData().getIsValid()); - } catch (RuntimeException ex) { - log.warnFormat("IsValidVDSCommand failed: {0}", ex.getMessage()); - getVDSReturnValue().setReturnValue(false); - } - } - - private static Log log = LogFactory.getLog(IsValidVDSCommand.class); -} -- To view, visit http://gerrit.ovirt.org/9097 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I73c0fa0fd66f2f14132594a0b0450a7ecd7cf166 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Michael Kublin <mkub...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches