Search in sources :

Example 1 with ComputeElementListRestRep

use of com.emc.storageos.model.compute.ComputeElementListRestRep in project coprhd-controller by CoprHD.

the class ComputeSystemService method deregisterComputeSystem.

/**
 * De-registers a previously registered Compute System. (Creation and
 * Discovery of the Compute System marks the Compute System "Registered" by
 * default)
 *
 * @param id
 *            the URN of a ViPR Compute System
 * @brief Deregister compute system
 * @return A detailed representation of the Compute System
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeSystemRestRep deregisterComputeSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the storage system.
    ArgValidator.checkUri(id);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, id);
    ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(cs.getRegistrationStatus())) {
        cs.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(cs);
        // Fetch all unprovisioned blades for this CS; remove them from any CVPs they are part of
        ComputeElementListRestRep result = getComputeElements(cs.getId());
        List<ComputeElementRestRep> blades = result.getList();
        List<URI> unprovisionedBlades = new ArrayList<URI>();
        for (ComputeElementRestRep ce : blades) {
            if (ce.getAvailable()) {
                unprovisionedBlades.add(ce.getId());
                _log.debug("Found unprovisioned blade:" + ce.getName());
            }
        }
        List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
        Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
        while (iter.hasNext()) {
            ComputeVirtualPool cvp = iter.next();
            _log.debug("Remove unprovisioned blades from cvp: " + cvp.getLabel());
            StringSet currentElements = new StringSet();
            if (cvp.getMatchedComputeElements() != null) {
                currentElements.addAll(cvp.getMatchedComputeElements());
                for (URI bladeId : unprovisionedBlades) {
                    currentElements.remove(bladeId.toString());
                }
            }
            cvp.setMatchedComputeElements(currentElements);
            _dbClient.updateAndReindexObject(cvp);
            _log.debug("Removed ces from cvp");
        }
        recordAndAudit(cs, OperationTypeEnum.DEREGISTER_COMPUTE_SYSTEM, true, null);
    }
    return getComputeSystem(id);
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with ComputeElementListRestRep

use of com.emc.storageos.model.compute.ComputeElementListRestRep in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolService method extractComputeElements.

private ComputeElementListRestRep extractComputeElements(ComputeVirtualPool cvp) {
    ComputeElementListRestRep result = new ComputeElementListRestRep();
    if (cvp.getMatchedComputeElements() != null) {
        Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, toUriList(cvp.getMatchedComputeElements()));
        Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
        Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "computeElement", "cluster"), ControllerUtils.getFullyImplementedCollection(hostIds));
        for (ComputeElement computeElement : computeElements) {
            if (computeElement != null) {
                Host associatedHost = null;
                for (Host host : hosts) {
                    if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement().equals(computeElement.getId())) {
                        associatedHost = host;
                        break;
                    }
                }
                Cluster cluster = null;
                if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
                    cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
                }
                ComputeElementRestRep rest = map(computeElement, associatedHost, cluster);
                result.getList().add(rest);
            }
        }
    }
    return result;
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI)

Example 3 with ComputeElementListRestRep

use of com.emc.storageos.model.compute.ComputeElementListRestRep in project coprhd-controller by CoprHD.

the class ComputeSystemServiceApiTest method testComputeElements.

@Test(groups = "runByDefault", dependsOnMethods = "testCreateComputeSystem")
public void testComputeElements() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (computeSystem == null) {
        Assert.fail("Unable to run the test as there's no Compute System to run the test against");
    }
    ComputeElementListRestRep computeElementList = rSys.path(COMPUTE_SYSTEM_RESOURCE + "/" + computeSystem.getId() + COMPUTE_ELEMENTS_RELATIVE_PATH).get(ComputeElementListRestRep.class);
    ComputeElementRestRep computeElementToDeAndReRegister = null;
    for (ComputeElementRestRep computeElement : computeElementList.getList()) {
        if (RegistrationStatus.REGISTERED.name().equals(computeElement.getRegistrationStatus())) {
            computeElementToDeAndReRegister = computeElement;
        }
        System.out.println(BeanUtils.describe(computeElement));
    }
    if (computeElementToDeAndReRegister != null) {
        System.out.println("De-registering compute element: " + BeanUtils.describe(computeElementToDeAndReRegister));
        computeElementToDeAndReRegister = rSys.path(COMPUTE_ELEMENT_RESOURCE + "/" + computeElementToDeAndReRegister.getId() + DEREGISTER_RELATIVE_PATH).post(ComputeElementRestRep.class);
        Assert.assertEquals(computeElementToDeAndReRegister.getRegistrationStatus(), RegistrationStatus.UNREGISTERED.name());
        System.out.println("De-registered compute element: " + BeanUtils.describe(computeElementToDeAndReRegister));
        System.out.println("Re-registering compute element: " + BeanUtils.describe(computeElementToDeAndReRegister));
        computeElementToDeAndReRegister = rSys.path(COMPUTE_ELEMENT_RESOURCE + "/" + computeElementToDeAndReRegister.getId() + REGISTER_RELATIVE_PATH).post(ComputeElementRestRep.class);
        Assert.assertEquals(computeElementToDeAndReRegister.getRegistrationStatus(), RegistrationStatus.REGISTERED.name());
        System.out.println("Re-registered compute element: " + BeanUtils.describe(computeElementToDeAndReRegister));
    }
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) Test(org.testng.annotations.Test)

Example 4 with ComputeElementListRestRep

use of com.emc.storageos.model.compute.ComputeElementListRestRep in project coprhd-controller by CoprHD.

the class HostService method findComputeElementsMatchingVarrayAndCVP.

/*
     * Returns a map of compute system URI to compute elements available on that compute system
     */
