Search in sources :

Example 6 with StorageException

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);
    }
}
Also used : GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) Test(org.junit.jupiter.api.Test)

Example 7 with StorageException

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);
    }
}
Also used : GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 8 with StorageException

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());
    }
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 9 with StorageException

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");
    }
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) OverwritingException(uk.gov.gchq.gaffer.commonutil.exception.OverwritingException) CacheOperationException(uk.gov.gchq.gaffer.cache.exception.CacheOperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 10 with StorageException

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;
}
Also used : User(uk.gov.gchq.gaffer.user.User) GraphSerialisable(uk.gov.gchq.gaffer.graph.GraphSerialisable) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FederatedStore(uk.gov.gchq.gaffer.federatedstore.FederatedStore)

Aggregations

StorageException (uk.gov.gchq.gaffer.federatedstore.exception.StorageException)10 GraphSerialisable (uk.gov.gchq.gaffer.graph.GraphSerialisable)8 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 Test (org.junit.jupiter.api.Test)4 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)3 Graph (uk.gov.gchq.gaffer.graph.Graph)3 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 OverwritingException (uk.gov.gchq.gaffer.commonutil.exception.OverwritingException)2 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)2 StoreException (uk.gov.gchq.gaffer.store.StoreException)2 GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)2 Connector (org.apache.accumulo.core.client.Connector)1 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)1 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)1 AccumuloStore (uk.gov.gchq.gaffer.accumulostore.AccumuloStore)1