51
51
import javax .xml .parsers .DocumentBuilder ;
52
52
import javax .xml .parsers .ParserConfigurationException ;
53
53
54
+ import com .cloud .utils .exception .ExceptionProxyObject ;
54
55
import org .apache .cloudstack .acl .ControlledEntity ;
55
56
import org .apache .cloudstack .acl .ControlledEntity .ACLType ;
56
57
import org .apache .cloudstack .acl .SecurityChecker .AccessType ;
@@ -4474,7 +4475,9 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin
4474
4475
4475
4476
VMTemplateVO templateVO = _templateDao .findById (template .getId ());
4476
4477
if (templateVO == null ) {
4477
- throw new InvalidParameterValueException ("Unable to look up template by id " + template .getId ());
4478
+ InvalidParameterValueException ipve = new InvalidParameterValueException ("Unable to look up template by id " + template .getId ());
4479
+ ipve .add (VirtualMachine .class , vm .getUuid ());
4480
+ throw ipve ;
4478
4481
}
4479
4482
4480
4483
validateRootDiskResize (hypervisorType , rootDiskSize , templateVO , vm , customParameters );
@@ -4545,6 +4548,43 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin
4545
4548
DiskOfferingVO rootDiskOfferingVO = _diskOfferingDao .findById (rootDiskOfferingId );
4546
4549
rootDiskTags .add (rootDiskOfferingVO .getTags ());
4547
4550
4551
+ orchestrateVirtualMachineCreate (vm , guestOSCategory , computeTags , rootDiskTags , plan , rootDiskSize , template , hostName , displayName , owner ,
4552
+ diskOfferingId , diskSize , offering , isIso ,networkNicMap , hypervisorType , extraDhcpOptionMap , dataDiskTemplateToDiskOfferingMap ,
4553
+ rootDiskOfferingId );
4554
+
4555
+ }
4556
+ CallContext .current ().setEventDetails ("Vm Id: " + vm .getUuid ());
4557
+
4558
+ if (!isImport ) {
4559
+ if (!offering .isDynamic ()) {
4560
+ UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_CREATE , accountId , zone .getId (), vm .getId (), vm .getHostName (), offering .getId (), template .getId (),
4561
+ hypervisorType .toString (), VirtualMachine .class .getName (), vm .getUuid (), vm .isDisplayVm ());
4562
+ } else {
4563
+ UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_CREATE , accountId , zone .getId (), vm .getId (), vm .getHostName (), offering .getId (), template .getId (),
4564
+ hypervisorType .toString (), VirtualMachine .class .getName (), vm .getUuid (), customParameters , vm .isDisplayVm ());
4565
+ }
4566
+
4567
+ try {
4568
+ //Update Resource Count for the given account
4569
+ resourceCountIncrement (accountId , isDisplayVm , new Long (offering .getCpu ()), new Long (offering .getRamSize ()));
4570
+ } catch (CloudRuntimeException cre ) {
4571
+ ArrayList <ExceptionProxyObject > epoList = cre .getIdProxyList ();
4572
+ if (epoList == null || !epoList .stream ().anyMatch ( e -> e .getUuid ().equals (vm .getUuid ()))) {
4573
+ cre .addProxyObject (vm .getUuid (), ApiConstants .VIRTUAL_MACHINE_ID );
4574
+ }
4575
+ throw cre ;
4576
+ }
4577
+ }
4578
+ return vm ;
4579
+ }
4580
+
4581
+ 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 ,
4582
+ Long diskOfferingId , Long diskSize ,
4583
+ ServiceOffering offering , boolean isIso , LinkedHashMap <String , List <NicProfile >> networkNicMap ,
4584
+ HypervisorType hypervisorType ,
4585
+ Map <String , Map <Integer , String >> extraDhcpOptionMap , Map <Long , DiskOffering > dataDiskTemplateToDiskOfferingMap ,
4586
+ Long rootDiskOfferingId ) throws InsufficientCapacityException {
4587
+ try {
4548
4588
if (isIso ) {
4549
4589
_orchSrvc .createVirtualMachineFromScratch (vm .getUuid (), Long .toString (owner .getAccountId ()), vm .getIsoId ().toString (), hostName , displayName ,
4550
4590
hypervisorType .name (), guestOSCategory .getName (), offering .getCpu (), offering .getSpeed (), offering .getRamSize (), diskSize , computeTags , rootDiskTags ,
@@ -4558,22 +4598,20 @@ private UserVmVO commitUserVm(final boolean isImport, final DataCenter zone, fin
4558
4598
if (logger .isDebugEnabled ()) {
4559
4599
logger .debug ("Successfully allocated DB entry for " + vm );
4560
4600
}
4561
- }
4562
- CallContext .current ().setEventDetails ("Vm Id: " + vm .getUuid ());
4601
+ } catch (CloudRuntimeException cre ) {
4602
+ ArrayList <ExceptionProxyObject > epoList = cre .getIdProxyList ();
4603
+ if (epoList == null || !epoList .stream ().anyMatch (e -> e .getUuid ().equals (vm .getUuid ()))) {
4604
+ cre .addProxyObject (vm .getUuid (), ApiConstants .VIRTUAL_MACHINE_ID );
4563
4605
4564
- if (!isImport ) {
4565
- if (!offering .isDynamic ()) {
4566
- UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_CREATE , accountId , zone .getId (), vm .getId (), vm .getHostName (), offering .getId (), template .getId (),
4567
- hypervisorType .toString (), VirtualMachine .class .getName (), vm .getUuid (), vm .isDisplayVm ());
4568
- } else {
4569
- UsageEventUtils .publishUsageEvent (EventTypes .EVENT_VM_CREATE , accountId , zone .getId (), vm .getId (), vm .getHostName (), offering .getId (), template .getId (),
4570
- hypervisorType .toString (), VirtualMachine .class .getName (), vm .getUuid (), customParameters , vm .isDisplayVm ());
4571
4606
}
4572
-
4573
- //Update Resource Count for the given account
4574
- resourceCountIncrement (accountId , isDisplayVm , new Long (offering .getCpu ()), new Long (offering .getRamSize ()));
4607
+ throw cre ;
4608
+ } catch (InsufficientCapacityException ice ) {
4609
+ ArrayList idList = ice .getIdProxyList ();
4610
+ if (idList == null || !idList .stream ().anyMatch (i -> i .equals (vm .getUuid ()))) {
4611
+ ice .addProxyObject (vm .getUuid ());
4612
+ }
4613
+ throw ice ;
4575
4614
}
4576
- return vm ;
4577
4615
}
4578
4616
4579
4617
protected void setVmRequiredFieldsForImport (boolean isImport , UserVmVO vm , DataCenter zone , HypervisorType hypervisorType ,
0 commit comments