Skip to content

Commit

Permalink
gh-209: Replace MockAccumuloStore usages in docs with MapStore
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Sep 27, 2021
1 parent 2c47070 commit 12415d2
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 114 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
target/
*/*.iml
*.iml
*/.settings
*/.project
**/.settings
**/.project
*/bin
*/*.class
*/atlassian-ide*
*/.idea
.idea/*
.idea
*/.classpath
**/.classpath
__pycache__
*.pem
*.pyc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public CloseableIterable<? extends Element> run() throws Exception {

final HashMapGraphLibrary library = new HashMapGraphLibrary();
library.addProperties("mapStore", getMapStoreProperties());
library.addProperties("accumuloStore", getAccumuloStoreProperties());
library.addSchema("roadTraffic", schema);

// [creating a federatedstore] create a store that federates to a MapStore and AccumuloStore
// [creating a federatedstore] create a store that federates to across two MapStores
// ---------------------------------------------------------
final Graph federatedGraph = new Graph.Builder()
.config(new GraphConfig.Builder()
Expand All @@ -88,27 +87,27 @@ public CloseableIterable<? extends Element> run() throws Exception {

final User user = new User("user01");

final AddGraph addMapGraph = new AddGraph.Builder()
.graphId("mapGraph")
final AddGraph addFirstGraph = new AddGraph.Builder()
.graphId("firstGraph")
.schema(new Schema.Builder()
.json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/entities.json"))
.json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json"))
.build())
.storeProperties(getMapStoreProperties())
.isPublic(true)
.build();
federatedGraph.execute(addMapGraph, user);
federatedGraph.execute(addFirstGraph, user);

final AddGraph addAccumuloGraph = new AddGraph.Builder()
.graphId("accumuloGraph")
final AddGraph addSecondGraph = new AddGraph.Builder()
.graphId("secondGraph")
.schema(new Schema.Builder()
.json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/edges.json"))
.json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json"))
.build())
.storeProperties(getAccumuloStoreProperties())
.storeProperties(getMapStoreProperties())
.isPublic(true)
.build();
federatedGraph.execute(addAccumuloGraph, user);
federatedGraph.execute(addSecondGraph, user);

// [add another graph] add a graph to the federated store.
// ---------------------------------------------------------
Expand All @@ -121,7 +120,7 @@ public CloseableIterable<? extends Element> run() throws Exception {
// ---------------------------------------------------------

improveReadabilityOfJson(addAnotherGraph);
addAccumuloGraph.setGraphAuths(null);
addAnotherGraph.setGraphAuths(null);
printJson("ADD_GRAPH", addAnotherGraph);

// [remove graph] remove a graph from the federated store.
Expand Down Expand Up @@ -181,26 +180,26 @@ public CloseableIterable<? extends Element> run() throws Exception {
printJsonAndPython("GET_ELEMENTS", getOpChain);


// [get elements from accumulo graph]
// [get elements from first graph]
// ---------------------------------------------------------
final OperationChain<CloseableIterable<? extends Element>> getOpChainOnAccumuloGraph = new OperationChain.Builder()
final OperationChain<CloseableIterable<? extends Element>> getOpChainOnFirstGraph = new OperationChain.Builder()
.first(new GetElements.Builder()
.input(new EntitySeed("10"))
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "accumuloGraph")
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "firstGraph")
.build())
.build();

CloseableIterable<? extends Element> elementsFromAccumuloGraph = federatedGraph.execute(getOpChainOnAccumuloGraph, user);
CloseableIterable<? extends Element> elementsFromFirstGraph = federatedGraph.execute(getOpChainOnFirstGraph, user);
// ---------------------------------------------------------

for (final Element element : elementsFromAccumuloGraph) {
print("ELEMENTS_FROM_ACCUMULO_GRAPH", element.toString());
for (final Element element : elementsFromFirstGraph) {
print("ELEMENTS_FROM_FIRST_GRAPH", element.toString());
}

// [select graphs for operations]
// ---------------------------------------------------------
GetAllElements selectGraphsForOperations = new Builder()
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "graphId1, graphId2")
.option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "firstGraph, secondGraph")
.build();
// ---------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void simpleExport() {
public void simpleExportWithCustomGraph() {
// ---------------------------------------------------------
final Schema schema = Schema.fromJson(StreamUtil.openStreams(getClass(), "operations/schema"));
final StoreProperties storeProperties = StoreProperties.loadStoreProperties(StreamUtil.openStream(getClass(), "othermockaccumulostore.properties"));
final StoreProperties storeProperties = new AccumuloProperties();
final OperationChain<Iterable<? extends Element>> opChain =
new OperationChain.Builder()
.first(new GetAllElements.Builder()
Expand Down Expand Up @@ -173,7 +173,7 @@ public void simpleExportUsingGraphFromGraphLibrary() {
final Graph graph = new Graph.Builder()
.config(StreamUtil.openStream(getClass(), "graphConfigWithLibrary.json"))
.addSchemas(StreamUtil.openStreams(getClass(), "operations/schema"))
.storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties"))
.storeProperties(new AccumuloProperties())
.build();

final OperationChain<Iterable<? extends Element>> opChain =
Expand Down Expand Up @@ -222,7 +222,7 @@ public void exportToNewGraphBasedOnConfigFromGraphLibrary() {
final Graph graph = new Graph.Builder()
.config(StreamUtil.openStream(getClass(), "graphConfigWithLibrary.json"))
.addSchemas(StreamUtil.openStreams(getClass(), "operations/schema"))
.storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties"))
.storeProperties(new AccumuloProperties())
.build();

final OperationChain<Iterable<? extends Element>> opChain =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected Graph createSimpleExampleGraph() {
.graphId(getClass().getSimpleName())
.build())
.addSchemas(StreamUtil.openStreams(getClass(), "operations/schema"))
.storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties"))
.storeProperties(StreamUtil.openStream(getClass(), "singleusemapstore.properties"))
.build();

// Create data generator
Expand Down Expand Up @@ -333,7 +333,7 @@ protected Graph createComplexExampleGraph() {
.graphId(getClass().getSimpleName())
.build())
.addSchemas(StreamUtil.openStreams(getClass(), "operations/schema"))
.storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties"))
.storeProperties(StreamUtil.openStream(getClass(), "singleusemapstore.properties"))
.build();

// Create data generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import org.apache.commons.io.IOUtils;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
import uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable;
import uk.gov.gchq.gaffer.data.element.Element;
import uk.gov.gchq.gaffer.data.elementdefinition.view.View;
import uk.gov.gchq.gaffer.doc.user.generator.RoadUseElementGenerator;
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.mapstore.SingleUseMapStore;
import uk.gov.gchq.gaffer.operation.OperationException;
import uk.gov.gchq.gaffer.operation.data.EntitySeed;
import uk.gov.gchq.gaffer.operation.impl.add.AddElements;
Expand Down Expand Up @@ -106,12 +106,8 @@ public CloseableIterable<? extends Element> run() throws OperationException, IOE
.build())
.build();

final AccumuloProperties properties = new AccumuloProperties();
properties.setStoreClass(SingleUseMockAccumuloStore.class);
properties.setInstance("instance1");
properties.setZookeepers("zookeeper1");
properties.setUser("user01");
properties.setPassword("password");
final MapStoreProperties properties = new MapStoreProperties();
properties.setStoreClass(SingleUseMapStore.class);

graph = new Graph.Builder()
.config(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public CloseableIterable<? extends Element> run() throws OperationException {
.graphId(getClass().getSimpleName())
.build())
.addSchemas(StreamUtil.openStreams(getClass(), "operations/schema"))
.storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties"))
.storeProperties(StreamUtil.openStream(getClass(), "singleusemapstore.properties"))
.build();
// ---------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static String substitute(final String text, final UserWalkthrough example
public static Map<String, String> createParameterMap(final UserWalkthrough example) {
final Map<String, String> params = new HashMap<>();
putParam(params, "SIMPLE_GRAPH_CONFIGURATION", getJsonBlockFromResource("graphConfig.json", example.getClass()));
putParam(params, "SIMPLE_STORE_PROPERTIES", getPropertiesBlockFromResource("mockaccumulostore.properties", example.getClass()));
putParam(params, "SIMPLE_STORE_PROPERTIES", getPropertiesBlockFromResource("singleusemapstore.properties", example.getClass()));
putParam(params, "ACCUMULO_STORE_PROPERTIES", getPropertiesBlockFromResource("accumulostore.properties", example.getClass()));
putParam(params, "ROAD_TRAFFIC_EXAMPLE_LINK", getGafferGitHubFileLink("Road Traffic Example", "example/road-traffic/README.md"));
putParam(params, "CSV_GENERATOR_JAVA", JavaSourceUtil.getJava(RoadUseCsvGenerator.class.getName(), null));
putParam(params, "DESCRIPTION_TRANSFORM_LINK", getGafferGitHubCodeLink(DescriptionTransform.class, "example/road-traffic/road-traffic-model"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
*/
package uk.gov.gchq.gaffer.doc.walkthrough;

import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;

import uk.gov.gchq.gaffer.accumulostore.AccumuloProperties;
import uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore;
import uk.gov.gchq.gaffer.bitmap.serialisation.json.BitmapJsonModules;
import uk.gov.gchq.gaffer.cache.impl.HashMapCacheService;
import uk.gov.gchq.gaffer.cache.util.CacheProperties;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
Expand Down Expand Up @@ -77,27 +73,15 @@ protected GraphConfig getDefaultGraphConfig() {
}

protected StoreProperties getDefaultStoreProperties() {
return getAccumuloStoreProperties();
}

protected StoreProperties getAccumuloStoreProperties() {
final AccumuloProperties properties = new AccumuloProperties();
properties.setStoreClass(SingleUseMockAccumuloStore.class);
properties.setInstance("instance1");
properties.setZookeepers("zookeeper1");
properties.setUser("user01");
properties.setPassword("password");
properties.set(CacheProperties.CACHE_SERVICE_CLASS, HashMapCacheService.class.getName());
properties.setJobTrackerEnabled(true);
properties.setJsonSerialiserModules(Sets.newHashSet(BitmapJsonModules.class));
properties.setOperationDeclarationPaths("sparkAccumuloOperationsDeclarations.json,ResultCacheExportOperations.json,ExportToOtherGraphOperationDeclarations.json,ScoreOperationChainDeclaration.json");
return properties;
return getMapStoreProperties();
}

protected StoreProperties getMapStoreProperties() {
final MapStoreProperties properties = new MapStoreProperties();
properties.setStoreClass(SingleUseMapStore.class);
properties.set(CacheProperties.CACHE_SERVICE_CLASS, HashMapCacheService.class.getName());
properties.setJobTrackerEnabled(true);
properties.setOperationDeclarationPaths("sparkAccumuloOperationsDeclarations.json,ResultCacheExportOperations.json,ExportToOtherGraphOperationDeclarations.json,ScoreOperationChainDeclaration.json");
return properties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.commons.lang3.text.StrSubstitutor;

import uk.gov.gchq.gaffer.accumulostore.AccumuloStore;
import uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore;
import uk.gov.gchq.gaffer.accumulostore.key.AccumuloKeyPackage;
import uk.gov.gchq.gaffer.commonutil.CommonConstants;
import uk.gov.gchq.gaffer.commonutil.StreamUtil;
Expand All @@ -35,6 +34,7 @@
import uk.gov.gchq.gaffer.data.generator.ObjectGenerator;
import uk.gov.gchq.gaffer.doc.util.JavaSourceUtil;
import uk.gov.gchq.gaffer.graph.Graph;
import uk.gov.gchq.gaffer.mapstore.MapStore;
import uk.gov.gchq.gaffer.operation.Operation;
import uk.gov.gchq.gaffer.operation.data.generator.EntityIdExtractor;
import uk.gov.gchq.gaffer.operation.impl.add.AddElements;
Expand Down Expand Up @@ -195,7 +195,7 @@ public static Map<String, String> createParameterMap() {
putJavaDocParam(params, User.class);
putJavaDocParam(params, Store.class);
putJavaDocParam(params, AccumuloStore.class);
putJavaDocParam(params, MockAccumuloStore.class);
putJavaDocParam(params, MapStore.class);
putJavaDocParam(params, Graph.class);
putJavaDocParam(params, ElementGenerator.class);
putJavaDocParam(params, ObjectGenerator.class);
Expand All @@ -218,6 +218,7 @@ public static Map<String, String> createParameterMap() {
putJavaDocParam(params, ExportToSet.class);
putJavaDocParam(params, ExportToGafferResultCache.class);
putParam(params, "ACCUMULO_USER_GUIDE", "[Accumulo Store User Guide](../../stores/accumulo-store)");
putParam(params, "MAP_USER_GUIDE", "[Map Store User Guide](../../stores/map-store)");
putParam(params, "ACCUMULO_KEY_PACKAGE", getGafferGitHubCodeLink(AccumuloKeyPackage.class, "store-implementations/accumulo-store"));
putParam(params, "OPERATION_EXAMPLES_LINK", "[Operation Examples](../operations/contents)");

Expand Down
9 changes: 3 additions & 6 deletions src/main/resources/RoadUse/store.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017 Crown Copyright
# Copyright 2017-2021 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,8 +14,5 @@
# limitations under the License.
#

gaffer.store.class=uk.gov.gchq.gaffer.accumulostore.SingleUseMockAccumuloStore
accumulo.instance=someInstanceName
accumulo.zookeepers=aZookeeper
accumulo.user=user01
accumulo.password=password
gaffer.store.class=uk.gov.gchq.gaffer.mapstore.SingleUseMapStore
gaffer.store.properties.class=uk.gov.gchq.gaffer.mapstore.MapStoreProperties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2016 Crown Copyright
# Copyright 2021 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
gaffer.store.class=uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore
gaffer.store.class=uk.gov.gchq.gaffer.accumulostore.AccumuloStore
gaffer.store.properties.class=uk.gov.gchq.gaffer.accumulostore.AccumuloProperties
accumulo.instance=someInstanceName
accumulo.zookeepers=aZookeeper
accumulo.user=user01
accumulo.password=password
gaffer.cache.service.class=uk.gov.gchq.gaffer.cache.impl.HashMapCacheService
gaffer.store.job.tracker.enabled=true
gaffer.store.operation.declarations=ExportToOtherGraphOperationDeclarations.json
gaffer.store.operation.declarations=ResultCacheExportOperations.json,ExportToOtherGraphOperationDeclarations.json
11 changes: 4 additions & 7 deletions src/main/resources/cache-store.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017 Crown Copyright
# Copyright 2017-2021 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
gaffer.store.class=uk.gov.gchq.gaffer.accumulostore.MockAccumuloStore
accumulo.instance=someInstanceName
accumulo.zookeepers=aZookeeper
accumulo.user=user01
accumulo.password=password
gaffer.store.job.executor.threads=1
gaffer.store.class=uk.gov.gchq.gaffer.mapstore.MapStore
gaffer.store.properties.class=uk.gov.gchq.gaffer.mapstore.MapStoreProperties
gaffer.store.mapstore.static=true
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ ${ELEMENTS}
```

${START_JAVA_CODE}
${GET_ELEMENTS_FROM_ACCUMULO_GRAPH_SNIPPET}
${GET_ELEMENTS_FROM_FIRST_GRAPH_SNIPPET}
${END_CODE}

and the results are:

```
${ELEMENTS_FROM_ACCUMULO_GRAPH}
${ELEMENTS_FROM_FIRST_GRAPH}
```

## Select Graphs for Operations
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/dev/walkthrough/Jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The job result cache is simply a second Gaffer Graph. So, if you are running on

Two operations are required for exporting and getting results from a Gaffer cache - ExportToGafferResultCache and GetGafferResultCacheExport.
These two operations need to be registered by providing an Operations Declarations JSON file in your store.properties file.
To use the Accumulo store as your Gaffer cache the operations declarations JSON file would need to look something like:
To use the Accumulo or Map store as your Gaffer cache the operations declarations JSON file would need to look something like:

${RESULT_CACHE_EXPORT_OPERATIONS}

Expand All @@ -42,7 +42,7 @@ gaffer.store.operation.declarations=/path/to/operations1.json,/path/to/ResultCac

The JSON files can either be placed on your file system or bundled as a resource in your JAR or WAR archive.

For this example the cache-store.properties just references another MockAccumuloStore table:
For this example the cache-store.properties is another MapStore. It is important that `gaffer.store.mapstore.static` is enabled:

${CACHE_STORE_PROPERTIES}

Expand Down
Loading

0 comments on commit 12415d2

Please sign in to comment.