Search in sources :

Example 16 with UCSServiceProfileTemplate

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

the class ComputeVirtualPoolService method updateServiceProfileTemplates.

/**
 * Updates the service profile templates to which the compute virtual pool is assigned.
 *
 * @param cvp - A reference to the compute virtual pool.
 *
 * @return true if there was a service profile template assignment change, false otherwise.
 */
private boolean updateServiceProfileTemplates(ComputeVirtualPool cvp, ServiceProfileTemplateAssignmentChanges sptAssignmentChanges) {
    // Validate that the SPTs to be assigned to the Compute Virtual Pool
    // reference existing SPTs in the database and add them to
    // to the CVP.
    boolean sptsForCvpUpdated = false;
    Set<String> sptsAddedToCvp = new HashSet<String>();
    Set<String> sptsRemovedFromCvp = new HashSet<String>();
    if (sptAssignmentChanges != null) {
        _log.debug("Update request has service profile template assignment changes for compute virtual pool {}", cvp.getId());
        // Verify the assignment changes in the request.
        verifySptAssignmentChanges(cvp, sptAssignmentChanges);
        _log.debug("Requested service profile template assignment changes verified.");
        ServiceProfileTemplateAssignments addAssignments = sptAssignmentChanges.getAdd();
        if (addAssignments != null) {
            Set<String> addSpts = addAssignments.getServiceProfileTemplates();
            if ((addSpts != null) && (!addSpts.isEmpty())) {
                _log.debug("Request specifies service profile templates to be added.");
                // Validate the requested URIs.
                checkServiceProfileTemplateURIs(addSpts, _dbClient);
                // Load a Set of the Compute Systems associated to current SPTs
                Map<URI, UCSServiceProfileTemplate> computeSystemToTemplateMap = new HashMap<URI, UCSServiceProfileTemplate>();
                // Iterate over all SPTs currently associated to the CVP
                if (cvp.getServiceProfileTemplates() != null && !cvp.getServiceProfileTemplates().isEmpty()) {
                    Collection<UCSServiceProfileTemplate> templates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(cvp.getServiceProfileTemplates()));
                    for (UCSServiceProfileTemplate template : templates) {
                        // verify the SPT exists in the db
                        ArgValidator.checkEntity(template, template.getId(), isIdEmbeddedInURL(template.getId()));
                        computeSystemToTemplateMap.put(template.getComputeSystem(), template);
                    }
                }
                // Iterate over the service profile templates and assign them to the CVP.
                StringSet currentAssignments = cvp.getServiceProfileTemplates();
                Collection<UCSServiceProfileTemplate> addedTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(addSpts));
                for (UCSServiceProfileTemplate addedTemplate : addedTemplates) {
                    if ((currentAssignments != null) && (currentAssignments.contains(addedTemplate.getId().toString()))) {
                        // Just ignore those already assigned
                        _log.info("Compute Virtual Pool already assigned to service profile template {}", addedTemplate.getId().toString());
                        continue;
                    }
                    // verify that the SPT is not associated to a Compute System already in use
                    ArgValidator.checkEntity(addedTemplate, addedTemplate.getId(), isIdEmbeddedInURL(addedTemplate.getId()));
                    UCSServiceProfileTemplate existingTemplate = computeSystemToTemplateMap.get(addedTemplate.getComputeSystem());
                    if (existingTemplate != null) {
                        _log.debug("Compute system " + addedTemplate.getComputeSystem() + " already contains a spt " + existingTemplate);
                        /*
                             * TODO: For 2.2 release, we will not check if SPT is in use but will only check if vcp is in use
                             * if(isServiceProfileTemplateInUse(cvp,existingTemplate)) {
                             * _log.info("SPT " + existingTemplate +
                             * " is already in use and cannot be disassociated and replaced with requested SPT " +
                             * addedTemplate.getId().toString());
                             * throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getId(),
                             * "Cannot replace service profile template that is already in use.");
                             * } else {
                             * _log.info("SPT " + existingTemplate +
                             * " is not in use and will be disassociated and replaced with requested SPT " +
                             * addedTemplate.getId().toString());
                             * sptsRemovedFromCvp.add(existingTemplate.getId().toString());
                             * }
                             */
                        if (isComputeVirtualPoolInUse(cvp)) {
                            _log.info("compute virtual pool is already in use and so SPT cannot be disassociated and replaced with requested SPT " + addedTemplate.getId().toString());
                            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot replace service profile template that is already in use.");
                        } else {
                            _log.info("compute virtual pool is not in use and so SPT will be disassociated and replaced with requested SPT " + addedTemplate.getId().toString());
                            sptsRemovedFromCvp.add(existingTemplate.getId().toString());
                        }
                    }
                    if (addedTemplate.getUpdating() == true) {
                        _log.info("selected spt is an updating template. So validate...");
                        if (!computeSystemService.isUpdatingSPTValid(addedTemplate, _dbClient)) {
                            throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Nic or hba names in updating service profile template " + addedTemplate.getLabel() + " do not match those in its boot policy.");
                        }
                    }
                    if (!computeSystemService.isServiceProfileTemplateValidForVarrays(cvp.getVirtualArrays(), addedTemplate.getId())) {
                        throw APIException.badRequests.sptIsNotValidForVarrays(addedTemplate.getLabel());
                    }
                    validateServiceProfileTemplate(cvp, addedTemplate);
                    sptsAddedToCvp.add(addedTemplate.getId().toString());
                    sptsForCvpUpdated = true;
                    _log.debug("Compute Virtual Pool will be assigned to service profile template {}", addedTemplate.getId().toASCIIString());
                }
            }
        }
        // Validate that the Service Profile Templates to be unassigned from the
        // Compute Virtual Pool reference existing Service Profile Templates in the database
        // and remove them from the CVP.
        ServiceProfileTemplateAssignments removeAssignments = sptAssignmentChanges.getRemove();
        if (removeAssignments != null) {
            Collection<UCSServiceProfileTemplate> removedTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(removeAssignments.getServiceProfileTemplates()));
            if ((removedTemplates != null) && (!removedTemplates.isEmpty())) {
                _log.debug("Request specifies service profile templates to be removed.");
                // If vcp is in use, SPTs cannot be removed - for the 2.2 release
                if (isComputeVirtualPoolInUse(cvp)) {
                    throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot remove service profile template since virtual compute pool is already in use.");
                }
                // Iterate over the service profile templates and unassign from the CVP
                StringSet currentAssignments = cvp.getServiceProfileTemplates();
                for (UCSServiceProfileTemplate removedTemplate : removedTemplates) {
                    if ((currentAssignments == null) || (!currentAssignments.contains(removedTemplate.getId().toString()))) {
                        // Just ignore those not assigned.
                        _log.debug("Compute Virtual Pool is not assigned to service profile template {}", removedTemplate.getId().toString());
                        continue;
                    }
                    if (isServiceProfileTemplateInUse(cvp, removedTemplate)) {
                        throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Cannot remove service profile template already in use.");
                    }
                    sptsRemovedFromCvp.add(removedTemplate.getId().toString());
                    sptsForCvpUpdated = true;
                    _log.info("Compute Virtual Pool will be unassigned from service profile template {}", removedTemplate.getId().toString());
                }
            }
        }
        // At this point all spt's being added have been verified
        // now make sure that only one spt per compute system
        Set<String> sptsCurrentAfterRemove = cvp.getServiceProfileTemplates();
        if (removeAssignments != null) {
            Collection<UCSServiceProfileTemplate> removedTempls = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(removeAssignments.getServiceProfileTemplates()));
            Set<String> removedIDs = new HashSet<String>();
            for (UCSServiceProfileTemplate rmvdTempl : removedTempls) {
                removedIDs.add(rmvdTempl.getId().toString());
            }
            sptsCurrentAfterRemove.removeAll(removedIDs);
        }
        Set<URI> sptComputeSystems = new HashSet<URI>();
        // Iterate over all SPTs in returned in the param stringset
        Collection<UCSServiceProfileTemplate> addedTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(sptsAddedToCvp));
        for (UCSServiceProfileTemplate template : addedTemplates) {
            _log.debug("Adding SPT : " + template.getId().toString());
            if (sptComputeSystems.contains(template.getComputeSystem())) {
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Service profile template already in use and associated to compute system.");
            } else {
                sptComputeSystems.add(template.getComputeSystem());
            }
        }
        Collection<UCSServiceProfileTemplate> existingTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(sptsCurrentAfterRemove));
        for (UCSServiceProfileTemplate template : existingTemplates) {
            _log.debug("Adding SPT : " + template.getId().toString());
            if (sptComputeSystems.contains(template.getComputeSystem())) {
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Duplicate compute system association.  Only one service profile template can be associated to a compute system in a Compute Virtual Pool.");
            } else {
                sptComputeSystems.add(template.getComputeSystem());
            }
        }
    }
    // Persist virtual array changes for the Compute Virtual Pool, if any.
    if (sptsForCvpUpdated) {
        if (!sptsAddedToCvp.isEmpty()) {
            cvp.addServiceProfileTemplates(sptsAddedToCvp);
        }
        if (!sptsRemovedFromCvp.isEmpty()) {
            cvp.removeServiceProfileTemplates(sptsRemovedFromCvp);
        }
    }
    return sptsForCvpUpdated;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) HashMap(java.util.HashMap) StringSet(com.emc.storageos.db.client.model.StringSet) ServiceProfileTemplateAssignments(com.emc.storageos.model.vpool.ServiceProfileTemplateAssignments) URI(java.net.URI) HashSet(java.util.HashSet)

