use of com.emc.sa.service.vipr.compute.tasks.DeactivateHost in project coprhd-controller by CoprHD.
the class ComputeUtils method setHostBootVolumes.
/**
* Sets the specified host's boot volume association; Optionally also sets the UCS service profile's san boot targets
* Any hosts for which boot volume association could not be set are deactivated.
*
* @param Map of Host to bootVolume URI
* @param boolean set to true to update the UCS service profile's san boot targets
* @return list of hosts for which boot volume association was successfully set.
*/
public static List<Host> setHostBootVolumes(Map<Host, URI> hostToVolumeIdMap, boolean updateSanBootTargets) {
List<Task<HostRestRep>> tasks = new ArrayList<>();
Map<URI, URI> volumeIdToHostIdMap = new HashMap<>();
for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
Host host = hostToVolumeIdEntry.getKey();
URI volumeId = hostToVolumeIdEntry.getValue();
volumeIdToHostIdMap.put(volumeId, host.getId());
if (host != null && !host.getInactive()) {
host.setBootVolumeId(volumeId);
try {
Task<HostRestRep> task = ViPRExecutionUtils.execute(new SetBootVolume(host, volumeId, updateSanBootTargets));
tasks.add(task);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure", host.getHostName() + " " + e.getMessage());
}
}
}
// monitor tasks
List<URI> successfulHostIds = Lists.newArrayList();
List<URI> hostsToRemove = Lists.newArrayList();
List<URI> bootVolumesToRemove = Lists.newArrayList();
while (!tasks.isEmpty()) {
tasks = waitAndRefresh(tasks);
for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasks)) {
tasks.remove(successfulTask);
URI hostId = successfulTask.getResource().getId();
Host newHost = execute(new GetHost(hostId));
if (newHost == null || newHost.getBootVolumeId() == null || newHost.getBootVolumeId().equals("null")) {
ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure", successfulTask.getResource().getName());
hostsToRemove.add(hostId);
} else {
ExecutionUtils.currentContext().logInfo("computeutils.sethostbootvolume.success", newHost.getHostName());
addAffectedResource(hostId);
successfulHostIds.add(hostId);
}
}
for (Task<HostRestRep> failedTask : getFailedTasks(tasks)) {
tasks.remove(failedTask);
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.sethostbootvolume.failure.task", failedTask.getResource().getName(), errorMessage);
URI hostId = failedTask.getResource().getId();
execute(new GetHost(hostId));
hostsToRemove.add(hostId);
}
}
for (Host host : hostToVolumeIdMap.keySet()) {
if (host != null && !host.getInactive()) {
if (!successfulHostIds.contains(host.getId()) && !hostsToRemove.contains(host.getId())) {
hostsToRemove.add(host.getId());
}
}
}
for (URI hostId : hostsToRemove) {
for (Host host : hostToVolumeIdMap.keySet()) {
if (host.getId().equals(hostId)) {
ExecutionUtils.currentContext().logInfo("computeutils.deactivatehost.nobootvolumeassociation", host.getHostName());
bootVolumesToRemove.add(hostToVolumeIdMap.get(host));
break;
}
}
execute(new DeactivateHost(hostId, true));
}
// Cleanup all boot volumes of the deactivated host so that we do not leave any unused boot volumes.
if (!bootVolumesToRemove.isEmpty()) {
try {
ExecutionUtils.currentContext().logInfo("computeutils.deactivatebootvolume.nobootvolumeassociation");
for (URI bootVolToRemove : bootVolumesToRemove) {
BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(bootVolToRemove);
URI hostId = volumeIdToHostIdMap.get(bootVolToRemove);
removeBootVolumeTag(volume, hostId);
}
BlockStorageUtils.deactivateVolumes(bootVolumesToRemove, VolumeDeleteTypeEnum.FULL);
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
}
}
// Only return successful hosts
List<Host> successfulHosts = new ArrayList<>();
for (Host host : hostToVolumeIdMap.keySet()) {
if ((host != null) && successfulHostIds.contains(host.getId())) {
successfulHosts.add(host);
}
}
return successfulHosts;
}
use of com.emc.sa.service.vipr.compute.tasks.DeactivateHost in project coprhd-controller by CoprHD.
the class InstallOsHelper method onSuccess.
@Override
public void onSuccess(Task<HostRestRep> task, HostRestRep host) {
ExecutionUtils.currentContext().logInfo("computeutils.installOs.success", host.getHostName());
addAffectedResource(host);
addRollback(new DeactivateHost(host.getId(), true));
successfulHostIds.add(host.getId());
}
Aggregations