Search in sources :

Example 61 with BlockSnapshotSession

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

the class ReplicaDeviceController method createReplicaIfCGHasReplica.

/**
 * Creates replica snap/clone/mirror for the newly created volume, if the existing CG Volume has any replica.
 *
 * @param workflow
 * @param waitFor
 * @param volumeDescriptors
 * @param cgURI
 * @return
 */
private String createReplicaIfCGHasReplica(Workflow workflow, String waitFor, List<VolumeDescriptor> volumeDescriptors, URI cgURI) {
    log.info("CG URI {}", cgURI);
    if (volumeDescriptors != null && !volumeDescriptors.isEmpty()) {
        VolumeDescriptor firstVolumeDescriptor = volumeDescriptors.get(0);
        if (firstVolumeDescriptor != null && cgURI != null) {
            // find member volumes in the group
            BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgURI);
            List<Volume> existingVolumesInCG = BlockConsistencyGroupUtils.getActiveNativeVolumesInCG(cg, _dbClient);
            URI storage = existingVolumesInCG.get(0).getStorageController();
            // We will not end up in more than 1 RG within a CG, hence taking System from CG is fine.
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
            if (checkIfCGHasCloneReplica(existingVolumesInCG)) {
                log.info("Adding clone steps for create {} volumes", firstVolumeDescriptor.getType());
                // create new clones for the newly created volumes
                // add the created clones to clone groups
                waitFor = createCloneSteps(workflow, waitFor, volumeDescriptors, existingVolumesInCG, cgURI);
            }
            if (checkIfCGHasMirrorReplica(existingVolumesInCG)) {
                log.info("Adding mirror steps for create {} volumes", firstVolumeDescriptor.getType());
                // create new mirrors for the newly created volumes
                // add the created mirrors to mirror groups
                waitFor = createMirrorSteps(workflow, waitFor, volumeDescriptors, existingVolumesInCG, cgURI);
            }
            List<BlockSnapshotSession> sessions = getSnapSessionsForCGVolume(existingVolumesInCG.get(0));
            boolean isExistingCGSnapShotAvailable = checkIfCGHasSnapshotReplica(existingVolumesInCG);
            boolean isExistingCGSnapSessionAvailable = sessions != null && !sessions.isEmpty();
            boolean isVMAX3ExistingVolume = ControllerUtils.isVmaxVolumeUsing803SMIS(existingVolumesInCG.get(0), _dbClient);
            List<URI> volumeListtoAddURIs = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
            List<Volume> volumeListToAdd = ControllerUtils.queryVolumesByIterativeQuery(_dbClient, volumeListtoAddURIs);
            if (isVMAX3ExistingVolume) {
                if (isVMAX3VolumeHasSessionOnly(isExistingCGSnapSessionAvailable, isExistingCGSnapShotAvailable)) {
                    log.info("Existing CG only has Snap Session, adding snap session steps for adding volumes");
                    processSnapSessions(existingVolumesInCG, workflow, waitFor, volumeListToAdd);
                } else if (isVMAX3VolumeHasSnapshotOnly(isExistingCGSnapSessionAvailable, isExistingCGSnapShotAvailable)) {
                    // create new snapshots for the newly added volumes
                    // add the created snapshots to snapshot groups
                    Set<String> snapGroupNames = ControllerUtils.getSnapshotReplicationGroupNames(existingVolumesInCG, _dbClient);
                    for (String snapGroupName : snapGroupNames) {
                        // we can use the same storage system as RG--> CG is 1:1 mapping
                        log.info("Existing CG only has Snapshots, adding snapshot steps for existing snap group {} adding volumes", snapGroupName);
                        waitFor = addSnapshotsToReplicationGroupStep(workflow, waitFor, storageSystem, volumeListToAdd, snapGroupName, cgURI);
                    }
                } else if (isVMAX3VolumeHasSessionAndSnapshot(isExistingCGSnapSessionAvailable, isExistingCGSnapShotAvailable)) {
                    log.info("Existing CG has both Sessions and linked targets, adding snapshot and session steps");
                    processSnapSessionsAndLinkedTargets(existingVolumesInCG, workflow, waitFor, volumeListToAdd, cgURI);
                }
            } else if (isExistingCGSnapShotAvailable) {
                // non VMAX3 volume
                log.info("Adding snapshot steps for adding volumes");
                // create new snapshots for the newly added volumes
                // add the created snapshots to snapshot groups
                Set<String> snapGroupNames = ControllerUtils.getSnapshotReplicationGroupNames(existingVolumesInCG, _dbClient);
                for (String snapGroupName : snapGroupNames) {
                    waitFor = addSnapshotsToReplicationGroupStep(workflow, waitFor, storageSystem, volumeListToAdd, snapGroupName, cgURI);
                }
            }
        }
    }
    return waitFor;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 62 with BlockSnapshotSession

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

the class ReplicaDeviceController method processSnapSessions.

