use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class UcsComputeDevice method addHostPortsToVArrayNetworks.
public void addHostPortsToVArrayNetworks(VirtualArray varray, Host host, String stepId) {
LOGGER.info("Adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
WorkflowStepCompleter.stepExecuting(stepId);
try {
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
Map<Network, List<String>> networkToInitiatorMap = Collections.synchronizedMap(new HashMap<Network, List<String>>());
Map<String, Network> networkIdNetworkMapInVarray = getVarrayNetworkMap(_dbClient, varray.getId());
URIQueryResultList ceHBAUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getHostComputeElemetHBAsConstraint(host.getId()), ceHBAUriList);
Iterator<URI> ceHBAUriListIterator = ceHBAUriList.iterator();
Cluster cluster = null;
if (host.getCluster() != null) {
cluster = _dbClient.queryObject(Cluster.class, host.getCluster());
}
while (ceHBAUriListIterator.hasNext()) {
URI ceHBAUri = ceHBAUriListIterator.next();
ComputeElementHBA computeElementHBA = _dbClient.queryObject(ComputeElementHBA.class, ceHBAUri);
Initiator initiator = new Initiator();
initiator.setHost(host.getId());
initiator.setHostName(host.getHostName());
initiator.setId(URIUtil.createId(Initiator.class));
if (cluster != null) {
initiator.setClusterName(cluster.getLabel());
}
initiator.setInitiatorNode(computeElementHBA.getNode());
initiator.setInitiatorPort(computeElementHBA.getPort());
initiator.setProtocol(computeElementHBA.getProtocol() != null ? computeElementHBA.getProtocol().toUpperCase() : null);
// Search against the database, fail if you see the wwn in the database already.
Initiator dbInitiator = ExportUtils.getInitiator(initiator.getInitiatorPort(), _dbClient);
if (dbInitiator != null) {
throw ComputeSystemControllerException.exceptions.illegalInitiator(host.getHostName(), dbInitiator.getInitiatorPort(), dbInitiator.getHostName());
}
Network network = networkIdNetworkMapInVarray.get(computeElementHBA.getVsanId());
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_065);
if (network == null) {
LOGGER.error("No corresponding Network for HBA {} in vArray {}. Network null from DB.", computeElementHBA.getPort(), varray.getId());
throw new RuntimeException(ComputeSystemControllerException.exceptions.noCorrespondingNetworkForHBAInVarray(computeElementHBA.getPort(), varray.getLabel(), null));
} else {
if (networkToInitiatorMap.get(network) == null) {
networkToInitiatorMap.put(network, new ArrayList<String>());
}
networkToInitiatorMap.get(network).add(computeElementHBA.getPort());
}
_dbClient.createObject(initiator);
}
/**
* Add all the newly added endpoints to their respective networks!
*/
for (Network network : networkToInitiatorMap.keySet()) {
network.addEndpoints(networkToInitiatorMap.get(network), false);
_dbClient.updateObject(network);
handleEndpointsAdded(network, networkToInitiatorMap.get(network), _dbClient, _coordinator);
}
}
WorkflowStepCompleter.stepSucceded(stepId);
LOGGER.info("Done adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
} catch (Exception ex) {
LOGGER.error("Exception while adding host ports to vArray networks. {}", ex);
WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToAddHostPortsToVArrayNetworks(varray.getLabel().toString(), ex));
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method unmountClusterStorage.
/**
* Unmounts storage for a cluster
*
* @param workflow the workflow to use
* @param waitFor the step to wait for
* @param clusterId the cluster id to unmount storage
* @return wait step
*/
private String unmountClusterStorage(Workflow workflow, String waitFor, URI clusterId) {
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
String newWaitFor = waitFor;
if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
List<ExportGroup> exportGroups = getSharedExports(_dbClient, clusterId);
List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, clusterId, Host.class, "cluster");
URI vcenterDataCenter = cluster.getVcenterDataCenter();
Collection<URI> exportIds = Collections2.transform(exportGroups, CommonTransformerFunctions.fctnDataObjectToID());
Map<URI, Collection<URI>> hostExports = Maps.newHashMap();
for (URI host : clusterHosts) {
hostExports.put(host, exportIds);
}
newWaitFor = this.verifyDatastoreForRemoval(hostExports, vcenterDataCenter, newWaitFor, workflow);
newWaitFor = this.unmountAndDetachVolumes(hostExports, vcenterDataCenter, newWaitFor, workflow);
}
return newWaitFor;
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method addHostsToExport.
@Override
public void addHostsToExport(URI eventId, List<URI> hostIds, URI clusterId, String taskId, URI oldCluster, boolean isVcenter) throws ControllerException {
HostCompleter completer = null;
try {
Workflow workflow = _workflowService.getNewWorkflow(this, REMOVE_HOST_STORAGE_WF_NAME, true, taskId);
String waitFor = null;
URI vCenterDataCenterId = NullColumnValueGetter.getNullURI();
Cluster cluster = _dbClient.queryObject(Cluster.class, clusterId);
if (cluster != null && !NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
vCenterDataCenterId = cluster.getVcenterDataCenter();
}
completer = new HostCompleter(eventId, hostIds, false, taskId);
if (!NullColumnValueGetter.isNullURI(oldCluster) && !oldCluster.equals(clusterId)) {
waitFor = addStepsForRemoveHost(workflow, waitFor, hostIds, oldCluster, vCenterDataCenterId, isVcenter);
}
waitFor = addStepForUpdatingHostAndInitiatorClusterReferences(workflow, waitFor, hostIds, clusterId, vCenterDataCenterId, completer);
waitFor = addStepsForAddHost(workflow, waitFor, hostIds, clusterId, isVcenter, eventId);
workflow.executePlan(completer, "Success", null, null, null, null);
} catch (Exception ex) {
String message = "addHostToExport caught an exception.";
_log.error(message, ex);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(ex);
completer.error(_dbClient, serviceError);
}
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeSystemHelper method doDeactivateVcenterDataCenter.
/**
* Utility function to recursively deactivate all the hosts / clusters from datacenter
*
* @param host the host to deactivate
*/
public static void doDeactivateVcenterDataCenter(DbClient dbClient, VcenterDataCenter dataCenter) {
List<NamedElementQueryResultList.NamedElement> hostUris = listChildren(dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
Set<URI> doNotDeleteclusters = new HashSet<URI>();
for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
Host host = dbClient.queryObject(Host.class, hostUri.getId());
if (host != null && !host.getInactive()) {
if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
doDeactivateHost(dbClient, host);
} else {
// do not delete hosts that have compute elements, simply break DC link
host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
dbClient.persistObject(host);
if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
doNotDeleteclusters.add(host.getCluster());
}
}
}
}
List<NamedElementQueryResultList.NamedElement> clustersUris = listChildren(dbClient, dataCenter.getId(), Cluster.class, "label", "vcenterDataCenter");
for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
if (cluster != null && !cluster.getInactive()) {
if (doNotDeleteclusters.contains(cluster.getId())) {
// do not delete clusters if hosts are not deleted, simply break DC link
cluster.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
cluster.setExternalId(NullColumnValueGetter.getNullStr());
dbClient.persistObject(cluster);
} else {
dbClient.markForDeletion(cluster);
EventUtils.deleteResourceEvents(dbClient, cluster.getId());
}
}
}
_log.info("marking DC for deletion: {} {}", dataCenter.getLabel(), dataCenter.getId());
dbClient.markForDeletion(dataCenter);
EventUtils.deleteResourceEvents(dbClient, dataCenter.getId());
}
use of com.emc.storageos.db.client.model.Cluster in project coprhd-controller by CoprHD.
the class ComputeSystemHelper method isDataCenterInUse.
/**
* Checks if an datacenter is in use by an export groups
*
* @param dbClient
* @param datacenterURI the datacenter URI
* @return true if the datacenter is in used by an export group.
*/
public static boolean isDataCenterInUse(DbClient dbClient, URI datacenterURI) {
VcenterDataCenter dataCenter = dbClient.queryObject(VcenterDataCenter.class, datacenterURI);
if (dataCenter != null && !dataCenter.getInactive()) {
List<NamedElementQueryResultList.NamedElement> hostUris = listChildren(dbClient, dataCenter.getId(), Host.class, "label", "vcenterDataCenter");
for (NamedElementQueryResultList.NamedElement hostUri : hostUris) {
Host host = dbClient.queryObject(Host.class, hostUri.getId());
// ignore provisioned hosts
if (host != null && !host.getInactive() && NullColumnValueGetter.isNullURI(host.getComputeElement()) && isHostInUse(dbClient, host.getId())) {
return true;
}
}
List<NamedElementQueryResultList.NamedElement> clustersUris = listChildren(dbClient, dataCenter.getId(), Cluster.class, "label", "vcenterDataCenter");
for (NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
if (cluster != null && !cluster.getInactive() && isClusterInExport(dbClient, clusterUri.getId())) {
return true;
}
}
}
return false;
}
Aggregations