Search in sources :

Example 11 with VcenterObjectNotFoundException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method exitMaintenanceMode.

@Override
public void exitMaintenanceMode(URI datacenterUri, URI clusterUri, URI hostUri) throws InternalException {
    VcenterApiClient vcenterApiClient = null;
    try {
        Host host = _dbClient.queryObject(Host.class, hostUri);
        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 exit maintenance mode for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel() + "/" + host.getHostName());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        vcenterApiClient.exitMaintenanceMode(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
    } 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("exitMaintenanceMode exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 12 with VcenterObjectNotFoundException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method getVirtualMachines.

private List<String> getVirtualMachines(URI datacenterUri, URI clusterUri, boolean runningOnly) 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 get virtual machines for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        return runningOnly ? vcenterApiClient.getRunningVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId()) : vcenterApiClient.getVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId());
    } 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("getVirtualMachines exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 13 with VcenterObjectNotFoundException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method checkVMsOnHostBootVolume.

@Override
public boolean checkVMsOnHostBootVolume(URI datacenterUri, URI clusterUri, URI hostId, URI bootVolumeId) {
    VcenterApiClient vcenterApiClient = null;
    boolean isVMsPresent = false;
    try {
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        Host host = _dbClient.queryObject(Host.class, hostId);
        Volume volume = _dbClient.queryObject(Volume.class, bootVolumeId);
        _log.info("Request to check VMs on boot volume {} of host {}", volume.getLabel() + " - " + bootVolumeId, host.getLabel());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        isVMsPresent = vcenterApiClient.checkVMsOnHostVolume(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), volume.getWWN());
    } 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("checkVMsOnHostBootVolume exception ", e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
    return isVMsPresent;
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Volume(com.emc.storageos.db.client.model.Volume) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 14 with VcenterObjectNotFoundException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method createUpdateVcenterClusterOperation.

public void createUpdateVcenterClusterOperation(boolean createCluster, URI vcenterId, URI vcenterDataCenterId, URI clusterId, 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);
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        String vcenterClusterId = null;
        if (createCluster) {
            _log.info("Create cluster with name " + cluster.getLabel());
            vcenterClusterId = vcenterApiClient.createCluster(vcenterDataCenter.getLabel(), cluster.getLabel());
        } else {
            // Use MoRef if present but don't stop if we fail to find cluster based off this because we'll fall back and try on name
            String externalId = cluster.getExternalId();
            if (externalId != null && !externalId.trim().equals("")) {
                _log.info("Update cluster with MoRef " + externalId);
                try {
                    vcenterClusterId = vcenterApiClient.updateCluster(vcenterDataCenter.getLabel(), externalId);
                } catch (VcenterObjectNotFoundException e) {
                    _log.info("Ignore VcenterObjectNotFoundException updateCluster when using MoRef... Try name based search next");
                }
            }
            if (vcenterClusterId == null) {
                _log.info("Update cluster with name " + cluster.getLabel());
                vcenterClusterId = vcenterApiClient.updateCluster(vcenterDataCenter.getLabel(), cluster.getLabel());
            }
        }
        _log.info("Successfully created or updated cluster " + cluster.getLabel() + " " + vcenterClusterId);
        cluster.setVcenterDataCenter(vcenterDataCenter.getId());
        cluster.setExternalId(vcenterClusterId);
        _dbClient.updateAndReindexObject(cluster);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("createUpdateVcenterClusterOperation exception " + e);
        WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.clusterException(e.getLocalizedMessage(), e));
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 15 with VcenterObjectNotFoundException

use of com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException in project coprhd-controller by CoprHD.

the class VcenterApiClient method exitMaintenanceMode.

public void exitMaintenanceMode(String datacenterName, String clusterNameOrMoRef, String hostname) throws VcenterSystemException, VcenterObjectNotFoundException, VcenterObjectConnectionException {
    try {
        _log.info("Request to exit maintenance mode for host " + hostname + " in datacenter " + datacenterName + " cluster " + clusterNameOrMoRef);
        exitMaintenanceModeHost((HostSystem) createManagedEntityMap(datacenterName, clusterNameOrMoRef, hostname, true).get("HostSystem"));
    } catch (VcenterSystemException | VcenterObjectNotFoundException | VcenterObjectConnectionException e) {
        throw e;
    } catch (Exception e) {
        _log.error("exitMaintenanceMode 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)

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