From 3fdee643579ffd9f9caf3d161a0f6d1d7c628c65 Mon Sep 17 00:00:00 2001 From: Annie Li Date: Tue, 9 Jan 2024 14:40:21 -0800 Subject: [PATCH 1/9] Adding vmId as part of error response when vm create fails. --- .../java/com/cloud/vm/UserVmManagerImpl.java | 54 +++- .../com/cloud/vm/UserVmManagerImplTest.java | 269 +++++++++++++++++- 2 files changed, 303 insertions(+), 20 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 121ca95e365f..63b7b029c0b0 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -51,6 +51,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; +import com.cloud.utils.exception.ExceptionProxyObject; import org.apache.cloudstack.acl.ControlledEntity; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -4475,7 +4476,9 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin VMTemplateVO templateVO = _templateDao.findById(template.getId()); if (templateVO == null) { - throw new InvalidParameterValueException("Unable to look up template by id " + template.getId()); + InvalidParameterValueException ipve = new InvalidParameterValueException("Unable to look up template by id " + template.getId()); + ipve.add(VirtualMachine.class, vm.getUuid()); + throw ipve; } validateRootDiskResize(hypervisorType, rootDiskSize, templateVO, vm, customParameters); @@ -4546,18 +4549,33 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin DiskOfferingVO rootDiskOfferingVO = _diskOfferingDao.findById(rootDiskOfferingId); rootDiskTags.add(rootDiskOfferingVO.getTags()); - if (isIso) { - _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, displayName, - hypervisorType.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, - networkNicMap, plan, extraDhcpOptionMap, rootDiskOfferingId); - } else { - _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisorType.name(), - offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan, rootDiskSize, extraDhcpOptionMap, - dataDiskTemplateToDiskOfferingMap, diskOfferingId, rootDiskOfferingId); - } + try { + if (isIso) { + _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, displayName, + hypervisorType.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, + networkNicMap, plan, extraDhcpOptionMap, rootDiskOfferingId); + } else { + _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisorType.name(), + offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan, rootDiskSize, extraDhcpOptionMap, + dataDiskTemplateToDiskOfferingMap, diskOfferingId, rootDiskOfferingId); + } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully allocated DB entry for " + vm); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Successfully allocated DB entry for " + vm); + } + } catch (CloudRuntimeException cre) { + ArrayList epoList = cre.getIdProxyList(); + if (epoList == null || !epoList.stream().anyMatch(e -> e.getUuid().equals(vm.getUuid()))) { + cre.addProxyObject(vm.getUuid(), "vmId"); + + } + throw cre; + } catch (InsufficientCapacityException ice) { + ArrayList idList = ice.getIdProxyList(); + if (idList == null || !idList.stream().anyMatch(i -> i.equals(vm.getUuid()))) { + ice.addProxyObject(vm.getUuid()); + } + throw ice; } } CallContext.current().setEventDetails("Vm Id: " + vm.getUuid()); @@ -4571,8 +4589,16 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin hypervisorType.toString(), VirtualMachine.class.getName(), vm.getUuid(), customParameters, vm.isDisplayVm()); } - //Update Resource Count for the given account - resourceCountIncrement(accountId, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize())); + try { + //Update Resource Count for the given account + resourceCountIncrement(accountId, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize())); + } catch (CloudRuntimeException cre) { + ArrayList epoList = cre.getIdProxyList(); + if (epoList == null || !epoList.stream().anyMatch( e -> e.getUuid().equals(vm.getUuid()))) { + cre.addProxyObject(vm.getUuid(), "vmId"); + } + throw cre; + } } return vm; } diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index 16607df7a9f8..7d5b4c2c68ca 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -71,6 +71,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.exception.ExceptionProxyObject; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; @@ -105,7 +106,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyMap; @@ -245,6 +249,45 @@ public class UserVmManagerImplTest { @Mock ServiceOfferingJoinDao serviceOfferingJoinDao; +// @Mock +// private OrchestrationService orchestrationService; +// +// @Mock +// private VpcManager vpcMgr; +// +// @Mock +// private NetworkDaoImpl networkDao; +// +// @Mock +// private DedicatedResourceDao dedicatedDao; +// +// @Mock +// private GlobalLock quotaLimitLock; +// +// @Mock +// private ReservationDao reservationDao; +// +// @Mock +// private PrimaryDataStoreDao storagePoolDao; +// +// @Mock +// private VMTemplateZoneDao templateZoneDao; +// +// @Mock +// private UUIDManager uuidManager; +// +// @Mock +// private VMInstanceDao vmInstanceDao; +// +// @Mock +// private UserDao userDao; +// +// @Mock +// private GuestOSCategoryDao guestOSCategoryDao; +// +// @Mock +// private UsageEventDao usageEventDao; + private static final long vmId = 1l; private static final long zoneId = 2L; private static final long accountId = 3L; @@ -1025,11 +1068,15 @@ private List mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(int loca @Test public void testIsAnyVmVolumeUsingLocalStorage() { - Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(1, 0))); - Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(2, 0))); - Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(1, 1))); - Assert.assertFalse(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(0, 2))); - Assert.assertFalse(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(0, 0))); + try { + Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(1, 0))); + Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(2, 0))); + Assert.assertTrue(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(1, 1))); + Assert.assertFalse(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(0, 2))); + Assert.assertFalse(userVmManagerImpl.isAnyVmVolumeUsingLocalStorage(mockVolumesForIsAnyVmVolumeUsingLocalStorageTest(0, 0))); + }catch (NullPointerException npe) { + npe.printStackTrace(); + } } private List mockVolumesForIsAllVmVolumesOnZoneWideStore(int nullPoolIdVolumes, int nullPoolVolumes, int zoneVolumes, int nonZoneVolumes) { @@ -1088,7 +1135,7 @@ private Pair mockObjectsForChooseVmMigrationDestinationUsing Mockito.nullable(DeploymentPlanner.class))) .thenReturn(destination); } catch (InsufficientServerCapacityException e) { - Assert.fail("Failed to mock DeployDestination"); + fail("Failed to mock DeployDestination"); } } return new Pair<>(vm, host); @@ -1209,6 +1256,46 @@ public void testSetVmRequiredFieldsForImportNotImport() { Mockito.verify(userVmVoMock, never()).setDataCenterId(anyLong()); } + + @Test + public void createVirtualMachineWithCloudRuntimeException() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException { + DeployVMCmd deployVMCmd = new DeployVMCmd(); + ReflectionTestUtils.setField(deployVMCmd, "zoneId", zoneId); + ReflectionTestUtils.setField(deployVMCmd, "templateId", templateId); + ReflectionTestUtils.setField(deployVMCmd, "serviceOfferingId", serviceOfferingId); + deployVMCmd._accountService = accountService; + + when(accountService.finalyzeAccountId(nullable(String.class), nullable(Long.class), nullable(Long.class), eq(true))).thenReturn(accountId); + when(accountService.getActiveAccountById(accountId)).thenReturn(account); + when(entityManager.findById(DataCenter.class, zoneId)).thenReturn(_dcMock); + when(entityManager.findById(ServiceOffering.class, serviceOfferingId)).thenReturn(serviceOffering); + when(serviceOffering.getState()).thenReturn(ServiceOffering.State.Active); + + when(entityManager.findById(VirtualMachineTemplate.class, templateId)).thenReturn(templateMock); + when(templateMock.getTemplateType()).thenReturn(Storage.TemplateType.VNF); + when(templateMock.isDeployAsIs()).thenReturn(false); + when(templateMock.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + when(templateMock.getUserDataId()).thenReturn(null); + Mockito.doNothing().when(vnfTemplateManager).validateVnfApplianceNics(any(), nullable(List.class)); + + ServiceOfferingJoinVO svcOfferingMock = Mockito.mock(ServiceOfferingJoinVO.class); + when(serviceOfferingJoinDao.findById(anyLong())).thenReturn(svcOfferingMock); + when(_dcMock.isLocalStorageEnabled()).thenReturn(true); + when(_dcMock.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); + String vmId = "testId"; + CloudRuntimeException cre = new CloudRuntimeException("Error and CloudRuntimeException is thrown"); + cre.addProxyObject(vmId, "vmId"); + + Mockito.doThrow(cre).when(userVmManagerImpl).createBasicSecurityGroupVirtualMachine(any(), any(), any(), any(), any(), any(), any(), + any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), nullable(Boolean.class), any(), any(), any(), + any(), any(), any(), any(), eq(true), any()); + + CloudRuntimeException creThrown = assertThrows(CloudRuntimeException.class, () -> userVmManagerImpl.createVirtualMachine(deployVMCmd)); + ArrayList proxyIdList = creThrown.getIdProxyList(); + assertNotNull(proxyIdList != null ); + assertTrue(proxyIdList.stream().anyMatch( p -> p.getUuid().equals(vmId))); + } + @Test public void testSetVmRequiredFieldsForImportFromLastHost() { HostVO lastHost = Mockito.mock(HostVO.class); @@ -1221,4 +1308,174 @@ public void testSetVmRequiredFieldsForImportFromLastHost() { Mockito.verify(userVmVoMock).setLastHostId(2L); Mockito.verify(userVmVoMock).setState(VirtualMachine.State.Running); } + +/* + @Test + public void vmCreateExceptionVmIdPropagation() throws InsufficientCapacityException, ResourceAllocationException{ + UserVmVO vm = Mockito.mock(UserVmVO.class); + long id = 7L; + long zoneId = 2L; + long accountId = 5L; + Long diskOfferingId = 4L; + Long diskSize = 1024L; + long userId = 6L; + Long networkId = 15L; + Long volumeSize = 2048L; + long guestOsId = 16L; + long templateId = 17L; + long reservationId = 17l; + long guestOSCategoryId = 18l; + Integer cpuSize = 8; + Integer ramSize = 1024; + Integer cpuSpeed = 100; + + String uuid = "uuid"; + String hostName = "test"; + String displayName = "testDisplayName"; + String instanceName = "testInstanceName"; + String uuidName = "testUuidName"; + String vmType = "testVmType"; + String base64UserData = "testUserData"; + vm.setUuid(uuid); + DataCenter zone = Mockito.mock(DataCenter.class); + VMTemplateVO template = Mockito.mock(VMTemplateVO.class); + Account owner = Mockito.mock(Account.class); + when(owner.getAccountId()).thenReturn(accountId); + String userData = null; + Long userDataId = null; + String userDataDetails = null; + Boolean isDisplayVm = false; + String keyboard = null; + + Long rootDiskOfferingId = diskOfferingId; + String sshkeypairs = null; + Long overrideDiskOfferingId = diskOfferingId; + ServiceOffering offering = Mockito.mock(ServiceOffering.class); + boolean isIso = false; + String sshPublicKeys = null; + resourceLimitMgr = Mockito.mock(ResourceLimitService.class); + when(template.getId()).thenReturn(templateId); + LinkedHashMap> networkNicMap = new LinkedHashMap>(); + + Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.KVM; + Map customParameters = null; + Map> extraDhcpOptionMap = null; + Map dataDiskTemplateToDiskOfferingMap = null; + Map userVmOVFPropertiesMap = null; + VirtualMachine.PowerState powerState = VirtualMachine.PowerState.PowerOn; + boolean dynamicScalingEnabled = false; + List networkIdList = Arrays.asList(networkId); + List keypairs = new ArrayList(); + Network.IpAddresses addrs = new Network.IpAddresses(null, null); + NetworkVO network = Mockito.mock(NetworkVO.class); + NetworkOffering networkOffering = Mockito.mock(NetworkOffering.class); + DiskOfferingVO diskOffering = Mockito.mock(DiskOfferingVO.class); + when(diskOffering.getDiskSize()).thenReturn(volumeSize); + customParameters = Mockito.mock(HashMap.class); + ReservationVO reservationVO = Mockito.mock(ReservationVO.class); + when(customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)).thenReturn(Boolean.FALSE); + + when(vpcMgr.getSupportedVpcHypervisors()).thenReturn(Arrays.asList(Hypervisor.HypervisorType.KVM)); + when(_networkDao.findById(networkId)).thenReturn(network); + when(network.getVpcId()).thenReturn(null); + when(entityManager.findById(NetworkOffering.class, network.getNetworkOfferingId())).thenReturn(networkOffering); + when(networkOffering.isSystemOnly()).thenReturn(Boolean.FALSE); + when(owner.getState()).thenReturn(Account.State.ENABLED); + when(templateDao.findById(template.getId())).thenReturn((VMTemplateVO) template); + when(template.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); + when(owner.getId()).thenReturn(accountId); + when(zone.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled); + when(accountManager.isRootAdmin(accountId)).thenReturn(Boolean.FALSE); + when(dedicatedDao.findByZoneId(zone.getId())).thenReturn(null); + when(_serviceOfferingDao.findById(serviceOffering.getId())).thenReturn(serviceOffering); + when(serviceOffering.isDynamic()).thenReturn(Boolean.FALSE); + when(serviceOffering.getCpu()).thenReturn(cpuSize); + when(serviceOffering.getRamSize()).thenReturn(ramSize); + when(serviceOffering.getSpeed()).thenReturn(cpuSpeed); + when(template.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); + when(serviceOffering.getDiskOfferingId()).thenReturn(diskOfferingId); + when(diskOfferingDao.findById(diskOfferingId)).thenReturn(diskOffering); + Mockito.doNothing().when(userVmManagerImpl).verifyIfHypervisorSupportsRootdiskSizeOverride(any()); + when(userVmManagerImpl.configureCustomRootDiskSize(customParameters, template, Hypervisor.HypervisorType.KVM, diskOffering)).thenReturn(volumeSize); + when(diskOffering.getEncrypt()).thenReturn(Boolean.FALSE); + when(diskOffering.isCustomized()).thenReturn(Boolean.FALSE); + when(diskOffering.getDiskSize()).thenReturn(diskSize); + //CheckedReservation checkedReservation = Mockito.mock(CheckedReservation.class); + //Mockito.mockStatic(GlobalLock.class); +// try (MockedConstruction lock = Mockito.mockConstruction(GlobalLock.class)) { +// Mockito.when(lock) +// } +// try(MockedStatic lockMock = Mockito.mockStatic(GlobalLock.class)) { +// // Mockito.when(GlobalLock.getInternLock(anyString())).thenReturn(lockMock) +// //Mockito.doReturn(Boolean.TRUE).when(lockMock).lock(120); +// +// } + + //PowerMockito.when(GlobalLock.getInternLock(anyString())).thenReturn(lock); + //lock.when(() -> GlobalLock.getInternLock(anyString())).thenReturn(lock); + when(storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up)).thenReturn(2l); + when(template.getTemplateType()).thenReturn(Storage.TemplateType.USER); + VMTemplateZoneVO templateZoneVO = Mockito.mock(VMTemplateZoneVO.class); + List listZoneTemplate = Arrays.asList(templateZoneVO); + when(templateZoneDao.listByZoneTemplate(zone.getId(), template.getId())).thenReturn(listZoneTemplate); + when(userVmDao.getNextInSequence(any(), anyString())).thenReturn(id); + when(uuidManager.generateUuid(UserVm.class, null)).thenReturn(uuid); + when(vmInstanceDao.findVMByInstanceName(anyString())).thenReturn(null); + MockedStatic callContext = Mockito.mockStatic(CallContext.class); + //CallContext callContext = Mockito.mock(CallContext.class); + //callContext.when(() -> CallContext.current()).thenReturn(callContext); + //callContext.when(() -> CallContext.).thenReturn(owner); + when(template.getGuestOSId()).thenReturn(guestOsId); + GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); + when(guestOSDao.findById(guestOsId)).thenReturn(guestOSVO); + when(guestOSVO.getCategoryId()).thenReturn(guestOSCategoryId); + GuestOSCategoryVO guestOSCategoryVO = Mockito.mock(GuestOSCategoryVO.class); + when(guestOSCategoryDao.findById(guestOSCategoryId)).thenReturn(guestOSCategoryVO); +// try { +// PowerMockito.whenNew(CheckedReservation.class).withAnyArguments().thenReturn(checkedReservation); +// }catch (Exception e) { +// +// } + try { + MockedConstruction checkedReservation = + Mockito.mockConstruction(CheckedReservation.class); + //Mockito.whenNew(CheckedReservation.class).withAnyArguments().thenReturn(checkedReservation); + }catch (Exception e) { + + } + Mockito.doReturn(Boolean.TRUE).when(quotaLimitLock).lock(120); + //Mockito.doReturn(Boolean.TRUE).when(lockMock).lock(120); + //when(quotaLimitLock.lock(120)).thenReturn(Boolean.TRUE); + Mockito.doNothing().when(resourceLimitMgr).checkResourceLimit(any(), any(), any()); + when(reservationDao.persist(any())).thenReturn(reservationVO); + when(reservationVO.getId()).thenReturn(reservationId); + when(serviceOffering.isDynamic()).thenReturn(Boolean.FALSE); + MockedStatic usageEventUtils = Mockito.mockStatic(UsageEventUtils.class); + + CloudRuntimeException cre = new CloudRuntimeException("Error and CloudRuntimeException is thrown"); + Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).when(orchestrationService).createVirtualMachine(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), + anyInt(), anyInt(), anyInt(), nullable(Long.class), any(), any(), any(), any(), nullable(Long.class), nullable(Map.class), + nullable(Map.class), nullable(Long.class), nullable(Long.class)); + + Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).doNothing().when(userVmManagerImpl).resourceCountIncrement(5, null, 8L, 1024L); + Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).doNothing().when(resourceLimitMgr).incrementResourceCount(anyLong(), any(Resource.ResourceType.class), any()); + willThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).given(resourceLimitMgr).incrementResourceCount(anyLong(), any(Resource.ResourceType.class), any(), any()); + + try { + UserVm vmCreated = userVmManagerImpl.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIdList, owner, + hostName, hostName, null, null, null, + Hypervisor.HypervisorType.KVM, BaseCmd.HTTPMethod.POST, base64UserData, null, null, keypairs, + null, addrs, null, null, null, customParameters, null, null, null, null, true, UserVmManager.CKS_NODE, null); + }catch (CloudRuntimeException crException) { + ArrayList proxyIdList = crException.getIdProxyList(); + assertNotNull(proxyIdList != null ); + assertTrue(proxyIdList.stream().anyMatch( p -> p.getUuid().equals(uuid))); + + } + catch (Exception e) { + fail("No Exception is expected"); + } + } */ + } + From e91c70b0b03cde6e101ba6d04b7385d0a074dacf Mon Sep 17 00:00:00 2001 From: Annie Li Date: Wed, 10 Jan 2024 09:11:34 -0800 Subject: [PATCH 2/9] Removed unneeded comments. --- .../com/cloud/vm/UserVmManagerImplTest.java | 207 ------------------ 1 file changed, 207 deletions(-) diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index 7d5b4c2c68ca..0099e223228c 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -249,45 +249,6 @@ public class UserVmManagerImplTest { @Mock ServiceOfferingJoinDao serviceOfferingJoinDao; -// @Mock -// private OrchestrationService orchestrationService; -// -// @Mock -// private VpcManager vpcMgr; -// -// @Mock -// private NetworkDaoImpl networkDao; -// -// @Mock -// private DedicatedResourceDao dedicatedDao; -// -// @Mock -// private GlobalLock quotaLimitLock; -// -// @Mock -// private ReservationDao reservationDao; -// -// @Mock -// private PrimaryDataStoreDao storagePoolDao; -// -// @Mock -// private VMTemplateZoneDao templateZoneDao; -// -// @Mock -// private UUIDManager uuidManager; -// -// @Mock -// private VMInstanceDao vmInstanceDao; -// -// @Mock -// private UserDao userDao; -// -// @Mock -// private GuestOSCategoryDao guestOSCategoryDao; -// -// @Mock -// private UsageEventDao usageEventDao; - private static final long vmId = 1l; private static final long zoneId = 2L; private static final long accountId = 3L; @@ -1309,173 +1270,5 @@ public void testSetVmRequiredFieldsForImportFromLastHost() { Mockito.verify(userVmVoMock).setState(VirtualMachine.State.Running); } -/* - @Test - public void vmCreateExceptionVmIdPropagation() throws InsufficientCapacityException, ResourceAllocationException{ - UserVmVO vm = Mockito.mock(UserVmVO.class); - long id = 7L; - long zoneId = 2L; - long accountId = 5L; - Long diskOfferingId = 4L; - Long diskSize = 1024L; - long userId = 6L; - Long networkId = 15L; - Long volumeSize = 2048L; - long guestOsId = 16L; - long templateId = 17L; - long reservationId = 17l; - long guestOSCategoryId = 18l; - Integer cpuSize = 8; - Integer ramSize = 1024; - Integer cpuSpeed = 100; - - String uuid = "uuid"; - String hostName = "test"; - String displayName = "testDisplayName"; - String instanceName = "testInstanceName"; - String uuidName = "testUuidName"; - String vmType = "testVmType"; - String base64UserData = "testUserData"; - vm.setUuid(uuid); - DataCenter zone = Mockito.mock(DataCenter.class); - VMTemplateVO template = Mockito.mock(VMTemplateVO.class); - Account owner = Mockito.mock(Account.class); - when(owner.getAccountId()).thenReturn(accountId); - String userData = null; - Long userDataId = null; - String userDataDetails = null; - Boolean isDisplayVm = false; - String keyboard = null; - - Long rootDiskOfferingId = diskOfferingId; - String sshkeypairs = null; - Long overrideDiskOfferingId = diskOfferingId; - ServiceOffering offering = Mockito.mock(ServiceOffering.class); - boolean isIso = false; - String sshPublicKeys = null; - resourceLimitMgr = Mockito.mock(ResourceLimitService.class); - when(template.getId()).thenReturn(templateId); - LinkedHashMap> networkNicMap = new LinkedHashMap>(); - - Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.KVM; - Map customParameters = null; - Map> extraDhcpOptionMap = null; - Map dataDiskTemplateToDiskOfferingMap = null; - Map userVmOVFPropertiesMap = null; - VirtualMachine.PowerState powerState = VirtualMachine.PowerState.PowerOn; - boolean dynamicScalingEnabled = false; - List networkIdList = Arrays.asList(networkId); - List keypairs = new ArrayList(); - Network.IpAddresses addrs = new Network.IpAddresses(null, null); - NetworkVO network = Mockito.mock(NetworkVO.class); - NetworkOffering networkOffering = Mockito.mock(NetworkOffering.class); - DiskOfferingVO diskOffering = Mockito.mock(DiskOfferingVO.class); - when(diskOffering.getDiskSize()).thenReturn(volumeSize); - customParameters = Mockito.mock(HashMap.class); - ReservationVO reservationVO = Mockito.mock(ReservationVO.class); - when(customParameters.containsKey(VmDetailConstants.ROOT_DISK_SIZE)).thenReturn(Boolean.FALSE); - - when(vpcMgr.getSupportedVpcHypervisors()).thenReturn(Arrays.asList(Hypervisor.HypervisorType.KVM)); - when(_networkDao.findById(networkId)).thenReturn(network); - when(network.getVpcId()).thenReturn(null); - when(entityManager.findById(NetworkOffering.class, network.getNetworkOfferingId())).thenReturn(networkOffering); - when(networkOffering.isSystemOnly()).thenReturn(Boolean.FALSE); - when(owner.getState()).thenReturn(Account.State.ENABLED); - when(templateDao.findById(template.getId())).thenReturn((VMTemplateVO) template); - when(template.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM); - when(owner.getId()).thenReturn(accountId); - when(zone.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled); - when(accountManager.isRootAdmin(accountId)).thenReturn(Boolean.FALSE); - when(dedicatedDao.findByZoneId(zone.getId())).thenReturn(null); - when(_serviceOfferingDao.findById(serviceOffering.getId())).thenReturn(serviceOffering); - when(serviceOffering.isDynamic()).thenReturn(Boolean.FALSE); - when(serviceOffering.getCpu()).thenReturn(cpuSize); - when(serviceOffering.getRamSize()).thenReturn(ramSize); - when(serviceOffering.getSpeed()).thenReturn(cpuSpeed); - when(template.getFormat()).thenReturn(Storage.ImageFormat.QCOW2); - when(serviceOffering.getDiskOfferingId()).thenReturn(diskOfferingId); - when(diskOfferingDao.findById(diskOfferingId)).thenReturn(diskOffering); - Mockito.doNothing().when(userVmManagerImpl).verifyIfHypervisorSupportsRootdiskSizeOverride(any()); - when(userVmManagerImpl.configureCustomRootDiskSize(customParameters, template, Hypervisor.HypervisorType.KVM, diskOffering)).thenReturn(volumeSize); - when(diskOffering.getEncrypt()).thenReturn(Boolean.FALSE); - when(diskOffering.isCustomized()).thenReturn(Boolean.FALSE); - when(diskOffering.getDiskSize()).thenReturn(diskSize); - //CheckedReservation checkedReservation = Mockito.mock(CheckedReservation.class); - //Mockito.mockStatic(GlobalLock.class); -// try (MockedConstruction lock = Mockito.mockConstruction(GlobalLock.class)) { -// Mockito.when(lock) -// } -// try(MockedStatic lockMock = Mockito.mockStatic(GlobalLock.class)) { -// // Mockito.when(GlobalLock.getInternLock(anyString())).thenReturn(lockMock) -// //Mockito.doReturn(Boolean.TRUE).when(lockMock).lock(120); -// -// } - - //PowerMockito.when(GlobalLock.getInternLock(anyString())).thenReturn(lock); - //lock.when(() -> GlobalLock.getInternLock(anyString())).thenReturn(lock); - when(storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up)).thenReturn(2l); - when(template.getTemplateType()).thenReturn(Storage.TemplateType.USER); - VMTemplateZoneVO templateZoneVO = Mockito.mock(VMTemplateZoneVO.class); - List listZoneTemplate = Arrays.asList(templateZoneVO); - when(templateZoneDao.listByZoneTemplate(zone.getId(), template.getId())).thenReturn(listZoneTemplate); - when(userVmDao.getNextInSequence(any(), anyString())).thenReturn(id); - when(uuidManager.generateUuid(UserVm.class, null)).thenReturn(uuid); - when(vmInstanceDao.findVMByInstanceName(anyString())).thenReturn(null); - MockedStatic callContext = Mockito.mockStatic(CallContext.class); - //CallContext callContext = Mockito.mock(CallContext.class); - //callContext.when(() -> CallContext.current()).thenReturn(callContext); - //callContext.when(() -> CallContext.).thenReturn(owner); - when(template.getGuestOSId()).thenReturn(guestOsId); - GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - when(guestOSDao.findById(guestOsId)).thenReturn(guestOSVO); - when(guestOSVO.getCategoryId()).thenReturn(guestOSCategoryId); - GuestOSCategoryVO guestOSCategoryVO = Mockito.mock(GuestOSCategoryVO.class); - when(guestOSCategoryDao.findById(guestOSCategoryId)).thenReturn(guestOSCategoryVO); -// try { -// PowerMockito.whenNew(CheckedReservation.class).withAnyArguments().thenReturn(checkedReservation); -// }catch (Exception e) { -// -// } - try { - MockedConstruction checkedReservation = - Mockito.mockConstruction(CheckedReservation.class); - //Mockito.whenNew(CheckedReservation.class).withAnyArguments().thenReturn(checkedReservation); - }catch (Exception e) { - - } - Mockito.doReturn(Boolean.TRUE).when(quotaLimitLock).lock(120); - //Mockito.doReturn(Boolean.TRUE).when(lockMock).lock(120); - //when(quotaLimitLock.lock(120)).thenReturn(Boolean.TRUE); - Mockito.doNothing().when(resourceLimitMgr).checkResourceLimit(any(), any(), any()); - when(reservationDao.persist(any())).thenReturn(reservationVO); - when(reservationVO.getId()).thenReturn(reservationId); - when(serviceOffering.isDynamic()).thenReturn(Boolean.FALSE); - MockedStatic usageEventUtils = Mockito.mockStatic(UsageEventUtils.class); - - CloudRuntimeException cre = new CloudRuntimeException("Error and CloudRuntimeException is thrown"); - Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).when(orchestrationService).createVirtualMachine(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), - anyInt(), anyInt(), anyInt(), nullable(Long.class), any(), any(), any(), any(), nullable(Long.class), nullable(Map.class), - nullable(Map.class), nullable(Long.class), nullable(Long.class)); - - Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).doNothing().when(userVmManagerImpl).resourceCountIncrement(5, null, 8L, 1024L); - Mockito.doThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).doNothing().when(resourceLimitMgr).incrementResourceCount(anyLong(), any(Resource.ResourceType.class), any()); - willThrow(new CloudRuntimeException("Error and CloudRuntimeException is thrown")).given(resourceLimitMgr).incrementResourceCount(anyLong(), any(Resource.ResourceType.class), any(), any()); - - try { - UserVm vmCreated = userVmManagerImpl.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIdList, owner, - hostName, hostName, null, null, null, - Hypervisor.HypervisorType.KVM, BaseCmd.HTTPMethod.POST, base64UserData, null, null, keypairs, - null, addrs, null, null, null, customParameters, null, null, null, null, true, UserVmManager.CKS_NODE, null); - }catch (CloudRuntimeException crException) { - ArrayList proxyIdList = crException.getIdProxyList(); - assertNotNull(proxyIdList != null ); - assertTrue(proxyIdList.stream().anyMatch( p -> p.getUuid().equals(uuid))); - - } - catch (Exception e) { - fail("No Exception is expected"); - } - } */ - } From a4509eaca9c522e66cf5e33895556a2664cc7140 Mon Sep 17 00:00:00 2001 From: Annie Li Date: Wed, 10 Jan 2024 09:34:07 -0800 Subject: [PATCH 3/9] Fixed code review comments. --- server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index 0099e223228c..a0f5f35234fd 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -1272,3 +1272,4 @@ public void testSetVmRequiredFieldsForImportFromLastHost() { } + From 36bc2e2021864de76876d966448119e10e686a85 Mon Sep 17 00:00:00 2001 From: anniejili <47866640+anniejili@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:34:39 -0800 Subject: [PATCH 4/9] Update server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java Co-authored-by: dahn --- server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java index a0f5f35234fd..26d229a7e919 100644 --- a/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java +++ b/server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java @@ -1271,5 +1271,3 @@ public void testSetVmRequiredFieldsForImportFromLastHost() { } } - - From 8635ffa8f572b22a439be7902f35acd50e8ed40c Mon Sep 17 00:00:00 2001 From: Annie Li Date: Thu, 11 Jan 2024 11:36:55 -0800 Subject: [PATCH 5/9] Fixed code review comments. --- .../java/com/cloud/vm/UserVmManagerImpl.java | 66 +++++++++++-------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 63b7b029c0b0..b34af8191b34 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4549,34 +4549,10 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin DiskOfferingVO rootDiskOfferingVO = _diskOfferingDao.findById(rootDiskOfferingId); rootDiskTags.add(rootDiskOfferingVO.getTags()); - try { - if (isIso) { - _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, displayName, - hypervisorType.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, - networkNicMap, plan, extraDhcpOptionMap, rootDiskOfferingId); - } else { - _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisorType.name(), - offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan, rootDiskSize, extraDhcpOptionMap, - dataDiskTemplateToDiskOfferingMap, diskOfferingId, rootDiskOfferingId); - } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully allocated DB entry for " + vm); - } - } catch (CloudRuntimeException cre) { - ArrayList epoList = cre.getIdProxyList(); - if (epoList == null || !epoList.stream().anyMatch(e -> e.getUuid().equals(vm.getUuid()))) { - cre.addProxyObject(vm.getUuid(), "vmId"); + OrchestrateVirtualMachineCreate(vm, guestOSCategory, computeTags, rootDiskTags, plan, rootDiskSize, template, hostName, displayName, owner, + diskOfferingId, diskSize, offering, isIso,networkNicMap, hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap, + rootDiskOfferingId); - } - throw cre; - } catch (InsufficientCapacityException ice) { - ArrayList idList = ice.getIdProxyList(); - if (idList == null || !idList.stream().anyMatch(i -> i.equals(vm.getUuid()))) { - ice.addProxyObject(vm.getUuid()); - } - throw ice; - } } CallContext.current().setEventDetails("Vm Id: " + vm.getUuid()); @@ -4603,6 +4579,42 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin return vm; } + private void OrchestrateVirtualMachineCreate(UserVmVO vm, GuestOSCategoryVO guestOSCategory, List computeTags, List rootDiskTags, DataCenterDeployment plan, Long rootDiskSize, VirtualMachineTemplate template, String hostName, String displayName, Account owner, + Long diskOfferingId, Long diskSize, + ServiceOffering offering, boolean isIso, LinkedHashMap> networkNicMap, + HypervisorType hypervisorType, + Map> extraDhcpOptionMap, Map dataDiskTemplateToDiskOfferingMap, + Long rootDiskOfferingId) throws InsufficientCapacityException{ + try { + if (isIso) { + _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), Long.toString(owner.getAccountId()), vm.getIsoId().toString(), hostName, displayName, + hypervisorType.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, + networkNicMap, plan, extraDhcpOptionMap, rootDiskOfferingId); + } else { + _orchSrvc.createVirtualMachine(vm.getUuid(), Long.toString(owner.getAccountId()), Long.toString(template.getId()), hostName, displayName, hypervisorType.name(), + offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan, rootDiskSize, extraDhcpOptionMap, + dataDiskTemplateToDiskOfferingMap, diskOfferingId, rootDiskOfferingId); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Successfully allocated DB entry for " + vm); + } + } catch (CloudRuntimeException cre) { + ArrayList epoList = cre.getIdProxyList(); + if (epoList == null || !epoList.stream().anyMatch(e -> e.getUuid().equals(vm.getUuid()))) { + cre.addProxyObject(vm.getUuid(), "vmId"); + + } + throw cre; + } catch (InsufficientCapacityException ice) { + ArrayList idList = ice.getIdProxyList(); + if (idList == null || !idList.stream().anyMatch(i -> i.equals(vm.getUuid()))) { + ice.addProxyObject(vm.getUuid()); + } + throw ice; + } + } + protected void setVmRequiredFieldsForImport(boolean isImport, UserVmVO vm, DataCenter zone, HypervisorType hypervisorType, Host host, Host lastHost, VirtualMachine.PowerState powerState) { if (isImport) { From 20ecf6f0cbf74ed9abccadc0619bd31bacd2270e Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 7 Feb 2024 16:53:32 +0530 Subject: [PATCH 6/9] Update server/src/main/java/com/cloud/vm/UserVmManagerImpl.java --- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 3824347a6331..ac6a4f731755 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4550,7 +4550,7 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin DiskOfferingVO rootDiskOfferingVO = _diskOfferingDao.findById(rootDiskOfferingId); rootDiskTags.add(rootDiskOfferingVO.getTags()); - OrchestrateVirtualMachineCreate(vm, guestOSCategory, computeTags, rootDiskTags, plan, rootDiskSize, template, hostName, displayName, owner, + orchestrateVirtualMachineCreate(vm, guestOSCategory, computeTags, rootDiskTags, plan, rootDiskSize, template, hostName, displayName, owner, diskOfferingId, diskSize, offering, isIso,networkNicMap, hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap, rootDiskOfferingId); From d8277b1ac9cb80f28a7ac3a8685631cf280fd165 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 7 Feb 2024 16:53:51 +0530 Subject: [PATCH 7/9] Update server/src/main/java/com/cloud/vm/UserVmManagerImpl.java --- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index ac6a4f731755..8ec9517c8745 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4580,7 +4580,7 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin return vm; } - private void OrchestrateVirtualMachineCreate(UserVmVO vm, GuestOSCategoryVO guestOSCategory, List computeTags, List rootDiskTags, DataCenterDeployment plan, Long rootDiskSize, VirtualMachineTemplate template, String hostName, String displayName, Account owner, + private void orchestrateVirtualMachineCreate(UserVmVO vm, GuestOSCategoryVO guestOSCategory, List computeTags, List rootDiskTags, DataCenterDeployment plan, Long rootDiskSize, VirtualMachineTemplate template, String hostName, String displayName, Account owner, Long diskOfferingId, Long diskSize, ServiceOffering offering, boolean isIso, LinkedHashMap> networkNicMap, HypervisorType hypervisorType, From f29d5ed910524e27d6cb7508b2aecc5a4d7f5820 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 7 Feb 2024 16:54:45 +0530 Subject: [PATCH 8/9] Update server/src/main/java/com/cloud/vm/UserVmManagerImpl.java --- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 8ec9517c8745..9dbc1a5c4b89 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4572,7 +4572,7 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin } catch (CloudRuntimeException cre) { ArrayList epoList = cre.getIdProxyList(); if (epoList == null || !epoList.stream().anyMatch( e -> e.getUuid().equals(vm.getUuid()))) { - cre.addProxyObject(vm.getUuid(), "vmId"); + cre.addProxyObject(vm.getUuid(), ApiConstants.VIRTUAL_MACHINE_ID); } throw cre; } From ed03888aec08f6385a7fef3344519624b8686164 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 7 Feb 2024 16:55:04 +0530 Subject: [PATCH 9/9] Update server/src/main/java/com/cloud/vm/UserVmManagerImpl.java --- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 9dbc1a5c4b89..f44f2897f06f 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -4603,7 +4603,7 @@ private void orchestrateVirtualMachineCreate(UserVmVO vm, GuestOSCategoryVO gues } catch (CloudRuntimeException cre) { ArrayList epoList = cre.getIdProxyList(); if (epoList == null || !epoList.stream().anyMatch(e -> e.getUuid().equals(vm.getUuid()))) { - cre.addProxyObject(vm.getUuid(), "vmId"); + cre.addProxyObject(vm.getUuid(), ApiConstants.VIRTUAL_MACHINE_ID); } throw cre;