weizhouapache commented on code in PR #8484:
URL: https://github.com/apache/cloudstack/pull/8484#discussion_r1481004842


##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4560,22 +4600,20 @@ private UserVmVO commitUserVm(final boolean isImport, 
final DataCenter zone, fin
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Successfully allocated DB entry for " + vm);
             }
-        }
-        CallContext.current().setEventDetails("Vm Id: " + vm.getUuid());
+        } catch (CloudRuntimeException cre) {
+            ArrayList<ExceptionProxyObject> epoList = cre.getIdProxyList();
+            if (epoList == null || !epoList.stream().anyMatch(e -> 
e.getUuid().equals(vm.getUuid()))) {
+                cre.addProxyObject(vm.getUuid(), "vmId");

Review Comment:
   same as above
   would be good to use `ApiConstants.VIRTUAL_MACHINE_ID` instead of `"vmid"`



##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4547,6 +4550,43 @@ 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,
+                    diskOfferingId, diskSize, offering, isIso,networkNicMap, 
hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap,
+                    rootDiskOfferingId);
+
+        }
+        CallContext.current().setEventDetails("Vm Id: " + vm.getUuid());
+
+        if (!isImport) {
+            if (!offering.isDynamic()) {
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, 
accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), 
template.getId(),
+                        hypervisorType.toString(), 
VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
+            } else {
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, 
accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), 
template.getId(),
+                        hypervisorType.toString(), 
VirtualMachine.class.getName(), vm.getUuid(), customParameters, 
vm.isDisplayVm());
+            }
+
+            try {
+                //Update Resource Count for the given account
+                resourceCountIncrement(accountId, isDisplayVm, new 
Long(offering.getCpu()), new Long(offering.getRamSize()));
+            } catch (CloudRuntimeException cre) {
+                ArrayList<ExceptionProxyObject> epoList =  
cre.getIdProxyList();
+                if (epoList == null || !epoList.stream().anyMatch( e -> 
e.getUuid().equals(vm.getUuid()))) {
+                    cre.addProxyObject(vm.getUuid(), "vmId");
+                }
+                throw cre;
+            }
+        }
+        return vm;
+    }
+
+    private void OrchestrateVirtualMachineCreate(UserVmVO vm, 
GuestOSCategoryVO guestOSCategory, List<String> computeTags, List<String> 
rootDiskTags, DataCenterDeployment plan, Long rootDiskSize, 
VirtualMachineTemplate template, String hostName, String displayName, Account 
owner,

Review Comment:
   the method should start with a lowercase letter.



##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4476,7 +4477,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;

Review Comment:
   this could be optimized to a line
   
   `return new InvalidParameterValueException("Unable to look up template by id 
" + template.getId()).add(VirtualMachine.class, vm.getUuid())`



##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -4547,6 +4550,43 @@ 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,
+                    diskOfferingId, diskSize, offering, isIso,networkNicMap, 
hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap,
+                    rootDiskOfferingId);
+
+        }
+        CallContext.current().setEventDetails("Vm Id: " + vm.getUuid());
+
+        if (!isImport) {
+            if (!offering.isDynamic()) {
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, 
accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), 
template.getId(),
+                        hypervisorType.toString(), 
VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
+            } else {
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, 
accountId, zone.getId(), vm.getId(), vm.getHostName(), offering.getId(), 
template.getId(),
+                        hypervisorType.toString(), 
VirtualMachine.class.getName(), vm.getUuid(), customParameters, 
vm.isDisplayVm());
+            }
+
+            try {
+                //Update Resource Count for the given account
+                resourceCountIncrement(accountId, isDisplayVm, new 
Long(offering.getCpu()), new Long(offering.getRamSize()));
+            } catch (CloudRuntimeException cre) {
+                ArrayList<ExceptionProxyObject> epoList =  
cre.getIdProxyList();
+                if (epoList == null || !epoList.stream().anyMatch( e -> 
e.getUuid().equals(vm.getUuid()))) {
+                    cre.addProxyObject(vm.getUuid(), "vmId");

Review Comment:
   would be good to use `ApiConstants.VIRTUAL_MACHINE_ID` instead of `"vmid"`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to