Search in sources :

Example 36 with ExportGroupRestRep

use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.

the class BlockStorageUtils method addClusterToExport.

public static void addClusterToExport(URI exportId, URI cluster, Integer minPaths, Integer maxPaths, Integer pathsPerInitiator, URI portGroup) {
    Task<ExportGroupRestRep> task = execute(new AddClusterToExport(exportId, cluster, minPaths, maxPaths, pathsPerInitiator, portGroup));
    addRollback(new DeactivateBlockExport(exportId));
    addAffectedResource(task);
}
Also used : DeactivateBlockExport(com.emc.sa.service.vipr.block.tasks.DeactivateBlockExport) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) AddClusterToExport(com.emc.sa.service.vipr.block.tasks.AddClusterToExport)

Example 37 with ExportGroupRestRep

use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.

the class ResourceUtils method getHostExports.

public static List<HostExport> getHostExports(Collection<ITLRestRep> itls) {
    Map<URI, HostExport> hostExports = Maps.newLinkedHashMap();
    Map<ITLRestRep, ExportGroupRestRep> exportMap = getExportMap(itls);
    for (Map.Entry<ITLRestRep, ExportGroupRestRep> entry : exportMap.entrySet()) {
        HostRestRep host = getHost(entry.getKey(), entry.getValue());
        if (host == null) {
            continue;
        }
        HostExport hostExport = hostExports.get(host.getId());
        if (hostExport == null) {
            hostExport = createHostExport(host);
            hostExports.put(host.getId(), hostExport);
        }
        hostExport.exportMap.put(entry.getKey(), entry.getValue());
    }
    return Lists.newArrayList(hostExports.values());
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep) URI(java.net.URI) Map(java.util.Map)

Example 38 with ExportGroupRestRep

use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.

the class ViPRClientApp method createBlockVolumeForHost.

public void createBlockVolumeForHost() {
    List<HostRestRep> hosts = client.hosts().getByUserTenant(HostTypeFilter.ESX.not());
    // User choice
    HostRestRep selectedHost = chooseHost(hosts);
    List<VirtualArrayRestRep> virtualArrays = client.varrays().findByConnectedHost(selectedHost);
    // User choice
    VirtualArrayRestRep selectedVirtualArray = chooseVirtualArray(virtualArrays);
    List<BlockVirtualPoolRestRep> virtualPools = client.blockVpools().getByVirtualArray(selectedVirtualArray.getId());
    // User choice
    BlockVirtualPoolRestRep selectedVirtualPool = chooseVirtualPool(virtualPools);
    List<ProjectRestRep> projects = client.projects().getByUserTenant();
    // User choice
    ProjectRestRep selectedProject = chooseProject(projects);
    URI volumeId = createVolume(selectedVirtualArray, selectedVirtualPool, selectedProject);
    List<ExportGroupRestRep> exports = new ArrayList<>();
    if (exports.isEmpty()) {
        createExport(volumeId, selectedHost, selectedVirtualArray, selectedProject);
    } else {
        addVolumeToExport(volumeId, exports.get(0));
    }
}
Also used : HostRestRep(com.emc.storageos.model.host.HostRestRep) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) VirtualArrayRestRep(com.emc.storageos.model.varray.VirtualArrayRestRep) ArrayList(java.util.ArrayList) BlockVirtualPoolRestRep(com.emc.storageos.model.vpool.BlockVirtualPoolRestRep) ProjectRestRep(com.emc.storageos.model.project.ProjectRestRep) URI(java.net.URI)

Example 39 with ExportGroupRestRep

use of com.emc.storageos.model.block.export.ExportGroupRestRep 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 40 with ExportGroupRestRep

use of com.emc.storageos.model.block.export.ExportGroupRestRep in project coprhd-controller by CoprHD.

the class ComputeUtils method exportBootVols.

/**
 * Exports all boot volumes to respective hosts.
 *
 * Since exporting to boot volumes requires only one volume be exported for OS install, we have extra checks
 * in here:
 * - If there is an existing EG with the same name, we need to make additional checks:
 *   - If the EG has no initiators and volumes, re-use it.  Add the host and volume.
 *   - If the EG has our initiators and a volume (or more), error out.
 *   - If the EG has different initiators, create an EG with a different name.
 *   - If the EG has our initiators and no volumes, re-use it.  Add the volume only.
 *
 * @param hostToVolumeIdMap host to boot volume ID map
 * @param project project
 * @param virtualArray virtual array
 * @param hlu HLU
 * @param portGroup port group URI
 * @return returns a map of hosts to Export Group URIs
 */
