mirror of
https://github.com/JHUAPL/AccumuloGraph.git
synced 2026-01-11 13:47:54 -05:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1ed999ab3 | ||
|
|
8b0a131f5c | ||
|
|
23df037c13 | ||
|
|
d954f1b4bd | ||
|
|
033d29320c | ||
|
|
a9813d0236 | ||
|
|
46112bbc32 | ||
|
|
c5a42df3aa | ||
|
|
9b66771627 | ||
|
|
05c6067303 | ||
|
|
b1a9a88fd6 | ||
|
|
e6464b59e3 | ||
|
|
13034977ea | ||
|
|
59b49f01ba | ||
|
|
1f630eb3ef |
22
README.md
22
README.md
@@ -28,7 +28,7 @@ to Maven Central.
|
||||
<dependency>
|
||||
<groupId>edu.jhuapl.tinkerpop</groupId>
|
||||
<artifactId>blueprints-accumulo-graph</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -211,3 +211,23 @@ Job j = new Job();
|
||||
j.setOutputFormatClass(ElementOutputFormat.class);
|
||||
ElementOutputFormat.setAccumuloGraphConfiguration(j, cfg);
|
||||
```
|
||||
|
||||
## Rexster Configuration
|
||||
Below is a snippet to show an example of AccumuloGraph integration with Rexster. For a complete list of options for configuration, see [`AccumuloGraphConfiguration$Keys`](https://github.com/JHUAPL/AccumuloGraph/blob/master/src/main/java/edu/jhuapl/tinkerpop/AccumuloGraphConfiguration.java#L110)
|
||||
|
||||
```xml
|
||||
<graph>
|
||||
<graph-enabled>true</graph-enabled>
|
||||
<graph-name>myGraph</graph-name>
|
||||
<graph-type>edu.jhuapl.tinkerpop.AccumuloRexsterGraphConfiguration</graph-type>
|
||||
<properties>
|
||||
<blueprints.accumulo.instance.type>Distributed</blueprints.accumulo.instance.type>
|
||||
<blueprints.accumulo.instance>accumulo</blueprints.accumulo.instance>
|
||||
<blueprints.accumulo.zkhosts>zk1,zk2,zk3</blueprints.accumulo.zkhosts>
|
||||
<blueprints.accumulo.user>user</blueprints.accumulo.user>
|
||||
<blueprints.accumulo.password>password</blueprints.accumulo.password>
|
||||
</properties>
|
||||
<extensions>
|
||||
</extensions>
|
||||
</graph>
|
||||
```
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
[2.2 Snapshot]
|
||||
-- 113 Applied instance name when mock instance is used
|
||||
-- 114 Made map reduce elements serializable
|
||||
-- 116 Made MapReduceElement serializable with a tranisent graph
|
||||
[2.1]
|
||||
Change Log started
|
||||
--109,103 Merged Metadata tables
|
||||
|
||||
11
pom.xml
11
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>edu.jhuapl.tinkerpop</groupId>
|
||||
<artifactId>blueprints-accumulo-graph</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.2.2-SNAPSHOT</version>
|
||||
<name>blueprints-accumulo-graph</name>
|
||||
<description>An Accumulo-backed implementation of the Tinkerpop Blueprints graph API.</description>
|
||||
<packaging>jar</packaging>
|
||||
@@ -36,12 +36,17 @@
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.tinkerpop</groupId>
|
||||
<artifactId>gremlin-core</artifactId>
|
||||
<version>3.0.0-incubating</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.accumulo</groupId>
|
||||
<artifactId>accumulo-core</artifactId>
|
||||
|
||||
@@ -235,16 +235,16 @@ public final class AccumuloBulkIngester {
|
||||
copy.setCreate(false).setClear(false);
|
||||
|
||||
AccumuloGraph g = (AccumuloGraph) GraphFactory.open(copy.getConfiguration());
|
||||
for (String key : g.getIndexedKeys(Vertex.class)) {
|
||||
g.dropKeyIndex(key, Vertex.class);
|
||||
g.createKeyIndex(key, Vertex.class);
|
||||
}
|
||||
|
||||
for (String key : g.getIndexedKeys(Edge.class)) {
|
||||
g.dropKeyIndex(key, Edge.class);
|
||||
g.createKeyIndex(key, Edge.class);
|
||||
}
|
||||
g.shutdown();
|
||||
// for (String key : g.getIndexedKeys(Vertex.class)) {
|
||||
// g.dropKeyIndex(key, Vertex.class);
|
||||
// g.createKeyIndex(key, Vertex.class);
|
||||
// }
|
||||
//
|
||||
// for (String key : g.getIndexedKeys(Edge.class)) {
|
||||
// g.dropKeyIndex(key, Edge.class);
|
||||
// g.createKeyIndex(key, Edge.class);
|
||||
// }
|
||||
g.close();
|
||||
|
||||
// TODO ... other house cleaning/verification?
|
||||
|
||||
|
||||
@@ -14,15 +14,21 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.tinkerpop.gremlin.structure.Direction;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
import org.apache.tinkerpop.gremlin.structure.Property;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
|
||||
|
||||
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.util.StringFactory;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -48,10 +54,7 @@ public class AccumuloEdge extends AccumuloElement implements Edge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vertex getVertex(Direction direction) throws IllegalArgumentException {
|
||||
if (!Direction.IN.equals(direction) && !Direction.OUT.equals(direction)) {
|
||||
throw new IllegalArgumentException("Invalid direction: "+direction);
|
||||
}
|
||||
public Iterator<Vertex> vertices(Direction direction) {
|
||||
|
||||
// The vertex information needs to be loaded.
|
||||
if (inVertex == null || outVertex == null || label == null) {
|
||||
@@ -59,17 +62,17 @@ public class AccumuloEdge extends AccumuloElement implements Edge {
|
||||
globals.getEdgeWrapper().loadEndpointsAndLabel(this);
|
||||
}
|
||||
|
||||
return Direction.IN.equals(direction) ? inVertex : outVertex;
|
||||
List<Vertex> verts = new ArrayList<Vertex>(2);
|
||||
if(Direction.IN.equals(direction) || Direction.BOTH.equals(direction)){
|
||||
verts.add(inVertex);
|
||||
}
|
||||
if(Direction.OUT.equals(direction) || Direction.BOTH.equals(direction)){
|
||||
verts.add(outVertex);
|
||||
}
|
||||
return verts.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
// TODO less special treatment for "LABEL" property...
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
return getProperty(StringFactory.LABEL);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
@@ -112,6 +115,24 @@ public class AccumuloEdge extends AccumuloElement implements Edge {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + getId() + ":" + inVertex + " -> " + label + " -> " + outVertex + "]";
|
||||
return StringFactory.edgeString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
// TODO less special treatment for "LABEL" property...
|
||||
if (label != null) {
|
||||
return label;
|
||||
}return "";
|
||||
// return getProperty(StringFactory.LABEL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public <V> Iterator<Property<V>> properties(String... propertyKeys) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,13 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
import org.apache.tinkerpop.gremlin.structure.Property;
|
||||
|
||||
import com.tinkerpop.blueprints.Index;
|
||||
import com.tinkerpop.blueprints.util.StringFactory;
|
||||
|
||||
@@ -58,33 +62,33 @@ public abstract class AccumuloElement implements Element {
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public <T> T property(String key) {
|
||||
// makeCache();
|
||||
//
|
||||
// // Get from property cache.
|
||||
// T value = propertyCache.get(key);
|
||||
//
|
||||
// // If not cached, get it from the backing table.
|
||||
// if (value == null) {
|
||||
// value = globals.getElementWrapper(type).readProperty(this, key);
|
||||
// }
|
||||
//
|
||||
// // Cache the new value.
|
||||
// if (value != null) {
|
||||
// propertyCache.put(key, value);
|
||||
// }
|
||||
//
|
||||
// return value;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public <T> T getProperty(String key) {
|
||||
makeCache();
|
||||
|
||||
// Get from property cache.
|
||||
T value = propertyCache.get(key);
|
||||
|
||||
// If not cached, get it from the backing table.
|
||||
if (value == null) {
|
||||
value = globals.getElementWrapper(type).readProperty(this, key);
|
||||
}
|
||||
|
||||
// Cache the new value.
|
||||
if (value != null) {
|
||||
propertyCache.put(key, value);
|
||||
}
|
||||
|
||||
return value;
|
||||
public Set<String> keys() {
|
||||
return Collections.unmodifiableSet(globals.getElementWrapper(type).readPropertyKeys(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getPropertyKeys() {
|
||||
return globals.getElementWrapper(type).readPropertyKeys(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProperty(String key, Object value) {
|
||||
public <V> Property<V> property(String key, V value) {
|
||||
makeCache();
|
||||
globals.getKeyIndexTableWrapper(type).setPropertyForIndex(this, key, value);
|
||||
// MDL 31 Dec 2014: The above calls getProperty, so this
|
||||
@@ -92,6 +96,7 @@ public abstract class AccumuloElement implements Element {
|
||||
globals.getElementWrapper(type).writeProperty(this, key, value);
|
||||
globals.checkedFlush();
|
||||
setPropertyInMemory(key, value);
|
||||
return new AccumuloProperty<V>(this, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +110,7 @@ public abstract class AccumuloElement implements Element {
|
||||
propertyCache.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public <T> T removeProperty(String key) {
|
||||
if (StringFactory.LABEL.equals(key) ||
|
||||
Constants.LABEL.equals(key)) {
|
||||
@@ -113,7 +118,7 @@ public abstract class AccumuloElement implements Element {
|
||||
}
|
||||
|
||||
makeCache();
|
||||
T value = getProperty(key);
|
||||
T value = (T) property(key).value();
|
||||
if (value != null) {
|
||||
globals.getElementWrapper(type).clearProperty(this, key);
|
||||
globals.checkedFlush();
|
||||
@@ -164,9 +169,14 @@ public abstract class AccumuloElement implements Element {
|
||||
makeCache();
|
||||
return propertyCache.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Graph graph() {
|
||||
return globals.getGraph();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getId() {
|
||||
public Object id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,49 +14,141 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import com.tinkerpop.blueprints.Features;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgeFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgePropertyFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.ElementFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.FeatureSet;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.PropertyFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VariableFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures;
|
||||
import org.apache.tinkerpop.gremlin.structure.util.FeatureDescriptor;
|
||||
|
||||
/**
|
||||
* {@link Features} creator.
|
||||
*/
|
||||
public class AccumuloFeatures {
|
||||
public class AccumuloFeatures implements Features {
|
||||
public GraphFeatures graph() {
|
||||
return new AccumuloGraphFeatures();
|
||||
}
|
||||
|
||||
public static Features get() {
|
||||
Features f = new Features();
|
||||
|
||||
// For simplicity, I accept all property types. They are handled in not the
|
||||
// best way. To be fixed later.
|
||||
f.ignoresSuppliedIds = true;
|
||||
f.isPersistent = true;
|
||||
f.isWrapper = false;
|
||||
f.supportsBooleanProperty = true;
|
||||
f.supportsDoubleProperty = true;
|
||||
f.supportsDuplicateEdges = true;
|
||||
f.supportsEdgeIndex = true;
|
||||
f.supportsEdgeIteration = true;
|
||||
f.supportsEdgeRetrieval = true;
|
||||
f.supportsEdgeKeyIndex = true;
|
||||
f.supportsEdgeProperties = true;
|
||||
f.supportsFloatProperty = true;
|
||||
f.supportsIndices = true;
|
||||
f.supportsIntegerProperty = true;
|
||||
f.supportsKeyIndices = true;
|
||||
f.supportsLongProperty = true;
|
||||
f.supportsMapProperty = true;
|
||||
f.supportsMixedListProperty = true;
|
||||
f.supportsPrimitiveArrayProperty = true;
|
||||
f.supportsSelfLoops = true;
|
||||
f.supportsSerializableObjectProperty = true;
|
||||
f.supportsStringProperty = true;
|
||||
f.supportsThreadedTransactions = false;
|
||||
f.supportsTransactions = false;
|
||||
f.supportsUniformListProperty = true;
|
||||
f.supportsVertexIndex = true;
|
||||
f.supportsVertexIteration = true;
|
||||
f.supportsVertexKeyIndex = true;
|
||||
f.supportsVertexProperties = true;
|
||||
f.supportsThreadIsolatedTransactions = false;
|
||||
public VertexFeatures vertex() {
|
||||
return new AccumuloVertexFeatures() {};
|
||||
}
|
||||
|
||||
return f;
|
||||
public EdgeFeatures edge() {
|
||||
return new AccumuloEdgeFeatures() {};
|
||||
}
|
||||
}
|
||||
|
||||
class AccumuloGraphFeatures implements GraphFeatures {
|
||||
@FeatureDescriptor(name = FEATURE_COMPUTER)
|
||||
public boolean supportsComputer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@FeatureDescriptor(name = FEATURE_PERSISTENCE)
|
||||
public boolean supportsPersistence() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@FeatureDescriptor(name = FEATURE_TRANSACTIONS)
|
||||
public boolean supportsTransactions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@FeatureDescriptor(name = FEATURE_THREADED_TRANSACTIONS)
|
||||
public boolean supportsThreadedTransactions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public VariableFeatures variables() {
|
||||
return new VariableFeatures(){};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AccumuloEdgeFeatures extends AccumuloElementFeatures implements EdgeFeatures {
|
||||
|
||||
public EdgePropertyFeatures properties() {
|
||||
return new EdgePropertyFeatures() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class AccumuloElementFeatures implements ElementFeatures {
|
||||
|
||||
}
|
||||
class AccumuloVertexFeatures extends AccumuloElementFeatures implements VertexFeatures{
|
||||
public VertexProperty.Cardinality getCardinality(final String key) {
|
||||
return VertexProperty.Cardinality.single;
|
||||
}
|
||||
|
||||
|
||||
@FeatureDescriptor(name = FEATURE_MULTI_PROPERTIES)
|
||||
public boolean supportsMultiProperties() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@FeatureDescriptor(name = FEATURE_META_PROPERTIES)
|
||||
public boolean supportsMetaProperties() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public VertexPropertyFeatures properties() {
|
||||
return new AccumuloVertexPropertyFeatures();
|
||||
}
|
||||
}
|
||||
class AccumuloVertexPropertyFeatures implements VertexPropertyFeatures {
|
||||
|
||||
}
|
||||
//
|
||||
// public static Features get() {
|
||||
// Features f = new Features();
|
||||
//
|
||||
// // For simplicity, I accept all property types. They are handled in not the
|
||||
// // best way. To be fixed later.
|
||||
// f.ignoresSuppliedIds = true;
|
||||
// f.isPersistent = true;
|
||||
// f.isWrapper = false;
|
||||
// f.supportsBooleanProperty = true;
|
||||
// f.supportsDoubleProperty = true;
|
||||
// f.supportsDuplicateEdges = true;
|
||||
// f.supportsEdgeIndex = true;
|
||||
// f.supportsEdgeIteration = true;
|
||||
// f.supportsEdgeRetrieval = true;
|
||||
// f.supportsEdgeKeyIndex = true;
|
||||
// f.supportsEdgeProperties = true;
|
||||
// f.supportsFloatProperty = true;
|
||||
// f.supportsIndices = true;
|
||||
// f.supportsIntegerProperty = true;
|
||||
// f.supportsKeyIndices = true;
|
||||
// f.supportsLongProperty = true;
|
||||
// f.supportsMapProperty = true;
|
||||
// f.supportsMixedListProperty = true;
|
||||
// f.supportsPrimitiveArrayProperty = true;
|
||||
// f.supportsSelfLoops = true;
|
||||
// f.supportsSerializableObjectProperty = true;
|
||||
// f.supportsStringProperty = true;
|
||||
// f.supportsThreadedTransactions = false;
|
||||
// f.supportsTransactions = false;
|
||||
// f.supportsUniformListProperty = true;
|
||||
// f.supportsVertexIndex = true;
|
||||
// f.supportsVertexIteration = true;
|
||||
// f.supportsVertexKeyIndex = true;
|
||||
// f.supportsVertexProperties = true;
|
||||
// f.supportsThreadIsolatedTransactions = false;
|
||||
//
|
||||
// return f;
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -14,32 +14,25 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
import org.apache.accumulo.core.client.BatchDeleter;
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
import org.apache.accumulo.core.client.admin.TableOperations;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
import org.apache.tinkerpop.gremlin.structure.Transaction;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Features;
|
||||
import com.tinkerpop.blueprints.Graph;
|
||||
import com.tinkerpop.blueprints.GraphFactory;
|
||||
import com.tinkerpop.blueprints.GraphQuery;
|
||||
import com.tinkerpop.blueprints.Index;
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
import com.tinkerpop.blueprints.Parameter;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.util.DefaultGraphQuery;
|
||||
import com.tinkerpop.blueprints.util.ExceptionFactory;
|
||||
|
||||
import edu.jhuapl.tinkerpop.cache.ElementCaches;
|
||||
@@ -59,7 +52,7 @@ import edu.jhuapl.tinkerpop.cache.ElementCaches;
|
||||
* <li>Hadoop integration</li>
|
||||
* </ol>
|
||||
*/
|
||||
public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
public class AccumuloGraph implements Graph {
|
||||
|
||||
private final GlobalInstances globals;
|
||||
|
||||
@@ -91,7 +84,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
try {
|
||||
globals = new GlobalInstances(config, config.getConnector()
|
||||
.createMultiTableBatchWriter(config.getBatchWriterConfig()),
|
||||
new ElementCaches(config));
|
||||
new ElementCaches(config), this);
|
||||
} catch (Exception e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
@@ -106,12 +99,9 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
return globals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Features getFeatures() {
|
||||
return AccumuloFeatures.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
// @Override
|
||||
public Vertex addVertex(Object id) {
|
||||
if (id == null) {
|
||||
id = AccumuloGraphUtils.generateId();
|
||||
@@ -136,8 +126,19 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
|
||||
return vert;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
/**
|
||||
* Flushes the backing writers so the data is persisted.
|
||||
* @throws MutationsRejectedException
|
||||
*/
|
||||
public void flush() throws MutationsRejectedException{
|
||||
globals.getMtbw().flush();
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
public Vertex getVertex(Object id) {
|
||||
if (id == null) {
|
||||
throw ExceptionFactory.vertexIdCanNotBeNull();
|
||||
@@ -175,12 +176,12 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
return vertex;
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public void removeVertex(Vertex vertex) {
|
||||
vertex.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public Iterable<Vertex> getVertices() {
|
||||
return globals.getVertexWrapper().getVertices();
|
||||
}
|
||||
@@ -199,23 +200,36 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
public Iterable<Vertex> getVerticesInRange(Object fromId, Object toId) {
|
||||
return globals.getVertexWrapper().getVerticesInRange(fromId, toId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<Vertex> getVertices(String key, Object value) {
|
||||
AccumuloGraphUtils.validateProperty(key, value);
|
||||
if (globals.getConfig().getAutoIndex() || getIndexedKeys(Vertex.class).contains(key)) {
|
||||
return globals.getVertexKeyIndexWrapper().getVertices(key, value);
|
||||
} else {
|
||||
return globals.getVertexWrapper().getVertices(key, value);
|
||||
public Iterator<Vertex> vertices(Object... vertexIds) {
|
||||
if(vertexIds.length==0){
|
||||
return globals.getVertexWrapper().getVertices().iterator();
|
||||
}else{
|
||||
List<Vertex> edges = new ArrayList<Vertex>(vertexIds.length);
|
||||
for(Object id : vertexIds){
|
||||
edges.add(getVertex(id));
|
||||
}
|
||||
return edges.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public Iterable<Vertex> getVertices(String key, Object value) {
|
||||
AccumuloGraphUtils.validateProperty(key, value);
|
||||
// if (globals.getConfig().getAutoIndex() || getIndexedKeys(Vertex.class).contains(key)) {
|
||||
// return globals.getVertexKeyIndexWrapper().getVertices(key, value);
|
||||
// } else {
|
||||
return globals.getVertexWrapper().getVertices(key, value);
|
||||
// }
|
||||
}
|
||||
|
||||
// @Override
|
||||
public Edge addEdge(Object id, Vertex outVertex, Vertex inVertex, String label) {
|
||||
return ((AccumuloVertex) outVertex).addEdge(id, label, inVertex);
|
||||
}
|
||||
|
||||
@Override
|
||||
//@Override
|
||||
public Edge getEdge(Object id) {
|
||||
if (id == null) {
|
||||
throw ExceptionFactory.edgeIdCanNotBeNull();
|
||||
@@ -256,38 +270,41 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
return edge;
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public void removeEdge(Edge edge) {
|
||||
edge.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Edge> getEdges() {
|
||||
return globals.getEdgeWrapper().getEdges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Edge> getEdges(String key, Object value) {
|
||||
AccumuloGraphUtils.nullCheckProperty(key, value);
|
||||
if (key.equalsIgnoreCase("label")) {
|
||||
key = Constants.LABEL;
|
||||
}
|
||||
|
||||
if (globals.getConfig().getAutoIndex() || getIndexedKeys(Edge.class).contains(key)) {
|
||||
return globals.getEdgeKeyIndexWrapper().getEdges(key, value);
|
||||
} else {
|
||||
return globals.getEdgeWrapper().getEdges(key, value);
|
||||
public Iterator<Edge> edges(Object... ids) {
|
||||
if(ids.length==0){
|
||||
return globals.getEdgeWrapper().getEdges().iterator();
|
||||
}else{
|
||||
List<Edge> edges = new ArrayList<Edge>(ids.length);
|
||||
for(Object id : ids){
|
||||
edges.add(getEdge(id));
|
||||
}
|
||||
return edges.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Eventually
|
||||
@Override
|
||||
public GraphQuery query() {
|
||||
return new DefaultGraphQuery(this);
|
||||
}
|
||||
// @Override
|
||||
// public Iterable<Edge> getEdges(String key, Object value) {
|
||||
// AccumuloGraphUtils.nullCheckProperty(key, value);
|
||||
// if (key.equalsIgnoreCase("label")) {
|
||||
// key = Constants.LABEL;
|
||||
// }
|
||||
//
|
||||
// if (globals.getConfig().getAutoIndex() || getIndexedKeys(Edge.class).contains(key)) {
|
||||
// return globals.getEdgeKeyIndexWrapper().getEdges(key, value);
|
||||
// } else {
|
||||
// return globals.getEdgeWrapper().getEdges(key, value);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
public void close() {
|
||||
try {
|
||||
globals.getMtbw().close();
|
||||
globals.getVertexWrapper().close();
|
||||
@@ -304,136 +321,136 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
return AccumuloGraphConfiguration.ACCUMULO_GRAPH_CLASS.getSimpleName().toLowerCase();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public <T extends Element> Index<T> createIndex(String indexName,
|
||||
Class<T> indexClass, Parameter... indexParameters) {
|
||||
if (indexClass == null) {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
else if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
}
|
||||
// @SuppressWarnings("rawtypes")
|
||||
// @Override
|
||||
// public <T extends Element> Index<T> createIndex(String indexName,
|
||||
// Class<T> indexClass, Parameter... indexParameters) {
|
||||
// if (indexClass == null) {
|
||||
// throw ExceptionFactory.classForElementCannotBeNull();
|
||||
// }
|
||||
// else if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
// throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
// }
|
||||
//
|
||||
// for (Index<?> index : globals.getIndexMetadataWrapper().getIndices()) {
|
||||
// if (index.getIndexName().equals(indexName)) {
|
||||
// throw ExceptionFactory.indexAlreadyExists(indexName);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return globals.getIndexMetadataWrapper().createIndex(indexName, indexClass);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public <T extends Element> Index<T> getIndex(String indexName, Class<T> indexClass) {
|
||||
// if (indexClass == null) {
|
||||
// throw ExceptionFactory.classForElementCannotBeNull();
|
||||
// }
|
||||
// else if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
// throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
// }
|
||||
//
|
||||
// return globals.getIndexMetadataWrapper().getIndex(indexName, indexClass);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Iterable<Index<? extends Element>> getIndices() {
|
||||
// if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
// throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
// }
|
||||
// return globals.getIndexMetadataWrapper().getIndices();
|
||||
// }
|
||||
|
||||
for (Index<?> index : globals.getIndexMetadataWrapper().getIndices()) {
|
||||
if (index.getIndexName().equals(indexName)) {
|
||||
throw ExceptionFactory.indexAlreadyExists(indexName);
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void dropIndex(String indexName) {
|
||||
// if (globals.getConfig().getIndexableGraphDisabled())
|
||||
// throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
//
|
||||
// for (Index<? extends Element> index : getIndices()) {
|
||||
// if (index.getIndexName().equals(indexName)) {
|
||||
// globals.getIndexMetadataWrapper().clearIndexNameEntry(indexName, index.getIndexClass());
|
||||
//
|
||||
// try {
|
||||
// globals.getConfig().getConnector().tableOperations().delete(globals.getConfig()
|
||||
// .getNamedIndexTableName(indexName));
|
||||
// } catch (Exception e) {
|
||||
// throw new AccumuloGraphException(e);
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// throw new AccumuloGraphException("Index does not exist: "+indexName);
|
||||
// }
|
||||
|
||||
return globals.getIndexMetadataWrapper().createIndex(indexName, indexClass);
|
||||
}
|
||||
// @Override
|
||||
// public <T extends Element> void dropKeyIndex(String key, Class<T> elementClass) {
|
||||
// // TODO Move below to somewhere appropriate.
|
||||
// if (elementClass == null) {
|
||||
// throw ExceptionFactory.classForElementCannotBeNull();
|
||||
// }
|
||||
//
|
||||
// globals.getIndexMetadataWrapper().clearKeyMetadataEntry(key, elementClass);
|
||||
//
|
||||
// String table = null;
|
||||
// if (elementClass.equals(Vertex.class)) {
|
||||
// table = globals.getConfig().getVertexKeyIndexTableName();
|
||||
// } else {
|
||||
// table = globals.getConfig().getEdgeKeyIndexTableName();
|
||||
// }
|
||||
// BatchDeleter bd = null;
|
||||
// try {
|
||||
// bd = globals.getConfig().getConnector().createBatchDeleter(table, globals.getConfig().getAuthorizations(), globals.getConfig().getMaxWriteThreads(), globals.getConfig().getBatchWriterConfig());
|
||||
// bd.setRanges(Collections.singleton(new Range()));
|
||||
// bd.fetchColumnFamily(new Text(key));
|
||||
// bd.delete();
|
||||
// } catch (Exception e) {
|
||||
// throw new AccumuloGraphException(e);
|
||||
// } finally {
|
||||
// if (bd != null)
|
||||
// bd.close();
|
||||
// }
|
||||
// globals.checkedFlush();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public <T extends Element> Index<T> getIndex(String indexName, Class<T> indexClass) {
|
||||
if (indexClass == null) {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
else if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
}
|
||||
// @SuppressWarnings("rawtypes")
|
||||
// @Override
|
||||
// public <T extends Element> void createKeyIndex(String key,
|
||||
// Class<T> elementClass, Parameter... indexParameters) {
|
||||
// // TODO Move below to somewhere appropriate.
|
||||
// if (elementClass == null) {
|
||||
// throw ExceptionFactory.classForElementCannotBeNull();
|
||||
// }
|
||||
//
|
||||
// // Add key to indexed keys list.
|
||||
// globals.getIndexMetadataWrapper().writeKeyMetadataEntry(key, elementClass);
|
||||
// globals.checkedFlush();
|
||||
//
|
||||
// // Reindex graph.
|
||||
// globals.getKeyIndexTableWrapper(elementClass).rebuildIndex(key, elementClass);
|
||||
// globals.getVertexKeyIndexWrapper().dump();
|
||||
// globals.checkedFlush();
|
||||
// }
|
||||
|
||||
return globals.getIndexMetadataWrapper().getIndex(indexName, indexClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Index<? extends Element>> getIndices() {
|
||||
if (globals.getConfig().getIndexableGraphDisabled()) {
|
||||
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
}
|
||||
return globals.getIndexMetadataWrapper().getIndices();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropIndex(String indexName) {
|
||||
if (globals.getConfig().getIndexableGraphDisabled())
|
||||
throw new UnsupportedOperationException("IndexableGraph is disabled via the configuration");
|
||||
|
||||
for (Index<? extends Element> index : getIndices()) {
|
||||
if (index.getIndexName().equals(indexName)) {
|
||||
globals.getIndexMetadataWrapper().clearIndexNameEntry(indexName, index.getIndexClass());
|
||||
|
||||
try {
|
||||
globals.getConfig().getConnector().tableOperations().delete(globals.getConfig()
|
||||
.getNamedIndexTableName(indexName));
|
||||
} catch (Exception e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new AccumuloGraphException("Index does not exist: "+indexName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Element> void dropKeyIndex(String key, Class<T> elementClass) {
|
||||
// TODO Move below to somewhere appropriate.
|
||||
if (elementClass == null) {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
|
||||
globals.getIndexMetadataWrapper().clearKeyMetadataEntry(key, elementClass);
|
||||
|
||||
String table = null;
|
||||
if (elementClass.equals(Vertex.class)) {
|
||||
table = globals.getConfig().getVertexKeyIndexTableName();
|
||||
} else {
|
||||
table = globals.getConfig().getEdgeKeyIndexTableName();
|
||||
}
|
||||
BatchDeleter bd = null;
|
||||
try {
|
||||
bd = globals.getConfig().getConnector().createBatchDeleter(table, globals.getConfig().getAuthorizations(), globals.getConfig().getMaxWriteThreads(), globals.getConfig().getBatchWriterConfig());
|
||||
bd.setRanges(Collections.singleton(new Range()));
|
||||
bd.fetchColumnFamily(new Text(key));
|
||||
bd.delete();
|
||||
} catch (Exception e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
} finally {
|
||||
if (bd != null)
|
||||
bd.close();
|
||||
}
|
||||
globals.checkedFlush();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public <T extends Element> void createKeyIndex(String key,
|
||||
Class<T> elementClass, Parameter... indexParameters) {
|
||||
// TODO Move below to somewhere appropriate.
|
||||
if (elementClass == null) {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
|
||||
// Add key to indexed keys list.
|
||||
globals.getIndexMetadataWrapper().writeKeyMetadataEntry(key, elementClass);
|
||||
globals.checkedFlush();
|
||||
|
||||
// Reindex graph.
|
||||
globals.getKeyIndexTableWrapper(elementClass).rebuildIndex(key, elementClass);
|
||||
globals.getVertexKeyIndexWrapper().dump();
|
||||
globals.checkedFlush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
|
||||
return globals.getIndexMetadataWrapper().getIndexedKeys(elementClass);
|
||||
}
|
||||
// @Override
|
||||
// public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
|
||||
// return globals.getIndexMetadataWrapper().getIndexedKeys(elementClass);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Clear out this graph. This drops and recreates the backing tables.
|
||||
*/
|
||||
public void clear() {
|
||||
shutdown();
|
||||
close();
|
||||
|
||||
try {
|
||||
TableOperations tableOps = globals.getConfig()
|
||||
.getConnector().tableOperations();
|
||||
for (Index<? extends Element> index : getIndices()) {
|
||||
tableOps.delete(((AccumuloIndex<? extends Element>)
|
||||
index).getTableName());
|
||||
}
|
||||
// for (Index<? extends Element> index : getIndices()) {
|
||||
// tableOps.delete(((AccumuloIndex<? extends Element>)
|
||||
// index).getTableName());
|
||||
// }
|
||||
|
||||
for (String table : globals.getConfig().getTableNames()) {
|
||||
if (tableOps.exists(table)) {
|
||||
@@ -466,4 +483,46 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Vertex addVertex(Object... keyValues) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C extends GraphComputer> C compute(Class<C> graphComputerClass) throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphComputer compute() throws IllegalArgumentException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Transaction tx() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Variables variables() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration configuration() {
|
||||
return globals.getConfig().getConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,12 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.Cloneable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
@@ -45,8 +48,8 @@ import org.apache.commons.configuration.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration.event.ConfigurationEvent;
|
||||
import org.apache.commons.configuration.event.ConfigurationListener;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
|
||||
import com.tinkerpop.blueprints.Graph;
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
|
||||
@@ -57,7 +60,7 @@ import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
* ease chained setting of parameters.
|
||||
*/
|
||||
public class AccumuloGraphConfiguration extends AbstractConfiguration
|
||||
implements Serializable {
|
||||
implements Serializable, Cloneable {
|
||||
|
||||
private static final long serialVersionUID = 7024072260167873696L;
|
||||
|
||||
@@ -256,6 +259,9 @@ implements Serializable {
|
||||
setPassword("");
|
||||
setCreate(true);
|
||||
}
|
||||
if(InstanceType.Mock.equals(type)){
|
||||
setInstanceName("mock-instance");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -326,6 +332,42 @@ implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public AccumuloGraphConfiguration setTokenWithFallback(byte[] token){
|
||||
try{
|
||||
setToken(token);
|
||||
}catch(IllegalArgumentException e){
|
||||
setPassword(token);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
protected AccumuloGraphConfiguration setToken(byte[] token){
|
||||
conf.setProperty(Keys.PASSWORD, new String(deserailize(token).getPassword()));
|
||||
return this;
|
||||
}
|
||||
|
||||
private PasswordToken deserailize(byte[] tokenBytes){
|
||||
PasswordToken type = null;
|
||||
try {
|
||||
type = PasswordToken.class.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot instantiate " + PasswordToken.class.getName(), e);
|
||||
}
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(tokenBytes);
|
||||
DataInputStream in = new DataInputStream(bais);
|
||||
try {
|
||||
type.readFields(in);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Cannot deserialize provided byte array as class " + PasswordToken.class.getName(), e);
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Shouldn't happen", e);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
public Authorizations getAuthorizations() {
|
||||
return conf.containsKey(Keys.AUTHORIZATIONS) ?
|
||||
new Authorizations(conf.getString(Keys.AUTHORIZATIONS).getBytes()) : null;
|
||||
@@ -929,7 +971,7 @@ implements Serializable {
|
||||
default:
|
||||
throw new AccumuloGraphException("Unexpected instance type: " + inst);
|
||||
}
|
||||
|
||||
|
||||
connector = inst.getConnector(getUser(), new PasswordToken(getPassword()));
|
||||
|
||||
// Make the configuration immutable.
|
||||
|
||||
45
src/main/java/edu/jhuapl/tinkerpop/AccumuloProperty.java
Normal file
45
src/main/java/edu/jhuapl/tinkerpop/AccumuloProperty.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Property;
|
||||
|
||||
public class AccumuloProperty<V> implements Property<V>{
|
||||
|
||||
final AccumuloElement element;
|
||||
final String key;
|
||||
final V value;
|
||||
|
||||
public AccumuloProperty(AccumuloElement ele, String key, V value){
|
||||
this.element=ele;
|
||||
this.key=key;
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V value() throws NoSuchElementException {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPresent() {
|
||||
return value!=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element element() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
element.removeProperty(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,17 +14,21 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.tinkerpop.blueprints.CloseableIterable;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
import com.tinkerpop.blueprints.VertexQuery;
|
||||
import com.tinkerpop.blueprints.util.DefaultVertexQuery;
|
||||
import org.apache.tinkerpop.gremlin.structure.Direction;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Property;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
|
||||
import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality;
|
||||
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
|
||||
|
||||
import com.tinkerpop.blueprints.util.ExceptionFactory;
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@@ -34,22 +38,14 @@ public class AccumuloVertex extends AccumuloElement implements Vertex {
|
||||
super(globals, id, Vertex.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Edge> getEdges(Direction direction, String... labels) {
|
||||
return globals.getVertexWrapper().getEdges(this, direction, labels);
|
||||
//TODO
|
||||
public <V> VertexProperty<V> property(String key, V value){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Vertex> getVertices(Direction direction, String... labels) {
|
||||
return globals.getVertexWrapper().getVertices(this, direction, labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexQuery query() {
|
||||
return new DefaultVertexQuery(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public Edge addEdge(String label, Vertex inVertex) {
|
||||
return addEdge(null, label, inVertex);
|
||||
}
|
||||
@@ -89,13 +85,13 @@ public class AccumuloVertex extends AccumuloElement implements Vertex {
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
globals.getCaches().remove(getId(), Vertex.class);
|
||||
globals.getCaches().remove(id(), Vertex.class);
|
||||
|
||||
super.removeElementFromNamedIndexes();
|
||||
|
||||
// Throw exception if the element does not exist.
|
||||
if (!globals.getVertexWrapper().elementExists(id)) {
|
||||
throw ExceptionFactory.vertexWithIdDoesNotExist(getId());
|
||||
throw ExceptionFactory.vertexWithIdDoesNotExist(id());
|
||||
}
|
||||
|
||||
// Remove properties from key/value indexes.
|
||||
@@ -108,11 +104,11 @@ public class AccumuloVertex extends AccumuloElement implements Vertex {
|
||||
}
|
||||
|
||||
// Remove edges incident to this vertex.
|
||||
CloseableIterable<Edge> iter = (CloseableIterable<Edge>)getEdges(Direction.BOTH);
|
||||
for (Edge edge : iter) {
|
||||
edge.remove();
|
||||
Iterator<Edge> iter = edges(Direction.BOTH);
|
||||
while (iter.hasNext()) {
|
||||
iter.next().remove();
|
||||
}
|
||||
iter.close();
|
||||
//iter.close();
|
||||
|
||||
globals.checkedFlush();
|
||||
|
||||
@@ -123,7 +119,43 @@ public class AccumuloVertex extends AccumuloElement implements Vertex {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + getId() + "]";
|
||||
return StringFactory.vertexString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Edge addEdge(String label, Vertex inVertex, Object... keyValues) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> VertexProperty<V> property(Cardinality cardinality, String key, V value, Object... keyValues) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Edge> edges(Direction direction, String... edgeLabels) {
|
||||
return globals.getVertexWrapper().getEdges(this, direction, edgeLabels).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) {
|
||||
return globals.getVertexWrapper().getVertices(this, direction, edgeLabels).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> Iterator<VertexProperty<V>> properties(String... propertyKeys) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,9 +17,12 @@ package edu.jhuapl.tinkerpop;
|
||||
import org.apache.accumulo.core.client.MultiTableBatchWriter;
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Graph;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.cache.ElementCaches;
|
||||
import edu.jhuapl.tinkerpop.tables.core.EdgeTableWrapper;
|
||||
@@ -39,14 +42,21 @@ public class GlobalInstances {
|
||||
private final AccumuloGraphConfiguration config;
|
||||
private final MultiTableBatchWriter mtbw;
|
||||
private final ElementCaches caches;
|
||||
|
||||
private final Graph graph;
|
||||
public GlobalInstances(AccumuloGraphConfiguration config,
|
||||
MultiTableBatchWriter mtbw, ElementCaches caches) {
|
||||
MultiTableBatchWriter mtbw, ElementCaches caches, AccumuloGraph g) {
|
||||
this.config = config;
|
||||
this.mtbw = mtbw;
|
||||
this.caches = caches;
|
||||
graph=g;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Graph getGraph(){
|
||||
return graph;
|
||||
}
|
||||
|
||||
|
||||
public AccumuloGraphConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@ import org.apache.accumulo.core.client.ScannerBase;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.util.PeekingIterator;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.tinkerpop.blueprints.CloseableIterable;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
|
||||
@@ -16,9 +16,10 @@ package edu.jhuapl.tinkerpop.cache;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
/**
|
||||
* Simple cache for retrieved graph elements,
|
||||
@@ -36,7 +37,7 @@ public class ElementCache<T extends Element> {
|
||||
}
|
||||
|
||||
public void cache(T element) {
|
||||
cache.put(element.getId(), element);
|
||||
cache.put(element.id(), element);
|
||||
}
|
||||
|
||||
public T retrieve(Object id) {
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.cache;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package edu.jhuapl.tinkerpop.mapreduce;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -59,7 +61,7 @@ public class EdgeInputFormat extends InputFormatBase<Text,Edge> {
|
||||
conf.setZooKeeperHosts(EdgeInputFormat.getInstance(attempt).getZooKeepers());
|
||||
conf.setInstanceName(EdgeInputFormat.getInstance(attempt).getInstanceName());
|
||||
conf.setUser(EdgeInputFormat.getPrincipal(attempt));
|
||||
conf.setPassword(EdgeInputFormat.getToken(attempt));
|
||||
conf.setTokenWithFallback(EdgeInputFormat.getToken(attempt));
|
||||
conf.setGraphName(attempt.getConfiguration().get(GRAPH_NAME));
|
||||
if (EdgeInputFormat.getInstance(attempt) instanceof MockInstance) {
|
||||
conf.setInstanceType(InstanceType.Mock);
|
||||
@@ -70,7 +72,7 @@ public class EdgeInputFormat extends InputFormatBase<Text,Edge> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean nextKeyValue() throws IOException, InterruptedException {
|
||||
if (rowIterator.hasNext()) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package edu.jhuapl.tinkerpop.mapreduce;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
@@ -70,10 +71,10 @@ public class ElementOutputFormat extends OutputFormat<NullWritable,Element> {
|
||||
return new NullOutputFormat<Text,Mutation>().getOutputCommitter(context);
|
||||
}
|
||||
|
||||
static class ElementRecordWriter extends RecordWriter<NullWritable,Element> {
|
||||
static class ElementRecordWriter extends RecordWriter<NullWritable,Element> implements Serializable{
|
||||
AccumuloGraphConfiguration config;
|
||||
|
||||
protected ElementRecordWriter(TaskAttemptContext context) {
|
||||
public ElementRecordWriter(TaskAttemptContext context) {
|
||||
config = new AccumuloGraphConfiguration();
|
||||
Configuration jobconf = context.getConfiguration();
|
||||
config.setUser(jobconf.get(USER));
|
||||
@@ -85,7 +86,7 @@ public class ElementOutputFormat extends OutputFormat<NullWritable,Element> {
|
||||
|
||||
}
|
||||
|
||||
BatchWriter bw;
|
||||
transient BatchWriter bw;
|
||||
|
||||
@Override
|
||||
public void write(NullWritable key, Element value) throws IOException, InterruptedException {
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.mapreduce;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
@@ -21,7 +23,7 @@ import com.tinkerpop.blueprints.util.ExceptionFactory;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class MapReduceEdge extends MapReduceElement implements Edge {
|
||||
public class MapReduceEdge extends MapReduceElement implements Edge, Serializable {
|
||||
|
||||
String sourceId;
|
||||
String label;
|
||||
@@ -30,6 +32,8 @@ public class MapReduceEdge extends MapReduceElement implements Edge {
|
||||
MapReduceEdge(AccumuloGraph parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
MapReduceEdge() { super(); }
|
||||
|
||||
void setSourceId(String id) {
|
||||
sourceId = id;
|
||||
|
||||
@@ -17,6 +17,7 @@ package edu.jhuapl.tinkerpop.mapreduce;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -31,7 +32,7 @@ import com.tinkerpop.blueprints.Graph;
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public abstract class MapReduceElement implements Element, WritableComparable<MapReduceElement> {
|
||||
public abstract class MapReduceElement implements Serializable, Element, WritableComparable<MapReduceElement> {
|
||||
|
||||
protected String id;
|
||||
|
||||
@@ -39,10 +40,14 @@ public abstract class MapReduceElement implements Element, WritableComparable<Ma
|
||||
|
||||
protected Map<String,Object> newProperties;
|
||||
|
||||
AccumuloGraph parent;
|
||||
transient AccumuloGraph parent;
|
||||
|
||||
MapReduceElement(AccumuloGraph parent) {
|
||||
this();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
MapReduceElement(){
|
||||
properties = new HashMap<String,Object>();
|
||||
newProperties = new HashMap<String,Object>();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package edu.jhuapl.tinkerpop.mapreduce;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -33,7 +34,7 @@ import com.tinkerpop.blueprints.util.DefaultVertexQuery;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class MapReduceVertex extends MapReduceElement implements Vertex {
|
||||
public class MapReduceVertex extends MapReduceElement implements Vertex, Serializable {
|
||||
|
||||
List<Edge> inEdges;
|
||||
List<Edge> outEdges;
|
||||
@@ -43,8 +44,14 @@ public class MapReduceVertex extends MapReduceElement implements Vertex {
|
||||
inEdges = new LinkedList<Edge>();
|
||||
outEdges = new LinkedList<Edge>();
|
||||
}
|
||||
|
||||
MapReduceVertex(){
|
||||
//super();
|
||||
inEdges = new LinkedList<Edge>();
|
||||
outEdges = new LinkedList<Edge>();
|
||||
}
|
||||
|
||||
void prepareEdge(String id, String src, String label, String dest) {
|
||||
MapReduceEdge prepareEdge(String id, String src, String label, String dest) {
|
||||
MapReduceEdge mre = new MapReduceEdge(parent, id, src, label, dest);
|
||||
if (src.equals(getId())) {
|
||||
outEdges.add(mre);
|
||||
@@ -54,6 +61,7 @@ public class MapReduceVertex extends MapReduceElement implements Vertex {
|
||||
if (dest.equals(getId())) {
|
||||
inEdges.add(mre);
|
||||
}
|
||||
return mre;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package edu.jhuapl.tinkerpop.mapreduce;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -23,8 +25,8 @@ import com.tinkerpop.blueprints.Vertex;
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
|
||||
public class VertexInputFormat extends InputFormatBase<Text,Vertex> {
|
||||
@@ -59,7 +61,7 @@ public class VertexInputFormat extends InputFormatBase<Text,Vertex> {
|
||||
conf.setZooKeeperHosts(VertexInputFormat.getInstance(attempt).getZooKeepers());
|
||||
conf.setInstanceName(VertexInputFormat.getInstance(attempt).getInstanceName());
|
||||
conf.setUser(VertexInputFormat.getPrincipal(attempt));
|
||||
conf.setPassword(VertexInputFormat.getToken(attempt));
|
||||
conf.setTokenWithFallback(VertexInputFormat.getToken(attempt));
|
||||
conf.setGraphName(attempt.getConfiguration().get(GRAPH_NAME));
|
||||
if (VertexInputFormat.getInstance(attempt) instanceof MockInstance) {
|
||||
conf.setInstanceType(InstanceType.Mock);
|
||||
@@ -70,6 +72,8 @@ public class VertexInputFormat extends InputFormatBase<Text,Vertex> {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean nextKeyValue() throws IOException, InterruptedException {
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutator;
|
||||
|
||||
@@ -27,10 +26,10 @@ public abstract class BaseEdgeMutator implements Mutator {
|
||||
protected final String label;
|
||||
|
||||
public BaseEdgeMutator(Edge edge) {
|
||||
this(edge.getId().toString(),
|
||||
edge.getVertex(Direction.OUT).getId().toString(),
|
||||
edge.getVertex(Direction.IN).getId().toString(),
|
||||
edge.getLabel());
|
||||
this(edge.id().toString(),
|
||||
edge.outVertex().id().toString(),
|
||||
edge.inVertex().id().toString(),
|
||||
edge.label());
|
||||
}
|
||||
public BaseEdgeMutator(String id, String outVertexId, String inVertexId, String label) {
|
||||
this.id = id;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.index;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
import edu.jhuapl.tinkerpop.Constants.IndexMetadataEntryType;
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.parser;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
|
||||
|
||||
@@ -30,8 +30,10 @@ import org.apache.accumulo.core.iterators.user.RegExFilter;
|
||||
import org.apache.accumulo.core.util.PeekingIterator;
|
||||
import org.apache.hadoop.io.Text;
|
||||
|
||||
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
|
||||
import com.tinkerpop.blueprints.CloseableIterable;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloEdge;
|
||||
|
||||
@@ -17,8 +17,8 @@ package edu.jhuapl.tinkerpop.tables.core;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.accumulo.core.client.BatchWriter;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
@@ -28,16 +28,16 @@ import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.user.RegExFilter;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.util.StringFactory;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
import edu.jhuapl.tinkerpop.GlobalInstances;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.mutator.property.ClearPropertyMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.property.WritePropertyMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.parser.PropertyParser;
|
||||
import edu.jhuapl.tinkerpop.tables.BaseTableWrapper;
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
public <V> V readProperty(Element element, String key) {
|
||||
Scanner s = getScanner();
|
||||
|
||||
s.setRange(new Range(element.getId().toString()));
|
||||
s.setRange(new Range(element.id().toString()));
|
||||
|
||||
Text colf = StringFactory.LABEL.equals(key)
|
||||
? new Text(Constants.LABEL) : new Text(key);
|
||||
@@ -112,7 +112,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
*/
|
||||
public Map<String, Object> readProperties(Element element, String[] propertyKeys) {
|
||||
Scanner s = getScanner();
|
||||
s.setRange(Range.exact((String) element.getId()));
|
||||
s.setRange(Range.exact((String) element.id()));
|
||||
|
||||
// If propertyKeys is null, we read everything.
|
||||
// Otherwise, limit to the given attributes.
|
||||
@@ -158,7 +158,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
public Set<String> readPropertyKeys(Element element) {
|
||||
Scanner s = getScanner();
|
||||
|
||||
s.setRange(new Range(element.getId().toString()));
|
||||
s.setRange(new Range(element.id().toString()));
|
||||
|
||||
Set<String> keys = new HashSet<String>();
|
||||
|
||||
@@ -184,7 +184,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
*/
|
||||
public void clearProperty(Element element, String key) {
|
||||
Mutators.apply(getWriter(),
|
||||
new ClearPropertyMutator(element.getId().toString(), key));
|
||||
new ClearPropertyMutator(element.id().toString(), key));
|
||||
globals.checkedFlush();
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
*/
|
||||
public void writeProperty(Element element, String key, Object value) {
|
||||
Mutators.apply(getWriter(),
|
||||
new WritePropertyMutator(element.getId().toString(),
|
||||
new WritePropertyMutator(element.id().toString(),
|
||||
key, value));
|
||||
globals.checkedFlush();
|
||||
}
|
||||
|
||||
@@ -30,11 +30,15 @@ import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.user.RegExFilter;
|
||||
import org.apache.accumulo.core.util.PeekingIterator;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.structure.Direction;
|
||||
import org.apache.tinkerpop.gremlin.structure.Edge;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
|
||||
import com.tinkerpop.blueprints.CloseableIterable;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloEdge;
|
||||
@@ -67,7 +71,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
* @param vertex
|
||||
*/
|
||||
public void writeVertex(Vertex vertex) {
|
||||
Mutators.apply(getWriter(), new AddVertexMutator(vertex.getId().toString()));
|
||||
Mutators.apply(getWriter(), new AddVertexMutator(vertex.id().toString()));
|
||||
globals.checkedFlush();
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
|
||||
try {
|
||||
deleter = getDeleter();
|
||||
deleter.setRanges(Arrays.asList(Range.exact((String) vertex.getId())));
|
||||
deleter.setRanges(Arrays.asList(Range.exact((String) vertex.id())));
|
||||
deleter.delete();
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -111,7 +115,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
public CloseableIterable<Edge> getEdges(Vertex vertex, Direction direction,
|
||||
String... labels) {
|
||||
Scanner scan = getScanner();
|
||||
scan.setRange(new Range(vertex.getId().toString()));
|
||||
scan.setRange(new Range(vertex.id().toString()));
|
||||
if (direction.equals(Direction.IN)) {
|
||||
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
|
||||
} else if (direction.equals(Direction.OUT)) {
|
||||
@@ -157,7 +161,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
|
||||
public Iterable<Vertex> getVertices(Vertex vertex, Direction direction, String... labels) {
|
||||
Scanner scan = getScanner();
|
||||
scan.setRange(new Range(vertex.getId().toString()));
|
||||
scan.setRange(new Range(vertex.id().toString()));
|
||||
if (direction.equals(Direction.IN)) {
|
||||
scan.fetchColumnFamily(new Text(Constants.IN_EDGE));
|
||||
} else if (direction.equals(Direction.OUT)) {
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.user.RegExFilter;
|
||||
import org.apache.accumulo.core.util.PeekingIterator;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
import org.apache.tinkerpop.gremlin.structure.Vertex;
|
||||
|
||||
import com.tinkerpop.blueprints.CloseableIterable;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloElement;
|
||||
@@ -103,7 +103,7 @@ public abstract class BaseIndexValuesTableWrapper extends BaseTableWrapper {
|
||||
.getIndexedKeys(elementType).contains(key)) {
|
||||
BatchWriter writer = getWriter();
|
||||
|
||||
Object oldValue = element.getProperty(key);
|
||||
Object oldValue = element.property(key);
|
||||
if (oldValue != null && !oldValue.equals(value)) {
|
||||
Mutators.apply(writer, new IndexValueMutator.Delete(element, key, oldValue));
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public abstract class BaseIndexValuesTableWrapper extends BaseTableWrapper {
|
||||
|
||||
IteratorSetting is = new IteratorSetting(10, "getEdgeFilter", RegExFilter.class);
|
||||
RegExFilter.setRegexs(is, null, null,
|
||||
"^"+Pattern.quote(element.getId().toString())+"$", null, false);
|
||||
"^"+Pattern.quote(element.id().toString())+"$", null, false);
|
||||
deleter.addScanIterator(is);
|
||||
deleter.delete();
|
||||
deleter.close();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Set;
|
||||
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.tinkerpop.gremlin.structure.Element;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
import com.tinkerpop.blueprints.Index;
|
||||
import com.tinkerpop.blueprints.IndexableGraph;
|
||||
import com.tinkerpop.blueprints.KeyIndexableGraph;
|
||||
|
||||
@@ -1,296 +1,309 @@
|
||||
/* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.tinkerpop.blueprints.GraphFactory;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
|
||||
|
||||
public class AccumuloGraphConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void testConfigurationInterface() throws Exception {
|
||||
Configuration conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsValid");
|
||||
for (String key : AccumuloGraphConfiguration.getValidInternalKeys()) {
|
||||
// This is bad... but we should allow them if they are valid keys.
|
||||
conf.setProperty(key, "value");
|
||||
}
|
||||
|
||||
conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsInvalid");
|
||||
try {
|
||||
conf.setProperty("invalidKey", "value");
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplits() throws Exception {
|
||||
AccumuloGraphConfiguration cfg;
|
||||
|
||||
// Tests for splits string.
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplits").setSplits((String) null);
|
||||
AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplits").setSplits("");
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("threeSplits").setSplits(" a b c ");
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
|
||||
assertEquals(3, splits.size());
|
||||
List<Text> arr = new ArrayList<Text>(splits);
|
||||
assertEquals("a", arr.get(0).toString());
|
||||
assertEquals("b", arr.get(1).toString());
|
||||
assertEquals("c", arr.get(2).toString());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
// Tests for splits array.
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplitsArray").setSplits((String[]) null);
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplitsArray").setSplits(new String[] {});
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("threeSplitsArray").setSplits(new String[] {"d", "e", "f"});
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
|
||||
assertEquals(3, splits.size());
|
||||
List<Text> arr = new ArrayList<Text>(splits);
|
||||
assertEquals("d", arr.get(0).toString());
|
||||
assertEquals("e", arr.get(1).toString());
|
||||
assertEquals("f", arr.get(2).toString());
|
||||
}
|
||||
graph.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValues() throws Exception {
|
||||
AccumuloGraph graph = new AccumuloGraph(AccumuloGraphTestUtils.generateGraphConfig("propertyValues"));
|
||||
// Tests for serialization/deserialization of properties.
|
||||
QName qname = new QName("ns", "prop");
|
||||
Vertex v = graph.addVertex(null);
|
||||
v.setProperty("qname", qname);
|
||||
assertTrue(v.getProperty("qname") instanceof QName);
|
||||
assertTrue(qname.equals(v.getProperty("qname")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("isEmpty");
|
||||
AccumuloGraph graph = new AccumuloGraph(cfg);
|
||||
assertTrue(graph.isEmpty());
|
||||
|
||||
graph.addVertex("A");
|
||||
assertFalse(graph.isEmpty());
|
||||
|
||||
graph.clear();
|
||||
assertTrue(graph.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndClear() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("noCreate").setCreate(false);
|
||||
try {
|
||||
new AccumuloGraph(cfg);
|
||||
fail("Create is disabled and graph does not exist");
|
||||
} catch (Exception e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("yesCreate").setCreate(true);
|
||||
for (String t : cfg.getTableNames()) {
|
||||
assertFalse(cfg.getConnector().tableOperations().exists(t));
|
||||
}
|
||||
AccumuloGraph graph = new AccumuloGraph(cfg);
|
||||
for (String t : cfg.getTableNames()) {
|
||||
assertTrue(cfg.getConnector().tableOperations().exists(t));
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
graph = new AccumuloGraph(cfg.clone().setCreate(false));
|
||||
assertTrue(graph.isEmpty());
|
||||
graph.addVertex("A");
|
||||
graph.addVertex("B");
|
||||
assertFalse(graph.isEmpty());
|
||||
graph.shutdown();
|
||||
|
||||
graph = new AccumuloGraph(cfg.clone().setClear(true));
|
||||
assertTrue(graph.isEmpty());
|
||||
graph.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrint() throws Exception {
|
||||
AccumuloGraphConfiguration cfg =
|
||||
AccumuloGraphTestUtils.generateGraphConfig("printTest");
|
||||
cfg.print();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidCacheParams() throws Exception {
|
||||
int size = 100;
|
||||
int timeout = 30000;
|
||||
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils
|
||||
.generateGraphConfig("cacheParams");
|
||||
cfg.validate();
|
||||
|
||||
|
||||
// Vertex cache.
|
||||
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
try {
|
||||
cfg.setVertexCacheParams(-1, timeout);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setVertexCacheParams(size, -1);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
cfg.setVertexCacheParams(size, timeout);
|
||||
cfg.validate();
|
||||
assertTrue(cfg.getVertexCacheEnabled());
|
||||
assertEquals(size, cfg.getVertexCacheSize());
|
||||
assertEquals(timeout, cfg.getVertexCacheTimeout());
|
||||
|
||||
cfg.setVertexCacheParams(-1, -1);
|
||||
cfg.validate();
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
|
||||
// Edge cache.
|
||||
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
|
||||
try {
|
||||
cfg.setEdgeCacheParams(-1, timeout);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setEdgeCacheParams(size, -1);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
|
||||
cfg.setEdgeCacheParams(size, timeout);
|
||||
cfg.validate();
|
||||
assertTrue(cfg.getEdgeCacheEnabled());
|
||||
assertEquals(size, cfg.getEdgeCacheSize());
|
||||
assertEquals(timeout, cfg.getEdgeCacheTimeout());
|
||||
|
||||
cfg.setEdgeCacheParams(-1, -1);
|
||||
cfg.validate();
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test different kinds of graph names (hyphens, punctuation, etc).
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGraphNames() throws Exception {
|
||||
AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();
|
||||
|
||||
String[] valid = new String[] {
|
||||
"alpha", "12345", "alnum12345",
|
||||
"12345alnum", "under_score1", "_under_score_2"};
|
||||
String[] invalid = new String[] {"hyph-en",
|
||||
"dot..s", "quo\"tes"};
|
||||
|
||||
for (String name : valid) {
|
||||
conf.setGraphName(name);
|
||||
}
|
||||
|
||||
for (String name : invalid) {
|
||||
try {
|
||||
conf.setGraphName(name);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreloadedProperties() {
|
||||
// Don't allow "all" and "some" preloaded properties.
|
||||
AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();
|
||||
conf.setPreloadAllProperties(true);
|
||||
conf.setPreloadedProperties(new String[]{"one", "two", "three"});
|
||||
try {
|
||||
conf.validate();
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImmutableConnector() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = new AccumuloGraphConfiguration().setInstanceType(
|
||||
InstanceType.Mock).setGraphName("immutableConnector")
|
||||
.setCreate(true).setAutoFlush(false);
|
||||
|
||||
cfg.getConnector();
|
||||
|
||||
try {
|
||||
cfg.setCreate(false);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setAutoFlush(true);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertTrue(cfg.getCreate());
|
||||
assertFalse(cfg.getAutoFlush());
|
||||
}
|
||||
}
|
||||
/* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.mock.MockInstance;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.tinkerpop.blueprints.GraphFactory;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
|
||||
|
||||
public class AccumuloGraphConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void testConfigurationInterface() throws Exception {
|
||||
Configuration conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsValid");
|
||||
for (String key : AccumuloGraphConfiguration.getValidInternalKeys()) {
|
||||
// This is bad... but we should allow them if they are valid keys.
|
||||
conf.setProperty(key, "value");
|
||||
}
|
||||
|
||||
conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsInvalid");
|
||||
try {
|
||||
conf.setProperty("invalidKey", "value");
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplits() throws Exception {
|
||||
AccumuloGraphConfiguration cfg;
|
||||
|
||||
// Tests for splits string.
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplits").setSplits((String) null);
|
||||
AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplits").setSplits("");
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("threeSplits").setSplits(" a b c ");
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
|
||||
assertEquals(3, splits.size());
|
||||
List<Text> arr = new ArrayList<Text>(splits);
|
||||
assertEquals("a", arr.get(0).toString());
|
||||
assertEquals("b", arr.get(1).toString());
|
||||
assertEquals("c", arr.get(2).toString());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
// Tests for splits array.
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplitsArray").setSplits((String[]) null);
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplitsArray").setSplits(new String[] {});
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("threeSplitsArray").setSplits(new String[] {"d", "e", "f"});
|
||||
graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
|
||||
for (String table : cfg.getTableNames()) {
|
||||
Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
|
||||
assertEquals(3, splits.size());
|
||||
List<Text> arr = new ArrayList<Text>(splits);
|
||||
assertEquals("d", arr.get(0).toString());
|
||||
assertEquals("e", arr.get(1).toString());
|
||||
assertEquals("f", arr.get(2).toString());
|
||||
}
|
||||
graph.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValues() throws Exception {
|
||||
AccumuloGraph graph = new AccumuloGraph(AccumuloGraphTestUtils.generateGraphConfig("propertyValues"));
|
||||
// Tests for serialization/deserialization of properties.
|
||||
QName qname = new QName("ns", "prop");
|
||||
Vertex v = graph.addVertex(null);
|
||||
v.setProperty("qname", qname);
|
||||
assertTrue(v.getProperty("qname") instanceof QName);
|
||||
assertTrue(qname.equals(v.getProperty("qname")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("isEmpty");
|
||||
AccumuloGraph graph = new AccumuloGraph(cfg);
|
||||
assertTrue(graph.isEmpty());
|
||||
|
||||
graph.addVertex("A");
|
||||
assertFalse(graph.isEmpty());
|
||||
|
||||
graph.clear();
|
||||
assertTrue(graph.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndClear() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("noCreate").setCreate(false);
|
||||
try {
|
||||
new AccumuloGraph(cfg);
|
||||
fail("Create is disabled and graph does not exist");
|
||||
} catch (Exception e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
cfg = AccumuloGraphTestUtils.generateGraphConfig("yesCreate").setCreate(true);
|
||||
for (String t : cfg.getTableNames()) {
|
||||
assertFalse(cfg.getConnector().tableOperations().exists(t));
|
||||
}
|
||||
AccumuloGraph graph = new AccumuloGraph(cfg);
|
||||
for (String t : cfg.getTableNames()) {
|
||||
assertTrue(cfg.getConnector().tableOperations().exists(t));
|
||||
}
|
||||
graph.shutdown();
|
||||
|
||||
graph = new AccumuloGraph(cfg.clone().setCreate(false));
|
||||
assertTrue(graph.isEmpty());
|
||||
graph.addVertex("A");
|
||||
graph.addVertex("B");
|
||||
assertFalse(graph.isEmpty());
|
||||
graph.shutdown();
|
||||
|
||||
graph = new AccumuloGraph(cfg.clone().setClear(true));
|
||||
assertTrue(graph.isEmpty());
|
||||
graph.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrint() throws Exception {
|
||||
AccumuloGraphConfiguration cfg =
|
||||
AccumuloGraphTestUtils.generateGraphConfig("printTest");
|
||||
cfg.print();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidCacheParams() throws Exception {
|
||||
int size = 100;
|
||||
int timeout = 30000;
|
||||
|
||||
AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils
|
||||
.generateGraphConfig("cacheParams");
|
||||
cfg.validate();
|
||||
|
||||
|
||||
// Vertex cache.
|
||||
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
try {
|
||||
cfg.setVertexCacheParams(-1, timeout);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setVertexCacheParams(size, -1);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
cfg.setVertexCacheParams(size, timeout);
|
||||
cfg.validate();
|
||||
assertTrue(cfg.getVertexCacheEnabled());
|
||||
assertEquals(size, cfg.getVertexCacheSize());
|
||||
assertEquals(timeout, cfg.getVertexCacheTimeout());
|
||||
|
||||
cfg.setVertexCacheParams(-1, -1);
|
||||
cfg.validate();
|
||||
assertFalse(cfg.getVertexCacheEnabled());
|
||||
|
||||
|
||||
// Edge cache.
|
||||
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
|
||||
try {
|
||||
cfg.setEdgeCacheParams(-1, timeout);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setEdgeCacheParams(size, -1);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
|
||||
cfg.setEdgeCacheParams(size, timeout);
|
||||
cfg.validate();
|
||||
assertTrue(cfg.getEdgeCacheEnabled());
|
||||
assertEquals(size, cfg.getEdgeCacheSize());
|
||||
assertEquals(timeout, cfg.getEdgeCacheTimeout());
|
||||
|
||||
cfg.setEdgeCacheParams(-1, -1);
|
||||
cfg.validate();
|
||||
assertFalse(cfg.getEdgeCacheEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test different kinds of graph names (hyphens, punctuation, etc).
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testGraphNames() throws Exception {
|
||||
AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();
|
||||
|
||||
String[] valid = new String[] {
|
||||
"alpha", "12345", "alnum12345",
|
||||
"12345alnum", "under_score1", "_under_score_2"};
|
||||
String[] invalid = new String[] {"hyph-en",
|
||||
"dot..s", "quo\"tes"};
|
||||
|
||||
for (String name : valid) {
|
||||
conf.setGraphName(name);
|
||||
}
|
||||
|
||||
for (String name : invalid) {
|
||||
try {
|
||||
conf.setGraphName(name);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreloadedProperties() {
|
||||
// Don't allow "all" and "some" preloaded properties.
|
||||
AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();
|
||||
conf.setPreloadAllProperties(true);
|
||||
conf.setPreloadedProperties(new String[]{"one", "two", "three"});
|
||||
try {
|
||||
conf.validate();
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImmutableConnector() throws Exception {
|
||||
AccumuloGraphConfiguration cfg = new AccumuloGraphConfiguration().setInstanceType(
|
||||
InstanceType.Mock).setGraphName("immutableConnector")
|
||||
.setCreate(true).setAutoFlush(false);
|
||||
|
||||
cfg.getConnector();
|
||||
|
||||
try {
|
||||
cfg.setCreate(false);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
try {
|
||||
cfg.setAutoFlush(true);
|
||||
fail();
|
||||
} catch (Exception e) { }
|
||||
|
||||
assertTrue(cfg.getCreate());
|
||||
assertFalse(cfg.getAutoFlush());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMockInstanceValue(){
|
||||
AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration().setInstanceType(InstanceType.Mock);
|
||||
assertNotNull(conf.getInstanceName());
|
||||
assertEquals("mock-instance", conf.getInstanceName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user