Search in sources :

Example 86 with BlockSnapshotSession

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

the class SRDFBlockServiceApiImpl method checkForDelete.

/**
 * {@inheritDoc}
 *
 * @throws InternalException
 */
@Override
public <T extends DataObject> String checkForDelete(final T object, List<Class<? extends DataObject>> excludeTypes) throws InternalException {
    // The standard dependency checker really doesn't fly with SRDF because we need to determine
    // if we can do
    // a tear-down of the volume, and that tear-down involved cleaning up dependent
    // relationships.
    // So this will be a bit more manual and calculated. In order to determine if we can delete
    // this object,
    // we need to make sure:
    // 1. This device is a SOURCE device if the protection set is happy and healthy (this is
    // done before we get here)
    // 2. This device and all of the other devices don't have any block snapshots
    // 3. If the device isn't part of a healthy SRDF protection, then do a dependency check
    // Generate a list of dependencies, if there are any.
    Map<URI, URI> dependencies = new HashMap<URI, URI>();
    // Get all of the volumes associated with the volume
    List<URI> volumeIDs;
    // JIRA CTRL-266; perhaps we can improve this using DB indexes
    volumeIDs = Volume.fetchSRDFVolumes(_dbClient, object.getId());
    for (URI volumeID : volumeIDs) {
        Volume volume = _dbClient.queryObject(Volume.class, volumeID);
        if (volume == null || volume.getInactive()) {
            continue;
        }
        // Check for dependent snapshots.
        List<BlockSnapshot> snapshots = getSnapshotsForVolume(volume);
        for (BlockSnapshot snapshot : snapshots) {
            if (snapshot != null && !snapshot.getInactive()) {
                dependencies.put(volumeID, snapshot.getId());
            }
        }
        // Also check for snapshot sessions.
        for (BlockSnapshotSession snapshotSession : getSnapshotSessionsForVolume(volume)) {
            dependencies.put(volume.getId(), snapshotSession.getId());
        }
        if (!dependencies.isEmpty()) {
            throw APIException.badRequests.cannotDeleteVolumeBlockSnapShotExists(String.valueOf(dependencies));
        }
        // Because that can only have happened if the RDF relationship was already torn down.
        if (volumeIDs.size() == 1) {
            List<Class<? extends DataObject>> excludes = new ArrayList<Class<? extends DataObject>>();
            if (excludeTypes != null) {
                excludes.addAll(excludeTypes);
            }
            excludes.add(Task.class);
            String depMsg = _dependencyChecker.checkDependencies(object.getId(), object.getClass(), true, excludes);
            if (depMsg != null) {
                return depMsg;
            }
            return object.canBeDeleted();
        }
    }
    return null;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) Volume(com.emc.storageos.db.client.model.Volume)

Example 87 with BlockSnapshotSession

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

the class RPBlockServiceApiImpl method checkForDelete.

/**
 * {@inheritDoc}
 *
 * @throws InternalException
 */
