Search in sources :

Example 66 with BlockSnapshot

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

the class VPlexBlockSnapshotSessionApiImpl method validateUnlinkSnapshotSessionTargets.

/**
 * {@inheritDoc}
 */
@Override
public void validateUnlinkSnapshotSessionTargets(BlockSnapshotSession snapSession, BlockObject snapSessionSourceObj, Project project, Map<URI, Boolean> targetMap, UriInfo uriInfo) {
    URI sourceURI = snapSessionSourceObj.getId();
    if (URIUtil.isType(sourceURI, Volume.class)) {
        // Get the platform specific implementation for the source side
        // backend storage system and call the validation routine.
        Volume vplexVolume = (Volume) snapSessionSourceObj;
        BlockObject srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, true, _dbClient);
        BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolume.getStorageController());
        snapSessionImpl.validateUnlinkSnapshotSessionTargets(snapSession, srcSideBackendVolume, project, targetMap, uriInfo);
        // block operations on a non-VPLEX volume.
        for (Entry<URI, Boolean> targetEntry : targetMap.entrySet()) {
            URI snapshotURI = targetEntry.getKey();
            Boolean deleteTarget = targetEntry.getValue();
            if (Boolean.FALSE == deleteTarget) {
                // block operations on a non-VPLEX volume.
                throw APIException.badRequests.mustDeleteTargetsOnUnlinkForVPlex();
            } else {
                // Don't allow if there is a VPLEX volume built on the linked target volume.
                // The VPLEX volume must be deleted first.
                BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotURI);
                String snapshotNativeGuid = snapshot.getNativeGuid();
                List<Volume> volumesWithSameNativeGuid = CustomQueryUtility.getActiveVolumeByNativeGuid(_dbClient, snapshotNativeGuid);
                if (!volumesWithSameNativeGuid.isEmpty()) {
                    // There should only be one and it should be a backend volume for
                    // a VPLEX volume.
                    List<Volume> vplexVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, AlternateIdConstraint.Factory.getVolumeByAssociatedVolumesConstraint(volumesWithSameNativeGuid.get(0).getId().toString()));
                    throw APIException.badRequests.cantDeleteSnapshotExposedByVolume(snapshot.getLabel().toString(), vplexVolumes.get(0).getLabel());
                }
            }
        }
    } else {
        // so should never be called.
        throw APIException.methodNotAllowed.notSupportedForVplexVolumes();
    }
}
Also used : 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) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 67 with BlockSnapshot

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

the class BlockServiceUtils method checkForDuplicateArraySnapshotName.

/**
 * Checks if there are any native array snapshots with the requested name.
 *
 * @param requestedName A name requested for a new native array snapshot.
 * @param sourceURI The URI of the snapshot source.
 * @param dbClient A reference to a database client.
 */
public static void checkForDuplicateArraySnapshotName(String requestedName, URI sourceURI, DbClient dbClient) {
    // First ensure the requested snapshot name is no more than 63 characters in length.
    // If we remove special characters and truncate to 63 characters, this could lead
    // to invalid duplicate name exceptions (COP-14512). By restricting to 63 characters in total, this
    // won't happen.
    ArgValidator.checkFieldLengthMaximum(requestedName, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH, "snapshotName");
    // We need to check the BlockSnapshotSession instances created using
    // the new Create Snapshot Session service as it creates a native
    // array snapshot.
    String modifiedRequestedName = ResourceOnlyNameGenerator.removeSpecialCharsForName(requestedName, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH);
    List<BlockSnapshotSession> snapSessions = null;
    Volume sourceVolume = null;
    if (URIUtil.isType(sourceURI, Volume.class)) {
        sourceVolume = dbClient.queryObject(Volume.class, sourceURI);
    }
    if (sourceVolume != null && NullColumnValueGetter.isNotNullValue(sourceVolume.getReplicationGroupInstance())) {
        snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getBlockSnapshotSessionByConsistencyGroup(sourceVolume.getConsistencyGroup()));
    } else {
        snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(sourceURI));
    }
    for (BlockSnapshotSession snapSession : snapSessions) {
        if (modifiedRequestedName.equals(snapSession.getSessionLabel())) {
            throw APIException.badRequests.duplicateLabel(requestedName);
        }
    }
    // We also need to check BlockSnapshot instances created on the source
    // using the existing Create Snapshot service.
    List<BlockSnapshot> sourceSnapshots = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshot.class, ContainmentConstraint.Factory.getVolumeSnapshotConstraint(sourceURI));
    for (BlockSnapshot snapshot : sourceSnapshots) {
        if (modifiedRequestedName.equals(snapshot.getSnapsetLabel())) {
            throw APIException.badRequests.duplicateLabel(requestedName);
        }
    }
}
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)

