use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionMigration method prepareSnapshotSession.
/**
* Prepare the ViPR BlockSnapshotSession instance for the pass BlockSnapshot instance.
*
* @param snapshot A reference to the snapshot.
*
* @return A reference to the newly created snapshot session.
*/
private BlockSnapshotSession prepareSnapshotSession(BlockSnapshot snapshot) {
s_logger.info("Prepare BlockSnapshotSession for snapshot {}", snapshot.getId());
BlockSnapshotSession snapshotSession = new BlockSnapshotSession();
URI snapSessionURI = URIUtil.createId(BlockSnapshotSession.class);
snapshotSession.setId(snapSessionURI);
snapshotSession.setSessionLabel(getSessionLabelFromSettingsInstance(snapshot));
URI cgURI = snapshot.getConsistencyGroup();
if (NullColumnValueGetter.isNullURI(cgURI)) {
snapshotSession.setParent(snapshot.getParent());
snapshotSession.setLabel(snapshot.getLabel());
} else {
snapshotSession.setConsistencyGroup(cgURI);
snapshotSession.setLabel(snapshot.getSnapsetLabel());
Volume parent = getDbClient().queryObject(Volume.class, snapshot.getParent());
if (parent != null) {
snapshotSession.setReplicationGroupInstance(parent.getReplicationGroupInstance());
snapshotSession.setSessionSetName(parent.getReplicationGroupInstance());
}
}
snapshotSession.setProject(snapshot.getProject());
snapshotSession.setStorageController(snapshot.getStorageController());
snapshotSession.setSessionInstance(snapshot.getSettingsInstance());
StringSet linkedTargets = new StringSet();
linkedTargets.add(snapshot.getId().toString());
snapshotSession.setLinkedTargets(linkedTargets);
return snapshotSession;
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession 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);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class BlockDeviceController method unlinkTargetsFromSnapshotSession.
/**
* {@inheritDoc}
*/
@Override
public void unlinkTargetsFromSnapshotSession(URI systemURI, URI snapSessionURI, Map<URI, Boolean> snapshotDeletionMap, OperationTypeEnum opType, String opId) {
TaskCompleter completer = new BlockSnapshotSessionUnlinkTargetsWorkflowCompleter(snapSessionURI, opType, opId);
try {
// Get a new workflow to unlinking of the targets from session.
Workflow workflow = _workflowService.getNewWorkflow(this, UNLINK_SNAPSHOT_SESSION_TARGETS_WF_NAME, false, opId);
_log.info("Created new workflow to unlink targets for snapshot session {} with operation id {}", snapSessionURI, opId);
Set<URI> targetKeys = snapshotDeletionMap.keySet();
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
// For CG's, ensure 1 target per ReplicationGroup
if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
Iterator<BlockSnapshot> snapshots = _dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotDeletionMap.keySet());
final Set<String> replicationGroups = new HashSet<>();
final Map<URI, BlockSnapshot> uriToSnapshotCache = new HashMap<>();
while (snapshots.hasNext()) {
BlockSnapshot snapshot = snapshots.next();
uriToSnapshotCache.put(snapshot.getId(), snapshot);
}
Map<URI, Boolean> filtered = Maps.filterEntries(snapshotDeletionMap, new Predicate<Map.Entry<URI, Boolean>>() {
@Override
public boolean apply(Map.Entry<URI, Boolean> input) {
BlockSnapshot blockSnapshot = uriToSnapshotCache.get(input.getKey());
String repGrpInstance = blockSnapshot.getReplicationGroupInstance();
if (replicationGroups.contains(repGrpInstance)) {
return false;
}
replicationGroups.add(repGrpInstance);
return true;
}
});
// assign to targetKeys filtered keySet view of snapshotDeletionMap.
targetKeys = filtered.keySet();
}
// TODO Use ModifyListSettingsDefineState here and remove the for-loop.
String waitFor = null;
// Create a workflow step to unlink each target specified in targetKeys
for (URI snapshotURI : targetKeys) {
waitFor = workflow.createStep(UNLINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Unlinking target for snapshot session %s", snapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), unlinkBlockSnapshotSessionTargetMethod(systemURI, snapSessionURI, snapshotURI, snapshotDeletionMap.get(snapshotURI)), null, null);
}
// Execute the workflow.
workflow.executePlan(completer, "Unlink block snapshot session targets successful");
} catch (Exception e) {
_log.error("Unlink block snapshot session targets failed", e);
ServiceCoded serviceException = DeviceControllerException.exceptions.unlinkBlockSnapshotSessionTargetsFailed(e);
completer.error(_dbClient, serviceException);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class BlockDeviceController method rollbackLinkBlockSnapshotSessionTarget.
/**
* Rollback a failed attempt to link a target volume to the array snapshot.
*
* @param systemURI
* The URI of the storage system.
* @param snapSessionURI
* The URI of the BlockSnapshotSession instance.
* @param snapshotURI
* The URI of the BlockSnapshot instance.
* @param stepId
* The unique id of the workflow step in which the rollback is executed.
*/
public void rollbackLinkBlockSnapshotSessionTarget(URI systemURI, URI snapSessionURI, URI snapshotURI, String stepId) {
// We do not rollback successfully linked targets. If the target
// was not successfully created and linked, it could in one of two
// states. Either the target is not provisioned, or the target is
// provisioned but not linked to the array snapshot. We call the
// method to unlink the target and make sure the unlink target
// algorithm accounts for these possibilities. Successfully linked
// targets will be in the list of linked targets for the session.
BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
StringSet linkedTargets = snapSession.getLinkedTargets();
if ((linkedTargets == null) || (!linkedTargets.contains(snapshotURI.toString()))) {
unlinkBlockSnapshotSessionTarget(systemURI, snapSessionURI, snapshotURI, Boolean.TRUE, stepId);
} else {
WorkflowStepCompleter.stepSucceded(stepId);
}
}
use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.
the class ReplicaDeviceController method deleteSnapshotSessionSteps.
/**
* Remove all snapshot sessions from the volumes to be deleted.
*
* @param workflow
* @param waitFor
* @param volumes
* @param isRemoveAllFromRG
* @return
*/
private String deleteSnapshotSessionSteps(Workflow workflow, String waitFor, List<Volume> volumes, boolean isRemoveAllFromRG) {
log.info("START delete snapshot session steps");
if (!isRemoveAllFromRG) {
log.info("Nothing to do");
return waitFor;
}
URI storage = volumes.get(0).getStorageController();
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
Set<String> replicationGroupInstances = new HashSet<>();
for (Volume volume : volumes) {
replicationGroupInstances.add(volume.getReplicationGroupInstance());
}
for (String replicationGroupInstance : replicationGroupInstances) {
Collection<BlockSnapshotSession> sessions = getSessionsForReplicationGroup(replicationGroupInstance, storage);
for (BlockSnapshotSession session : sessions) {
Workflow.Method deleteMethod = BlockDeviceController.deleteBlockSnapshotSessionMethod(storage, session.getId(), replicationGroupInstance, true);
waitFor = workflow.createStep("RemoveSnapshotSessions", "Remove Snapshot Session", waitFor, storage, storageSystem.getSystemType(), BlockDeviceController.class, deleteMethod, null, null);
}
}
return waitFor;
}
Aggregations