use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class BlockService method deactivateMirror.
/**
* Deactivate continuous copies for given source volume
*
* NOTE: This is an asynchronous operation.
*
* @prereq none
*
* @param id
* the URN of a ViPR Source volume
* @param param
* List of copies to deactivate
* @param type {@link DefaultValue} FULL
* Possible type of deletion
* <ul>
* <li>FULL</li>
* <li>VIPR_ONLY</li>
* </ul>
* if type is FULL, ViPR deletes the continuous copy from storage array and removes from ViPR data base.
* if type is VIPR_ONLY, ViPR removes the continuous copy only from ViPR data base and leaves the continuous copy on storage
* array as it is.
*
* @brief Delete continuous copies
* @return TaskList
*
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList deactivateMirror(@PathParam("id") URI id, CopiesParam param, @DefaultValue("FULL") @QueryParam("type") String deleteType) throws ControllerException {
TaskList taskList = new TaskList();
// Validate the source volume URI
ArgValidator.checkFieldUriType(id, Volume.class, "id");
Volume volume = _dbClient.queryObject(Volume.class, id);
// Make sure that we don't have some pending
// operation against the volume
checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
// Validate the list of copies
ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
boolean vplexVolume = checkIfVolumeIsForVplex(id);
// Process the list of copies
for (Copy copy : param.getCopies()) {
// Validate the copy ID
URI copyID = copy.getCopyID();
ArgValidator.checkUri(copyID);
// Validate a copy type was passed
ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
if (TechnologyType.NATIVE.toString().equalsIgnoreCase(copy.getType())) {
String task = UUID.randomUUID().toString();
StorageSystem device;
String mirrorLabel;
URI mirrorURI;
BlockServiceApi blockServiceApi;
if (vplexVolume) {
VplexMirror mirror = queryVplexMirror(copyID);
ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
if (!mirror.getSource().getURI().equals(id)) {
throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
}
mirrorLabel = mirror.getLabel();
mirrorURI = mirror.getId();
device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
} else {
BlockMirror mirror = queryMirror(copyID);
ArgValidator.checkEntity(mirror, mirror.getId(), isIdEmbeddedInURL(copyID));
if (!mirror.getSource().getURI().equals(id)) {
throw APIException.badRequests.mirrorDoesNotBelongToVolume(copyID, id);
}
mirrorLabel = mirror.getLabel();
mirrorURI = mirror.getId();
device = _dbClient.queryObject(StorageSystem.class, mirror.getStorageController());
blockServiceApi = getBlockServiceImpl("mirror");
}
// Deactivate the mirror
TaskList deactivateTaskList = blockServiceApi.deactivateMirror(device, mirrorURI, task, deleteType);
// Create the audit log message
String opStage = VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType) ? null : AuditLogManager.AUDITOP_BEGIN;
boolean opStatus = true;
for (TaskResourceRep resultTask : deactivateTaskList.getTaskList()) {
if (Operation.Status.error.name().equals(resultTask.getState())) {
opStatus = false;
break;
}
}
auditOp(OperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, opStatus, opStage, copyID.toString(), mirrorLabel);
// Add tasks for this copy
taskList.getTaskList().addAll(deactivateTaskList.getTaskList());
} else {
throw APIException.badRequests.invalidCopyType(copy.getType());
}
}
return taskList;
}
use of com.emc.storageos.model.TaskList 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.model.TaskList in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method failoverProtection.
/**
* Request to failover the protection link associated with the copy. The target
* copy is specified by identifying the virtual array in param.copyId.
*
* NOTE: This is an asynchronous operation.
*
* If volume is srdf protected, then invoking failover internally triggers
* SRDF SWAP on volume pairs.
*
* @prereq none
*
* @param id the URI of a BlockConsistencyGroup
* @param param Copy to failover to
*
* @brief Failover the protection link
* @return TaskList
*
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverProtection(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
TaskResourceRep taskResp = null;
TaskList taskList = new TaskList();
// Validate the consistency group URI
ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
// Validate the list of copies
ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
// Query Consistency Group
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
// system types.
if (!consistencyGroup.created()) {
throw APIException.badRequests.consistencyGroupNotCreated();
}
List<Copy> copies = param.getCopies();
if (copies.size() > 1) {
throw APIException.badRequests.failoverCopiesParamCanOnlyBeOne();
}
Copy copy = copies.get(0);
ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER.getRestOp());
taskList.getTaskList().add(taskResp);
} else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.FAILOVER.getRestOp());
taskList.getTaskList().add(taskResp);
} else {
throw APIException.badRequests.invalidCopyType(copy.getType());
}
return taskList;
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method failoverCancel.
/**
* Request to cancel fail over on already failed over consistency group.
*
* @prereq none
*
* @param id the URI of the BlockConsistencyGroup.
* @param param Copy to fail back
*
* @brief Cancel a failover and return to source
* @return TaskList
*
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover-cancel")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverCancel(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
TaskResourceRep taskResp = null;
TaskList taskList = new TaskList();
// Validate the source volume URI
ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
// Validate the list of copies
ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
// Query Consistency Group
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
// system types.
if (!consistencyGroup.created()) {
throw APIException.badRequests.consistencyGroupNotCreated();
}
List<Copy> copies = param.getCopies();
if (copies.size() > 1) {
throw APIException.badRequests.failOverCancelCopiesParamCanOnlyBeOne();
}
Copy copy = copies.get(0);
ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
taskResp = performProtectionAction(id, copy, ProtectionOp.FAILOVER_CANCEL.getRestOp());
taskList.getTaskList().add(taskResp);
} else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.FAILOVER_CANCEL.getRestOp());
taskList.getTaskList().add(taskResp);
} else {
throw APIException.badRequests.invalidCopyType(copy.getType());
}
return taskList;
}
use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method swap.
/**
* Request to reverse the replication direction, i.e. R1 and R2 are interchanged.
*
* @prereq none
*
* @param id the URI of a BlockConsistencyGroup
* @param param Copy to swap
*
* @brief Reverse roles of source and target
* @return TaskList
*
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/swap")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList swap(@PathParam("id") URI id, CopiesParam param) throws ControllerException {
TaskResourceRep taskResp = null;
TaskList taskList = new TaskList();
// Validate the source volume URI
ArgValidator.checkFieldUriType(id, BlockConsistencyGroup.class, "id");
// Validate the list of copies
ArgValidator.checkFieldNotEmpty(param.getCopies(), "copies");
// Query Consistency Group
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(id);
// system types.
if (!consistencyGroup.created()) {
throw APIException.badRequests.consistencyGroupNotCreated();
}
List<Copy> copies = param.getCopies();
if (copies.size() > 1) {
throw APIException.badRequests.swapCopiesParamCanOnlyBeOne();
}
Copy copy = copies.get(0);
ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
ArgValidator.checkFieldNotEmpty(copy.getType(), "type");
if (TechnologyType.RP.name().equalsIgnoreCase(copy.getType())) {
taskResp = performProtectionAction(id, copy, ProtectionOp.SWAP.getRestOp());
taskList.getTaskList().add(taskResp);
} else if (TechnologyType.SRDF.name().equalsIgnoreCase(copy.getType())) {
taskResp = performSRDFProtectionAction(id, copy, ProtectionOp.SWAP.getRestOp());
taskList.getTaskList().add(taskResp);
} else {
throw APIException.badRequests.invalidCopyType(copy.getType());
}
return taskList;
}
Aggregations