use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.
the class VcenterApiClient method createOrUpdateCluster.
private String createOrUpdateCluster(String datacenterName, String clusterNameOrMoRef) throws VcenterSystemException, VcenterObjectNotFoundException {
try {
_log.info("Request to create or update cluster " + clusterNameOrMoRef + " in datacenter " + datacenterName);
Map<String, ManagedEntity> managedEntityMap = createManagedEntityMap(datacenterName, null, null, false);
// Ensure datacenter exists
Datacenter datacenter = (Datacenter) managedEntityMap.get("Datacenter");
ClusterComputeResource clusterComputeResource = null;
try {
clusterComputeResource = searchClusterComputeResource(datacenterName, clusterNameOrMoRef);
_log.info("Cluster " + clusterNameOrMoRef + " already exists so no work to do");
} catch (VcenterObjectNotFoundException e) {
_log.info("Cluster " + clusterNameOrMoRef + " does not exist and will be created");
ClusterConfigSpecEx clusterConfigSpecEx = clusterConfigurer.configure(propertyInfo);
clusterComputeResource = datacenter.getHostFolder().createClusterEx(clusterNameOrMoRef, clusterConfigSpecEx);
_log.info("Cluster " + clusterNameOrMoRef + " created with key " + clusterComputeResource.getMOR().getVal());
}
return clusterComputeResource.getMOR().getVal();
} catch (VcenterSystemException | VcenterObjectNotFoundException e) {
throw e;
} catch (Exception e) {
_log.error("Exception creating cluster: " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.
the class VcenterApiClient method removeCluster.
public void removeCluster(String datacenterName, String clusterNameOrMoRef) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
try {
_log.info("Request to remove cluster in datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
try {
ClusterComputeResource clusterComputeResource = (ClusterComputeResource) createManagedEntityMap(datacenterName, clusterNameOrMoRef, null, false).get("ClusterComputeResource");
String clusterName = clusterComputeResource.getName();
_log.info("Attempt to delete cluster " + clusterName);
// Remove
Integer clusterOperationTimeout = Integer.parseInt(propertyInfo.getProperty("vcenter_operation_timeout"));
VcenterTaskMonitor taskMonitor = new VcenterTaskMonitor(clusterOperationTimeout);
Task deleteClusterTask = clusterComputeResource.destroy_Task();
// call blocks
VcenterTaskMonitor.TaskStatus taskStatus = taskMonitor.monitor(deleteClusterTask);
if (taskStatus == VcenterTaskMonitor.TaskStatus.SUCCESS) {
_log.info("Delete cluster " + clusterName + " task succeeded");
} else if (taskStatus == VcenterTaskMonitor.TaskStatus.ERROR) {
String errorMessage = "Delete cluster " + clusterName + " task failed - " + taskMonitor.errorDescription;
_log.error(errorMessage);
throw new VcenterSystemException(errorMessage);
} else if (taskStatus == VcenterTaskMonitor.TaskStatus.TIMED_OUT) {
_log.error("Delete cluster " + clusterName + " task timed out at " + taskMonitor.progressPercent);
throw new VcenterSystemException("Delete cluster " + clusterName + " task timed out at " + taskMonitor.progressPercent);
} else {
// Should not execute - Just here in case someone ever added a new state so we catch it
_log.error("Unknown task status encountered tracking delete cluster " + taskStatus);
throw new VcenterSystemException("Unknown task status encountered tracking delete cluster " + taskStatus);
}
} catch (VcenterObjectNotFoundException e) {
_log.info("Cluster not found thus no delete necessary");
}
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("Exception removing cluster: " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.
the class VcenterApiClient method checkHostConnectedPoweredOn.
public void checkHostConnectedPoweredOn(String datacenterName, String clusterNameOrMoRef, String hostname) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
try {
_log.info("Request to check connected and powered on for host " + hostname + " in datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get(// checkHostConnectedPoweredOn is performed in this call
"HostSystem");
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("checkHostConnectedPoweredOn exception " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.
the class VcenterApiClient method searchClusterComputeResource.
private ClusterComputeResource searchClusterComputeResource(String datacenterName, String clusterNameOrMoRef) throws VcenterSystemException, VcenterObjectNotFoundException {
if (serviceInstance == null) {
_log.error("Invoke setup to open connection before using client");
throw new VcenterSystemException("Invoke setup to open connection before using client");
}
try {
// MoRef search first
_log.info("Search cluster by MoRef " + clusterNameOrMoRef);
ManagedEntity[] clusterComputeResources = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("ClusterComputeResource");
for (ManagedEntity managedEntity : clusterComputeResources) {
if (managedEntity.getMOR().getVal().equals(clusterNameOrMoRef)) {
_log.info("Found cluster " + managedEntity.getName() + " by MoRef " + clusterNameOrMoRef);
return (ClusterComputeResource) managedEntity;
}
}
// Then name
_log.info("Search cluster by name " + clusterNameOrMoRef + " in datacenter " + datacenterName);
Datacenter datacenter = (Datacenter) new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntity("Datacenter", datacenterName);
if (datacenter == null) {
_log.error("Datacenter " + datacenterName + " does not exist");
throw new VcenterObjectNotFoundException("Datacenter " + datacenterName + " does not exist");
}
ClusterComputeResource clusterComputeResource = (ClusterComputeResource) new InventoryNavigator(datacenter).searchManagedEntity("ClusterComputeResource", clusterNameOrMoRef);
if (clusterComputeResource == null) {
_log.error("Cluster " + clusterNameOrMoRef + " does not exist");
throw new VcenterObjectNotFoundException("Cluster " + clusterNameOrMoRef + " does not exist");
}
return clusterComputeResource;
} catch (VcenterObjectNotFoundException e) {
throw e;
} catch (Exception e) {
_log.error("searchClusterComputeResources exception " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException in project coprhd-controller by CoprHD.
the class VcenterApiClient method getVirtualMachines.
private List<VirtualMachine> getVirtualMachines(ClusterComputeResource clusterComputeResource, boolean runningOnly) throws VcenterSystemException {
try {
List<VirtualMachine> virtualMachines = new ArrayList<VirtualMachine>();
String clusterName = clusterComputeResource.getName();
_log.info("Inspect cluster " + clusterName + " for virtual machines running only " + runningOnly);
ResourcePool resourcePool = clusterComputeResource.getResourcePool();
if (resourcePool != null) {
_log.info("Inspect resource pool " + resourcePool.getName() + " for virtual machines");
if (resourcePool.getVMs() != null) {
for (VirtualMachine virtualMachine : resourcePool.getVMs()) {
_log.info("Found virtual machine " + virtualMachine.getName() + " in resource pool " + resourcePool.getName());
_log.info(toDetails(virtualMachine));
if (runningOnly) {
// Anything !poweredOff (poweredOn and suspended) will be considered running
if (!virtualMachine.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOff)) {
virtualMachines.add(virtualMachine);
}
} else {
virtualMachines.add(virtualMachine);
}
}
}
}
_log.info("Cluster " + clusterName + " has " + virtualMachines.size() + " virtual machines");
return virtualMachines;
} catch (Exception e) {
_log.error("getVirtualMachines clusterComputeResource exception " + e);
throw new VcenterSystemException("Error checking cluster for virtual machines");
}
}
Aggregations