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;
}
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);
}
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 + ".");
}
}
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);
}
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());
}
Aggregations