Search in sources :

Example 81 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList 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 82 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ComputeImageServerService method checkActiveJobsForImageServer.

/**
 * Check if the given imageServer has any active computeImageJob
 * if so throws an appropriate exception
 * @param imageServerURI
 */
private void checkActiveJobsForImageServer(URI imageServerURI) {
    log.info("Check if any active ComputeImageJobs are present for imageServer id {} ", imageServerURI);
    // make sure there are no active jobs associated with this imageserver
    URIQueryResultList computeImageJobsUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByComputeImageServerConstraint(imageServerURI), computeImageJobsUriList);
    Iterator<URI> iterator = computeImageJobsUriList.iterator();
    while (iterator.hasNext()) {
        ComputeImageJob job = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
        if (job.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
            throw APIException.badRequests.cannotDeleteOrUpdateImageServerWhileInUse();
        }
    }
}
Also used : ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 83 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ComputeSystemService method getServiceProfileTemplatesForComputeSystem.

public List<NamedRelatedResourceRep> getServiceProfileTemplatesForComputeSystem(ComputeSystem cs, DbClient dbClient) {
    List<NamedRelatedResourceRep> serviceProfileTemplates = new ArrayList<NamedRelatedResourceRep>();
    URIQueryResultList sptIdList = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(cs.getId()), sptIdList);
    List<UCSServiceProfileTemplate> profileTemplateList = dbClient.queryObject(UCSServiceProfileTemplate.class, sptIdList, true);
    for (UCSServiceProfileTemplate serviceProfileTemplate : profileTemplateList) {
        if (!serviceProfileTemplate.getUpdating()) {
            NamedRelatedResourceRep sptNamedRelatedResource = new NamedRelatedResourceRep();
            sptNamedRelatedResource.setId(serviceProfileTemplate.getId());
            sptNamedRelatedResource.setName(serviceProfileTemplate.getLabel() + " (Initial Template)");
            serviceProfileTemplates.add(sptNamedRelatedResource);
        } else {
            _log.info(" updating service profile template:" + serviceProfileTemplate.getLabel() + " id:" + serviceProfileTemplate.getId().toString());
            boolean valid = isUpdatingSPTValid(serviceProfileTemplate, dbClient);
            if (valid) {
                NamedRelatedResourceRep sptNamedRelatedResource = new NamedRelatedResourceRep();
                sptNamedRelatedResource.setId(serviceProfileTemplate.getId());
                sptNamedRelatedResource.setName(serviceProfileTemplate.getLabel() + " (Updating Template)");
                serviceProfileTemplates.add(sptNamedRelatedResource);
            } else {
                _log.info("invalid uSPT");
            }
        }
    // TODO: Check if SPT uses updating vnic templates here. If so, it is invalid for use.
    }
    return serviceProfileTemplates;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 84 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ComputeSystemService method isSPTBootDefinitionValid.

