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);
}
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();
}
}
}
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;
}
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;
}
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;
}
Aggregations