Search in sources :

Example 36 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep 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)

Example 37 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method deactivateHostsNotAddedToCluster.

/**
 * validate that specified hosts are in the cluster export groups, else deactivate the host
 * @param List to hosts to check
 * @param Cluster
 * @return list of goodHosts ie hosts that are in the cluster EGs.
 */
public static List<Host> deactivateHostsNotAddedToCluster(List<Host> hosts, Cluster cluster) {
    List<Host> hostsToRemove = new ArrayList<Host>();
    List<Host> goodHosts = new ArrayList<Host>();
    if ((hosts != null) && (cluster != null)) {
        List<ExportGroupRestRep> exports = BlockStorageUtils.findExportsContainingCluster(cluster.getId(), null, null);
        if (exports != null) {
            for (Host host : hosts) {
                boolean hostAddedToExports = true;
                for (ExportGroupRestRep exportGroup : exports) {
                    List<HostRestRep> exportedHosts = exportGroup.getHosts();
                    boolean found = false;
                    for (HostRestRep exportedHost : exportGroup.getHosts()) {
                        if (host.getId().equals(exportedHost.getId())) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        hostAddedToExports = false;
                        ExecutionUtils.currentContext().logError("computeutils.clusterexport.hostnotadded", host.getLabel(), exportGroup.getGeneratedName());
                    } else {
                        ExecutionUtils.currentContext().logInfo("computeutils.clusterexport.hostadded", host.getLabel(), exportGroup.getGeneratedName());
                    }
                }
                if (hostAddedToExports) {
                    goodHosts.add(host);
                } else {
                    hostsToRemove.add(host);
                }
            }
        }
    }
    if (!hostsToRemove.isEmpty()) {
        for (Host host : hostsToRemove) {
            try {
                execute(new RemoveHostFromCluster(host.getId()));
            } catch (Exception e) {
                ExecutionUtils.currentContext().logError("computeutils.deactivatehost.failure", host.getHostName(), e.getMessage());
            }
        }
        try {
            List<Host> hostsRemoved = deactivateHosts(hostsToRemove);
        } catch (Exception e) {
            ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
        }
    }
    return goodHosts;
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) RemoveHostFromCluster(com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) 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) TimeoutException(com.emc.vipr.client.exceptions.TimeoutException) ExecutionException(com.emc.sa.engine.ExecutionException) ViPRException(com.emc.vipr.client.exceptions.ViPRException)

Example 38 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep 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 39 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method getVblockHostURIsByCluster.

/**
 * This method fetches all vblock hosts for the given cluster
 * @param clusterId cluster id URI
 * @return
 */
public static Map<URI, String> getVblockHostURIsByCluster(URI clusterId) {
    List<HostRestRep> resp = getVblockHostsInCluster(clusterId);
    List<URI> provisionedHostURIs = Lists.newArrayList();
    Map<URI, String> provisionedHostMap = new HashMap<URI, String>(resp.size());
    for (HostRestRep r : resp) {
        provisionedHostURIs.add(r.getId());
        provisionedHostMap.put(r.getId(), r.getName());
    }
    return provisionedHostMap;
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) HashMap(java.util.HashMap) URI(java.net.URI)

Example 40 with HostRestRep

use of com.emc.storageos.model.host.HostRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method getHostNamesByName.

/**
 * This method checks if the given host names already exist.
 * @param list of host names to check
 * @return list of host names in given list that already exist
 */
public static List<String> getHostNamesByName(ViPRCoreClient client, List<String> names) {
    List<String> hostNames = Lists.newArrayList();
    if (names == null) {
        return Collections.emptyList();
    }
    for (String hostName : names) {
        NameIgnoreCaseFilter<HostRestRep> filter = new NameIgnoreCaseFilter<HostRestRep>(hostName);
        List<HostRestRep> resp = client.hosts().getByTenant(getOrderTenant(), filter);
        for (HostRestRep hostRestRep : resp) {
            hostNames.add(hostRestRep.getHostName());
        }
    }
    return hostNames;
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) NameIgnoreCaseFilter(com.emc.vipr.client.core.filters.NameIgnoreCaseFilter)

Aggregations

HostRestRep (com.emc.storageos.model.host.HostRestRep)46 URI (java.net.URI)17 ArrayList (java.util.ArrayList)10 ExecutionException (com.emc.sa.engine.ExecutionException)7 Host (com.emc.storageos.db.client.model.Host)6 ClusterRestRep (com.emc.storageos.model.host.cluster.ClusterRestRep)6 DeactivateHost (com.emc.sa.service.vipr.compute.tasks.DeactivateHost)5 DiscoverHost (com.emc.sa.service.vipr.compute.tasks.DiscoverHost)5 GetHost (com.emc.sa.service.vipr.tasks.GetHost)5 ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)5 TimeoutException (com.emc.vipr.client.exceptions.TimeoutException)5 ViPRException (com.emc.vipr.client.exceptions.ViPRException)5 HashMap (java.util.HashMap)5 HostUpdateParam (com.emc.storageos.model.host.HostUpdateParam)4 InitiatorRestRep (com.emc.storageos.model.host.InitiatorRestRep)4 Asset (com.emc.sa.asset.annotation.Asset)3 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)3 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)3 VcenterDataCenterRestRep (com.emc.storageos.model.host.vcenter.VcenterDataCenterRestRep)3 Task (com.emc.vipr.client.Task)3