use of com.emc.storageos.model.compute.ComputeElementRestRep in project coprhd-controller by CoprHD.
the class ComputeElementService method queryBulkResourceReps.
@Override
public ComputeElementBulkRep queryBulkResourceReps(List<URI> ids) {
Iterator<ComputeElement> _dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
return new ComputeElementBulkRep(BulkList.wrapping(_dbIterator, new Function<ComputeElement, ComputeElementRestRep>() {
@Override
public ComputeElementRestRep apply(ComputeElement ce) {
Host associatedHost = getAssociatedHost(ce, _dbClient);
Cluster cluster = null;
if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
}
ComputeElementRestRep restRep = ComputeMapper.map(ce, associatedHost, cluster);
return restRep;
}
}));
}
use of com.emc.storageos.model.compute.ComputeElementRestRep 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);
}
use of com.emc.storageos.model.compute.ComputeElementRestRep 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;
}
use of com.emc.storageos.model.compute.ComputeElementRestRep 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));
}
}
use of com.emc.storageos.model.compute.ComputeElementRestRep in project coprhd-controller by CoprHD.
the class ComputeSystems method elementDetails.
public static void elementDetails(String id) {
ComputeElementRestRep computeElement = ComputeSystemUtils.getComputeElement(id);
if (computeElement == null) {
error(MessagesUtils.get(UNKNOWN, id));
}
render(computeElement);
}
Aggregations