Search in sources :

Example 16 with FileGraphLibrary

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

the class AddUpdateTableIteratorTest method shouldRunMainWithNoGraphLibrary.

@Test
public void shouldRunMainWithNoGraphLibrary() throws Exception {
    // Given
    final String[] args = { GRAPH_ID, SCHEMA_DIR, STORE_PROPS_PATH, "update" };
    // When
    AddUpdateTableIterator.main(args);
    // Then - no exceptions
    final Pair<Schema, StoreProperties> pair = new FileGraphLibrary(FILE_GRAPH_LIBRARY_TEST_PATH).get(GRAPH_ID);
    assertNull(pair, "Graph should not have been stored");
}
Also used : FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 17 with FileGraphLibrary

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

the class AddUpdateTableIteratorTest method shouldRunMainWithFileGraphLibrary.

@Test
public void shouldRunMainWithFileGraphLibrary() throws Exception {
    // Given
    final String[] args = { GRAPH_ID, SCHEMA_DIR, STORE_PROPS_PATH, "update", FILE_GRAPH_LIBRARY_TEST_PATH };
    // When
    AddUpdateTableIterator.main(args);
    // Then
    final Pair<Schema, StoreProperties> pair = new FileGraphLibrary(FILE_GRAPH_LIBRARY_TEST_PATH).get(GRAPH_ID);
    assertNotNull(pair, "Graph for " + GRAPH_ID + " was not found");
    assertNotNull(pair.getFirst(), "Schema not found");
    assertNotNull(pair.getSecond(), "Store properties not found");
    JsonAssert.assertEquals(Schema.fromJson(Paths.get(SCHEMA_DIR)).toJson(false), pair.getFirst().toJson(false));
    assertEquals(AccumuloProperties.loadStoreProperties(STORE_PROPS_PATH).getProperties(), pair.getSecond().getProperties());
}
Also used : FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 18 with FileGraphLibrary

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

the class AddUpdateTableIteratorTest method shouldOverrideExistingGraphInGraphLibrary.

@Test
public void shouldOverrideExistingGraphInGraphLibrary() throws Exception {
    // Given
    // load version graph version 1 into the library.
    shouldRunMainWithFileGraphLibrary();
    final String[] args = { GRAPH_ID, SCHEMA_2_DIR, STORE_PROPS_2_PATH, "update", FILE_GRAPH_LIBRARY_TEST_PATH };
    // When
    AddUpdateTableIterator.main(args);
    // Then
    final Pair<Schema, StoreProperties> pair = new FileGraphLibrary(FILE_GRAPH_LIBRARY_TEST_PATH).get(GRAPH_ID);
    assertNotNull(pair, "Graph for " + GRAPH_ID + " was not found");
    assertNotNull(pair.getFirst(), "Schema not found");
    assertNotNull(pair.getSecond(), "Store properties not found");
    JsonAssert.assertEquals(Schema.fromJson(Paths.get(SCHEMA_2_DIR)).toJson(false), pair.getFirst().toJson(false));
    assertEquals(AccumuloProperties.loadStoreProperties(STORE_PROPS_2_PATH).getProperties(), pair.getSecond().getProperties());
}
Also used : FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 19 with FileGraphLibrary

use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary 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)

Example 20 with FileGraphLibrary

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

the class TableUtilsTest method shouldRunMainWithNoGraphLibrary.

@Test
public void shouldRunMainWithNoGraphLibrary() throws Exception {
    // Given
    final String[] args = { GRAPH_ID, SCHEMA_DIR, STORE_PROPS_PATH };
    // When
    TableUtils.main(args);
    // Then - no exceptions
    final Pair<Schema, StoreProperties> pair = new FileGraphLibrary(FILE_GRAPH_LIBRARY_TEST_PATH).get(GRAPH_ID);
    assertNull(pair, "Graph should not have been stored");
}
Also used : FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

FileGraphLibrary (uk.gov.gchq.gaffer.store.library.FileGraphLibrary)20 Schema (uk.gov.gchq.gaffer.store.schema.Schema)16 Test (org.junit.jupiter.api.Test)15 GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)13 ExportToOtherAuthorisedGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph)9 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)6 Graph (uk.gov.gchq.gaffer.graph.Graph)4 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)3 ArrayList (java.util.ArrayList)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 ExportToOtherGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph)2 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)2 NoGraphLibrary (uk.gov.gchq.gaffer.store.library.NoGraphLibrary)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 IsTrue (uk.gov.gchq.koryphe.impl.predicate.IsTrue)2 File (java.io.File)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1 TableName (org.apache.hadoop.hbase.TableName)1