Example 17 with UCSServiceProfileTemplate

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

the class ComputeSystemService method isServiceProfileTemplateValidForVarrays.

/*
     * Check whether the SPT's vsans are in atleast one of the varrays' networks. If yes, valid.
     */
public boolean isServiceProfileTemplateValidForVarrays(StringSet varrayIds, URI sptId) {
    boolean isValid = true;
    UCSServiceProfileTemplate template = (UCSServiceProfileTemplate) _dbClient.queryObject(sptId);
    Set<String> networkVsanIds = new HashSet<String>();
    URIQueryResultList uriVhbas = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeElemetHBAsConstraint(sptId), uriVhbas);
    List<ComputeElementHBA> vhbas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
    // Filter out SPTs without any vhbas
    if ((vhbas == null) || vhbas.isEmpty()) {
        isValid = false;
        _log.info("ServiceProfileTemplate " + template.getLabel() + " does not have any vhbas and hence is not valid for use.");
        return isValid;
    }
    for (String varrayId : varrayIds) {
        // get varray networks
        List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, URI.create(varrayId), Network.class, "connectedVirtualArrays");
        // collect network vsanIds
        Set<String> varrayNetworkVsanIds = new HashSet<String>();
        for (Network network : networks) {
            if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType())) {
                varrayNetworkVsanIds.add(network.getNativeId());
            // _log.debug("varray vsan :"+ network.getNativeId());
            }
        }
        if (networkVsanIds.isEmpty()) {
            networkVsanIds.addAll(varrayNetworkVsanIds);
        } else {
            networkVsanIds.retainAll(varrayNetworkVsanIds);
        }
        for (ComputeElementHBA vhba : vhbas) {
            String vsanId = vhba.getVsanId();
            _log.debug("vhba vsan:" + vsanId);
            if (!networkVsanIds.contains(vsanId)) {
                isValid = false;
                _log.error("SPT " + template.getLabel() + " has hba on vsan " + vsanId + " not included in varray " + varrayId);
                return isValid;
            }
        }
    }
    if (template.getUpdating()) {
        isValid = isUpdatingSPTValidForVarrays(varrayIds, template);
    }
    return isValid;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) Network(com.emc.storageos.db.client.model.Network) ComputeElementHBA(com.emc.storageos.db.client.model.ComputeElementHBA) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Example 18 with UCSServiceProfileTemplate

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

