Search in sources :

Example 76 with BlockObject

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

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

the class BlockDeviceController method addStepsForRestoreFromFullcopy.

/**
 * Add steps to restore full copy
 *
 * @param workflow
 *            - the workflow the steps would be added to
 * @param waitFor
 *            - the step would be waited before the added steps would be executed
 * @param storage
 *            - the storage controller URI
 * @param fullcopies
 *            - the full copies to restore
 * @param opId
 * @param completer
 *            - the CloneRestoreCompleter
 * @return the step id for the added step
 * @throws InternalException
 */
public String addStepsForRestoreFromFullcopy(Workflow workflow, String waitFor, URI storage, List<URI> fullcopies, String opId, TaskCompleter completer) throws InternalException {
    Volume firstFullCopy = _dbClient.queryObject(Volume.class, fullcopies.get(0));
    // Don't do anything if this is VPLEX full copy
    if (firstFullCopy.isVPlexVolume(_dbClient)) {
        return waitFor;
    }
    BlockObject firstSource = BlockObject.fetch(_dbClient, firstFullCopy.getAssociatedSourceVolume());
    if (!NullColumnValueGetter.isNullURI(firstSource.getConsistencyGroup())) {
        completer.addConsistencyGroupId(firstSource.getConsistencyGroup());
    }
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, storage);
    Workflow.Method restoreFromFullcopyMethod = new Workflow.Method(RESTORE_FROM_FULLCOPY_METHOD_NAME, storage, fullcopies, Boolean.TRUE);
    waitFor = workflow.createStep(RESTORE_FROM_FULLCOPY_STEP, "Restore volumes from full copies", waitFor, storage, system.getSystemType(), this.getClass(), restoreFromFullcopyMethod, null, null);
    _log.info("Created workflow step to restore volume from full copies");
    return waitFor;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) Workflow(com.emc.storageos.workflow.Workflow) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 78 with BlockObject

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

Example 79 with BlockObject

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

the class BlockDeviceExportController method getExportRemovableObjects.

/**
 * Not all block objects in the export group are what they seem.
 * Some block objects are volumes that are associated with RP snapshots
 * Some volumes in the export mask don't belong to the export group being removed.
 * This method sorts out of relevant from the irrelevant and creates a real list of URIs to remove.
 *
 * @param exportGroup export group
 * @param exportMask export mask
 * @return URIs of block objects to remove
 */
private List<URI> getExportRemovableObjects(ExportGroup exportGroup, ExportMask exportMask) {
    List<URI> uriList = new ArrayList<URI>();
    // map to the same volume.
    if (exportMask.getVolumes() != null) {
        for (URI volumeID : URIUtil.toURIList(exportMask.getVolumes().keySet())) {
            if (!exportGroup.hasBlockObject(volumeID)) {
                // with a RP snapshot.
                if (exportGroup.getSnapshots() != null) {
                    for (URI snapshotID : URIUtil.toURIList(exportGroup.getSnapshots())) {
                        BlockObject bo = Volume.fetchExportMaskBlockObject(_dbClient, snapshotID);
                        // and it's not null, then that means it's an RP target volume by definition.
                        if (bo != null && !bo.getId().equals(snapshotID) && !uriList.contains(snapshotID)) {
                            // Add this snapshot to the list of "volumes" to be removed from this mask,
                            // so it gets routed through RP Controller.
                            uriList.add(snapshotID);
                        }
                    }
                }
            } else {
                uriList.add(volumeID);
            }
        }
    }
    _log.info(String.format("Export Group being removed contains block objects: { %s }", exportGroup.getVolumes() != null ? Joiner.on(',').join(exportGroup.getVolumes().keySet()) : "NONE"));
    _log.info(String.format("Export Mask being analyzed contains block objects: { %s }", exportMask.getVolumes() != null ? Joiner.on(',').join(exportMask.getVolumes().keySet()) : "NONE"));
    _log.info(String.format("Block Objects being sent in for removal: { %s }", Joiner.on(',').join(uriList)));
    return uriList;
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 80 with BlockObject

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

the class BlockDeviceExportController method getStorageToVolumes.

/**
 * Get mapping of the storage arrays to the volumes based on the volumes list.
 * If any of the volumes are protected RP snapshots, all of the volumes/snaps for
 * that storage system should go through the protection controller so we don't fire
 * off multiple export group operations on the same export group concurrently.
 *
 * @param volumes - BlockObject URI list
 * @return Mapping of storage arrays (StorageSystem URI) to volumes list
 * @throws IOException
 */
private Map<URI, List<URI>> getStorageToVolumes(Collection<URI> volumes) throws IOException {
    Map<URI, List<URI>> storageToVolumesMap = new HashMap<URI, List<URI>>();
    Map<URI, URI> storageToProtectionMap = new HashMap<URI, URI>();
    // down that go to the protection controller together.
    for (URI uri : volumes) {
        BlockObject blockObject = BlockObject.fetch(_dbClient, uri);
        URI storage = getExportStorageController(blockObject);
        if (URIUtil.isType(storage, ProtectionSystem.class)) {
            List<URI> storageVolumes = storageToVolumesMap.get(storage);
            if (storageVolumes == null) {
                storageVolumes = new ArrayList<URI>();
                storageToVolumesMap.put(storage, storageVolumes);
            }
            storageVolumes.add(uri);
            // Add this storage system to the map ("storage" is the protection ctlr)
            storageToProtectionMap.put(blockObject.getStorageController(), storage);
        }
    }
    // Assemble a map of controllers that need to get called, and their respective volumes.
    for (URI uri : volumes) {
        BlockObject blockObject = BlockObject.fetch(_dbClient, uri);
        URI storage = getExportStorageController(blockObject);
        if (URIUtil.isType(storage, StorageSystem.class) || storageToProtectionMap.isEmpty()) {
            if (storageToProtectionMap.get(storage) != null) {
                // Add this to the existing protection controller's list
                storage = storageToProtectionMap.get(storage);
            }
            List<URI> storageVolumes = storageToVolumesMap.get(storage);
            if (storageVolumes == null) {
                storageVolumes = new ArrayList<URI>();
                storageToVolumesMap.put(storage, storageVolumes);
            }
            storageVolumes.add(uri);
        }
    }
    return storageToVolumesMap;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)341 URI (java.net.URI)222 ArrayList (java.util.ArrayList)152 Volume (com.emc.storageos.db.client.model.Volume)141 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)109 NamedURI (com.emc.storageos.db.client.model.NamedURI)82 HashMap (java.util.HashMap)82 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)69 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)65 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)60 ExportMask (com.emc.storageos.db.client.model.ExportMask)56 HashSet (java.util.HashSet)56 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)45 CIMObjectPath (javax.cim.CIMObjectPath)44 Initiator (com.emc.storageos.db.client.model.Initiator)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 List (java.util.List)40 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)38 StringSet (com.emc.storageos.db.client.model.StringSet)36