use of com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException in project coprhd-controller by CoprHD.
the class BlockService method performSRDFProtectionAction.
/**
* perform SRDF Protection APIs
*
* @param id
* the URN of a ViPR volume associated
* @param copy
* @param op
* @return
* @throws InternalException
*/
private TaskResourceRep performSRDFProtectionAction(URI id, Copy copy, String op) throws InternalException {
URI copyID = copy.getCopyID();
ArgValidator.checkFieldUriType(copyID, Volume.class, "copyID");
// Get the volume associated with the URI
Volume volume = queryVolumeResource(id);
Volume copyVolume = null;
if (null == copyID) {
copyVolume = volume;
} else {
copyVolume = queryVolumeResource(copyID);
}
ArgValidator.checkEntity(volume, id, true);
ArgValidator.checkEntity(copyVolume, copyID, true);
// passed in source volume
if (!copyVolume.getSrdfParent().getURI().equals(id) && !copyVolume.getId().equals(id)) {
throw APIException.badRequests.protectionVolumeInvalidTargetOfVolume(copyID, id);
}
// Make sure that we don't have some pending
// operation against the volume
checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
if (Volume.isSRDFProtectedVolume(copyVolume)) {
if (op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER_TEST.getRestOp())) {
String task = UUID.randomUUID().toString();
Operation status = new Operation();
status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
_dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
_dbClient.ready(Volume.class, volume.getId(), task);
return toTask(volume, task, status);
}
if (PersonalityTypes.SOURCE.name().equalsIgnoreCase(copyVolume.getPersonality())) {
if (op.equalsIgnoreCase(ProtectionOp.FAILOVER_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp())) {
throw new ServiceCodeException(ServiceCode.IO_ERROR, "Expected SRDF Target R2 volume, instead R1 {0} is being passed, hence cannot proceed with failover or failback.", new Object[] { copyVolume.getNativeGuid() });
} else if (copyVolume.getSrdfTargets() == null || copyVolume.getSrdfTargets().isEmpty()) {
throw new ServiceCodeException(ServiceCode.IO_ERROR, "Target Volume Empty for a given source R1 {0}, hence cannot proceed with failover or failback.", new Object[] { copyVolume.getNativeGuid() });
} else if (PersonalityTypes.TARGET.name().equalsIgnoreCase(copyVolume.getPersonality()) && RemoteDirectorGroup.SupportedCopyModes.ADAPTIVECOPY.name().equalsIgnoreCase(copyVolume.getSrdfCopyMode())) {
if (ProtectionOp.CHANGE_COPY_MODE.getRestOp().equalsIgnoreCase(op)) {
validateVpoolCopyModeSetting(volume, copy.getCopyMode());
}
}
}
// COP-25377. We need to block failover and swap operations for SRDF ACTIVE COPY MODE
if (Mode.ACTIVE.toString().equalsIgnoreCase(copyVolume.getSrdfCopyMode()) && (op.equalsIgnoreCase(ProtectionOp.FAILOVER_CANCEL.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp()))) {
throw BadRequestException.badRequests.operationNotPermittedOnSRDFActiveCopyMode(op);
}
String task = UUID.randomUUID().toString();
Operation status = new Operation();
status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
_dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
/*
* CTRL-6972: In the absence of a /restore API, we re-use /sync with a syncDirection parameter for
* specifying either SMI-S Resume or Restore:
* SOURCE_TO_TARGET -> ViPR Resume -> SMI-S Resume -> SRDF Incremental Establish (R1 overwrites R2)
* TARGET_TO_SOURCE -> ViPR Sync -> SMI-S Restore -> SRDF Full Restore (R2 overwrites R1)
*/
if (op.equalsIgnoreCase(ProtectionOp.SYNC.getRestOp()) && SOURCE_TO_TARGET.toString().equalsIgnoreCase(copy.getSyncDirection())) {
op = ProtectionOp.RESUME.getRestOp();
} else if (isSuspendCopyRequest(op, copy)) {
op = ProtectionOp.SUSPEND.getRestOp();
}
ProtectionOrchestrationController protectionController = getController(ProtectionOrchestrationController.class, ProtectionOrchestrationController.PROTECTION_ORCHESTRATION_DEVICE);
StorageSystem system = _dbClient.queryObject(StorageSystem.class, copyVolume.getStorageController());
protectionController.performSRDFProtectionOperation(system.getId(), copy, op, task);
return toTask(volume, task, status);
} else {
throw new ServiceCodeException(ServiceCode.IO_ERROR, "Volume {0} is not SRDF protected", new Object[] { copyVolume.getNativeGuid() });
}
}
use of com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException in project coprhd-controller by CoprHD.
the class BlockSnapshotService method activate.
/**
* Call will activate this snapshot, essentially establishing the synchronization
* between the source and target. The "heavy lifting" of getting the snapshot
* to the point where it can be activated should have been done by the create.
*
* @prereq Create snapshot as inactive
* @param id [required] - the URN of a ViPR block snapshot to restore from
* @brief Activate 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.ANY })
@Path("/{id}/activate")
public TaskResourceRep activate(@PathParam("id") URI id) {
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT);
ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
// Get the block service API implementation for the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Make sure that we don't have some pending
// operation against the parent volume
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), Arrays.asList(parentVolume));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
BlockController controller = getController(BlockController.class, device.getSystemType());
String task = UUID.randomUUID().toString();
// another request to activate it again.
if (snapshot.getIsSyncActive()) {
op.ready("Snapshot is already active");
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
return toTask(snapshot, task, op);
}
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
List<URI> snapshotList = new ArrayList<URI>();
if (!NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
for (BlockSnapshot snap : snapshots) {
snapshotList.add(snap.getId());
}
} else {
snapshotList.add(id);
}
// If the volume is under protection
if (snapshot.getEmName() != null) {
// RP snapshots cannot be activated so throw exception
throw new ServiceCodeException(API_BAD_REQUEST, "RecoverPoint snapshots cannot be activated.", null);
} else {
controller.activateSnapshot(device.getId(), snapshotList, task);
}
auditOp(OperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
return toTask(snapshot, task, op);
}
Aggregations