Search in sources :

Example 26 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.

the class VolumeIngestionUtil method clearSnapshotSessionsFlags.

/**
 * Clear the flags of the snapshot sessions of the RP volume
 *
 * @param blockObject the block Object to clear flags on
 * @param updatedObjects a Set of DataObjects to be updated in the database at the end of ingestion
 * @param dbClient dbClient reference.
 */
public static void clearSnapshotSessionsFlags(BlockObject blockObject, Set<DataObject> updatedObjects, DbClient dbClient) {
    URIQueryResultList queryResults = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(blockObject.getId()), queryResults);
    Iterator<URI> resultsIter = queryResults.iterator();
    while (resultsIter.hasNext()) {
        BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, resultsIter.next());
        _logger.info("Clearing internal volume flag of snapshot session {} of RP volume {}", snapSession.getLabel(), blockObject.getLabel());
        snapSession.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
        updatedObjects.add(snapSession);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 27 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.

the class VolumeIngestionUtil method clearReplicaFlagsInIngestionContext.

/**
 * Clear the flags of replicas which have been updated during the ingestion process
 *
 * @param requestContext current unManagedVolume Ingestion context.
 * @param volumes RP volumes
 * @param dbClient database client
 */
public static void clearReplicaFlagsInIngestionContext(IngestionRequestContext requestContext, List<Volume> volumes, DbClient dbClient) {
    // We need to look for all snapshots and snapshot session in the contexts related to the rp volumes and its backend volumes and
    // clear their flags.
    _logger.info("Clearing flags of replicas in the context");
    List<String> rpVolumes = new ArrayList<String>();
    for (Volume volume : volumes) {
        rpVolumes.add(volume.getId().toString());
        if (RPHelper.isVPlexVolume(volume, dbClient) && volume.getAssociatedVolumes() != null && !volume.getAssociatedVolumes().isEmpty()) {
            StringSet associatedVolumes = volume.getAssociatedVolumes();
            rpVolumes.addAll(associatedVolumes);
        }
    }
    for (VolumeIngestionContext volumeIngestionContext : requestContext.getRootIngestionRequestContext().getProcessedUnManagedVolumeMap().values()) {
        if (volumeIngestionContext instanceof IngestionRequestContext) {
            for (Set<DataObject> objectsToBeUpdated : ((IngestionRequestContext) volumeIngestionContext).getDataObjectsToBeUpdatedMap().values()) {
                for (DataObject o : objectsToBeUpdated) {
                    boolean rpBlockSnapshot = (o instanceof BlockSnapshot && rpVolumes.contains(((BlockSnapshot) o).getParent().getURI().toString()));
                    boolean rpBlockSnapshotSession = (o instanceof BlockSnapshotSession && rpVolumes.contains(((BlockSnapshotSession) o).getParent().getURI().toString()));
                    if (rpBlockSnapshot || rpBlockSnapshotSession) {
                        _logger.info(String.format("Clearing internal volume flag of %s %s of RP volume ", (rpBlockSnapshot ? "BlockSnapshot" : "BlockSnapshotSession"), o.getLabel()));
                        o.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
                    }
                }
            }
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) IngestionRequestContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.IngestionRequestContext) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.VplexVolumeIngestionContext) RpVplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RpVplexVolumeIngestionContext) BlockVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BlockVolumeIngestionContext) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext)

Example 28 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.

the class BlockDeviceController method relinkTargetsToSnapshotSession.

/**
 * {@inheritDoc}
 */
