Search in sources :

Example 66 with BlockObject

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

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

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

the class BlockSnapshotSessionManager method getAllSnapshotSessionSources.

private List<BlockObject> getAllSnapshotSessionSources(BlockSnapshotSession snapSession) {
    if (snapSession.hasConsistencyGroup() && NullColumnValueGetter.isNotNullValue(snapSession.getReplicationGroupInstance())) {
        BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, snapSession.getConsistencyGroup());
        List<Volume> cgSources = BlockConsistencyGroupUtils.getAllCGVolumes(cg, _dbClient);
        // return only those volumes belonging to session's RG
        return ControllerUtils.getAllVolumesForRGInCG(cgSources, snapSession.getReplicationGroupInstance(), snapSession.getStorageController(), _dbClient);
    } else {
        BlockObject snapSessionSourceObj = BlockSnapshotSessionUtils.querySnapshotSessionSource(snapSession.getParent().getURI(), _uriInfo, true, _dbClient);
        return Lists.newArrayList(snapSessionSourceObj);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockObject(com.emc.storageos.db.client.model.BlockObject) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 69 with BlockObject

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

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

the class VolumeIngestionUtil method getVolumeObjects.

/**
 * For a given set of Volume native GUIDs, this method will return a List of
 * URIs for any Volumes that were actually found in the database for that GUID.
 * If a Volume cannot be found in the database, then the IngestionRequestContext
 * will be checked for any Volumes that were created but not saved yet.
 *
 * @param targets a list of Volume native GUIDs to look for
 * @param requestContext the IngestionRequestContext to analyze for newly-created objects
 * @param dbClient a reference to the database client
 * @return a List of BlockObjects for the given native GUIDs
 */
public static List<BlockObject> getVolumeObjects(StringSet targets, IngestionRequestContext requestContext, DbClient dbClient) {
    List<BlockObject> targetUriList = new ArrayList<BlockObject>();
    for (String targetId : targets) {
        List<URI> targetUris = dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeNativeGuidConstraint(targetId));
        if (null != targetUris && !targetUris.isEmpty()) {
            for (URI targetUri : targetUris) {
                BlockObject bo = (BlockObject) dbClient.queryObject(targetUri);
                _logger.info("found volume block object: " + bo);
                if (null != bo) {
                    if (!bo.getInactive()) {
                        targetUriList.add(bo);
                        break;
                    } else {
                        _logger.warn("BlockObject {} was retrieved from the database but is in an inactive state. " + "there may be a stale BlockObject column family alternate id index entry present " + "for native guid {}", bo.forDisplay(), targetId);
                    }
                }
            }
        } else {
            _logger.info("Volume not ingested yet {}. Checking in the created object map", targetId);
            // check in the created object map
            BlockObject blockObject = requestContext.getRootIngestionRequestContext().findCreatedBlockObject(targetId);
            if (blockObject != null) {
                _logger.info("Found the volume in the created object map");
                targetUriList.add(blockObject);
            }
        }
    }
    return targetUriList;
}
Also used : ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Aggregations

BlockObject (com.emc.storageos.db.client.model.BlockObject)341 URI (java.net.URI)222 ArrayList (java.util.ArrayList)152 Volume (com.emc.storageos.db.client.model.Volume)141 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)109 NamedURI (com.emc.storageos.db.client.model.NamedURI)82 HashMap (java.util.HashMap)82 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)69 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)65 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)60 ExportMask (com.emc.storageos.db.client.model.ExportMask)56 HashSet (java.util.HashSet)56 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)48 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)45 CIMObjectPath (javax.cim.CIMObjectPath)44 Initiator (com.emc.storageos.db.client.model.Initiator)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 List (java.util.List)40 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)38 StringSet (com.emc.storageos.db.client.model.StringSet)36