Search in sources :

Example 46 with Cluster

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

the class UcsComputeDevice method addHostPortsToVArrayNetworks.

public void addHostPortsToVArrayNetworks(VirtualArray varray, Host host, String stepId) {
    LOGGER.info("Adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
            Map<Network, List<String>> networkToInitiatorMap = Collections.synchronizedMap(new HashMap<Network, List<String>>());
            Map<String, Network> networkIdNetworkMapInVarray = getVarrayNetworkMap(_dbClient, varray.getId());
            URIQueryResultList ceHBAUriList = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getHostComputeElemetHBAsConstraint(host.getId()), ceHBAUriList);
            Iterator<URI> ceHBAUriListIterator = ceHBAUriList.iterator();
            Cluster cluster = null;
            if (host.getCluster() != null) {
                cluster = _dbClient.queryObject(Cluster.class, host.getCluster());
            }
            while (ceHBAUriListIterator.hasNext()) {
                URI ceHBAUri = ceHBAUriListIterator.next();
                ComputeElementHBA computeElementHBA = _dbClient.queryObject(ComputeElementHBA.class, ceHBAUri);
                Initiator initiator = new Initiator();
                initiator.setHost(host.getId());
                initiator.setHostName(host.getHostName());
                initiator.setId(URIUtil.createId(Initiator.class));
                if (cluster != null) {
                    initiator.setClusterName(cluster.getLabel());
                }
                initiator.setInitiatorNode(computeElementHBA.getNode());
                initiator.setInitiatorPort(computeElementHBA.getPort());
                initiator.setProtocol(computeElementHBA.getProtocol() != null ? computeElementHBA.getProtocol().toUpperCase() : null);
                // Search against the database, fail if you see the wwn in the database already.
                Initiator dbInitiator = ExportUtils.getInitiator(initiator.getInitiatorPort(), _dbClient);
                if (dbInitiator != null) {
                    throw ComputeSystemControllerException.exceptions.illegalInitiator(host.getHostName(), dbInitiator.getInitiatorPort(), dbInitiator.getHostName());
                }
                Network network = networkIdNetworkMapInVarray.get(computeElementHBA.getVsanId());
                // Test mechanism to invoke a failure. No-op on production systems.
                InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_065);
                if (network == null) {
                    LOGGER.error("No corresponding Network for HBA {} in vArray {}.  Network null from DB.", computeElementHBA.getPort(), varray.getId());
                    throw new RuntimeException(ComputeSystemControllerException.exceptions.noCorrespondingNetworkForHBAInVarray(computeElementHBA.getPort(), varray.getLabel(), null));
                } else {
                    if (networkToInitiatorMap.get(network) == null) {
                        networkToInitiatorMap.put(network, new ArrayList<String>());
                    }
                    networkToInitiatorMap.get(network).add(computeElementHBA.getPort());
                }
                _dbClient.createObject(initiator);
            }
            /**
             * Add all the newly added endpoints to their respective networks!
             */
            for (Network network : networkToInitiatorMap.keySet()) {
                network.addEndpoints(networkToInitiatorMap.get(network), false);
                _dbClient.updateObject(network);
                handleEndpointsAdded(network, networkToInitiatorMap.get(network), _dbClient, _coordinator);
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
        LOGGER.info("Done adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
    } catch (Exception ex) {
        LOGGER.error("Exception while adding host ports to vArray networks. {}", ex);
        WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToAddHostPortsToVArrayNetworks(varray.getLabel().toString(), ex));
    }
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) ComputeElementHBA(com.emc.storageos.db.client.model.ComputeElementHBA) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ComputeSystemControllerTimeoutException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException) MalformedURLException(java.net.MalformedURLException) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) Network(com.emc.storageos.db.client.model.Network) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 47 with Cluster

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

the class ComputeSystemControllerImpl method unmountClusterStorage.

/**
 * Unmounts storage for a cluster
 *
 * @param workflow the workflow to use
 * @param waitFor the step to wait for
 * @param clusterId the cluster id to unmount storage
 * @return wait step
 */
private String unmountClusterStorage(Workflow workflow, String waitFor, URI clusterId) {
    Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
    String newWaitFor = waitFor;
    if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        List<ExportGroup> exportGroups = getSharedExports(_dbClient, clusterId);
        List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
        URI vcenterDataCenter = cluster.getVcenterDataCenter();
        Collection<URI> exportIds = Collections2.transform(exportGroups, CommonTransformerFunctions.fctnDataObjectToID());
        Map<URI, Collection<URI>> hostExports = Maps.newHashMap();
        for (URI host : clusterHosts) {
            hostExports.put(host, exportIds);
        }
        newWaitFor = this.verifyDatastoreForRemoval(hostExports, vcenterDataCenter, newWaitFor, workflow);
        newWaitFor = this.unmountAndDetachVolumes(hostExports, vcenterDataCenter, newWaitFor, workflow);
    }
    return newWaitFor;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Cluster(com.emc.storageos.db.client.model.Cluster) Collection(java.util.Collection) URI(java.net.URI)