private String processSnapSessions(List<Volume> existingVolumesInCG, Workflow workflow, String waitFor, List<Volume> volumesToAdd) {
    // Get # of existing sessions for RG volumes, and create session for new volumes for every existing session
    Volume existingVolume = existingVolumesInCG.get(0);
    URI system = existingVolume.getStorageController();
    log.info("Processing RG {}", existingVolume.getReplicationGroupInstance());
    List<BlockSnapshotSession> sessions = getSnapSessionsForCGVolume(existingVolumesInCG.get(0));
    for (BlockSnapshotSession session : sessions) {
        log.info("Processing SnapSession {} for RG {}", session.getSessionLabel(), session.getReplicationGroupInstance());
        waitFor = createSnapshotSessionsStep(workflow, waitFor, system, volumesToAdd, existingVolume.getReplicationGroupInstance(), session);
    }
    return waitFor;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 63 with BlockSnapshotSession

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

the class ReplicaDeviceController method markSnapSessionsInactiveOrRemoveTargetId.

/**
 * A workflow step that
 * removes the given target ids from snap session object
 * if no target ids provided or the linked target set is empty after removing given targets, it marks the snap session inactive.
 *
 * @param snapSessionURI the snap session uri
 * @param targetIds the target ids
 * @param stepId -- Workflow Step Id.
 */
public void markSnapSessionsInactiveOrRemoveTargetId(URI snapSessionURI, List<URI> targetIds, String stepId) {
    try {
        BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
        StringSet linkedTargets = null;
        if (snapSession != null && !snapSession.getInactive()) {
            if (targetIds != null) {
                log.info("Removing target ids {} from snap session {}", Joiner.on(", ").join(targetIds), snapSession.getLabel());
                List<String> targets = newArrayList(transform(targetIds, FCTN_URI_TO_STRING));
                linkedTargets = snapSession.getLinkedTargets();
                if (linkedTargets != null) {
                    log.info("target ids present: {}", Joiner.on(", ").join(linkedTargets));
                    linkedTargets.removeAll(targets);
                }
            }
            if (targetIds == null || (linkedTargets == null || linkedTargets.isEmpty())) {
                log.info("Marking snap session in-active: {}", snapSession.getLabel());
                snapSession.setInactive(true);
            }
            _dbClient.updateObject(snapSession);
        }
    } finally {
        WorkflowStepCompleter.stepSucceded(stepId);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 64 with BlockSnapshotSession

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

the class ReplicaDeviceController method removeSnapshotsFromReplicationGroupStep.

private String removeSnapshotsFromReplicationGroupStep(final Workflow workflow, String waitFor, StorageSystem storageSystem, URI cgURI, List<URI> snapshots, String repGroupName) {
    log.info("START remove snapshot from CG steps");
    URI storage = storageSystem.getId();
    waitFor = workflow.createStep(BlockDeviceController.UPDATE_CONSISTENCY_GROUP_STEP_GROUP, String.format("Updating consistency group  %s", cgURI), waitFor, storage, _blockDeviceController.getDeviceType(storage), this.getClass(), removeFromReplicationGroupMethod(storage, cgURI, repGroupName, snapshots), _blockDeviceController.rollbackMethodNullMethod(), null);
    log.info(String.format("Step created for remove snapshots [%s] to group on device [%s]", Joiner.on("\t").join(snapshots), storage));
    BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshots.get(0));
    Volume sourceVol = _dbClient.queryObject(Volume.class, snap.getParent());
    // delete replication group from array if no more snapshots in the group.
    boolean rgHasNoOtherSnapshot = ControllerUtils.replicationGroupHasNoOtherSnapshot(_dbClient, repGroupName, snapshots, storage);
    if (rgHasNoOtherSnapshot) {
        log.info(String.format("Adding step to delete the replication group %s", repGroupName));
        String sourceRepGroupName = sourceVol.getReplicationGroupInstance();
        waitFor = workflow.createStep(BlockDeviceController.DELETE_GROUP_STEP_GROUP, String.format("Deleting replication group  %s", repGroupName), waitFor, storage, storageSystem.getSystemType(), BlockDeviceController.class, _blockDeviceController.deleteReplicationGroupMethod(storage, cgURI, ControllerUtils.extractGroupName(repGroupName), true, false, sourceRepGroupName), _blockDeviceController.rollbackMethodNullMethod(), null);
    }
    // get snap session associated if any
    List<BlockSnapshotSession> sessions = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(snap.getId()));
    Iterator<BlockSnapshotSession> itr = sessions.iterator();
    if (itr.hasNext()) {
        BlockSnapshotSession session = itr.next();
        // add step to remove target ids from snap session object
        // snap session will be marked inactive when removing last target
        waitFor = workflow.createStep(MARK_SNAP_SESSIONS_INACTIVE_OR_REMOVE_TARGET_ID, String.format("marking snap session %s inactive or removing target ids", session.getLabel()), waitFor, storage, _blockDeviceController.getDeviceType(storage), this.getClass(), markSnapSessionInactiveOrRemoveTargetIdsMethod(session.getId(), snapshots), _blockDeviceController.rollbackMethodNullMethod(), null);
    }
    return waitFor;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 65 with BlockSnapshotSession

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

the class ReplicaDeviceController method prepareSnapshotSessionFromSource.

public BlockSnapshotSession prepareSnapshotSessionFromSource(BlockObject sourceObj, BlockSnapshotSession existingSession) {
    BlockSnapshotSession snapSession = new BlockSnapshotSession();
    URI sourceProject = ControllerUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
    snapSession.setId(URIUtil.createId(BlockSnapshotSession.class));
    snapSession.setProject(new NamedURI(sourceProject, sourceObj.getLabel()));
    snapSession.setStorageController(sourceObj.getStorageController());
    snapSession.setParent(new NamedURI(sourceObj.getId(), sourceObj.getLabel()));
    // session label should be same as group session's label
    String sessionLabel = existingSession.getSessionLabel();
    // append source object name to session label to uniquely identify this session from RG session
    String instanceLabel = String.format("%s-%s", existingSession.getLabel(), sourceObj.getLabel());
    snapSession.setLabel(instanceLabel);
    snapSession.setSessionLabel(ResourceOnlyNameGenerator.removeSpecialCharsForName(sessionLabel, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH));
    _dbClient.createObject(snapSession);
    return snapSession;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) NamedURI(com.emc.storageos.db.client.model.NamedURI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

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