Example 68 with BlockSnapshot

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

the class BlockServiceUtils method getNumNativeSnapshots.

/**
 * Gets the number of native array snapshots created for the source with
 * the passed URI.
 *
 * @param sourceURI The URI of the source.
 * @param dbClient A reference to a database client.
 *
 * @return The number of native array snapshots for the source.
 */
public static int getNumNativeSnapshots(URI sourceURI, DbClient dbClient) {
    // The number of native array snapshots is determined by the
    // number of BlockSnapshotSession instances created for the
    // source using new Create Snapshot Session service.
    List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(sourceURI));
    int numSnapshots = snapSessions.size();
    // Also, we must account for the native array snapshots associated
    // with the BlockSnapshot instances created using the existing Create
    // Block Snapshot service. These will be the BlockSnapshot instances
    // that are not a linked target for a BlockSnapshotSession instance.
    List<BlockSnapshot> sourceSnapshots = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshot.class, ContainmentConstraint.Factory.getVolumeSnapshotConstraint(sourceURI));
    for (BlockSnapshot snapshot : sourceSnapshots) {
        URIQueryResultList queryResults = new URIQueryResultList();
        dbClient.queryByConstraint(ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint(snapshot.getId()), queryResults);
        Iterator<URI> queryResultsIter = queryResults.iterator();
        if ((!queryResultsIter.hasNext()) && (TechnologyType.NATIVE.toString().equalsIgnoreCase(snapshot.getTechnologyType()))) {
            numSnapshots++;
        }
    }
    return numSnapshots;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 69 with BlockSnapshot

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

the class BlockServiceUtils method validateVMAX3ActiveSnapSessionsExists.

/**
 * For VMAX3, We can't create fullcopy/mirror when there are active snap sessions.
 *
 * @TODO remove this validation when provider add support for this.
 * @param sourceVolURI
 * @param dbClient
 */
public static void validateVMAX3ActiveSnapSessionsExists(URI sourceVolURI, DbClient dbClient, String replicaType) {
    URIQueryResultList queryResults = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeSnapshotConstraint(sourceVolURI), queryResults);
    Iterator<URI> queryResultsIter = queryResults.iterator();
    while (queryResultsIter.hasNext()) {
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, queryResultsIter.next());
        if ((snapshot != null) && (!snapshot.getInactive()) && (snapshot.getIsSyncActive())) {
            throw APIException.badRequests.noFullCopiesForVMAX3VolumeWithActiveSnapshot(replicaType);
        }
    }
    // Also check for snapshot sessions.
    List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(sourceVolURI));
    if (!snapSessions.isEmpty()) {
        throw APIException.badRequests.noFullCopiesForVMAX3VolumeWithActiveSnapshot(replicaType);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 70 with BlockSnapshot

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

the class ExportUtils method getBlockObjectsForMasks.

private static Map<String, BlockObject> getBlockObjectsForMasks(Collection<ExportMask> exportMasks, DbClient dbClient) {
    Map<String, BlockObject> blockObjects = new HashMap<String, BlockObject>();
    List<URI> masksURIs = getMaskVolumeURI(exportMasks);
    List<URI> volUris = new ArrayList<URI>();
    List<URI> snapUris = new ArrayList<URI>();
    for (URI uri : masksURIs) {
        if (URIUtil.isType(uri, BlockSnapshot.class)) {
            snapUris.add(uri);
        } else if (URIUtil.isType(uri, Volume.class)) {
            volUris.add(uri);
        }
    }
    Iterator<Volume> vols = dbClient.queryIterativeObjects(Volume.class, volUris, true);
    while (vols.hasNext()) {
        Volume vol = vols.next();
        blockObjects.put(vol.getId().toString(), vol);
    }
    Iterator<BlockSnapshot> snaps = dbClient.queryIterativeObjects(BlockSnapshot.class, snapUris, true);
    while (snaps.hasNext()) {
        BlockSnapshot snap = snaps.next();
        blockObjects.put(snap.getId().toString(), snap);
    }
    return blockObjects;
}
Also used : HashMap(java.util.HashMap) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Aggregations

BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)401 Volume (com.emc.storageos.db.client.model.Volume)215 URI (java.net.URI)209 ArrayList (java.util.ArrayList)112 NamedURI (com.emc.storageos.db.client.model.NamedURI)110 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)106 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)91 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)63 BlockObject (com.emc.storageos.db.client.model.BlockObject)63 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)55 CIMObjectPath (javax.cim.CIMObjectPath)51 StringSet (com.emc.storageos.db.client.model.StringSet)49 HashMap (java.util.HashMap)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)41 WBEMException (javax.wbem.WBEMException)38 Produces (javax.ws.rs.Produces)36 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)35 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)33 Path (javax.ws.rs.Path)33