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