From 338fe55c95be78ec0c3d79d30b045ec53257a18e Mon Sep 17 00:00:00 2001 From: tb06904 <141412860+tb06904@users.noreply.github.com> Date: Thu, 23 Jan 2025 10:30:25 +0000 Subject: [PATCH] move back to serialisables --- .../java/uk/gov/gchq/gaffer/graph/Graph.java | 9 -- .../federated/simple/FederatedStore.java | 76 +++++-------- .../federated/simple/FederatedUtils.java | 8 +- .../handler/FederatedOperationHandler.java | 18 +-- .../handler/FederatedOutputHandler.java | 12 +- .../handler/SeparateOutputHandler.java | 8 +- .../handler/add/AddGraphHandler.java | 2 +- .../handler/get/GetSchemaHandler.java | 14 +-- .../federated/simple/FederatedStoreTest.java | 62 ++++------ .../federated/simple/FederatedUtilsTest.java | 107 ++++++------------ .../simple/PreDefinedFederatedStore.java | 21 +--- .../simple/operation/AddGraphTest.java | 5 +- .../simple/operation/ChangeGraphIdTest.java | 20 ++-- .../simple/operation/GetSchemaTest.java | 26 +---- 14 files changed, 136 insertions(+), 252 deletions(-) diff --git a/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/Graph.java b/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/Graph.java index 1cdbc8ec356..87d5af0eec2 100644 --- a/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/Graph.java +++ b/core/graph/src/main/java/uk/gov/gchq/gaffer/graph/Graph.java @@ -470,15 +470,6 @@ public List> getGraphHooks() { return config.getHooks().stream().map(GraphHook::getClass).collect(Collectors.toList()); } - /** - * Returns the {@link Store} for this graph. - * - * @return The store - */ - public Store getStore() { - return store; - } - /** * @return a collection of all the supported {@link Operation}s. */ diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedStore.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedStore.java index cf1d4d7d070..1c1a3f49b27 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedStore.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedStore.java @@ -50,11 +50,7 @@ import uk.gov.gchq.gaffer.federated.simple.operation.handler.misc.ChangeGraphAccessHandler; import uk.gov.gchq.gaffer.federated.simple.operation.handler.misc.ChangeGraphIdHandler; import uk.gov.gchq.gaffer.federated.simple.operation.handler.misc.RemoveGraphHandler; -import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphSerialisable; -import uk.gov.gchq.gaffer.graph.hook.GraphHook; -import uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver; -import uk.gov.gchq.gaffer.graph.hook.NamedViewResolver; import uk.gov.gchq.gaffer.named.operation.AddNamedOperation; import uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation; import uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations; @@ -134,7 +130,7 @@ public class FederatedStore extends Store { // Quick access in memory cache of graphs added to this instance whist it was running. // Will use this first then resort to the full graph cache if not found. - private final Map> quickAccessGraphs = new HashMap<>(); + private final Map> quickAccessGraphs = new HashMap<>(); // Gaffer cache of available graphs private Cache> graphCache; @@ -160,21 +156,20 @@ public class FederatedStore extends Store { * * @throws IllegalArgumentException If there is already a graph with the supplied ID */ - public void addGraph(final Graph graph, final GraphAccess graphAccess) { + public void addGraph(final GraphSerialisable graph, final GraphAccess graphAccess) { String graphId = graph.getGraphId(); LOGGER.debug("Adding Graph: '{}'", graphId); // Pair the graph with its access - Pair graphAndAccessPair = new ImmutablePair<>(graph, graphAccess); - Pair gsAndAccessPair = new ImmutablePair<>(new GraphSerialisable(graph), graphAccess); + Pair graphAndAccessPair = new ImmutablePair<>(graph, graphAccess); try { // Add safely to the cache - graphCache.getCache().putSafe(graphId, gsAndAccessPair); + graphCache.getCache().putSafe(graphId, graphAndAccessPair); // Add to quick access if (quickAccessGraphs.containsKey(graphId)) { throw new OverwritingException("Graph with ID: '" + graphId + "' already exists"); + } else { + quickAccessGraphs.put(graphId, graphAndAccessPair); } - - quickAccessGraphs.put(graphId, graphAndAccessPair); } catch (final CacheOperationException e) { // Unknown issue adding to cache throw new GafferRuntimeException(e.getMessage(), e); @@ -211,7 +206,7 @@ public void removeGraph(final String graphId) { * @throws CacheOperationException If issue getting from cache. * @throws IllegalArgumentException If graph not found. */ - public Graph getGraph(final String graphId) throws CacheOperationException { + public GraphSerialisable getGraph(final String graphId) throws CacheOperationException { return getGraphAccessPair(graphId).getLeft(); } @@ -237,7 +232,7 @@ public GraphAccess getGraphAccess(final String graphId) throws CacheOperationExc * @throws CacheOperationException If issue getting from cache. * @throws IllegalArgumentException If graph not found. */ - public Pair getGraphAccessPair(final String graphId) throws CacheOperationException { + public Pair getGraphAccessPair(final String graphId) throws CacheOperationException { if (quickAccessGraphs.containsKey(graphId)) { return quickAccessGraphs.get(graphId); } @@ -248,16 +243,9 @@ public Pair getGraphAccessPair(final String graphId) throws String.format(GRAPH_ID_ERROR, graphId)); } // Save to quick access for next time - Graph graph = new Graph.Builder() - .config(graphAndAccess.getLeft().getConfig()) - .addSchema(graphAndAccess.getLeft().getSchema()) - .storeProperties(graphAndAccess.getLeft().getStoreProperties()) - .addToLibrary(false) - .build(); - Pair pair = new ImmutablePair<>(graph, graphAndAccess.getRight()); - quickAccessGraphs.putIfAbsent(graphId, pair); - - return pair; + quickAccessGraphs.putIfAbsent(graphId, graphAndAccess); + + return graphAndAccess; } /** @@ -308,8 +296,8 @@ public void setDefaultGraphIds(final List defaultGraphIds) { */ public void changeGraphId(final String graphToUpdateId, final String newGraphId) throws StoreException, CacheOperationException { // Get existing graph and access - final Pair graphPairToUpdate = getGraphAccessPair(graphToUpdateId); - final Graph graphToUpdate = graphPairToUpdate.getLeft(); + final Pair graphPairToUpdate = getGraphAccessPair(graphToUpdateId); + final GraphSerialisable graphToUpdate = graphPairToUpdate.getLeft(); final GraphAccess graphAccess = graphPairToUpdate.getRight(); // Remove from cache @@ -318,28 +306,18 @@ public void changeGraphId(final String graphToUpdateId, final String newGraphId) // For accumulo update the table with the new graph ID if (graphToUpdate.getStoreProperties().getStoreClass().startsWith(AccumuloStore.class.getPackage().getName())) { renameTable((AccumuloProperties) graphToUpdate.getStoreProperties(), graphToUpdateId, newGraphId); + // Update id in the original graph + graphToUpdate.getConfig().setGraphId(newGraphId); + GraphSerialisable updatedGraphSerialisable = new GraphSerialisable.Builder(graphToUpdate) + .config(graphToUpdate.getConfig()) + .build(); + // Add graph with new id back to cache + addGraph(updatedGraphSerialisable, graphAccess); + } else { + // For other stores just re-add with new graph ID + graphToUpdate.getConfig().setGraphId(newGraphId); + addGraph(graphToUpdate, graphAccess); } - - // Need to remove old cache hooks in the config so the hooks update with the correct suffix - List graphHooks = new ArrayList<>(graphToUpdate - .getConfig() - .getHooks()); - graphHooks.removeIf(NamedViewResolver.class::isInstance); - graphHooks.removeIf(NamedOperationResolver.class::isInstance); - graphToUpdate.getConfig().setHooks(null); - graphToUpdate.getConfig().setHooks(graphHooks); - - // Re-initialise so the store reference gets updated with the new ID - graphToUpdate.getConfig().setGraphId(newGraphId); - Graph updatedGraph = new Graph.Builder() - .config(graphToUpdate.getConfig()) - .addSchema(graphToUpdate.getSchema()) - .storeProperties(graphToUpdate.getStoreProperties()) - .store(graphToUpdate.getStore()) - .build(); - - // Add graph with new id back to cache - addGraph(updatedGraph, graphAccess); } /** @@ -351,12 +329,10 @@ public void changeGraphId(final String graphToUpdateId, final String newGraphId) * @throws CacheOperationException If issue updating the cache. */ public void changeGraphAccess(final String graphId, final GraphAccess newAccess) throws CacheOperationException { - final Graph graph = getGraph(graphId); // Create the new pairs - final Pair graphAndAccessPair = new ImmutablePair<>(graph, newAccess); - final Pair gsAndAccessPair = new ImmutablePair<>(new GraphSerialisable(graph), newAccess); + final Pair graphAndAccessPair = new ImmutablePair<>(getGraph(graphId), newAccess); // Add to the cache this will overwrite any existing value - graphCache.getCache().put(graphId, gsAndAccessPair); + graphCache.getCache().put(graphId, graphAndAccessPair); // Add to quick access quickAccessGraphs.put(graphId, graphAndAccessPair); } diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtils.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtils.java index 9e210c7882b..70c26ba4d29 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtils.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtils.java @@ -21,7 +21,7 @@ import uk.gov.gchq.gaffer.data.elementdefinition.view.View; import uk.gov.gchq.gaffer.federated.simple.operation.handler.FederatedOperationHandler; -import uk.gov.gchq.gaffer.graph.Graph; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.Operation; import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.graph.OperationView; @@ -50,7 +50,7 @@ private FederatedUtils() { * @param graphs Graphs to check. * @return Do they share groups. */ - public static boolean doGraphsShareGroups(final List graphs) { + public static boolean doGraphsShareGroups(final List graphs) { // Compare all schemas against each other for (int i = 0; i < graphs.size() - 1; i++) { for (int j = i + 1; j < graphs.size(); j++) { @@ -75,7 +75,7 @@ public static boolean doGraphsShareGroups(final List graphs) { * @param depthLimit Limit to the recursion depth. * @return A valid version of the operation chain. */ - public static OperationChain getValidOperationForGraph(final Operation operation, final Graph graph, final int depth, final int depthLimit) { + public static OperationChain getValidOperationForGraph(final Operation operation, final GraphSerialisable graph, final int depth, final int depthLimit) { LOGGER.debug("Creating valid operation for graph, depth is: {}", depth); final Collection updatedOperations = new ArrayList<>(); @@ -123,7 +123,7 @@ public static OperationChain getValidOperationForGraph(final Operation operation * @param graph The relevant graph. * @return A version of the view valid for the graph. */ - public static View getValidViewForGraph(final View view, final Graph graph) { + public static View getValidViewForGraph(final View view, final GraphSerialisable graph) { final Schema schema = graph.getSchema(); // Figure out all the groups relevant to the graph diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOperationHandler.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOperationHandler.java index 6edcc9507c4..9377f96d2d3 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOperationHandler.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOperationHandler.java @@ -24,8 +24,9 @@ import uk.gov.gchq.gaffer.federated.simple.FederatedStore; import uk.gov.gchq.gaffer.federated.simple.FederatedUtils; import uk.gov.gchq.gaffer.federated.simple.access.GraphAccess; -import uk.gov.gchq.gaffer.graph.Graph; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.Operation; +import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.operation.io.Output; import uk.gov.gchq.gaffer.store.Context; @@ -114,18 +115,17 @@ public Object doOperation(final P operation, final Context context, final Store return new FederatedOutputHandler<>().doOperation((Output) operation, context, store); } - List graphsToExecute = getGraphsToExecuteOn(operation, context, (FederatedStore) store); + List graphsToExecute = getGraphsToExecuteOn(operation, context, (FederatedStore) store); // No-op if (graphsToExecute.isEmpty()) { return null; } // Execute the operation chain on each graph - for (final Graph graph : graphsToExecute) { + for (final GraphSerialisable graph : graphsToExecute) { try { - graph.execute( - FederatedUtils.getValidOperationForGraph(operation, graph, 0, fixLimit), - context.getUser()); + OperationChain fixedChain = FederatedUtils.getValidOperationForGraph(operation, graph, 0, fixLimit); + graph.getGraph().execute(fixedChain, context.getUser()); } catch (final OperationException | UnsupportedOperationException | IllegalArgumentException e) { // Optionally skip this error if user has specified to do so LOGGER.error("Operation failed on graph: {}", graph.getGraphId()); @@ -154,11 +154,11 @@ public Object doOperation(final P operation, final Context context, final Store * @return List of {@link Graph}s to execute on. * @throws OperationException Fail to get Graphs. */ - protected List getGraphsToExecuteOn(final Operation operation, final Context context, + protected List getGraphsToExecuteOn(final Operation operation, final Context context, final FederatedStore store) throws OperationException { List specifiedGraphIds = new ArrayList<>(); - List graphsToExecute = new ArrayList<>(); + List graphsToExecute = new ArrayList<>(); // If user specified graph IDs for this chain parse as comma separated list if (operation.containsOption(OPT_SHORT_GRAPH_IDS)) { @@ -181,7 +181,7 @@ protected List getGraphsToExecuteOn(final Operation operation, final Cont // Get the corresponding graph serialisables for (final String id : specifiedGraphIds) { try { - Pair pair = store.getGraphAccessPair(id); + Pair pair = store.getGraphAccessPair(id); // Check the user has access to the graph if (pair.getRight().hasReadAccess(context.getUser(), store.getProperties().getAdminAuth())) { diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOutputHandler.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOutputHandler.java index 137563bd750..6e11b4cb4a1 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOutputHandler.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/FederatedOutputHandler.java @@ -24,7 +24,7 @@ import uk.gov.gchq.gaffer.federated.simple.merge.DefaultResultAccumulator; import uk.gov.gchq.gaffer.federated.simple.merge.FederatedResultAccumulator; import uk.gov.gchq.gaffer.federated.simple.operation.handler.get.GetSchemaHandler; -import uk.gov.gchq.gaffer.graph.Graph; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.operation.io.Output; @@ -50,7 +50,7 @@ public class FederatedOutputHandler

, O> @Override public O doOperation(final P operation, final Context context, final Store store) throws OperationException { final int fixLimit = Integer.parseInt(operation.getOption(OPT_FIX_OP_LIMIT, String.valueOf(DFLT_FIX_OP_LIMIT))); - List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); + List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); // No-op if (graphsToExecute.isEmpty()) { @@ -59,10 +59,10 @@ public O doOperation(final P operation, final Context context, final Store store // Execute the operation chain on each graph List graphResults = new ArrayList<>(); - for (final Graph graph : graphsToExecute) { + for (final GraphSerialisable graph : graphsToExecute) { try { OperationChain fixedChain = FederatedUtils.getValidOperationForGraph(operation, graph, 0, fixLimit); - graphResults.add(graph.execute(fixedChain, context.getUser())); + graphResults.add(graph.getGraph().execute(fixedChain, context.getUser())); } catch (final OperationException | UnsupportedOperationException | IllegalArgumentException e) { // Optionally skip this error if user has specified to do so LOGGER.error("Operation failed on graph: {}", graph.getGraphId()); @@ -110,7 +110,7 @@ public O doOperation(final P operation, final Context context, final Store store protected FederatedResultAccumulator getResultAccumulator( final P operation, final FederatedStore store, - final List graphsToExecute) throws OperationException { + final List graphsToExecute) throws OperationException { // Merge the store props with the operation options for setting up the // accumulator Properties combinedProps = store.getProperties().getProperties(); @@ -131,7 +131,7 @@ protected FederatedResultAccumulator getResultAccumulator( } // Set the merged schema if we are aggregating if (resultAccumulator.aggregateElements()) { - List schemas = graphsToExecute.stream().map(Graph::getSchema).collect(Collectors.toList()); + List schemas = graphsToExecute.stream().map(GraphSerialisable::getSchema).collect(Collectors.toList()); resultAccumulator.setSchema(GetSchemaHandler.getMergedSchema(schemas)); } diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/SeparateOutputHandler.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/SeparateOutputHandler.java index 86c05b3bcc3..8adf8767905 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/SeparateOutputHandler.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/SeparateOutputHandler.java @@ -21,7 +21,7 @@ import uk.gov.gchq.gaffer.federated.simple.FederatedStore; import uk.gov.gchq.gaffer.federated.simple.FederatedUtils; -import uk.gov.gchq.gaffer.graph.Graph; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.operation.io.Output; @@ -42,7 +42,7 @@ public class SeparateOutputHandler

