use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method performVolumeGroupSnapshotSessionOperation.
/*
* Wrapper of BlockConsistencyGroupService methods for snapshot session operations
*
* @param volumeGroupId
*
* @param param
*
* @return a TaskList
*/
private TaskList performVolumeGroupSnapshotSessionOperation(final URI volumeGroupId, final VolumeGroupSnapshotSessionOperationParam param, OperationTypeEnum opType) {
List<BlockSnapshotSession> snapSessions = getSnapshotSessionsGroupedBySnapSessionset(volumeGroupId, param);
// Check for pending tasks
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, volumeGroupId);
if (opType == OperationTypeEnum.RESTORE_VOLUME_GROUP_SNAPSHOT_SESSION) {
checkForApplicationPendingTasks(volumeGroup, _dbClient, true);
} else {
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
}
auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), param.getSnapshotSessions());
TaskList taskList = new TaskList();
Table<URI, String, BlockSnapshotSession> storageRgToSnapshot = ControllerUtils.getSnapshotSessionForStorageReplicationGroup(snapSessions, _dbClient);
for (Cell<URI, String, BlockSnapshotSession> cell : storageRgToSnapshot.cellSet()) {
BlockSnapshotSession session = cell.getValue();
log.info("{} for replication group {}", opType.getDescription(), cell.getColumnKey());
ResourceOperationTypeEnum oprEnum = null;
try {
// should not be null
URI cgUri = session.getConsistencyGroup();
URI sessionUri = session.getId();
log.info("CG: {}, Session: {}", cgUri, session.getLabel());
switch(opType) {
case RESTORE_VOLUME_GROUP_SNAPSHOT_SESSION:
oprEnum = ResourceOperationTypeEnum.RESTORE_SNAPSHOT_SESSION;
taskList.addTask(_blockConsistencyGroupService.restoreConsistencyGroupSnapshotSession(cgUri, sessionUri));
break;
case DELETE_VOLUME_GROUP_SNAPSHOT_SESSION:
oprEnum = ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT_SESSION;
taskList.getTaskList().addAll(_blockConsistencyGroupService.deactivateConsistencyGroupSnapshotSession(cgUri, sessionUri).getTaskList());
break;
case LINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
oprEnum = ResourceOperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGETS;
SnapshotSessionLinkTargetsParam linkParam = new SnapshotSessionLinkTargetsParam(((VolumeGroupSnapshotSessionLinkTargetsParam) param).getNewLinkedTargets());
taskList.getTaskList().addAll(_blockConsistencyGroupService.linkTargetVolumes(cgUri, sessionUri, linkParam).getTaskList());
break;
case RELINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
oprEnum = ResourceOperationTypeEnum.RELINK_CONSISTENCY_GROUP_SNAPSHOT_SESSION_TARGETS;
SnapshotSessionRelinkTargetsParam relinkParam = new SnapshotSessionRelinkTargetsParam(getRelinkTargetIdsForSession((VolumeGroupSnapshotSessionRelinkTargetsParam) param, session, snapSessions.size()));
taskList.getTaskList().addAll(_blockConsistencyGroupService.relinkTargetVolumes(cgUri, sessionUri, relinkParam).getTaskList());
break;
case UNLINK_VOLUME_GROUP_SNAPSHOT_SESSION_TARGET:
oprEnum = ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS;
SnapshotSessionUnlinkTargetsParam unlinkParam = new SnapshotSessionUnlinkTargetsParam(getUnlinkTargetIdsForSession((VolumeGroupSnapshotSessionUnlinkTargetsParam) param, session));
taskList.addTask(_blockConsistencyGroupService.unlinkTargetVolumesForSession(cgUri, sessionUri, unlinkParam));
break;
default:
log.error("Unsupported operation {}", opType.getDescription());
break;
}
} catch (InternalException | APIException e) {
String errMsg = String.format("Exception occurred while performing %s on Replication group %s", opType.getDescription(), cell.getColumnKey());
log.error(errMsg, e);
TaskResourceRep task = BlockServiceUtils.createFailedTaskOnSnapshotSession(_dbClient, session, oprEnum, e);
taskList.addTask(task);
} catch (Exception ex) {
String errMsg = String.format("Unexpected Exception occurred while performing %s on Replication group %s", opType.getDescription(), cell.getColumnKey());
log.error(errMsg, ex);
}
}
auditOp(opType, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), param.getSnapshotSessions());
return taskList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getSnapshotsGroupedBySnapset.
/**
* Validate resources and group snapshots by snapsetLabel
*
* If partial, group snapshots in VolumeGroupSnapshotOperationParam by snapsetLabel
* If full, find all the snapshots for each snapsetLabel that the snapshots in the param belong to
*
* @param volumeGroupId
* @param param
* @return map snapsetLabel to snapshots
*/
private Map<String, List<BlockSnapshot>> getSnapshotsGroupedBySnapset(final URI volumeGroupId, VolumeGroupSnapshotOperationParam param) {
// Query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
List<URI> snapshotsInRequest = new ArrayList<URI>();
boolean partialRequest = false;
if (param.getSnapshots() != null && !param.getSnapshots().isEmpty()) {
// validate only one snapshot URI is provided for full request
if (!param.getPartial() && param.getSnapshots().size() > 1) {
throw APIException.badRequests.invalidNumberOfReplicas(ReplicaTypeEnum.SNAPSHOT.toString());
}
snapshotsInRequest.addAll(param.getSnapshots());
partialRequest = param.getPartial();
} else {
ArgValidator.checkFieldNotEmpty(param.getCopySetName(), COPY_SET_NAME_FIELD);
if (param.getSubGroups() != null && !param.getSubGroups().isEmpty()) {
partialRequest = validateSubGroupsParam(param.getSubGroups(), volumeGroup);
}
URIQueryResultList snapshotIds = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotsBySnapsetLabel(param.getCopySetName()), snapshotIds);
Iterator<BlockSnapshot> iter = _dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotIds);
if (partialRequest) {
// get one snapshot per sub group requested
List<Volume> volumesInApplication = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
Map<URI, Volume> volumesMap = new HashMap<URI, Volume>();
for (Volume volume : volumesInApplication) {
if (volume.getAssociatedVolumes() != null) {
List<URI> assocVolIds = new ArrayList<URI>();
for (String s : volume.getAssociatedVolumes()) {
assocVolIds.add(URI.create(s));
}
List<Volume> assocVols = _dbClient.queryObject(Volume.class, assocVolIds);
for (Volume assocVol : assocVols) {
volumesMap.put(assocVol.getId(), assocVol);
}
} else {
volumesMap.put(volume.getId(), volume);
}
}
while (iter.hasNext()) {
BlockSnapshot snapshot = iter.next();
Volume parent = volumesMap.get(snapshot.getParent().getURI());
if (parent != null && param.getSubGroups().contains(parent.getReplicationGroupInstance())) {
snapshotsInRequest.add(snapshot.getId());
}
}
} else {
// for non-partial, we only need one snapshot per sub group
Map<String, List<URI>> subGroupSnapshotMap = new HashMap<String, List<URI>>();
while (iter.hasNext()) {
BlockSnapshot snapshot = iter.next();
if (NullColumnValueGetter.isNotNullValue(snapshot.getReplicationGroupInstance())) {
if (subGroupSnapshotMap.get(snapshot.getReplicationGroupInstance()) == null) {
subGroupSnapshotMap.put(snapshot.getReplicationGroupInstance(), new ArrayList<URI>());
}
subGroupSnapshotMap.get(snapshot.getReplicationGroupInstance()).add(snapshot.getId());
}
}
for (Entry<String, List<URI>> entry : subGroupSnapshotMap.entrySet()) {
snapshotsInRequest.add(entry.getValue().get(0));
}
}
}
Map<String, List<BlockSnapshot>> snapsetToSnapshots = new HashMap<String, List<BlockSnapshot>>();
for (URI snapshotURI : snapshotsInRequest) {
ArgValidator.checkFieldUriType(snapshotURI, BlockSnapshot.class, SNAPSHOT_FIELD);
// Get the snapshot
BlockSnapshot snapshot = BlockServiceUtils.querySnapshotResource(snapshotURI, uriInfo, _dbClient);
if (NullColumnValueGetter.isNullValue(snapshot.getReplicationGroupInstance())) {
throw APIException.badRequests.noReplicationGroupForReplica(snapshot.getLabel());
}
// validate that source of the provided snapshot is part of the volume group
if (!ControllerUtils.isSourceInVoumeGroup(snapshot, volumeGroupId, _dbClient)) {
throw APIException.badRequests.replicaOperationNotAllowedSourceNotInVolumeGroup(ReplicaTypeEnum.SNAPSHOT.toString(), snapshot.getLabel());
}
String snapsetLabel = snapshot.getSnapsetLabel();
List<BlockSnapshot> snapshots = snapsetToSnapshots.get(snapsetLabel);
if (snapshots == null) {
if (partialRequest) {
snapshots = new ArrayList<BlockSnapshot>();
snapshots.add(snapshot);
} else {
snapshots = ControllerUtils.getVolumeGroupSnapshots(volumeGroup.getId(), snapsetLabel, _dbClient);
}
snapsetToSnapshots.put(snapsetLabel, snapshots);
} else if (partialRequest) {
snapshots.add(snapshot);
}
}
return snapsetToSnapshots;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method createVolumeGroupFullCopy.
/**
* Creates a volume group full copy
* - Creates full copy for all the array replication groups within this Application.
* - If partial flag is specified, it creates full copy only for set of array replication groups.
* A Volume from each array replication group can be provided to indicate which array replication
* groups are required to take full copy.
*
* @prereq none
*
* @param volumeGroupId the URI of the Volume Group
* - Volume group URI
* @param param VolumeGroupFullCopyCreateParam
*
* @brief Create volume group fullcopy
* @return TaskList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createVolumeGroupFullCopy(@PathParam("id") final URI volumeGroupId, VolumeGroupFullCopyCreateParam param) {
ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
// Query Volume Group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
ArgValidator.checkEntityNotNull(volumeGroup, volumeGroupId, isIdEmbeddedInURL(volumeGroupId));
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.FULL_COPY);
TaskList taskList = new TaskList();
// get all volumes
List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
// validate that there should be some volumes in VolumeGroup
if (volumes.isEmpty()) {
throw APIException.badRequests.replicaOperationNotAllowedOnEmptyVolumeGroup(volumeGroup.getLabel(), ReplicaTypeEnum.FULL_COPY.toString());
}
List<URI> partialVolumeList = new ArrayList<URI>();
boolean partial = isPartialRequest(param, volumeGroup, partialVolumeList);
if (partial) {
log.info("Full Copy requested for subset of array groups in Application.");
// validate that at least one volume URI is provided
ArgValidator.checkFieldNotEmpty(partialVolumeList, "volumes");
// validate that provided volumes
Set<String> arrayGroupNames = new HashSet<String>();
List<Volume> volumesInRequest = new ArrayList<Volume>();
for (URI volumeURI : partialVolumeList) {
ArgValidator.checkFieldUriType(volumeURI, Volume.class, "volume");
// Get the Volume.
Volume volume = (Volume) BlockFullCopyUtils.queryFullCopyResource(volumeURI, uriInfo, true, _dbClient);
String arrayGroupName = volume.getReplicationGroupInstance();
if (volume.isVPlexVolume(_dbClient)) {
// get backend source volume to get RG name
Volume backedVol = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
if (backedVol != null) {
arrayGroupName = backedVol.getReplicationGroupInstance();
}
}
// this shouldn't happen, but just in case, skip if replicationGroupInstance is null
if (NullColumnValueGetter.isNullValue(arrayGroupName)) {
log.info("Skipping volume {} because replicationGroupInstance is null", volume.getLabel());
continue;
}
// skip repeated array groups
if (arrayGroupNames.contains(arrayGroupName)) {
log.info("Skipping repetitive request for Volume array group {}. Volume: {}", arrayGroupName, volume.getLabel());
continue;
}
arrayGroupNames.add(arrayGroupName);
// validate that provided volumes are part of Volume Group
if (!volume.getVolumeGroupIds().contains(volumeGroupId.toString())) {
throw APIException.badRequests.replicaOperationNotAllowedVolumeNotInVolumeGroup(ReplicaTypeEnum.FULL_COPY.toString(), volume.getLabel());
}
volumesInRequest.add(volume);
}
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
// check for full copy not supported volumes
for (String groupName : arrayGroupNames) {
checkForFullCopyNotSupportedVolumes(CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, AlternateIdConstraint.Factory.getVolumeReplicationGroupInstanceConstraint(groupName)));
}
for (Volume volume : volumesInRequest) {
// set Flag in Volume so that we will know about partial request during processing.
volume.addInternalFlags(Flag.VOLUME_GROUP_PARTIAL_REQUEST);
_dbClient.updateObject(volume);
// to make the requested name unique across array replication groups
try {
taskList.getTaskList().addAll(getFullCopyManager().createFullCopy(volume.getId(), param).getTaskList());
} catch (Exception e) {
volume.clearInternalFlags(Flag.VOLUME_GROUP_PARTIAL_REQUEST);
_dbClient.updateObject(volume);
throw e;
}
}
} else {
log.info("Full Copy requested for entire Application");
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
// make sure there are no xtremio/unity volumes in the application
checkForFullCopyNotSupportedVolumes(volumes);
auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_FULL_COPY, true, AuditLogManager.AUDITOP_BEGIN, volumeGroup.getId().toString(), param.getName(), param.getCount());
// Full copy will be created for all volumes in Application
taskList = getFullCopyManager().createFullCopy(volumes.get(0).getId(), param);
}
return taskList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshot.
/**
* Get the specified volume group snapshot
*
* @prereq none
* @param volumeGroupId The URI of the volume group
* @param snapshotId The URI of the snapshot
* @brief Get the specified volume group snapshot
* @return BlockSnapshotRestRep
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotRestRep getVolumeGroupSnapshot(@PathParam("id") final URI volumeGroupId, @PathParam("sid") URI snapshotId) {
// query Volume Group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// validate snapshot ID
ArgValidator.checkFieldUriType(snapshotId, BlockSnapshot.class, SNAPSHOT_ID_FIELD);
// get snapshot
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotId);
ArgValidator.checkEntity(snapshot, snapshotId, isIdEmbeddedInURL(snapshotId), true);
// validate that source of the provided snapshot is part of the volume group
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
if (volume != null && Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
// get VPLEX virtual volume to check for volume group reference
volume = Volume.fetchVplexVolume(_dbClient, volume);
}
if (volume == null || volume.getInactive() || !volume.getVolumeGroupIds().contains(volumeGroupId.toString())) {
throw APIException.badRequests.replicaOperationNotAllowedSourceNotInVolumeGroup(ReplicaTypeEnum.SNAPSHOT.toString(), snapshot.getLabel());
}
return BlockMapper.map(_dbClient, snapshot);
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupFullCopy.
/**
* Get the specified volume group full copy.
*
* @prereq none
* @param volumeGroupId The URI of the volume group.
* @param fullCopyURI The URI of the full copy.
*
* @brief Get the specified volume group full copy.
*
* @return The full copy volume.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies/{fcid}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public VolumeRestRep getVolumeGroupFullCopy(@PathParam("id") final URI volumeGroupId, @PathParam("fcid") URI fullCopyURI) {
ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
// Query Volume Group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.FULL_COPY);
Volume fullCopyVolume = (Volume) BlockFullCopyUtils.queryFullCopyResource(fullCopyURI, uriInfo, false, _dbClient);
verifyReplicaForCopyRequest(fullCopyVolume, volumeGroupId);
// Get and return the full copy.
return BlockMapper.map(_dbClient, fullCopyVolume);
}
Aggregations