private Map<URI, List<URI>> findComputeElementsMatchingVarrayAndCVP(ComputeVirtualPool cvp, VirtualArray varray) {
    Map<URI, List<URI>> computeSystemToComputeElementsMap = new HashMap<URI, List<URI>>();
    _log.debug("Look up compute elements for cvp " + cvp.getId());
    List<String> cvpCEList = new ArrayList<String>();
    if (cvp.getMatchedComputeElements() != null) {
        Iterator<String> iter = cvp.getMatchedComputeElements().iterator();
        while (iter.hasNext()) {
            String uriStr = iter.next();
            cvpCEList.add(uriStr);
        }
    }
    // Find all SPTs assigned for this CVP and their corresponding ComputeSystems
    Map<URI, URI> cvpTemplatesMap = new HashMap<URI, URI>();
    if (cvp.getServiceProfileTemplates() != null) {
        for (String templateIdString : cvp.getServiceProfileTemplates()) {
            URI templateId = URI.create(templateIdString);
            UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, templateId);
            if (template.getUpdating() == true) {
                if (!computeSystemService.isUpdatingSPTValid(template, _dbClient)) {
                    throw APIException.badRequests.invalidUpdatingSPT(template.getLabel());
                }
                StringSet varrayIds = new StringSet();
                varrayIds.add(varray.getId().toString());
                if (!computeSystemService.isServiceProfileTemplateValidForVarrays(varrayIds, templateId)) {
                    throw APIException.badRequests.incompatibleSPT(template.getLabel(), varray.getLabel());
                }
            }
            cvpTemplatesMap.put(template.getComputeSystem(), templateId);
        }
    }
    _log.debug("Look up compute systems for virtual array " + varray.getId());
    ComputeSystemBulkRep computeSystemBulkRep = virtualArrayService.getComputeSystems(varray.getId());
    if (computeSystemBulkRep.getComputeSystems() != null) {
        for (ComputeSystemRestRep computeSystemRestRep : computeSystemBulkRep.getComputeSystems()) {
            _log.debug("Found compute system " + computeSystemRestRep.getId() + " for virtual array " + varray.getId());
            if (!cvpTemplatesMap.containsKey(computeSystemRestRep.getId())) {
                _log.info("The CVP has no service profile templates assigned from compute system " + computeSystemRestRep.getName() + ". So no blades will be used from this compute system.");
                continue;
            }
            ComputeElementListRestRep computeElementListRestRep = computeSystemService.getComputeElements(computeSystemRestRep.getId());
            if (computeElementListRestRep.getList() != null) {
                List<URI> computeElementList = new ArrayList<URI>();
                for (ComputeElementRestRep computeElementRestRep : computeElementListRestRep.getList()) {
                    _log.debug("Compute system contains compute element " + computeElementRestRep.getId());
                    for (String computeElement : cvpCEList) {
                        if (computeElement.equals(computeElementRestRep.getId().toString())) {
                            if (computeElementRestRep.getAvailable() && computeElementRestRep.getRegistrationStatus().equals(RegistrationStatus.REGISTERED.name())) {
                                computeElementList.add(computeElementRestRep.getId());
                                _log.debug("Added compute element " + computeElementRestRep.getId());
                            } else {
                                _log.debug("found unavailable compute element" + computeElementRestRep.getId());
                            }
                        }
                    }
                }
                computeSystemToComputeElementsMap.put(computeSystemRestRep.getId(), computeElementList);
            }
        }
    } else {
        throw APIException.badRequests.noComputeSystemsFoundForVarray();
    }
    return computeSystemToComputeElementsMap;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI) ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeSystemBulkRep(com.emc.storageos.model.compute.ComputeSystemBulkRep) UnManagedExportMaskList(com.emc.storageos.model.block.UnManagedExportMaskList) UnManagedVolumeList(com.emc.storageos.model.block.UnManagedVolumeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InitiatorList(com.emc.storageos.model.host.InitiatorList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) LinkedList(java.util.LinkedList) IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) ComputeSystemRestRep(com.emc.storageos.model.compute.ComputeSystemRestRep)

