use of uk.gov.gchq.gaffer.federatedstore.exception.StorageException in project Gaffer by gchq.
the class FederatedGraphStorageTest method checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccess.
@Test
public void checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccess() throws Exception {
// Given
Schema schemaNotToBeExposed = new Schema.Builder().type(UNUSUAL_TYPE, String.class).type(DIRECTED_EITHER, Boolean.class).entity(GROUP_ENT, new SchemaEntityDefinition.Builder().vertex(UNUSUAL_TYPE).build()).edge(GROUP_EDGE, new SchemaEdgeDefinition.Builder().source(UNUSUAL_TYPE).destination(UNUSUAL_TYPE).directed(DIRECTED_EITHER).build()).build();
final GraphSerialisable graph1 = new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID_A).build()).properties(PROPERTIES).schema(schemaNotToBeExposed).build();
graphStorage.put(graph1, access);
// When / Then
try {
graphStorage.put(graph1, altAccess);
} catch (StorageException e) {
assertEquals("Error adding graph " + GRAPH_ID_A + " to storage due to: " + String.format(FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE, GRAPH_ID_A), e.getMessage());
testNotLeakingContents(e, UNUSUAL_TYPE, GROUP_EDGE, GROUP_ENT);
}
}
use of uk.gov.gchq.gaffer.federatedstore.exception.StorageException in project Gaffer by gchq.
the class PublicAccessPredefinedFederatedStore method initialise.
@Override
public void initialise(final String graphId, final Schema schema, final StoreProperties properties) throws StoreException {
HashMapGraphLibrary.clear();
CacheServiceLoader.shutdown();
ExecutorService.shutdown();
super.initialise(graphId, schema, properties);
try {
// Accumulo store just contains edges
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_EDGES)).schema(new Schema.Builder().merge(schema.clone()).entities(Collections.emptyMap()).build()).properties(PROPERTIES).build());
// Accumulo store just contains entities
addGraphs(null, User.UNKNOWN_USER_ID, true, new GraphSerialisable.Builder().config(new GraphConfig(ACCUMULO_GRAPH_WITH_ENTITIES)).schema(new Schema.Builder().merge(schema.clone()).edges(Collections.emptyMap()).build()).properties(PROPERTIES).build());
} catch (final StorageException e) {
throw new StoreException(e.getMessage(), e);
}
}
use of uk.gov.gchq.gaffer.federatedstore.exception.StorageException in project Gaffer by gchq.
the class FederatedGraphStorageTest method shouldNotAddGraphWhenLibraryThrowsExceptionDuringAdd.
@Test
public void shouldNotAddGraphWhenLibraryThrowsExceptionDuringAdd() throws Exception {
// given
GraphLibrary mock = mock(GraphLibrary.class);
String testMockException = "testMockException";
String graphId = a.getDeserialisedConfig().getGraphId();
Mockito.doThrow(new RuntimeException(testMockException)).when(mock).checkExisting(graphId, a.getDeserialisedSchema(), a.getDeserialisedProperties());
graphStorage.setGraphLibrary(mock);
try {
graphStorage.put(a, access);
fail(EXCEPTION_EXPECTED);
} catch (final Exception e) {
assertTrue(e instanceof StorageException);
assertEquals(testMockException, e.getCause().getMessage());
}
try {
// when
graphStorage.get(testUser, Lists.newArrayList(graphId));
fail(EXCEPTION_EXPECTED);
} catch (final IllegalArgumentException e) {
// then
assertEquals(String.format(GRAPH_IDS_NOT_VISIBLE, Arrays.toString(new String[] { graphId })), e.getMessage());
}
}
use of uk.gov.gchq.gaffer.federatedstore.exception.StorageException in project Gaffer by gchq.
the class FederatedGraphStorage method put.
/**
* places a graph into storage, protected by the given access.
* <p> GraphId can't already exist, otherwise {@link
* OverwritingException} is thrown.
* <p> Access can't be null otherwise {@link IllegalArgumentException} is
* thrown
*
* @param graph the graph to add to the storage.
* @param access access required to for the graph.
* @throws StorageException if unable to put arguments into storage
*/
public void put(final GraphSerialisable graph, final FederatedAccess access) throws StorageException {
if (graph != null) {
String graphId = graph.getDeserialisedConfig().getGraphId();
try {
if (null == access) {
throw new IllegalArgumentException(ACCESS_IS_NULL);
}
if (null != graphLibrary) {
graphLibrary.checkExisting(graphId, graph.getDeserialisedSchema(), graph.getDeserialisedProperties());
}
validateExisting(graph);
final Graph builtGraph = graph.getGraph();
if (isCacheEnabled()) {
addToCache(builtGraph, access);
}
Set<Graph> existingGraphs = storage.get(access);
if (null == existingGraphs) {
existingGraphs = Sets.newHashSet(builtGraph);
storage.put(access, existingGraphs);
} else {
existingGraphs.add(builtGraph);
}
} catch (final Exception e) {
throw new StorageException("Error adding graph " + graphId + " to storage due to: " + e.getMessage(), e);
}
} else {
throw new StorageException("Graph cannot be null");
}
}
use of uk.gov.gchq.gaffer.federatedstore.exception.StorageException 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;
}
Aggregations