Search in sources :

Example 56 with BlockSnapshotSession

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

the class BlockSnapshotSessionMigration method prepareSnapshotSession.

/**
 * Prepare the ViPR BlockSnapshotSession instance for the pass BlockSnapshot instance.
 *
 * @param snapshot A reference to the snapshot.
 *
 * @return A reference to the newly created snapshot session.
 */
private BlockSnapshotSession prepareSnapshotSession(BlockSnapshot snapshot) {
    s_logger.info("Prepare BlockSnapshotSession for snapshot {}", snapshot.getId());
    BlockSnapshotSession snapshotSession = new BlockSnapshotSession();
    URI snapSessionURI = URIUtil.createId(BlockSnapshotSession.class);
    snapshotSession.setId(snapSessionURI);
    snapshotSession.setSessionLabel(getSessionLabelFromSettingsInstance(snapshot));
    URI cgURI = snapshot.getConsistencyGroup();
    if (NullColumnValueGetter.isNullURI(cgURI)) {
        snapshotSession.setParent(snapshot.getParent());
        snapshotSession.setLabel(snapshot.getLabel());
    } else {
        snapshotSession.setConsistencyGroup(cgURI);
        snapshotSession.setLabel(snapshot.getSnapsetLabel());
        Volume parent = getDbClient().queryObject(Volume.class, snapshot.getParent());
        if (parent != null) {
            snapshotSession.setReplicationGroupInstance(parent.getReplicationGroupInstance());
            snapshotSession.setSessionSetName(parent.getReplicationGroupInstance());
        }
    }
    snapshotSession.setProject(snapshot.getProject());
    snapshotSession.setStorageController(snapshot.getStorageController());
    snapshotSession.setSessionInstance(snapshot.getSettingsInstance());
    StringSet linkedTargets = new StringSet();
    linkedTargets.add(snapshot.getId().toString());
    snapshotSession.setLinkedTargets(linkedTargets);
    return snapshotSession;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI)

Example 57 with BlockSnapshotSession

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

the class BlockDeviceController method deleteSnapshotSession.

/**
 * {@inheritDoc}
 */
@Override
public void deleteSnapshotSession(URI systemURI, URI snapSessionURI, String opId) {
    TaskCompleter completer = new BlockSnapshotSessionDeleteWorkflowCompleter(snapSessionURI, opId);
    try {
        // Get a new workflow delete the snapshot session.
        Workflow workflow = _workflowService.getNewWorkflow(this, DELETE_SNAPSHOT_SESSION_WF_NAME, false, opId);
        _log.info("Created new workflow to delete snapshot session {} with operation id {}", snapSessionURI, opId);
        // When deleting a group snapshot we need the name of the group.
        String groupName = null;
        boolean isCG = checkSnapshotSessionConsistencyGroup(snapSessionURI, _dbClient, completer);
        if (isCG) {
            BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
            groupName = snapSession.getReplicationGroupInstance();
        }
        // Create the workflow step to delete the snapshot session.
        workflow.createStep(DELETE_SNAPSHOT_SESSION_STEP_GROUP, String.format("Delete snapshot session %s", snapSessionURI), null, systemURI, getDeviceType(systemURI), getClass(), deleteBlockSnapshotSessionMethod(systemURI, snapSessionURI, groupName, Boolean.FALSE), null, null);
        // Execute the workflow.
        workflow.executePlan(completer, "Delete block snapshot session successful");
    } catch (Exception e) {
        _log.error("Delete block snapshot session failed", e);
        ServiceCoded serviceException = DeviceControllerException.exceptions.deleteBlockSnapshotSessionFailed(e);
        completer.error(_dbClient, serviceException);
    }
}
Also used : BlockSnapshotSessionDeleteWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionDeleteWorkflowCompleter) 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) 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 58 with BlockSnapshotSession

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

the class BlockDeviceController method unlinkTargetsFromSnapshotSession.

/**
 * {@inheritDoc}
 */
