Search in sources :

Example 1 with VcenterObjectNotFoundException

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());
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HashMap(java.util.HashMap) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) InventoryNavigator(com.vmware.vim25.mo.InventoryNavigator) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) Datacenter(com.vmware.vim25.mo.Datacenter) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Example 2 with VcenterObjectNotFoundException

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;
}
Also used : VmfsDatastoreInfo(com.vmware.vim25.VmfsDatastoreInfo) ScsiLun(com.vmware.vim25.ScsiLun) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) HostStorageSystem(com.vmware.vim25.mo.HostStorageSystem) HostStorageDeviceInfo(com.vmware.vim25.HostStorageDeviceInfo) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) HostScsiDisk(com.vmware.vim25.HostScsiDisk) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)

Example 3 with VcenterObjectNotFoundException

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());
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)

Example 4 with VcenterObjectNotFoundException

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());
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)

Example 5 with VcenterObjectNotFoundException

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());
    }
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) Datacenter(com.vmware.vim25.mo.Datacenter) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ClusterConfigSpecEx(com.vmware.vim25.ClusterConfigSpecEx)

Aggregations

VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)23 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)23 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)19 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)13 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)10 Cluster (com.emc.storageos.db.client.model.Cluster)8 ClusterComputeResource (com.vmware.vim25.mo.ClusterComputeResource)7 HostSystem (com.vmware.vim25.mo.HostSystem)7 Vcenter (com.emc.storageos.db.client.model.Vcenter)6 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)6 Host (com.emc.storageos.db.client.model.Host)5 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)4 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)4 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)4 Datacenter (com.vmware.vim25.mo.Datacenter)3 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)3 Task (com.vmware.vim25.mo.Task)3