public static Map<Host, URI> exportBootVols(Map<Host, URI> hostToVolumeIdMap, URI project, URI virtualArray, Integer hlu, URI portGroup) {
    if (hostToVolumeIdMap == null || hostToVolumeIdMap.isEmpty()) {
        return Maps.newHashMap();
    }
    Map<Task<ExportGroupRestRep>, Host> taskToHostMap = new HashMap<>();
    for (Entry<Host, URI> hostToVolumeIdEntry : hostToVolumeIdMap.entrySet()) {
        Host host = hostToVolumeIdEntry.getKey();
        URI volumeId = hostToVolumeIdEntry.getValue();
        if (!NullColumnValueGetter.isNullURI(volumeId) && (host != null) && !(host.getInactive())) {
            try {
                ExportGroupRestRep export = BlockStorageUtils.findExportByHost(host, project, virtualArray, null);
                if (export != null && !export.getVolumes().isEmpty()) {
                    throw new IllegalStateException(new Throwable("Existing export contains other volumes.  Controller supports only the boot volume visible to host." + host.getHostName()));
                }
                // We can add the host to that export group if it's empty.
                if (export == null) {
                    export = BlockStorageUtils.findExportsByName(host.getHostName(), project, virtualArray);
                }
                boolean createExport = export == null;
                boolean isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
                String exportName = host.getHostName();
                if (export != null && !isEmptyExport) {
                    exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
                    createExport = true;
                }
                Task<ExportGroupRestRep> task = null;
                if (createExport) {
                    task = BlockStorageUtils.createHostExportNoWait(exportName, project, virtualArray, Arrays.asList(volumeId), hlu, host, portGroup);
                } else {
                    task = BlockStorageUtils.addHostAndVolumeToExportNoWait(export.getId(), // Don't add the host if there are already initiators in this export group.
                    export.getInitiators() != null && !export.getInitiators().isEmpty() ? null : host.getId(), volumeId, hlu, portGroup);
                }
                taskToHostMap.put(task, host);
            } catch (ExecutionException e) {
                String errorMessage = e.getMessage() == null ? "" : e.getMessage();
                ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", host.getHostName(), errorMessage);
            }
            // prevent exports from rolling back on exception
            ExecutionUtils.clearRollback();
        }
    }
    // Monitor tasks
    Map<Host, URI> hostToEgIdMap = new HashMap<>();
    List<Task<ExportGroupRestRep>> tasks = new ArrayList<>(taskToHostMap.keySet());
    while (!tasks.isEmpty()) {
        tasks = waitAndRefresh(tasks);
        for (Task<ExportGroupRestRep> successfulTask : getSuccessfulTasks(tasks)) {
            URI exportId = successfulTask.getResourceId();
            addAffectedResource(exportId);
            hostToEgIdMap.put(taskToHostMap.get(successfulTask), exportId);
            tasks.remove(successfulTask);
        }
        for (Task<ExportGroupRestRep> failedTask : getFailedTasks(tasks)) {
            String errorMessage = failedTask.getMessage() == null ? "" : failedTask.getMessage();
            ExecutionUtils.currentContext().logError("computeutils.exportbootvolumes.failure", failedTask.getResource().getName(), errorMessage);
            tasks.remove(failedTask);
        }
    }
    return hostToEgIdMap;
}
Also used : Task(com.emc.vipr.client.Task) 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) Date(java.util.Date) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) ExecutionException(com.emc.sa.engine.ExecutionException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ExportGroupRestRep (com.emc.storageos.model.block.export.ExportGroupRestRep)59 URI (java.net.URI)36 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)24 Asset (com.emc.sa.asset.annotation.Asset)10 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)10 FlashException (controllers.util.FlashException)9 ExportUpdateParam (com.emc.storageos.model.block.export.ExportUpdateParam)8 AssetOption (com.emc.vipr.model.catalog.AssetOption)8 ArrayList (java.util.ArrayList)8 ExportBlockParam (com.emc.storageos.model.block.export.ExportBlockParam)7 DeactivateBlockExport (com.emc.sa.service.vipr.block.tasks.DeactivateBlockExport)5 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)5 BlockObjectRestRep (com.emc.storageos.model.block.BlockObjectRestRep)5 ITLRestRep (com.emc.storageos.model.block.export.ITLRestRep)5 HostRestRep (com.emc.storageos.model.host.HostRestRep)5 HashSet (java.util.HashSet)5 BlockSnapshotRestRep (com.emc.storageos.model.block.BlockSnapshotRestRep)4 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)4 SimpleValueRep (com.emc.storageos.model.customconfig.SimpleValueRep)4 StoragePortGroupRestRepList (com.emc.storageos.model.portgroup.StoragePortGroupRestRepList)4