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