use of com.emc.sa.service.vipr.compute.tasks.InstallOs in project coprhd-controller by CoprHD.
the class ComputeUtils method installOsOnHosts.
/**
* Install OS image on the specified hosts
* @param map of Host to OsInstallParam -- this param has the details of which image to use, the netmask, ip address, etc required for installing os
*/
public static void installOsOnHosts(Map<Host, OsInstallParam> osInstallParamMap) {
if ((osInstallParamMap == null) || osInstallParamMap.isEmpty()) {
return;
}
Set<Host> hosts = osInstallParamMap.keySet();
// execute all tasks (no waiting)
List<Task<HostRestRep>> tasks = Lists.newArrayList();
for (Host host : hosts) {
if (host != null) {
if (osInstallParamMap.get(host) == null) {
continue;
}
try {
tasks.add(execute(new InstallOs(host, osInstallParamMap.get(host))));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.installOs.failure", host.getId() + " " + e.getMessage());
}
}
}
// monitor tasks
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) {
ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure", successfulTask.getResource().getName());
} else {
ExecutionUtils.currentContext().logInfo("computeutils.installOs.success", newHost.getHostName());
addAffectedResource(hostId);
}
}
for (Task<HostRestRep> failedTask : getFailedTasks(tasks)) {
tasks.remove(failedTask);
String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure.task", failedTask.getResource().getName(), errorMessage);
}
}
}
Aggregations