use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method verifyDatastore.
/**
* Verifies that datastores contained within an export group can be unmounted. It must not be entering maintenance mode or contain any
* virtual machines running on the given ESXi host.
*
* @param exportGroupId
* export group that contains volumes
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param esxHostname
* the hostname of the ESXi host
*
* @param stepId
* the id of the workflow step
*/
public void verifyDatastore(URI exportGroupId, URI vCenterId, URI vcenterDatacenter, String esxHostname, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem host = api.findHostSystem(vCenterDataCenter.getLabel(), esxHostname);
if (host == null) {
_log.info("Not able to find host " + esxHostname + " in vCenter. Unable to validate");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(host);
if (exportGroup != null && exportGroup.getVolumes() != null) {
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null) {
ComputeSystemHelper.verifyDatastore(datastore, host);
}
}
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_029);
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method rescanHostStorage.
/**
* Rescans HBAs and storage system for an ESX host
*
* @param hostId the host id
* @param vCenterId the vcenter id
* @param vcenterDatacenter the vcenter datacenter id
* @param stepId the workflow step
*/
public void rescanHostStorage(URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host {} in vCenter. Unable to refresh HBAs", esxHost.getLabel());
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
storageAPI.refreshStorage();
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method attachAndMountVolumes.
/**
* Creates workflow steps for attaching disks and mounting datastores
*
* @param vCenterHostExportMap
* the map of hosts and export groups to operate on
* @param waitFor
* the step to wait on for this workflow step
* @param workflow
* the workflow to create the step
* @return the step id
*/
private String attachAndMountVolumes(Map<URI, Collection<URI>> vCenterHostExportMap, String waitFor, Workflow workflow) {
if (vCenterHostExportMap == null) {
return waitFor;
}
for (URI hostId : vCenterHostExportMap.keySet()) {
Host esxHost = _dbClient.queryObject(Host.class, hostId);
if (esxHost != null) {
URI virtualDataCenter = esxHost.getVcenterDataCenter();
VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, virtualDataCenter);
URI vCenterId = vcenterDataCenter.getVcenter();
for (URI export : vCenterHostExportMap.get(hostId)) {
waitFor = workflow.createStep(MOUNT_AND_ATTACH_STEP, String.format("Mounting and attaching volumes from export group %s", export), waitFor, export, export.toString(), this.getClass(), attachAndMountMethod(export, esxHost.getId(), vCenterId, vcenterDataCenter.getId()), rollbackMethodNullMethod(), null);
}
}
}
return waitFor;
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class ComputeSystemControllerImpl method attachAndMount.
/**
* Attaches and mounts every disk and datastore associated with the volumes in the export group.
* For each volume in the export group, the associated disk is attached to the host and any datastores backed by the
* volume are mounted
* to the host.
*
* @param exportGroupId
* export group that contains volumes
* @param hostId
* host to attach and mount to
* @param vcenterId
* vcenter that the host belongs to
* @param vcenterDatacenter
* vcenter datacenter that the host belongs to
* @param stepId
* the id of the workflow step
*/
public void attachAndMount(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
WorkflowStepCompleter.stepExecuting(stepId);
try {
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_054);
Host esxHost = _dbClient.queryObject(Host.class, hostId);
Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
if (hostSystem == null) {
_log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to attach disks and mount datastores");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
if (exportGroup != null && exportGroup.getVolumes() != null) {
_log.info("Refreshing storage");
storageAPI.refreshStorage();
Set<BlockObject> blockObjects = Sets.newHashSet();
for (String volume : exportGroup.getVolumes().keySet()) {
BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
blockObjects.add(blockObject);
for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
if (VMwareUtils.isDiskOff(entry)) {
_log.info("Attach SCSI Lun " + entry.getCanonicalName() + " on host " + esxHost.getLabel());
storageAPI.attachScsiLun(entry);
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_055);
break;
}
}
}
int retries = 0;
while (retries++ < MAXIMUM_RESCAN_ATTEMPTS && !blockObjects.isEmpty()) {
_log.info("Rescanning VMFS for host " + esxHost.getLabel());
storageAPI.getStorageSystem().rescanVmfs();
_log.info("Waiting for {} milliseconds before checking for datastores", RESCAN_DELAY_MS);
Thread.sleep(RESCAN_DELAY_MS);
_log.info("Looking for datastores for {} volumes", blockObjects.size());
Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
Iterator<BlockObject> objectIterator = blockObjects.iterator();
while (objectIterator.hasNext()) {
BlockObject blockObject = objectIterator.next();
if (blockObject != null) {
Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
if (datastore != null && VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Datastore {} is already mounted on {}", datastore.getName(), esxHost.getLabel());
objectIterator.remove();
} else if (datastore != null && !VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
_log.info("Mounting datastore {} on host {}", datastore.getName(), esxHost.getLabel());
storageAPI.mountDatastore(datastore);
objectIterator.remove();
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_056);
}
}
}
}
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (Exception ex) {
_log.error(ex.getMessage(), ex);
WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class AbstractDiscoveryAdapter method processHostChanges.
@SuppressWarnings("unchecked")
public void processHostChanges(List<HostStateChange> changes, List<URI> deletedHosts, List<URI> deletedClusters, boolean isVCenter) {
log.info("There are " + changes.size() + " changes");
// Iterate through all host state changes and create states for all of the affected export groups
for (HostStateChange change : changes) {
log.info("HostChange: " + change);
Host host = dbClient.queryObject(Host.class, change.getHost().getId());
// For every host change (added/removed initiator, cluster change), get all exports that this host
// currently belongs to
List<Initiator> newInitiatorObjects = dbClient.queryObject(Initiator.class, change.getNewInitiators());
List<Initiator> oldInitiatorObjects = dbClient.queryObject(Initiator.class, change.getOldInitiators());
if (newInitiatorObjects.isEmpty() && !oldInitiatorObjects.isEmpty()) {
List<URI> hostInitiators = ComputeSystemHelper.getChildrenUris(dbClient, host.getId(), Initiator.class, "host");
if (hostInitiators.size() == oldInitiatorObjects.size()) {
log.info("No initiators were re-discovered for host " + host.getId() + " so we will not delete its initiators");
DiscoveryStatusUtils.markAsFailed(getModelClient(), host, "No initiators were discovered", null);
continue;
}
}
// 3) If no datacenter or cluster change, make sure we have updated atleast the new datacenter for the host
if (!NullColumnValueGetter.isNullURI(change.getOldDatacenter()) && !NullColumnValueGetter.isNullURI(change.getNewDatacenter()) && !change.getOldDatacenter().toString().equalsIgnoreCase(change.getNewDatacenter().toString())) {
VcenterDataCenter oldDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getOldDatacenter());
VcenterDataCenter currentDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getNewDatacenter());
Cluster cluster = null;
if (!NullColumnValueGetter.isNullURI(change.getNewCluster())) {
cluster = dbClient.queryObject(Cluster.class, change.getNewCluster());
}
URI oldClusterURI = change.getOldCluster();
Cluster oldCluster = null;
if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
oldCluster = dbClient.queryObject(Cluster.class, oldClusterURI);
}
if (!oldDatacenter.getVcenter().toString().equals(currentDatacenter.getVcenter().toString())) {
Vcenter oldVcenter = dbClient.queryObject(Vcenter.class, oldDatacenter.getVcenter());
Vcenter currentVcenter = dbClient.queryObject(Vcenter.class, currentDatacenter.getVcenter());
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_VCENTER_CHANGE, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeLabel", oldVcenter.getLabel(), currentVcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeDescription", host.getLabel(), oldCluster == null ? "N/A" : oldCluster.getLabel(), cluster == null ? " N/A " : cluster.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostVcenterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter }, EventUtils.hostVcenterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter });
} else {
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_DATACENTER_CHANGE, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeLabel", oldDatacenter.getLabel(), currentDatacenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeDescription", host.getLabel(), oldCluster == null ? "N/A" : oldCluster.getLabel(), cluster == null ? " N/A " : cluster.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostDatacenterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter }, EventUtils.hostDatacenterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter });
}
} else if ((change.getOldCluster() == null && change.getNewCluster() != null) || (change.getOldCluster() != null && change.getNewCluster() == null) || (change.getOldCluster() != null && change.getNewCluster() != null && !change.getOldCluster().toString().equals(change.getNewCluster().toString()))) {
Cluster cluster = null;
if (!NullColumnValueGetter.isNullURI(change.getNewCluster())) {
cluster = dbClient.queryObject(Cluster.class, change.getNewCluster());
}
URI oldClusterURI = change.getOldCluster();
Cluster oldCluster = null;
if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
oldCluster = dbClient.queryObject(Cluster.class, oldClusterURI);
}
boolean oldClusterInUse = oldCluster == null ? false : ComputeSystemHelper.isClusterInExport(dbClient, oldCluster.getId());
boolean newClusterInUse = cluster == null ? false : ComputeSystemHelper.isClusterInExport(dbClient, cluster.getId());
if ((cluster != null || oldCluster != null) && (oldClusterInUse || newClusterInUse)) {
String name = null;
String description = null;
if (cluster != null && oldCluster == null) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeAddedLabel", cluster.getLabel());
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeAddedDescription", host.getLabel(), cluster.getLabel());
} else if (cluster == null && oldCluster != null) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeRemovedLabel", oldCluster.getLabel());
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeRemovedDescription", host.getLabel(), oldCluster.getLabel());
} else {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeMovedLabel", oldCluster.getLabel(), cluster.getLabel());
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeMovedDescription", host.getLabel(), oldCluster.getLabel(), cluster.getLabel());
}
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_CLUSTER_CHANGE, host.getTenant(), name, description, ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostClusterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), NullColumnValueGetter.isNullURI(change.getNewDatacenter()) ? NullColumnValueGetter.getNullURI() : change.getNewDatacenter(), isVCenter }, EventUtils.hostClusterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), NullColumnValueGetter.isNullURI(change.getNewDatacenter()) ? NullColumnValueGetter.getNullURI() : change.getNewDatacenter(), isVCenter });
} else {
host.setCluster(cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId());
dbClient.updateObject(host);
ComputeSystemHelper.updateHostAndInitiatorClusterReferences(dbClient, host.getCluster(), host.getId());
if (cluster != null) {
ComputeSystemHelper.updateHostVcenterDatacenterReference(dbClient, host.getId(), cluster != null ? cluster.getVcenterDataCenter() : NullColumnValueGetter.getNullURI());
}
}
} else if (!NullColumnValueGetter.isNullURI(change.getNewDatacenter())) {
VcenterDataCenter currentDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getNewDatacenter());
host.setTenant(currentDatacenter.getTenant());
host.setVcenterDataCenter(currentDatacenter.getId());
dbClient.updateObject(host);
}
if (ComputeSystemHelper.isHostInUse(dbClient, host.getId()) && (!oldInitiatorObjects.isEmpty() || !newInitiatorObjects.isEmpty())) {
ActionableEvent duplicateEvent = EventUtils.getDuplicateEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_UPDATES.getCode(), host.getId(), null);
List<URI> duplicateEventAddInitiators = Lists.newArrayList();
List<URI> duplicateEventRemoveInitiators = Lists.newArrayList();
if (duplicateEvent != null) {
info("Found duplicate event %s for %s to update initiators", duplicateEvent.forDisplay(), host.forDisplay());
ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(duplicateEvent.getApproveMethod());
if (eventMethod == null) {
log.info("Event method is null or empty for event " + duplicateEvent.getId());
} else if (eventMethod.getArgs() == null) {
log.info("Event method arguments are null for event " + duplicateEvent.getId());
} else {
// Parameters for updateInitiators are hostId, addInitiatorIds, removeInitiatorIds
Object[] parameters = eventMethod.getArgs();
if (parameters != null && parameters.length == EventUtils.UPDATE_INITIATORS_METHOD_PARAMETERS) {
duplicateEventAddInitiators = (List<URI>) parameters[EventUtils.UPDATE_INITIATORS_METHOD_ADD_INITIATOR_INDEX];
duplicateEventRemoveInitiators = (List<URI>) parameters[EventUtils.UPDATE_INITIATORS_METHOD_REMOVE_INITIATOR_INDEX];
}
}
}
// if there are old HOST_INITIATOR_DELETE events for the same deleted initiators, then mark those events as declined
if (oldInitiatorObjects != null) {
for (Initiator initiator : oldInitiatorObjects) {
List<ActionableEvent> hostEvents = EventUtils.findAffectedResourcePendingEvents(dbClient, initiator.getId());
for (ActionableEvent hostEvent : hostEvents) {
if (hostEvent.getEventCode().equals(EventCode.HOST_INITIATOR_DELETE.getCode())) {
hostEvent.setEventStatus(ActionableEvent.Status.system_declined.name());
log.info("Marking old initiator delete event " + hostEvent.forDisplay() + " as system declined because we will merge it with a batched initiator event");
dbClient.updateObject(hostEvent);
}
}
}
}
newInitiatorObjects.addAll(dbClient.queryObject(Initiator.class, duplicateEventAddInitiators));
oldInitiatorObjects.addAll(dbClient.queryObject(Initiator.class, duplicateEventRemoveInitiators));
Set<String> oldInitiatorPorts = Sets.newHashSet();
Set<String> newInitiatorPorts = Sets.newHashSet();
Set<URI> oldInitiatorIds = Sets.newHashSet();
Set<URI> newInitiatorIds = Sets.newHashSet();
for (Initiator oldInitiator : oldInitiatorObjects) {
oldInitiatorPorts.add(oldInitiator.getInitiatorPort());
oldInitiatorIds.add(oldInitiator.getId());
}
for (Initiator newInitiator : newInitiatorObjects) {
newInitiatorPorts.add(newInitiator.getInitiatorPort());
newInitiatorIds.add(newInitiator.getId());
}
List<URI> allAffectedResources = Lists.newArrayList();
allAffectedResources.add(host.getId());
allAffectedResources.addAll(newInitiatorIds);
allAffectedResources.addAll(oldInitiatorIds);
String name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelAddAndRemove", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
String description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionAddAndRemove", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
if (!newInitiatorPorts.isEmpty() && oldInitiatorPorts.isEmpty()) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelAddOnly", StringUtils.join(newInitiatorPorts, ","));
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionAddOnly", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
} else if (newInitiatorPorts.isEmpty() && !oldInitiatorPorts.isEmpty()) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelRemoveOnly", StringUtils.join(oldInitiatorPorts, ","));
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionRemoveOnly", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
}
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_UPDATES, host.getTenant(), name, description, ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsWarning"), host, allAffectedResources, EventUtils.updateInitiators, new Object[] { host.getId(), Lists.newArrayList(newInitiatorIds), Lists.newArrayList(oldInitiatorIds) }, EventUtils.updateInitiatorsDecline, new Object[] { host.getId(), Lists.newArrayList(newInitiatorIds), Lists.newArrayList(oldInitiatorIds) });
} else {
for (Initiator oldInitiator : oldInitiatorObjects) {
info("Deleting Initiator %s because it was not re-discovered and is not in use by any export groups", oldInitiator.getId());
dbClient.removeObject(oldInitiator);
}
}
}
log.info("Number of undiscovered hosts: " + deletedHosts.size());
Set<URI> incorrectDeletedHosts = Sets.newHashSet();
for (URI deletedHost : deletedHosts) {
Host host = dbClient.queryObject(Host.class, deletedHost);
URI clusterId = host.getCluster();
List<URI> clusterHosts = Lists.newArrayList();
if (!NullColumnValueGetter.isNullURI(clusterId)) {
clusterHosts = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
}
if (clusterHosts.contains(deletedHost) && deletedHosts.containsAll(clusterHosts)) {
incorrectDeletedHosts.add(deletedHost);
DiscoveryStatusUtils.markAsFailed(getModelClient(), host, "Error discovering host cluster", null);
log.info("Host " + host.getId() + " is part of a cluster that was not re-discovered. Fail discovery and keep the host in our database");
} else {
Vcenter vcenter = ComputeSystemHelper.getHostVcenter(dbClient, host);
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.UNASSIGN_HOST_FROM_VCENTER, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignLabel", vcenter == null ? "N/A" : vcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignDescription", host.getLabel(), vcenter == null ? "N/A" : vcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignWarning"), host, Lists.newArrayList(host.getId(), host.getCluster()), EventUtils.hostVcenterUnassign, new Object[] { deletedHost }, EventUtils.hostVcenterUnassignDecline, new Object[] { deletedHost });
}
}
// delete clusters that don't contain any hosts, don't have any exports, and don't have any pending events
for (URI clusterId : deletedClusters) {
List<URI> hostUris = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
if (hostUris.isEmpty() && !ComputeSystemHelper.isClusterInExport(dbClient, clusterId) && EventUtils.findAffectedResourcePendingEvents(dbClient, clusterId).isEmpty()) {
Cluster cluster = dbClient.queryObject(Cluster.class, clusterId);
info("Deactivating Cluster: " + clusterId);
ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
} else {
info("Unable to delete cluster " + clusterId);
}
}
}
Aggregations