Search in sources :

Example 21 with VcenterObjectNotFoundException

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

the class ComputeDeviceControllerImpl method removeHostFromVcenterCluster.

/**
 * This will attempt to remove host from vCenter cluster.
 *
 * @param hostId
 * @param stepId
 */
public void removeHostFromVcenterCluster(URI hostId, String stepId) {
    log.info("removeHostFromVcenterCluster {}", hostId);
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
            log.info("datacenter is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        if (NullColumnValueGetter.isNullURI(host.getCluster())) {
            log.warn("cluster is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_068);
        String taskId = stepId;
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
        _dbClient.createTaskOpStatus(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId, op);
        AsyncTask task = new AsyncTask(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId);
        final String workflowKey = "updateVcenterCluster";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
            vcenterController.updateVcenterCluster(task, host.getCluster(), null, new URI[] { host.getId() }, null);
            // Mark this workflow as created/executed so we don't do it
            // again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
        }
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
        if (e.getCause() instanceof VcenterObjectNotFoundException) {
            log.info("did not find the host, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else if (e.getCause() instanceof VcenterObjectConnectionException) {
            log.info("host is not connected, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            log.error("failure " + e);
            WorkflowStepCompleter.stepFailed(stepId, e);
        }
    } catch (InternalException e) {
        log.error("InternalException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception: " + e.getMessage(), e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveHostVcenterCluster(host != null ? host.getHostName() : hostId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 22 with VcenterObjectNotFoundException

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

the class ComputeDeviceControllerImpl method putHostInMaintenanceMode.

/**
 * This will attempt to put host into maintenance mode on a Vcenter.
 *
 * @param hostId
 * @param stepId
 */
public void putHostInMaintenanceMode(URI hostId, String stepId) {
    log.info("putHostInMaintenanceMode {}", hostId);
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
            log.info("datacenter is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        if (NullColumnValueGetter.isNullURI(host.getCluster())) {
            log.warn("cluster is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        vcenterController.enterMaintenanceMode(host.getVcenterDataCenter(), host.getCluster(), host.getId());
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to putHostInMaintenanceMode: " + e.getMessage(), e);
        if (e.getCause() instanceof VcenterObjectNotFoundException) {
            if (checkPreviouslyFailedDecommission(host)) {
                log.info("did not find the host, considering success based on previous delete host operation");
                WorkflowStepCompleter.stepSucceded(stepId);
            } else {
                log.info("did not find the host, considering failure as no previous delete host operation found");
                WorkflowStepCompleter.stepFailed(stepId, e);
            }
        } else if (e.getCause() instanceof VcenterObjectConnectionException) {
            if (checkPreviouslyFailedDecommission(host)) {
                log.info("host is not connected, considering success based on previous delete host operation");
                WorkflowStepCompleter.stepSucceded(stepId);
            } else {
                log.info("host is not connected, considering failure as no previous delete host operation found");
                WorkflowStepCompleter.stepFailed(stepId, e);
            }
        } else {
            log.error("failure " + e);
            WorkflowStepCompleter.stepFailed(stepId, e);
        }
    } catch (InternalException e) {
        log.error("InternalException when trying to putHostInMaintenanceMode: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception" + e.getMessage(), e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToPutHostInMaintenanceMode(host != null ? host.getHostName() : hostId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 23 with VcenterObjectNotFoundException

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

the class ComputeDeviceControllerImpl method checkClusterVms.

/**
 * Checks if the cluster in Vcenter has VMs. Exception is thrown if VMs are
 * present.
 *
 * @param clusterId
 * @param datacenterId
 * @param stepId
 */
// TODO COP-28962 verify whether this really throws an exception
// seems like we throw an exception, and catch it again, and throw another exception
// logic is somewhat difficult to understand
public void checkClusterVms(URI clusterId, URI datacenterId, String stepId) {
    log.info("checkClusterVms {} {}", clusterId, datacenterId);
    Cluster cluster = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        cluster = _dbClient.queryObject(Cluster.class, clusterId);
        List<String> vmList = vcenterController.getVirtualMachines(datacenterId, clusterId);
        if (!vmList.isEmpty()) {
            log.error("there are {} VMs in the cluster", vmList.size());
            throw ComputeSystemControllerException.exceptions.clusterHasVms(cluster != null ? cluster.getLabel() : clusterId.toString());
        } else {
            log.info("there are no VMs in the cluster, step successful");
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to checkClusterVms: " + e.getMessage(), e);
        if (e.getCause() instanceof VcenterObjectNotFoundException) {
            log.info("did not find the datacenter or cluster, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            log.error("failure " + e);
            WorkflowStepCompleter.stepFailed(stepId, e);
        }
    } catch (InternalException e) {
        log.error("InternalException when trying to checkClusterVms: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception " + e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToCheckClusterVms(cluster != null ? cluster.getLabel() : clusterId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Cluster(com.emc.storageos.db.client.model.Cluster) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

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