Search in sources :

Example 21 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWhenGraphIdCannotBeFound.

@Test
public void shouldThrowExceptionWhenGraphIdCannotBeFound(@TempDir Path tmpPath) {
    GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
    // Given
    given(store.getGraphLibrary()).willReturn(graphLibrary);
    List<String> graphIdAuths = new ArrayList<>();
    graphIdAuths.add("auth1");
    idAuths.put(GRAPH_ID + 1, graphIdAuths);
    final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 1).build();
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("GraphLibrary cannot be found with graphId");
}
Also used : ExportToOtherAuthorisedGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 22 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class FederatedStoreTest method shouldThrowWithPropertiesErrorFromGraphLibrary.

@Test
public void shouldThrowWithPropertiesErrorFromGraphLibrary() throws Exception {
    Builder schema = new Builder();
    for (String path : new String[] { PATH_BASIC_EDGE_SCHEMA_JSON }) {
        schema.merge(getSchemaFromPath(path));
    }
    final GraphLibrary mockLibrary = Mockito.mock(GraphLibrary.class);
    final String error = "test Something went wrong";
    Mockito.when(mockLibrary.getProperties(ID_PROPS_ACC_2)).thenThrow(new IllegalArgumentException(error));
    store.setGraphLibrary(mockLibrary);
    clearCache();
    store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
    try {
        store.execute(new AddGraph.Builder().graphId(ACC_ID_2).parentPropertiesId(ID_PROPS_ACC_2).isPublic(true).schema(schema.build()).build(), userContext);
        fail("exception not thrown");
    } catch (Exception e) {
        assertEquals(error, e.getCause().getMessage());
    }
    Mockito.verify(mockLibrary).getProperties(ID_PROPS_ACC_2);
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreException(uk.gov.gchq.gaffer.store.StoreException) FederatedGetTraitsHandlerTest(uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest) Test(org.junit.jupiter.api.Test)

Example 23 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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 24 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class DefaultGraphFactory method createGraphBuilder.

@Override
public Graph.Builder createGraphBuilder() {
    final String storePropertiesPath = System.getProperty(SystemProperty.STORE_PROPERTIES_PATH);
    if (null == storePropertiesPath) {
        throw new SchemaException("The path to the Store Properties was not found in system properties for key: " + SystemProperty.STORE_PROPERTIES_PATH);
    }
    final StoreProperties storeProperties = StoreProperties.loadStoreProperties(storePropertiesPath);
    // Disable any operations required
    storeProperties.addOperationDeclarationPaths("disableOperations.json");
    final Graph.Builder builder = new Graph.Builder();
    builder.storeProperties(storeProperties);
    final String graphConfigPath = System.getProperty(SystemProperty.GRAPH_CONFIG_PATH);
    if (null != graphConfigPath) {
        builder.config(Paths.get(graphConfigPath));
    }
    for (final Path path : getSchemaPaths()) {
        builder.addSchema(path);
    }
    final String graphId = System.getProperty(SystemProperty.GRAPH_ID);
    if (null != graphId) {
        builder.graphId(graphId);
    }
    String graphLibraryClassName = System.getProperty(SystemProperty.GRAPH_LIBRARY_CLASS);
    if (null != graphLibraryClassName) {
        GraphLibrary library;
        try {
            library = Class.forName(graphLibraryClassName).asSubclass(GraphLibrary.class).newInstance();
        } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new RuntimeException("Error creating GraphLibrary class", e);
        }
        library.initialise(System.getProperty(SystemProperty.GRAPH_LIBRARY_CONFIG));
        builder.library(library);
    }
    final String graphHooksPath = System.getProperty(SystemProperty.GRAPH_HOOKS_PATH);
    if (null != graphHooksPath) {
        builder.addHooks(Paths.get(graphHooksPath));
    }
    return builder;
}
Also used : Path(java.nio.file.Path) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Graph(uk.gov.gchq.gaffer.graph.Graph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 25 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class TableUtils method main.

/**
 * Utility for creating and updating an HBase table.
 * See the HBase Store README for more information on what changes to your schema you are allowed to make.
 * HBase tables are automatically created when the Gaffer HBase store is initialised when an instance of Graph is created.
 * <p>
 * Running this with an existing table will remove the existing Gaffer Coprocessor and recreate it.
 * </p>
 * <p>
 * A FileGraphLibrary path must be specified as an argument.  If no path is set NoGraphLibrary will be used.
 * </p>
 * <p>
 * Usage:
 * </p>
 * <p>
 * java -cp hbase-store-[version]-utility.jar uk.gov.gchq.gaffer.hbasestore.utils.TableUtils [graphId] [pathToSchemaDirectory] [pathToStoreProperties] [pathToFileGraphLibrary]
 * </p>
 *
 * @param args [graphId] [schema directory path] [store properties path] [ file graph library path]
 * @throws Exception if the tables fails to be created/updated
 */
public static void main(final String[] args) throws Exception {
    if (args.length < NUM_REQUIRED_ARGS) {
        System.err.println("Wrong number of arguments. \nUsage: " + "<graphId> <schema directory path> <store properties path> <file graph library path>");
        System.exit(1);
    }
    final HBaseProperties storeProps = HBaseProperties.loadStoreProperties(getStorePropertiesPathString(args));
    if (null == storeProps) {
        throw new IllegalArgumentException("Store properties are required to create a store");
    }
    final Schema schema = Schema.fromJson(getSchemaDirectoryPath(args));
    GraphLibrary library;
    if (null == getFileGraphLibraryPathString(args)) {
        library = new NoGraphLibrary();
    } else {
        library = new FileGraphLibrary(getFileGraphLibraryPathString(args));
    }
    library.addOrUpdate(getGraphId(args), schema, storeProps);
    final String storeClass = storeProps.getStoreClass();
    if (null == storeClass) {
        throw new IllegalArgumentException("The Store class name was not found in the store properties for key: " + StoreProperties.STORE_CLASS);
    }
    final HBaseStore store;
    try {
        store = Class.forName(storeClass).asSubclass(HBaseStore.class).newInstance();
    } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new IllegalArgumentException("Could not create store of type: " + storeClass, e);
    }
    store.preInitialise(getGraphId(args), schema, storeProps);
    if (!store.getConnection().getAdmin().tableExists(store.getTableName())) {
        createTable(store);
    }
    try (final Admin admin = store.getConnection().getAdmin()) {
        final TableName tableName = store.getTableName();
        if (admin.tableExists(tableName)) {
            final HTableDescriptor descriptor = admin.getTableDescriptor(tableName);
            descriptor.removeCoprocessor(GafferCoprocessor.class.getName());
            addCoprocesssor(descriptor, store);
            admin.modifyTable(tableName, descriptor);
        } else {
            TableUtils.createTable(store);
        }
    }
}
Also used : HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) TableName(org.apache.hadoop.hbase.TableName) GafferCoprocessor(uk.gov.gchq.gaffer.hbasestore.coprocessor.GafferCoprocessor) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) HBaseProperties(uk.gov.gchq.gaffer.hbasestore.HBaseProperties)

Aggregations

GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)26 Test (org.junit.jupiter.api.Test)17 Schema (uk.gov.gchq.gaffer.store.schema.Schema)14 FileGraphLibrary (uk.gov.gchq.gaffer.store.library.FileGraphLibrary)13 ExportToOtherAuthorisedGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph)9 Graph (uk.gov.gchq.gaffer.graph.Graph)7 HashMapGraphLibrary (uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary)7 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)5 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)3 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)3 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 ArrayList (java.util.ArrayList)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)2 FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)2 NamedViewResolver (uk.gov.gchq.gaffer.graph.hook.NamedViewResolver)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2