private boolean isSPTBootDefinitionValid(UCSServiceProfileTemplate serviceProfileTemplate, ComputeBootDef bootDef) {
    boolean valid = true;
    _log.debug("validating SPT Boot Def " + bootDef.getId().toString());
    if (bootDef.getEnforceVnicVhbaNames() == true) {
        _log.debug("enforce vhba vnic names -- true");
        URIQueryResultList uriVhbas = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeElemetHBAsConstraint(serviceProfileTemplate.getId()), uriVhbas);
        List<ComputeElementHBA> vhbas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
        URIQueryResultList uriSanBoot = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeSanBootConstraint(bootDef.getId()), uriSanBoot);
        List<ComputeSanBoot> computeSanBoots = _dbClient.queryObject(ComputeSanBoot.class, uriSanBoot, true);
        if (computeSanBoots == null || computeSanBoots.isEmpty()) {
            _log.error("SPT: " + serviceProfileTemplate.getLabel() + " no san boot policy specified");
            valid = false;
        }
        for (ComputeSanBoot computeSanBoot : computeSanBoots) {
            if (!computeSanBoot.getIsFirstBootDevice()) {
                _log.error("SPT: " + serviceProfileTemplate.getLabel() + " san is not the first boot device");
                valid = false;
            }
            URIQueryResultList sanImageUris = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSanBootImageConstraint(computeSanBoot.getId()), sanImageUris);
            List<ComputeSanBootImage> sanBootImageList = _dbClient.queryObject(ComputeSanBootImage.class, sanImageUris, true);
            for (ComputeSanBootImage image : sanBootImageList) {
                boolean matched = false;
                for (ComputeElementHBA hba : vhbas) {
                    if (hba.getLabel().equals(image.getVnicName())) {
                        matched = true;
                    }
                }
                if (!matched) {
                    _log.error("SPT: " + serviceProfileTemplate.getLabel() + " enforces vnic and vhba names,but hba names in san boot policy do not match the names of the hbas on the template");
                    valid = false;
                }
            }
        }
        URIQueryResultList uriVnics = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeVnicsConstraint(serviceProfileTemplate.getId()), uriVnics);
        List<ComputeVnic> vnics = _dbClient.queryObject(ComputeVnic.class, uriVnics, true);
        URIQueryResultList uriLanBoot = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeLanBootConstraint(bootDef.getId()), uriLanBoot);
        List<ComputeLanBoot> computeLanBoots = _dbClient.queryObject(ComputeLanBoot.class, uriLanBoot, true);
        for (ComputeLanBoot computeLanBoot : computeLanBoots) {
            URIQueryResultList lanImageUris = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeLanBootImagePathsConstraint(computeLanBoot.getId()), lanImageUris);
            List<ComputeLanBootImagePath> lanBootImageList = _dbClient.queryObject(ComputeLanBootImagePath.class, lanImageUris, true);
            for (ComputeLanBootImagePath image : lanBootImageList) {
                boolean matched = false;
                for (ComputeVnic nic : vnics) {
                    if (nic.getName().equals(image.getVnicName())) {
                        matched = true;
                    }
                }
                if (!matched) {
                    _log.error("SPT: " + serviceProfileTemplate.getLabel() + " enforces vnic and vhba names,but vnic names in lan boot policy do not match the names of the hbas on the template");
                    valid = false;
                }
            }
        }
    }
    return valid;
}
Also used : ComputeSanBootImage(com.emc.storageos.db.client.model.ComputeSanBootImage) ComputeElementHBA(com.emc.storageos.db.client.model.ComputeElementHBA) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeLanBoot(com.emc.storageos.db.client.model.ComputeLanBoot) ComputeSanBoot(com.emc.storageos.db.client.model.ComputeSanBoot) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) ComputeVnic(com.emc.storageos.db.client.model.ComputeVnic)

Example 85 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class ComputeSystemService method isSanBootValidForVarrays.

private boolean isSanBootValidForVarrays(StringSet varrayIds, ComputeSanBoot computeSanBoot) {
    _log.debug("validate San Boot For Varrays");
    boolean isValid = true;
    if (computeSanBoot.getOrder() > 1) {
        _log.error("San boot should be the first boot device");
        isValid = false;
        return isValid;
    }
    URIQueryResultList sanImageUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSanBootImageConstraint(computeSanBoot.getId()), sanImageUris);
    List<ComputeSanBootImage> sanBootImageList = _dbClient.queryObject(ComputeSanBootImage.class, sanImageUris, true);
    for (ComputeSanBootImage image : sanBootImageList) {
        URIQueryResultList sanImagePathUris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSanBootImagePathConstraint(image.getId()), sanImagePathUris);
        List<ComputeSanBootImagePath> sanBootImagePathList = _dbClient.queryObject(ComputeSanBootImagePath.class, sanImagePathUris, true);
        // Validate the sanboot targets
        StringSet portWWPNs = new StringSet();
        for (ComputeSanBootImagePath imagePath : sanBootImagePathList) {
            String portWWPN = imagePath.getPortWWN();
            portWWPNs.add(portWWPN);
        }
        if (!portWWPNs.isEmpty()) {
            isValid = isSanBootTargetValidForVarrays(varrayIds, portWWPNs);
            if (!isValid) {
                return isValid;
            }
        } else {
            _log.debug("No san boot targets specified");
        }
    }
    return isValid;
}
Also used : ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeSanBootImage(com.emc.storageos.db.client.model.ComputeSanBootImage) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38