use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException 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.VcenterObjectNotFoundException 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.VcenterObjectNotFoundException 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.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.
the class VcenterApiClient method createDatastore.
public String createDatastore(String datacenterName, String clusterNameOrMoRef, String hostname, String volumeUuid, String datastoreName) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
try {
_log.info("Request to create datastore on volume " + volumeUuid + " host " + hostname + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get("HostSystem");
if (volumeUuid == null || volumeUuid.trim().equals("")) {
_log.error("Volume UUID not specified");
throw new VcenterSystemException("Volume UUID not specified");
}
Datastore[] datastores = hostSystem.getDatastores();
if (datastores != null && datastores.length > 0) {
_log.info("Check host " + hostname + " for existing datastore on volume " + volumeUuid);
String specifiedVolumeDevicePath = null;
HostStorageSystem hostStorageSystem = hostSystem.getHostStorageSystem();
HostStorageDeviceInfo hostStorageDeviceInfo = hostStorageSystem.getStorageDeviceInfo();
ScsiLun[] hostScsiLuns = hostStorageDeviceInfo.getScsiLun();
for (ScsiLun scsiLun : hostScsiLuns) {
if (scsiLun instanceof HostScsiDisk) {
HostScsiDisk hostScsiDisk = (HostScsiDisk) scsiLun;
if (hostScsiDisk.getUuid().toLowerCase().contains(volumeUuid.toLowerCase())) {
_log.info("Found disk " + hostScsiDisk.getUuid() + " on " + hostname + " for volume UUID " + volumeUuid);
specifiedVolumeDevicePath = hostScsiDisk.getDevicePath();
break;
}
}
}
// datastore already exists.
if (specifiedVolumeDevicePath != null) {
for (Datastore datastore : datastores) {
if (datastore.getInfo() instanceof VmfsDatastoreInfo) {
VmfsDatastoreInfo vmfsDatastoreInfo = (VmfsDatastoreInfo) datastore.getInfo();
_log.info("Found datastore " + vmfsDatastoreInfo.getName() + " " + vmfsDatastoreInfo.getVmfs().getUuid());
String diskName = vmfsDatastoreInfo.getVmfs().getExtent()[0].getDiskName();
_log.info("Found datastore " + vmfsDatastoreInfo.getName() + " on disk " + diskName);
String devicePath = "/vmfs/devices/disks/" + diskName;
if (devicePath.equalsIgnoreCase(specifiedVolumeDevicePath)) {
_log.info("Datastore " + vmfsDatastoreInfo.getName() + " " + devicePath + " " + datastore.getMOR().getVal() + " already present");
return datastore.getMOR().getVal();
}
}
}
}
}
_log.info("Search for candidate disk via host " + hostname);
HostDatastoreSystem hostDatastoreSystem = hostSystem.getHostDatastoreSystem();
HostScsiDisk[] hostScsiDisks = hostDatastoreSystem.queryAvailableDisksForVmfs(null);
HostScsiDisk candidateHostScsiDisk = null;
for (HostScsiDisk hostScsiDisk : hostScsiDisks) {
_log.info("Found disk " + hostScsiDisk.getDevicePath() + " " + hostScsiDisk.getUuid());
if (hostScsiDisk.getUuid().toLowerCase().contains(volumeUuid.toLowerCase())) {
candidateHostScsiDisk = hostScsiDisk;
break;
}
}
if (candidateHostScsiDisk == null) {
_log.error("Disk " + volumeUuid + " not found - Ensure underlying storage properly configured and disk accessible to host");
throw new VcenterSystemException("Disk " + volumeUuid + " not found - Ensure underlying storage properly configured and disk accessible to host");
}
String devicePath = candidateHostScsiDisk.getDevicePath();
_log.info("Create datastore via host " + hostname + " on disk " + devicePath);
VmfsDatastoreOption[] vmfsDatastoreOption = hostDatastoreSystem.queryVmfsDatastoreCreateOptions(devicePath);
VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption[0].getSpec();
vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
// TODO externalize
vmfsDatastoreCreateSpec.getVmfs().setBlockSizeMb(1);
Datastore datastore = null;
try {
datastore = hostDatastoreSystem.createVmfsDatastore(vmfsDatastoreCreateSpec);
} catch (HostConfigFault hcf) {
_log.info("HostConfigFault creating datastore on disk " + devicePath + " thus retry");
if (hcf.getFaultMessage() != null && hcf.getFaultMessage().length > 0 && hcf.getFaultMessage()[0] != null) {
String errorMessage = hcf.getFaultMessage()[0].toString();
_log.error("HostConfigFault details are " + errorMessage);
}
datastore = hostDatastoreSystem.createVmfsDatastore(vmfsDatastoreCreateSpec);
}
if (datastore == null) {
// Should not happen
_log.error("Datastore null after create");
throw new VcenterSystemException("Error creating datastore");
}
return datastore.getMOR().getVal();
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("Exception creating datastore: " + e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.
the class VcenterControllerImpl method removeVcenterCluster.
@Override
public void removeVcenterCluster(URI datacenterUri, URI clusterUri) throws InternalException {
VcenterApiClient vcenterApiClient = null;
try {
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
_log.info("Request to remove cluster " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
vcenterApiClient.removeCluster(vcenterDataCenter.getLabel(), cluster.getExternalId());
} catch (VcenterObjectConnectionException e) {
throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
} catch (VcenterObjectNotFoundException e) {
throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
} catch (VcenterServerConnectionException e) {
throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
} catch (Exception e) {
_log.error("removeVcenterCluster exception " + e);
throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
} finally {
if (vcenterApiClient != null) {
vcenterApiClient.destroy();
}
}
}
Aggregations