Search in sources :

Example 11 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method updateComputeVirtualPool.

/**
 * Update a Compute Virtual Pool
 *
 * @brief Update a compute virtual pool
 * @param param The Compute Virtual Pool update spec
 * @return ComputeVirtualPoolRestRep The updated Compute Virtual Pool
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeVirtualPoolRestRep updateComputeVirtualPool(@PathParam("id") URI id, ComputeVirtualPoolUpdateParam param) {
    ComputeVirtualPool cvp = null;
    _log.debug("Update Parameters:\n" + param.toString());
    // Validate that Virtual Pool exists
    ArgValidator.checkFieldUriType(id, ComputeVirtualPool.class, "id");
    cvp = this.queryObject(ComputeVirtualPool.class, id, true);
    boolean nicOrHbaRangeChanges = false;
    // If current value not set OR if param is more restrictive then change is more restrictive
    boolean moreRestrictiveChange = false;
    // Process the update parameters
    // If a name is specified on request and that value is different that current name
    boolean nameChange = (param.getName() != null && !(cvp.getLabel().equals(param.getName())));
    if (nameChange) {
        checkForDuplicateName(param.getName(), ComputeVirtualPool.class);
        cvp.setLabel(param.getName());
    }
    if (null != param.getDescription()) {
        cvp.setDescription(param.getDescription());
    }
    if (null != param.getSystemType()) {
        ArgValidator.checkFieldValueFromEnum(param.getSystemType(), "system_type", ComputeVirtualPool.SupportedSystemTypes.class);
        // Don't allow changes of system type if there are service profile templates already set
        if (cvp.getServiceProfileTemplates() != null) {
            if (!cvp.getServiceProfileTemplates().isEmpty()) {
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot change system type when Service Profile Temples are associated");
            }
        }
        cvp.setSystemType(param.getSystemType());
    }
    if (isParamSet(param.getMinProcessors()) && ((cvp.getMinProcessors() == null) || (cvp.getMinProcessors() < param.getMinProcessors()))) {
        moreRestrictiveChange = true;
        _log.debug("Min Processors increased from " + cvp.getMinProcessors() + " to " + param.getMinProcessors());
    }
    cvp.setMinProcessors(getParamValue(param.getMinProcessors()));
    if (isParamSet(param.getMaxProcessors()) && ((cvp.getMaxProcessors() == null) || (cvp.getMaxProcessors() == -1) || (cvp.getMaxProcessors() > param.getMaxProcessors()))) {
        moreRestrictiveChange = true;
        _log.debug("Max Processors decreased from " + cvp.getMaxProcessors() + " to " + param.getMaxProcessors());
    }
    cvp.setMaxProcessors(getParamMaxValue(param.getMaxProcessors()));
    validateMinMaxIntValues(cvp.getMinProcessors(), cvp.getMaxProcessors(), "min_processors", "max_processors");
    if (isParamSet(param.getMinTotalCores()) && ((cvp.getMinTotalCores() == null) || (cvp.getMinTotalCores() < param.getMinTotalCores()))) {
        moreRestrictiveChange = true;
        _log.debug("Min TotalCores increased from " + cvp.getMinTotalCores() + " to " + param.getMinTotalCores());
    }
    cvp.setMinTotalCores(getParamValue(param.getMinTotalCores()));
    if (isParamSet(param.getMaxTotalCores()) && ((cvp.getMaxTotalCores() == null) || (cvp.getMaxTotalCores() == -1) || (cvp.getMaxTotalCores() > param.getMaxTotalCores()))) {
        moreRestrictiveChange = true;
        _log.debug("Max TotalCores decreased from " + cvp.getMaxTotalCores() + " to " + param.getMaxTotalCores());
    }
    cvp.setMaxTotalCores(getParamMaxValue(param.getMaxTotalCores()));
    validateMinMaxIntValues(cvp.getMinTotalCores(), cvp.getMaxTotalCores(), "min_total_cores", "max_total_cores");
    if (isParamSet(param.getMinTotalThreads()) && ((cvp.getMinTotalThreads() == null) || (cvp.getMinTotalThreads() < param.getMinTotalThreads()))) {
        moreRestrictiveChange = true;
        _log.debug("Min TotalThreads increased from " + cvp.getMinTotalThreads() + " to " + param.getMinTotalThreads());
    }
    cvp.setMinTotalThreads(getParamValue(param.getMinTotalThreads()));
    if (isParamSet(param.getMaxTotalThreads()) && ((cvp.getMaxTotalThreads() == null) || (cvp.getMaxTotalThreads() == -1) || (cvp.getMaxTotalThreads() > param.getMaxTotalThreads()))) {
        moreRestrictiveChange = true;
        _log.debug("Max TotalThreads decreased from " + cvp.getMaxTotalThreads() + " to " + param.getMaxMemory());
    }
    cvp.setMaxTotalThreads(getParamMaxValue(param.getMaxTotalThreads()));
    validateMinMaxIntValues(cvp.getMinTotalThreads(), cvp.getMaxTotalThreads(), "min_total_threads", "max_total_threads");
    if (isParamSet(param.getMinCpuSpeed()) && ((cvp.getMinCpuSpeed() == null) || (cvp.getMinCpuSpeed() < param.getMinCpuSpeed()))) {
        moreRestrictiveChange = true;
        _log.debug("Min CpuSpeed increased from " + cvp.getMinCpuSpeed() + " to " + param.getMinCpuSpeed());
    }
    cvp.setMinCpuSpeed(getParamValue(param.getMinCpuSpeed()));
    if (isParamSet(param.getMaxCpuSpeed()) && ((cvp.getMaxCpuSpeed() == null) || (cvp.getMaxCpuSpeed() == -1) || (cvp.getMaxCpuSpeed() > param.getMaxCpuSpeed()))) {
        moreRestrictiveChange = true;
        _log.debug("Max CpuSpeed decreased from " + cvp.getMaxCpuSpeed() + " to " + param.getMaxCpuSpeed());
    }
    cvp.setMaxCpuSpeed(getParamMaxValue(param.getMaxCpuSpeed()));
    validateMinMaxIntValues(cvp.getMinCpuSpeed(), cvp.getMaxCpuSpeed(), "min_processor_speed", "max_processor_speed");
    if (isParamSet(param.getMinMemory()) && ((cvp.getMinMemory() == null) || (cvp.getMinMemory() < param.getMinMemory()))) {
        moreRestrictiveChange = true;
        _log.debug("Min Memory increased from " + cvp.getMinMemory() + " to " + param.getMinMemory());
    }
    cvp.setMinMemory(getParamValue(param.getMinMemory()));
    if (isParamSet(param.getMaxMemory()) && ((cvp.getMaxMemory() == null) || (cvp.getMaxMemory() == -1) || (cvp.getMaxMemory() > param.getMaxMemory()))) {
        moreRestrictiveChange = true;
        _log.debug("Max Memory decreased from " + cvp.getMaxMemory() + " to " + param.getMaxMemory());
    }
    cvp.setMaxMemory(getParamMaxValue(param.getMaxMemory()));
    validateMinMaxIntValues(cvp.getMinMemory(), cvp.getMaxMemory(), "min_memory", "max_memory");
    // If current value not set OR if param is more restrictive then change is more
    boolean moreRestrictiveNicHbaChange = false;
    if (isParamSet(param.getMinNics()) && ((cvp.getMinNics() == null) || (cvp.getMinNics() < param.getMinNics()))) {
        moreRestrictiveNicHbaChange = true;
        _log.debug("Min nic increased from " + cvp.getMinNics() + " to " + param.getMinNics());
    }
    cvp.setMinNics(getParamValue(param.getMinNics()));
    if (isParamSet(param.getMaxNics()) && ((cvp.getMaxNics() == null) || (cvp.getMaxNics() == -1) || (cvp.getMaxNics() > param.getMaxNics()))) {
        moreRestrictiveNicHbaChange = true;
        _log.debug("Max nic decreased from " + cvp.getMaxNics() + " to " + param.getMaxNics());
    }
    cvp.setMaxNics(getParamMaxValue(param.getMaxNics()));
    validateMinMaxIntValues(cvp.getMinNics(), cvp.getMaxNics(), "min_nics", "max_nics");
    if (isParamSet(param.getMinHbas()) && ((cvp.getMinHbas() == null) || (cvp.getMinHbas() < param.getMinHbas()))) {
        moreRestrictiveNicHbaChange = true;
        _log.debug("Min hba increased from " + cvp.getMinHbas() + " to " + param.getMinHbas());
    }
    cvp.setMinHbas(getParamValue(param.getMinHbas()));
    if (isParamSet(param.getMaxHbas()) && ((cvp.getMaxHbas() == null) || (cvp.getMaxHbas() == -1) || (cvp.getMaxHbas() > param.getMaxHbas()))) {
        moreRestrictiveNicHbaChange = true;
        _log.debug("Max hba decreased from " + cvp.getMaxHbas() + " to " + param.getMaxHbas());
    }
    cvp.setMaxHbas(getParamMaxValue(param.getMaxHbas()));
    validateMinMaxIntValues(cvp.getMinHbas(), cvp.getMaxHbas(), "min_hbas", "max_hbas");
    boolean changeToStaticAssignment = false;
    boolean changeToDynamicAssignment = false;
    Collection<ComputeElement> staticElements = new HashSet<ComputeElement>();
    if (!cvp.getUseMatchedElements() && cvp.getMatchedComputeElements() != null && !cvp.getMatchedComputeElements().isEmpty()) {
        staticElements.addAll(_dbClient.queryObject(ComputeElement.class, toUriList(cvp.getMatchedComputeElements())));
        _log.debug("static elements count:" + staticElements.size());
    }
    if (null != param.getUseMatchedElements()) {
        // Will need to clear current matches when changing to static assignment
        changeToStaticAssignment = (param.getUseMatchedElements() == false) && (param.getUseMatchedElements() != cvp.getUseMatchedElements());
        changeToDynamicAssignment = (param.getUseMatchedElements() == true) && (param.getUseMatchedElements() != cvp.getUseMatchedElements());
        cvp.setUseMatchedElements(param.getUseMatchedElements());
    }
    if (changeToStaticAssignment) {
        // Clear dynamic matches when changing to static to get ready for upcoming assignments
        if (cvp.getMatchedComputeElements() != null) {
            cvp.getMatchedComputeElements().clear();
        }
    }
    if (null != param.getVarrayChanges()) {
        updateVirtualArrays(cvp, param.getVarrayChanges());
    }
    if (null != param.getSptChanges()) {
        if (cvp.getSystemType().contentEquals(ComputeVirtualPool.SupportedSystemTypes.Cisco_UCSM.toString())) {
            updateServiceProfileTemplates(cvp, param.getSptChanges());
        }
    }
    // Check SPTs meet criteria after updates above
    if (moreRestrictiveNicHbaChange) {
        if (isComputeVirtualPoolInUse(cvp)) {
            _log.warn("VCP is in use; more restrictive Nic or Hba change is not allowed");
            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "More restrictive updates to network adapter and hba range not allowed because compute virtual pool is already in use.");
        }
        Set<String> sptsNotMeetingCriteria = new HashSet<String>();
        Collection<UCSServiceProfileTemplate> templates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(cvp.getServiceProfileTemplates()));
        for (UCSServiceProfileTemplate template : templates) {
            boolean inUse = isServiceProfileTemplateInUse(cvp, template);
            try {
                validateServiceProfileTemplate(cvp, template);
            } catch (APIException e) {
                _log.warn("SPT " + template.getLabel() + ":" + template.getDn() + " is in use(" + inUse + ") and does not meet criteria " + e.toString());
                /*
                     * Since we are disallowing more restrictive changes if the VCP is in use, the if block below will not be used for the
                     * 2.2 release.
                     */
                if (inUse) {
                    throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Updates to pool not allowed because service profile template(s) already in use do not meet requested criteria.");
                }
                // if spt not in use then simply remove
                sptsNotMeetingCriteria.add(template.getId().toString());
                _log.warn("SPT does not meet criteria; so being removed");
            }
        }
        cvp.removeServiceProfileTemplates(sptsNotMeetingCriteria);
    }
    if (cvp.getUseMatchedElements()) {
        _log.debug("Compute pool " + cvp.getLabel() + " configured to use dynamic matching");
        getMatchingCEsforCVPAttributes(cvp);
    }
    if (changeToDynamicAssignment && !staticElements.isEmpty()) {
        // to possibly include them
        for (ComputeElement computeElement : staticElements) {
            if (!isAvailable(computeElement)) {
                _log.error("Cannot change to dynamic matching because statically assigned compute element(s) have been used in pool " + cvp.getId());
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot change to automatic matching because manually assigned compute element(s) already in use.");
            }
        }
        updateOtherPoolsComputeElements(cvp);
    }
    if (moreRestrictiveChange) {
        if (isComputeVirtualPoolInUse(cvp)) {
            _log.warn("VCP is in use; more restrictive change is not allowed");
            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "More restrictive updates to qualifiers not allowed because compute virtual pool is already in use.");
        }
        // VCP is not in use. So check if there are statically assigned members that need to be removed from vcp membership
        _log.info("VCP is not in use. So check if there are statically assigned members that need to be removed from vcp membership");
        if (!cvp.getUseMatchedElements() && !staticElements.isEmpty()) {
            Set<ComputeElement> cesNotMeetingCriteria = new HashSet<ComputeElement>();
            Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, getURIs(staticElements));
            for (ComputeElement element : computeElements) {
                _log.debug("Blade:" + element.getChassisId() + "/" + element.getSlotId());
                boolean inUse = (element.getAvailable() == false);
                try {
                    validateComputeElement(cvp, element);
                } catch (APIException e) {
                    _log.warn("Compute Element " + element.getLabel() + ":" + element.getDn() + " is in use(" + inUse + ") and does not meet criteria " + e.toString());
                    /*
                         * Since we are disallowing more restrictive changes if the VCP is in use, the if block below will not be used for
                         * the 2.2 release.
                         */
                    if (inUse) {
                        throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Updates to pool not allowed because compute element(s) already in use do not meet requested criteria.");
                    }
                    // if ces not in use then simply remove
                    cesNotMeetingCriteria.add(element);
                    _log.warn("Compute Element does not meet criteria; so being removed");
                }
            }
        }
    }
    updateHostToCVPRelation(cvp);
    _dbClient.updateAndReindexObject(cvp);
    recordOperation(OperationTypeEnum.UPDATE_COMPUTE_VPOOL, VPOOL_UPDATED_DESCRIPTION, cvp);
    return toComputeVirtualPool(_dbClient, cvp, isComputeVirtualPoolInUse(cvp));
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method getAclsOnVirtualPool.

