Search in sources :

Example 51 with ExportGroupRestRep

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

the class BlockExportGroupSnapshotsDataTable method fetch.

public static List<ExportBlockSnapshot> fetch(URI exportGroupId) {
    if (exportGroupId == null) {
        return Collections.emptyList();
    }
    ViPRCoreClient client = BourneUtil.getViprClient();
    ExportGroupRestRep exportGroup = client.blockExports().get(exportGroupId);
    List<ExportBlockSnapshot> snapshots = Lists.newArrayList();
    for (ExportBlockParam exportBlockParam : exportGroup.getVolumes()) {
        if (ResourceType.isType(BLOCK_SNAPSHOT, exportBlockParam.getId())) {
            BlockSnapshotRestRep snapshot = client.blockSnapshots().get(exportBlockParam.getId());
            VolumeRestRep volume = client.blockVolumes().get(snapshot.getParent().getId());
            snapshots.add(new ExportBlockSnapshot(snapshot, volume.getName()));
        }
    }
    return snapshots;
}
Also used : ExportBlockParam(com.emc.storageos.model.block.export.ExportBlockParam) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotRestRep(com.emc.storageos.model.block.BlockSnapshotRestRep) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep)

Example 52 with ExportGroupRestRep

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

the class CreateBlockVolumeForHostHelper method exportVolumes.

