Search in sources :

Example 11 with BlockSnapshotSession

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

the class VolumeGroupService method getVolumeGroupSnapshotSessions.

/**
 * List snapshot sessions for a volume group
 *
 * @param volumeGroupId The URI of the volume group.
 * @brief List snapshot session for a volume group
 * @return BlockSnapshotSessionList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshot-sessions")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public BlockSnapshotSessionList getVolumeGroupSnapshotSessions(@PathParam("id") final URI volumeGroupId) {
    ArgValidator.checkFieldUriType(volumeGroupId, VolumeGroup.class, ID_FIELD);
    // query volume group
    final VolumeGroup volumeGroup = (VolumeGroup) queryResource(volumeGroupId);
    // get the snapshot sessions for each CG in the volume group
    BlockSnapshotSessionList snapshotSessionList = new BlockSnapshotSessionList();
    // get all snapshot sessions for the volume group
    List<BlockSnapshotSession> volumeGroupSessions = getVolumeGroupSnapshotSessions(volumeGroup);
    for (BlockSnapshotSession session : volumeGroupSessions) {
        snapshotSessionList.getSnapSessionRelatedResourceList().add(toNamedRelatedResource(session));
    }
    return snapshotSessionList;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with BlockSnapshotSession

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

the class BlockSnapIngestOrchestrator method ingestBlockObjects.

@Override
public <T extends BlockObject> T ingestBlockObjects(IngestionRequestContext requestContext, Class<T> clazz) throws IngestionException {
    UnManagedVolume unManagedVolume = requestContext.getCurrentUnmanagedVolume();
    boolean unManagedVolumeExported = requestContext.getVolumeContext().isVolumeExported();
    BlockSnapshot snapShot = null;
    String snapNativeGuid = unManagedVolume.getNativeGuid().replace(NativeGUIDGenerator.UN_MANAGED_VOLUME, NativeGUIDGenerator.VOLUME);
    snapShot = VolumeIngestionUtil.checkSnapShotExistsInDB(snapNativeGuid, _dbClient);
    // Check if ingested volume has exportmasks pending for ingestion.
    if (isExportIngestionPending(snapShot, unManagedVolume.getId(), unManagedVolumeExported)) {
        return clazz.cast(snapShot);
    }
    if (null == snapShot) {
        // @TODO Need to revisit this. In 8.x provider, Replication Group is
        // automatically created when a volume is associated to a
        // StorageGroup.
        // checkUnManagedVolumeAddedToCG(unManagedVolume, virtualArray,
        // tenant, project, vPool);
        checkVolumeExportState(unManagedVolume, unManagedVolumeExported);
        VolumeIngestionUtil.checkUnManagedResourceIngestable(unManagedVolume);
        snapShot = createSnapshot(requestContext, snapNativeGuid);
        // See if this is a linked target for existing block snapshot sessions.
        if (!NullColumnValueGetter.isNullValue(snapShot.getSettingsInstance())) {
            URIQueryResultList queryResults = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotSessionBySessionInstance(snapShot.getSettingsInstance()), queryResults);
            Iterator<URI> queryResultsIter = queryResults.iterator();
            while (queryResultsIter.hasNext()) {
                BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, queryResultsIter.next());
                StringSet linkedTargets = snapSession.getLinkedTargets();
                if ((linkedTargets != null)) {
                    linkedTargets.add(snapShot.getId().toString());
                } else {
                    linkedTargets = new StringSet();
                    linkedTargets.add(snapShot.getId().toString());
                    snapSession.setLinkedTargets(linkedTargets);
                }
                _dbClient.updateObject(snapSession);
            }
        }
    }
    // Run this logic always when Volume is NO_PUBLIC_ACCESS
    if (markUnManagedVolumeInactive(requestContext, snapShot)) {
        _logger.info("All the related replicas and parent of unManagedVolume {} has been ingested ", unManagedVolume.getNativeGuid());
        // mark inactive if this is not to be exported. Else, mark as inactive after successful export
        if (!unManagedVolumeExported) {
            unManagedVolume.setInactive(true);
            requestContext.getUnManagedVolumesToBeDeleted().add(unManagedVolume);
        }
    } else {
        _logger.info("Not all the parent/replicas of unManagedVolume {} have been ingested , hence marking as internal", unManagedVolume.getNativeGuid());
        snapShot.addInternalFlags(INTERNAL_VOLUME_FLAGS);
    }
    return clazz.cast(snapShot);
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 13 with BlockSnapshotSession

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

the class BlockVolumeIngestOrchestrator method ingestBlockObjects.

@Override
protected <T extends BlockObject> T ingestBlockObjects(IngestionRequestContext requestContext, Class<T> clazz) throws IngestionException {
    UnManagedVolume unManagedVolume = requestContext.getCurrentUnmanagedVolume();
    boolean unManagedVolumeExported = requestContext.getVolumeContext().isVolumeExported();
    Volume volume = null;
    List<BlockSnapshotSession> snapSessions = new ArrayList<BlockSnapshotSession>();
    URI unManagedVolumeUri = unManagedVolume.getId();
    String volumeNativeGuid = unManagedVolume.getNativeGuid().replace(VolumeIngestionUtil.UNMANAGEDVOLUME, VolumeIngestionUtil.VOLUME);
    volume = VolumeIngestionUtil.checkIfVolumeExistsInDB(volumeNativeGuid, _dbClient);
    // Check if ingested volume has export masks pending for ingestion.
    if (isExportIngestionPending(volume, unManagedVolumeUri, unManagedVolumeExported)) {
        return clazz.cast(volume);
    }
    if (null == volume) {
        validateUnManagedVolume(unManagedVolume, requestContext.getVpool(unManagedVolume));
        // @TODO Need to revisit this. In 8.x Provider, ReplicationGroup is automatically created when a volume is associated to a
        // StorageGroup.
        // checkUnManagedVolumeAddedToCG(unManagedVolume, virtualArray, tenant, project, vPool);
        checkVolumeExportState(unManagedVolume, unManagedVolumeExported);
        checkVPoolValidForExportInitiatorProtocols(requestContext.getVpool(unManagedVolume), unManagedVolume);
        checkHostIOLimits(requestContext.getVpool(unManagedVolume), unManagedVolume, unManagedVolumeExported);
        StoragePool pool = validateAndReturnStoragePoolInVAarray(unManagedVolume, requestContext.getVarray(unManagedVolume));
        // validate quota is exceeded for storage systems and pools
        checkSystemResourceLimitsExceeded(requestContext.getStorageSystem(), unManagedVolume, requestContext.getExhaustedStorageSystems());
        checkPoolResourceLimitsExceeded(requestContext.getStorageSystem(), pool, unManagedVolume, requestContext.getExhaustedPools());
        String autoTierPolicyId = getAutoTierPolicy(unManagedVolume, requestContext.getStorageSystem(), requestContext.getVpool(unManagedVolume));
        validateAutoTierPolicy(autoTierPolicyId, unManagedVolume, requestContext.getVpool(unManagedVolume));
        volume = createVolume(requestContext, volumeNativeGuid, pool, unManagedVolume, autoTierPolicyId);
    }
    if (volume != null) {
        String syncActive = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.IS_SYNC_ACTIVE.toString(), unManagedVolume.getVolumeInformation());
        boolean isSyncActive = (null != syncActive) ? Boolean.parseBoolean(syncActive) : false;
        volume.setSyncActive(isSyncActive);
        if (VolumeIngestionUtil.isFullCopy(unManagedVolume)) {
            _logger.info("Setting clone related properties {}", unManagedVolume.getId());
            String replicaState = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.REPLICA_STATE.toString(), unManagedVolume.getVolumeInformation());
            volume.setReplicaState(replicaState);
            String replicationGroupName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.FULL_COPY_CONSISTENCY_GROUP_NAME.toString(), unManagedVolume.getVolumeInformation());
            if (replicationGroupName != null && !replicationGroupName.isEmpty()) {
                volume.setReplicationGroupInstance(replicationGroupName);
            }
        }
        // Create snapshot sessions for each synchronization aspect for the volume.
        StringSet syncAspectInfoForVolume = PropertySetterUtil.extractValuesFromStringSet(SupportedVolumeInformation.SNAPSHOT_SESSIONS.toString(), unManagedVolume.getVolumeInformation());
        if ((syncAspectInfoForVolume != null) && (!syncAspectInfoForVolume.isEmpty())) {
            Project project = requestContext.getProject();
            // If this is a vplex backend volume, then the front end project should be set as snapshot session's project
            if (requestContext instanceof VplexVolumeIngestionContext && VolumeIngestionUtil.isVplexBackendVolume(unManagedVolume)) {
                project = ((VplexVolumeIngestionContext) requestContext).getFrontendProject();
            }
            for (String syncAspectInfo : syncAspectInfoForVolume) {
                String[] syncAspectInfoComponents = syncAspectInfo.split(":");
                String syncAspectName = syncAspectInfoComponents[0];
                String syncAspectObjPath = syncAspectInfoComponents[1];
                // Make sure it is not already created.
                URIQueryResultList queryResults = new URIQueryResultList();
                _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotSessionBySessionInstance(syncAspectObjPath), queryResults);
                Iterator<URI> queryResultsIter = queryResults.iterator();
                if (!queryResultsIter.hasNext()) {
                    BlockSnapshotSession session = new BlockSnapshotSession();
                    session.setId(URIUtil.createId(BlockSnapshotSession.class));
                    session.setLabel(syncAspectName);
                    session.setSessionLabel(syncAspectName);
                    session.setParent(new NamedURI(volume.getId(), volume.getLabel()));
                    session.setProject(new NamedURI(project.getId(), project.getLabel()));
                    session.setStorageController(volume.getStorageController());
                    session.setSessionInstance(syncAspectObjPath);
                    StringSet linkedTargetURIs = new StringSet();
                    URIQueryResultList snapshotQueryResults = new URIQueryResultList();
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getBlockSnapshotBySettingsInstance(syncAspectObjPath), snapshotQueryResults);
                    Iterator<URI> snapshotQueryResultsIter = snapshotQueryResults.iterator();
                    while (snapshotQueryResultsIter.hasNext()) {
                        linkedTargetURIs.add(snapshotQueryResultsIter.next().toString());
                    }
                    session.setLinkedTargets(linkedTargetURIs);
                    session.setOpStatus(new OpStatusMap());
                    snapSessions.add(session);
                }
            }
            if (!snapSessions.isEmpty()) {
                _dbClient.createObject(snapSessions);
            }
        }
    }
    // Note that a VPLEX backend volume can also be a snapshot target volume.
    // When the VPLEX ingest orchestrator is executed, it gets the ingestion
    // strategy for the backend volume and executes it. If the backend volume
    // is both a snapshot and a VPLEX backend volume, this local volume ingest
    // strategy is invoked and a Volume instance will result. That is fine because
    // we need to represent that VPLEX backend volume. However, we also need a
    // BlockSnapshot instance to represent the snapshot target volume. Therefore,
    // if the unmanaged volume is also a snapshot target volume, we get and
    // execute the local snapshot ingest strategy to create this BlockSnapshot
    // instance and we add it to the created object list. Note that since the
    // BlockSnapshot is added to the created objects list and the Volume and
    // BlockSnapshot instance will have the same native GUID, we must be careful
    // about adding the Volume to the created object list in the VPLEX ingestion
    // strategy.
    BlockObject snapshot = null;
    if (VolumeIngestionUtil.isSnapshot(unManagedVolume)) {
        String strategyKey = ReplicationStrategy.LOCAL.name() + "_" + VolumeType.SNAPSHOT.name();
        IngestStrategy ingestStrategy = ingestStrategyFactory.getIngestStrategy(IngestStrategyEnum.getIngestStrategy(strategyKey));
        snapshot = ingestStrategy.ingestBlockObjects(requestContext, BlockSnapshot.class);
        requestContext.getBlockObjectsToBeCreatedMap().put(snapshot.getNativeGuid(), snapshot);
    }
    // Run this always when volume NO_PUBLIC_ACCESS
    if (markUnManagedVolumeInactive(requestContext, volume)) {
        _logger.info("All the related replicas and parent has been ingested ", unManagedVolume.getNativeGuid());
        // RP masks.
        if (!unManagedVolumeExported && !VolumeIngestionUtil.checkUnManagedResourceIsRecoverPointEnabled(unManagedVolume)) {
            unManagedVolume.setInactive(true);
            requestContext.getUnManagedVolumesToBeDeleted().add(unManagedVolume);
        }
    } else if (volume != null) {
        _logger.info("Not all the parent/replicas of unManagedVolume {} have been ingested , hence marking as internal", unManagedVolume.getNativeGuid());
        volume.addInternalFlags(INTERNAL_VOLUME_FLAGS);
        for (BlockSnapshotSession snapSession : snapSessions) {
            snapSession.addInternalFlags(INTERNAL_VOLUME_FLAGS);
        }
        _dbClient.updateObject(snapSessions);
    }
    return clazz.cast(volume);
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) NamedURI(com.emc.storageos.db.client.model.NamedURI) VplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.VplexVolumeIngestionContext) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Project(com.emc.storageos.db.client.model.Project) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 14 with BlockSnapshotSession

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

the class BlockSnapshotSessionUtils method volumeHasSnapshotSession.

/**
 * Determines if the passed volume has a snapshot session.
 *
 * @param volume A reference to the volume.
 * @param dbClient A reference to a database client.
 *
 * @return true if the volume has an active session, false otherwise.
 */
