@@ -245,8 +245,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
245245 }
246246
247247 _defaultSystemVmNicAdapterType = _configDao .getValue (Config .VmwareSystemVmNicDeviceType .key ());
248- if (_defaultSystemVmNicAdapterType == null )
248+ if (_defaultSystemVmNicAdapterType == null ) {
249249 _defaultSystemVmNicAdapterType = VirtualEthernetCardType .E1000 .toString ();
250+ }
250251
251252 _additionalPortRangeStart = NumbersUtil .parseInt (_configDao .getValue (Config .VmwareAdditionalVncPortRangeStart .key ()), 59000 );
252253 if (_additionalPortRangeStart > 65535 ) {
@@ -263,19 +264,23 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
263264 _routerExtraPublicNics = NumbersUtil .parseInt (_configDao .getValue (Config .RouterExtraPublicNics .key ()), 2 );
264265
265266 _reserveCpu = _configDao .getValue (Config .VmwareReserveCpu .key ());
266- if (_reserveCpu == null || _reserveCpu .isEmpty ())
267+ if (_reserveCpu == null || _reserveCpu .isEmpty ()) {
267268 _reserveCpu = "false" ;
269+ }
268270 _reserveMem = _configDao .getValue (Config .VmwareReserveMem .key ());
269- if (_reserveMem == null || _reserveMem .isEmpty ())
271+ if (_reserveMem == null || _reserveMem .isEmpty ()) {
270272 _reserveMem = "false" ;
273+ }
271274
272275 _recycleHungWorker = _configDao .getValue (Config .VmwareRecycleHungWorker .key ());
273- if (_recycleHungWorker == null || _recycleHungWorker .isEmpty ())
276+ if (_recycleHungWorker == null || _recycleHungWorker .isEmpty ()) {
274277 _recycleHungWorker = "false" ;
278+ }
275279
276280 _rootDiskController = _configDao .getValue (Config .VmwareRootDiskControllerType .key ());
277- if (_rootDiskController == null || _rootDiskController .isEmpty ())
281+ if (_rootDiskController == null || _rootDiskController .isEmpty ()) {
278282 _rootDiskController = DiskControllerType .ide .toString ();
283+ }
279284
280285 s_logger .info ("Additional VNC port allocation range is settled at " + _additionalPortRangeStart + " to " + (_additionalPortRangeStart + _additionalPortRangeSize ));
281286
@@ -359,8 +364,9 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep
359364 public List <ManagedObjectReference > addHostToPodCluster (VmwareContext serviceContext , long dcId , Long podId , Long clusterId ,
360365 String hostInventoryPath ) throws Exception {
361366 ManagedObjectReference mor = null ;
362- if (serviceContext != null )
367+ if (serviceContext != null ) {
363368 mor = serviceContext .getHostMorByPath (hostInventoryPath );
369+ }
364370 String privateTrafficLabel = null ;
365371 privateTrafficLabel = serviceContext .getStockObject ("privateTrafficLabel" );
366372 if (privateTrafficLabel == null ) {
@@ -459,11 +465,24 @@ private ManagedObjectReference addHostToVCenterCluster(VmwareContext serviceCont
459465 @ Override
460466 public String getSecondaryStorageStoreUrl (long dcId ) {
461467
468+ String secUrl = null ;
462469 DataStore secStore = _dataStoreMgr .getImageStore (dcId );
463- if (secStore != null )
464- return secStore .getUri ();
470+ if (secStore != null ) {
471+ secUrl = secStore .getUri ();
472+ }
465473
466- return null ;
474+ if (secUrl == null ) {
475+ // we are using non-NFS image store, then use cache storage instead
476+ s_logger .info ("Secondary storage is not NFS, we need to use cache storage" );
477+ DataStore cacheStore = _dataStoreMgr .getImageCacheStore (dcId );
478+ if (cacheStore != null ) {
479+ secUrl = cacheStore .getUri ();
480+ } else {
481+ s_logger .warn ("No cache storage is found when non-NFS secondary storage is used" );
482+ }
483+ }
484+
485+ return secUrl ;
467486 }
468487
469488 @ Override
@@ -478,8 +497,9 @@ public String getManagementPortGroupName() {
478497
479498 @ Override
480499 public String getManagementPortGroupByHost (HostMO hostMo ) throws Exception {
481- if (hostMo .getHostType () == VmwareHostType .ESXi )
500+ if (hostMo .getHostType () == VmwareHostType .ESXi ) {
482501 return _managemetPortGroupName ;
502+ }
483503 return _serviceConsoleName ;
484504 }
485505
@@ -530,7 +550,7 @@ public void prepareSecondaryStorageStore(String storageUrl) {
530550 _configServer .updateKeyPairs ();
531551
532552 s_logger .info ("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso .getAbsolutePath () +
533- ", destination: " + destIso .getAbsolutePath ());
553+ ", destination: " + destIso .getAbsolutePath ());
534554 try {
535555 FileUtil .copyfile (srcIso , destIso );
536556 } catch (IOException e ) {
@@ -541,8 +561,9 @@ public void prepareSecondaryStorageStore(String storageUrl) {
541561 throw new CloudRuntimeException (msg );
542562 }
543563 } else {
544- if (s_logger .isTraceEnabled ())
564+ if (s_logger .isTraceEnabled ()) {
545565 s_logger .trace ("SystemVM ISO file " + destIso .getPath () + " already exists" );
566+ }
546567 }
547568 } finally {
548569 lock .unlock ();
@@ -579,7 +600,7 @@ private File getSystemVMPatchIsoFile() {
579600
580601 assert (isoFile != null );
581602 if (!isoFile .exists ()) {
582- s_logger .error ("Unable to locate systemvm.iso in your setup at " + isoFile .toString ());
603+ s_logger .error ("Unable to locate systemvm.iso in your setup at " + isoFile .toString ());
583604 }
584605 return isoFile ;
585606 }
@@ -596,7 +617,7 @@ public File getSystemVMKeyFile() {
596617 }
597618 assert (keyFile != null );
598619 if (!keyFile .exists ()) {
599- s_logger .error ("Unable to locate id_rsa.cloud in your setup at " + keyFile .toString ());
620+ s_logger .error ("Unable to locate id_rsa.cloud in your setup at " + keyFile .toString ());
600621 }
601622 return keyFile ;
602623 }
@@ -957,11 +978,11 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc
957978 if (associatedVmwareDc .getVcenterHost ().equalsIgnoreCase (vCenterHost ) &&
958979 associatedVmwareDc .getVmwareDatacenterName ().equalsIgnoreCase (vmwareDcName )) {
959980 s_logger .info ("Ignoring API call addVmwareDc, because VMware DC " + vCenterHost + "/" + vmwareDcName +
960- " is already associated with specified zone with id " + zoneId );
981+ " is already associated with specified zone with id " + zoneId );
961982 return associatedVmwareDc ;
962983 } else {
963984 throw new CloudRuntimeException ("Zone " + zoneId + " is already associated with a VMware datacenter. " +
964- "Only 1 VMware DC can be associated with a zone." );
985+ "Only 1 VMware DC can be associated with a zone." );
965986 }
966987 }
967988 // Zone validation to check if the zone already has resources.
@@ -1051,8 +1072,9 @@ public VmwareDatacenterVO addVmwareDatacenter(AddVmwareDcCmd cmd) throws Resourc
10511072 }
10521073 throw new CloudRuntimeException (msg );
10531074 } finally {
1054- if (context != null )
1075+ if (context != null ) {
10551076 context .close ();
1077+ }
10561078 context = null ;
10571079 }
10581080 return vmwareDc ;
@@ -1129,8 +1151,9 @@ public boolean removeVmwareDatacenter(RemoveVmwareDcCmd cmd) throws ResourceInUs
11291151 s_logger .error (msg );
11301152 throw new CloudRuntimeException (msg );
11311153 } finally {
1132- if (context != null )
1154+ if (context != null ) {
11331155 context .close ();
1156+ }
11341157 context = null ;
11351158 }
11361159 return true ;
0 commit comments