the class ComputeVirtualPoolService method validateAndSetSpts.

private void validateAndSetSpts(ComputeVirtualPool cvp, Set<String> addSpts) {
    _log.debug("System type = " + cvp.getSystemType());
    if (cvp.getSystemType().contentEquals(ComputeVirtualPool.SupportedSystemTypes.Cisco_UCSM.toString())) {
        // Process Service Profile Templates
        _log.debug("Processing Service Profile Templates");
        if (addSpts != null && !addSpts.isEmpty()) {
            _log.debug("Found SPTs to add");
            for (String spt : addSpts) {
                URI sptURI = URI.create(spt);
                ArgValidator.checkUri(sptURI);
                this.queryObject(UCSServiceProfileTemplate.class, sptURI, true);
            }
            // Initialize set of compute systems used
            Set<URI> sptComputeSystems = new HashSet<URI>();
            cvp.setServiceProfileTemplates(new StringSet());
            // Iterate over all SPTs in returned in the param stringset
            Collection<UCSServiceProfileTemplate> templates = _dbClient.queryObject(UCSServiceProfileTemplate.class, toUriList(addSpts));
            if (addSpts.size() != templates.size()) {
                throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Invalid service profile template specified.");
            }
            for (UCSServiceProfileTemplate template : templates) {
                _log.debug("Adding SPT : " + template.getId().toString());
                // verify the SPT exists in the db
                ArgValidator.checkEntity(template, template.getId(), isIdEmbeddedInURL(template.getId()));
                // verify that there was not already an SPT with the same compute system (check set)
                if (sptComputeSystems.contains(template.getComputeSystem())) {
                    throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Duplicate assignment of service profile template for compute system. Only one service profile template per compute system is permitted.");
                }
                // verify the number of nic and hbas match the associated ranges (if set)
                if (cvp.getMinNics() != null) {
                    ArgValidator.checkFieldMinimum(template.getNumberOfVNICS(), cvp.getMinNics(), "service_profile_template");
                }
                if (cvp.getMaxNics() != null && (cvp.getMaxNics() != -1)) {
                    ArgValidator.checkFieldMaximum(template.getNumberOfVNICS(), cvp.getMaxNics(), "service_profile_template");
                }
                if (cvp.getMinHbas() != null) {
                    ArgValidator.checkFieldMinimum(template.getNumberOfVHBAS(), cvp.getMinHbas(), "service_profile_template");
                }
                if (cvp.getMaxHbas() != null && (cvp.getMaxHbas() != -1)) {
                    ArgValidator.checkFieldMaximum(template.getNumberOfVHBAS(), cvp.getMaxHbas(), "service_profile_template");
                }
                if (template.getUpdating() == true) {
                    if (!computeSystemService.isUpdatingSPTValid(template, _dbClient)) {
                        throw APIException.badRequests.changeToComputeVirtualPoolNotSupported(cvp.getLabel(), "Nic or hba names in updating service profile template " + template.getLabel() + " do not match those in its boot policy.");
                    }
                }
                if (!computeSystemService.isServiceProfileTemplateValidForVarrays(cvp.getVirtualArrays(), template.getId())) {
                    throw APIException.badRequests.sptIsNotValidForVarrays(template.getLabel());
                }
                // add the spt to the VCP
                cvp.getServiceProfileTemplates().add(template.getId().toString());
                // update the set of compute systems used
                sptComputeSystems.add(template.getComputeSystem());
            }
        }
    }
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) HashSet(java.util.HashSet)

