use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionManager method restoreSnapshotSession.
/**
* Restores the data on the array snapshot point-in-time copy represented by the
* BlockSnapshotSession instance with the passed URI, to the snapshot session source
* object.
*
* @param snapSessionURI The URI of the BlockSnapshotSession instance to be restored.
*
* @return TaskResourceRep representing the snapshot session task.
*/
public TaskResourceRep restoreSnapshotSession(URI snapSessionURI) {
s_logger.info("START restore snapshot session {}", snapSessionURI);
// Get the snapshot session.
BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
BlockObject snapSessionSourceObj = null;
List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
snapSessionSourceObj = snapSessionSourceObjs.get(0);
// Get the project for the snapshot session source object.
Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
// Validate that the snapshot session can be restored.
snapSessionApiImpl.validateRestoreSnapshotSession(snapSessionSourceObjs, project);
// 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.RESTORE_SNAPSHOT_SESSION);
_dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
snapSession.getOpStatus().put(taskId, op);
TaskResourceRep resourceRep = toTask(snapSession, taskId);
// Restore the snapshot session.
try {
snapSessionApiImpl.restoreSnapshotSession(snapSession, snapSessionSourceObjs.get(0), taskId);
} catch (Exception e) {
String errorMsg = format("Failed to restore snapshot session %s: %s", snapSessionURI, e.getMessage());
ServiceCoded sc = null;
if (e instanceof ServiceCoded) {
sc = (ServiceCoded) e;
} else {
sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
}
cleanupFailure(Lists.newArrayList(resourceRep), new ArrayList<DataObject>(), errorMsg, taskId, sc);
throw e;
}
// Create the audit log entry.
auditOp(OperationTypeEnum.RESTORE_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObjs.get(0).getId().toString(), snapSessionSourceObjs.get(0).getStorageController().toString());
s_logger.info("FINISH restore snapshot session {}", snapSessionURI);
return resourceRep;
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class RPDeviceController method updateConsistencyGroupPolicyStep.
/**
* Updates the consistency group policy (replication mode).
*
* @param protectionSystem
* the RP protection system
* @param cgUri
* the consistency group ID
* @param copyMode
* the copy/replication mode (sync or async)
* @param stepId
* the step ID
* @return true if the step executes successfully, false otherwise.
*/
public boolean updateConsistencyGroupPolicyStep(ProtectionSystem protectionSystem, URI cgUri, String copyMode, String stepId) {
try {
_log.info(String.format("Updating consistency group policy for CG %s.", cgUri));
WorkflowStepCompleter.stepExecuting(stepId);
RecoverPointClient rp = RPHelper.getRecoverPointClient(protectionSystem);
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
// lock around update policy operations on the same CG
List<String> lockKeys = new ArrayList<String>();
lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, cgUri, protectionSystem.getId()));
boolean lockAcquired = _workflowService.acquireWorkflowStepLocks(stepId, lockKeys, LockTimeoutValue.get(LockType.RP_CG));
if (!lockAcquired) {
throw DeviceControllerException.exceptions.failedToAcquireLock(lockKeys.toString(), String.format("Upgrade policy for RP consistency group %s; id: %s", cg.getLabel(), cgUri.toString()));
}
CGPolicyParams policyParams = new CGPolicyParams(copyMode);
UpdateCGPolicyParams updateParams = new UpdateCGPolicyParams(cg.getCgNameOnStorageSystem(protectionSystem.getId()), policyParams);
rp.updateConsistencyGroupPolicy(updateParams);
// Update the workflow state.
WorkflowStepCompleter.stepSucceded(stepId);
} catch (InternalException e) {
_log.error("Operation failed with Exception: ", e);
return stepFailed(stepId, (ServiceCoded) e, "updateConsistencyGroupPolicyStep");
} catch (Exception e) {
_log.error("Operation failed with Exception: ", e);
return stepFailed(stepId, e, "updateConsistencyGroupPolicyStep");
}
return true;
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class RPDeviceController method restoreVolume.
/**
* Restore an RP bookmark. This will enable the specified bookmark on the CG if the CG is not already enabled. This
* step is
* required for RP bookmark restores.
*
* @param protectionDevice
* RP protection system URI
* @param storageDevice
* storage device of the volume
* @param snapshotId
* snapshot URI
* @param task
* task ID
* @return true if the step completed successfully, false otherwise.
* @throws InternalException
*/
public boolean restoreVolume(URI protectionDevice, URI storageDevice, URI snapshotID, BlockSnapshotRestoreCompleter completer, String stepId) throws InternalException {
try {
_log.info("Restoring bookmark on the RP CG");
WorkflowStepCompleter.stepExecuting(stepId);
ProtectionSystem system = null;
system = _dbClient.queryObject(ProtectionSystem.class, protectionDevice);
if (system == null) {
// Verify non-null storage device returned from the database client.
throw DeviceControllerExceptions.recoverpoint.failedConnectingForMonitoring(protectionDevice);
}
Set<String> volumeWWNs = new HashSet<String>();
String emName = null;
// Get the volume associated with this snapshot
BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
if (snapshot.getEmName() != null) {
emName = snapshot.getEmName();
}
Volume volume = _dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
// Take out a workflow step lock on the CG
_workflowService.getWorkflowFromStepId(stepId);
List<String> lockKeys = new ArrayList<String>();
lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, volume.getConsistencyGroup(), system.getId()));
boolean lockAcquired = _workflowService.acquireWorkflowStepLocks(stepId, lockKeys, LockTimeoutValue.get(LockType.RP_CG));
if (!lockAcquired) {
throw DeviceControllerException.exceptions.failedToAcquireLock(lockKeys.toString(), String.format("failed to get lock while restoring volumes in RP consistency group: %s", volume.getConsistencyGroup().toString()));
}
// Now determine the target volume that corresponds to the site of the snapshot
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, volume.getProtectionSet());
Volume targetVolume = ProtectionSet.getTargetVolumeFromSourceAndInternalSiteName(_dbClient, protectionSet, volume, snapshot.getEmInternalSiteName());
volumeWWNs.add(RPHelper.getRPWWn(targetVolume.getId(), _dbClient));
// Now restore image access
RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
MultiCopyRestoreImageRequestParams request = new MultiCopyRestoreImageRequestParams();
request.setBookmark(emName);
request.setVolumeWWNSet(volumeWWNs);
MultiCopyRestoreImageResponse response = rp.restoreImageCopies(request);
if (response == null) {
throw DeviceControllerExceptions.recoverpoint.failedToImageAccessBookmark();
}
WorkflowStepCompleter.stepSucceded(stepId);
_log.info("restoreVolume step is complete");
} catch (InternalException e) {
_log.error("Operation failed with Exception: ", e);
return stepFailed(stepId, (ServiceCoded) e, "restoreVolumeStep");
} catch (URISyntaxException e) {
_log.error("Operation failed with Exception: ", e);
return stepFailed(stepId, e, "restoreVolumeStep");
} catch (Exception e) {
_log.error("Operation failed with Exception: ", e);
return stepFailed(stepId, e, "restoreVolumeStep");
}
return true;
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class BlockDeviceController method createSnapshotSession.
/**
* {@inheritDoc}
*/
@Override
public void createSnapshotSession(URI systemURI, URI snapSessionURI, List<List<URI>> sessionSnapshotURIs, String copyMode, String opId) throws InternalException {
TaskCompleter completer = new BlockSnapshotSessionCreateWorkflowCompleter(snapSessionURI, sessionSnapshotURIs, opId);
try {
// Get a new workflow to execute creation of the snapshot session and if
// necessary creation and linking of target volumes to the new session.
Workflow workflow = _workflowService.getNewWorkflow(this, CREATE_SAPSHOT_SESSION_WF_NAME, false, opId);
_log.info("Created new workflow to create a new snapshot session for source with operation id {}", opId);
// When creating a group snapshot we need the name of the group.
String groupName = null;
boolean isCG = checkSnapshotSessionConsistencyGroup(snapSessionURI, _dbClient, completer);
if (isCG) {
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
groupName = snapSession.getReplicationGroupInstance();
}
// Create a step to create the session.
String waitFor = workflow.createStep(CREATE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Creating block snapshot session"), null, systemURI, getDeviceType(systemURI), getClass(), createBlockSnapshotSessionMethod(systemURI, snapSessionURI, groupName), rollbackMethodNullMethod(), null);
// Add steps to create any new targets and link them to the session, if necessary
if ((sessionSnapshotURIs != null) && (!sessionSnapshotURIs.isEmpty())) {
if (isCG) {
for (List<URI> snapshotURIs : sessionSnapshotURIs) {
workflow.createStep(LINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Linking group targets snapshot sessions %s", snapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), linkBlockSnapshotSessionTargetGroupMethod(systemURI, snapSessionURI, snapshotURIs, copyMode, Boolean.FALSE), rollbackLinkBlockSnapshotSessionTargetMethod(systemURI, snapSessionURI, snapshotURIs.get(0)), null);
}
} else {
for (List<URI> snapshotURIs : sessionSnapshotURIs) {
if ((snapshotURIs != null) && (!snapshotURIs.isEmpty())) {
for (URI snapshotURI : snapshotURIs) {
workflow.createStep(LINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Linking targets for snapshot session %s", snapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), linkBlockSnapshotSessionTargetMethod(systemURI, snapSessionURI, snapshotURI, copyMode, Boolean.FALSE), rollbackLinkBlockSnapshotSessionTargetMethod(systemURI, snapSessionURI, snapshotURI), null);
}
}
}
}
}
workflow.executePlan(completer, "Create block snapshot session successful");
} catch (Exception e) {
_log.error("Create block snapshot session failed", e);
ServiceCoded serviceException = DeviceControllerException.exceptions.createBlockSnapshotSessionFailed(e);
completer.error(_dbClient, serviceException);
}
}
use of com.emc.storageos.svcs.errorhandling.model.ServiceCoded in project coprhd-controller by CoprHD.
the class BlockDeviceController method deleteSnapshotSession.
/**
* {@inheritDoc}
*/
@Override
public void deleteSnapshotSession(URI systemURI, URI snapSessionURI, String opId) {
TaskCompleter completer = new BlockSnapshotSessionDeleteWorkflowCompleter(snapSessionURI, opId);
try {
// Get a new workflow delete the snapshot session.
Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_SNAPSHOT_SESSION_WF_NAME, false, opId);
_log.info("Created new workflow to delete snapshot session {} with operation id {}", snapSessionURI, opId);
// When deleting a group snapshot we need the name of the group.
String groupName = null;
boolean isCG = checkSnapshotSessionConsistencyGroup(snapSessionURI, _dbClient, completer);
if (isCG) {
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
groupName = snapSession.getReplicationGroupInstance();
}
// Create the workflow step to delete the snapshot session.
workflow.createStep(DELETE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Delete snapshot session %s", snapSessionURI), null, systemURI, getDeviceType(systemURI), getClass(), deleteBlockSnapshotSessionMethod(systemURI, snapSessionURI, groupName, Boolean.FALSE), null, null);
// Execute the workflow.
workflow.executePlan(completer, "Delete block snapshot session successful");
} catch (Exception e) {
_log.error("Delete block snapshot session failed", e);
ServiceCoded serviceException = DeviceControllerException.exceptions.deleteBlockSnapshotSessionFailed(e);
completer.error(_dbClient, serviceException);
}
}
Aggregations