Search in sources :

Example 11 with ComputeElement

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

the class ComputeVirtualPoolService method assignMatchedElements.

/**
 * Assign Compute Elements to the Compute Virtual Pool
 *
 * @param param The Compute Virtual Pool Compute Elements to be added and removed
 * @brief Assign compute elements to the compute virtual pool
 * @return ComputeVirtualPoolRestRep The updated Compute Virtual Pool
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/assign-matched-elements")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeVirtualPoolRestRep assignMatchedElements(@PathParam("id") URI id, ComputeVirtualPoolElementUpdateParam param) throws APIException {
    // Validate that Virtual Pool exists
    ArgValidator.checkFieldUriType(id, ComputeVirtualPool.class, "id");
    ComputeVirtualPool cvp = this.queryObject(ComputeVirtualPool.class, id, true);
    _log.debug("Assign compute elements to compute pool " + cvp.getLabel());
    if (cvp.getUseMatchedElements()) {
        _log.error("Cannot assign compute elements when pool is set to use automatic matching");
        throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot assign compute elements when pool is set to use automatic matching.");
    }
    StringSet currentElements = new StringSet();
    if (cvp.getMatchedComputeElements() != null) {
        currentElements.addAll(cvp.getMatchedComputeElements());
    }
    _log.debug("Currently " + currentElements.size() + " existing compute elements: " + currentElements);
    boolean addRequest = param.getComputeVirtualPoolAssignmentChanges().getAdd() != null && param.getComputeVirtualPoolAssignmentChanges().getAdd().getComputeElements() != null;
    if (addRequest) {
        Set<String> addElementsUris = param.getComputeVirtualPoolAssignmentChanges().getAdd().getComputeElements();
        _log.debug("Add " + addElementsUris.size() + " compute elements: " + addElementsUris);
        // Validate
        Collection<ComputeElement> addElements = _dbClient.queryObject(ComputeElement.class, toUriList(addElementsUris));
        // exists
        if (addElementsUris.size() != addElements.size()) {
            _log.error("Invalid add compute element(s) specified - Requested " + addElementsUris.size() + " but only " + addElements.size() + " found");
            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Invalid add compute element(s) specified.");
        }
        List<URI> staticCeUris = findAllStaticallyAssignedComputeElementsInOtherPools(cvp);
        for (ComputeElement computeElement : addElements) {
            if (staticCeUris.contains(computeElement.getId())) {
                _log.error("Compute element " + computeElement.getId() + " already statically assigned to a different pool");
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot assign compute element(s) already manually assigned to different pool(s).");
            }
        }
        // Add against the current collection of compute elements
        for (String computeElementUriString : addElementsUris) {
            boolean added = currentElements.add(computeElementUriString);
            _log.info("Compute pool " + cvp.getLabel() + " already contained compute element " + computeElementUriString + ": " + added);
        }
    }
    boolean removeRequest = param.getComputeVirtualPoolAssignmentChanges().getRemove() != null && param.getComputeVirtualPoolAssignmentChanges().getRemove().getComputeElements() != null;
    if (removeRequest) {
        Set<String> removeElementsUris = param.getComputeVirtualPoolAssignmentChanges().getRemove().getComputeElements();
        _log.debug("Remove " + removeElementsUris.size() + " compute elements: " + removeElementsUris);
        // Validate
        Collection<ComputeElement> removeElements = _dbClient.queryObject(ComputeElement.class, toUriList(removeElementsUris));
        // exists
        if (removeElementsUris.size() != removeElements.size()) {
            _log.error("Invalid remove compute element(s) specified - Requested " + removeElementsUris.size() + " but only " + removeElements.size() + " found");
            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Invalid remove compute element(s) specified.");
        }
        // Remove against the current collection of compute elements
        for (String computeElementUriString : removeElementsUris) {
            boolean removed = currentElements.remove(computeElementUriString);
            _log.debug("Compute pool " + cvp.getLabel() + " needed removal of compute element " + computeElementUriString + ": " + removed);
        }
        removeHostToCVPRelation(removeElements, cvp);
    }
    // Validate
    Collection<ComputeElement> assignedElements = _dbClient.queryObject(ComputeElement.class, toUriList(currentElements));
    // exists
    for (ComputeElement element : assignedElements) {
        boolean inUse = false;
        if (!element.getAvailable()) {
            inUse = true;
        }
        // validate that this is element matches the current vcp criteria
        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 virtual pool is already in use and some compute elements being assigned do not meet criteria.");
            }
            // if ces not in use then simply remove
            currentElements.remove(element.getId().toString());
            _log.warn("Compute Element does not meet criteria; so being removed");
        }
    }
    cvp.setMatchedComputeElements(currentElements);
    updateHostToCVPRelation(cvp);
    _dbClient.updateAndReindexObject(cvp);
    // Crucial that we save the static assignments before running updateOtherPoolsComputeElements
    // so that the dynamic matching reassignments happen with latest static assignments
    updateOtherPoolsComputeElements(cvp);
    return toComputeVirtualPool(_dbClient, cvp, isComputeVirtualPoolInUse(cvp));
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool) 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 ComputeElement

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

the class ComputeVirtualPoolService method updateHostToCVPRelation.

private void updateHostToCVPRelation(ComputeVirtualPool cvp) {
    Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, toUriList(cvp.getMatchedComputeElements()));
    List<Host> updatedHosts = Lists.newArrayList();
    for (ComputeElement computeElement : computeElements) {
        List<Host> hosts = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Host.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(computeElement.getId(), Host.class, "computeElement"));
        for (Host host : hosts) {
            if (NullColumnValueGetter.isNullURI(host.getComputeVirtualPoolId()) || !cvp.getId().equals(host.getComputeVirtualPoolId())) {
                host.setComputeVirtualPoolId(cvp.getId());
                updatedHosts.add(host);
            }
        }
    }
    if (CollectionUtils.isNotEmpty(updatedHosts)) {
        _dbClient.updateObject(updatedHosts);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host)

Example 13 with ComputeElement

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

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

the class HostToComputeElementMatcher method matchHostsToBladesAndSPs.

private static void matchHostsToBladesAndSPs() {
    // lookup map (to find CEs by their UUID)
    Map<String, ComputeElement> ceMap = new HashMap<>();
    for (ComputeElement ce : computeElementMap.values()) {
        if (isValidUuid(ce.getUuid())) {
            ceMap.put(ce.getUuid(), ce);
        }
    }
    // lookup map (to find SPs by their UUID)
    Map<String, UCSServiceProfile> spMap = new HashMap<>();
    for (UCSServiceProfile sp : serviceProfileMap.values()) {
        if (isValidUuid(sp.getUuid())) {
            spMap.put(sp.getUuid(), sp);
        }
    }
    for (Host host : hostMap.values()) {
        _log.info("matching host " + info(host));
        // clear blade & SP associations for hosts that are unregistered or have bad UUIDs
        if (isUnregistered(host) || !hasValidUuid(host)) {
            _log.info("skipping host (unregistered or bad UUID); " + info(host));
            clearHostAssociations(host);
            // next host
            continue;
        }
        // find matching blade & SP
        ComputeElement ce = getMatchingComputeElement(host, ceMap);
        UCSServiceProfile sp = getMatchingServiceProfile(host, spMap);
        // update Host & ServiceProfile
        if (sp == null) {
            _log.info("no SP match for host " + info(host));
            // clear associations if no SP match
            clearHostAssociations(host);
        } else {
            _log.info("matched host to SP & CE " + info(host) + ", " + info(sp) + ", " + info(ce));
            setHostAssociations(host, ce, sp);
        }
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) HashMap(java.util.HashMap) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host)

Example 15 with ComputeElement

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

the class ComputeDeviceControllerImpl method addStepsPreOsInstall.

/**
 * Create/Add Pre-OS install steps to the workflow.
 *
 * @param workflow
 *            {@link Workflow} instance
 * @param waitFor
 *            If non-null, the step will not be queued for execution in the
 *            Dispatcher until the Step or StepGroup indicated by the
 *            waitFor has completed. The waitFor may either be a string
 *            representation of a Step UUID, or the name of a StepGroup.
 * @param computeSystemId
 *            {@link URI} computeSystem Id
 * @param hostId
 *            {@link URI} host Id
 * @param prepStepId
 *            {@link String} step Id
 * @return waitFor step name
 */