@Override
public void relinkTargetsToSnapshotSession(URI systemURI, URI tgtSnapSessionURI, List<URI> snapshotURIs, Boolean updateStatus, String opId) throws InternalException {
    TaskCompleter completer = new BlockSnapshotSessionRelinkTargetsWorkflowCompleter(tgtSnapSessionURI, updateStatus, opId);
    try {
        // Get a new workflow to execute the linking of the target volumes
        // to the new session.
        Workflow workflow = _workflowService.getNewWorkflow(this, RELINK_SNAPSHOT_SESSION_TARGETS_WF_NAME, false, opId);
        _log.info("Created new workflow to re-link targets to snapshot session {} with operation id {}", tgtSnapSessionURI, opId);
        Iterable<URI> snapshotsIterable = snapshotURIs;
        BlockSnapshotSession tgtSnapSession = _dbClient.queryObject(BlockSnapshotSession.class, tgtSnapSessionURI);
        // For CG's, ensure 1 target per ReplicationGroup
        if (tgtSnapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(tgtSnapSession.getReplicationGroupInstance())) {
            snapshotsIterable = ControllerUtils.ensureOneSnapshotPerReplicationGroup(snapshotURIs, _dbClient);
        }
        String waitFor = null;
        for (URI snapshotURI : snapshotsIterable) {
            waitFor = workflow.createStep(RELINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Re-linking target to snapshot session %s", tgtSnapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), relinkBlockSnapshotSessionTargetMethod(systemURI, tgtSnapSessionURI, snapshotURI), null, null);
        }
        workflow.executePlan(completer, "Re-link target volumes to block snapshot session successful");
    } catch (Exception e) {
        _log.error("Re-link target volumes to block snapshot session failed", e);
        ServiceCoded serviceException = DeviceControllerException.exceptions.relinkBlockSnapshotSessionTargetsFailed(e);
        completer.error(_dbClient, serviceException);
    }
}
Also used : BlockSnapshotSessionRelinkTargetsWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionRelinkTargetsWorkflowCompleter) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Workflow(com.emc.storageos.workflow.Workflow) 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) 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)

Example 29 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.

the class BlockDeviceController method restoreSnapshotSession.

/**
 * {@inheritDoc}
 */
@Override
public void restoreSnapshotSession(URI systemURI, URI snapSessionURI, Boolean updateStatus, String opId) {
    BlockSnapshotSession snapshotSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
    TaskCompleter completer = new BlockSnapshotSessionRestoreWorkflowCompleter(snapshotSession.getId(), updateStatus, opId);
    try {
        // Get a new workflow to restore the snapshot session.
        Workflow workflow = _workflowService.getNewWorkflow(this, RESTORE_SNAPSHOT_SESSION_WF_NAME, false, opId);
        _log.info("Created new workflow to restore snapshot session {} with operation id {}", snapSessionURI, opId);
        String waitFor = null;
        // Check if we are dealing with a single volume or a group...
        BlockObject sourceObj = null;
        if (snapshotSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapshotSession.getReplicationGroupInstance())) {
            // We need a single source volume for the session.
            BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, snapshotSession.getConsistencyGroup());
            List<Volume> nativeVolumes = BlockConsistencyGroupUtils.getActiveNativeVolumesInCG(cg, _dbClient);
            // get source group name from the session.
            String sourceGroupName = snapshotSession.getReplicationGroupInstance();
            for (Volume volume : nativeVolumes) {
                if (sourceGroupName.equals(volume.getReplicationGroupInstance())) {
                    sourceObj = volume;
                    // get source volume which matches session's RG name
                    break;
                }
            }
        } else {
            sourceObj = BlockObject.fetch(_dbClient, snapshotSession.getParent().getURI());
        }
        if (sourceObj instanceof Volume && isNonSplitSRDFTargetVolume((Volume) sourceObj)) {
            // PRIOR to Restoring R2 Device from its session, we need to
            // a) SUSPEND the R1-R2 pair if the Copy Mode is ACTIVE Or
            // b) SPLIT the R1-R2 pair if the Copy Mode is SYNC/ ASYNC
            Volume sourceVolume = (Volume) sourceObj;
            URI srdfSourceVolumeURI = sourceVolume.getSrdfParent().getURI();
            Volume srdfSourceVolume = _dbClient.queryObject(Volume.class, srdfSourceVolumeURI);
            URI srdfSourceStorageSystemURI = srdfSourceVolume.getStorageController();
            if (Mode.ACTIVE.equals(Mode.valueOf(sourceVolume.getSrdfCopyMode()))) {
                waitFor = suspendSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, srdfSourceVolumeURI, sourceObj.getId(), workflow);
            } else {
                // split all members the group
                Workflow.Method splitMethod = srdfDeviceController.splitSRDFGroupLinkMethod(srdfSourceStorageSystemURI, srdfSourceVolumeURI, sourceObj.getId(), false);
                Workflow.Method splitRollbackMethod = srdfDeviceController.resumeGroupPairsMethod(srdfSourceStorageSystemURI, srdfSourceVolumeURI, sourceObj.getId());
                waitFor = workflow.createStep(SRDFDeviceController.SPLIT_SRDF_MIRRORS_STEP_GROUP, SRDFDeviceController.SPLIT_SRDF_MIRRORS_STEP_DESC, waitFor, srdfSourceStorageSystemURI, getDeviceType(srdfSourceStorageSystemURI), SRDFDeviceController.class, splitMethod, splitRollbackMethod, null);
            }
        } else if (sourceObj instanceof Volume && isNonSplitSRDFSourceVolume((Volume) sourceObj)) {
            // PRIOR to Restoring R1 Device from its session, we need to SUSPEND the R1-R2 pair if the Copy Mode is
            // ACTIVE
            Volume srdfSourceVolume = (Volume) sourceObj;
            URI srdfSourceStorageSystemURI = srdfSourceVolume.getStorageController();
            StringSet targets = srdfSourceVolume.getSrdfTargets();
            if (null != targets) {
                for (String target : targets) {
                    if (NullColumnValueGetter.isNotNullValue(target)) {
                        Volume srdfTargetVolume = _dbClient.queryObject(Volume.class, URI.create(target));
                        if (null != srdfTargetVolume && Mode.ACTIVE.equals(Mode.valueOf(srdfTargetVolume.getSrdfCopyMode()))) {
                            waitFor = suspendSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, srdfSourceVolume.getId(), srdfTargetVolume.getId(), workflow);
                        }
                        break;
                    }
                }
            }
        }
        // Create the workflow step to restore the snapshot session.
        waitFor = workflow.createStep(RESTORE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Restore snapshot session %s", snapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), restoreBlockSnapshotSessionMethod(systemURI, snapSessionURI), rollbackMethodNullMethod(), null);
        // Execute the workflow.
        workflow.executePlan(completer, "Restore block snapshot session successful");
    } catch (Exception e) {
        _log.error("Restore block snapshot session failed", e);
        ServiceCoded serviceException = DeviceControllerException.exceptions.restoreBlockSnapshotSessionFailed(e);
        completer.error(_dbClient, serviceException);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshotSessionRestoreWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionRestoreWorkflowCompleter) 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) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) SRDFDeviceController(com.emc.storageos.srdfcontroller.SRDFDeviceController) StringSet(com.emc.storageos.db.client.model.StringSet) 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) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 30 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession in project coprhd-controller by CoprHD.

