We now have AkkaGraphActors configured fully via our Configuration model -- graph.configuration(), actorProgram.configuration(), etc... Generates appropriate Config for Akka and we are off to the races. More work on Host..... I have some good ideas here... didn't have time to get to it today.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/45a24aa5 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/45a24aa5 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/45a24aa5 Branch: refs/heads/TINKERPOP-1564 Commit: 45a24aa59b9213cc88dc11641d4c0a8f41d2d215 Parents: ef185eb Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Thu Jan 12 15:54:52 2017 -0700 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Thu Jan 19 10:28:05 2017 -0700 ---------------------------------------------------------------------- .../conf/akka-tinkerpop-modern.properties | 33 ++++++++++++++++ .../akka/process/actors/AkkaConfigFactory.java | 31 ++++++++++++--- .../akka/process/actors/AkkaGraphActors.java | 12 +++--- .../gremlin/akka/process/actors/Constants.java | 41 ++++++++++++++++++++ .../src/main/resources/application.conf | 23 ----------- .../akka/process/actors/AkkaActorsProvider.java | 16 ++++++-- .../traverser/B_LP_O_P_S_SE_SL_Traverser.java | 3 +- .../traverser/B_LP_O_S_SE_SL_Traverser.java | 3 +- .../traverser/LP_O_OB_P_S_SE_SL_Traverser.java | 3 +- .../traverser/LP_O_OB_S_SE_SL_Traverser.java | 3 +- .../traverser/util/AbstractTraverser.java | 6 +-- .../tinkerpop/gremlin/structure/Partition.java | 13 ++++++- .../gremlin/structure/util/Attachable.java | 37 ++---------------- .../tinkerpop/gremlin/structure/util/Host.java | 6 ++- .../util/config/SerializableConfiguration.java | 19 ++++++++- pom.xml | 1 - 16 files changed, 161 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/conf/akka-tinkerpop-modern.properties ---------------------------------------------------------------------- diff --git a/akka-gremlin/conf/akka-tinkerpop-modern.properties b/akka-gremlin/conf/akka-tinkerpop-modern.properties new file mode 100644 index 0000000..c56408f --- /dev/null +++ b/akka-gremlin/conf/akka-tinkerpop-modern.properties @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph +gremlin.tinkergraph.graphLocation=../data/tinkerpop-modern.kryo +gremlin.tinkergraph.graphFormat=gryo +################################# +# AkkaGraphActors Configuration # +################################# +gremlin.graphActors=org.apache.tinkerpop.gremlin.akka.process.actors.AkkaGraphActors +gremlin.graphActors.workers=2 +akka.actor.serializers.gryo=org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo.GryoSerializer +akka.actor.serialize-messages=on +akka.actor.provider=remote +akka.remote.enabled-transports=akka.remote.netty.tcp +akka.remote.netty.tcp.hostname="127.0.0.1" +akka.remote.netty.tcp.port=2552 +akka.cluster.seed-nodes="akka.tcp://tinkerpop@127.0.0.1:2552" +akka.cluster.auto-down-unreachable-after=10s +akka.log-dead-letters-during-shutdown="false" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java ---------------------------------------------------------------------- diff --git a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java index ad6a3d6..c20e380 100644 --- a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java +++ b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java @@ -22,15 +22,18 @@ package org.apache.tinkerpop.gremlin.akka.process.actors; import akka.actor.Address; import akka.actor.AddressFromURIString; import com.typesafe.config.Config; +import com.typesafe.config.ConfigException; import com.typesafe.config.ConfigFactory; import com.typesafe.config.ConfigValueFactory; +import org.apache.commons.configuration.Configuration; import org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo.GryoSerializer; import org.apache.tinkerpop.gremlin.process.actors.ActorProgram; import org.apache.tinkerpop.gremlin.structure.Partition; -import java.net.InetAddress; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -44,7 +47,7 @@ final class AkkaConfigFactory { // static method class } - static Config generateAkkaConfig(final ActorProgram actorProgram) { + static Config generateAkkaConfig(final ActorProgram actorProgram, final Configuration configuration) { final Map<String, String> registeredGryoClasses = new HashMap<>(); new GryoSerializer().getGryoMapper().getRegisteredClasses().stream().filter(clazz -> !clazz.isArray()).forEach(clazz -> { int index = clazz.getCanonicalName().lastIndexOf("."); @@ -52,7 +55,7 @@ final class AkkaConfigFactory { clazz.getCanonicalName() : clazz.getCanonicalName().substring(0, index) + "$" + clazz.getCanonicalName().substring(index + 1), "gryo"); }); - return ConfigFactory.defaultApplication(). + Config config = ConfigFactory.defaultApplication(). withValue("akka.actor.serialization-bindings", ConfigValueFactory.fromMap(registeredGryoClasses)). withValue("custom-dispatcher.mailbox-requirement", ConfigValueFactory.fromAnyRef(ActorMailbox.class.getCanonicalName() + "$" + ActorMailbox.ActorSemantics.class.getSimpleName())). withValue("custom-dispatcher-mailbox.mailbox-type", ConfigValueFactory.fromAnyRef(ActorMailbox.class.getCanonicalName())). @@ -63,10 +66,28 @@ final class AkkaConfigFactory { stream(). map(Class::getCanonicalName). collect(Collectors.toList()).toString())); + final Iterator<String> keys = configuration.getKeys(); + while (keys.hasNext()) { + final String key = keys.next(); + try { + final Object value = configuration.getProperty(key); + config = config.withValue(key, ConfigValueFactory.fromAnyRef(convertValue(key, value))); + } catch (final ConfigException.BugOrBroken e) { + // do nothing -- basically, unserializable object + } + } + return config; } - static Address getMasterActorDeployment() { - final List<String> seedNodes = ConfigFactory.defaultApplication().getStringList("akka.cluster.seed-nodes"); + private static Object convertValue(final String key, final Object value) { + if (key.equals(Constants.AKKA_REMOTE_ENABLED_TRANSPORTS) || key.equals(Constants.AKKA_CLUSTER_SEED_NODES)) + return value instanceof Collection ? value : Collections.singletonList(value); + else + return value; + } + + static Address getMasterActorDeployment(final Config config) { + final List<String> seedNodes = config.getStringList(Constants.AKKA_CLUSTER_SEED_NODES); return AddressFromURIString.parse(seedNodes.get(0)); } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaGraphActors.java ---------------------------------------------------------------------- diff --git a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaGraphActors.java b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaGraphActors.java index d967aed..04bd071 100644 --- a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaGraphActors.java +++ b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaGraphActors.java @@ -23,6 +23,7 @@ import akka.actor.ActorSystem; import akka.actor.Deploy; import akka.actor.Props; import akka.remote.RemoteScope; +import com.typesafe.config.Config; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationUtils; @@ -82,13 +83,14 @@ public final class AkkaGraphActors<R> implements GraphActors<R> { if (this.executed) throw new IllegalStateException("Can not execute twice"); this.executed = true; - - final ActorSystem system = ActorSystem.create("tinkerpop", AkkaConfigFactory.generateAkkaConfig(this.actorProgram)); + /////// + final Configuration finalConfiguration = new SerializableConfiguration(graph.configuration()); + ConfigurationUtils.copy(this.configuration, finalConfiguration); + final Config config = AkkaConfigFactory.generateAkkaConfig(this.actorProgram, finalConfiguration); + final ActorSystem system = ActorSystem.create("tinkerpop", config); final ActorsResult<R> result = new DefaultActorsResult<>(); - final Configuration finalConfiguration = new SerializableConfiguration(this.configuration); - ConfigurationUtils.copy(graph.configuration(), finalConfiguration); /////// - final akka.actor.Address masterAddress = AkkaConfigFactory.getMasterActorDeployment(); + final akka.actor.Address masterAddress = AkkaConfigFactory.getMasterActorDeployment(config); system.actorOf(Props.create(MasterActor.class, finalConfiguration, result).withDeploy(new Deploy(new RemoteScope(masterAddress))), "master"); return CompletableFuture.supplyAsync(() -> { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/Constants.java ---------------------------------------------------------------------- diff --git a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/Constants.java b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/Constants.java new file mode 100644 index 0000000..dacdd2d --- /dev/null +++ b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/Constants.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.tinkerpop.gremlin.akka.process.actors; + +/** + * @author Marko A. Rodriguez (http://markorodriguez.com) + */ +public final class Constants { + + private Constants() { + // static method class + } + + public static final String AKKA_LOG_DEAD_LETTERS_DURING_SHUTDOWN = "akka.log-dead-letters-during-shutdown"; + public static final String AKKA_ACTOR_SERIALIZE_MESSAGES = "akka.actor.serialize-messages"; + public static final String AKKA_ACTOR_SERIALIZERS_GRYO = "akka.actor.serializers.gryo"; + public static final String AKKA_ACTOR_PROVIDER = "akka.actor.provider"; + public static final String AKKA_REMOTE_ENABLED_TRANSPORTS = "akka.remote.enabled-transports"; + public static final String AKKA_REMOTE_NETTY_TCP_HOSTNAME = "akka.remote.netty.tcp.hostname"; + public static final String AKKA_REMOTE_NETTY_TCP_PORT = "akka.remote.netty.tcp.port"; + public static final String AKKA_CLUSTER_SEED_NODES = "akka.cluster.seed-nodes"; + public static final String AKKA_CLUSTER_AUTO_DOWN_UNREACHABLE_AFTER = "akka.cluster.auto-down-unreachable-after"; + +} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/src/main/resources/application.conf ---------------------------------------------------------------------- diff --git a/akka-gremlin/src/main/resources/application.conf b/akka-gremlin/src/main/resources/application.conf deleted file mode 100644 index 6d1915f..0000000 --- a/akka-gremlin/src/main/resources/application.conf +++ /dev/null @@ -1,23 +0,0 @@ -akka { - log-dead-letters-during-shutdown = "false" - actor { - provider = remote - serialize-messages = on - serializers { - gryo = "org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo.GryoSerializer" - } - } - remote { - enabled-transports = ["akka.remote.netty.tcp"] - netty.tcp { - hostname = "127.0.0.1" - port = 2552 - } - } - cluster { - seed-nodes = [ - "akka.tcp://tinkerpop@127.0.0.1:2552" - "akka.tcp://tinkerpop@127.0.0.1:2552"] - auto-down-unreachable-after = 10s - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/akka-gremlin/src/test/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaActorsProvider.java ---------------------------------------------------------------------- diff --git a/akka-gremlin/src/test/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaActorsProvider.java b/akka-gremlin/src/test/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaActorsProvider.java index b92d39e..8fd2239 100644 --- a/akka-gremlin/src/test/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaActorsProvider.java +++ b/akka-gremlin/src/test/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaActorsProvider.java @@ -23,13 +23,13 @@ import org.apache.commons.configuration.Configuration; import org.apache.tinkerpop.gremlin.AbstractGraphProvider; import org.apache.tinkerpop.gremlin.LoadGraphWith; import org.apache.tinkerpop.gremlin.TestHelper; +import org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo.GryoSerializer; import org.apache.tinkerpop.gremlin.process.actors.GraphActors; import org.apache.tinkerpop.gremlin.process.traversal.TraversalInterruptionTest; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.process.traversal.step.ComplexTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphTest; import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProfileTest; -import org.apache.tinkerpop.gremlin.process.traversal.step.map.ProgramTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GroupTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectTest; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphTest; @@ -50,6 +50,7 @@ import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertexProperty; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -79,8 +80,7 @@ public class AkkaActorsProvider extends AbstractGraphProvider { PartitionStrategyProcessTest.class.getCanonicalName(), EventStrategyProcessTest.class.getCanonicalName(), ElementIdStrategyProcessTest.class.getCanonicalName(), - TraversalInterruptionTest.class.getCanonicalName(), - ProgramTest.Traversals.class.getCanonicalName())); + TraversalInterruptionTest.class.getCanonicalName())); private static final Set<Class> IMPLEMENTATION = new HashSet<Class>() {{ add(TinkerEdge.class); @@ -136,6 +136,16 @@ public class AkkaActorsProvider extends AbstractGraphProvider { if (loadGraphWith == LoadGraphWith.GraphData.CREW) put(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.name()); } + // Akka specific configuration + put(Constants.AKKA_LOG_DEAD_LETTERS_DURING_SHUTDOWN, false); + put(Constants.AKKA_ACTOR_PROVIDER, "remote"); + put(Constants.AKKA_ACTOR_SERIALIZE_MESSAGES, "on"); + put(Constants.AKKA_ACTOR_SERIALIZERS_GRYO, GryoSerializer.class.getCanonicalName()); + put(Constants.AKKA_REMOTE_ENABLED_TRANSPORTS, Collections.singletonList("akka.remote.netty.tcp")); + put(Constants.AKKA_REMOTE_NETTY_TCP_HOSTNAME, "127.0.0.1"); + put(Constants.AKKA_REMOTE_NETTY_TCP_PORT, 2552); + put(Constants.AKKA_CLUSTER_SEED_NODES, Collections.singletonList("akka.tcp://tinkerpop@127.0.0.1:2552")); + put(Constants.AKKA_CLUSTER_AUTO_DOWN_UNREACHABLE_AFTER, "10s"); }}; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java index 02f3306..2f1ffb4 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java @@ -63,8 +63,7 @@ public class B_LP_O_P_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T> { @Override public Traverser.Admin<T> attach(final Host host) { super.attach(host); - if (host instanceof Partition || host instanceof Graph) - this.path = host.attach(this.path); + this.path = host.attach(this.path).orElse(this.path); return this; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java index 5da2c2d..c18ad3b 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java @@ -67,8 +67,7 @@ public class B_LP_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T> { @Override public Traverser.Admin<T> attach(final Host host) { super.attach(host); - if (host instanceof Partition || host instanceof Graph) - this.path = host.attach(this.path); + this.path = host.attach(this.path).orElse(this.path); return this; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java index 4b0d9a7..ee9c038 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java @@ -65,8 +65,7 @@ public class LP_O_OB_P_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T> { @Override public Traverser.Admin<T> attach(final Host host) { super.attach(host); - if (host instanceof Partition || host instanceof Graph) - this.path = host.attach(this.path); + this.path = host.attach(this.path).orElse(this.path); return this; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java index fe60e9e..92f4358 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java @@ -67,8 +67,7 @@ public class LP_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T> { @Override public Traverser.Admin<T> attach(final Host host) { super.attach(host); - if (host instanceof Partition || host instanceof Graph) - this.path = host.attach(this.path); + this.path = host.attach(this.path).orElse(this.path); return this; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java index 0711182..c28c9e5 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java @@ -24,8 +24,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects; import org.apache.tinkerpop.gremlin.process.traversal.Traverser; import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyPath; import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversalSideEffects; -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.Partition; import org.apache.tinkerpop.gremlin.structure.util.Attachable; import org.apache.tinkerpop.gremlin.structure.util.Host; import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory; @@ -142,9 +140,7 @@ public abstract class AbstractTraverser<T> implements Traverser<T>, Traverser.Ad @Override public Admin<T> attach(final Host host) { - // you do not want to attach a path because it will reference graph objects not at the current vertex - if (!(this.t instanceof Path) || host instanceof Graph || host instanceof Partition) - this.t = host.attach(this.t); + this.t = host.attach(this.t).orElse(this.t); return this; } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java index b2d60d1..ba477ad 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java @@ -23,8 +23,8 @@ import org.apache.tinkerpop.gremlin.structure.util.Attachable; import org.apache.tinkerpop.gremlin.structure.util.Host; import java.net.InetAddress; -import java.net.URI; import java.util.Iterator; +import java.util.Optional; import java.util.UUID; /** @@ -71,14 +71,23 @@ public interface Partition extends Host { public String id(); /** - * Get the {@link InetAddress} of the locations physical location. + * Get the {@link InetAddress} of the partition's physical location. * * @return the physical location of the partition. */ public InetAddress location(); + /** + * Get the {@link Partitioner} containing this partition. + * + * @return the partitioner containing the collection of all partitions over the graph + */ public Partitioner partitioner(); + public default <A> Optional<A> attach(final A a) { + return a instanceof Attachable ? Optional.of(((Attachable<A>) a).attach(Attachable.Method.get(this.partitioner().getGraph()))) : Optional.of(a); + } + public static interface PhysicalPartition extends Partition { } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java index cbad51a..fa999aa 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java @@ -22,7 +22,6 @@ import org.apache.tinkerpop.gremlin.structure.Direction; 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.Partition; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -76,27 +75,21 @@ public interface Attachable<V> { if (base instanceof Vertex) { final Optional<Vertex> optional = hostVertexOrGraph instanceof Graph ? Method.getVertex((Attachable<Vertex>) attachable, (Graph) hostVertexOrGraph) : - hostVertexOrGraph instanceof Vertex ? - Method.getVertex((Attachable<Vertex>) attachable, (Vertex) hostVertexOrGraph) : - Method.getVertex((Attachable<Vertex>) attachable, (Partition) hostVertexOrGraph); + Method.getVertex((Attachable<Vertex>) attachable, (Vertex) hostVertexOrGraph); return (V) optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ? Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) : Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph)); } else if (base instanceof Edge) { final Optional<Edge> optional = hostVertexOrGraph instanceof Graph ? Method.getEdge((Attachable<Edge>) attachable, (Graph) hostVertexOrGraph) : - hostVertexOrGraph instanceof Vertex ? - Method.getEdge((Attachable<Edge>) attachable, (Vertex) hostVertexOrGraph) : - Method.getEdge((Attachable<Edge>) attachable, (Partition) hostVertexOrGraph); + Method.getEdge((Attachable<Edge>) attachable, (Vertex) hostVertexOrGraph); return (V) optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ? Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) : Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph)); } else if (base instanceof VertexProperty) { final Optional<VertexProperty> optional = hostVertexOrGraph instanceof Graph ? Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Graph) hostVertexOrGraph) : - hostVertexOrGraph instanceof Vertex ? - Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Vertex) hostVertexOrGraph) : - Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Partition) hostVertexOrGraph); + Method.getVertexProperty((Attachable<VertexProperty>) attachable, (Vertex) hostVertexOrGraph); return (V) optional.orElseThrow(() -> hostVertexOrGraph instanceof Graph ? Attachable.Exceptions.canNotGetAttachableFromHostGraph(attachable, (Graph) hostVertexOrGraph) : Attachable.Exceptions.canNotGetAttachableFromHostVertex(attachable, (Vertex) hostVertexOrGraph)); @@ -185,11 +178,6 @@ public interface Attachable<V> { return ElementHelper.areEqual(attachableVertex.get(), hostVertex) ? Optional.of(hostVertex) : Optional.empty(); } - public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Partition hostPartition) { - final Iterator<Vertex> iterator = hostPartition.partitioner().getGraph().vertices(attachableVertex.get().id()); - return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.empty(); - } - public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) { final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id()); return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty(); @@ -206,11 +194,6 @@ public interface Attachable<V> { return Optional.empty(); } - public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Partition hostPartition) { - final Iterator<Edge> iterator = hostPartition.partitioner().getGraph().edges(attachableEdge.get().id()); - return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.empty(); - } - public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); @@ -236,20 +219,6 @@ public interface Attachable<V> { return Optional.empty(); } - public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Partition hostPartition) { - final VertexProperty baseVertexProperty = attachableVertexProperty.get(); - final Iterator<Vertex> vertexIterator= hostPartition.partitioner().getGraph().vertices(baseVertexProperty.element().id()); - if (vertexIterator.hasNext()) { - final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key()); - while (vertexPropertyIterator.hasNext()) { - final VertexProperty vertexProperty = vertexPropertyIterator.next(); - if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) - return Optional.of(vertexProperty); - } - } - return Optional.empty(); - } - public static Optional<Property> getProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) { final Property baseProperty = attachableProperty.get(); final Element propertyElement = attachableProperty.get().element(); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java index 7ceb728..de3b0a8 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java @@ -18,6 +18,8 @@ */ package org.apache.tinkerpop.gremlin.structure.util; +import java.util.Optional; + /** * A marker interface that identifies an object as something that an {@link Attachable} can connect to. * @@ -26,7 +28,7 @@ package org.apache.tinkerpop.gremlin.structure.util; */ public interface Host { - public default <T> T attach(final T t) { - return t instanceof Attachable ? ((Attachable<T>) t).attach(Attachable.Method.get(this)) : t; + public default <T> Optional<T> attach(final T t) { + return Optional.of(t instanceof Attachable ? ((Attachable<T>) t).attach(Attachable.Method.get(this)) : t); } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/config/SerializableConfiguration.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/config/SerializableConfiguration.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/config/SerializableConfiguration.java index 2a1eac1..44529d1 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/config/SerializableConfiguration.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/config/SerializableConfiguration.java @@ -23,8 +23,11 @@ import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.Configuration; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -46,7 +49,17 @@ public final class SerializableConfiguration extends AbstractConfiguration imple @Override protected void addPropertyDirect(final String key, final Object value) { - this.properties.put(key, value); + Object previous = this.properties.get(key); + if(null == previous) + this.properties.put(key,value); + else if(previous instanceof Collection) + ((Collection) previous).add(value); + else { + final List list = new ArrayList<>(); + list.add(previous); + list.add(value); + this.properties.put(key,list); + } } @Override @@ -74,4 +87,8 @@ public final class SerializableConfiguration extends AbstractConfiguration imple return this.properties.keySet().iterator(); } + @Override + public String toString() { + return this.properties.toString(); + } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/45a24aa5/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 97e8cdf..e1b5200 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,6 @@ limitations under the License. <exclude>gremlin-console/bin/gremlin.sh</exclude> <exclude>docs/site/home/css/**</exclude> <exclude>docs/site/home/js/**</exclude> - <exclude>**/resources/application.conf</exclude> </excludes> <licenses> <license implementation="org.apache.rat.analysis.license.ApacheSoftwareLicense20"/>