use of com.emc.sa.service.vipr.compute.tasks.CreateHosts in project coprhd-controller by CoprHD.
the class ComputeUtils method createHosts.
/**
* Creates tasks to provision specified hosts to the given cluster.
* @param Cluster
* @param URI of computeVirtualPool to pick blades from
* @param List of hostNames
* @param URI of varray
* @return list of successfully created hosts
*/
public static List<Host> createHosts(Cluster cluster, URI vcp, List<String> hostNamesIn, URI varray) throws Exception {
// new hosts will be created with lower case hostNames. force it here so we can find host afterwards
List<String> hostNames = Lists.newArrayList();
for (String hostNameIn : hostNamesIn) {
hostNames.add(hostNameIn != null ? hostNameIn.toLowerCase() : null);
}
List<Host> createdHosts = new ArrayList<>();
Tasks<HostRestRep> tasks = null;
try {
tasks = execute(new CreateHosts(vcp, cluster.getId(), hostNames, varray));
} catch (Exception e) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure", hostNames, e.getMessage());
}
// Some tasks could succeed while others could error out.
Map<URI, String> hostDeactivateMap = new HashMap<URI, String>();
if ((tasks != null) && (tasks.getTasks() != null)) {
List<Task<HostRestRep>> tasklist = tasks.getTasks();
List<Task<HostRestRep>> oritasklist = tasks.getTasks();
while (!tasklist.isEmpty()) {
tasklist = waitAndRefresh(tasklist);
for (Task<HostRestRep> successfulTask : getSuccessfulTasks(tasklist)) {
URI hostUri = successfulTask.getResourceId();
addAffectedResource(hostUri);
Host host = execute(new GetHost(hostUri));
createdHosts.add(host);
tasklist.remove(successfulTask);
oritasklist.remove(successfulTask);
}
for (Task<HostRestRep> failedTask : getFailedTasks(tasklist)) {
ExecutionUtils.currentContext().logError("computeutils.createhosts.failure.task", failedTask.getResource().getName(), failedTask.getMessage());
hostDeactivateMap.put(failedTask.getResourceId(), failedTask.getResource().getName());
tasklist.remove(failedTask);
oritasklist.remove(failedTask);
}
}
for (Task<HostRestRep> hostToRemove : oritasklist) {
hostDeactivateMap.put(hostToRemove.getResourceId(), hostToRemove.getResource().getName());
}
} else {
ExecutionUtils.currentContext().logError("computeutils.createhosts.noTasks,created", hostNames);
}
// Deactivate hosts that failed in the create step
if (MapUtils.isNotEmpty(hostDeactivateMap)) {
deactivateHostURIs(hostDeactivateMap);
}
return createdHosts;
}
Aggregations