use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWhenGraphIdCannotBeFound.
@Test
public void shouldThrowExceptionWhenGraphIdCannotBeFound(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> graphIdAuths = new ArrayList<>();
graphIdAuths.add("auth1");
idAuths.put(GRAPH_ID + 1, graphIdAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 1).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("GraphLibrary cannot be found with graphId");
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class FederatedStoreTest method shouldThrowWithPropertiesErrorFromGraphLibrary.
@Test
public void shouldThrowWithPropertiesErrorFromGraphLibrary() throws Exception {
Builder schema = new Builder();
for (String path : new String[] { PATH_BASIC_EDGE_SCHEMA_JSON }) {
schema.merge(getSchemaFromPath(path));
}
final GraphLibrary mockLibrary = Mockito.mock(GraphLibrary.class);
final String error = "test Something went wrong";
Mockito.when(mockLibrary.getProperties(ID_PROPS_ACC_2)).thenThrow(new IllegalArgumentException(error));
store.setGraphLibrary(mockLibrary);
clearCache();
store.initialise(FEDERATED_STORE_ID, null, federatedProperties);
try {
store.execute(new AddGraph.Builder().graphId(ACC_ID_2).parentPropertiesId(ID_PROPS_ACC_2).isPublic(true).schema(schema.build()).build(), userContext);
fail("exception not thrown");
} catch (Exception e) {
assertEquals(error, e.getCause().getMessage());
}
Mockito.verify(mockLibrary).getProperties(ID_PROPS_ACC_2);
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class FederatedGraphStorageTest method shouldNotAddGraphWhenLibraryThrowsExceptionDuringAdd.
@Test
public void shouldNotAddGraphWhenLibraryThrowsExceptionDuringAdd() throws Exception {
// given
GraphLibrary mock = mock(GraphLibrary.class);
String testMockException = "testMockException";
String graphId = a.getDeserialisedConfig().getGraphId();
Mockito.doThrow(new RuntimeException(testMockException)).when(mock).checkExisting(graphId, a.getDeserialisedSchema(), a.getDeserialisedProperties());
graphStorage.setGraphLibrary(mock);
try {
graphStorage.put(a, access);
fail(EXCEPTION_EXPECTED);
} catch (final Exception e) {
assertTrue(e instanceof StorageException);
assertEquals(testMockException, e.getCause().getMessage());
}
try {
// when
graphStorage.get(testUser, Lists.newArrayList(graphId));
fail(EXCEPTION_EXPECTED);
} catch (final IllegalArgumentException e) {
// then
assertEquals(String.format(GRAPH_IDS_NOT_VISIBLE, Arrays.toString(new String[] { graphId })), e.getMessage());
}
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.
the class DefaultGraphFactory method createGraphBuilder.
@Override
public Graph.Builder createGraphBuilder() {
final String storePropertiesPath = System.getProperty(SystemProperty.STORE_PROPERTIES_PATH);
if (null == storePropertiesPath) {
throw new SchemaException("The path to the Store Properties was not found in system properties for key: " + SystemProperty.STORE_PROPERTIES_PATH);
}
final StoreProperties storeProperties = StoreProperties.loadStoreProperties(storePropertiesPath);
// Disable any operations required
storeProperties.addOperationDeclarationPaths("disableOperations.json");
final Graph.Builder builder = new Graph.Builder();
builder.storeProperties(storeProperties);
final String graphConfigPath = System.getProperty(SystemProperty.GRAPH_CONFIG_PATH);
if (null != graphConfigPath) {
builder.config(Paths.get(graphConfigPath));
}
for (final Path path : getSchemaPaths()) {
builder.addSchema(path);
}
final String graphId = System.getProperty(SystemProperty.GRAPH_ID);
if (null != graphId) {
builder.graphId(graphId);
}
String graphLibraryClassName = System.getProperty(SystemProperty.GRAPH_LIBRARY_CLASS);
if (null != graphLibraryClassName) {
GraphLibrary library;
try {
library = Class.forName(graphLibraryClassName).asSubclass(GraphLibrary.class).newInstance();
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Error creating GraphLibrary class", e);
}
library.initialise(System.getProperty(SystemProperty.GRAPH_LIBRARY_CONFIG));
builder.library(library);
}
final String graphHooksPath = System.getProperty(SystemProperty.GRAPH_HOOKS_PATH);
if (null != graphHooksPath) {
builder.addHooks(Paths.get(graphHooksPath));
}
return builder;
}
use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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);
}
}
}
Aggregations