Example 5 with ComputeElementListRestRep

use of com.emc.storageos.model.compute.ComputeElementListRestRep in project coprhd-controller by CoprHD.

the class ComputeVirtualPoolService method findComputeElementsFromDeviceAssociations.

private List<URI> findComputeElementsFromDeviceAssociations(ComputeVirtualPool computeVirtualPool) {
    // Get CEs from associated varrays
    List<URI> ceList = new ArrayList<URI>();
    if (computeVirtualPool.getVirtualArrays() != null) {
        for (String virtualArrayId : computeVirtualPool.getVirtualArrays()) {
            URI virtualArrayURI = URI.create(virtualArrayId);
            ArgValidator.checkUri(virtualArrayURI);
            this.queryObject(VirtualArray.class, virtualArrayURI, true);
            _log.debug("Look up compute systems for virtual array " + virtualArrayURI);
            ComputeSystemBulkRep computeSystemBulkRep = virtualArrayService.getComputeSystems(virtualArrayURI);
            if (computeSystemBulkRep.getComputeSystems() != null) {
                for (ComputeSystemRestRep computeSystemRestRep : computeSystemBulkRep.getComputeSystems()) {
                    _log.debug("Found compute system " + computeSystemRestRep.getId() + " for virtual array " + virtualArrayURI);
                    ComputeElementListRestRep computeElementListRestRep = computeSystemService.getComputeElements(computeSystemRestRep.getId());
                    if (computeElementListRestRep.getList() != null) {
                        for (ComputeElementRestRep computeElementRestRep : computeElementListRestRep.getList()) {
                            _log.debug("Compute system contains compute element " + computeElementRestRep.getId());
                            ceList.add(computeElementRestRep.getId());
                        }
                    }
                }
            }
        }
    }
    return ceList;
}
Also used : ComputeElementListRestRep(com.emc.storageos.model.compute.ComputeElementListRestRep) ArrayList(java.util.ArrayList) ComputeSystemBulkRep(com.emc.storageos.model.compute.ComputeSystemBulkRep) ComputeSystemRestRep(com.emc.storageos.model.compute.ComputeSystemRestRep) ComputeElementRestRep(com.emc.storageos.model.compute.ComputeElementRestRep) URI(java.net.URI)

Aggregations

ComputeElementListRestRep (com.emc.storageos.model.compute.ComputeElementListRestRep)7 ComputeElementRestRep (com.emc.storageos.model.compute.ComputeElementRestRep)7 URI (java.net.URI)5 ArrayList (java.util.ArrayList)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 Host (com.emc.storageos.db.client.model.Host)3 Cluster (com.emc.storageos.db.client.model.Cluster)2 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ComputeLanBootImagePath (com.emc.storageos.db.client.model.ComputeLanBootImagePath)2 ComputeSanBootImagePath (com.emc.storageos.db.client.model.ComputeSanBootImagePath)2 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 ComputeSystemBulkRep (com.emc.storageos.model.compute.ComputeSystemBulkRep)2 ComputeSystemRestRep (com.emc.storageos.model.compute.ComputeSystemRestRep)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)1