use of com.emc.storageos.db.client.model.Host 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.Host 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.db.client.model.Host in project coprhd-controller by CoprHD.
the class ExportGroupService method validateInitiatorsData.
/**
* Validates that the host belongs to same tenant org and/or project as the export group.
* Also validates that the host has connectivity to all the storage systems that the
* export group has block objects in.
*
* @param host the host being validated
* @param exportGroup the export group where the host will be added
* @param storageSystems the storage systems the export group has block objects in.
* @param project the export group project
* @param initiators the list of initiators to be updated with the host initiators.
*/
private void validateInitiatorsData(List<Initiator> initiators, Set<URI> initiatorsHosts, ExportGroup exportGroup) {
if (initiatorsHosts.size() != 1) {
throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
}
Host host = queryObject(Host.class, initiatorsHosts.iterator().next(), true);
// if the host is in a project
if (!NullColumnValueGetter.isNullURI(host.getProject())) {
// validate it is in the same project as the as the export group,
if (!host.getProject().equals(exportGroup.getProject().getURI())) {
throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentProject(host.getHostName(), exportGroup.getProject().getName());
}
} else {
// validate the host is in the same tenant Org as the as the export group,
Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
if (!host.getTenant().equals(project.getTenantOrg().getURI())) {
throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentTenant(host.getHostName(), project.getLabel());
}
}
validatePortConnectivity(exportGroup, initiators);
_log.info("The initiators were validated successfully.");
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ExportGroupService method validateInitiatorHostOS.
/**
* Validate that all the initiators to be added to the export group belong to the same host type
*
* @param initiators the list of initiators to validate
*/
private void validateInitiatorHostOS(Set<URI> initiators) {
Set<String> hostTypes = new HashSet<String>();
List<URI> hostList = new ArrayList<URI>();
// Dummy URI used in case we encounter null values
URI fillerHostURI = NullColumnValueGetter.getNullURI();
if (initiators != null && !initiators.isEmpty()) {
for (URI initiatorUri : initiators) {
Initiator ini = queryObject(Initiator.class, initiatorUri, true);
// If ini.getHost() returns a null value, set hostURI to fillerHostURI
URI hostURI = (ini.getHost() == null) ? fillerHostURI : ini.getHost();
// no need to go to the DB again..
if (!hostList.isEmpty() && hostList.contains(hostURI)) {
continue;
} else {
// add the hostURI to the hostList so that it can
// help in the next iteration.
hostList.add(hostURI);
}
if (hostURI == fillerHostURI) {
hostTypes.add(String.valueOf(fillerHostURI));
} else {
Host host = queryObject(Host.class, hostURI, true);
hostTypes.add(host.getType());
}
}
if (hostTypes.size() != 1) {
throw APIException.badRequests.initiatorHostsInSameOS();
}
}
}
use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.
the class ExportGroupService method validateClusterData.
/**
* Validates that a cluster is in the same tenant org and/or project as the export group.
* Also makes sure that all hosts in the cluster have connectivity to all storage systems
* the export group has block objects in.
*
* @param cluster the cluster being validated
* @param exportGroup the export where the cluster will be added
* @param storageSystems the storage systems the export group has block objects in.
* @param project the export group project
* @param allHosts the list of hosts to be updated with the cluster hosts
* @param allInitiators the list of initiators to be updated with the cluster initiators.
*/
private void validateClusterData(Cluster cluster, ExportGroup exportGroup, Collection<URI> storageSystems, Project project, List<URI> allHosts, List<URI> allInitiators) {
boolean newCluster = exportGroup.getClusters() == null || !exportGroup.getClusters().contains(cluster.getId().toString());
// if the host is in a project
if (!NullColumnValueGetter.isNullURI(cluster.getProject())) {
// validate it is in the same project as the as the export group,
if (!(cluster.getProject().equals(project.getId()) || !newCluster)) {
throw APIException.badRequests.invalidParameterClusterAssignedToDifferentProject(cluster.getLabel(), project.getLabel());
}
} else {
// validate it is in the same tenant Org as the as the export group,
if (!cluster.getTenant().equals(project.getTenantOrg().getURI()) && newCluster) {
throw APIException.badRequests.invalidParameterClusterInDifferentTenantToProject(cluster.getLabel(), project.getLabel());
}
}
List<Host> clusterHosts = getChildren(cluster.getId(), Host.class, "cluster");
for (Host host : clusterHosts) {
validateHostData(host, exportGroup, storageSystems, project, allInitiators);
if (!allHosts.contains(host.getId())) {
allHosts.add(host.getId());
}
}
_log.info("Cluster {} was validated successfully", cluster.getId().toString());
}
Aggregations