, O> extends FederatedOper @Override public Map doOperation(final P operation, final Context context, final Store store) throws OperationException { final int fixLimit = Integer.parseInt(operation.getOption(OPT_FIX_OP_LIMIT, String.valueOf(DFLT_FIX_OP_LIMIT))); - List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); + List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); if (graphsToExecute.isEmpty()) { return new HashMap<>(); @@ -51,10 +51,10 @@ public Map doOperation(final P operation, final Context context, fina // Execute the operation chain on each graph LOGGER.debug("Returning separated graph results"); Map results = new HashMap<>(); - for (final Graph graph : graphsToExecute) { + for (final GraphSerialisable graph : graphsToExecute) { try { OperationChain fixedChain = FederatedUtils.getValidOperationForGraph(operation, graph, 0, fixLimit); - results.put(graph.getGraphId(), graph.execute(fixedChain, context.getUser())); + results.put(graph.getGraphId(), graph.getGraph().execute(fixedChain, context.getUser())); } catch (final OperationException | UnsupportedOperationException e) { // Optionally skip this error if user has specified to do so LOGGER.error("Operation failed on graph: {}", graph.getGraphId()); diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/add/AddGraphHandler.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/add/AddGraphHandler.java index 91fdf287406..3d65a92156c 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/add/AddGraphHandler.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/add/AddGraphHandler.java @@ -59,7 +59,7 @@ public Void doOperation(final AddGraph operation, final Context context, final S } // Add the graph - ((FederatedStore) store).addGraph(newGraph.getGraph(), access); + ((FederatedStore) store).addGraph(newGraph, access); return null; } diff --git a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/get/GetSchemaHandler.java b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/get/GetSchemaHandler.java index eca20ec676e..5525b0927aa 100644 --- a/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/get/GetSchemaHandler.java +++ b/store-implementation/simple-federated-store/src/main/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/get/GetSchemaHandler.java @@ -21,7 +21,7 @@ import uk.gov.gchq.gaffer.federated.simple.FederatedStore; import uk.gov.gchq.gaffer.federated.simple.operation.handler.FederatedOutputHandler; -import uk.gov.gchq.gaffer.graph.Graph; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.store.Context; import uk.gov.gchq.gaffer.store.Store; @@ -41,7 +41,7 @@ public class GetSchemaHandler extends FederatedOutputHandler @Override public Schema doOperation(final GetSchema operation, final Context context, final Store store) throws OperationException { - List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); + List graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); if (graphsToExecute.isEmpty()) { return new Schema(); @@ -49,8 +49,8 @@ public Schema doOperation(final GetSchema operation, final Context context, fina // Execute the operation chain on each graph List graphResults = new ArrayList<>(); - for (final Graph graph : graphsToExecute) { - graphResults.add(graph.execute(operation, context.getUser())); + for (final GraphSerialisable graph : graphsToExecute) { + graphResults.add(graph.getGraph().execute(operation, context.getUser())); } return getMergedSchema(graphResults); @@ -69,15 +69,15 @@ public Schema doOperation(final GetSchema operation, final Context context, fina public Schema doOperationOnGraphs( final GetSchema operation, final Context context, - final List graphsToExecute) throws OperationException { + final List graphsToExecute) throws OperationException { if (graphsToExecute.isEmpty()) { return new Schema(); } // Execute the operation chain on each graph List graphResults = new ArrayList<>(); - for (final Graph graph : graphsToExecute) { - graphResults.add(graph.execute(operation, context.getUser())); + for (final GraphSerialisable graph : graphsToExecute) { + graphResults.add(graph.getGraph().execute(operation, context.getUser())); } return getMergedSchema(graphResults); diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedStoreTest.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedStoreTest.java index 261681232f7..5cdf05191c8 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedStoreTest.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedStoreTest.java @@ -28,7 +28,6 @@ import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; import uk.gov.gchq.gaffer.graph.GraphSerialisable; -import uk.gov.gchq.gaffer.mapstore.MapStoreProperties; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.store.Context; import uk.gov.gchq.gaffer.store.StoreException; @@ -86,20 +85,10 @@ void shouldReturnDefaultGraphIdsThatExist() throws StoreException { // Set the defaults to graphs and make sure to add them properties.set(PROP_DEFAULT_GRAPH_IDS, graphId1 + "," + graphId2); store.initialise(graphId, null, properties); - store.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId1)) - .addSchema(new Schema()) - .storeProperties(new MapStoreProperties()) - .build(), - new GraphAccess()); - store.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId2)) - .addSchema(new Schema()) - .storeProperties(new MapStoreProperties()) - .build(), - new GraphAccess()); + store.addGraph(new GraphSerialisable(new GraphConfig(graphId1), new Schema(), new StoreProperties()), + new GraphAccess()); + store.addGraph(new GraphSerialisable(new GraphConfig(graphId2), new Schema(), new StoreProperties()), + new GraphAccess()); assertThat(store.getDefaultGraphIds()).containsExactly(graphId1, graphId2); } @@ -115,20 +104,10 @@ void shouldAllowSettingDefaultGraphIdsUsingOperation() throws StoreException, Op // Set the defaults to graph1 properties.set(PROP_DEFAULT_GRAPH_IDS, graphId1); store.initialise(graphId, null, properties); - store.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId1)) - .addSchema(new Schema()) - .addStoreProperties(new MapStoreProperties()) - .build(), - new GraphAccess()); - store.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId2)) - .addSchema(new Schema()) - .addStoreProperties(new MapStoreProperties()) - .build(), - new GraphAccess()); + store.addGraph(new GraphSerialisable(new GraphConfig(graphId1), new Schema(), new StoreProperties()), + new GraphAccess()); + store.addGraph(new GraphSerialisable(new GraphConfig(graphId2), new Schema(), new StoreProperties()), + new GraphAccess()); assertThat(store.getDefaultGraphIds()).containsExactly(graphId1); @@ -152,24 +131,21 @@ void shouldAddAndGetGraphsViaStoreInterface() throws StoreException, CacheOperat final GraphSerialisable graph1Serialisable = new GraphSerialisable(graph1.getConfig(), graph1.getSchema(), graph1.getStoreProperties()); final GraphSerialisable graph2Serialisable = new GraphSerialisable(graph2.getConfig(), graph2.getSchema(), graph2.getStoreProperties()); - final Graph expectedGraph1 = FederatedTestUtils.getBlankGraphWithModernSchema(this.getClass(), graphId1, StoreType.MAP); - final Graph expectedGraph2 = FederatedTestUtils.getBlankGraphWithModernSchema(this.getClass(), graphId2, StoreType.MAP); - // When FederatedStore store = new FederatedStore(); store.initialise(federatedGraphId, null, new StoreProperties()); - store.addGraph(graph1Serialisable.getGraph(), new GraphAccess()); - store.addGraph(graph2Serialisable.getGraph(), new GraphAccess()); + store.addGraph(graph1Serialisable, new GraphAccess()); + store.addGraph(graph2Serialisable, new GraphAccess()); // Then - Graph addedGraph1 = store.getGraph(graphId1); - Graph addedGraph2 = store.getGraph(graphId2); - - assertThat(addedGraph1.getGraphId()).isEqualTo(expectedGraph1.getGraphId()); - assertThat(addedGraph1.getSchema()).isEqualTo(expectedGraph1.getSchema()); - assertThat(addedGraph1.getStoreProperties()).isEqualTo(expectedGraph1.getStoreProperties()); - assertThat(addedGraph2.getGraphId()).isEqualTo(expectedGraph2.getGraphId()); - assertThat(addedGraph2.getSchema()).isEqualTo(expectedGraph2.getSchema()); - assertThat(addedGraph2.getStoreProperties()).isEqualTo(expectedGraph2.getStoreProperties()); + GraphSerialisable addedGraph1 = store.getGraph(graphId1); + GraphSerialisable addedGraph2 = store.getGraph(graphId2); + + assertThat(addedGraph1.getConfig()).isEqualTo(graph1Serialisable.getConfig()); + assertThat(addedGraph1.getSchema()).isEqualTo(graph1Serialisable.getSchema()); + assertThat(addedGraph1.getStoreProperties()).isEqualTo(graph1Serialisable.getStoreProperties()); + assertThat(addedGraph2.getConfig()).isEqualTo(graph2Serialisable.getConfig()); + assertThat(addedGraph2.getSchema()).isEqualTo(graph2Serialisable.getSchema()); + assertThat(addedGraph2.getStoreProperties()).isEqualTo(graph2Serialisable.getStoreProperties()); } } diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtilsTest.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtilsTest.java index 5d8d88ecaf7..aa9d0a7465b 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtilsTest.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/FederatedUtilsTest.java @@ -19,13 +19,13 @@ import org.junit.jupiter.api.Test; import uk.gov.gchq.gaffer.data.elementdefinition.view.View; -import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; -import uk.gov.gchq.gaffer.mapstore.MapStoreProperties; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.operation.Operation; import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.graph.OperationView; import uk.gov.gchq.gaffer.operation.impl.get.GetAllElements; +import uk.gov.gchq.gaffer.store.StoreProperties; import uk.gov.gchq.gaffer.store.schema.Schema; import uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition; import uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition; @@ -44,27 +44,19 @@ void shouldRemoveGroupFromViewIfNotInSchema() { // Given String entityInSchema = "entityInSchema"; String edgeInSchema = "edgeInSchema"; - String stringTypeName = "string"; - SchemaEntityDefinition entityDef = new SchemaEntityDefinition.Builder() - .vertex(stringTypeName) - .build(); + View testView = new View.Builder() .entity(entityInSchema) .entity("entityNotInSchema") .edge(edgeInSchema) .edge("edgeNotInSchema") .build(); - Graph graph = new Graph.Builder() - .config(new GraphConfig("test")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity(entityInSchema, entityDef) - .edge(edgeInSchema, new SchemaEdgeDefinition.Builder() - .source(stringTypeName) - .destination(stringTypeName) - .build()).build()) - .storeProperties(new MapStoreProperties()) - .build(); + GraphSerialisable graph = new GraphSerialisable( + new GraphConfig("test"), + new Schema.Builder() + .entity(entityInSchema, new SchemaEntityDefinition()) + .edge(edgeInSchema, new SchemaEdgeDefinition()).build(), + new StoreProperties()); // When View fixedView = FederatedUtils.getValidViewForGraph(testView, graph); @@ -76,25 +68,16 @@ void shouldRemoveGroupFromViewIfNotInSchema() { @Test void shouldPreventExecutionIfNoGroupsInViewAreRelevant() { // Given - String stringTypeName = "string"; - SchemaEntityDefinition entityDef = new SchemaEntityDefinition.Builder() - .vertex(stringTypeName) - .build(); View testView = new View.Builder() .entity("entityNotInSchema") .edge("edgeNotInSchema") .build(); - Graph graph = new Graph.Builder() - .config(new GraphConfig("test")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity("entityInSchema", entityDef) - .edge("edgeInSchema", new SchemaEdgeDefinition.Builder() - .source(stringTypeName) - .destination(stringTypeName) - .build()).build()) - .storeProperties(new MapStoreProperties()) - .build(); + GraphSerialisable graph = new GraphSerialisable( + new GraphConfig("test"), + new Schema.Builder() + .entity("entityInSchema", new SchemaEntityDefinition()) + .edge("edgeInSchema", new SchemaEdgeDefinition()).build(), + new StoreProperties()); // When assertThatExceptionOfType(IllegalArgumentException.class) @@ -105,21 +88,13 @@ void shouldPreventExecutionIfNoGroupsInViewAreRelevant() { void shouldChangeViewsOfNestedOperations() { String entityInSchema = "entityInSchema"; String edgeInSchema = "edgeInSchema"; - String stringTypeName = "string"; - SchemaEntityDefinition entityDef = new SchemaEntityDefinition.Builder() - .vertex(stringTypeName) - .build(); - Graph graph = new Graph.Builder() - .config(new GraphConfig("test")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity(entityInSchema, entityDef) - .edge(edgeInSchema, new SchemaEdgeDefinition.Builder() - .source(stringTypeName) - .destination(stringTypeName) - .build()).build()) - .storeProperties(new MapStoreProperties()) - .build(); + + GraphSerialisable graph = new GraphSerialisable( + new GraphConfig("test"), + new Schema.Builder() + .entity(entityInSchema, new SchemaEntityDefinition()) + .edge(edgeInSchema, new SchemaEdgeDefinition()).build(), + new StoreProperties()); // View with some mixed groups in View testView = new View.Builder() @@ -160,31 +135,19 @@ void shouldChangeViewsOfNestedOperations() { void shouldDetectIfGraphsShareGroups() { // Given String sharedGroup = "sharedGroup"; - String stringTypeName = "string"; - SchemaEntityDefinition entityDef = new SchemaEntityDefinition.Builder() - .vertex(stringTypeName) - .build(); - Graph graph1 = new Graph.Builder() - .config(new GraphConfig("graph1")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity(sharedGroup, entityDef).build()) - .storeProperties(new MapStoreProperties()) - .build(); - Graph graph2 = new Graph.Builder() - .config(new GraphConfig("graph2")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity(sharedGroup, entityDef).build()) - .storeProperties(new MapStoreProperties()) - .build(); - Graph graph3 = new Graph.Builder() - .config(new GraphConfig("graph3")) - .addSchema(new Schema.Builder() - .type(stringTypeName, String.class) - .entity("notShared", entityDef).build()) - .storeProperties(new MapStoreProperties()) - .build(); + + GraphSerialisable graph1 = new GraphSerialisable( + new GraphConfig("graph1"), + new Schema.Builder().entity(sharedGroup, new SchemaEntityDefinition()).build(), + new StoreProperties()); + GraphSerialisable graph2 = new GraphSerialisable( + new GraphConfig("graph2"), + new Schema.Builder().entity(sharedGroup, new SchemaEntityDefinition()).build(), + new StoreProperties()); + GraphSerialisable graph3 = new GraphSerialisable( + new GraphConfig("graph3"), + new Schema.Builder().entity("notShared", new SchemaEntityDefinition()).build(), + new StoreProperties()); // When/Then assertThat(FederatedUtils.doGraphsShareGroups(Arrays.asList(graph1, graph2))).isTrue(); diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/PreDefinedFederatedStore.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/PreDefinedFederatedStore.java index 9326053d0ea..47b4a9cb800 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/PreDefinedFederatedStore.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/PreDefinedFederatedStore.java @@ -20,8 +20,8 @@ import uk.gov.gchq.gaffer.cache.CacheServiceLoader; import uk.gov.gchq.gaffer.commonutil.StreamUtil; import uk.gov.gchq.gaffer.federated.simple.access.GraphAccess; -import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.store.StoreException; import uk.gov.gchq.gaffer.store.StoreProperties; import uk.gov.gchq.gaffer.store.schema.Schema; @@ -40,19 +40,10 @@ public void initialise(final String graphId, final Schema schema, final StorePro super.initialise(graphId, schema, properties); - addGraph( - new Graph.Builder() - .config(new GraphConfig("graphA")) - .addSchema(schema.clone()) - .storeProperties(STORE_PROPERTIES) - .build(), - new GraphAccess()); - addGraph( - new Graph.Builder() - .config(new GraphConfig("graphB")) - .addSchema(schema.clone()) - .storeProperties(STORE_PROPERTIES) - .build(), - new GraphAccess()); + addGraph(new GraphSerialisable(new GraphConfig("graphA"), + schema.clone(), STORE_PROPERTIES), new GraphAccess()); + + addGraph(new GraphSerialisable(new GraphConfig("graphB"), + schema.clone(), STORE_PROPERTIES), new GraphAccess()); } } diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/AddGraphTest.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/AddGraphTest.java index 98017fd19f0..72240a97717 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/AddGraphTest.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/AddGraphTest.java @@ -31,7 +31,6 @@ import uk.gov.gchq.gaffer.federated.simple.FederatedStore; import uk.gov.gchq.gaffer.federated.simple.FederatedStoreProperties; import uk.gov.gchq.gaffer.federated.simple.access.GraphAccess; -import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser; @@ -80,7 +79,7 @@ void shouldAddGraphUsingBuilder() throws StoreException, OperationException, Cac federatedStore.initialise(federatedGraphId, null, new StoreProperties()); federatedStore.execute(operation, new Context()); - final Graph addedGraph = federatedStore.getGraph(graphId); + final GraphSerialisable addedGraph = federatedStore.getGraph(graphId); // Then assertThat(addedGraph.getConfig().getGraphId()) @@ -121,7 +120,7 @@ void shouldAddGraphUsingJSONSerialisation() final AddGraph operation = JSONSerialiser.deserialise(jsonOperation.toString(), AddGraph.class); federatedStore.execute(operation, new Context()); - final Graph addedGraph = federatedStore.getGraph(graphId); + final GraphSerialisable addedGraph = federatedStore.getGraph(graphId); // Then assertThat(addedGraph.getGraphId()).isEqualTo(expectedSerialisable.getGraphId()); diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/ChangeGraphIdTest.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/ChangeGraphIdTest.java index 4de8f59f5cb..81d0346ab50 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/ChangeGraphIdTest.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/ChangeGraphIdTest.java @@ -18,6 +18,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import uk.gov.gchq.gaffer.access.predicate.NoAccessPredicate; import uk.gov.gchq.gaffer.cache.CacheServiceLoader; @@ -30,6 +32,7 @@ import uk.gov.gchq.gaffer.federated.simple.util.FederatedTestUtils; import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.mapstore.MapStoreProperties; import uk.gov.gchq.gaffer.operation.OperationChain; import uk.gov.gchq.gaffer.operation.OperationException; @@ -54,11 +57,12 @@ void reset() { CacheServiceLoader.shutdown(); } - @Test - void shouldChangeGraphIdAndPreserveData() throws StoreException, OperationException, CacheOperationException { - // Given (only possible on accumulo stores) + @ParameterizedTest + @EnumSource(StoreType.class) + void shouldChangeGraphIdAndPreserveData(StoreType store) throws StoreException, OperationException, CacheOperationException { + // Given final String graphId = "shouldChangeGraphIdAndPreserveData"; - final Graph originalGraph = FederatedTestUtils.getBlankGraphWithModernSchema(this.getClass(), graphId, StoreType.ACCUMULO); + final Graph originalGraph = FederatedTestUtils.getBlankGraphWithModernSchema(this.getClass(), graphId, store); // Elements to add to the graph final Properties graphEntityProps = new Properties(); @@ -70,7 +74,7 @@ void shouldChangeGraphIdAndPreserveData() throws StoreException, OperationExcept federatedStore.initialise(FED_STORE_ID, null, new StoreProperties()); // Add elements to the graph FederatedTestUtils.addGraphWithElements(federatedStore, originalGraph, graphEntity); - Graph expectedGraph = federatedStore.getGraph(graphId); + GraphSerialisable expectedGraphSerialisable = federatedStore.getGraph(graphId); // Change graph ID operation final ChangeGraphId changeGraphId = new ChangeGraphId.Builder() @@ -85,11 +89,11 @@ void shouldChangeGraphIdAndPreserveData() throws StoreException, OperationExcept .satisfies(gs -> { assertThat(gs.getConfig()) .usingRecursiveComparison() - .ignoringFields("graphId", "hooks") - .isEqualTo(expectedGraph.getConfig()); + .ignoringFields("graphId") + .isEqualTo(expectedGraphSerialisable.getConfig()); assertThat(gs.getStoreProperties()) - .isEqualTo(expectedGraph.getStoreProperties()); + .isEqualTo(expectedGraphSerialisable.getStoreProperties()); }); // Ensure that there are no references to the 'old' graph ID diff --git a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/GetSchemaTest.java b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/GetSchemaTest.java index 724c4081582..7a6359e0844 100644 --- a/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/GetSchemaTest.java +++ b/store-implementation/simple-federated-store/src/test/java/uk/gov/gchq/gaffer/federated/simple/operation/GetSchemaTest.java @@ -24,8 +24,8 @@ import uk.gov.gchq.gaffer.federated.simple.FederatedStoreProperties; import uk.gov.gchq.gaffer.federated.simple.access.GraphAccess; import uk.gov.gchq.gaffer.federated.simple.operation.handler.FederatedOperationHandler; -import uk.gov.gchq.gaffer.graph.Graph; import uk.gov.gchq.gaffer.graph.GraphConfig; +import uk.gov.gchq.gaffer.graph.GraphSerialisable; import uk.gov.gchq.gaffer.mapstore.MapStoreProperties; import uk.gov.gchq.gaffer.operation.OperationException; import uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser; @@ -60,18 +60,10 @@ void shouldMergeSchemasWithConflictingVisibilities() throws StoreException, Oper federatedStore.initialise("federated", null, new FederatedStoreProperties()); federatedStore.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId1)) - .addSchema(schema1) - .storeProperties(new MapStoreProperties()) - .build(), + new GraphSerialisable(new GraphConfig(graphId1), schema1, new MapStoreProperties()), new GraphAccess()); federatedStore.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId2)) - .addSchema(schema2) - .storeProperties(new MapStoreProperties()) - .build(), + new GraphSerialisable(new GraphConfig(graphId2), schema2, new MapStoreProperties()), new GraphAccess()); GetSchema getOp = new GetSchema.Builder() @@ -100,18 +92,10 @@ void shouldMergeSchemasWithConflictingSerialisers() throws StoreException, Opera federatedStore.initialise("federated", null, new FederatedStoreProperties()); federatedStore.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId1)) - .addSchema(schema1) - .storeProperties(new MapStoreProperties()) - .build(), + new GraphSerialisable(new GraphConfig(graphId1), schema1, new MapStoreProperties()), new GraphAccess()); federatedStore.addGraph( - new Graph.Builder() - .config(new GraphConfig(graphId2)) - .addSchema(schema2) - .storeProperties(new MapStoreProperties()) - .build(), + new GraphSerialisable(new GraphConfig(graphId2), schema2, new MapStoreProperties()), new GraphAccess()); GetSchema getOp = new GetSchema.Builder()