Search in sources :

Example 1 with RemoveHostFromCluster

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

the class ComputeUtils method deactivateHostsWithNoBootVolume.

/**
 * Deactivate hosts whose boot volumes were not properly created.
 *
 * @param hostToVolumeIdMap map of host object to its respective boot volume
 * @param cluster cluster ID
 * @return list of hosts that were NOT deactivated.  This includes hosts with good boot volumes and hosts where the deactivation failed.
 */
public static Map<Host, URI> deactivateHostsWithNoBootVolume(Map<Host, URI> hostToVolumeIdMap, Cluster cluster) {
    if (hostToVolumeIdMap == null) {
        return Maps.newHashMap();
    }
    List<Host> hostsToRemove = Lists.newArrayList();
    Map<Host, URI> hostsToVolumeIdNotRemovedMap = new HashMap<>(hostToVolumeIdMap);
    for (Entry<Host, URI> hostVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
        Host host = hostVolumeIdEntry.getKey();
        URI volumeId = hostVolumeIdEntry.getValue();
        if ((host != null) && (volumeId == null)) {
            try {
                execute(new RemoveHostFromCluster(host.getId()));
            } catch (Exception e) {
                ExecutionUtils.currentContext().logError("computeutils.deactivatehost.failure", host.getHostName(), e.getMessage());
            }
            hostsToRemove.add(host);
            host.setInactive(true);
        }
    }
    if (!hostsToRemove.isEmpty()) {
        try {
            List<Host> hostsRemoved = deactivateHosts(hostsToRemove);
            for (Host hostCreated : hostToVolumeIdMap.keySet()) {
                boolean isRemovedHost = false;
                for (Host hostRemoved : hostsRemoved) {
                    if (hostCreated.getId().equals(hostRemoved.getId())) {
                        isRemovedHost = true;
                    }
                }
                if (isRemovedHost) {
                    hostsToVolumeIdNotRemovedMap.remove(hostCreated);
                }
            }
        } catch (Exception e) {
            ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
        }
    }
    return hostsToVolumeIdNotRemovedMap;
}
Also used : RemoveHostFromCluster(com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster) HashMap(java.util.HashMap) 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 2 with RemoveHostFromCluster

use of com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster 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 3 with RemoveHostFromCluster

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

the class ComputeUtils method deactivateHostsWithNoExport.

/**
 * Deactivate hosts with no valid export of the boot volume, return a map of hosts still standing.
 *
 * @param hostToVolumeIdMap hosts to volume ID map
 * @param hostToEgIdMap hosts to export group ID map
 * @param cluster cluster, if applicable
 * @return a map of hosts to volume ID that are still exported.
 */
public static Map<Host, URI> deactivateHostsWithNoExport(Map<Host, URI> hostToVolumeIdMap, Map<Host, URI> hostToEgIdMap, Cluster cluster) {
    if (hostToVolumeIdMap == null || hostToVolumeIdMap.isEmpty()) {
        return Maps.newHashMap();
    }
    List<Host> hostsToRemove = Lists.newArrayList();
    Map<Host, URI> hostToVolumeIdNotRemovedMap = new HashMap<Host, URI>(hostToVolumeIdMap);
    // Perform all host removal from cluster operations first.
    for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
        Host host = hostToVolumeIdEntry.getKey();
        URI egId = hostToEgIdMap.get(host);
        if (NullColumnValueGetter.isNullURI(egId) && host != null) {
            try {
                execute(new RemoveHostFromCluster(host.getId()));
            } catch (Exception e) {
                ExecutionUtils.currentContext().logError("computeutils.deactivatehost.noexport", host.getHostName(), e.getMessage());
            }
            hostsToRemove.add(host);
            host.setInactive(true);
        }
    }
    if (!hostsToRemove.isEmpty()) {
        // Deactivate all the hosts at the same time.
        try {
            deactivateHosts(hostsToRemove);
        } catch (Exception e) {
            ExecutionUtils.currentContext().logError("computeutils.deactivatehost.deactivate.failure", e.getMessage());
        }
        // Deactivate all the of boot volumes at the same time.
        try {
            List<URI> bootVolsToRemove = Lists.newArrayList();
            for (Host host : hostsToRemove) {
                URI volumeId = hostToVolumeIdMap.get(host);
                bootVolsToRemove.add(volumeId);
                BlockObjectRestRep volume = BlockStorageUtils.getBlockResource(volumeId);
                removeBootVolumeTag(volume, host.getId());
            }
            BlockStorageUtils.deactivateVolumes(bootVolsToRemove, VolumeDeleteTypeEnum.FULL);
        } catch (Exception e) {
            ExecutionUtils.currentContext().logError("computeutils.bootvolume.deactivate.failure", e.getMessage());
        }
        // Now remove host entries from the map that we removed.
        hostToVolumeIdNotRemovedMap.remove(hostsToRemove);
    }
    return hostToVolumeIdNotRemovedMap;
}
Also used : RemoveHostFromCluster(com.emc.sa.service.vipr.compute.tasks.RemoveHostFromCluster) HashMap(java.util.HashMap) 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)

Aggregations

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