Example 48 with Cluster

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

the class ComputeSystemControllerImpl method addHostsToExport.

@Override
public void addHostsToExport(URI eventId, List<URI> hostIds, URI clusterId, String taskId, URI oldCluster, boolean isVcenter) throws ControllerException {
    HostCompleter completer = null;
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, REMOVE_HOST_STORAGE_WF_NAME, true, taskId);
        String waitFor = null;
        URI vCenterDataCenterId = NullColumnValueGetter.getNullURI();
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
        if (cluster != null && !NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
            vCenterDataCenterId = cluster.getVcenterDataCenter();
        }
        completer = new HostCompleter(eventId, hostIds, false, taskId);
        if (!NullColumnValueGetter.isNullURI(oldCluster) && !oldCluster.equals(clusterId)) {
            waitFor = addStepsForRemoveHost(workflow, waitFor, hostIds, oldCluster, vCenterDataCenterId, isVcenter);
        }
        waitFor = addStepForUpdatingHostAndInitiatorClusterReferences(workflow, waitFor, hostIds, clusterId, vCenterDataCenterId, completer);
        waitFor = addStepsForAddHost(workflow, waitFor, hostIds, clusterId, isVcenter, eventId);
        workflow.executePlan(completer, "Success", null, null, null, null);
    } catch (Exception ex) {
        String message = "addHostToExport caught an exception.";
        _log.error(message, ex);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(ex);
        completer.error(_dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Workflow(com.emc.storageos.workflow.Workflow) Cluster(com.emc.storageos.db.client.model.Cluster) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 49 with Cluster

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

the class ComputeSystemHelper method doDeactivateVcenterDataCenter.

/**
 * Utility function to recursively deactivate all the hosts / clusters from datacenter
 *
 * @param host the host to deactivate
 */
public static void doDeactivateVcenterDataCenter(DbClient dbClient, VcenterDataCenter dataCenter) {
    List<NamedElementQueryResultList.NamedElement> hostUris = listChildren(dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
    Set<URI> doNotDeleteclusters = new HashSet<URI>();
    for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
        Host host = dbClient.queryObject(Host.class, hostUri.getId());
        if (host != null && !host.getInactive()) {
            if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                doDeactivateHost(dbClient, host);
            } else {
                // do not delete hosts that have compute elements, simply break DC link
                host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
                dbClient.persistObject(host);
                if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
                    doNotDeleteclusters.add(host.getCluster());
                }
            }
        }
    }
    List<NamedElementQueryResultList.NamedElement> clustersUris = listChildren(dbClient, dataCenter.getId(), Cluster.class, "label", "vcenterDataCenter");
    for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
        Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
        if (cluster != null && !cluster.getInactive()) {
            if (doNotDeleteclusters.contains(cluster.getId())) {
                // do not delete clusters if hosts are not deleted, simply break DC link
                cluster.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
                cluster.setExternalId(NullColumnValueGetter.getNullStr());
                dbClient.persistObject(cluster);
            } else {
                dbClient.markForDeletion(cluster);
                EventUtils.deleteResourceEvents(dbClient, cluster.getId());
            }
        }
    }
    _log.info("marking DC for deletion: {} {}", dataCenter.getLabel(), dataCenter.getId());
    dbClient.markForDeletion(dataCenter);
    EventUtils.deleteResourceEvents(dbClient, dataCenter.getId());
}
Also used : NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URI(java.net.URI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) HashSet(java.util.HashSet)

Example 50 with Cluster

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

the class ComputeSystemHelper method isDataCenterInUse.

/**
 * Checks if an datacenter is in use by an export groups
 *
 * @param dbClient
 * @param datacenterURI the datacenter URI
 * @return true if the datacenter is in used by an export group.
 */
public static boolean isDataCenterInUse(DbClient dbClient, URI datacenterURI) {
    VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, datacenterURI);
    if (dataCenter != null && !dataCenter.getInactive()) {
        List<NamedElementQueryResultList.NamedElement> hostUris = listChildren(dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
        for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
            Host host = dbClient.queryObject(Host.class, hostUri.getId());
            // ignore provisioned hosts
            if (host != null && !host.getInactive() && NullColumnValueGetter.isNullURI(host.getComputeElement()) && isHostInUse(dbClient, host.getId())) {
                return true;
            }
        }
        List<NamedElementQueryResultList.NamedElement> clustersUris = listChildren(dbClient, dataCenter.getId(), Cluster.class, "label", "vcenterDataCenter");
        for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
            Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
            if (cluster != null && !cluster.getInactive() && isClusterInExport(dbClient, clusterUri.getId())) {
                return true;
            }
        }
    }
    return false;
}
Also used : NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

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