Search in sources :

Example 36 with DataObject

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

the class DiscoveredObjectTaskScheduler method scheduleAsyncTasks.

public TaskList scheduleAsyncTasks(List<AsyncTask> tasks) {
    TaskList list = new TaskList();
    for (AsyncTask task : tasks) {
        if (task instanceof ArrayAffinityAsyncTask) {
            List<URI> systemIds = ((ArrayAffinityAsyncTask) task).getSystemIds();
            for (URI uri : systemIds) {
                DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, uri);
                Operation op = new Operation();
                op.setResourceType(_taskExecutor.getOperation());
                _dbClient.createTaskOpStatus(task._clazz, uri, task._opId, op);
                list.getTaskList().add(toTask(discoveredObject, task._opId, op));
            }
        } else {
            DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, task._id);
            Operation op = new Operation();
            op.setResourceType(_taskExecutor.getOperation());
            _dbClient.createTaskOpStatus(task._clazz, task._id, task._opId, op);
            list.getTaskList().add(toTask(discoveredObject, task._opId, op));
        }
    }
    try {
        _taskExecutor.executeTasks(tasks.toArray(new AsyncTask[tasks.size()]));
    } catch (ControllerException | APIException ex) {
        for (AsyncTask task : tasks) {
            DataObject discoveredObject = (DataObject) _dbClient.queryObject(task._clazz, task._id);
            Operation op = _dbClient.error(task._clazz, task._id, task._opId, ex);
            list.getTaskList().add(toTask(discoveredObject, task._opId, op));
        }
    }
    return list;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ControllerException(com.emc.storageos.volumecontroller.ControllerException) TaskList(com.emc.storageos.model.TaskList) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI)

Example 37 with DataObject

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

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

the class VolumeIngestionUtil method verifyExportGroupExists.

/**
 * Get the export group associated with initiator URIs
 *
 * Note: Once it finds an export group associated with any initiator, it returns that export group. This may not
 * be what the caller wants.
 *
 * @param requestContext current unManagedVolume Ingestion context.
 * @param exportGroupGeneratedName the generated name for the ExportGroup label
 * @param project project
 * @param knownInitiatorUris initiators list
 * @param vArray virtual array
 * @param dbClient dbclient
 * @return export group
 */
public static ExportGroup verifyExportGroupExists(IngestionRequestContext requestContext, String exportGroupGeneratedName, URI project, StringSet knownInitiatorUris, URI vArray, DbClient dbClient) {
    ExportGroup exportGroup = null;
    for (String initiatorIdStr : knownInitiatorUris) {
        AlternateIdConstraint constraint = AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorIdStr);
        URIQueryResultList egUris = new URIQueryResultList();
        dbClient.queryByConstraint(constraint, egUris);
        List<ExportGroup> queryExportGroups = dbClient.queryObject(ExportGroup.class, egUris);
        for (ExportGroup eg : queryExportGroups) {
            if (!eg.getGeneratedName().equals(exportGroupGeneratedName)) {
                continue;
            }
            if (!eg.getProject().getURI().equals(project)) {
                continue;
            }
            if (!eg.getVirtualArray().equals(vArray)) {
                continue;
            }
            if (queryExportGroups.size() > 1) {
                _logger.info("More than one export group contains the initiator(s) requested.  Choosing : " + eg.getId().toString());
            }
            exportGroup = eg;
            break;
        }
    }
    if (exportGroup != null) {
        DataObject alreadyLoadedExportGroup = requestContext.findInUpdatedObjects(exportGroup.getId());
        if (alreadyLoadedExportGroup != null && (alreadyLoadedExportGroup instanceof ExportGroup)) {
            _logger.info("Found an already loaded export group");
            exportGroup = (ExportGroup) alreadyLoadedExportGroup;
        }
    }
    return exportGroup;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) DataObject(com.emc.storageos.db.client.model.DataObject) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 39 with DataObject

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

the class VolumeIngestionUtil method isRPProtectingVplexVolumes.

/**
 * Checks whether RP is protecting any VPLEX volumes or not.
 *
 * 1. Get the ProtectionSet from the context for the given unmanagedvolume.
 * 2. Check every volume in the protectionset.
 * 3. If the volume belongs to a VPLEX or not.
 * 4. If it belongs to VPLEX break the loop and return true.
 *
 * @param umv - unmanaged volume to ingest
 * @param requestContext - current unmanaged volume context.
 * @param dbClient - dbclient reference.
 */
