Search in sources :

Example 21 with BlockSnapshotSession

use of com.emc.storageos.db.client.model.BlockSnapshotSession 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 22 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method relinkTargetVolumesToSnapshotSession.

/**
 * Implements a request to relink the passed targets from the
 * BlockSnapshotSession instance with the passed URI.
 *
 * @param snapSessionURI The URI of a BlockSnapshotSession instance.
 * @param param The linked target information.
 *
 * @return A TaskList.
 */
public TaskList relinkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionRelinkTargetsParam param) {
    s_logger.info("START relink targets to 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);
    // Get the platform specific block snapshot session implementation.
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(snapSessionSourceObj);
    // Get the target information.
    List<URI> linkedTargetURIs = param.getLinkedTargetIds();
    // Validate that the requested targets can be re-linked to the snapshot session.
    snapSessionApiImpl.validateRelinkSnapshotSessionTargets(snapSessionSourceObj, snapSession, project, linkedTargetURIs, _uriInfo);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    // Create a task for the snapshot session.
    Operation op = new Operation();
    op.setResourceType(getRelinkResourceOperationTypeEnum(snapSession));
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
    snapSession.getOpStatus().put(taskId, op);
    TaskResourceRep response = toTask(snapSession, taskId);
    TaskList taskList = new TaskList();
    taskList.addTask(response);
    // Re-link the targets to the snapshot session.
    try {
        snapSessionApiImpl.relinkTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, linkedTargetURIs, taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to relink targets to 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(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    auditOp(OperationTypeEnum.RELINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
    s_logger.info("FINISH relink targets to snapshot session {}", snapSessionURI);
    return taskList;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 23 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method unlinkTargetVolumesFromSnapshotSession.

/**
 * Implements a request to unlink the passed targets from the
 * BlockSnapshotSession instance with the passed URI.
 *
 * @param snapSessionURI The URI of a BlockSnapshotSession instance.
 * @param param The linked target information.
 * @param opType The operation type for the audit and event logs.
 *
 * @return A TaskResourceRep.
 */
public TaskResourceRep unlinkTargetVolumesFromSnapshotSession(URI snapSessionURI, SnapshotSessionUnlinkTargetsParam param, OperationTypeEnum opType) {
    s_logger.info("START unlink targets from 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);
    // Get the target information.
    Map<URI, Boolean> targetMap = new HashMap<>();
    for (SnapshotSessionUnlinkTargetParam targetInfo : param.getLinkedTargets()) {
        URI targetURI = targetInfo.getId();
        Boolean deleteTarget = targetInfo.getDeleteTarget();
        if (deleteTarget == null) {
            deleteTarget = Boolean.FALSE;
        }
        targetMap.put(targetURI, deleteTarget);
    }
    // Validate that the requested targets can be unlinked from the snapshot session.
    snapSessionApiImpl.validateUnlinkSnapshotSessionTargets(snapSession, snapSessionSourceObj, project, targetMap, _uriInfo);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    // Create a task for the snapshot session.
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.UNLINK_SNAPSHOT_SESSION_TARGETS);
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
    snapSession.getOpStatus().put(taskId, op);
    TaskResourceRep response = toTask(snapSession, taskId);
    // Unlink the targets from the snapshot session.
    try {
        snapSessionApiImpl.unlinkTargetVolumesFromSnapshotSession(snapSessionSourceObj, snapSession, targetMap, opType, taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to unlink targets from 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(Arrays.asList(response), new ArrayList<DataObject>(), errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    auditOp(opType, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
    s_logger.info("FINISH unlink targets from snapshot session {}", snapSessionURI);
    return response;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) SnapshotSessionUnlinkTargetParam(com.emc.storageos.model.block.SnapshotSessionUnlinkTargetParam) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 24 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method linkTargetVolumesToSnapshotSession.

/**
 * Implements a request to create and link new target volumes to the
 * BlockSnapshotSession instance with the passed URI.
 *
 * @param snapSessionURI The URI of a BlockSnapshotSession instance.
 * @param param The linked target information.
 *
 * @return A TaskResourceRep.
 */
public TaskList linkTargetVolumesToSnapshotSession(URI snapSessionURI, SnapshotSessionLinkTargetsParam param) {
    s_logger.info("START link new targets for 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);
    boolean inApplication = false;
    if (snapSessionSourceObj instanceof Volume && ((Volume) snapSessionSourceObj).getApplication(_dbClient) != null) {
        inApplication = true;
    } else if (snapSessionSourceObj instanceof BlockSnapshot) {
        BlockSnapshot sourceSnap = (BlockSnapshot) snapSessionSourceObj;
        NamedURI namedUri = sourceSnap.getParent();
        if (!NullColumnValueGetter.isNullNamedURI(namedUri)) {
            Volume source = _dbClient.queryObject(Volume.class, namedUri.getURI());
            if (source != null && source.getApplication(_dbClient) != null) {
                inApplication = true;
            }
        }
    }
    // Get the target information.
    int newLinkedTargetsCount = param.getNewLinkedTargets().getCount();
    String newTargetsName = param.getNewLinkedTargets().getTargetName();
    String newTargetsCopyMode = param.getNewLinkedTargets().getCopyMode();
    if (newTargetsCopyMode == null) {
        newTargetsCopyMode = BlockSnapshot.CopyMode.nocopy.name();
    }
    // Validate that the requested new targets can be linked to the snapshot session.
    snapSessionApiImpl.validateLinkNewTargetsRequest(snapSessionSourceObj, project, newLinkedTargetsCount, newTargetsName, newTargetsCopyMode);
    // Prepare the BlockSnapshot instances to represent the new linked targets.
    List<Map<URI, BlockSnapshot>> snapshots = snapSessionApiImpl.prepareSnapshotsForSession(snapSessionSourceObjs, 0, newLinkedTargetsCount, newTargetsName, inApplication);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    TaskList response = new TaskList();
    List<DataObject> preparedObjects = new ArrayList<>();
    // Create a task for the snapshot session.
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGETS);
    _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSessionURI, taskId, op);
    snapSession.getOpStatus().put(taskId, op);
    response.getTaskList().add(toTask(snapSession, taskId));
    List<List<URI>> snapSessionSnapshotURIs = new ArrayList<>();
    for (Map<URI, BlockSnapshot> snapshotMap : snapshots) {
        // Set Copy Mode
        for (Entry<URI, BlockSnapshot> entry : snapshotMap.entrySet()) {
            entry.getValue().setCopyMode(newTargetsCopyMode);
        }
        preparedObjects.addAll(snapshotMap.values());
        Set<URI> uris = snapshotMap.keySet();
        snapSessionSnapshotURIs.add(Lists.newArrayList(uris));
    }
    // persist copyMode changes
    _dbClient.updateObject(preparedObjects);
    // Create and link new targets to the snapshot session.
    try {
        snapSessionApiImpl.linkNewTargetVolumesToSnapshotSession(snapSessionSourceObj, snapSession, snapSessionSnapshotURIs, newTargetsCopyMode, taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to link new targets for 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(response.getTaskList(), preparedObjects, errorMsg, taskId, sc);
        throw e;
    }
    // Create the audit log entry.
    auditOp(OperationTypeEnum.LINK_SNAPSHOT_SESSION_TARGET, true, AuditLogManager.AUDITOP_BEGIN, snapSessionURI.toString(), snapSessionSourceObj.getId().toString(), snapSessionSourceObj.getStorageController().toString());
    s_logger.info("FINISH link new targets for snapshot session {}", snapSessionURI);
    return response;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) List(java.util.List) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BlockObject(com.emc.storageos.db.client.model.BlockObject) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Map(java.util.Map) HashMap(java.util.HashMap)

Example 25 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method getSnapshotSessionsForCG.

/**
 * Gets the snapshot sessions for consistency group.
 *
 * @param group the consistency group
 * @return the snapshot sessions for consistency group
 */
public List<BlockSnapshotSession> getSnapshotSessionsForCG(BlockConsistencyGroup group) {
    List<Volume> volumes = ControllerUtils.getVolumesPartOfCG(group.getId(), _dbClient);
    if (volumes.isEmpty()) {
        return Collections.<BlockSnapshotSession>emptyList();
    }
    Volume sourceVolume = volumes.get(0);
    // Get the platform specific block snapshot session implementation.
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(sourceVolume);
    // Get the BlockSnapshotSession instances for the source.
    return snapSessionApiImpl.getSnapshotSessionsForConsistencyGroup(group);
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume)

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