use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshotSessionsByCopySet.
/**
* List snapshot sessions in a session set for a volume group.
*
* @param volumeGroupId The URI of the volume group
* @param param the VolumeGroupCopySetParam containing set name
* @return BlockSnapshotSessionList
* @brief List snapshot sessions in session set for a volume group
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions/copy-sets")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotSessionList getVolumeGroupSnapshotSessionsByCopySet(@PathParam("id") final URI volumeGroupId, final VolumeGroupCopySetParam param) {
ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, ID_FIELD);
// query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate snap session set name
String sessionsetName = param.getCopySetName();
ArgValidator.checkFieldNotNull(sessionsetName, COPY_SET_NAME_FIELD);
// get the snapshot sessions for the given set name in the volume group
BlockSnapshotSessionList snapshotSessionList = new BlockSnapshotSessionList();
// validate that the provided set name actually belongs to this Application
VolumeGroupCopySetList copySetList = getVolumeGroupSnapsetSessionSets(volumeGroup);
if (copySetList.getCopySets().contains(sessionsetName)) {
// get the snapshot sessions for the volume group
List<BlockSnapshotSession> volumeGroupSessions = getVolumeGroupSnapshotSessions(volumeGroup);
for (BlockSnapshotSession session : volumeGroupSessions) {
if (sessionsetName.equals(session.getSessionSetName())) {
snapshotSessionList.getSnapSessionRelatedResourceList().add(toNamedRelatedResource(session));
}
}
}
return snapshotSessionList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshotsForSet.
/**
* List snapshots in a snapshot set for a volume group
*
* @prereq none
* @param volumeGroupId The URI of the volume group
* @brief List snapshots in snapshot set for a volume group
* @return SnapshotList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/copy-sets")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getVolumeGroupSnapshotsForSet(@PathParam("id") final URI volumeGroupId, final VolumeGroupCopySetParam param) {
// query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// validate copy set name
String copySetName = param.getCopySetName();
ArgValidator.checkFieldNotEmpty(copySetName, COPY_SET_NAME_FIELD);
// get all volumes
List<Volume> volumes = ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup);
// get the snapshots for each volume in the group
SnapshotList snapshotList = new SnapshotList();
for (Volume volume : volumes) {
if (volume.isVPlexVolume(_dbClient)) {
volume = VPlexUtil.getVPLEXBackendVolume(volume, true, _dbClient);
if (volume == null || volume.getInactive()) {
log.warn("Cannot find backend volume for VPLEX volume {}", volume.getLabel());
}
}
URIQueryResultList snapshotURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volume.getId()), snapshotURIs);
if (!snapshotURIs.iterator().hasNext()) {
continue;
}
List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotURIs);
for (BlockSnapshot snapshot : snapshots) {
if (snapshot != null && !snapshot.getInactive()) {
if (copySetName.equals(snapshot.getSnapsetLabel())) {
snapshotList.getSnapList().add(toNamedRelatedResource(snapshot));
}
}
}
}
return snapshotList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method getVolumeGroupSnapshotSession.
/**
* Get the specified volume group snapshot session.
*
* @param volumeGroupId The URI of the volume group.
* @param snapshotIsnapshotSessionIdd The URI of the snapshot session.
* @brief Get the specified volume group snapshot session.
* @return BlockSnapshotSessionRestRep.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions/{sid}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotSessionRestRep getVolumeGroupSnapshotSession(@PathParam("id") final URI volumeGroupId, @PathParam("sid") final URI snapshotSessionId) {
ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, ID_FIELD);
// query Volume Group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// get snapshot session
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapshotSessionId, uriInfo, _dbClient, true);
// validate that the provided snapshot session is part of the volume group
validateSnapSessionBelongsToApplication(snapSession, volumeGroup);
return map(_dbClient, snapSession);
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method createVolumeGroupSnapshot.
/**
* Creates a volume group snapshot
* Creates snapshot for all the array replication groups within this Application.
* If partial flag is specified, it creates snapshot 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 snapshot.
*
* @prereq none
*
* @param volumeGroupId the URI of the Volume Group
* - Volume group URI
* @param param VolumeGroupSnapshotCreateParam
*
* @brief Create volume group snapshot
* @return TaskList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createVolumeGroupSnapshot(@PathParam("id") final URI volumeGroupId, VolumeGroupSnapshotCreateParam param) {
// Query volume group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.SNAPSHOT);
// validate name
String name = param.getName();
ArgValidator.checkFieldNotEmpty(name, NAME_FIELD);
name = TimeUtils.formatDateForCurrent(name);
// snapsetLabel is normalized in RP, do it here too to avoid potential mismatch
name = ResourceOnlyNameGenerator.removeSpecialCharsForName(name, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH);
if (StringUtils.isEmpty(name)) {
// original name has special chars only
throw APIException.badRequests.invalidCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT.toString());
}
// check name provided is not duplicate
VolumeGroupCopySetList copySetList = getVolumeGroupSnapshotSets(volumeGroup);
if (copySetList.getCopySets().contains(name)) {
// duplicate name
throw APIException.badRequests.duplicateCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT.toString());
}
// volumes to be processed
List<Volume> volumes = new ArrayList<Volume>();
List<URI> partialVolumeList = new ArrayList<URI>();
boolean partial = isPartialRequest(param, volumeGroup, partialVolumeList);
if (partial) {
log.info("Snapshot requested for subset of array groups in Application.");
// validate that at least one volume URI is provided
ArgValidator.checkFieldNotEmpty(partialVolumeList, VOLUMES_FIELD);
// validate that provided volumes
for (URI volumeURI : partialVolumeList) {
ArgValidator.checkFieldUriType(volumeURI, Volume.class, VOLUME_FIELD);
// Get the volume
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
ArgValidator.checkEntity(volume, volumeURI, isIdEmbeddedInURL(volumeURI));
// validate that provided volume is part of Volume Group
if (!volume.getVolumeGroupIds().contains(volumeGroupId.toString())) {
throw APIException.badRequests.replicaOperationNotAllowedVolumeNotInVolumeGroup(ReplicaTypeEnum.SNAPSHOT.toString(), volume.getLabel());
}
volumes.add(volume);
}
} else {
log.info("Snapshot creation for entire Application");
// get all volumes
volumes.addAll(ControllerUtils.getVolumeGroupVolumes(_dbClient, volumeGroup));
// validate that there should be some volumes in VolumeGroup
if (volumes.isEmpty()) {
throw APIException.badRequests.replicaOperationNotAllowedOnEmptyVolumeGroup(volumeGroup.getLabel(), ReplicaTypeEnum.SNAPSHOT.toString());
}
}
// Check for pending tasks
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), name);
TaskList taskList = new TaskList();
/**
* If there are VMAX3 volumes in the request, we need to create snap session for them.
* For others, create snapshot.
*
* vmax3Volumes - block VMAX3 or backend VMAX3 for VPLEX based on copy side requested
* volumes - except volumes filtered out for above case
*/
// TODO consider copyOnHaSide from user's request once the underlying implementation supports it.
List<Volume> vmax3Volumes = getVMAX3Volumes(volumes, false);
if (!vmax3Volumes.isEmpty()) {
// check snap session name provided is not duplicate
VolumeGroupCopySetList sessionSet = getVolumeGroupSnapsetSessionSets(volumeGroup);
if (sessionSet.getCopySets().contains(name)) {
// duplicate name
throw APIException.badRequests.duplicateCopySetName(name, ReplicaTypeEnum.SNAPSHOT_SESSION.toString());
}
}
// create snapshot
Map<URI, List<URI>> cgToVolUris = ControllerUtils.groupVolumeURIsByCG(volumes);
Set<Entry<URI, List<URI>>> entrySet = cgToVolUris.entrySet();
for (Entry<URI, List<URI>> entry : entrySet) {
URI cgUri = entry.getKey();
log.info("Create snapshot with consistency group {}", cgUri);
try {
BlockConsistencyGroupSnapshotCreate cgSnapshotParam = new BlockConsistencyGroupSnapshotCreate(name, entry.getValue(), param.getCreateInactive(), param.getReadOnly());
TaskList cgTaskList = _blockConsistencyGroupService.createConsistencyGroupSnapshot(cgUri, cgSnapshotParam);
List<TaskResourceRep> taskResourceRepList = cgTaskList.getTaskList();
if (taskResourceRepList != null && !taskResourceRepList.isEmpty()) {
for (TaskResourceRep taskResRep : taskResourceRepList) {
taskList.addTask(taskResRep);
}
}
} catch (InternalException | APIException e) {
log.error("Exception when creating snapshot for consistency group {}", cgUri, e);
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
TaskResourceRep task = BlockServiceUtils.createFailedTaskOnCG(_dbClient, cg, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, e);
taskList.addTask(task);
} catch (Exception ex) {
log.error("Unexpected Exception occurred when creating snapshot for consistency group {}", cgUri, ex);
}
}
// create snapshot session for VMAX3
Map<URI, List<URI>> cgToV3VolUris = ControllerUtils.groupVolumeURIsByCG(vmax3Volumes);
Set<Entry<URI, List<URI>>> entrySetV3 = cgToV3VolUris.entrySet();
for (Entry<URI, List<URI>> entry : entrySetV3) {
URI cgUri = entry.getKey();
log.info("Create snapshot session for consistency group {}, volumes {}", cgUri, Joiner.on(',').join(entry.getValue()));
try {
// create snap session with No targets
SnapshotSessionCreateParam cgSnapshotSessionParam = new SnapshotSessionCreateParam(name, null, entry.getValue());
taskList.getTaskList().addAll(_blockConsistencyGroupService.createConsistencyGroupSnapshotSession(cgUri, cgSnapshotSessionParam).getTaskList());
} catch (InternalException | APIException e) {
log.error("Exception while creating snapshot session for consistency group {}: {}", cgUri, e);
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
TaskResourceRep task = BlockServiceUtils.createFailedTaskOnCG(_dbClient, cg, ResourceOperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT_SESSION, e);
taskList.addTask(task);
} catch (Exception ex) {
log.error("Unexpected Exception occurred while creating snapshot session for consistency group {}: {}", cgUri, ex);
}
}
auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), name);
return taskList;
}
use of com.emc.storageos.db.client.model.VolumeGroup in project coprhd-controller by CoprHD.
the class VolumeGroupService method activateVolumeGroupFullCopy.
/**
* Activate the specified Volume group full copy.
* - Activates full copy for all the array replication groups within this Application.
* - If partial flag is specified, it activates full copy only for set of array replication groups.
* A Full Copy from each array replication group can be provided to indicate which array replication
* groups's full copies needs to be activated.
*
* @prereq Create Volume group full copy as inactive.
*
* @param volumeGroupId The URI of the Volume group.
* @param fullCopyURI The URI of the full copy.
*
* @brief Activate Volume group full copy.
*
* @return TaskList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/full-copies/activate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList activateVolumeGroupFullCopy(@PathParam("id") final URI volumeGroupId, final VolumeGroupFullCopyActivateParam param) {
ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, "id");
// Query Volume Group
final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
TaskList taskList = new TaskList();
// validate replica operation for volume group
validateCopyOperationForVolumeGroup(volumeGroup, ReplicaTypeEnum.FULL_COPY);
// validate the requested full copies
List<Volume> fullCopyVolumesInRequest = new ArrayList<Volume>();
boolean partial = validateFullCopiesInRequest(fullCopyVolumesInRequest, param.getFullCopies(), param.getCopySetName(), param.getSubGroups(), volumeGroupId);
/**
* 1. VolumeGroupService Clone API accepts a Clone URI (to identify clone set and RG)
* - then get All full copies belonging to same full copy set
* - get full copy set name from the requested full copy
* 2. If partial, there will be a List of Clone URIs (one from each RG)
* 3. Group the full copies by Replication Group(RG)
* 4. For each RG, invoke the ConsistencyGroup full copy API (CG uri, clone uri)
* - a. Skip the CG/RG calls when thrown error and continue with other entries; create 'ERROR' Task for this call
* - b. Finally return the Task List (RG tasks may finish at different times as they are different calls)
*/
if (!partial) {
Volume fullCopy = fullCopyVolumesInRequest.get(0);
log.info("Full Copy operation requested for entire Application, Considering full copy {} in request.", fullCopy.getLabel());
fullCopyVolumesInRequest.clear();
fullCopyVolumesInRequest.addAll(getClonesBySetName(fullCopy.getFullCopySetName(), volumeGroup.getId()));
} else {
log.info("Full Copy operation requested for subset of array replication groups in Application.");
}
Map<String, Volume> repGroupToFullCopyMap = groupVolumesByReplicationGroup(fullCopyVolumesInRequest);
for (Map.Entry<String, Volume> entry : repGroupToFullCopyMap.entrySet()) {
String replicationGroup = entry.getKey();
Volume fullCopy = entry.getValue();
log.info("Processing Array Replication Group {}, Full Copy {}", replicationGroup, fullCopy.getLabel());
try {
// get CG URI
URI cgURI = getConsistencyGroupForFullCopy(fullCopy);
// Activate the full copy. Note that it will take into account the
// fact that the volume is in a ReplicationGroup
// and all volumes in that ReplicationGroup will be activated.
taskList.getTaskList().addAll(_blockConsistencyGroupService.activateConsistencyGroupFullCopy(cgURI, fullCopy.getId()).getTaskList());
} catch (InternalException | APIException e) {
String errMsg = String.format("Error activating Array Replication Group %s, Full Copy %s", replicationGroup, fullCopy.getLabel());
log.error(errMsg, e);
TaskResourceRep task = BlockServiceUtils.createFailedTaskOnVolume(_dbClient, fullCopy, ResourceOperationTypeEnum.ACTIVATE_VOLUME_FULL_COPY, e);
taskList.addTask(task);
}
}
if (!partial) {
auditOp(OperationTypeEnum.ACTIVATE_VOLUME_GROUP_FULL_COPY, true, AuditLogManager.AUDITOP_BEGIN, volumeGroup.getId().toString(), fullCopyVolumesInRequest.get(0).getLabel());
}
return taskList;
}
Aggregations