public List<BlockObjectRestRep> exportVolumes(List<URI> volumeIds) {
    List<URI> batchVolumeIds = Lists.newArrayList();
    int batchCount = 0;
    Iterator<URI> ids = volumeIds.iterator();
    while (ids.hasNext()) {
        batchCount++;
        URI id = ids.next();
        batchVolumeIds.add(id);
        if (batchCount == EXPORT_CHUNK_SIZE || !ids.hasNext()) {
            // See if an existing export exists for the host ports
            ExportGroupRestRep export = null;
            if (cluster != null) {
                export = BlockStorageUtils.findExportByCluster(cluster, project, virtualArray, null);
            } else {
                export = BlockStorageUtils.findExportByHost(host, project, virtualArray, null);
            }
            // If did not find export group for the host/cluster, try find existing empty export with
            // host/cluster name
            boolean createExport = export == null;
            boolean isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
            String exportName = cluster != null ? cluster.getLabel() : host.getHostName();
            if (export == null) {
                export = BlockStorageUtils.findExportsByName(exportName, project, virtualArray);
                isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
                createExport = export == null || !isEmptyExport;
                // If there is an existing non-empty export with the same name, append a time stamp to the name to make it unique
                if (export != null && !isEmptyExport) {
                    exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
                }
            }
            // If the export does not exist or there is a non-empty export with the same name, create a new one
            if (createExport) {
                URI exportId = null;
                if (cluster != null) {
                    exportId = BlockStorageUtils.createClusterExport(project, virtualArray, batchVolumeIds, hlu, cluster, new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                } else {
                    exportId = BlockStorageUtils.createHostExport(project, virtualArray, batchVolumeIds, hlu, host, new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                }
                logInfo("create.block.volume.create.export", exportId);
            } else // Add the volume to the existing export
            {
                BlockStorageUtils.addVolumesToExport(batchVolumeIds, hlu, export.getId(), new HashMap<URI, Integer>(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                // If not, add them.
                if (isEmptyExport) {
                    if (cluster != null) {
                        BlockStorageUtils.addClusterToExport(export.getId(), cluster.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                    } else {
                        BlockStorageUtils.addHostToExport(export.getId(), host.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
                    }
                }
                logInfo("create.block.volume.update.export", export.getId());
            }
            batchVolumeIds.clear();
            batchCount = 0;
        }
    }
    if (host != null) {
        ExecutionUtils.addAffectedResource(host.getId().toString());
    } else if (cluster != null) {
        ExecutionUtils.addAffectedResource(cluster.getId().toString());
    }
    // The volume is created and exported, clear the rollback steps so it will still be available if any other
    // further steps fail
    ExecutionUtils.clearRollback();
    // Get the volumes after exporting, volumes would not have WWNs until after export in VPLEX
    List<BlockObjectRestRep> volumes = BlockStorageUtils.getBlockResources(volumeIds);
    return volumes;
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) Date(java.util.Date) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with ExportGroupRestRep

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

the class ExportBlockVolumeHelper method exportBlockResources.

/**
 * export the block resources identified by URIs in the given resource id list
 *
 * @param resourceIds the list of URIs which identify the block resources that need to be exported
 * @param parentId the parent URI for the list of resourceIds
 * @return The list of export groups which have been created/updated
 */
public List<ExportGroupRestRep> exportBlockResources(List<URI> resourceIds, URI parentId) {
    // the list of exports to return
    List<ExportGroupRestRep> exports = Lists.newArrayList();
    List<URI> newVolumes = new ArrayList<URI>();
    Map<URI, Set<URI>> addVolumeExports = Maps.newHashMap();
    Map<URI, URI> addComputeResourceToExports = Maps.newHashMap();
    // we will need to keep track of the current HLU number
    Integer currentHlu = hlu;
    // get a list of all block resources using the id list provided
    List<BlockObjectRestRep> blockResources = BlockStorageUtils.getBlockResources(resourceIds, parentId);
    URI virtualArrayId = null;
    String exportName = cluster != null ? cluster.getLabel() : host.getHostName();
    // Flag to indicate an empty ExportGroup object in ViPR, i.e., ExportGroup without any volumes and initiators in it.
    boolean isEmptyExport = true;
    ExportGroupRestRep export = null;
    for (BlockObjectRestRep blockResource : blockResources) {
        virtualArrayId = getVirtualArrayId(blockResource);
        // see if we can find an export that uses this block resource
        export = findExistingExportGroup(blockResource, virtualArrayId);
        boolean createExport = export == null;
        isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
        // host/cluster name
        if (export == null) {
            export = BlockStorageUtils.findExportsByName(exportName, projectId, virtualArrayId);
            isEmptyExport = export != null && BlockStorageUtils.isEmptyExport(export);
            createExport = export == null || !isEmptyExport;
        }
        if (createExport) {
            newVolumes.add(blockResource.getId());
        } else // Export exists, check if volume belongs to it
        {
            if (BlockStorageUtils.isVolumeInExportGroup(export, blockResource.getId())) {
                logInfo("export.block.volume.contains.volume", export.getId(), blockResource.getId());
            } else {
                updateExportVolumes(export, blockResource, addVolumeExports);
            }
            // If not, add them.
            if (isEmptyExport) {
                URI computeResource = cluster != null ? cluster.getId() : host.getId();
                addComputeResourceToExports.put(export.getId(), computeResource);
            }
            exports.add(export);
        }
    }
    // If there is an existing non-empty export with the same name, append a time stamp to the name to make it unique
    if (export != null && !isEmptyExport) {
        exportName = exportName + BlockStorageUtils.UNDERSCORE + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
    }
    // Bulk update multiple volumes to single export
    List<URI> volumeIds = Lists.newArrayList();
    for (Map.Entry<URI, Set<URI>> entry : addVolumeExports.entrySet()) {
        volumeIds.addAll(entry.getValue());
    }
    Map<URI, Integer> volumeHlus = getVolumeHLUs(volumeIds);
    for (Map.Entry<URI, Set<URI>> entry : addVolumeExports.entrySet()) {
        BlockStorageUtils.addVolumesToExport(entry.getValue(), currentHlu, entry.getKey(), volumeHlus, minPaths, maxPaths, pathsPerInitiator, portGroup);
        logInfo("export.block.volume.add.existing", entry.getValue(), entry.getKey());
        if ((currentHlu != null) && (currentHlu > -1)) {
            currentHlu += entry.getValue().size();
        }
    }
    for (Map.Entry<URI, URI> entry : addComputeResourceToExports.entrySet()) {
        if (cluster != null) {
            BlockStorageUtils.addClusterToExport(entry.getKey(), cluster.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
            logInfo("export.cluster.add.existing", entry.getValue(), entry.getKey());
        } else {
            BlockStorageUtils.addHostToExport(entry.getKey(), host.getId(), minPaths, maxPaths, pathsPerInitiator, portGroup);
            logInfo("export.host.add.existing", entry.getValue(), entry.getKey());
        }
    }
    // Create new export with multiple volumes that don't belong to an export
    if (!newVolumes.isEmpty()) {
        volumeHlus = getVolumeHLUs(newVolumes);
        URI exportId = null;
        if (cluster != null) {
            exportId = BlockStorageUtils.createClusterExport(projectId, virtualArrayId, newVolumes, currentHlu, cluster, volumeHlus, minPaths, maxPaths, pathsPerInitiator, portGroup);
        } else {
            exportId = BlockStorageUtils.createHostExport(projectId, virtualArrayId, newVolumes, currentHlu, host, volumeHlus, minPaths, maxPaths, pathsPerInitiator, portGroup);
        }
        ExportGroupRestRep exportGroup = BlockStorageUtils.getExport(exportId);
        // add this export to the list of exports we will return to the caller
        exports.add(exportGroup);
    }
    // add host or cluster to the affected resources
    if (host != null) {
        ExecutionUtils.addAffectedResource(host.getId().toString());
    } else if (cluster != null) {
        ExecutionUtils.addAffectedResource(cluster.getId().toString());
    }
    // Clear the rollback at this point so later errors won't undo the exports
    ExecutionUtils.clearRollback();
    return exports;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) Date(java.util.Date) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map)

Example 54 with ExportGroupRestRep

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

the class ExportChangePortGroupService method execute.

@Override
public void execute() throws Exception {
    Task<ExportGroupRestRep> task = execute(new ExportChangePortGroup(exportId, currentPortGroupId, newPortGroupId, suspendWait));
    addAffectedResource(task);
}
Also used : ExportChangePortGroup(com.emc.sa.service.vipr.block.tasks.ExportChangePortGroup) ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep)

Example 55 with ExportGroupRestRep

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

the class UnexportHostService method precheck.

@Override
public void precheck() {
    host = BlockStorageUtils.getHost(hostId);
    String hostName = host.getLabel();
    exports = BlockStorageUtils.findExportsContainingHost(hostId, null, null);
    if (exports.isEmpty()) {
        ExecutionUtils.fail("failTask.UnexportHostService.export", args(), args(hostName));
    }
    volumes = BlockStorageUtils.getBlockResources(uris(volumeIds));
    if (volumes.isEmpty()) {
        ExecutionUtils.fail("failTask.UnexportHostService.volumes", args(), args());
    }
    if (volumes.size() < volumeIds.size()) {
        logWarn("unexport.host.service.not.found", volumeIds.size(), volumes.size());
    }
    for (ExportGroupRestRep export : exports) {
        for (BlockObjectRestRep volume : volumes) {
            URI volumeId = ResourceUtils.id(volume);
            if (BlockStorageUtils.isVolumeInExportGroup(export, volumeId) && StringUtils.equalsIgnoreCase(export.getType(), ExportGroupType.Cluster.name())) {
                ExecutionUtils.fail("failTask.UnexportHostService.clusterExport", args(), args(export.getName()));
            }
        }
    }
    checkForBootVolumes(volumeIds);
}
Also used : ExportGroupRestRep(com.emc.storageos.model.block.export.ExportGroupRestRep) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep) URI(java.net.URI)

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