use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.
the class BlockStorageUtils method getBlockResources.
/**
* Retrieve a list of block resources based on the resource ids provided. This will gather
* the appropriate resources based on the resource type of the ids provided.
*
* @param resourceIds of the resources to retrieve.
* @param parentId of a continuous copy. This will be null for all other resource types.
* @return list of block resources
*/
public static List<BlockObjectRestRep> getBlockResources(List<URI> resourceIds, URI parentId) {
List<BlockObjectRestRep> blockResources = Lists.newArrayList();
List<URI> blockVolumes = new ArrayList<URI>();
List<URI> blockSnapshots = new ArrayList<URI>();
List<URI> blockContinuousCopies = new ArrayList<URI>();
for (URI resourceId : resourceIds) {
ResourceType volumeType = ResourceType.fromResourceId(resourceId.toString());
switch(volumeType) {
case VOLUME:
blockVolumes.add(resourceId);
break;
case BLOCK_SNAPSHOT:
blockSnapshots.add(resourceId);
break;
case BLOCK_CONTINUOUS_COPY:
blockContinuousCopies.add(resourceId);
break;
default:
break;
}
}
if (!blockVolumes.isEmpty()) {
blockResources.addAll(getVolumes(blockVolumes));
}
if (!blockSnapshots.isEmpty()) {
blockResources.addAll(getBlockSnapshots(blockSnapshots));
}
if (!blockContinuousCopies.isEmpty()) {
blockResources.addAll(getBlockContinuousCopies(blockContinuousCopies, parentId));
}
return blockResources;
}
use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.
the class CreateBlockSnapshotService method checkAndPurgeObsoleteSnapshots.
/**
* Check retention policy and delete obsolete snapshots if necessary
*
* @param volumeOrCgId - volume id or consistency group id
*/
private void checkAndPurgeObsoleteSnapshots(String volumeOrCgId) {
if (!isRetentionRequired()) {
return;
}
List<RetainedReplica> replicas = findObsoleteReplica(volumeOrCgId);
for (RetainedReplica replica : replicas) {
if (replica.getAssociatedReplicaIds() == null || replica.getAssociatedReplicaIds().isEmpty())
continue;
for (String obsoleteSnapshotId : replica.getAssociatedReplicaIds()) {
info("Deactivating snapshot %s since it exceeds max number of snapshots allowed", obsoleteSnapshotId);
if (ConsistencyUtils.isVolumeStorageType(storageType)) {
if (BlockProvider.SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
BlockSnapshotSessionRestRep obsoloteCopy = getClient().blockSnapshotSessions().get(uri(obsoleteSnapshotId));
info("Deactivating snapshot session %s", obsoloteCopy.getName());
execute(new DeactivateBlockSnapshotSession(uri(obsoleteSnapshotId)));
} else {
BlockObjectRestRep obsoleteCopy = BlockStorageUtils.getVolume(uri(obsoleteSnapshotId));
info("Deactivating snapshot %s", obsoleteCopy.getName());
execute(new DeactivateBlockSnapshot(uri(obsoleteSnapshotId), VolumeDeleteTypeEnum.FULL));
}
} else {
if (BlockProvider.CG_SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
BlockSnapshotSessionRestRep obsoloteCopy = getClient().blockSnapshotSessions().get(uri(obsoleteSnapshotId));
info("Deactivating snapshot session %s", obsoloteCopy.getName());
ConsistencyUtils.removeSnapshotSession(uri(volumeOrCgId), uri(obsoleteSnapshotId));
} else {
BlockObjectRestRep obsoleteCopy = BlockStorageUtils.getVolume(uri(obsoleteSnapshotId));
info("Deactivating snapshot %s", obsoleteCopy.getName());
ConsistencyUtils.removeSnapshot(uri(volumeOrCgId), uri(obsoleteSnapshotId));
}
}
}
getModelClient().delete(replica);
}
}
use of com.emc.storageos.model.block.BlockObjectRestRep in project coprhd-controller by CoprHD.
the class CreateBlockSnapshotService method execute.
@Override
public void execute() {
Tasks<? extends DataObjectRestRep> tasks = null;
if (ConsistencyUtils.isVolumeStorageType(storageType)) {
for (BlockObjectRestRep volume : volumes) {
checkAndPurgeObsoleteSnapshots(volume.getId().toString());
if (BlockProvider.SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
tasks = execute(new CreateBlockSnapshotSession(volume.getId(), nameParam, linkedSnapshotName, linkedSnapshotCount, linkedSnapshotCopyMode));
} else {
tasks = execute(new CreateBlockSnapshot(volume.getId(), type, nameParam, readOnly));
}
addAffectedResources(tasks);
addRetainedReplicas(volume.getId(), tasks.getTasks());
}
} else {
for (String consistencyGroupId : volumeIds) {
checkAndPurgeObsoleteSnapshots(consistencyGroupId);
if (BlockProvider.CG_SNAPSHOT_SESSION_TYPE_VALUE.equals(type)) {
tasks = ConsistencyUtils.createSnapshotSession(uri(consistencyGroupId), nameParam, linkedSnapshotName, linkedSnapshotCount, linkedSnapshotCopyMode);
} else {
tasks = ConsistencyUtils.createSnapshot(uri(consistencyGroupId), nameParam, readOnly);
}
addAffectedResources(tasks);
addRetainedReplicas(uri(consistencyGroupId), tasks.getTasks());
}
}
}
use of com.emc.storageos.model.block.BlockObjectRestRep 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.BlockObjectRestRep in project coprhd-controller by CoprHD.
the class BlockStorageUtils method verifyVolumeDependencies.
/**
* Verify that list of volume doesn't contain any dependencies (snapshot, full copies, continuous copy)
*
* @param volumeIds of the volumes to validate dependencies
*/
public static void verifyVolumeDependencies(List<URI> volumeIds, URI projectId) {
List<URI> allBlockResources = Lists.newArrayList(volumeIds);
for (URI volumeId : volumeIds) {
BlockObjectRestRep volume = getVolume(volumeId);
allBlockResources.addAll(getSrdfTargetVolumes(volume));
allBlockResources.addAll(getRpTargetVolumes(volume));
}
execute(new VerifyVolumeDependencies(allBlockResources, projectId));
}
Aggregations