Search in sources :

Example 6 with Node

use of io.atomix.cluster.Node in project atomix by atomix.

the class RaftPerformanceTest method nextNode.

/**
 * Returns the next unique member identifier.
 *
 * @return The next unique member identifier.
 */
private Node nextNode(Node.Type type) {
    Endpoint endpoint = Endpoint.from("localhost", ++port);
    Node node = Node.builder(NodeId.from(String.valueOf(++nextId))).withType(type).withEndpoint(endpoint).build();
    endpointMap.put(node.id(), endpoint);
    return node;
}
Also used : Endpoint(io.atomix.messaging.Endpoint) Node(io.atomix.cluster.Node)

Example 7 with Node

use of io.atomix.cluster.Node in project atomix by atomix.

the class AbstractAtomixTest method createAtomix.

/**
 * Creates an Atomix instance.
 */
protected static Atomix createAtomix(Node.Type type, int id, Integer... ids) {
    Node localNode = Node.builder(String.valueOf(id)).withType(type).withEndpoint(Endpoint.from("localhost", BASE_PORT + id)).build();
    Collection<Node> bootstrapNodes = Stream.of(ids).map(nodeId -> Node.builder(String.valueOf(nodeId)).withType(Node.Type.CORE).withEndpoint(Endpoint.from("localhost", BASE_PORT + nodeId)).build()).collect(Collectors.toList());
    return new TestAtomix.Builder().withClusterName("test").withDataDirectory(new File("target/test-logs/" + id)).withLocalNode(localNode).withBootstrapNodes(bootstrapNodes).withCorePartitions(3).withDataPartitions(// Lower number of partitions for faster testing
    3).build();
}
Also used : ManagedClusterMetadataService(io.atomix.cluster.ManagedClusterMetadataService) Node(io.atomix.cluster.Node) DefaultPartitionService(io.atomix.primitive.partition.impl.DefaultPartitionService) BeforeClass(org.junit.BeforeClass) RaftProtocol(io.atomix.protocols.raft.RaftProtocol) PrimitiveTypeRegistry(io.atomix.primitive.PrimitiveTypeRegistry) ManagedPartitionService(io.atomix.primitive.partition.ManagedPartitionService) ManagedClusterService(io.atomix.cluster.ManagedClusterService) StorageLevel(io.atomix.storage.StorageLevel) ManagedPartitionGroup(io.atomix.primitive.partition.ManagedPartitionGroup) Path(java.nio.file.Path) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) PrimaryBackupPartitionGroup(io.atomix.protocols.backup.partition.PrimaryBackupPartitionGroup) ManagedMessagingService(io.atomix.messaging.ManagedMessagingService) AfterClass(org.junit.AfterClass) Files(java.nio.file.Files) Collection(java.util.Collection) Endpoint(io.atomix.messaging.Endpoint) IOException(java.io.IOException) ManagedClusterEventingService(io.atomix.cluster.messaging.ManagedClusterEventingService) RaftPartitionGroup(io.atomix.protocols.raft.partition.RaftPartitionGroup) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) File(java.io.File) FileVisitResult(java.nio.file.FileVisitResult) ManagedClusterMessagingService(io.atomix.cluster.messaging.ManagedClusterMessagingService) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Node(io.atomix.cluster.Node) File(java.io.File)

Example 8 with Node

use of io.atomix.cluster.Node in project atomix by atomix.

the class DefaultClusterEventingService method gossip.

/**
 * Sends a gossip message to an active peer.
 */
private void gossip() {
    List<Node> nodes = clusterService.getNodes().stream().filter(node -> !localNodeId.equals(node.id())).filter(node -> node.getState() == Node.State.ACTIVE).collect(Collectors.toList());
    if (!nodes.isEmpty()) {
        Collections.shuffle(nodes);
        Node node = nodes.get(0);
        updateNode(node);
    }
}
Also used : Node(io.atomix.cluster.Node) NodeId(io.atomix.cluster.NodeId) Arrays(java.util.Arrays) ClusterEventingService(io.atomix.cluster.messaging.ClusterEventingService) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Threads.namedThreads(io.atomix.utils.concurrent.Threads.namedThreads) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KryoNamespace(io.atomix.utils.serializer.KryoNamespace) Futures(io.atomix.utils.concurrent.Futures) MessagingException(io.atomix.messaging.MessagingException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) Endpoint(io.atomix.messaging.Endpoint) ManagedClusterEventingService(io.atomix.cluster.messaging.ManagedClusterEventingService) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Subscription(io.atomix.cluster.messaging.Subscription) Stream(java.util.stream.Stream) MessagingService(io.atomix.messaging.MessagingService) KryoNamespaces(io.atomix.utils.serializer.KryoNamespaces) LogicalTimestamp(io.atomix.utils.time.LogicalTimestamp) WallClockTimestamp(io.atomix.utils.time.WallClockTimestamp) ClusterService(io.atomix.cluster.ClusterService) Serializer(io.atomix.utils.serializer.Serializer) Collections(java.util.Collections) Node(io.atomix.cluster.Node)

Example 9 with Node

use of io.atomix.cluster.Node in project atomix by atomix.

the class DefaultClusterMetadataServiceTest method testSingleNodeBootstrap.