the class BlockDeviceController method restoreVolume.

@Override
public void restoreVolume(URI storage, URI pool, URI volumeURI, URI snapshot, Boolean updateOpStatus, String syncDirection, String opId) throws ControllerException {
    SimpleTaskCompleter completer = new SimpleTaskCompleter(BlockSnapshot.class, snapshot, opId);
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, RESTORE_VOLUME_WF_NAME, false, opId);
        _log.info("Created new restore workflow with operation id {}", opId);
        Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
        BlockSnapshot blockSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        StorageSystem system = _dbClient.queryObject(StorageSystem.class, storage);
        String description = String.format("Restore volume %s from snapshot %s", volumeURI, snapshot);
        String waitFor = null;
        URI srdfSourceStorageSystemURI = null;
        Volume srdfSourceVolume = null;
        Volume srdfTargetVolume = null;
        boolean active = false;
        /**
         * We need to split the SRDF link for R2 snap restore if it is not paused already.
         * Refer OPT#476788
         */
        if (isNonSplitSRDFTargetVolume(volume)) {
            URI srdfSourceVolumeURI = volume.getSrdfParent().getURI();
            srdfSourceVolume = _dbClient.queryObject(Volume.class, srdfSourceVolumeURI);
            srdfTargetVolume = volume;
            srdfSourceStorageSystemURI = srdfSourceVolume.getStorageController();
            if (Mode.ACTIVE.equals(Mode.valueOf(volume.getSrdfCopyMode()))) {
                active = true;
                waitFor = suspendSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, srdfSourceVolumeURI, volumeURI, workflow);
            } else {
                // split all members the group
                Workflow.Method splitMethod = srdfDeviceController.splitSRDFGroupLinkMethod(srdfSourceStorageSystemURI, srdfSourceVolumeURI, volumeURI, false);
                Workflow.Method splitRollbackMethod = srdfDeviceController.resumeGroupPairsMethod(srdfSourceStorageSystemURI, srdfSourceVolumeURI, volumeURI);
                waitFor = workflow.createStep(SRDFDeviceController.SPLIT_SRDF_MIRRORS_STEP_GROUP, SRDFDeviceController.SPLIT_SRDF_MIRRORS_STEP_DESC, waitFor, srdfSourceStorageSystemURI, getDeviceType(srdfSourceStorageSystemURI), SRDFDeviceController.class, splitMethod, splitRollbackMethod, null);
            }
        } else if (isNonSplitSRDFSourceVolume(volume)) {
            srdfSourceVolume = volume;
            srdfSourceStorageSystemURI = volume.getStorageController();
            StringSet targets = volume.getSrdfTargets();
            if (null != targets) {
                for (String target : targets) {
                    if (NullColumnValueGetter.isNotNullValue(target)) {
                        srdfTargetVolume = _dbClient.queryObject(Volume.class, URI.create(target));
                        if (null != srdfTargetVolume && Mode.ACTIVE.equals(Mode.valueOf(srdfTargetVolume.getSrdfCopyMode()))) {
                            active = true;
                            waitFor = suspendSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, volume.getId(), srdfTargetVolume.getId(), workflow);
                        }
                        break;
                    }
                }
            }
        }
        if (system.checkIfVmax3()) {
            _log.info("Creating workflow for restore VMAX3 snapshot {}", blockSnapshot.getId());
            // To restore the source from a linked target volume for VMAX3 SnapVX, we must
            // do the following:
            // 
            // 1. Terminate any stale restore sessions on the source.
            // 2. Create a temporary snapvx snapshot session of the linked target volume or target group.
            // 3. Link the source volume(s) of the BlockSnapshot(s) to the temporary snapshot session in copy mode.
            // 4. Wait for the data from the session to be copied to the source volume(s)
            // 5. Unlink the source volume(s) from the temporary snapvx snapshot session.
            // 6. Delete the temporary session.
            // 
            // This is essentially restoring by creating a cascaded snapshot session or group
            // snapshot session on the linked target volume associated with the passed block
            // snapshot or associated linked target group in the case of a group operation.
            // Create a workflow step to terminate stale restore sessions.
            waitFor = workflow.createStep(BLOCK_VOLUME_RESTORE_GROUP, String.format("Terminating VMAX restore session from %s to %s", blockSnapshot.getId(), volume.getId()), waitFor, system.getId(), system.getSystemType(), BlockDeviceController.class, terminateRestoreSessionsMethod(system.getId(), volume.getId(), blockSnapshot.getId()), rollbackMethodNullMethod(), null);
            // Get all snapshots if this is a group snapshot.
            String replicationGroupName = null;
            List<BlockSnapshot> allSnapshots = new ArrayList<>();
            String replicationGroupId = blockSnapshot.getReplicationGroupInstance();
            if (!NullColumnValueGetter.isNullValue(replicationGroupId)) {
                allSnapshots.addAll(ControllerUtils.getSnapshotsPartOfReplicationGroup(blockSnapshot, _dbClient));
                int nameStartIndex = replicationGroupId.indexOf("+") + 1;
                replicationGroupName = replicationGroupId.substring(nameStartIndex);
            } else {
                allSnapshots.add(blockSnapshot);
            }
            // Create a temporary BlockSnapshot instance to represent the parent source volumes
            // for each block snapshot. Linking to a session required BlockSnapshot instances so
            // we need to create some to represent the source volume(s).
            StringSet linkedTargets = new StringSet();
            List<BlockSnapshot> sourceSnapshots = new ArrayList<>();
            List<URI> sourceSnapshotURIs = new ArrayList<>();
            URI cgURI = blockSnapshot.getConsistencyGroup();
            for (BlockSnapshot aSnapshot : allSnapshots) {
                BlockObject aSourceObj = BlockObject.fetch(_dbClient, aSnapshot.getParent().getURI());
                BlockSnapshot sourceSnapshot = new BlockSnapshot();
                URI sourceSnapshotURI = URIUtil.createId(BlockSnapshot.class);
                sourceSnapshot.setId(sourceSnapshotURI);
                sourceSnapshot.setNativeId(aSourceObj.getNativeId());
                sourceSnapshot.setParent(new NamedURI(aSnapshot.getId(), aSnapshot.getLabel()));
                sourceSnapshot.setSourceNativeId(aSnapshot.getNativeId());
                sourceSnapshot.setStorageController(storage);
                sourceSnapshot.setSystemType(system.getSystemType());
                if (!NullColumnValueGetter.isNullURI(cgURI)) {
                    sourceSnapshot.setConsistencyGroup(cgURI);
                }
                sourceSnapshot.addInternalFlags(Flag.INTERNAL_OBJECT);
                sourceSnapshots.add(sourceSnapshot);
                sourceSnapshotURIs.add(sourceSnapshotURI);
                linkedTargets.add(sourceSnapshotURI.toString());
            }
            _dbClient.createObject(sourceSnapshots);
            // Create a BlockSnapshotSession instance to represent the temporary snapshot session.
            BlockSnapshotSession snapSession = new BlockSnapshotSession();
            URI snapSessionURI = URIUtil.createId(BlockSnapshotSession.class);
            snapSession.setId(snapSessionURI);
            snapSession.setLabel(blockSnapshot.getLabel() + System.currentTimeMillis());
            snapSession.setSessionLabel(snapSession.getLabel());
            snapSession.setProject(blockSnapshot.getProject());
            snapSession.setStorageController(storage);
            snapSession.addInternalFlags(Flag.INTERNAL_OBJECT);
            if (!NullColumnValueGetter.isNullURI(cgURI) && NullColumnValueGetter.isNotNullValue(replicationGroupName)) {
                snapSession.setConsistencyGroup(cgURI);
                snapSession.setReplicationGroupInstance(replicationGroupName);
                snapSession.setSessionSetName(replicationGroupName);
            } else {
                snapSession.setParent(new NamedURI(blockSnapshot.getId(), blockSnapshot.getLabel()));
            }
            snapSession.setLinkedTargets(linkedTargets);
            _dbClient.createObject(snapSession);
            // Now create a workflow step that will create the snapshot session.
            // This will create a group session in the case of a group operation.
            waitFor = workflow.createStep(CREATE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Create snapshot session %s for snapshot target volume %s", snapSessionURI, snapshot), waitFor, storage, getDeviceType(storage), BlockDeviceController.class, createBlockSnapshotSessionMethod(storage, snapSessionURI, replicationGroupName), deleteBlockSnapshotSessionMethod(storage, snapSessionURI, replicationGroupName, Boolean.TRUE), null);
            // Create a workflow step to link the source volume for the passed snapshot
            // to the snapshot session create by the previous step. We link the source
            // volume in copy mode so that that the point-in-time copy of the snapshot
            // target volume represented by the snapshot session is copied to the source
            // volume. This is essentially the restore step so that the source will now
            // reflect the data on the snapshot target volume. This step will not complete
            // until the data is copied and the link has achieved the copied state. If this
            // is group operation the source target group will be linked to the created
            // group session.
            Workflow.Method linkMethod;
            if (!NullColumnValueGetter.isNullURI(cgURI) && NullColumnValueGetter.isNotNullValue(replicationGroupName)) {
                linkMethod = linkBlockSnapshotSessionTargetGroupMethod(storage, snapSessionURI, sourceSnapshotURIs, BlockSnapshotSession.CopyMode.copy.name(), Boolean.TRUE);
            } else {
                linkMethod = linkBlockSnapshotSessionTargetMethod(storage, snapSessionURI, sourceSnapshotURIs.get(0), BlockSnapshotSession.CopyMode.copy.name(), Boolean.TRUE);
            }
            waitFor = workflow.createStep(LINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Link source volume %s to snapshot session for snapshot target volume %s", volume, snapshot), waitFor, storage, getDeviceType(storage), BlockDeviceController.class, linkMethod, unlinkBlockSnapshotSessionTargetMethod(storage, snapSessionURI, sourceSnapshotURIs.get(0), Boolean.FALSE), null);
            // Once the data is fully copied to the source, we can unlink the source from the session.
            // Again, for a group operation, this will unlink the source group from the group session.
            waitFor = workflow.createStep(UNLINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Unlink source volume %s from snapshot session for snapshot target volume %s", volumeURI, snapshot), waitFor, storage, getDeviceType(storage), BlockDeviceController.class, unlinkBlockSnapshotSessionTargetMethod(storage, snapSessionURI, sourceSnapshotURIs.get(0), Boolean.FALSE), rollbackMethodNullMethod(), null);
            // Finally create a step to delete the snapshot session we created on the snapshot
            // target volume.
            waitFor = workflow.createStep(DELETE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Delete snapshot session %s for snapshot target volume %s", snapSessionURI, snapshot), waitFor, storage, getDeviceType(storage), BlockDeviceController.class, deleteBlockSnapshotSessionMethod(storage, snapSessionURI, replicationGroupName, Boolean.TRUE), rollbackMethodNullMethod(), null);
            /*
                 * If Active mode then create a step to resume srdf group or restore R2 To R1 or do nothing.
                 * If syncdirection is not specified means its null then after R1 snapshot restore, resume.
                 * If syncdirection is not specified means its null then after R2 snapshot restore, restore R2 to R1.
                 * If syncdirection is SOURCE_TO_TARGET then after R1 or R2 snapshot restore, resume.
                 * If syncdirection is TARGET_TO_SOURCE then after R1 or R2 snapshot restore, restore R2 to R1.
                 * If syncdirection is NONE then do nothing, RDF group will stay in suspend state.
                 */
            if (active) {
                if (null == syncDirection) {
                    if (null != srdfSourceVolume && volumeURI.equals(srdfSourceVolume.getId())) {
                        resumeSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, srdfSourceVolume.getId(), srdfTargetVolume.getId(), workflow);
                    } else if (null != srdfTargetVolume && volumeURI.equals(srdfTargetVolume.getId())) {
                        restoreWorkflowStep(waitFor, srdfTargetVolume.getStorageController(), srdfSourceVolume.getId(), srdfTargetVolume.getId(), workflow);
                    }
                } else if (null != syncDirection) {
                    if (SRDFUtils.SyncDirection.SOURCE_TO_TARGET.toString().equals(syncDirection)) {
                        resumeSRDFLinkWorkflowStep(waitFor, srdfSourceStorageSystemURI, srdfSourceVolume.getId(), srdfTargetVolume.getId(), workflow);
                    } else if (SRDFUtils.SyncDirection.TARGET_TO_SOURCE.toString().equals(syncDirection)) {
                        restoreWorkflowStep(waitFor, srdfTargetVolume.getStorageController(), srdfSourceVolume.getId(), srdfTargetVolume.getId(), workflow);
                    } else if (SRDFUtils.SyncDirection.NONE.toString().equals(syncDirection)) {
                        _log.info("Sync direction is specified as {} hence no action will be done after retsore snapshot which" + " means the RDF group for volume {} will be in a suspended state.", syncDirection, volume.getLabel());
                    }
                }
            }
        } else {
            waitFor = workflow.createStep(BLOCK_VOLUME_RESTORE_GROUP, description, waitFor, storage, getDeviceType(storage), BlockDeviceController.class, restoreVolumeMethod(storage, pool, volumeURI, snapshot, updateOpStatus), rollbackMethodNullMethod(), null);
            // Skip the step for VMAX3, as restore operation may still be in progress (OPT#476325)
            // Regardless, termination of restore session should be call before restore
            // Note this is not needed for VNX
            addPostRestoreVolumeSteps(workflow, system, volume, blockSnapshot, waitFor);
        }
        _log.info("Executing workflow {}", BLOCK_VOLUME_RESTORE_GROUP);
        String msg = String.format("Restore of volume %s from %s completed successfully", volumeURI, snapshot);
        workflow.executePlan(completer, msg);
    } catch (Exception e) {
        String msg = String.format("Could not restore volume %s from snapshot %s", volumeURI, snapshot);
        _log.error(msg, e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(_dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) NamedURI(com.emc.storageos.db.client.model.NamedURI) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) 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) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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) Volume(com.emc.storageos.db.client.model.Volume) SRDFDeviceController(com.emc.storageos.srdfcontroller.SRDFDeviceController) StringSet(com.emc.storageos.db.client.model.StringSet) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)112 URI (java.net.URI)64 Volume (com.emc.storageos.db.client.model.Volume)43 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)41 NamedURI (com.emc.storageos.db.client.model.NamedURI)38 ArrayList (java.util.ArrayList)33 BlockObject (com.emc.storageos.db.client.model.BlockObject)29 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)27 StringSet (com.emc.storageos.db.client.model.StringSet)25 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 HashMap (java.util.HashMap)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)16 CIMObjectPath (javax.cim.CIMObjectPath)13 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)11 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)11 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)11 DataObject (com.emc.storageos.db.client.model.DataObject)10 Project (com.emc.storageos.db.client.model.Project)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10