use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockService method changeVolumeVirtualPool.
/**
* Allows the caller to change the virtual pool for the volume identified in
* the request. Currently, the only virtual pool changes that are supported
* are as follows:
*
* Change the virtual pool for a VPLEX virtual volume. This virtual pool
* change would allow the caller to change the types of drives, for example,
* used for the backend volume(s) that are used by the virtual volume.
*
* Change the virtual pool for a VPLEX virtual volume, such that a local
* VPLEX virtual volumes becomes a distributed VPLEX virtual volume.
*
* Change the virtual pool of a VMAX or VNX Block volume to make the volume
* a local or distributed VPLEX virtual volume. Essentially, the volume
* becomes the backend volume for a VPLEX virtual volume. Similar to
* creating a virtual volume, but instead of creating a new backend volume,
* using the volume identified in the request. The VMAX or VNX volume cannot
* currently be exported for this change.
*
* Change the virtual pool of a VMAX or VNX Block volume to make the volume
* a RecoverPoint protected volume. The volume must be able to stay put, and
* ViPR will build a protection around it.
*
* Change the virtual pool of a VMAX or VNX Block volume to allow native
* continuous copies to be created for it.
*
* Change the virtual pool of a volume to increase the export path parameter max_paths.
* The number of paths will be upgraded if possible for all Export Groups / Export Masks
* containing this volume. If the volume is not currently exported, max_paths can be
* decreased or paths_per_initiator can be changed. Note that changing max_paths does
* not have any effect on the export of BlockSnapshots that were created from this volume.
*
* Change the virtual pool of a VMAX and VNX volume to allow change of Auto-tiering policy
* associated with it.
* <p>
* Since this method has been deprecated use POST /block/volumes/vpool-change
*
* @brief Change the virtual pool for a volume.
*
* @prereq none
*
* @param id
* the URN of a ViPR volume.
* @param param
* The parameter specifying the new virtual pool.
* @return A TaskResourceRep representing the virtual pool change for the
* volume.
* @throws InternalException,
* APIException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vpool")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Deprecated
public TaskResourceRep changeVolumeVirtualPool(@PathParam("id") URI id, VirtualPoolChangeParam param) throws InternalException, APIException {
_log.info("Request to change VirtualPool for volume {}", id);
// Get the volume.
ArgValidator.checkFieldUriType(id, Volume.class, "id");
Volume volume = queryVolumeResource(id);
_log.info("Found volume");
// Don't operate on VPLEX backend or RP Journal volumes.
BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
// Don't operate on ingested volumes.
VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL, _dbClient);
// Get the project.
URI projectURI = volume.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found volume project {}", projectURI);
// Verify the user is authorized for the volume's project.
BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, getUserFromContext(), _permissionsHelper);
_log.info("User is authorized for volume's project");
// Get the VirtualPool for the request and verify that the
// project's tenant has access to the VirtualPool.
VirtualPool vpool = getVirtualPoolForRequest(project, param.getVirtualPool(), _dbClient, _permissionsHelper);
_log.info("Found new VirtualPool {}", vpool.getId());
// Verify that the VirtualPool change is allowed for the
// requested volume and VirtualPool.
verifyVirtualPoolChangeSupportedForVolumeAndVirtualPool(volume, vpool);
_log.info("VirtualPool change is supported for requested volume and VirtualPool");
verifyAllVolumesInCGRequirement(Arrays.asList(volume), vpool);
// verify quota
if (!CapacityUtils.validateVirtualPoolQuota(_dbClient, vpool, volume.getProvisionedCapacity())) {
throw APIException.badRequests.insufficientQuotaForVirtualPool(vpool.getLabel(), "volume");
}
// Create a unique task id.
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Volume.class, id, taskId, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL);
// execute the VirtualPool update on the volume.
try {
BlockServiceApi blockServiceAPI = getBlockServiceImplForVirtualPoolChange(volume, vpool);
_log.info("Got block service implementation for VirtualPool change request");
blockServiceAPI.changeVolumeVirtualPool(Arrays.asList(volume), vpool, param, taskId);
_log.info("Executed VirtualPool change for volume.");
} catch (InternalException | APIException e) {
String errorMsg = String.format("Volume VirtualPool change error: %s", e.getMessage());
op = new Operation(Operation.Status.error.name(), errorMsg);
_dbClient.updateTaskOpStatus(Volume.class, id, taskId, op);
throw e;
}
auditOp(OperationTypeEnum.CHANGE_VOLUME_VPOOL, true, AuditLogManager.AUDITOP_BEGIN, volume.getLabel(), 1, volume.getVirtualArray().toString(), volume.getProject().toString());
return toTask(volume, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockService method createVolumeTaskList.
/**
* A method that pre-creates task and volume objects to return to the caller of the API.
*
* @param size
* size of the volume
* @param project
* project of the volume
* @param varray
* virtual array of the volume
* @param vpool
* virtual pool of the volume
* @param label
* label
* @param task
* task string
* @param volumeCount
* number of volumes requested
* @return a list of tasks associated with this request
*/
private TaskList createVolumeTaskList(String size, Project project, VirtualArray varray, VirtualPool vpool, String label, String task, Integer volumeCount) {
TaskList taskList = new TaskList();
try {
// For each volume requested, pre-create a volume object/task object
long lsize = SizeUtil.translateSize(size);
for (int i = 0; i < volumeCount; i++) {
Volume volume = StorageScheduler.prepareEmptyVolume(_dbClient, lsize, project, varray, vpool, label, i, volumeCount);
Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
volume.getOpStatus().put(task, op);
TaskResourceRep volumeTask = toTask(volume, task, op);
taskList.getTaskList().add(volumeTask);
_log.info(String.format("Volume and Task Pre-creation Objects [Init]-- Source Volume: %s, Task: %s, Op: %s", volume.getId(), volumeTask.getId(), task));
}
} catch (APIException ex) {
// Mark the dummy objects inactive
String errMsg = "Caught Exception while creating Volume and Task objects. Marking pre-created Objects inactive";
_log.error(errMsg, ex);
for (TaskResourceRep taskObj : taskList.getTaskList()) {
taskObj.setMessage(String.format("%s. %s", errMsg, ex.getMessage()));
taskObj.setState(Operation.Status.error.name());
URI volumeURI = taskObj.getResource().getId();
_dbClient.error(Volume.class, volumeURI, task, ex);
// Set the volumes to inactive
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
volume.setInactive(true);
_dbClient.updateObject(volume);
}
// throw the Exception to the caller
throw ex;
}
return taskList;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockService method establishVolumeMirrorGroupRelation.
private TaskResourceRep establishVolumeMirrorGroupRelation(URI id, Copy copy, String op) throws InternalException {
URI copyID = copy.getCopyID();
ArgValidator.checkFieldUriType(copyID, BlockMirror.class, "copyID");
// Get the volume associated with the URI
Volume volume = queryVolumeResource(id);
BlockMirror mirror = queryMirror(copyID);
ArgValidator.checkEntity(volume, id, true);
ArgValidator.checkEntity(mirror, copyID, true);
StringSet mirrors = volume.getMirrors();
if (mirrors == null || mirrors.isEmpty()) {
throw APIException.badRequests.invalidParameterVolumeHasNoContinuousCopies(id);
}
if (!mirror.getSource().getURI().equals(id)) {
throw APIException.badRequests.invalidParameterBlockCopyDoesNotBelongToVolume(copyID, id);
}
if (!volume.hasConsistencyGroup() || !mirror.hasConsistencyGroup()) {
throw APIException.badRequests.blockObjectHasNoConsistencyGroup();
}
String task = UUID.randomUUID().toString();
Operation status = new Operation();
status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
_dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
auditOp(OperationTypeEnum.ESTABLISH_VOLUME_MIRROR, true, AuditLogManager.AUDITOP_BEGIN, mirrors);
StorageSystem system = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
BlockServiceApi blockServiceApi = getBlockServiceImpl("mirror");
return blockServiceApi.establishVolumeAndNativeContinuousCopyGroupRelation(system, volume, mirror, task);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockSnapshotService method deactivateSnapshot.
/**
* Deactivate volume snapshot, will result in permanent deletion of the requested snapshot from the storage system it was created on
* and will move the snapshot to a "marked-for-delete" state after the deletion happens on the array side.
* It will be deleted by the garbage collector on a subsequent iteration
* If this snapshot was created from a volume that is part of a consistency group,
* then all the related snapshots will be deactivated, as well.
*
* If "?type=VIPR_ONLY" is added to the path, it will delete snapshot only from ViPR data base and leaves the snapshot on storage array
* as it is.
* Possible value for attribute type : FULL, VIPR_ONLY
* FULL : Deletes the snapshot permanently on array and ViPR data base.
* VIPR_ONLY : Deletes the snapshot only from ViPR data base and leaves the snapshot on array as it is.
*
* @prereq none
* @param id the URN of a ViPR snapshot
* @param type the type of deletion {@link DefaultValue} FULL
* @brief Delete snapshot
* @return Snapshot information
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateSnapshot(@PathParam("id") URI id, @DefaultValue("FULL") @QueryParam("type") String type) {
_log.info("Executing {} snapshot delete for snapshot {}", type, id);
String opStage = null;
boolean successStatus = true;
String taskId = UUID.randomUUID().toString();
TaskList response = new TaskList();
// Get the snapshot.
BlockSnapshot snap = (BlockSnapshot) queryResource(id);
// We can ignore dependencies on BlockSnapshotSession. In this case
// the BlockSnapshot instance is a linked target for a BlockSnapshotSession
// and we will unlink the snapshot from the session and delete it.
List<Class<? extends DataObject>> excludeTypes = new ArrayList<Class<? extends DataObject>>();
excludeTypes.add(BlockSnapshotSession.class);
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
excludeTypes.add(ExportGroup.class);
excludeTypes.add(ExportMask.class);
}
ArgValidator.checkReference(BlockSnapshot.class, id, checkForDelete(snap, excludeTypes));
if (!VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(type)) {
// The audit log message operation stage.
opStage = AuditLogManager.AUDITOP_BEGIN;
// If the BlockSnapshot instance represents a linked target, then
// we need to unlink the target form the snapshot session and then
// delete the target.
URIQueryResultList snapSessionURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(id), snapSessionURIs);
Iterator<URI> snapSessionURIsIter = snapSessionURIs.iterator();
if (snapSessionURIsIter.hasNext()) {
_log.info("Snapshot is linked target for a snapshot session");
SnapshotSessionUnlinkTargetsParam param = new SnapshotSessionUnlinkTargetsParam();
List<SnapshotSessionUnlinkTargetParam> targetInfoList = new ArrayList<SnapshotSessionUnlinkTargetParam>();
SnapshotSessionUnlinkTargetParam targetInfo = new SnapshotSessionUnlinkTargetParam(id, Boolean.TRUE);
targetInfoList.add(targetInfo);
param.setLinkedTargets(targetInfoList);
response.getTaskList().add(getSnapshotSessionManager().unlinkTargetVolumesFromSnapshotSession(snapSessionURIsIter.next(), param, OperationTypeEnum.DELETE_VOLUME_SNAPSHOT));
return response;
}
// Not an error if the snapshot we try to delete is already deleted
if (snap.getInactive()) {
_log.info("Snapshot is already inactive");
Operation op = new Operation();
op.ready("The snapshot has already been deleted");
op.setResourceType(ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), taskId, op);
response.getTaskList().add(toTask(snap, taskId, op));
return response;
}
}
// Get the storage system.
StorageSystem device = _dbClient.queryObject(StorageSystem.class, snap.getStorageController());
// Determine all snapshots to delete.
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
final URI cgId = snap.getConsistencyGroup();
if (!NullColumnValueGetter.isNullURI(cgId) && !NullColumnValueGetter.isNullValue(snap.getReplicationGroupInstance())) {
// Collect all the BlockSnapshots if part of a CG.
snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snap, _dbClient);
} else {
// Snap is not part of a CG so only delete the snap
snapshots.add(snap);
}
// Get the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
// Check that there are no pending tasks for these snapshots.
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
// Create tasks on the volume.
for (BlockSnapshot snapshot : snapshots) {
Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.DELETE_VOLUME_SNAPSHOT);
response.getTaskList().add(toTask(snapshot, taskId, snapOp));
}
// should be returned.
try {
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
blockServiceApiImpl.deleteSnapshot(snap, snapshots, taskId, type);
} catch (APIException | InternalException e) {
successStatus = false;
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
_log.error(errorMsg);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, e);
}
} catch (Exception e) {
successStatus = false;
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snap.getId(), e.getMessage());
_log.error(errorMsg);
ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(sc.getMessage());
_dbClient.error(BlockSnapshot.class, taskResourceRep.getResource().getId(), taskId, sc);
}
}
auditOp(OperationTypeEnum.DELETE_VOLUME_SNAPSHOT, successStatus, opStage, id.toString(), snap.getLabel(), snap.getParent().getName(), device.getId().toString());
return response;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockSnapshotService method resynchronize.
/**
* Call will resynchronize this snapshot from the volume that it is associated with.
* If this snapshot was created from a volume in a consistency group, then all
* related snapshots will be resynchronized.
*
* @prereq none
* @param id [required] - the URN of a ViPR block snapshot to restore from
* @brief Resynchronize snapshot
* @return TaskResourceRep - Task resource object for tracking this operation
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Path("/{id}/resynchronize")
public TaskResourceRep resynchronize(@PathParam("id") URI id) {
// Validate an get the snapshot to be restored.
ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
// Get the block service API implementation for the snapshot parent volume.
Volume volume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Get the storage system for the volume
StorageSystem storage = _permissionsHelper.getObjectById(volume.getStorageController(), StorageSystem.class);
if (storage.checkIfVmax3()) {
if (snapshot.getSettingsInstance() == null) {
throw APIException.badRequests.snapshotNullSettingsInstance(snapshot.getLabel());
}
}
// resync for OpenStack storage system type is not supported
if (Type.openstack.name().equalsIgnoreCase(storage.getSystemType())) {
throw APIException.methodNotAllowed.notSupportedWithReason(String.format("Snapshot resynchronization is not possible on third-party storage systems"));
}
// resync for VNX storage system type is not supported
if (Type.vnxblock.name().equalsIgnoreCase(storage.getSystemType())) {
throw APIException.methodNotAllowed.notSupportedWithReason("Snapshot resynchronization is not supported on VNX storage systems");
}
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(volume, _dbClient);
// Validate the resync snapshot request.
blockServiceApiImpl.validateResynchronizeSnapshot(snapshot, volume);
// Create the task identifier.
String taskId = UUID.randomUUID().toString();
// Create the operation status entry in the status map for the snapshot.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, op);
snapshot.getOpStatus().put(taskId, op);
// Resync the snapshot.
blockServiceApiImpl.resynchronizeSnapshot(snapshot, volume, taskId);
// Create the audit log entry.
auditOp(OperationTypeEnum.RESYNCHRONIZE_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, id.toString(), volume.getId().toString(), snapshot.getStorageController().toString());
return toTask(snapshot, taskId, op);
}
Aggregations