Search in sources :

Example 1 with InstallOs

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);
        }
    }
}
Also used : Task(com.emc.vipr.client.Task) InstallOs(com.emc.sa.service.vipr.compute.tasks.InstallOs) HostRestRep(com.emc.storageos.model.host.HostRestRep) GetHost(com.emc.sa.service.vipr.tasks.GetHost) 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)

Aggregations

ExecutionException (com.emc.sa.engine.ExecutionException)1 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)1 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)1 InstallOs (com.emc.sa.service.vipr.compute.tasks.InstallOs)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