public static boolean volumeHasSnapshotSession(Volume volume, DbClient dbClient) {
    Constraint constraint = null;
    URI cgURI = volume.getConsistencyGroup();
    if (NullColumnValueGetter.isNullURI(cgURI)) {
        constraint = ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volume.getId());
    } else {
        constraint = ContainmentConstraint.Factory.getBlockSnapshotSessionByConsistencyGroup(cgURI);
    }
    List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, constraint);
    return !snapSessions.isEmpty();
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URI(java.net.URI)

Example 15 with BlockSnapshotSession

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

the class DefaultBlockSnapshotSessionApiImpl method validateRelinkSnapshotSessionTargets.

/**
 * {@inheritDoc}
 */
@Override
public void validateRelinkSnapshotSessionTargets(BlockObject snapSessionSourceObj, BlockSnapshotSession tgtSnapSession, Project project, List<URI> snapshotURIs, UriInfo uriInfo) {
    // Validate the project tenant.
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    ArgValidator.checkEntity(tenant, project.getTenantOrg().getURI(), false);
    // Verify the user is authorized.
    BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, BlockServiceUtils.getUserFromContext(_securityContext), _permissionsHelper);
    // Verify that each target is currently linked to a block
    // snapshot session of the same source.
    URI currentSnapSessionSourceURI = null;
    String currentSnapSessionSourceGroupName = null;
    for (URI snapshotURI : snapshotURIs) {
        BlockSnapshotSessionUtils.validateSnapshot(snapshotURI, uriInfo, _dbClient);
        List<BlockSnapshotSession> snaphotSessionsList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(snapshotURI));
        if (snaphotSessionsList.isEmpty()) {
            // The target is not linked to an active snapshot session.
            throw APIException.badRequests.relinkTargetNotLinkedToActiveSnapshotSession(snapshotURI.toString());
        }
        // A target can only be linked to a single session.
        BlockSnapshotSession snapshotSnapSession = snaphotSessionsList.get(0);
        if (snapshotSnapSession.hasConsistencyGroup()) {
            if (currentSnapSessionSourceURI == null) {
                currentSnapSessionSourceURI = snapshotSnapSession.getConsistencyGroup();
            } else if (!snapshotSnapSession.getConsistencyGroup().equals(currentSnapSessionSourceURI)) {
                // snapshot session of the same source.
                throw APIException.badRequests.relinkSnapshotSessionsNotOfSameSource();
            }
            // validate for source Replication Group since there can be multiple replication groups within a CG.
            if (currentSnapSessionSourceGroupName == null) {
                currentSnapSessionSourceGroupName = snapshotSnapSession.getReplicationGroupInstance();
            } else if (!currentSnapSessionSourceGroupName.equals(snapshotSnapSession.getReplicationGroupInstance())) {
                // snapshot session of the same source group.
                throw APIException.badRequests.relinkSnapshotSessionsNotOfSameSource();
            }
        } else {
            // as that for the other targets to be re-linked.
            if (currentSnapSessionSourceURI == null) {
                currentSnapSessionSourceURI = snapshotSnapSession.getParent().getURI();
            } else if (!snapshotSnapSession.getParent().getURI().equals(currentSnapSessionSourceURI)) {
                // snapshot session of the same source.
                throw APIException.badRequests.relinkSnapshotSessionsNotOfSameSource();
            }
        }
    }
    // All targets to be re-linked are linked to an active block snapshot
    // session of the same source. Now make sure target snapshot session
    // has this same source.
    URI tgtSnapSessionSourceURI = tgtSnapSession.hasConsistencyGroup() ? tgtSnapSession.getConsistencyGroup() : tgtSnapSession.getParent().getURI();
    if (!tgtSnapSessionSourceURI.equals(currentSnapSessionSourceURI)) {
        throw APIException.badRequests.relinkTgtSnapshotSessionHasDifferentSource(currentSnapSessionSourceURI.toString());
    }
    String tgtSnapSessionSourceGroupName = tgtSnapSession.getReplicationGroupInstance();
    if (NullColumnValueGetter.isNotNullValue(tgtSnapSessionSourceGroupName) && !tgtSnapSessionSourceGroupName.equals(currentSnapSessionSourceGroupName)) {
        throw APIException.badRequests.relinkTgtSnapshotSessionHasDifferentSource(currentSnapSessionSourceGroupName);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) 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