use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationChainHandler method doOperation.
@Override
public CloseableIterable<O_ITEM> doOperation(final FederatedOperationChain<I, O_ITEM> operation, final Context context, final Store store) throws OperationException {
final Collection<Graph> graphs = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS), operation);
final List<Object> results = new ArrayList<>(graphs.size());
for (final Graph graph : graphs) {
final OperationChain opChain = operation.getOperationChain();
OperationHandlerUtil.updateOperationInput(opChain, operation.getInput());
final OperationChain updatedOp = FederatedStoreUtil.updateOperationForGraph(opChain, graph);
if (null != updatedOp) {
Object result = null;
try {
result = graph.execute(updatedOp, context);
} catch (final Exception e) {
if (!Boolean.valueOf(updatedOp.getOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE))) {
throw new OperationException(FederatedStoreUtil.createOperationErrorMsg(operation, graph.getGraphId(), e), e);
}
}
if (null != result) {
results.add(result);
}
}
}
return mergeResults(results, operation, context, store);
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationChainValidator method validateAllGraphsIdViews.
/**
* If the given view is valid for at least 1 of the graphIds, then view is valid and exit.
* Else none are valid, return all the errors within the validation result.
*
* @param op The operation with view to test
* @param user The requesting user
* @param store The current store
* @param validationResult The result of validation
* @param graphIdsCSV The graphs to test the view against
*/
private void validateAllGraphsIdViews(final Operation op, final User user, final Store store, final ValidationResult validationResult, final String graphIdsCSV) {
ValidationResult savedResult = new ValidationResult();
ValidationResult currentResult = null;
final Operation clonedOp = shallowCloneWithDeepOptions(op);
Collection<Graph> graphs = ((FederatedStore) store).getGraphs(user, graphIdsCSV, clonedOp);
for (final Graph graph : graphs) {
String graphId = graph.getGraphId();
final boolean graphIdValid = ((FederatedStore) store).getAllGraphIds(user).contains(graphId);
// If graphId is not valid, then there is no schema to validate a view against.
if (graphIdValid) {
currentResult = new ValidationResult();
clonedOp.addOption(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphId);
if (!graph.hasTrait(StoreTrait.DYNAMIC_SCHEMA)) {
super.validateViews(clonedOp, user, store, currentResult);
}
if (currentResult.isValid()) {
// If any graph has a valid View, break with valid current result
break;
} else {
ValidationResult prependGraphId = new ValidationResult();
currentResult.getErrors().forEach(s -> prependGraphId.addError(String.format("(graphId: %s) %s", graphId, s)));
savedResult.add(prependGraphId);
}
}
}
// What state did the for loop exit with?
if (currentResult != null && !currentResult.isValid()) {
validationResult.addError("View is not valid for graphIds:" + getGraphIds(op, user, (FederatedStore) store).stream().collect(Collectors.joining(",", "[", "]")));
// If invalid, no graphs views where valid, so add all saved errors.
validationResult.add(savedResult);
}
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedAddGraphHandlerParent method doOperation.
@Override
public Void doOperation(final OP operation, final Context context, final Store store) throws OperationException {
final User user = context.getUser();
boolean isLimitedToLibraryProperties = ((FederatedStore) store).isLimitedToLibraryProperties(user);
if (isLimitedToLibraryProperties && null != operation.getStoreProperties()) {
throw new OperationException(String.format(USER_IS_LIMITED_TO_ONLY_USING_PARENT_PROPERTIES_ID_FROM_GRAPHLIBRARY_BUT_FOUND_STORE_PROPERTIES_S, operation.getProperties().toString()));
}
final GraphSerialisable graphSerialisable;
try {
graphSerialisable = _makeGraph(operation, store);
} catch (final Exception e) {
throw new OperationException(String.format(ERROR_BUILDING_GRAPH_GRAPH_ID_S, operation.getGraphId()), e);
}
try {
((FederatedStore) store).addGraphs(operation.getGraphAuths(), context.getUser().getUserId(), operation.getIsPublic(), operation.isDisabledByDefault(), operation.getReadAccessPredicate(), operation.getWriteAccessPredicate(), graphSerialisable);
} catch (final StorageException e) {
throw new OperationException(e.getMessage(), e);
} catch (final Exception e) {
throw new OperationException(String.format(ERROR_ADDING_GRAPH_GRAPH_ID_S, operation.getGraphId()), e);
}
addGenericHandler((FederatedStore) store, graphSerialisable.getGraph());
return null;
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedOperationHandlerTest method shouldMergeResultsFromFieldObjects.
@Test
public final void shouldMergeResultsFromFieldObjects() throws Exception {
// Given
final Operation op = mock(Operation.class);
final Operation opClone = mock(Operation.class);
given(op.shallowClone()).willReturn(opClone);
given(opClone.shallowClone()).willReturn(opClone);
final OperationChain<?> opChainClone = OperationChain.wrap(opClone);
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStore1 = getMockStore(unusedSchema, storeProperties);
Store mockStore2 = getMockStore(unusedSchema, storeProperties);
Store mockStore3 = getMockStore(unusedSchema, storeProperties);
Store mockStore4 = getMockStore(unusedSchema, storeProperties);
Graph graph1 = getGraphWithMockStore(mockStore1);
Graph graph2 = getGraphWithMockStore(mockStore2);
Graph graph3 = getGraphWithMockStore(mockStore3);
Graph graph4 = getGraphWithMockStore(mockStore4);
FederatedStore mockStore = mock(FederatedStore.class);
LinkedHashSet<Graph> linkedGraphs = Sets.newLinkedHashSet();
linkedGraphs.add(graph1);
linkedGraphs.add(graph2);
linkedGraphs.add(graph3);
linkedGraphs.add(graph4);
when(mockStore.getGraphs(user, null, op)).thenReturn(linkedGraphs);
// When
new FederatedOperationHandler().doOperation(op, context, mockStore);
verify(mockStore1).execute(eq(opChainClone), any(Context.class));
verify(mockStore2).execute(eq(opChainClone), any(Context.class));
verify(mockStore3).execute(eq(opChainClone), any(Context.class));
verify(mockStore4).execute(eq(opChainClone), any(Context.class));
}
use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.
the class FederatedAddGraphHandlerTest method setUp.
@BeforeEach
public void setUp() throws Exception {
CacheServiceLoader.shutdown();
this.store = new FederatedStore();
federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
testUser = testUser();
authUser = authUser();
blankUser = blankUser();
ignore = new IgnoreOptions();
}
Aggregations