public static boolean isRPProtectingVplexVolumes(UnManagedVolume umv, IngestionRequestContext requestContext, DbClient dbClient) {
    VolumeIngestionContext context = requestContext.getVolumeContext(umv.getNativeGuid());
    boolean isRPProtectingVplexVolumes = false;
    // We expect RP Context to validate Vplex volumes protected by RP or not.
    if (context instanceof RecoverPointVolumeIngestionContext) {
        RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) context;
        ProtectionSet pset = rpContext.getManagedProtectionSet();
        if (pset == null) {
            return isRPProtectingVplexVolumes;
        }
        // Iterate thru protection set volumes.
        for (String volumeIdStr : pset.getVolumes()) {
            for (Set<DataObject> dataObjList : rpContext.getDataObjectsToBeUpdatedMap().values()) {
                for (DataObject dataObj : dataObjList) {
                    if (URIUtil.identical(dataObj.getId(), URI.create(volumeIdStr))) {
                        Volume volume = (Volume) dataObj;
                        if (volume.isVPlexVolume(dbClient)) {
                            isRPProtectingVplexVolumes = true;
                            break;
                        }
                    }
                }
            }
        }
    } else if (context instanceof BlockVolumeIngestionContext) {
        // In this case, the last volume ingested was a replica, so we need to fish out RP information slightly differently.
        Set<DataObject> updatedObjects = requestContext.getDataObjectsToBeUpdatedMap().get(umv.getNativeGuid());
        if (updatedObjects != null && !updatedObjects.isEmpty()) {
            for (DataObject dataObj : updatedObjects) {
                if (dataObj instanceof Volume) {
                    Volume volume = (Volume) dataObj;
                    if (volume.isVPlexVolume(dbClient)) {
                        isRPProtectingVplexVolumes = true;
                        break;
                    }
                }
            }
        }
    } else {
        _logger.error("Context found of type: {} invalid", context.getClass().toString());
    }
    return isRPProtectingVplexVolumes;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BlockVolumeIngestionContext) VplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.VplexVolumeIngestionContext) RpVplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RpVplexVolumeIngestionContext) BlockVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BlockVolumeIngestionContext) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext)

Example 40 with DataObject

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

the class VolumeIngestionUtil method clearReplicaFlagsInIngestionContext.

/**
 * Clear the flags of replicas which have been updated during the ingestion process
 *
 * @param requestContext current unManagedVolume Ingestion context.
 * @param volumes RP volumes
 * @param dbClient database client
 */
public static void clearReplicaFlagsInIngestionContext(IngestionRequestContext requestContext, List<Volume> volumes, DbClient dbClient) {
    // We need to look for all snapshots and snapshot session in the contexts related to the rp volumes and its backend volumes and
    // clear their flags.
    _logger.info("Clearing flags of replicas in the context");
    List<String> rpVolumes = new ArrayList<String>();
    for (Volume volume : volumes) {
        rpVolumes.add(volume.getId().toString());
        if (RPHelper.isVPlexVolume(volume, dbClient) && volume.getAssociatedVolumes() != null && !volume.getAssociatedVolumes().isEmpty()) {
            StringSet associatedVolumes = volume.getAssociatedVolumes();
            rpVolumes.addAll(associatedVolumes);
        }
    }
    for (VolumeIngestionContext volumeIngestionContext : requestContext.getRootIngestionRequestContext().getProcessedUnManagedVolumeMap().values()) {
        if (volumeIngestionContext instanceof IngestionRequestContext) {
            for (Set<DataObject> objectsToBeUpdated : ((IngestionRequestContext) volumeIngestionContext).getDataObjectsToBeUpdatedMap().values()) {
                for (DataObject o : objectsToBeUpdated) {
                    boolean rpBlockSnapshot = (o instanceof BlockSnapshot && rpVolumes.contains(((BlockSnapshot) o).getParent().getURI().toString()));
                    boolean rpBlockSnapshotSession = (o instanceof BlockSnapshotSession && rpVolumes.contains(((BlockSnapshotSession) o).getParent().getURI().toString()));
                    if (rpBlockSnapshot || rpBlockSnapshotSession) {
                        _logger.info(String.format("Clearing internal volume flag of %s %s of RP volume ", (rpBlockSnapshot ? "BlockSnapshot" : "BlockSnapshotSession"), o.getLabel()));
                        o.clearInternalFlags(BlockIngestOrchestrator.INTERNAL_VOLUME_FLAGS);
                    }
                }
            }
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) IngestionRequestContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.IngestionRequestContext) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.VplexVolumeIngestionContext) RpVplexVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RpVplexVolumeIngestionContext) BlockVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BlockVolumeIngestionContext) RecoverPointVolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.RecoverPointVolumeIngestionContext) VolumeIngestionContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.VolumeIngestionContext)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8