Search in sources :

Example 1 with BlockSnapshotSessionUnlinkTargetsWorkflowCompleter

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);
    }
}
Also used : BlockSnapshotSessionUnlinkTargetsWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionUnlinkTargetsWorkflowCompleter) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Workflow(com.emc.storageos.workflow.Workflow) NamedURI(com.emc.storageos.db.client.model.NamedURI) FCTN_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScanTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.ScanTaskCompleter) BlockSnapshotEstablishGroupTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter) BlockMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) ApplicationTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)1 FCTN_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)1 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)1 ApplicationTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter)1 BlockMirrorTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter)1 BlockSnapshotEstablishGroupTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter)1 BlockSnapshotSessionUnlinkTargetsWorkflowCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionUnlinkTargetsWorkflowCompleter)1 CloneTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter)1 MultiVolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter)1 SimpleTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter)1 VolumeTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter)1