@Test
public void testSingleNodeBootstrap() throws Exception {
    TestMessagingServiceFactory messagingServiceFactory = new TestMessagingServiceFactory();
    ClusterMetadata clusterMetadata = buildClusterMetadata(1);
    Node localNode1 = buildNode(1, Node.Type.CORE);
    ManagedClusterMetadataService metadataService1 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode1.endpoint()).start().join());
    metadataService1.start().join();
    assertEquals(1, metadataService1.getMetadata().bootstrapNodes().size());
    Node localNode2 = buildNode(2, Node.Type.CORE);
    ManagedClusterMetadataService metadataService2 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode2.endpoint()).start().join());
    metadataService2.start().join();
    metadataService2.addNode(localNode2);
    assertEquals(2, metadataService2.getMetadata().bootstrapNodes().size());
}
Also used : ClusterMetadata(io.atomix.cluster.ClusterMetadata) ManagedClusterMetadataService(io.atomix.cluster.ManagedClusterMetadataService) Node(io.atomix.cluster.Node) TestMessagingServiceFactory(io.atomix.cluster.messaging.impl.TestMessagingServiceFactory) Test(org.junit.Test)

Example 10 with Node

use of io.atomix.cluster.Node in project atomix by atomix.

the class DefaultClusterMetadataServiceTest method testClusterMetadataService.

@Test
public void testClusterMetadataService() throws Exception {
    TestMessagingServiceFactory messagingServiceFactory = new TestMessagingServiceFactory();
    ClusterMetadata clusterMetadata = buildClusterMetadata(1, 2, 3);
    Node localNode1 = buildNode(1, Node.Type.CORE);
    ManagedClusterMetadataService metadataService1 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode1.endpoint()).start().join());
    Node localNode2 = buildNode(2, Node.Type.CORE);
    ManagedClusterMetadataService metadataService2 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode2.endpoint()).start().join());
    Node localNode3 = buildNode(3, Node.Type.CORE);
    ManagedClusterMetadataService metadataService3 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode3.endpoint()).start().join());
    List<CompletableFuture<ClusterMetadataService>> futures = new ArrayList<>();
    futures.add(metadataService1.start());
    futures.add(metadataService2.start());
    futures.add(metadataService3.start());
    Futures.allOf(futures).join();
    assertEquals(3, metadataService1.getMetadata().bootstrapNodes().size());
    assertEquals(3, metadataService2.getMetadata().bootstrapNodes().size());
    assertEquals(3, metadataService3.getMetadata().bootstrapNodes().size());
    Node localNode4 = buildNode(4, Node.Type.CORE);
    ManagedClusterMetadataService metadataService4 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode4.endpoint()).start().join());
    metadataService4.start().join();
    assertEquals(3, metadataService4.getMetadata().bootstrapNodes().size());
    TestClusterMetadataEventListener localEventListener = new TestClusterMetadataEventListener();
    metadataService4.addListener(localEventListener);
    TestClusterMetadataEventListener remoteEventListener1 = new TestClusterMetadataEventListener();
    metadataService1.addListener(remoteEventListener1);
    TestClusterMetadataEventListener remoteEventListener2 = new TestClusterMetadataEventListener();
    metadataService2.addListener(remoteEventListener2);
    TestClusterMetadataEventListener remoteEventListener3 = new TestClusterMetadataEventListener();
    metadataService3.addListener(remoteEventListener3);
    metadataService4.addNode(localNode4);
    assertEquals(4, metadataService4.getMetadata().bootstrapNodes().size());
    assertEquals(4, localEventListener.event().subject().bootstrapNodes().size());
    assertEquals(4, remoteEventListener1.event().subject().bootstrapNodes().size());
    assertEquals(4, metadataService1.getMetadata().bootstrapNodes().size());
    assertEquals(4, remoteEventListener2.event().subject().bootstrapNodes().size());
    assertEquals(4, metadataService2.getMetadata().bootstrapNodes().size());
    assertEquals(4, remoteEventListener3.event().subject().bootstrapNodes().size());
    assertEquals(4, metadataService3.getMetadata().bootstrapNodes().size());
    Node localNode5 = buildNode(5, Node.Type.CORE);
    ManagedClusterMetadataService metadataService5 = new DefaultClusterMetadataService(clusterMetadata, messagingServiceFactory.newMessagingService(localNode5.endpoint()).start().join());
    metadataService5.start().join();
    assertEquals(4, metadataService5.getMetadata().bootstrapNodes().size());
}
Also used : ClusterMetadata(io.atomix.cluster.ClusterMetadata) ManagedClusterMetadataService(io.atomix.cluster.ManagedClusterMetadataService) CompletableFuture(java.util.concurrent.CompletableFuture) Node(io.atomix.cluster.Node) ArrayList(java.util.ArrayList) TestMessagingServiceFactory(io.atomix.cluster.messaging.impl.TestMessagingServiceFactory) Test(org.junit.Test)

Aggregations

Node (io.atomix.cluster.Node)13 Endpoint (io.atomix.messaging.Endpoint)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 ClusterMetadata (io.atomix.cluster.ClusterMetadata)5 MessagingService (io.atomix.messaging.MessagingService)5 Collectors (java.util.stream.Collectors)5 Maps (com.google.common.collect.Maps)4 ClusterService (io.atomix.cluster.ClusterService)4 ManagedClusterMetadataService (io.atomix.cluster.ManagedClusterMetadataService)4 NodeId (io.atomix.cluster.NodeId)4 Collection (java.util.Collection)4 Map (java.util.Map)4 Set (java.util.Set)4 Logger (org.slf4j.Logger)4 Sets (com.google.common.collect.Sets)3 TestMessagingServiceFactory (io.atomix.cluster.messaging.impl.TestMessagingServiceFactory)3 KryoNamespaces (io.atomix.utils.serializer.KryoNamespaces)3 Serializer (io.atomix.utils.serializer.Serializer)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3