Skip to content

Instantly share code, notes, and snippets.

@pawel-kaminski-krk
Created January 15, 2018 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawel-kaminski-krk/d351c6f9450bce8421bfc47221da6307 to your computer and use it in GitHub Desktop.
Save pawel-kaminski-krk/d351c6f9450bce8421bfc47221da6307 to your computer and use it in GitHub Desktop.
adding node to cluster in paralel
package io.carousel.it;
import com.google.common.io.Files;
import com.google.common.util.concurrent.Uninterruptibles;
import io.atomix.cluster.Node;
import io.atomix.core.Atomix;
import io.atomix.messaging.Endpoint;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
public class AddNewNodes {
private static final Logger logger = LogManager.getLogger(AddNewNodes.class);
public static void main(String[] args) {
Node[] bootstrapNodes = new Node[] {
Node.builder("server1")
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("127.0.0.1", 5001))
.build(),
Node.builder("server2")
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("127.0.0.1", 5002))
.build(),
Node.builder("server3")
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("127.0.0.1", 5003))
.build()
};
Atomix atomix1 = createAtomicNode("server1", 5001, bootstrapNodes);
Atomix atomix2 = createAtomicNode("server2", 5002, bootstrapNodes);
Atomix atomix3 = createAtomicNode("server3", 5003, bootstrapNodes);
CompletableFuture
.allOf(
atomix1.start(),
atomix2.start(),
atomix3.start()
)
.whenCompleteAsync((aVoid, throwable) -> logger.info("completed ", throwable))
.join();
logger.info("server4/5 joining cluster");
Atomix atomix4 = createAtomicNode("server4", 5004, bootstrapNodes);
Atomix atomix5 = createAtomicNode("server5", 5005, bootstrapNodes);
CompletableFuture
.allOf(
atomix4.start(),
atomix5.start()
)
.whenCompleteAsync((aVoid, throwable) -> logger.info("completed adding 4 and 5", throwable))
.join();
printNodesState(atomix4);
printNodesState(atomix5);
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
System.exit(0);
}
private static void printNodesState(Atomix givenNode) {
logger.info("it seems {} is running {}.", givenNode.clusterService().getLocalNode().id(),
givenNode.isRunning());
for (Node availableNode : givenNode.clusterService().getNodes()) {
logger.info("node {} is in state {}.", availableNode, availableNode.getState());
}
}
private static Atomix createAtomicNode(String nodeId, int port, Node[] bootstrapNodes) {
Atomix.Builder builder = Atomix.builder();
return builder
.withLocalNode(Node.builder(nodeId)
.withType(Node.Type.DATA)
.withEndpoint(Endpoint.from("127.0.0.1", port))
.build())
.withDataDirectory(Files.createTempDir())
.withBootstrapNodes(bootstrapNodes)
.build();
}
}
@nmathew
Copy link

nmathew commented Apr 11, 2018

Hi Pawel,

I need some help, very basic setup in atomix

When I run your code here(above one)(in Windows 7 Machine), I get below errors,:

Any Help?

Apr 11, 2018 3:43:41 PM io.atomix.messaging.impl.NettyMessagingService loadKeyStores
WARNING: Disabling TLS for intra-cluster messaging; Could not load cluster key store: ..\config\atomix.jks (The system cannot find the path specified)
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$startAcceptingConnections$24
INFO: /127.0.0.1 accepting incoming connections on port 5001
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$start$0
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService loadKeyStores
WARNING: Disabling TLS for intra-cluster messaging; Could not load cluster key store: ..\config\atomix.jks (The system cannot find the path specified)
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterMetadataService lambda$start$12
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService loadKeyStores
WARNING: Disabling TLS for intra-cluster messaging; Could not load cluster key store: ..\config\atomix.jks (The system cannot find the path specified)
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterMessagingService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$startAcceptingConnections$24
INFO: /127.0.0.1 accepting incoming connections on port 5002
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterEventingService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$start$0
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterMetadataService lambda$start$12
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterMessagingService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterEventingService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$startAcceptingConnections$24
INFO: /127.0.0.1 accepting incoming connections on port 5003
Apr 11, 2018 3:43:43 PM io.atomix.messaging.impl.NettyMessagingService lambda$start$0
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterMetadataService lambda$start$12
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.impl.DefaultClusterService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterMessagingService start
INFO: Started
Apr 11, 2018 3:43:43 PM io.atomix.cluster.messaging.impl.DefaultClusterEventingService start
INFO: Started
Exception in thread "main" java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: No cluster specified
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:961)
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: No cluster specified
at io.atomix.protocols.raft.impl.DefaultRaftClient.connect(DefaultRaftClient.java:107)
at io.atomix.protocols.raft.partition.impl.RaftPartitionClient.start(RaftPartitionClient.java:85)
at io.atomix.protocols.raft.partition.RaftPartition.open(RaftPartition.java:136)
at io.atomix.protocols.raft.partition.RaftPartitionGroup.lambda$open$1(RaftPartitionGroup.java:124)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1548)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at io.atomix.protocols.raft.partition.RaftPartitionGroup.open(RaftPartitionGroup.java:126)
at io.atomix.core.Atomix.lambda$start$4(Atomix.java:225)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:952)
... 9 more

@nmathew
Copy link

nmathew commented Apr 11, 2018

I am using 2.1.0-SNAPSHOT on java8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment