Search in sources :

Example 6 with FileGraphLibrary

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

the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths.

@Test
public void shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths(@TempDir Path tmpPath) {
    GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
    // Given
    Schema schema1 = new Schema.Builder().build();
    graphLibrary.addOrUpdate(GRAPH_ID + 1, schema, storeProperties);
    graphLibrary.addSchema(SCHEMA_ID_1, schema1);
    given(store.getGraphLibrary()).willReturn(graphLibrary);
    List<String> opAuths = Lists.newArrayList("auth1");
    idAuths.put(GRAPH_ID + 2, opAuths);
    idAuths.put(SCHEMA_ID_1, opAuths);
    idAuths.put(STORE_PROPS_ID, opAuths);
    final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentStorePropertiesId(STORE_PROPS_ID).build();
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("parentSchemaIds must be specified with parentStorePropertiesId");
}
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) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.jupiter.api.Test)

Example 7 with FileGraphLibrary

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

the class TableUtilsTest 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, FILE_GRAPH_LIBRARY_TEST_PATH };
    // When
    TableUtils.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(HBaseProperties.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 8 with FileGraphLibrary

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

the class TableUtilsTest method shouldRunMainWithFileGraphLibrary.

@Test
public void shouldRunMainWithFileGraphLibrary() throws Exception {
    // Given
    final String[] args = { GRAPH_ID, SCHEMA_DIR, STORE_PROPS_PATH, FILE_GRAPH_LIBRARY_TEST_PATH };
    // When
    TableUtils.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(HBaseProperties.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 9 with FileGraphLibrary

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

the class ExportToOtherGraphHandlerTest method before.

@BeforeEach
public void before() throws IOException {
    storeProperties = StoreProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
    storeProperties.set(HashMapCacheService.STATIC_CACHE, String.valueOf(false));
    final File graphLibraryFolder = tempDir.resolve("graphLibrary").toFile();
    graphLibrary = new FileGraphLibrary(graphLibraryFolder.getPath());
    given(store.getGraphLibrary()).willReturn(graphLibrary);
    given(store.getGraphId()).willReturn(GRAPH_ID);
}
Also used : FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with FileGraphLibrary

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

the class AddUpdateTableIterator method main.

/**
 * Utility for creating and updating an Accumulo table.
 * Accumulo tables are automatically created when the Gaffer Accumulo store
 * is initialised when an instance of Graph is created.
 * <p>
 * Running this with an existing table will remove the existing iterators
 * and recreate them with the provided schema.
 * </p>
 * <p>
 * A FileGraphLibrary path must be specified as an argument.  If no path is set NoGraphLibrary will be used.
 * </p>
 * <p>
 * Usage: java -cp accumulo-store-[version]-utility.jar uk.gov.gchq.gaffer.accumulostore.utils.AddUpdateTableIterator [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> " + "<comma separated schema paths> <store properties path> " + "<" + ADD_KEY + "," + REMOVE_KEY + " or " + UPDATE_KEY + "> " + "<file graph library path>");
        System.exit(1);
    }
    final AccumuloProperties storeProps = AccumuloProperties.loadStoreProperties(getAccumuloPropertiesPath(args));
    if (null == storeProps) {
        throw new IllegalArgumentException("Store properties are required to create a store");
    }
    final Schema schema = Schema.fromJson(getSchemaPaths(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 AccumuloStore store;
    try {
        store = Class.forName(storeClass).asSubclass(AccumuloStore.class).newInstance();
    } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new IllegalArgumentException("Could not create store of type: " + storeClass, e);
    }
    try {
        store.preInitialise(getGraphId(args), schema, storeProps);
    } catch (final StoreException e) {
        throw new IllegalArgumentException("Could not initialise the store with provided arguments.", e);
    }
    if (!store.getConnection().tableOperations().exists(store.getTableName())) {
        TableUtils.createTable(store);
    }
    final String modifyKey = getModifyKey(args);
    switch(modifyKey) {
        case UPDATE_KEY:
            for (final String iterator : ITERATORS) {
                updateIterator(store, iterator);
            }
            break;
        case ADD_KEY:
            for (final String iterator : ITERATORS) {
                addIterator(store, iterator);
            }
            break;
        case REMOVE_KEY:
            for (final String iterator : ITERATORS) {
                removeIterator(store, iterator);
            }
            break;
        default:
            throw new IllegalArgumentException("Supplied add or update key (" + modifyKey + ") was not valid, it must either be " + ADD_KEY + "," + REMOVE_KEY + " or " + UPDATE_KEY + ".");
    }
}
Also used : AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreException(uk.gov.gchq.gaffer.store.StoreException) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) AccumuloStore(uk.gov.gchq.gaffer.accumulostore.AccumuloStore)

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