Search in sources :

Example 6 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method constructAndValidateComputeVirtualPool.

private ComputeVirtualPool constructAndValidateComputeVirtualPool(ComputeVirtualPoolCreateParam param) throws DatabaseException {
    // Initial Validations
    if (param.getSystemType() != null) {
        ArgValidator.checkFieldValueFromEnum(param.getSystemType(), "system_type", ComputeVirtualPool.SupportedSystemTypes.class);
    } else {
        throw APIException.badRequests.requiredParameterMissingOrEmpty("system_type");
    }
    validateMinMaxIntValues(param.getMinProcessors(), param.getMaxProcessors(), "min_processors", "max_processors");
    validateMinMaxIntValues(param.getMinTotalCores(), param.getMaxTotalCores(), "min_total_cores", "max_total_cores");
    validateMinMaxIntValues(param.getMinTotalThreads(), param.getMaxTotalThreads(), "min_total_threads", "max_total_threads");
    validateMinMaxIntValues(param.getMinCpuSpeed(), param.getMaxCpuSpeed(), "min_cpu_speed", "max_cpu_speed");
    validateMinMaxIntValues(param.getMinMemory(), param.getMaxMemory(), "min_memory", "max_memory");
    validateMinMaxIntValues(param.getMinNics(), param.getMaxNics(), "min_nics", "max_nics");
    validateMinMaxIntValues(param.getMinHbas(), param.getMaxHbas(), "min_hbas", "max_hbas");
    // Create Compute Virtual Pool
    ComputeVirtualPool cvp = new ComputeVirtualPool();
    // Populate Virtual Pool
    if (NullColumnValueGetter.isNotNullValue(param.getId())) {
        cvp.setId(URI.create(param.getId()));
    } else {
        cvp.setId(URIUtil.createId(ComputeVirtualPool.class));
    }
    cvp.setLabel(param.getName());
    cvp.setDescription(param.getDescription());
    cvp.setSystemType(param.getSystemType());
    cvp.setMinProcessors(param.getMinProcessors());
    cvp.setMaxProcessors(param.getMaxProcessors());
    cvp.setMinTotalCores(param.getMinTotalCores());
    cvp.setMaxTotalCores(param.getMaxTotalCores());
    cvp.setMinTotalThreads(param.getMinTotalThreads());
    cvp.setMaxTotalThreads(param.getMaxTotalThreads());
    cvp.setMinCpuSpeed(param.getMinCpuSpeed());
    cvp.setMaxCpuSpeed(param.getMaxCpuSpeed());
    cvp.setMinMemory(param.getMinMemory());
    cvp.setMaxMemory(param.getMaxMemory());
    cvp.setMinNics(param.getMinNics());
    cvp.setMaxNics(param.getMaxNics());
    cvp.setMinHbas(param.getMinHbas());
    cvp.setMaxHbas(param.getMaxHbas());
    // Validate and set Virtual Arrays
    Set<String> addVarrays = param.getVarrays();
    if (addVarrays != null && !addVarrays.isEmpty()) {
        cvp.setVirtualArrays(new StringSet());
        for (String vArray : addVarrays) {
            URI vArrayURI = URI.create(vArray);
            ArgValidator.checkUri(vArrayURI);
            this.queryObject(VirtualArray.class, vArrayURI, true);
            cvp.getVirtualArrays().add(vArray);
        }
    }
    cvp.setUseMatchedElements(param.getUseMatchedElements());
    validateAndSetSpts(cvp, param.getServiceProfileTemplates());
    if (cvp.getUseMatchedElements()) {
        _log.debug("Compute pool " + cvp.getLabel() + " configured to use dynamic matching");
        getMatchingCEsforCVPAttributes(cvp);
    }
    return cvp;
}
Also used : 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)

Example 7 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method findAllStaticallyAssignedComputeElements.

private List<URI> findAllStaticallyAssignedComputeElements() {
    Collection<String> staticallyAssignedComputeElementUriStrings = new HashSet<String>();
    List<URI> computeVirtualPoolUris = _dbClient.queryByType(ComputeVirtualPool.class, true);
    Collection<ComputeVirtualPool> computeVirtualPools = _dbClient.queryObject(ComputeVirtualPool.class, computeVirtualPoolUris);
    for (ComputeVirtualPool computeVirtualPool : computeVirtualPools) {
        if (!computeVirtualPool.getUseMatchedElements()) {
            _log.debug("Compute pool " + computeVirtualPool.getLabel() + " using static matching");
            if (computeVirtualPool.getMatchedComputeElements() != null) {
                _log.debug("Compute pool " + computeVirtualPool.getLabel() + " has " + computeVirtualPool.getMatchedComputeElements().size() + " statically assigned compute elements");
                staticallyAssignedComputeElementUriStrings.addAll(computeVirtualPool.getMatchedComputeElements());
            }
        }
    }
    _log.debug("Found " + computeVirtualPools.size() + " compute pools using static matching containing the following compute elements: " + staticallyAssignedComputeElementUriStrings);
    return toUriList(staticallyAssignedComputeElementUriStrings);
}
Also used : URI(java.net.URI) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool) HashSet(java.util.HashSet)

Example 8 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method deleteComputeVirtualPool.

/**
 * Delete a Compute Virtual Pool
 *
 * @brief Delete a compute virtual pool
 * @param id The ID of Compute Virtual Pool
 * @return Response result
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteComputeVirtualPool(@PathParam("id") URI id) {
    ArgValidator.checkUri(id);
    ComputeVirtualPool cvp = _dbClient.queryObject(ComputeVirtualPool.class, id);
    ArgValidator.checkEntityNotNull(cvp, id, isIdEmbeddedInURL(id));
    // make sure cvp is unused by CE
    ArgValidator.checkReference(ComputeVirtualPool.class, id, checkForDelete(cvp));
    if (isComputeVirtualPoolInUse(cvp)) {
        throw APIException.badRequests.cannotRemoveVCP(cvp.getLabel());
    }
    _dbClient.markForDeletion(cvp);
    recordOperation(OperationTypeEnum.DELETE_COMPUTE_VPOOL, VPOOL_DELETED_DESCRIPTION, cvp);
    return Response.ok().build();
}
Also used : ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with ComputeVirtualPool

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

the class ComputeVirtualPoolService method queryResource.

@Override
protected DataObject queryResource(URI id) {
    ComputeVirtualPool cvp = _permissionsHelper.getObjectById(id, ComputeVirtualPool.class);
    ArgValidator.checkEntityNotNull(cvp, id, isIdEmbeddedInURL(id));
    return cvp;
}
Also used : ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeVirtualPoolMapper.toComputeVirtualPool(com.emc.storageos.api.mapper.ComputeVirtualPoolMapper.toComputeVirtualPool)

Example 10 with ComputeVirtualPool

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

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