use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.
the class VcenterApiClient method createManagedEntityMap.
/*
* Provide names of the vCenter elements and method will locate the MangedEntity representation
* Each search is done within context of previous entity thus there is a dependency
* Cluster
* Datacenter
* Host
* Parameters are optional (ie, leave host null to only search datacenter and cluster)
* Must provide parent element name or child will not be searched
* hostConnectedPoweredOn ensures host is operational and ready for calls
*/
private Map<String, ManagedEntity> createManagedEntityMap(String datacenterName, String clusterNameOrMoRef, String hostname, boolean hostConnectedPoweredOn) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
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 {
Map<String, ManagedEntity> vcenterManagedEntityMap = new HashMap<String, ManagedEntity>();
if (datacenterName != null && !datacenterName.trim().equals("")) {
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");
}
vcenterManagedEntityMap.put("Datacenter", datacenter);
if (clusterNameOrMoRef != null && !clusterNameOrMoRef.trim().equals("")) {
ClusterComputeResource clusterComputeResource = searchClusterComputeResource(datacenterName, clusterNameOrMoRef);
vcenterManagedEntityMap.put("ClusterComputeResource", clusterComputeResource);
if (hostname != null && !hostname.trim().equals("")) {
HostSystem hostSystem = findByHostname(clusterComputeResource, hostname);
if (hostSystem == null) {
_log.error("Host " + hostname + " does not exist");
throw new VcenterObjectNotFoundException("Host " + hostname + " does not exist");
}
if (hostConnectedPoweredOn) {
checkHostConnectedPoweredOn(hostSystem);
}
vcenterManagedEntityMap.put("HostSystem", hostSystem);
}
}
}
return vcenterManagedEntityMap;
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("getVcenterObjects 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 checkVMsOnHostVolume.
/**
* Verifies if the host can see the volume, if so then check for VMs (powered on/off)
* on the datastore identified for the given volume wwn.
*
* @param datacenterName {@link String} name of the dataCenter
* @param clusterNameOrMoRef {@link String} name of the cluster
* @param hostName {@link String} name of the host
* @param volumewwn {@link String} volume wwn
* @return true when there are any VMs on the datastore identified by the volume wwn, otherwise false
* @throws VcenterSystemException
* @throws VcenterObjectNotFoundException
* @throws VcenterObjectConnectionException
*/
public boolean checkVMsOnHostVolume(String datacenterName, String clusterNameOrMoRef, String hostName, String volumewwn) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
boolean isVMsPresent = false;
try {
_log.info("Request to check VMs on volume " + volumewwn + " host " + hostName + " to datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
HostSystem hostSystem = (HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostName, false).get("HostSystem");
if (volumewwn == null || volumewwn.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("Found {} datastores for host {}", datastores.length, hostName);
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;
// Check if host is able to see the specified volume
if (hostScsiDisk.getUuid().toLowerCase().contains(volumewwn.toLowerCase())) {
_log.info("Found disk " + hostScsiDisk.getUuid() + " on " + hostName + " for volume UUID " + volumewwn);
specifiedVolumeDevicePath = hostScsiDisk.getDevicePath();
break;
}
}
}
if (specifiedVolumeDevicePath != null) {
Datastore bootVolDatastore = null;
for (Datastore datastore : datastores) {
_log.info("Find existing datastore on volume " + volumewwn + " for host " + hostName);
if (datastore.getInfo() instanceof VmfsDatastoreInfo) {
VmfsDatastoreInfo vmfsDatastoreInfo = (VmfsDatastoreInfo) datastore.getInfo();
String diskName = vmfsDatastoreInfo.getVmfs().getExtent()[0].getDiskName();
if (specifiedVolumeDevicePath.contains(diskName) && diskName.contains(volumewwn.toLowerCase())) {
_log.info("Found datastore " + vmfsDatastoreInfo.getName() + " on disk " + diskName);
bootVolDatastore = datastore;
break;
}
}
}
if (bootVolDatastore != null) {
if (CollectionUtils.isNotEmpty(Arrays.asList(bootVolDatastore.getVms()))) {
isVMsPresent = true;
_log.info("Found {} VMs on the datastore {}", bootVolDatastore.getVms().length, bootVolDatastore.getName());
} else {
_log.info("No VMs found on datastore {}", bootVolDatastore.getName());
}
} else {
_log.warn("Could not find datastore for host {} on volume wwn {}", hostName, volumewwn);
}
} else {
_log.warn("Could not find disk on host {} for volume UUID {}", hostName, volumewwn);
}
} else {
_log.info("No datastores found for host {}, hence inferring that no VMs are present on the given volume wwn {}", hostName, volumewwn);
}
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
_log.error("Vcenter exception checkVMsOnHostVolume : {}", e);
throw e;
} catch (Exception e) {
_log.error("Exception checkVMsOnHostVolume : {}", e);
throw new VcenterSystemException(e.getLocalizedMessage());
}
return isVMsPresent;
}
use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.
the class VcenterApiClient method createCluster.
public String createCluster(String datacenterName, String clusterNameOrMoRef) throws VcenterSystemException, VcenterObjectNotFoundException {
try {
// Ensures datacenter exists
createManagedEntityMap(datacenterName, null, null, false).get("Datacenter");
ClusterComputeResource clusterComputeResource = null;
try {
clusterComputeResource = searchClusterComputeResource(datacenterName, clusterNameOrMoRef);
} catch (VcenterObjectNotFoundException e) {
_log.info("Ignore VcenterObjectNotFoundException on cluster search since we are creating new cluster");
}
if (clusterComputeResource != null) {
_log.error("Cluster " + clusterNameOrMoRef + " already exists");
throw new VcenterSystemException("Cluster " + clusterNameOrMoRef + " already exists");
}
return createOrUpdateCluster(datacenterName, clusterNameOrMoRef);
} catch (VcenterSystemException | VcenterObjectNotFoundException e) {
throw e;
} catch (Exception e) {
_log.error("createCluster 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 enterMaintenanceMode.
public void enterMaintenanceMode(String datacenterName, String clusterNameOrMoRef, String hostname) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
try {
_log.info("Request to enter maintenance mode for host " + hostname + " in datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
enterMaintenanceModeHost((HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get("HostSystem"));
} catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
throw e;
} catch (Exception e) {
_log.error("enterMaintenanceMode 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 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());
}
}
Aggregations