@Override
public <T extends DataObject> String checkForDelete(T object, List<Class<? extends DataObject>> excludeTypes) throws InternalException {
    // The standard dependency checker really doesn't fly with RP because we need to determine if we can do
    // a tear-down of the volume, and that tear-down involved cleaning up dependent relationships.
    // So this will be a bit more manual and calculated. In order to determine if we can delete this object,
    // we need to make sure:
    // 1. This device is a SOURCE device if the protection set is happy and healthy (this is done before we get
    // here)
    // 2. This device and all of the other devices don't have any block snapshots
    // 3. If the device isn't part of a healthy protection set, then do a dependency check
    // Generate a list of dependencies, if there are any.
    Map<URI, URI> dependencies = new HashMap<URI, URI>();
    Volume sourceVolume = (Volume) object;
    // Get all of the snapshots associated with the volume
    for (BlockSnapshot snapshot : this.getSnapshotsForVolume(sourceVolume)) {
        if (snapshot != null && !snapshot.getInactive()) {
            dependencies.put(sourceVolume.getId(), snapshot.getId());
        }
        // Get all the snapshots of the corresponding target volumes
        if (Volume.PersonalityTypes.SOURCE.name().equals(sourceVolume.getPersonality())) {
            StringSet rpTargets = sourceVolume.getRpTargets();
            for (String rpTarget : rpTargets) {
                Volume rpTargetVolume = _dbClient.queryObject(Volume.class, URI.create(rpTarget));
                for (BlockSnapshot targetSnapshot : this.getSnapshotsForVolume(rpTargetVolume)) {
                    if (targetSnapshot != null && !targetSnapshot.getInactive()) {
                        dependencies.put(rpTargetVolume.getId(), targetSnapshot.getId());
                    }
                }
            }
        }
    }
    // Get all of the snapshot sessions associated with the volume
    for (BlockSnapshotSession snapshotSession : getSnapshotSessionsForVolume(sourceVolume)) {
        dependencies.put(sourceVolume.getId(), snapshotSession.getId());
    }
    // Get all the snapshot sessions of the corresponding target volumes
    if (Volume.PersonalityTypes.SOURCE.name().equals(sourceVolume.getPersonality())) {
        StringSet rpTargets = sourceVolume.getRpTargets();
        for (String rpTarget : rpTargets) {
            Volume rpTargetVolume = _dbClient.queryObject(Volume.class, URI.create(rpTarget));
            for (BlockSnapshotSession targetSnapshotSession : getSnapshotSessionsForVolume(rpTargetVolume)) {
                dependencies.put(rpTargetVolume.getId(), targetSnapshotSession.getId());
            }
        }
    }
    if (!dependencies.isEmpty()) {
        throw APIException.badRequests.cannotDeleteVolumeBlockSnapShotExists(String.valueOf(dependencies));
    }
    List<URI> volumeIDs = RPHelper.getReplicationSetVolumes((Volume) object, _dbClient);
    // down.
    if (volumeIDs.size() == 1) {
        List<Class<? extends DataObject>> excludes = new ArrayList<Class<? extends DataObject>>();
        if (excludeTypes != null) {
            excludes.addAll(excludeTypes);
        }
        excludes.add(Task.class);
        String depMsg = _dependencyChecker.checkDependencies(object.getId(), object.getClass(), true, excludes);
        if (depMsg != null) {
            return depMsg;
        }
        return object.canBeDeleted();
    }
    return null;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 88 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method restoreSnapshotSession.

/**
 * Restores the data on the array snapshot point-in-time copy represented by the
 * BlockSnapshotSession instance with the passed URI, to the snapshot session source
 * object.
 *
 * @param snapSessionURI The URI of the BlockSnapshotSession instance to be restored.
 *
 * @return TaskResourceRep representing the snapshot session task.
 */
public TaskResourceRep restoreSnapshotSession(URI snapSessionURI) {
    s_logger.info("START restore snapshot session {}", snapSessionURI);
    // Get the snapshot session.
    BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
    BlockObject snapSessionSourceObj = null;
    List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
    snapSessionSourceObj = snapSessionSourceObjs.get(0);
    // Get the project for the snapshot session source object.
    Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
    // Validate that the snapshot session can be restored.
    snapSessionApiImpl.validateRestoreSnapshotSession(snapSessionSourceObjs, project);
    // Create the task identifier.
    String taskId = UUID.randomUUID().toString();
    // Create the operation status entry in the status map for the snapshot.
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.RESTORE_SNAPSHOT_SESSION);
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
    snapSession.getOpStatus().put(taskId, op);
    TaskResourceRep resourceRep = toTask(snapSession, taskId);
    // Restore the snapshot session.
    try {
        snapSessionApiImpl.restoreSnapshotSession(snapSession, snapSessionSourceObjs.get(0), taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to restore snapshot session %s: %s", snapSessionURI, e.getMessage());
        ServiceCoded sc = null;
        if (e instanceof ServiceCoded) {
            sc = (ServiceCoded) e;
        } else {
            sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        }
        cleanupFailure(Lists.newArrayList(resourceRep), new ArrayList<DataObject>(), errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    auditOp(OperationTypeEnum.RESTORE_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObjs.get(0).getId().toString(), snapSessionSourceObjs.get(0).getStorageController().toString());
    s_logger.info("FINISH restore snapshot session {}", snapSessionURI);
    return resourceRep;
}
Also used : Project(com.emc.storageos.db.client.model.Project) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) BlockObject(com.emc.storageos.db.client.model.BlockObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 89 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method deleteSnapshotSession.

/**
 * Delete the snapshot session with the passed URI.
 *
 * @param snapSessionURI The URI of the BlockSnapshotSession instance.
 * @param deleteType The deletion type i.e, VIPR_ONLY or FULL
 *
 * @return TaskResourceRep representing the snapshot session task.
 */
public TaskList deleteSnapshotSession(URI snapSessionURI, String deleteType) {
    s_logger.info("START delete snapshot session {} of type {}", snapSessionURI, deleteType);
    // Get the snapshot session.
    BlockSnapshotSession snapSession = BlockSnapshotSessionUtils.querySnapshotSession(snapSessionURI, _uriInfo, _dbClient, true);
    BlockObject snapSessionSourceObj = null;
    List<BlockObject> snapSessionSourceObjs = getAllSnapshotSessionSources(snapSession);
    snapSessionSourceObj = snapSessionSourceObjs.get(0);
    // Get the project for the snapshot session source object.
    Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(snapSessionSourceObj, _dbClient);
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
    // Validate that the snapshot session can be deleted.
    snapSessionApiImpl.validateDeleteSnapshotSession(snapSession, snapSessionSourceObj, project);
    // Create the task identifier.
    String taskId = UUID.randomUUID().toString();
    TaskList taskList = new TaskList();
    Operation snapSessionOp = new Operation();
    snapSessionOp.setResourceType(getDeleteResourceOperationTypeEnum(snapSession));
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSession.getId(), taskId, snapSessionOp);
    snapSession.getOpStatus().put(taskId, snapSessionOp);
    taskList.addTask(toTask(snapSession, taskId, snapSessionOp));
    if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
        addConsistencyGroupTasks(snapSessionSourceObjs, taskList, taskId, getDeleteResourceOperationTypeEnum(snapSession));
    }
    // Delete the snapshot session.
    try {
        snapSessionApiImpl.deleteSnapshotSession(snapSession, snapSessionSourceObj, taskId, deleteType);
    } catch (Exception e) {
        String errorMsg = format("Failed to delete snapshot session %s: %s", snapSessionURI, e.getMessage());
        ServiceCoded sc = null;
        if (e instanceof ServiceCoded) {
            sc = (ServiceCoded) e;
        } else {
            sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
        }
        cleanupFailure(taskList.getTaskList(), new ArrayList<DataObject>(), errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    String opStage = VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType) ? null : AuditLogManager.AUDITOP_BEGIN;
    auditOp(OperationTypeEnum.DELETE_SNAPSHOT_SESSION, true, opStage, snapSessionURI.toString(), snapSessionURI.toString(), snapSessionSourceObj.getStorageController().toString());
    s_logger.info("FINISH delete snapshot session {}", snapSessionURI);
    return taskList;
}
Also used : Project(com.emc.storageos.db.client.model.Project) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) BlockObject(com.emc.storageos.db.client.model.BlockObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 90 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method getSnapshotSessionsForSource.

/**
 * Get the BlockSnapshotSession instances for the source object with the passed URI.
 *
 * @param sourceURI The URI of the snapshot session source object.
 *
 * @return A BlockSnapshotSessionList of the snapshot sessions for the source.
 */
public BlockSnapshotSessionList getSnapshotSessionsForSource(URI sourceURI) {
    // Get the snapshot session source object.
    BlockObject sourceObj = BlockSnapshotSessionUtils.querySnapshotSessionSource(sourceURI, _uriInfo, true, _dbClient);
    // Get the platform specific block snapshot session implementation.
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(sourceObj);
    // Get the BlockSnapshotSession instances for the source and prepare the result.
    List<BlockSnapshotSession> snapSessionsForSource = snapSessionApiImpl.getSnapshotSessionsForSource(sourceObj);
    BlockSnapshotSessionList result = new BlockSnapshotSessionList();
    for (BlockSnapshotSession snapSessionForSource : snapSessionsForSource) {
        result.getSnapSessionRelatedResourceList().add(toNamedRelatedResource(snapSessionForSource));
    }
    return result;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) BlockObject(com.emc.storageos.db.client.model.BlockObject)

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