use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method deactivateConsistencyGroupSnapshot.
/**
* Deactivate the specified Consistency Group Snapshot
*
* @prereq none
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Deactivate consistency group snapshot session
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
// Snapshots of RecoverPoint consistency groups is not supported.
if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
}
// check for backend CG
if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
_log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
throw APIException.badRequests.cannotCreateSnapshotOfCG();
}
final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// 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);
ArgValidator.checkReference(BlockSnapshot.class, snapshotId, checkForDelete(snapshot, excludeTypes));
// Snapshot session linked targets must be unlinked instead.
BlockSnapshotSession session = BlockSnapshotSessionUtils.getLinkedTargetSnapshotSession(snapshot, _dbClient);
if (session != null) {
return deactivateAndUnlinkTargetVolumesForSession(session, snapshot);
}
// Generate task id
final String task = UUID.randomUUID().toString();
TaskList response = new TaskList();
// Not an error if the snapshot we try to delete is already deleted
if (snapshot.getInactive()) {
Operation op = new Operation();
op.ready("The consistency group snapshot has already been deactivated");
op.setResourceType(ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
response.getTaskList().add(toTask(snapshot, task, op));
return response;
}
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
// Get the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Check that there are no pending tasks for these snapshots.
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
for (BlockSnapshot snap : snapshots) {
Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_SNAPSHOT);
response.getTaskList().add(toTask(snap, task, snapOp));
}
addConsistencyGroupTask(consistencyGroup, response, task, ResourceOperationTypeEnum.DEACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
try {
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
blockServiceApiImpl.deleteSnapshot(snapshot, snapshots, task, VolumeDeleteTypeEnum.FULL.name());
} catch (APIException | InternalException e) {
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
_log.error(errorMsg);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
@SuppressWarnings({ "unchecked" }) Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
_dbClient.error(clazz, taskResourceRep.getResource().getId(), task, e);
}
throw e;
} catch (Exception e) {
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
_log.error(errorMsg);
APIException apie = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(apie.getMessage());
@SuppressWarnings("unchecked") Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
_dbClient.error(clazz, taskResourceRep.getResource().getId(), task, apie);
}
throw apie;
}
auditBlockConsistencyGroup(OperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
return response;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method restoreConsistencyGroupSnapshot.
/**
* Restore the specified consistency group snapshot
*
* @prereq Activate consistency group snapshot
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Restore consistency group snapshot
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/restore")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep restoreConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
// Get the consistency group and snapshot and verify the snapshot
// is actually associated with the consistency group.
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// check for backend CG
if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
_log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
throw APIException.badRequests.cannotCreateSnapshotOfCG();
}
// Get the parent volume.
final Volume snapshotParentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Get the block implementation
BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
// Validate the snapshot restore.
blockServiceApiImpl.validateRestoreSnapshot(snapshot, snapshotParentVolume);
// Create the restore operation task for the snapshot.
final String taskId = UUID.randomUUID().toString();
final Operation op = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.RESTORE_CONSISTENCY_GROUP_SNAPSHOT);
// Restore the snapshot.
blockServiceApiImpl.restoreSnapshot(snapshot, snapshotParentVolume, null, taskId);
auditBlockConsistencyGroup(OperationTypeEnum.RESTORE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshotId.toString(), consistencyGroupId.toString(), snapshot.getStorageController().toString());
return toTask(snapshot, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method resynchronizeConsistencyGroupSnapshot.
/**
* Resynchronize the specified consistency group snapshot
*
* @prereq Activate consistency group snapshot
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Resynchronize consistency group snapshot
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/resynchronize")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep resynchronizeConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
// Get the consistency group and snapshot and verify the snapshot
// is actually associated with the consistency group.
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// check for backend CG
if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
_log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
throw APIException.badRequests.cannotCreateSnapshotOfCG();
}
// Get the storage system for the consistency group.
StorageSystem storage = _permissionsHelper.getObjectById(snapshot.getStorageController(), StorageSystem.class);
// 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 IBM XIV storage system type is not supported
if (Type.ibmxiv.name().equalsIgnoreCase(storage.getSystemType())) {
throw APIException.methodNotAllowed.notSupportedWithReason("Snapshot resynchronization is not supported on IBM XIV 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");
}
if (storage.checkIfVmax3()) {
throw APIException.methodNotAllowed.notSupportedWithReason("Snapshot resynchronization is not supported on VMAX3 storage systems");
}
// Get the parent volume.
final Volume snapshotParentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Get the block implementation
BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
// Validate the snapshot restore.
blockServiceApiImpl.validateResynchronizeSnapshot(snapshot, snapshotParentVolume);
// Create the restore operation task for the snapshot.
final String taskId = UUID.randomUUID().toString();
final Operation op = _dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), taskId, ResourceOperationTypeEnum.RESYNCHRONIZE_CONSISTENCY_GROUP_SNAPSHOT);
// Resync the snapshot.
blockServiceApiImpl.resynchronizeSnapshot(snapshot, snapshotParentVolume, taskId);
auditBlockConsistencyGroup(OperationTypeEnum.RESTORE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshotId.toString(), consistencyGroupId.toString(), snapshot.getStorageController().toString());
return toTask(snapshot, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method pauseNativeContinuousCopies.
/**
* {@inheritDoc}
*
* @throws ControllerException
*/
@Override
public TaskList pauseNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<BlockMirror> blockMirrors, Boolean sync, String taskId) throws ControllerException {
TaskList taskList = new TaskList();
List<URI> mirrorUris = new ArrayList<>();
// Assume all continuous copies are to be paused
List<BlockMirror> pausedMirrors = new ArrayList<>();
Map<BlockMirror, Volume> groupMirrorSourceMap = null;
List<BlockMirror> mirrorsToProcess = null;
boolean isCG = sourceVolume.isInCG();
if (isCG) {
if (blockMirrors == null) {
for (String uriStr : sourceVolume.getMirrors()) {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
if (mirrorIsPausable(mirror)) {
groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
// only process one mirror group
break;
}
}
} else {
groupMirrorSourceMap = getGroupMirrorSourceMap(blockMirrors.get(0), sourceVolume);
}
if (groupMirrorSourceMap == null || groupMirrorSourceMap.isEmpty()) {
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
op.setMessage("No continuous copy can be paused");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
return taskList;
}
mirrorsToProcess = new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet());
mirrorUris = new ArrayList<URI>(transform(mirrorsToProcess, FCTN_MIRROR_TO_URI));
} else {
// Assume all continuous copies are to be paused
mirrorsToProcess = blockMirrors;
if (mirrorsToProcess == null) {
mirrorsToProcess = new ArrayList<BlockMirror>();
for (String uriStr : sourceVolume.getMirrors()) {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
mirrorsToProcess.add(mirror);
}
}
for (BlockMirror mirror : mirrorsToProcess) {
if (mirrorIsResumable(mirror)) {
// extract mirrors that are in "paused" state
pausedMirrors.add(mirror);
} else if (!mirrorIsPausable(mirror)) {
// if there is a mirror is not in paused state, and not pausable, throw exception
throw APIException.badRequests.cannotPauseContinuousCopyWithSyncState(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
} else if (mirrorIsResynchronizing(mirror)) {
throw APIException.badRequests.cannotPauseContinuousCopyWhileResynchronizing(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
} else {
// otherwise, place mirror a list... get ready to pause
mirrorUris.add(mirror.getId());
}
}
}
/*
* if all mirrors are paused, then there is no task to do.
* Return a successful task
*/
if (!pausedMirrors.isEmpty() && mirrorUris.isEmpty()) {
// If the mirrors is already paused, there would be no need to queue another request to activate it again.
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
op.setMessage("The continuous copies are already paused");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
} else {
if (!isCG) {
Collection<String> mirrorTargetIds = Collections2.transform(mirrorsToProcess, FCTN_VOLUME_URI_TO_STR);
String mirrorTargetCommaDelimList = Joiner.on(',').join(mirrorTargetIds);
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR, mirrorTargetCommaDelimList);
taskList.getTaskList().add(toTask(sourceVolume, mirrorsToProcess, taskId, op));
} else {
populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
}
try {
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.pauseNativeContinuousCopies(storageSystem.getId(), mirrorUris, sync, taskId);
} catch (ControllerException e) {
String errorMsg = format("Failed to pause continuous copies for source volume %s", sourceVolume.getId());
_log.error(errorMsg, e);
_dbClient.error(Volume.class, sourceVolume.getId(), taskId, e);
}
}
return taskList;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method changeVolumeVirtualPool.
@Override
public TaskList changeVolumeVirtualPool(URI systemURI, Volume volume, VirtualPool virtualPool, VirtualPoolChangeParam cosChangeParam, String taskId) throws ControllerException {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, systemURI);
String systemType = storageSystem.getSystemType();
List<Volume> volumes = new ArrayList<Volume>();
volumes.add(volume);
if (checkCommonVpoolUpdates(volumes, virtualPool, taskId)) {
return null;
}
if (DiscoveredDataObject.Type.vnxblock.name().equals(systemType) || DiscoveredDataObject.Type.vmax.name().equals(systemType)) {
URI original = volume.getVirtualPool();
// Update the volume with the new virtual pool
volume.setVirtualPool(virtualPool.getId());
_dbClient.updateObject(volume);
// Update the task
String msg = format("VirtualPool changed from %s to %s for Volume %s", original, virtualPool.getId(), volume.getId());
Operation opStatus = new Operation(Operation.Status.ready.name(), msg);
_dbClient.updateTaskOpStatus(Volume.class, volume.getId(), taskId, opStatus);
} else {
throw APIException.badRequests.unsupportedSystemType(systemType);
}
return null;
}
Aggregations