Search in sources :

Example 21 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class HostService method getIpInterfaces.

/**
 * Gets the id and name for all the interfaces of a host.
 *
 * @param id
 *            the URN of a ViPR Host
 * @brief List host interfaces
 * @return a list of interfaces that belong to the host
 * @throws DatabaseException
 *             when a DB error occurs
 */
@GET
@Path("/{id}/ip-interfaces")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public IpInterfaceList getIpInterfaces(@PathParam("id") URI id) throws DatabaseException {
    Host host = queryObject(Host.class, id, false);
    // check the user permissions
    verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
    // get the ip interfaces
    IpInterfaceList list = new IpInterfaceList();
    List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(id, IpInterface.class, "ipAddress", "host");
    for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
        list.getIpInterfaces().add(toNamedRelatedResource(ResourceTypeEnum.IPINTERFACE, dataObject.getId(), dataObject.getName()));
    }
    return list;
}
Also used : IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) Host(com.emc.storageos.db.client.model.Host) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ActionableEventExecutor method hostVcenterUnassignDetails.

/**
 * Get details for the hostVcenterUnassign method
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host id to unassign from vCenter
 * @return list of event details
 */
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostVcenterUnassignDetails(URI hostId) {
    List<String> result = Lists.newArrayList();
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (host != null) {
        Vcenter vcenter = ComputeSystemHelper.getHostVcenter(_dbClient, host);
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignDetails", host.getLabel(), vcenter == null ? "N/A" : vcenter.getLabel()));
        result.addAll(hostClusterChangeDetails(hostId, NullColumnValueGetter.getNullURI(), NullColumnValueGetter.getNullURI(), true));
    }
    return result;
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) Host(com.emc.storageos.db.client.model.Host)

Example 23 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ActionableEventExecutor method hostClusterChangeDetails.

/**
 * Get details for the hostClusterChange method
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host that is moving clusters
 * @param clusterId the cluster the host is moving to
 * @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
 *            datastores
 * @param vCenterDataCenterId the datacenter to assign the host to
 * @return list of event details
 */
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostClusterChangeDetails(URI hostId, URI clusterId, URI vCenterDataCenterId, boolean isVcenter) {
    List<String> result = Lists.newArrayList();
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (host == null) {
        return Lists.newArrayList("Host has been deleted");
    }
    URI oldClusterURI = host.getCluster();
    Cluster oldCluster = null;
    if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
        oldCluster = _dbClient.queryObject(Cluster.class, oldClusterURI);
    }
    Cluster newCluster = null;
    if (!NullColumnValueGetter.isNullURI(clusterId)) {
        newCluster = _dbClient.queryObject(Cluster.class, clusterId);
    }
    if (newCluster != null && oldCluster != null) {
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetails", host.getLabel(), oldCluster.getLabel(), newCluster.getLabel()));
    } else if (newCluster == null && oldCluster != null) {
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetailsRemovedFromCluster", host.getLabel(), oldCluster.getLabel()));
    } else if (newCluster != null && oldCluster == null) {
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetailsAddedToCluster", host.getLabel(), newCluster.getLabel()));
    }
    if (!NullColumnValueGetter.isNullURI(oldClusterURI) && NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI)) {
        List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, oldClusterURI);
        for (ExportGroup export : exportGroups) {
            if (export != null) {
                List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, export.getVolumes());
                result.addAll(getVolumeDetails(affectedVolumes, false));
            }
        }
    } else if (NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
        // Non-clustered host being added to a cluster
        List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, clusterId);
        for (ExportGroup eg : exportGroups) {
            List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, eg.getVolumes());
            result.addAll(getVolumeDetails(affectedVolumes, true));
        }
    } else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && !oldClusterURI.equals(clusterId) && (ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI) || ComputeSystemHelper.isClusterInExport(_dbClient, clusterId))) {
        // Clustered host being moved to another cluster
        List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, oldClusterURI);
        for (ExportGroup export : exportGroups) {
            if (export != null) {
                List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, export.getVolumes());
                result.addAll(getVolumeDetails(affectedVolumes, false));
            }
        }
        exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, clusterId);
        for (ExportGroup eg : exportGroups) {
            List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, eg.getVolumes());
            result.addAll(getVolumeDetails(affectedVolumes, true));
        }
    }
    return result;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) List(java.util.List) URI(java.net.URI)

Example 24 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ActionableEventExecutor method hostClusterChange.

/**
 * Method to move a host to a new cluster and update shared exports.
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host that is moving clusters
 * @param clusterId the cluster the host is moving to
 * @param vCenterDataCenterId the vcenter datacenter id to set
 * @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
 *            datastores
 * @param eventId the event id
 * @return task for updating export groups
 */
public TaskResourceRep hostClusterChange(URI hostId, URI clusterId, URI vCenterDataCenterId, boolean isVcenter, URI eventId) {
    Host hostObj = _dbClient.queryObject(Host.class, hostId);
    URI oldClusterURI = hostObj.getCluster();
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Host.class, hostId, taskId, ResourceOperationTypeEnum.UPDATE_HOST);
    if (!NullColumnValueGetter.isNullURI(oldClusterURI) && NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI)) {
        // Remove host from shared export
        computeController.removeHostsFromExport(eventId, Arrays.asList(hostId), oldClusterURI, isVcenter, vCenterDataCenterId, taskId);
    } else if (NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
        // Non-clustered host being added to a cluster
        computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
    } else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && !oldClusterURI.equals(clusterId) && (ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI) || ComputeSystemHelper.isClusterInExport(_dbClient, clusterId))) {
        // Clustered host being moved to another cluster
        computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
    } else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && oldClusterURI.equals(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
        // Cluster hasn't changed but we should add host to the shared exports in case they weren't added to all of them
        computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
    } else {
        ComputeSystemHelper.updateHostAndInitiatorClusterReferences(_dbClient, clusterId, hostId);
        ComputeSystemHelper.updateHostVcenterDatacenterReference(_dbClient, hostId, vCenterDataCenterId);
        _dbClient.ready(Host.class, hostId, taskId);
    }
    return toTask(hostObj, taskId, op);
}
Also used : Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI)

Example 25 with Host

use of com.emc.storageos.db.client.model.Host 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;
        }
    }));
}
Also used : Function(com.google.common.base.Function) ComputeElementBulkRep(com.emc.storageos.model.compute.ComputeElementBulkRep) 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)

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