Search in sources :

Example 11 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedGetSchemaHandlerTest method setup.

@BeforeEach
public void setup() throws StoreException {
    HashMapGraphLibrary.clear();
    CacheServiceLoader.shutdown();
    handler = new FederatedGetSchemaHandler();
    user = new User("testUser");
    context = new Context(user);
    properties = new FederatedStoreProperties();
    properties.set(HashMapCacheService.STATIC_CACHE, String.valueOf(true));
    fStore = new FederatedStore();
    fStore.initialise(TEST_FED_STORE, null, properties);
    library.clear();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) FederatedStoreProperties(uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedOperationOutputHandler method doOperation.

@Override
public O doOperation(final OP 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<O> results = new ArrayList<>(graphs.size());
    for (final Graph graph : graphs) {
        final OP updatedOp = FederatedStoreUtil.updateOperationForGraph(operation, graph);
        if (null != updatedOp) {
            O execute = null;
            try {
                execute = graph.execute(updatedOp, context);
            } catch (final Exception e) {
                if (!Boolean.valueOf(getSkipFailedFederatedStoreExecute(updatedOp))) {
                    throw new OperationException(FederatedStoreUtil.createOperationErrorMsg(operation, graph.getGraphId(), e), e);
                }
            }
            if (null != execute) {
                results.add(execute);
            }
        }
    }
    try {
        return mergeResults(results, operation, context, store);
    } catch (final Exception e) {
        throw new OperationException(e);
    }
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) 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 13 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedChangeGraphIdHandler method doOperation.

@Override
public Boolean doOperation(final ChangeGraphId operation, final Context context, final Store store) throws OperationException {
    try {
        final boolean userRequestingAdminUsage = FederatedStoreUtil.isUserRequestingAdminUsage(operation);
        final User user = context.getUser();
        return ((FederatedStore) store).changeGraphId(user, operation.getGraphId(), operation.getNewGraphId(), userRequestingAdminUsage);
    } catch (final Exception e) {
        throw new OperationException("Error changing graphId", e);
    }
}
Also used : User(uk.gov.gchq.gaffer.user.User) OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Example 14 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedGetAllGraphInfoHandler method doOperation.

@Override
public Map<String, Object> doOperation(final GetAllGraphInfo operation, final Context context, final Store store) throws OperationException {
    try {
        final boolean userRequestingAdminUsage = isUserRequestingAdminUsage(operation);
        final String graphIdsCsv = operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS);
        return ((FederatedStore) store).getAllGraphsAndAuths(context.getUser(), graphIdsCsv, userRequestingAdminUsage);
    } catch (final Exception e) {
        throw new OperationException("Error getting graph information.", e);
    }
}
Also used : OperationException(uk.gov.gchq.gaffer.operation.OperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Example 15 with FederatedStore

use of uk.gov.gchq.gaffer.federatedstore.FederatedStore in project Gaffer by gchq.

the class FederatedOperationHandlerTest method shouldNotThrowExceptionBecauseSkipFlagSetTrue.

@Test
public void shouldNotThrowExceptionBecauseSkipFlagSetTrue() throws Exception {
    // Given
    final String graphID = "1,3";
    final Operation op = mock(Operation.class);
    when(op.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS)).thenReturn(graphID);
    when(op.getOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE)).thenReturn(String.valueOf(true));
    when(op.getOption(eq(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE), any(String.class))).thenReturn(String.valueOf(true));
    given(op.shallowClone()).willReturn(op);
    Schema unusedSchema = new Schema.Builder().build();
    StoreProperties storeProperties = new StoreProperties();
    Store mockStore1 = getMockStore(unusedSchema, storeProperties);
    given(mockStore1.execute(any(OperationChain.class), eq(context))).willReturn(1);
    Store mockStore2 = getMockStore(unusedSchema, storeProperties);
    given(mockStore2.execute(any(OperationChain.class), eq(context))).willThrow(new RuntimeException("Test Exception"));
    FederatedStore mockStore = mock(FederatedStore.class);
    LinkedHashSet<Graph> filteredGraphs = Sets.newLinkedHashSet();
    filteredGraphs.add(getGraphWithMockStore(mockStore1));
    filteredGraphs.add(getGraphWithMockStore(mockStore2));
    when(mockStore.getGraphs(user, graphID, op)).thenReturn(filteredGraphs);
    // When
    try {
        new FederatedOperationHandler().doOperation(op, context, mockStore);
    } catch (Exception e) {
        fail("Exception should not have been thrown: " + e.getMessage());
    }
    // Then
    final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
    verify(mockStore1, atLeastOnce()).execute(any(OperationChain.class), contextCaptor1.capture());
    assertEquals(context.getUser(), contextCaptor1.getValue().getUser());
    assertNotEquals(context.getJobId(), contextCaptor1.getValue().getJobId());
    final ArgumentCaptor<Context> contextCaptor2 = ArgumentCaptor.forClass(Context.class);
    verify(mockStore2, atLeastOnce()).execute(any(OperationChain.class), contextCaptor2.capture());
    assertEquals(context.getUser(), contextCaptor2.getValue().getUser());
    assertNotEquals(context.getJobId(), contextCaptor2.getValue().getJobId());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore) Test(org.junit.jupiter.api.Test)

Aggregations

FederatedStore (uk.gov.gchq.gaffer.federatedstore.FederatedStore)38 Test (org.junit.jupiter.api.Test)25 Context (uk.gov.gchq.gaffer.store.Context)25 Schema (uk.gov.gchq.gaffer.store.schema.Schema)19 Graph (uk.gov.gchq.gaffer.graph.Graph)16 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)12 OperationException (uk.gov.gchq.gaffer.operation.OperationException)12 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)11 Store (uk.gov.gchq.gaffer.store.Store)10 FederatedOperationChain (uk.gov.gchq.gaffer.federatedstore.operation.FederatedOperationChain)8 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)7 FederatedStoreProperties (uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties)7 PredefinedFederatedStore (uk.gov.gchq.gaffer.federatedstore.PredefinedFederatedStore)7 Operation (uk.gov.gchq.gaffer.operation.Operation)7 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)6 User (uk.gov.gchq.gaffer.user.User)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Element (uk.gov.gchq.gaffer.data.element.Element)4 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)4 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)4