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