mirror of
https://github.com/JHUAPL/AccumuloGraph.git
synced 2026-01-09 12:47:56 -05:00
Merge pull request #119 from JHUAPL/passwordToken
Changes to support token changes in 1.6
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
@@ -329,6 +331,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;
|
||||
@@ -932,7 +970,7 @@ implements Serializable {
|
||||
default:
|
||||
throw new AccumuloGraphException("Unexpected instance type: " + inst);
|
||||
}
|
||||
|
||||
|
||||
connector = inst.getConnector(getUser(), new PasswordToken(getPassword()));
|
||||
|
||||
// Make the configuration immutable.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MapReduceVertex extends MapReduceElement implements Vertex, Seriali
|
||||
}
|
||||
|
||||
MapReduceVertex(){
|
||||
super();
|
||||
//super();
|
||||
inEdges = new LinkedList<Edge>();
|
||||
outEdges = new LinkedList<Edge>();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user