Search in sources :

Example 11 with GraphLibrary

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

the class GraphDelegate method resolveStorePropertiesForGraph.

protected StoreProperties resolveStorePropertiesForGraph(final Store store, final StoreProperties properties, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) {
    StoreProperties resultProps;
    if (null != existingGraphPair) {
        // If there is an existing graph then ignore any user provided properties and just use the existing properties
        resultProps = existingGraphPair.getSecond();
    } else {
        final GraphLibrary graphLibrary = store.getGraphLibrary();
        resultProps = (null == graphLibrary) ? properties : graphLibrary.resolveStoreProperties(properties, parentStorePropertiesId);
    }
    return resultProps;
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 12 with GraphLibrary

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

the class StoreTest method shouldSetAndGetGraphLibrary.

@Test
public void shouldSetAndGetGraphLibrary() {
    // Given
    final Store store = new StoreImpl();
    final GraphLibrary graphLibrary = mock(GraphLibrary.class);
    // When
    store.setGraphLibrary(graphLibrary);
    final GraphLibrary result = store.getGraphLibrary();
    // Then
    assertSame(graphLibrary, result);
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Test(org.junit.jupiter.api.Test)

Example 13 with GraphLibrary

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

Example 14 with GraphLibrary

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

the class FederatedStoreTest method shouldThrowWithSchemaErrorFromGraphLibrary.

@Test
public void shouldThrowWithSchemaErrorFromGraphLibrary() throws Exception {
    // Given
    final GraphLibrary mockLibrary = Mockito.mock(GraphLibrary.class);
    final String error = "test Something went wrong";
    Mockito.when(mockLibrary.getSchema(ID_SCHEMA_ENTITY)).thenThrow(new IllegalArgumentException(error));
    store.setGraphLibrary(mockLibrary);
    clearCache();
    store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
    // When / Then
    try {
        store.execute(new AddGraph.Builder().graphId(ACC_ID_2).storeProperties(PROPERTIES_ALT).isPublic(true).parentSchemaIds(Lists.newArrayList(ID_SCHEMA_ENTITY)).build(), userContext);
        fail(EXCEPTION_NOT_THROWN);
    } catch (Exception e) {
        assertEquals(error, e.getCause().getMessage());
    }
    Mockito.verify(mockLibrary).getSchema(ID_SCHEMA_ENTITY);
}
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 15 with GraphLibrary

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

the class GraphTest method shouldBuildGraphFromConfigAndOverrideFields.

@Test
public void shouldBuildGraphFromConfigAndOverrideFields() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final String graphId1 = "graphId1";
    final String graphId2 = "graphId2";
    final GraphLibrary library1 = mock(GraphLibrary.class);
    final GraphLibrary library2 = mock(GraphLibrary.class);
    final View view1 = new View.Builder().entity(TestGroups.ENTITY).build();
    final View view2 = new View.Builder().edge(TestGroups.EDGE).build();
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final GraphHook hook3 = mock(GraphHook.class);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId(graphId2).library(library2).addHook(hook2).view(view2).build();
    final Graph graph = new Graph.Builder().config(config).graphId(graphId1).library(library1).view(view1).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(hook1).addHook(hook3).build();
    // Then
    assertEquals(graphId1, graph.getGraphId());
    assertEquals(view1, graph.getView());
    assertEquals(library1, graph.getGraphLibrary());
    assertEquals(Arrays.asList(NamedViewResolver.class, hook2.getClass(), hook1.getClass(), hook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

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