Search in sources :

Example 91 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method getSnapshotSessionsForConsistencyGroup.

/**
 * @param group
 * @return
 */
public BlockSnapshotSessionList getSnapshotSessionsForConsistencyGroup(BlockConsistencyGroup group) {
    BlockSnapshotSessionList result = new BlockSnapshotSessionList();
    List<Volume> volumes = ControllerUtils.getVolumesPartOfCG(group.getId(), _dbClient);
    if (volumes.isEmpty()) {
        return result;
    }
    // if any of the source volumes are in an application, replica management must be done via the application
    for (Volume srcVol : volumes) {
        if (srcVol.getApplication(_dbClient) != null) {
            return result;
        }
    }
    Volume sourceVolume = volumes.get(0);
    // Get the platform specific block snapshot session implementation.
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(sourceVolume);
    // Get the BlockSnapshotSession instances for the source and prepare the result.
    List<BlockSnapshotSession> snapSessions = snapSessionApiImpl.getSnapshotSessionsForConsistencyGroup(group);
    for (BlockSnapshotSession snapSession : snapSessions) {
        result.getSnapSessionRelatedResourceList().add(toNamedRelatedResource(snapSession));
    }
    return result;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshotSessionList(com.emc.storageos.model.block.BlockSnapshotSessionList)

Example 92 with BlockSnapshotSession

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

the class BlockSnapshotSessionManager method createSnapshotSession.

/**
 * Implements a request to create a new block snapshot session.
 *
 * @param snapSessionSourceObjList The URI of the snapshot session source object.
 * @param param A reference to the create session information.
 * @param fcManager A reference to a full copy manager.
 *
 * @return TaskList A TaskList
 */
public TaskList createSnapshotSession(List<BlockObject> snapSessionSourceObjList, SnapshotSessionCreateParam param, BlockFullCopyManager fcManager) {
    Collection<URI> sourceURIs = transform(snapSessionSourceObjList, fctnDataObjectToID());
    s_logger.info("START create snapshot session for sources {}", Joiner.on(',').join(sourceURIs));
    // Get the snapshot session label.
    String snapSessionLabel = TimeUtils.formatDateForCurrent(param.getName());
    // Get the target device information, if any.
    int newLinkedTargetsCount = 0;
    String newTargetsName = null;
    String newTargetsCopyMode = BlockSnapshot.CopyMode.nocopy.name();
    SnapshotSessionNewTargetsParam linkedTargetsParam = param.getNewLinkedTargets();
    if (linkedTargetsParam != null) {
        newLinkedTargetsCount = linkedTargetsParam.getCount().intValue();
        newTargetsName = TimeUtils.formatDateForCurrent(linkedTargetsParam.getTargetName());
        newTargetsCopyMode = linkedTargetsParam.getCopyMode();
    }
    BlockObject sourceObj = snapSessionSourceObjList.get(0);
    // Get the project for the snapshot session source object.
    Project project = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
    // Get the platform specific block snapshot session implementation.
    BlockSnapshotSessionApi snapSessionApiImpl = determinePlatformSpecificImplForSource(sourceObj);
    // Validate the create snapshot session request.
    snapSessionApiImpl.validateSnapshotSessionCreateRequest(sourceObj, snapSessionSourceObjList, project, snapSessionLabel, newLinkedTargetsCount, newTargetsName, newTargetsCopyMode, false, fcManager);
    // Create a unique task identifier.
    String taskId = UUID.randomUUID().toString();
    boolean inApplication = false;
    if (sourceObj instanceof Volume && ((Volume) sourceObj).getApplication(_dbClient) != null) {
        inApplication = true;
    } else if (sourceObj instanceof BlockSnapshot) {
        BlockSnapshot sourceSnap = (BlockSnapshot) sourceObj;
        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;
            }
        }
    }
    // Prepare the ViPR BlockSnapshotSession instances and BlockSnapshot
    // instances for any new targets to be created and linked to the
    // snapshot sessions.
    List<Map<URI, BlockSnapshot>> snapSessionSnapshots = new ArrayList<>();
    BlockSnapshotSession snapSession = snapSessionApiImpl.prepareSnapshotSession(snapSessionSourceObjList, snapSessionLabel, newLinkedTargetsCount, newTargetsName, snapSessionSnapshots, taskId, inApplication);
    // Populate the preparedObjects list and create tasks for each snapshot session.
    TaskList response = new TaskList();
    Operation snapSessionOp = _dbClient.createTaskOpStatus(BlockSnapshotSession.class, snapSession.getId(), taskId, getCreateResourceOperationTypeEnum(snapSession));
    snapSession.getOpStatus().put(taskId, snapSessionOp);
    response.getTaskList().add(toTask(snapSession, taskId, snapSessionOp));
    if (snapSession.hasConsistencyGroup()) {
        addConsistencyGroupTasks(snapSessionSourceObjList, response, taskId, getCreateResourceOperationTypeEnum(snapSession));
    } else {
        for (BlockObject sourceForTask : snapSessionSourceObjList) {
            @SuppressWarnings("unchecked") Operation op = _dbClient.createTaskOpStatus(URIUtil.getModelClass(sourceForTask.getId()), sourceForTask.getId(), taskId, ResourceOperationTypeEnum.CREATE_SNAPSHOT_SESSION);
            response.getTaskList().add(toTask(sourceForTask, taskId, op));
        }
    }
    List<DataObject> preparedObjects = new ArrayList<>();
    List<List<URI>> snapSessionSnapshotURIs = new ArrayList<>();
    for (Map<URI, BlockSnapshot> snapshotMap : snapSessionSnapshots) {
        // 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);
    preparedObjects.add(snapSession);
    // Create the snapshot sessions.
    try {
        snapSessionApiImpl.createSnapshotSession(sourceObj, snapSession.getId(), snapSessionSnapshotURIs, newTargetsCopyMode, taskId);
    } catch (Exception e) {
        String errorMsg = format("Failed to create snapshot sessions for source %s: %s", sourceObj.getId(), 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;
    }
    // Record a message in the audit log.
    auditOp(OperationTypeEnum.CREATE_SNAPSHOT_SESSION, true, AuditLogManager.AUDITOP_BEGIN, snapSessionLabel, sourceObj.getId().toString(), sourceObj.getStorageController().toString());
    s_logger.info("FINISH create snapshot session for source {}", sourceObj.getId());
    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) SnapshotSessionNewTargetsParam(com.emc.storageos.model.block.SnapshotSessionNewTargetsParam) 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 93 with BlockSnapshotSession

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

the class VPlexBlockSnapshotSessionApiImpl method getSnapshotSessionsForSource.

/**
 * {@inheritDoc}
 */
@Override
public List<BlockSnapshotSession> getSnapshotSessionsForSource(BlockObject sourceObj) {
    List<BlockSnapshotSession> snapSessions;
    if (URIUtil.isType(sourceObj.getId(), Volume.class)) {
        Volume vplexVolume = (Volume) sourceObj;
        Volume srcSideBackendVolume = null;
        try {
            srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume(vplexVolume, true, _dbClient);
        } catch (Exception e) {
            // Just log a warning and return the empty list.
            s_logger.warn("Cound not find source side backend volume for VPLEX volume {}", vplexVolume.getId());
            return new ArrayList<BlockSnapshotSession>();
        }
        if (srcSideBackendVolume != null) {
            URI parentURI = srcSideBackendVolume.getId();
            snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(parentURI));
        } else {
            s_logger.warn("Cound not find source side backend volume for VPLEX volume {}", vplexVolume.getId());
            return new ArrayList<BlockSnapshotSession>();
        }
    } else {
        // so should not be called.
        throw APIException.methodNotAllowed.notSupportedForVplexVolumes();
    }
    return snapSessions;
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 94 with BlockSnapshotSession

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

the class VPlexBlockSnapshotSessionApiImpl method prepareSnapshotSessionFromSource.

/**
 * {@inheritDoc}
 */
@Override
public BlockSnapshotSession prepareSnapshotSessionFromSource(BlockObject sourceObj, String snapSessionLabel, String instanceLabel, String taskId, boolean inApplication) {
    // The snapshot is generally prepared with information from the
    // source side backend volume, which is the volume being snapped.
    // The passed source object will be a volume, else would not have
    // made it this far.
    Volume srcSideBackendVolume = VPlexUtil.getVPLEXBackendVolume((Volume) sourceObj, true, _dbClient);
    BlockSnapshotSessionApi snapSessionImpl = getImplementationForBackendSystem(srcSideBackendVolume.getStorageController());
    BlockSnapshotSession snapSession = snapSessionImpl.prepareSnapshotSessionFromSource(srcSideBackendVolume, snapSessionLabel, instanceLabel, taskId, inApplication);
    // However, the project is from the VPLEX volume.
    Project sourceProject = BlockSnapshotSessionUtils.querySnapshotSessionSourceProject(sourceObj, _dbClient);
    snapSession.setProject(new NamedURI(sourceProject.getId(), sourceObj.getLabel()));
    return snapSession;
}
Also used : Project(com.emc.storageos.db.client.model.Project) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Example 95 with BlockSnapshotSession

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

the class BlockServiceUtils method validateVolumeNoReplica.

/**
 * validate volume with no replica
 *
 * @param volume
 * @param application
 * @param dbClient
 */
public static void validateVolumeNoReplica(Volume volume, VolumeGroup application, DbClient dbClient) {
    // check if the volume has any replica
    // no need to check backing volumes for vplex virtual volumes because for full copies
    // there will be a virtual volume for the clone
    boolean hasReplica = volume.getFullCopies() != null && !volume.getFullCopies().isEmpty() || volume.getMirrors() != null && !volume.getMirrors().isEmpty();
    // check for snaps only if no full copies
    if (!hasReplica) {
        Volume snapSource = volume;
        if (volume.isVPlexVolume(dbClient)) {
            snapSource = VPlexUtil.getVPLEXBackendVolume(volume, true, dbClient);
            if (snapSource == null || snapSource.getInactive()) {
                return;
            }
        }
        hasReplica = ControllerUtils.checkIfVolumeHasSnapshot(snapSource, dbClient);
        // check for VMAX3 individual session and group session
        if (!hasReplica && snapSource.isVmax3Volume(dbClient)) {
            hasReplica = ControllerUtils.checkIfVolumeHasSnapshotSession(snapSource.getId(), dbClient);
            String rgName = snapSource.getReplicationGroupInstance();
            if (!hasReplica && NullColumnValueGetter.isNotNullValue(rgName)) {
                URI cgURI = snapSource.getConsistencyGroup();
                List<BlockSnapshotSession> sessionsList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getBlockSnapshotSessionByConsistencyGroup(cgURI));
                for (BlockSnapshotSession session : sessionsList) {
                    if (rgName.equals(session.getReplicationGroupInstance())) {
                        hasReplica = true;
                        break;
                    }
                }
            }
        }
    }
    if (hasReplica) {
        throw APIException.badRequests.volumeGroupCantBeUpdated(application.getLabel(), String.format("the volume %s has replica. please remove all replicas from the volume", volume.getLabel()));
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) Volume(com.emc.storageos.db.client.model.Volume) URI(java.net.URI) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_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