Example 19 with UCSServiceProfileTemplate

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

the class ComputeVirtualPoolMapper method toComputeVirtualPool.

public static ComputeVirtualPoolRestRep toComputeVirtualPool(DbClient dbClient, ComputeVirtualPool from, boolean inUse) {
    if (from == null) {
        return null;
    }
    ComputeVirtualPoolRestRep to = new ComputeVirtualPoolRestRep();
    to.setDescription(from.getDescription());
    to.setSystemType(from.getSystemType());
    to.setMinProcessors(translateDbValueToClientValue(from.getMinProcessors()));
    to.setMaxProcessors(translateDbValueToClientValue(from.getMaxProcessors()));
    to.setMinTotalCores(translateDbValueToClientValue(from.getMinTotalCores()));
    to.setMaxTotalCores(translateDbValueToClientValue(from.getMaxTotalCores()));
    to.setMinTotalThreads(translateDbValueToClientValue(from.getMinTotalThreads()));
    to.setMaxTotalThreads(translateDbValueToClientValue(from.getMaxTotalThreads()));
    to.setMinCpuSpeed(translateDbValueToClientValue(from.getMinCpuSpeed()));
    to.setMaxCpuSpeed(translateDbValueToClientValue(from.getMaxCpuSpeed()));
    to.setMinMemory(translateDbValueToClientValue(from.getMinMemory()));
    to.setMaxMemory(translateDbValueToClientValue(from.getMaxMemory()));
    to.setMinNics(translateDbValueToClientValue(from.getMinNics()));
    to.setMaxNics(translateDbValueToClientValue(from.getMaxNics()));
    to.setMinHbas(translateDbValueToClientValue(from.getMinHbas()));
    to.setMaxHbas(translateDbValueToClientValue(from.getMaxHbas()));
    if (from.getVirtualArrays() != null) {
        for (String varray : from.getVirtualArrays()) {
            to.getVirtualArrays().add(toRelatedResource(ResourceTypeEnum.VARRAY, URI.create(varray)));
        }
    }
    to.setUseMatchedElements(from.getUseMatchedElements());
    to.setInUse(inUse);
    if (from.getMatchedComputeElements() != null) {
        for (String ce : from.getMatchedComputeElements()) {
            to.getMatchedComputeElements().add(toRelatedResource(ResourceTypeEnum.COMPUTE_ELEMENT, URI.create(ce)));
        }
    }
    if (dbClient != null) {
        if (from.getServiceProfileTemplates() != null) {
            for (String spt : from.getServiceProfileTemplates()) {
                URI sptURI = URI.create(spt);
                UCSServiceProfileTemplate template = dbClient.queryObject(UCSServiceProfileTemplate.class, sptURI);
                NamedRelatedResourceRep sptNamedRelatedResource = new NamedRelatedResourceRep();
                sptNamedRelatedResource.setId(template.getId());
                sptNamedRelatedResource.setName(template.getLabel());
                to.getServiceProfileTemplates().add(sptNamedRelatedResource);
            }
        }
        if (from.getMatchedComputeElements() != null) {
            to.getAvailableMatchedComputeElements().addAll(getAvailableComputeElements(dbClient, from.getMatchedComputeElements()));
        }
    }
    mapDataObjectFields(from, to);
    return to;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ComputeVirtualPoolRestRep(com.emc.storageos.model.vpool.ComputeVirtualPoolRestRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI)

Aggregations

UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)19 URI (java.net.URI)11 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)8 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)6 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)4 DataObject (com.emc.storageos.db.client.model.DataObject)4 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)4 StringSet (com.emc.storageos.db.client.model.StringSet)4 ComputeElementHBA (com.emc.storageos.db.client.model.ComputeElementHBA)3 DiscoveredSystemObject (com.emc.storageos.db.client.model.DiscoveredSystemObject)3 Host (com.emc.storageos.db.client.model.Host)3 List (java.util.List)3 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)2 VnicFc (com.emc.cloud.platform.ucs.out.model.VnicFc)2 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)2