Search in sources :

Example 46 with BlockSnapshotSession

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

the class BlockSnapshotSessionMigrationTest method verifySingleSnapshotResults.

/**
 * Verifies the migration results for single volume snapshots.
 */
private void verifySingleSnapshotResults() {
    List<URI> snapSessionURIs = _dbClient.queryByType(BlockSnapshotSession.class, true);
    Iterator<BlockSnapshotSession> snapSessionsIter = _dbClient.queryIterativeObjects(BlockSnapshotSession.class, snapSessionURIs, true);
    Assert.assertTrue("Did not find any snapshot sessions after migration", snapSessionsIter.hasNext());
    int sessionCount = 0;
    while (snapSessionsIter.hasNext()) {
        BlockSnapshotSession snapSession = snapSessionsIter.next();
        // Process single volume snapshot sessions.
        if (NullColumnValueGetter.isNullURI(snapSession.getConsistencyGroup())) {
            sessionCount++;
            Assert.assertNotNull("Snapshot session is null", snapSession);
            StringSet linkedTargets = snapSession.getLinkedTargets();
            Assert.assertNotNull("Snapshot session linked targets list is null", snapSession);
            Assert.assertFalse("Snapshot session linked targets list is empty", linkedTargets.isEmpty());
            Assert.assertEquals("Snapshot session does not have a singled linked target", linkedTargets.size(), 1);
            String linkedTargetId = linkedTargets.iterator().next();
            Assert.assertTrue("Snapshot session linked target not in linked targets map", _linkedTargetsMap.containsKey(linkedTargetId));
            BlockSnapshot linkedTarget = _linkedTargetsMap.remove(linkedTargetId);
            Assert.assertEquals("Label is not correct", linkedTarget.getLabel(), snapSession.getLabel());
            Assert.assertEquals("Session label is not correct", "elementName", snapSession.getSessionLabel());
            Assert.assertEquals("Session instance is not correct", linkedTarget.getSettingsInstance(), snapSession.getSessionInstance());
            Assert.assertEquals("Project is not correct", linkedTarget.getProject(), snapSession.getProject());
            Assert.assertEquals("Parent is not correct", linkedTarget.getParent(), snapSession.getParent());
        }
    }
    // Get the single volume snapshots in the database.
    // Note: Don't use List#size() as it is not supported by the derived
    // List class returned by the DB client.
    int svSnapshotCount = 0;
    List<URI> snapshotURIs = _dbClient.queryByType(BlockSnapshot.class, true);
    Iterator<BlockSnapshot> snapshotsIter = _dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotURIs);
    while (snapshotsIter.hasNext()) {
        BlockSnapshot snapshot = snapshotsIter.next();
        if (NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
            svSnapshotCount++;
        }
    }
    Assert.assertEquals("Snapshot count is not correct", svSnapshotCount, SNAPVX_SNAPSHOT_COUNT + SNAPSHOT_COUNT);
    Assert.assertEquals("Snapshot session count is not correct", sessionCount, SNAPVX_SNAPSHOT_COUNT);
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 47 with BlockSnapshotSession

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

the class SRDFUtils method CheckIfVolumeHasReplica.

/**
 * Checks if a volume has snapshot, snapshot session, or clone or mirror associated.
 */
private boolean CheckIfVolumeHasReplica(Volume volume) {
    boolean forceAdd = false;
    URI volumeURI = volume.getId();
    URIQueryResultList list = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(volumeURI), list);
    Iterator<URI> it = list.iterator();
    while (it.hasNext()) {
        URI snapshotID = it.next();
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotID);
        if (snapshot != null) {
            log.debug("There are Snapshot(s) available for volume {}", volumeURI);
            forceAdd = true;
            break;
        }
    }
    // Check snapshot sessions also.
    if (!forceAdd) {
        List<BlockSnapshotSession> snapSessions = queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volumeURI));
        if (!snapSessions.isEmpty()) {
            log.debug("There are snapshot sessions available on volume {}", volumeURI);
            forceAdd = true;
        }
    }
    if (!forceAdd) {
        // TODO ignore DETACHED clones?
        URIQueryResultList cloneList = new URIQueryResultList();
        dbClient.queryByConstraint(ContainmentConstraint.Factory.getAssociatedSourceVolumeConstraint(volumeURI), cloneList);
        Iterator<URI> iter = cloneList.iterator();
        while (iter.hasNext()) {
            URI cloneID = iter.next();
            Volume clone = dbClient.queryObject(Volume.class, cloneID);
            if (clone != null) {
                log.debug("There are Clone(s) available for volume {}", volumeURI);
                forceAdd = true;
                break;
            }
        }
    }
    if (!forceAdd) {
        URIQueryResultList mirrorList = new URIQueryResultList();
        dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeBlockMirrorConstraint(volumeURI), mirrorList);
        Iterator<URI> itr = mirrorList.iterator();
        while (itr.hasNext()) {
            URI mirrorID = itr.next();
            BlockMirror mirror = dbClient.queryObject(BlockMirror.class, mirrorID);
            if (mirror != null) {
                log.debug("There are Mirror(s) available for volume {}", volumeURI);
                forceAdd = true;
                break;
            }
        }
    }
    return forceAdd;
}
Also used : BlockMirror(com.emc.storageos.db.client.model.BlockMirror) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 48 with BlockSnapshotSession

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

the class BlockSnapshotSessionMigration method process.

/**
 * {@inheritDoc}
 */
