use of com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHostsWithNoBootVolume.
/**
* Deactivate hosts whose boot volumes were not properly created.
*
* @param hostToVolumeIdMap map of host object to its respective boot volume
* @param cluster cluster ID
* @return list of hosts that were NOT deactivated. This includes hosts with good boot volumes and hosts where the deactivation failed.
*/
public static Map<Host, URI> deactivateHostsWithNoBootVolume(Map<Host, URI> hostToVolumeIdMap, Cluster cluster) {
if (hostToVolumeIdMap == null) {
return Maps.newHashMap();
}
List<Host> hostsToRemove = Lists.newArrayList();
Map<Host, URI> hostsToVolumeIdNotRemovedMap = new HashMap<>(hostToVolumeIdMap);
for (Entry<Host, URI> hostVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
Host host = hostVolumeIdEntry.getKey();
URI volumeId = hostVolumeIdEntry.getValue();
if ((host != null) && (volumeId == null)) {
try {
execute(new RemoveHostFromCluster(host.getId()));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.failure", host.getHostName(), e.getMessage());
}
hostsToRemove.add(host);
host.setInactive(true);
}
}
if (!hostsToRemove.isEmpty()) {
try {
List<Host> hostsRemoved = deactivateHosts(hostsToRemove);
for (Host hostCreated : hostToVolumeIdMap.keySet()) {
boolean isRemovedHost = false;
for (Host hostRemoved : hostsRemoved) {
if (hostCreated.getId().equals(hostRemoved.getId())) {
isRemovedHost = true;
}
}
if (isRemovedHost) {
hostsToVolumeIdNotRemovedMap.remove(hostCreated);
}
}
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
}
}
return hostsToVolumeIdNotRemovedMap;
}
use of com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHostsNotAddedToCluster.
/**
* validate that specified hosts are in the cluster export groups, else deactivate the host
* @param List to hosts to check
* @param Cluster
* @return list of goodHosts ie hosts that are in the cluster EGs.
*/
public static List<Host> deactivateHostsNotAddedToCluster(List<Host> hosts, Cluster cluster) {
List<Host> hostsToRemove = new ArrayList<Host>();
List<Host> goodHosts = new ArrayList<Host>();
if ((hosts != null) && (cluster != null)) {
List<ExportGroupRestRep> exports = BlockStorageUtils.findExportsContainingCluster(cluster.getId(), null, null);
if (exports != null) {
for (Host host : hosts) {
boolean hostAddedToExports = true;
for (ExportGroupRestRep exportGroup : exports) {
List<HostRestRep> exportedHosts = exportGroup.getHosts();
boolean found = false;
for (HostRestRep exportedHost : exportGroup.getHosts()) {
if (host.getId().equals(exportedHost.getId())) {
found = true;
break;
}
}
if (!found) {
hostAddedToExports = false;
ExecutionUtils.currentContext().logError("computeutils.clusterexport.hostnotadded", host.getLabel(), exportGroup.getGeneratedName());
} else {
ExecutionUtils.currentContext().logInfo("computeutils.clusterexport.hostadded", host.getLabel(), exportGroup.getGeneratedName());
}
}
if (hostAddedToExports) {
goodHosts.add(host);
} else {
hostsToRemove.add(host);
}
}
}
}
if (!hostsToRemove.isEmpty()) {
for (Host host : hostsToRemove) {
try {
execute(new RemoveHostFromCluster(host.getId()));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.failure", host.getHostName(), e.getMessage());
}
}
try {
List<Host> hostsRemoved = deactivateHosts(hostsToRemove);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
}
}
return goodHosts;
}
use of com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster in project coprhd-controller by CoprHD.
the class ComputeUtils method deactivateHostsWithNoExport.
/**
* Deactivate hosts with no valid export of the boot volume, return a map of hosts still standing.
*
* @param hostToVolumeIdMap hosts to volume ID map
* @param hostToEgIdMap hosts to export group ID map
* @param cluster cluster, if applicable
* @return a map of hosts to volume ID that are still exported.
*/
public static Map<Host, URI> deactivateHostsWithNoExport(Map<Host, URI> hostToVolumeIdMap, Map<Host, URI> hostToEgIdMap, Cluster cluster) {
if (hostToVolumeIdMap == null || hostToVolumeIdMap.isEmpty()) {
return Maps.newHashMap();
}
List<Host> hostsToRemove = Lists.newArrayList();
Map<Host, URI> hostToVolumeIdNotRemovedMap = new HashMap<Host, URI>(hostToVolumeIdMap);
// Perform all host removal from cluster operations first.
for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
Host host = hostToVolumeIdEntry.getKey();
URI egId = hostToEgIdMap.get(host);
if (NullColumnValueGetter.isNullURI(egId) && host != null) {
try {
execute(new RemoveHostFromCluster(host.getId()));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.noexport", host.getHostName(), e.getMessage());
}
hostsToRemove.add(host);
host.setInactive(true);
}
}
if (!hostsToRemove.isEmpty()) {
// Deactivate all the hosts at the same time.
try {
deactivateHosts(hostsToRemove);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
}
// Deactivate all the of boot volumes at the same time.
try {
List<URI> bootVolsToRemove = Lists.newArrayList();
for (Host host : hostsToRemove) {
URI volumeId = hostToVolumeIdMap.get(host);
bootVolsToRemove.add(volumeId);
BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(volumeId);
removeBootVolumeTag(volume, host.getId());
}
BlockStorageUtils.deactivateVolumes(bootVolsToRemove, VolumeDeleteTypeEnum.FULL);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
}
// Now remove host entries from the map that we removed.
hostToVolumeIdNotRemovedMap.remove(hostsToRemove);
}
return hostToVolumeIdNotRemovedMap;
}
Aggregations