Search in sources :

Example 6 with ComputeElement

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

the class ComputeElementService method deregisterComputeElement.

/**
 * Allows the user to deregister a registered compute element so that it is no
 * longer used by the system. This simply sets the registration_status of
 * the compute element to UNREGISTERED.
 *
 * @param id the URN of a ViPR compute element to deregister.
 *
 * @brief Unregister compute element
 * @return Status indicating success or failure.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeElementRestRep deregisterComputeElement(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeElement.class, "id");
    ComputeElement ce = queryResource(id);
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getHostComputeElementConstraint(ce.getId()), uris);
    List<Host> hosts = _dbClient.queryObject(Host.class, uris, true);
    if (!hosts.isEmpty()) {
        throw APIException.badRequests.unableToDeregisterProvisionedComputeElement(ce.getLabel(), hosts.get(0).getHostName());
    }
    if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(ce.getRegistrationStatus())) {
        ce.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(ce);
        // Remove the element being deregistered from all CVPs it is part of.
        URIQueryResultList cvpList = new URIQueryResultList();
        _log.debug("Looking for CVPs this blade is in");
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getMatchedComputeElementComputeVirtualPoolConstraint(id), cvpList);
        Iterator<URI> cvpListItr = cvpList.iterator();
        while (cvpListItr.hasNext()) {
            ComputeVirtualPool cvp = _dbClient.queryObject(ComputeVirtualPool.class, cvpListItr.next());
            _log.debug("Found cvp:" + cvp.getLabel() + "containing compute element being deregistered");
            StringSet currentElements = new StringSet();
            if (cvp.getMatchedComputeElements() != null) {
                currentElements.addAll(cvp.getMatchedComputeElements());
                currentElements.remove(ce.getId().toString());
            }
            cvp.setMatchedComputeElements(currentElements);
            _dbClient.updateAndReindexObject(cvp);
            _log.debug("Removed ce from cvp");
        }
        // Record the compute element deregister event.
        // recordComputeElementEvent(OperationTypeEnum.DEREGISTER_COMPUTE_ELEMENT,
        // COMPUTE_ELEMENT_DEREGISTERED_DESCRIPTION, ce.getId());
        recordAndAudit(ce, OperationTypeEnum.DEREGISTER_COMPUTE_ELEMENT, true, null);
    }
    return ComputeMapper.map(ce, null, null);
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) StringSet(com.emc.storageos.db.client.model.StringSet) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with ComputeElement

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

the class ComputeElementService method registerComputeElement.

/**
 * Manually register the discovered compute element with the passed id on the
 * registered compute system with the passed id.
 *
 * @param computeElementId The id of the compute element.
 *
 * @brief Register compute system compute element
 * @return A reference to a ComputeElementRestRep specifying the data for the
 *         registered compute element.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/{id}/register")
public ComputeElementRestRep registerComputeElement(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ComputeElement.class, "id");
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
    ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
    if (ce == null) {
        throw APIException.badRequests.computeElementNotFound(id);
    }
    if (ce.getComputeSystem() == null) {
        throw APIException.badRequests.computeElementNotBelongingToSystem(id, null);
    } else {
        ComputeSystemUtils.queryRegisteredSystem(ce.getComputeSystem(), _dbClient, isIdEmbeddedInURL(ce.getComputeSystem()));
    }
    // if not registered, registered it. Otherwise, dont do anything
    if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(ce.getRegistrationStatus())) {
        registerComputeElement(ce);
        List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
        Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
        while (iter.hasNext()) {
            ComputeVirtualPool cvp = iter.next();
            if (cvp.getUseMatchedElements()) {
                _log.debug("Compute pool " + cvp.getLabel() + " configured to use dynamic matching -- refresh matched elements");
                computeVirtualPoolService.getMatchingCEsforCVPAttributes(cvp);
                _dbClient.updateAndReindexObject(cvp);
            }
        }
    }
    return map(ce, null, null);
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) URI(java.net.URI) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with ComputeElement

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

the class ComputeElementService method queryResource.

@Override
protected ComputeElement queryResource(URI id) {
    ArgValidator.checkUri(id);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
    ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
    return ce;
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement)

Example 9 with ComputeElement

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

the class ComputeVirtualPoolService method getMatchingCEsforCVPAttributes.

public void getMatchingCEsforCVPAttributes(ComputeVirtualPool cvp) {
    if (cvp.getMatchedComputeElements() != null) {
        cvp.getMatchedComputeElements().clear();
    }
    String sysType = null;
    if (cvp.getSystemType() != null) {
        if (cvp.getSystemType().contentEquals(ComputeVirtualPool.SupportedSystemTypes.Cisco_UCSM.toString())) {
            sysType = "ucs";
        }
    }
    if (sysType != null) {
        _log.debug("Iterating over all CEs");
        List<URI> ceList = findComputeElementsFromDeviceAssociations(cvp);
        List<URI> staticallyAssignedComputeElements = findAllStaticallyAssignedComputeElementsInOtherPools(cvp);
        StringSet ceIds = new StringSet();
        Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, ceList);
        for (ComputeElement ce : computeElements) {
            if (ce.getSystemType() == null) {
                continue;
            }
            if (!ce.getSystemType().contentEquals((CharSequence) sysType)) {
                continue;
            }
            if (!isRegistered(ce)) {
                continue;
            }
            if (staticallyAssignedComputeElements.contains(ce.getId())) {
                _log.debug("Compute element " + ce.getId() + " has been statically assigned and will be filtered out");
                continue;
            }
            if (isParamSet(cvp.getMinTotalCores()) && (ce.getNumOfCores() < cvp.getMinTotalCores())) {
                continue;
            }
            if (isParamSet(cvp.getMaxTotalCores()) && (cvp.getMaxTotalCores() != -1) && (ce.getNumOfCores() > cvp.getMaxTotalCores())) {
                continue;
            }
            if (isParamSet(cvp.getMinProcessors()) && (ce.getNumberOfProcessors() < cvp.getMinProcessors())) {
                continue;
            }
            if (isParamSet(cvp.getMaxProcessors()) && (cvp.getMaxProcessors() != -1) && (ce.getNumberOfProcessors() > cvp.getMaxProcessors())) {
                continue;
            }
            if (isParamSet(cvp.getMinTotalThreads()) && (ce.getNumberOfThreads() < cvp.getMinTotalThreads())) {
                continue;
            }
            if (isParamSet(cvp.getMaxTotalThreads()) && (cvp.getMaxTotalThreads() != -1) && (ce.getNumberOfThreads() > cvp.getMaxTotalThreads())) {
                continue;
            }
            float ceSpeed = Float.parseFloat(ce.getProcessorSpeed());
            if (isParamSet(cvp.getMinCpuSpeed())) {
                if (ceSpeed < (float) cvp.getMinCpuSpeed()) {
                    continue;
                }
            }
            if (isParamSet(cvp.getMaxCpuSpeed()) && (cvp.getMaxCpuSpeed() != -1)) {
                if (ceSpeed > (float) cvp.getMaxCpuSpeed()) {
                    continue;
                }
            }
            if (isParamSet(cvp.getMinMemory()) && (ce.getRam() / 1024 < cvp.getMinMemory())) {
                continue;
            }
            if (isParamSet(cvp.getMaxMemory()) && (cvp.getMaxMemory() != -1) && (ce.getRam() / 1024 > cvp.getMaxMemory())) {
                continue;
            }
            ceIds.add(ce.getId().toASCIIString());
        }
        cvp.addMatchedComputeElements(ceIds);
        Integer size = cvp.getMatchedComputeElements() != null ? cvp.getMatchedComputeElements().size() : 0;
        _log.debug("putting CEs in the pool, cnt: " + size);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI)

Example 10 with ComputeElement

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

the class ComputeVirtualPoolService method extractComputeElements.

private ComputeElementListRestRep extractComputeElements(ComputeVirtualPool cvp) {
    ComputeElementListRestRep result = new ComputeElementListRestRep();
    if (cvp.getMatchedComputeElements() != null) {
        Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, toUriList(cvp.getMatchedComputeElements()));
        Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
        Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "computeElement", "cluster"), ControllerUtils.getFullyImplementedCollection(hostIds));
        for (ComputeElement computeElement : computeElements) {
            if (computeElement != null) {
                Host associatedHost = null;
                for (Host host : hosts) {
                    if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement().equals(computeElement.getId())) {
                        associatedHost = host;
                        break;
                    }
                }
                Cluster cluster = null;
                if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
                    cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
                }
                ComputeElementRestRep rest = map(computeElement, associatedHost, cluster);
                result.getList().add(rest);
            }
        }
    }
    return result;
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI)

Aggregations

ComputeElement (com.emc.storageos.db.client.model.ComputeElement)52 Host (com.emc.storageos.db.client.model.Host)24 URI (java.net.URI)20 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)10 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)10 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)9 MalformedURLException (java.net.MalformedURLException)9 Produces (javax.ws.rs.Produces)9 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)6 UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)6 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)6 Cluster (com.emc.storageos.db.client.model.Cluster)4