Search in sources :

Example 41 with Cluster

use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method vcenterClusterAddHostOperation.

public void vcenterClusterAddHostOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI hostId, 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);
        Host host = _dbClient.queryObject(Host.class, hostId);
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        String key = vcenterApiClient.addHost(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), host.getUsername(), host.getPassword());
        _log.info("Successfully added or located host " + host.getHostName() + " " + key);
        host.setVcenterDataCenter(vcenterDataCenter.getId());
        _dbClient.updateAndReindexObject(host);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("vcenterClusterAddHostOperation exception " + e);
        WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) 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 42 with Cluster

use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method vcenterClusterCreateDatastoreOperation.

public void vcenterClusterCreateDatastoreOperation(URI vcenterId, URI vcenterDataCenterId, URI clusterId, URI volumeId, String selectHostStepId, String stepId) {
    VcenterApiClient vcenterApiClient = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        URI hostId = (URI) _workflowService.loadStepData(selectHostStepId);
        if (hostId == null) {
            _log.error("Workflow loadStepData on " + selectHostStepId + " is null");
            throw new Exception("Workflow loadStepData on " + selectHostStepId + " is null");
        }
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterId);
        Host host = _dbClient.queryObject(Host.class, hostId);
        Volume volume = _dbClient.queryObject(Volume.class, volumeId);
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        String key = vcenterApiClient.createDatastore(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName(), volume.getWWN(), volume.getLabel());
        _log.info("Successfully created or located datastore " + volume.getLabel() + " " + key);
        host.setVcenterDataCenter(vcenterDataCenter.getId());
        _dbClient.updateAndReindexObject(host);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        _log.error("vcenterClusterCreateDatastoreOperation exception " + e);
        WorkflowStepCompleter.stepFailed(stepId, VcenterControllerException.exceptions.hostException(e.getLocalizedMessage(), e));
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Volume(com.emc.storageos.db.client.model.Volume) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) 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 43 with Cluster

use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method removeVcenterCluster.

/**
 * Remove cluster from vCenter.
 *
 * @param clusterId
 * @param datacenterId
 * @param stepId
 */
public void removeVcenterCluster(URI clusterId, URI datacenterId, String stepId) {
    log.info("removeVcenterCluster {} {}", clusterId, datacenterId);
    Cluster cluster = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        cluster = _dbClient.queryObject(Cluster.class, clusterId);
        vcenterController.removeVcenterCluster(datacenterId, clusterId);
        log.info("Remove vCenter cluster success");
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to removeVcenterCluster: " + 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 removeVcenterCluster: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception " + e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveVcenterCluster(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)

Example 44 with Cluster

use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method addStepsVcenterClusterCleanup.

/**
 * A cluster could have only discovered hosts, only provisioned hosts, or mixed.
 * If cluster has only provisioned hosts, then the hosts will be deleted from vCenter.
 * If cluster has only discovered hosts, then the hosts will not be deleted from vCenter.
 * If cluster is mixed, then the hosts will not be deleted from the vCenter; however, the
 * provisioned hosts will still be decommissioned, and their state in vCenter will be "disconnected".
 * If a cluster is provisioned or mixed, then check VMs step will be executed since hosts with running
 * VMs may endup decommissioned.
 */
@Override
public String addStepsVcenterClusterCleanup(Workflow workflow, String waitFor, URI clusterId, boolean deactivateCluster) throws InternalException {
    Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
    if (null == cluster) {
        log.info("Could not find cluster instance for cluster having id {}", clusterId.toString());
        return waitFor;
    }
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        log.info("cluster is not synced to vcenter");
        return waitFor;
    }
    List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
    // Before we get to this cluster removal, ClusterService has a precheck to verify the matching environments
    if (deactivateCluster && (null == clusterHosts || clusterHosts.isEmpty())) {
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
        log.info("Cluster has no hosts, removing empty cluster : {}, from vCenter : {}", cluster.getLabel(), vcenterDataCenter.getLabel());
        waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), null, null);
        return waitFor;
    }
    boolean hasDiscoveredHosts = false;
    boolean hasProvisionedHosts = false;
    List<Host> hosts = _dbClient.queryObject(Host.class, clusterHosts);
    for (Host host : hosts) {
        if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
            hasDiscoveredHosts = true;
        } else {
            hasProvisionedHosts = true;
        }
    }
    log.info("cluster has provisioned hosts: {}, and discovered hosts: {}", hasProvisionedHosts, hasDiscoveredHosts);
    /*
         * Check for VMs only if the cluster was provisioned or is mixed.
         */
    if (hasProvisionedHosts) {
        waitFor = workflow.createStep(CHECK_CLUSTER_VMS, "If synced with vCenter, check if there are VMs in the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("checkClusterVms", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
    }
    /*
         * Remove cluster from vcenter only if all hosts are provisioned.
         */
    if (hasProvisionedHosts && !hasDiscoveredHosts && deactivateCluster) {
        waitFor = workflow.createStep(REMOVE_VCENTER_CLUSTER, "If synced with vCenter, remove the cluster", waitFor, clusterId, clusterId.toString(), this.getClass(), new Workflow.Method("removeVcenterCluster", cluster.getId(), cluster.getVcenterDataCenter()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
    }
    return waitFor;
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 45 with Cluster

use of com.emc.storageos.db.client.model.Cluster 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

Cluster (com.emc.storageos.db.client.model.Cluster)67 Host (com.emc.storageos.db.client.model.Host)38 URI (java.net.URI)26 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)20 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)19 Initiator (com.emc.storageos.db.client.model.Initiator)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)13 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)13 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)13 ArrayList (java.util.ArrayList)13 Vcenter (com.emc.storageos.db.client.model.Vcenter)12 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 HashSet (java.util.HashSet)9 MapCluster (com.emc.storageos.api.mapper.functions.MapCluster)8 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6