Search in sources :

Example 1 with CreateHosts

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;
}
Also used : Task(com.emc.vipr.client.Task) HashMap(java.util.HashMap) GetHost(com.emc.sa.service.vipr.tasks.GetHost) ArrayList(java.util.ArrayList) GetHost(com.emc.sa.service.vipr.tasks.GetHost) DiscoverHost(com.emc.sa.service.vipr.compute.tasks.DiscoverHost) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException) HostRestRep(com.emc.storageos.model.host.HostRestRep) CreateHosts(com.emc.sa.service.vipr.compute.tasks.CreateHosts)

Aggregations

ExecutionException (com.emc.sa.engine.ExecutionException)1 CreateHosts (com.emc.sa.service.vipr.compute.tasks.CreateHosts)1 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)1 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)1 GetHost (com.emc.sa.service.vipr.tasks.GetHost)1 Host (com.emc.storageos.db.client.model.Host)1 HostRestRep (com.emc.storageos.model.host.HostRestRep)1 Task (com.emc.vipr.client.Task)1 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)1 ViPRException (com.emc.vipr.client.exceptions.ViPRException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1