private ACLAssignments getAclsOnVirtualPool(URI id) {
    ComputeVirtualPool vpool = (ComputeVirtualPool) queryResource(id);
    ArgValidator.checkEntityNotNull(vpool, id, isIdEmbeddedInURL(id));
    ACLAssignments response = new ACLAssignments();
    response.setAssignments(_permissionsHelper.convertToACLEntries(vpool.getAcls()));
    return response;
}
Also used : ACLAssignments(com.emc.storageos.model.auth.ACLAssignments) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool)

Example 13 with ComputeVirtualPool

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

the class ComputeSystemService method deregisterComputeSystem.

/**
 * De-registers a previously registered Compute System. (Creation and
 * Discovery of the Compute System marks the Compute System "Registered" by
 * default)
 *
 * @param id
 *            the URN of a ViPR Compute System
 * @brief Deregister compute system
 * @return A detailed representation of the Compute System
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeSystemRestRep deregisterComputeSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the storage system.
    ArgValidator.checkUri(id);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, id);
    ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(cs.getRegistrationStatus())) {
        cs.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(cs);
        // Fetch all unprovisioned blades for this CS; remove them from any CVPs they are part of
        ComputeElementListRestRep result = getComputeElements(cs.getId());
        List<ComputeElementRestRep> blades = result.getList();
        List<URI> unprovisionedBlades = new ArrayList<URI>();
        for (ComputeElementRestRep ce : blades) {
            if (ce.getAvailable()) {
                unprovisionedBlades.add(ce.getId());
                _log.debug("Found unprovisioned blade:" + ce.getName());
            }
        }
        List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
        Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
        while (iter.hasNext()) {
            ComputeVirtualPool cvp = iter.next();
            _log.debug("Remove unprovisioned blades from cvp: " + cvp.getLabel());
            StringSet currentElements = new StringSet();
            if (cvp.getMatchedComputeElements() != null) {
                currentElements.addAll(cvp.getMatchedComputeElements());
                for (URI bladeId : unprovisionedBlades) {
                    currentElements.remove(bladeId.toString());
                }
            }
            cvp.setMatchedComputeElements(currentElements);
            _dbClient.updateAndReindexObject(cvp);
            _log.debug("Removed ces from cvp");
        }
        recordAndAudit(cs, OperationTypeEnum.DEREGISTER_COMPUTE_SYSTEM, true, null);
    }
    return getComputeSystem(id);
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with ComputeVirtualPool

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

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

Aggregations

ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)23 ComputeVirtualPoolMapper.toComputeVirtualPool (com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool)15 URI (java.net.URI)12 Produces (javax.ws.rs.Produces)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)11 Path (javax.ws.rs.Path)11 POST (javax.ws.rs.POST)7 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)6 Consumes (javax.ws.rs.Consumes)6 StringSet (com.emc.storageos.db.client.model.StringSet)4 HashSet (java.util.HashSet)4 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)3 Host (com.emc.storageos.db.client.model.Host)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 GET (javax.ws.rs.GET)3 PUT (javax.ws.rs.PUT)3 ComputeLanBootImagePath (com.emc.storageos.db.client.model.ComputeLanBootImagePath)2 ComputeSanBootImagePath (com.emc.storageos.db.client.model.ComputeSanBootImagePath)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)2