Search in sources :

Example 86 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ComputeUtils method deactivateHosts.

/**
 * Deactivate a list of hosts.
 *
 * @param hosts hosts to deactivate
 * @return list of hosts that were successfully deactivated
 */
public static List<Host> deactivateHosts(List<Host> hosts) {
    List<Host> hostsDeactivated = new ArrayList<>();
    Map<URI, String> hostURIMap = new HashMap<URI, String>();
    for (Host host : hosts) {
        hostURIMap.put(host.getId(), host.getLabel());
    }
    List<URI> deactivatedHostURIs = deactivateHostURIs(hostURIMap);
    ListIterator<Host> hostItr = nonNull(hosts).listIterator();
    while (hostItr.hasNext()) {
        Host host = hostItr.next();
        if (deactivatedHostURIs.contains(host.getId())) {
            hostsDeactivated.add(host);
        }
    }
    return hostsDeactivated;
}
Also used : HashMap(java.util.HashMap) 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)

Example 87 with Host

use of com.emc.storageos.db.client.model.Host 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 88 with Host

use of com.emc.storageos.db.client.model.Host 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 89 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class CreateBareMetalClusterService method execute.

@Override
public void execute() throws Exception {
    if (cluster == null) {
        cluster = ComputeUtils.createCluster(name);
        logInfo("compute.cluster.created", name);
    } else {
        // If the hostName already exists, we remove it from the hostnames
        // list.
        hostNames = ComputeUtils.removeExistingHosts(hostNames, cluster);
    }
    acquireClusterLock(cluster);
    List<Host> hosts = ComputeUtils.createHosts(cluster, computeVirtualPool, hostNames, virtualArray);
    for (Host host : hosts) {
        acquireHostLock(host, cluster);
    }
    logInfo("compute.cluster.hosts.created", ComputeUtils.nonNull(hosts).size());
    Map<Host, URI> hostToBootVolumeIdMap = ComputeUtils.makeBootVolumes(project, virtualArray, virtualPool, size, hosts, getClient(), portGroup);
    logInfo("compute.cluster.boot.volumes.created", hostToBootVolumeIdMap != null ? ComputeUtils.nonNull(hostToBootVolumeIdMap.values()).size() : 0);
    // Deactivate hosts with no boot volume, return list of hosts remaining.
    hostToBootVolumeIdMap = ComputeUtils.deactivateHostsWithNoBootVolume(hostToBootVolumeIdMap, cluster);
    // Export the boot volume, return a map of hosts and their EG IDs
    Map<Host, URI> hostToEgIdMap = ComputeUtils.exportBootVols(hostToBootVolumeIdMap, project, virtualArray, hlu, portGroup);
    logInfo("compute.cluster.exports.created", hostToEgIdMap != null ? ComputeUtils.nonNull(hostToEgIdMap.values()).size() : 0);
    // Deactivate any hosts where the export failed, return list of hosts remaining
    hostToBootVolumeIdMap = ComputeUtils.deactivateHostsWithNoExport(hostToBootVolumeIdMap, hostToEgIdMap, cluster);
    // Set host boot volume ids and set san boot targets.
    hosts = ComputeUtils.setHostBootVolumes(hostToBootVolumeIdMap, true);
    ComputeUtils.addHostsToCluster(hosts, cluster);
    hosts = ComputeUtils.deactivateHostsNotAddedToCluster(hosts, cluster);
    if (ComputeUtils.findHostNamesInCluster(cluster).isEmpty()) {
        logInfo("compute.cluster.removing.empty.cluster");
        ComputeUtils.deactivateCluster(cluster);
    }
    String orderErrors = ComputeUtils.getOrderErrors(cluster, copyOfHostNames, null, null);
    if (orderErrors.length() > 0) {
        // fail order so user can resubmit
        if (ComputeUtils.nonNull(hosts).isEmpty()) {
            throw new IllegalStateException(ExecutionUtils.getMessage("compute.cluster.order.incomplete", orderErrors));
        } else {
            logError("compute.cluster.order.incomplete", orderErrors);
            setPartialSuccess();
        }
    }
}
Also used : Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 90 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class CreateComputeClusterService method installOSForHosts.

private void installOSForHosts(Map<String, String> hostToIps, Map<String, URI> hostNameToBootVolumeMap, List<Host> createdHosts) {
    Map<Host, OsInstallParam> osInstallParamMap = new HashMap<Host, OsInstallParam>();
    for (Host host : createdHosts) {
        if ((host != null) && ((host.getType() == null) || host.getType().isEmpty() || host.getType().equals(Host.HostType.No_OS.name()))) {
            OsInstallParam param = new OsInstallParam();
            String hostIp = hostToIps.get(host.getHostName());
            param.setComputeImage(computeImage);
            param.setHostName(host.getHostName());
            param.setDnsServers(dnsServers);
            param.setGateway(gateway);
            param.setNetmask(netmask);
            param.setHostIp(hostIp);
            param.setVolume(hostNameToBootVolumeMap.get(host.getHostName()));
            param.setManagementNetwork(managementNetwork);
            param.setNtpServer(ntpServer);
            param.setRootPassword(rootPassword);
            osInstallParamMap.put(host, param);
        } else {
            osInstallParamMap.put(host, null);
        }
    }
    try {
        ComputeUtils.installOsOnHosts(osInstallParamMap);
    } catch (Exception e) {
        logError(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) Host(com.emc.storageos.db.client.model.Host) OsInstallParam(com.emc.storageos.model.compute.OsInstallParam)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16