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;
}
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;
}
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;
}
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;
}
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);
}
}
}
}
}
}
Aggregations