use of com.emc.storageos.db.client.model.ComputeElement 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);
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeElementService method registerComputeElement.
/**
* Manually register the discovered compute element with the passed id on the
* registered compute system with the passed id.
*
* @param computeElementId The id of the compute element.
*
* @brief Register compute system compute element
* @return A reference to a ComputeElementRestRep specifying the data for the
* registered compute element.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/{id}/register")
public ComputeElementRestRep registerComputeElement(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, ComputeElement.class, "id");
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
if (ce == null) {
throw APIException.badRequests.computeElementNotFound(id);
}
if (ce.getComputeSystem() == null) {
throw APIException.badRequests.computeElementNotBelongingToSystem(id, null);
} else {
ComputeSystemUtils.queryRegisteredSystem(ce.getComputeSystem(), _dbClient, isIdEmbeddedInURL(ce.getComputeSystem()));
}
// if not registered, registered it. Otherwise, dont do anything
if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(ce.getRegistrationStatus())) {
registerComputeElement(ce);
List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
while (iter.hasNext()) {
ComputeVirtualPool cvp = iter.next();
if (cvp.getUseMatchedElements()) {
_log.debug("Compute pool " + cvp.getLabel() + " configured to use dynamic matching -- refresh matched elements");
computeVirtualPoolService.getMatchingCEsforCVPAttributes(cvp);
_dbClient.updateAndReindexObject(cvp);
}
}
}
return map(ce, null, null);
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeElementService method queryResource.
@Override
protected ComputeElement queryResource(URI id) {
ArgValidator.checkUri(id);
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
return ce;
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeVirtualPoolService method getMatchingCEsforCVPAttributes.
public void getMatchingCEsforCVPAttributes(ComputeVirtualPool cvp) {
if (cvp.getMatchedComputeElements() != null) {
cvp.getMatchedComputeElements().clear();
}
String sysType = null;
if (cvp.getSystemType() != null) {
if (cvp.getSystemType().contentEquals(ComputeVirtualPool.SupportedSystemTypes.Cisco_UCSM.toString())) {
sysType = "ucs";
}
}
if (sysType != null) {
_log.debug("Iterating over all CEs");
List<URI> ceList = findComputeElementsFromDeviceAssociations(cvp);
List<URI> staticallyAssignedComputeElements = findAllStaticallyAssignedComputeElementsInOtherPools(cvp);
StringSet ceIds = new StringSet();
Collection<ComputeElement> computeElements = _dbClient.queryObject(ComputeElement.class, ceList);
for (ComputeElement ce : computeElements) {
if (ce.getSystemType() == null) {
continue;
}
if (!ce.getSystemType().contentEquals((CharSequence) sysType)) {
continue;
}
if (!isRegistered(ce)) {
continue;
}
if (staticallyAssignedComputeElements.contains(ce.getId())) {
_log.debug("Compute element " + ce.getId() + " has been statically assigned and will be filtered out");
continue;
}
if (isParamSet(cvp.getMinTotalCores()) && (ce.getNumOfCores() < cvp.getMinTotalCores())) {
continue;
}
if (isParamSet(cvp.getMaxTotalCores()) && (cvp.getMaxTotalCores() != -1) && (ce.getNumOfCores() > cvp.getMaxTotalCores())) {
continue;
}
if (isParamSet(cvp.getMinProcessors()) && (ce.getNumberOfProcessors() < cvp.getMinProcessors())) {
continue;
}
if (isParamSet(cvp.getMaxProcessors()) && (cvp.getMaxProcessors() != -1) && (ce.getNumberOfProcessors() > cvp.getMaxProcessors())) {
continue;
}
if (isParamSet(cvp.getMinTotalThreads()) && (ce.getNumberOfThreads() < cvp.getMinTotalThreads())) {
continue;
}
if (isParamSet(cvp.getMaxTotalThreads()) && (cvp.getMaxTotalThreads() != -1) && (ce.getNumberOfThreads() > cvp.getMaxTotalThreads())) {
continue;
}
float ceSpeed = Float.parseFloat(ce.getProcessorSpeed());
if (isParamSet(cvp.getMinCpuSpeed())) {
if (ceSpeed < (float) cvp.getMinCpuSpeed()) {
continue;
}
}
if (isParamSet(cvp.getMaxCpuSpeed()) && (cvp.getMaxCpuSpeed() != -1)) {
if (ceSpeed > (float) cvp.getMaxCpuSpeed()) {
continue;
}
}
if (isParamSet(cvp.getMinMemory()) && (ce.getRam() / 1024 < cvp.getMinMemory())) {
continue;
}
if (isParamSet(cvp.getMaxMemory()) && (cvp.getMaxMemory() != -1) && (ce.getRam() / 1024 > cvp.getMaxMemory())) {
continue;
}
ceIds.add(ce.getId().toASCIIString());
}
cvp.addMatchedComputeElements(ceIds);
Integer size = cvp.getMatchedComputeElements() != null ? cvp.getMatchedComputeElements().size() : 0;
_log.debug("putting CEs in the pool, cnt: " + size);
}
}
use of com.emc.storageos.db.client.model.ComputeElement 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;
}
Aggregations