use of uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain in project Gaffer by gchq.
the class FederatedOperationChainHandlerTest method shouldHandleChainWithIterableOutput.
@Test
public void shouldHandleChainWithIterableOutput() throws OperationException {
// Given
final FederatedStore store = createStore();
final Context context = new Context();
final FederatedOperationChain<Void, Element> opChain = new FederatedOperationChain.Builder<Void, Element>().operationChain(new OperationChain.Builder().first(new GetAllElements()).then(new Limit<>(1)).build()).option(KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_IDS).build();
// When
final Iterable result = store.execute(opChain, context);
// Then - the result will contain 2 elements - 1 from each graph
ElementUtil.assertElementEquals(Arrays.asList(elements[0], elements[1]), result);
}
use of uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain in project Gaffer by gchq.
the class FederatedOperationChainHandlerTest method shouldHandleChainWithLongOutput.
@Test
public void shouldHandleChainWithLongOutput() throws OperationException {
// Given
final FederatedStore store = createStore();
final Context context = new Context();
final FederatedOperationChain<Void, Long> opChain = new FederatedOperationChain.Builder<Void, Long>().operationChain(new OperationChain.Builder().first(new GetAllElements()).then(new Count<>()).build()).option(KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_IDS).build();
// When
final Iterable result = store.execute(opChain, context);
// Then
assertEquals(Lists.newArrayList(1L, 1L), Lists.newArrayList(result));
}
use of uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain in project Gaffer by gchq.
the class FederatedGetTraitsHandler method doOperation.
@Override
public Set<StoreTrait> doOperation(final GetTraits operation, final Context context, final Store store) throws OperationException {
try {
FederatedOperationChain<Void, StoreTrait> wrappedFedChain = new FederatedOperationChain.Builder<Void, StoreTrait>().operationChain(OperationChain.wrap(operation)).options(isNull(operation.getOptions()) ? new HashMap<>() : new HashMap<>(operation.getOptions())).build();
final CloseableIterable<StoreTrait> concatResults = store.execute(wrappedFedChain, context);
Map<StoreTrait, Integer> rtn;
if (nonNull(concatResults) && nonNull(concatResults.iterator()) && concatResults.iterator().hasNext()) {
rtn = Streams.toStream(concatResults).collect(Collectors.toMap(t -> t, ignore -> 1, (existing, replacement) -> existing + replacement));
long graphIdsSize = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS), operation).stream().count();
rtn.values().removeIf(v -> v < graphIdsSize);
} else {
rtn = Collections.EMPTY_MAP;
}
return rtn.keySet();
} catch (final Exception e) {
throw new OperationException("Error getting federated traits.", e);
}
}
use of uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain 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.operation.FederatedOperationChain in project Gaffer by gchq.
the class FederatedOperationChainHandlerTest method shouldHandleChainWithNoOutput.
@Test
public void shouldHandleChainWithNoOutput() throws OperationException {
// Given
final FederatedStore store = createStore();
final Context context = new Context();
final FederatedOperationChain<Object, Void> opChain = new FederatedOperationChain.Builder<Object, Void>().operationChain(new OperationChain.Builder().first(new AddElements.Builder().input(elements2).build()).build()).option(KEY_OPERATION_OPTIONS_GRAPH_IDS, GRAPH_IDS).build();
// When
final Iterable result = store.execute(opChain, context);
// Then
assertNull(result);
final CloseableIterable<? extends Element> allElements = store.execute(new GetAllElements(), context);
ElementUtil.assertElementEquals(Arrays.asList(elements[0], elements[1], elements2[0], elements2[1]), allElements);
}
Aggregations