@Override
public void process() throws MigrationCallbackException {
    s_logger.info("Executing BlockSnapshotSession migration callback.");
    try {
        DbClient dbClient = getDbClient();
        List<BlockSnapshotSession> snapshotSessions = new ArrayList<BlockSnapshotSession>();
        Map<URI, Map<String, BlockSnapshotSession>> groupSessionMap = new HashMap<>();
        List<URI> snapshotURIs = dbClient.queryByType(BlockSnapshot.class, true);
        Iterator<BlockSnapshot> snapshotsIter = dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotURIs, true);
        while (snapshotsIter.hasNext()) {
            BlockSnapshot snapshot = snapshotsIter.next();
            if (isSnapshotSessionSupported(snapshot)) {
                // Check if this is a group snapshot.
                URI cgURI = snapshot.getConsistencyGroup();
                if (NullColumnValueGetter.isNullURI(cgURI)) {
                    // The storage system for the single volume snapshot supports
                    // snapshot sessions, then we need to prepare and create a
                    // snapshot session for that snapshot and add the snapshot as
                    // a linked target for the session.
                    BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
                    snapshotSessions.add(snapshotSession);
                } else {
                    // Create the group session if necessary and add the snapshot as a
                    // linked target for that group session.
                    String settingsInstance = snapshot.getSettingsInstance();
                    Map<String, BlockSnapshotSession> grpSnapshotSessions = groupSessionMap.get(cgURI);
                    if (grpSnapshotSessions != null) {
                        BlockSnapshotSession snapshotSession = grpSnapshotSessions.get(settingsInstance);
                        if (snapshotSession == null) {
                            snapshotSession = prepareSnapshotSession(snapshot);
                            grpSnapshotSessions.put(settingsInstance, snapshotSession);
                            snapshotSessions.add(snapshotSession);
                        } else {
                            StringSet linkedTargets = snapshotSession.getLinkedTargets();
                            linkedTargets.add(snapshot.getId().toString());
                        }
                    } else {
                        grpSnapshotSessions = new HashMap<String, BlockSnapshotSession>();
                        groupSessionMap.put(cgURI, grpSnapshotSessions);
                        BlockSnapshotSession snapshotSession = prepareSnapshotSession(snapshot);
                        grpSnapshotSessions.put(settingsInstance, snapshotSession);
                        snapshotSessions.add(snapshotSession);
                    }
                }
            }
        }
        if (!snapshotSessions.isEmpty()) {
            dbClient.createObject(snapshotSessions);
        }
    } catch (Exception e) {
        s_logger.error("Caught exception during BlockSnapshotSession migration", e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 49 with BlockSnapshotSession

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

the class BlockSnapshotSessionsDataTable method fetch.

public static List<BlockSnapshotSession> fetch(URI projectId) {
    if (projectId == null) {
        return Collections.emptyList();
    }
    ViPRCoreClient client = getViprClient();
    List<BlockSnapshotSessionRestRep> blockSnapshots = client.blockSnapshotSessions().findByProject(projectId);
    Map<URI, VolumeRestRep> parentVolumes = getParentVolumes(blockSnapshots);
    List<BlockSnapshotSession> results = Lists.newArrayList();
    for (BlockSnapshotSessionRestRep blockSnapshot : blockSnapshots) {
        BlockSnapshotSession snap = new BlockSnapshotSession(blockSnapshot);
        // Get the parent volume of the snapshot
        VolumeRestRep volume = parentVolumes.get(ResourceUtils.id(blockSnapshot.getParent()));
        snap.volume = ResourceUtils.name(volume);
        results.add(snap);
    }
    return results;
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) BlockSnapshotSessionRestRep(com.emc.storageos.model.block.BlockSnapshotSessionRestRep) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) VolumeRestRep(com.emc.storageos.model.block.VolumeRestRep) URI(java.net.URI)

Example 50 with BlockSnapshotSession

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

the class BlockDeviceController method addStepsForCreateSnapshotSession.

/**
 * @param workflow
 * @param waitFor
 * @param volumeDescriptors
 * @param taskId
 * @return
 */
public String addStepsForCreateSnapshotSession(Workflow workflow, String waitFor, List<VolumeDescriptor> volumeDescriptors, String taskId) {
    List<VolumeDescriptor> blockVolmeDescriptors = VolumeDescriptor.filterByType(volumeDescriptors, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_SNAPSHOT_SESSION }, new VolumeDescriptor.Type[] {});
    // If no volumes to create, just return
    if (blockVolmeDescriptors.isEmpty()) {
        return waitFor;
    }
    // we expect just one snapshot session volume descriptor
    VolumeDescriptor descriptor = blockVolmeDescriptors.get(0);
    BlockSnapshotSession session = _dbClient.queryObject(BlockSnapshotSession.class, descriptor.getVolumeURI());
    if (session != null && !session.getInactive()) {
        String stepId = workflow.createStepId();
        // Now add the steps to create the snapshot session on the storage system
        URI storageURI = session.getStorageController();
        StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageURI);
        Workflow.Method createSnapshotSessionMethod = new Workflow.Method(METHOD_CREATE_SNAPSHOT_SESSION_STEP, storageURI, descriptor.getVolumeURI(), descriptor.getSnapSessionSnapshotURIs(), descriptor.getCapabilitiesValues().getSnapshotSessionCopyMode());
        Workflow.Method nullRollbackMethod = new Workflow.Method(ROLLBACK_METHOD_NULL);
        waitFor = workflow.createStep(SNAPSHOT_SESSION_CREATE_ORCHESTRATION_STEP, "Create Block Snapshot Session", waitFor, storageSystem.getId(), storageSystem.getSystemType(), this.getClass(), createSnapshotSessionMethod, nullRollbackMethod, stepId);
        _log.info(String.format("Added %s step [%s] in workflow", SNAPSHOT_SESSION_CREATE_STEP_GROUP, stepId));
    }
    return waitFor;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

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