use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionUnlinkTargetsWorkflowCompleter 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);
}
}
Aggregations