// Find a host connected and powered on then refresh it public void vcenterClusterSelectHostOperation( URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI[] hostUris, String stepId) { VcenterApiClient vcenterApiClient = null; try { WorkflowStepCompleter.stepExecuting(stepId); VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId); Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId); Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId); Collection<Host> hosts = _dbClient.queryObject(Host.class, hostUris); vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo()); vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword()); Host hostForStorageOperations = null; for (Host host : hosts) { try { vcenterApiClient.checkHostConnectedPoweredOn( vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName()); hostForStorageOperations = host; _log.info("Host " + host.getHostName() + " to be used for storage operations"); break; } catch (Exception e) { _log.info( "Host " + host.getHostName() + " not valid for storage operations due to exception " + e.getLocalizedMessage()); } } if (hostForStorageOperations == null) { _log.error( "No host valid for performing storage operations thus cannot perform datastore operations"); throw new Exception( "No host valid for performing storage operations thus cannot perform datastore operations"); } vcenterApiClient.refreshRescanHostStorage( vcenterDataCenter.getLabel(), cluster.getExternalId(), hostForStorageOperations.getHostName()); // persist hostForStorageOperations ID in wf data _workflowService.storeStepData(stepId, hostForStorageOperations.getId()); WorkflowStepCompleter.stepSucceded(stepId); } catch (Exception e) { _log.error("vcenterClusterSelectHostOperation exception " + e); WorkflowStepCompleter.stepFailed( stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e)); } finally { if (vcenterApiClient != null) vcenterApiClient.destroy(); } }