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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations