Search in sources :

Example 1 with ServiceProfileTemplateAssignments

use of com.emc.storageos.model.vpool.ServiceProfileTemplateAssignments in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolService method verifySptAssignmentChanges.

/**
 * Verifies the service profile template assignment changes in the update request are
 * valid, else throws a bad request exception.
 *
 * @param cvp - A reference to a Compute Virtual Pool.
 * @param sptAssignmentChanges The service profile template assignment changes in a
 *            compute virtual pool update request.
 */
private void verifySptAssignmentChanges(ComputeVirtualPool cvp, ServiceProfileTemplateAssignmentChanges sptAssignmentChanges) {
    // Verify the add/remove sets do not overlap.
    ServiceProfileTemplateAssignments addAssignments = sptAssignmentChanges.getAdd();
    ServiceProfileTemplateAssignments removeAssignments = sptAssignmentChanges.getRemove();
    if ((addAssignments != null) && (removeAssignments != null)) {
        Set<String> addSpts = addAssignments.getServiceProfileTemplates();
        Set<String> removeSpts = removeAssignments.getServiceProfileTemplates();
        if ((addSpts != null) && (removeSpts != null)) {
            Set<String> addSet = new HashSet<String>(addSpts);
            Set<String> removeSet = new HashSet<String>(removeSpts);
            addSet.retainAll(removeSet);
            if (!addSet.isEmpty()) {
                _log.error("Request specifies the same service profile templates (s) in both the add and remove lists {}", addSet);
                // TODO: add more specific exception
                throw APIException.badRequests.sameVirtualArrayInAddRemoveList();
            }
        }
    }
}
Also used : ServiceProfileTemplateAssignments(com.emc.storageos.model.vpool.ServiceProfileTemplateAssignments) HashSet(java.util.HashSet)

Example 2 with ServiceProfileTemplateAssignments

use of com.emc.storageos.model.vpool.ServiceProfileTemplateAssignments 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)

Aggregations

ServiceProfileTemplateAssignments (com.emc.storageos.model.vpool.ServiceProfileTemplateAssignments)2 HashSet (java.util.HashSet)2 StringSet (com.emc.storageos.db.client.model.StringSet)1 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1