@Override
public void unlinkTargetsFromSnapshotSession(URI systemURI, URI snapSessionURI, Map<URI, Boolean> snapshotDeletionMap, OperationTypeEnum opType, String opId) {
    TaskCompleter completer = new BlockSnapshotSessionUnlinkTargetsWorkflowCompleter(snapSessionURI, opType, opId);
    try {
        // Get a new workflow to unlinking of the targets from session.
        Workflow workflow = _workflowService.getNewWorkflow(this, UNLINK_SNAPSHOT_SESSION_TARGETS_WF_NAME, false, opId);
        _log.info("Created new workflow to unlink targets for snapshot session {} with operation id {}", snapSessionURI, opId);
        Set<URI> targetKeys = snapshotDeletionMap.keySet();
        BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
        // For CG's, ensure 1 target per ReplicationGroup
        if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
            Iterator<BlockSnapshot> snapshots = _dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotDeletionMap.keySet());
            final Set<String> replicationGroups = new HashSet<>();
            final Map<URI, BlockSnapshot> uriToSnapshotCache = new HashMap<>();
            while (snapshots.hasNext()) {
                BlockSnapshot snapshot = snapshots.next();
                uriToSnapshotCache.put(snapshot.getId(), snapshot);
            }
            Map<URI, Boolean> filtered = Maps.filterEntries(snapshotDeletionMap, new Predicate<Map.Entry<URI, Boolean>>() {

                @Override
                public boolean apply(Map.Entry<URI, Boolean> input) {
                    BlockSnapshot blockSnapshot = uriToSnapshotCache.get(input.getKey());
                    String repGrpInstance = blockSnapshot.getReplicationGroupInstance();
                    if (replicationGroups.contains(repGrpInstance)) {
                        return false;
                    }
                    replicationGroups.add(repGrpInstance);
                    return true;
                }
            });
            // assign to targetKeys filtered keySet view of snapshotDeletionMap.
            targetKeys = filtered.keySet();
        }
        // TODO Use ModifyListSettingsDefineState here and remove the for-loop.
        String waitFor = null;
        // Create a workflow step to unlink each target specified in targetKeys
        for (URI snapshotURI : targetKeys) {
            waitFor = workflow.createStep(UNLINK_SNAPSHOT_SESSION_TARGET_STEP_GROUP, String.format("Unlinking target for snapshot session %s", snapSessionURI), waitFor, systemURI, getDeviceType(systemURI), getClass(), unlinkBlockSnapshotSessionTargetMethod(systemURI, snapSessionURI, snapshotURI, snapshotDeletionMap.get(snapshotURI)), null, null);
        }
        // Execute the workflow.
        workflow.executePlan(completer, "Unlink block snapshot session targets successful");
    } catch (Exception e) {
        _log.error("Unlink block snapshot session targets failed", e);
        ServiceCoded serviceException = DeviceControllerException.exceptions.unlinkBlockSnapshotSessionTargetsFailed(e);
        completer.error(_dbClient, serviceException);
    }
}
Also used : BlockSnapshotSessionUnlinkTargetsWorkflowCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotSessionUnlinkTargetsWorkflowCompleter) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Workflow(com.emc.storageos.workflow.Workflow) NamedURI(com.emc.storageos.db.client.model.NamedURI) FCTN_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ScanTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.ScanTaskCompleter) BlockSnapshotEstablishGroupTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter) BlockMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) ApplicationTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 59 with BlockSnapshotSession

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

the class BlockDeviceController method rollbackLinkBlockSnapshotSessionTarget.

/**
 * Rollback a failed attempt to link a target volume to the array snapshot.
 *
 * @param systemURI
 *            The URI of the storage system.
 * @param snapSessionURI
 *            The URI of the BlockSnapshotSession instance.
 * @param snapshotURI
 *            The URI of the BlockSnapshot instance.
 * @param stepId
 *            The unique id of the workflow step in which the rollback is executed.
 */
public void rollbackLinkBlockSnapshotSessionTarget(URI systemURI, URI snapSessionURI, URI snapshotURI, String stepId) {
    // We do not rollback successfully linked targets. If the target
    // was not successfully created and linked, it could in one of two
    // states. Either the target is not provisioned, or the target is
    // provisioned but not linked to the array snapshot. We call the
    // method to unlink the target and make sure the unlink target
    // algorithm accounts for these possibilities. Successfully linked
    // targets will be in the list of linked targets for the session.
    BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
    StringSet linkedTargets = snapSession.getLinkedTargets();
    if ((linkedTargets == null) || (!linkedTargets.contains(snapshotURI.toString()))) {
        unlinkBlockSnapshotSessionTarget(systemURI, snapSessionURI, snapshotURI, Boolean.TRUE, stepId);
    } else {
        WorkflowStepCompleter.stepSucceded(stepId);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 60 with BlockSnapshotSession

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

the class ReplicaDeviceController method deleteSnapshotSessionSteps.

/**
 * Remove all snapshot sessions from the volumes to be deleted.
 *
 * @param workflow
 * @param waitFor
 * @param volumes
 * @param isRemoveAllFromRG
 * @return
 */
private String deleteSnapshotSessionSteps(Workflow workflow, String waitFor, List<Volume> volumes, boolean isRemoveAllFromRG) {
    log.info("START delete snapshot session steps");
    if (!isRemoveAllFromRG) {
        log.info("Nothing to do");
        return waitFor;
    }
    URI storage = volumes.get(0).getStorageController();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
    Set<String> replicationGroupInstances = new HashSet<>();
    for (Volume volume : volumes) {
        replicationGroupInstances.add(volume.getReplicationGroupInstance());
    }
    for (String replicationGroupInstance : replicationGroupInstances) {
        Collection<BlockSnapshotSession> sessions = getSessionsForReplicationGroup(replicationGroupInstance, storage);
        for (BlockSnapshotSession session : sessions) {
            Workflow.Method deleteMethod = BlockDeviceController.deleteBlockSnapshotSessionMethod(storage, session.getId(), replicationGroupInstance, true);
            waitFor = workflow.createStep("RemoveSnapshotSessions", "Remove Snapshot Session", waitFor, storage, storageSystem.getSystemType(), BlockDeviceController.class, deleteMethod, null, null);
        }
    }
    return waitFor;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) Workflow(com.emc.storageos.workflow.Workflow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

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