Search in sources :

Example 1 with GetHost

use of com.emc.sa.service.vipr.tasks.GetHost in project coprhd-controller by CoprHD.

the class ComputeUtils method deactivateHostsWithNoOS.

/**
 * Deactivate hosts which failed the OS install process
 * @param hosts {@link List} hosts that need to be verified for OS install
 * @return {@link List} hostsWithOS
 */
public static List<Host> deactivateHostsWithNoOS(List<Host> hosts) {
    if (nonNull(hosts).isEmpty()) {
        return Collections.emptyList();
    }
    List<Host> hostsWithOS = Lists.newArrayList();
    Map<URI, String> hostDeactivateMap = new HashMap<URI, String>();
    for (Host osHost : hosts) {
        Host host = execute(new GetHost(osHost.getId()));
        if (host.getType() != null && host.getType().equalsIgnoreCase(Host.HostType.No_OS.name())) {
            hostDeactivateMap.put(host.getId(), host.getLabel());
        } else {
            hostsWithOS.add(host);
        }
    }
    // Deactivate hosts which failed the OS install step
    if (MapUtils.isNotEmpty(hostDeactivateMap)) {
        ExecutionUtils.currentContext().logError("computeutils.installOs.installing.failure.task.deactivate.failedinstallOSHost", hostDeactivateMap.values());
        deactivateHostURIs(hostDeactivateMap);
    }
    return hostsWithOS;
}
Also used : HashMap(java.util.HashMap) 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)

Example 2 with GetHost

use of com.emc.sa.service.vipr.tasks.GetHost 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)

Example 3 with GetHost

use of com.emc.sa.service.vipr.tasks.GetHost 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)

Example 4 with GetHost

use of com.emc.sa.service.vipr.tasks.GetHost 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;
}
Also used : Task(com.emc.vipr.client.Task) DeactivateHost(com.emc.sa.service.vipr.compute.tasks.DeactivateHost) 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) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) 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) SetBootVolume(com.emc.sa.service.vipr.compute.tasks.SetBootVolume)

Aggregations

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