Search in sources :

Example 86 with BlockSnapshot

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

the class BlockDeviceController method resyncSnapshot.

@Override
public void resyncSnapshot(URI storage, URI volume, URI snapshot, Boolean updateOpStatus, String opId) throws ControllerException {
    TaskCompleter completer = null;
    try {
        StorageSystem storageDevice = _dbClient.queryObject(StorageSystem.class, storage);
        BlockSnapshot snapObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        completer = new BlockSnapshotResyncCompleter(snapObj, opId, updateOpStatus);
        getDevice(storageDevice.getSystemType()).doResyncSnapshot(storageDevice, volume, snapshot, completer);
    } catch (Exception e) {
        _log.error(String.format("resync snapshot failed - storage: %s, volume: %s, snapshot: %s", storage.toString(), volume.toString(), snapshot.toString()));
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(_dbClient, serviceError);
        doFailTask(BlockSnapshot.class, snapshot, opId, serviceError);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshotResyncCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotResyncCompleter) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) 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) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 87 with BlockSnapshot

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

the class BlockDeviceController method deleteSelectedSnapshot.

public void deleteSelectedSnapshot(URI storage, URI snapshot, String opId) throws ControllerException {
    _log.info("START deleteSelectedSnapshot");
    TaskCompleter completer = null;
    WorkflowStepCompleter.stepExecuting(opId);
    try {
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        BlockSnapshot snapObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        completer = BlockSnapshotDeleteCompleter.createCompleter(_dbClient, snapObj, opId);
        getDevice(storageObj.getSystemType()).doDeleteSelectedSnapshot(storageObj, snapshot, completer);
    } catch (Exception e) {
        if (completer != null) {
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
            WorkflowStepCompleter.stepFailed(opId, serviceError);
            completer.error(_dbClient, serviceError);
        } else {
            throw DeviceControllerException.exceptions.deleteVolumeSnapshotFailed(e);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) 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) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 88 with BlockSnapshot

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

the class BlockDeviceController method createFullCopy.

@Override
public void createFullCopy(URI storage, List<URI> fullCopyVolumes, Boolean createInactive, String taskId) throws ControllerException {
    _log.info("START fullCopyVolumes");
    TaskCompleter taskCompleter = new CloneCreateWorkflowCompleter(fullCopyVolumes, taskId);
    Volume clone = _dbClient.queryObject(Volume.class, fullCopyVolumes.get(0));
    URI sourceVolume = clone.getAssociatedSourceVolume();
    try {
        StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
        Workflow workflow = _workflowService.getNewWorkflow(this, FULL_COPY_WORKFLOW, true, taskId);
        boolean isCG = false;
        Volume source = URIUtil.isType(sourceVolume, Volume.class) ? _dbClient.queryObject(Volume.class, sourceVolume) : null;
        VolumeGroup volumeGroup = (source != null) ? source.getApplication(_dbClient) : null;
        if (volumeGroup != null) {
            /**
             * If a Volume is in Volume Group (COPY type),
             * Query all volumes belonging to that Volume Group,
             * Group full-copies by Array Replication Group and create workflow step for each Array Group,
             * these steps runs in parallel
             */
            _log.info("Creating full copy for Application {}", volumeGroup.getLabel());
            createFullCopyForApplicationCGs(workflow, volumeGroup, fullCopyVolumes, createInactive, taskCompleter);
        } else if (checkCloneConsistencyGroup(fullCopyVolumes.get(0), _dbClient, taskCompleter)) {
            // check if the clone is in a CG
            isCG = true;
            _log.info("Creating group full copy");
            createCGFullCopy(storage, sourceVolume, fullCopyVolumes, storageSystem, workflow, createInactive, isCG);
        } else {
            for (URI uri : fullCopyVolumes) {
                Workflow.Method createMethod = createFullCopyVolumeMethod(storage, sourceVolume, Arrays.asList(uri), createInactive, isCG);
                Workflow.Method rollbackMethod = rollbackFullCopyVolumeMethod(storage, asList(uri));
                workflow.createStep(FULL_COPY_CREATE_STEP_GROUP, "Creating full copy", null, storage, storageSystem.getSystemType(), getClass(), createMethod, rollbackMethod, null);
                // clone state.
                if (!createInactive && !getDriverManager().isDriverManaged(storageSystem.getSystemType())) {
                    // After all full copies have been created, wait for synchronization to complete
                    Workflow.Method waitForSyncMethod = waitForSynchronizedMethod(Volume.class, storage, Arrays.asList(uri), isCG);
                    String waitForSyncStep = workflow.createStep(FULL_COPY_WFS_STEP_GROUP, "Waiting for synchronization", FULL_COPY_CREATE_STEP_GROUP, storage, storageSystem.getSystemType(), getClass(), waitForSyncMethod, rollbackMethodNullMethod(), null);
                    Volume cloneVol = _dbClient.queryObject(Volume.class, uri);
                    BlockObject sourceObj = BlockObject.fetch(_dbClient, cloneVol.getAssociatedSourceVolume());
                    // detach if source is snapshot, or storage system is not vmax/vnx/hds
                    if (storageSystem.deviceIsType(Type.openstack)) {
                        setCloneReplicaStateStep(workflow, storageSystem, asList(uri), waitForSyncStep, ReplicationState.SYNCHRONIZED);
                    } else if (sourceObj instanceof BlockSnapshot || !(storageSystem.deviceIsType(Type.vmax) || storageSystem.deviceIsType(Type.hds) || storageSystem.deviceIsType(Type.vnxblock))) {
                        Workflow.Method detachMethod = detachFullCopyMethod(storage, asList(uri));
                        workflow.createStep(FULL_COPY_DETACH_STEP_GROUP, "Detaching full copy", waitForSyncStep, storage, storageSystem.getSystemType(), getClass(), detachMethod, rollbackMethodNullMethod(), null);
                    } else if (storageSystem.deviceIsType(Type.vnxblock)) {
                        workflow.createStep(FULL_COPY_FRACTURE_STEP_GROUP, "fracture full copy", waitForSyncStep, storage, storageSystem.getSystemType(), BlockDeviceController.class, fractureCloneMethod(storage, Arrays.asList(uri), isCG), rollbackMethodNullMethod(), null);
                    } else {
                        setCloneReplicaStateStep(workflow, storageSystem, asList(uri), waitForSyncStep, ReplicationState.SYNCHRONIZED);
                    }
                }
            }
        }
        String successMsg = String.format("Full copy of %s to %s successful", sourceVolume, fullCopyVolumes);
        workflow.executePlan(taskCompleter, successMsg);
    } catch (InternalException e) {
        _log.error("Failed to create full copy of volume", e);
        doFailTask(Volume.class, sourceVolume, taskId, e);
        WorkflowStepCompleter.stepFailed(taskId, e);
    } catch (Exception e) {
        _log.error("Failed to create full copy of volume", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        doFailTask(Volume.class, sourceVolume, taskId, serviceError);
        WorkflowStepCompleter.stepFailed(taskId, serviceError);
    }
}
Also used : CloneCreateWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneCreateWorkflowCompleter) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 89 with BlockSnapshot

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

the class BlockDeviceController method addStepsForRestoreVolume.

@Override
public String addStepsForRestoreVolume(Workflow workflow, String waitFor, URI storage, URI pool, URI volume, URI snapshot, Boolean updateOpStatus, String syncDirection, String taskId, BlockSnapshotRestoreCompleter completer) throws ControllerException {
    BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshot);
    URI parentVolumeURI = snap.getParent().getURI();
    Volume parentVolume = _dbClient.queryObject(Volume.class, parentVolumeURI);
    Volume associatedVPlexVolume = Volume.fetchVplexVolume(_dbClient, parentVolume);
    // VPlex controller will add the required block restore steps.
    if (NullColumnValueGetter.isNotNullValue(snap.getTechnologyType()) && !snap.getTechnologyType().equals(TechnologyType.NATIVE.toString()) || associatedVPlexVolume != null) {
        return waitFor;
    }
    Workflow.Method restoreVolumeMethod = new Workflow.Method(RESTORE_VOLUME_METHOD_NAME, storage, pool, volume, snapshot, Boolean.TRUE, syncDirection);
    workflow.createStep(RESTORE_VOLUME_STEP, String.format("Restore volume %s from snapshot %s", volume, snapshot), waitFor, storage, getDeviceType(storage), BlockDeviceController.class, restoreVolumeMethod, rollbackMethodNullMethod(), null);
    _log.info("Created workflow step to restore block volume {} from snapshot {}", volume, snapshot);
    return RESTORE_VOLUME_STEP;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) 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)

Example 90 with BlockSnapshot

use of com.emc.storageos.db.client.model.BlockSnapshot 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

BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)401 Volume (com.emc.storageos.db.client.model.Volume)215 URI (java.net.URI)209 ArrayList (java.util.ArrayList)112 NamedURI (com.emc.storageos.db.client.model.NamedURI)110 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)106 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)91 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)63 BlockObject (com.emc.storageos.db.client.model.BlockObject)63 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)55 CIMObjectPath (javax.cim.CIMObjectPath)51 StringSet (com.emc.storageos.db.client.model.StringSet)49 HashMap (java.util.HashMap)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)41 WBEMException (javax.wbem.WBEMException)38 Produces (javax.ws.rs.Produces)36 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)35 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)33 Path (javax.ws.rs.Path)33