use of com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam in project coprhd-controller by CoprHD.
the class CreateSnapshotSessionForApplication method doExecute.
@Override
protected Tasks<TaskResourceRep> doExecute() throws Exception {
VolumeGroupSnapshotSessionCreateParam input = new VolumeGroupSnapshotSessionCreateParam();
input.setName(name);
input.setVolumes(volumes);
input.setPartial(true);
TaskList taskList = getClient().application().createSnapshotSessionOfApplication(applicationId, input);
return new Tasks<TaskResourceRep>(getClient().auth().getClient(), taskList.getTaskList(), TaskResourceRep.class);
}
use of com.emc.storageos.model.application.VolumeGroupSnapshotSessionCreateParam in project coprhd-controller by CoprHD.
the class VolumeGroupService method createVolumeGroupSnapshotSession.
/**
* Creates a volume group snapshot session
* - Creates snapshot session for all the array replication groups within this Application.
* - If partial flag is specified, it creates snapshot session 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 session.
*
* @prereq none
*
* @param volumeGroupId the URI of the Volume Group
* - Volume group URI
* @param param VolumeGroupSnapshotSessionCreateParam
*
* @brief Create volume group snapshot session
* @return TaskList
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ANY })
public TaskList createVolumeGroupSnapshotSession(@PathParam("id") final URI volumeGroupId, VolumeGroupSnapshotSessionCreateParam param) {
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_SESSION);
// validate name
String name = TimeUtils.formatDateForCurrent(param.getName());
ArgValidator.checkFieldNotEmpty(name, NAME_FIELD);
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_SESSION.toString());
}
// check name provided is not duplicate
VolumeGroupCopySetList sessionSet = getVolumeGroupSnapsetSessionSets(volumeGroup);
if (sessionSet.getCopySets().contains(name)) {
// duplicate name
throw APIException.badRequests.duplicateCopySetName(param.getName(), ReplicaTypeEnum.SNAPSHOT_SESSION.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 Session requested for subset of array groups in Application.");
// validate that at least one volume URI is provided
ArgValidator.checkFieldNotEmpty(partialVolumeList, VOLUMES_FIELD);
// validate the 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_SESSION.toString(), volume.getLabel());
}
volumes.add(volume);
}
} else {
log.info("Snapshot Session 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_SESSION.toString());
}
}
// Check for pending tasks
checkForApplicationPendingTasks(volumeGroup, _dbClient, false);
auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, volumeGroupId.toString(), name);
TaskList taskList = new TaskList();
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 session for consistency group {}, volumes {}", cgUri, Joiner.on(',').join(entry.getValue()));
try {
SnapshotSessionCreateParam cgSnapshotSessionParam = new SnapshotSessionCreateParam(name, param.getNewLinkedTargets(), entry.getValue());
taskList.getTaskList().addAll(_blockConsistencyGroupService.createConsistencyGroupSnapshotSession(cgUri, cgSnapshotSessionParam).getTaskList());
} catch (Exception ex) {
log.error("Unexpected Exception occurred when creating snapshot session for consistency group {}", cgUri, ex);
}
}
auditOp(OperationTypeEnum.CREATE_VOLUME_GROUP_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_END, volumeGroupId.toString(), name);
return taskList;
}
Aggregations