@Override
public String addStepsPreOsInstall(Workflow workflow, String waitFor, URI computeSystemId, URI hostId, String prepStepId) {
    log.info("addStepsPreOsInstall");
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    Host host = _dbClient.queryObject(Host.class, hostId);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    // TODO COP-28960 check for null ce
    URI computeElementId = ce.getId();
    log.info("sptId:" + ce.getSptId());
    if (ce.getSptId() != null) {
        URI sptId = URI.create(ce.getSptId());
        UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptId);
        // TODO COP-28960 check template not null
        log.info("is updating:" + template.getUpdating());
        if (template.getUpdating()) {
            waitFor = workflow.createStep(UNBIND_HOST_FROM_TEMPLATE, "prepare host for os install by unbinding it from service profile template", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("unbindHostFromTemplateStep", computeSystemId, hostId), new Workflow.Method("rollbackUnbindHostFromTemplate", computeSystemId, hostId), null);
        }
        // Set host to boot from lan
        waitFor = workflow.createStep(OS_INSTALL_SET_LAN_BOOT, "Set the host to boot from LAN", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("setLanBootTargetStep", computeSystemId, computeElementId, hostId), new Workflow.Method("setNoBootStep", computeSystemId, computeElementId, hostId), null);
        // Set the OS install Vlan on the first vnic
        waitFor = workflow.createStep(OS_INSTALL_PREPARE_OS_NETWORK, "prepare network for os install", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("prepareOsInstallNetworkStep", computeSystemId, computeElementId), new Workflow.Method("rollbackOsInstallNetwork", computeSystemId, computeElementId, prepStepId), prepStepId);
    } else {
        log.error("sptId is null!");
        throw new IllegalArgumentException("addStepsPreOsInstall method failed.  Could not find Serviceprofile template id from computeElement" + ce.getLabel());
    }
    return waitFor;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

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