Search in sources :

Example 26 with Host

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);
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) StringSet(com.emc.storageos.db.client.model.StringSet) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 27 with Host

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;
}
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 28 with Host

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.");
}
Also used : Project(com.emc.storageos.db.client.model.Project) Host(com.emc.storageos.db.client.model.Host)

Example 29 with Host

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();
        }
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 30 with Host

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());
}
Also used : Host(com.emc.storageos.db.client.model.Host)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16