Search in sources :

Example 1 with FederatedOperationChain

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) PredefinedFederatedStore(uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore) Test(org.junit.jupiter.api.Test)

Example 2 with FederatedOperationChain

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) PredefinedFederatedStore(uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore) Test(org.junit.jupiter.api.Test)

Example 3 with FederatedOperationChain

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);
    }
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Example 4 with FederatedOperationChain

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);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ArrayList(java.util.ArrayList) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Example 5 with FederatedOperationChain

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) FederatedOperationChain(uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) PredefinedFederatedStore(uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore) Test(org.junit.jupiter.api.Test)

Aggregations

FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)5 FederatedOperationChain (uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain)5 Test (org.junit.jupiter.api.Test)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3 PredefinedFederatedStore (uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore)3 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)3 Context (uk.gov.gchq.gaffer.store.Context)3 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 ArrayList (java.util.ArrayList)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)1