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