Skip to content

Commit

Permalink
Simplify cluster configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Apr 9, 2018
1 parent c96b476 commit 14fe3df
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 255 deletions.
21 changes: 10 additions & 11 deletions agent/src/test/resources/atomix.yaml
Expand Up @@ -2,17 +2,16 @@ data-directory: target/test-logs/
# Cluster configuration # Cluster configuration
cluster: cluster:
name: test name: test
core: nodes:
nodes: - id: node1
- id: node1 type: core
type: core address: localhost:5000
address: localhost:5000 - id: node2
- id: node2 type: core
type: core address: localhost:5001
address: localhost:5001 - id: node3
- id: node3 type: core
type: core address: localhost:5002
address: localhost:5002
# A list of partition groups # A list of partition groups
partition-groups: partition-groups:
- type: raft - type: raft
Expand Down
100 changes: 0 additions & 100 deletions cluster/src/main/java/io/atomix/cluster/BootstrapConfig.java

This file was deleted.

72 changes: 54 additions & 18 deletions cluster/src/main/java/io/atomix/cluster/ClusterConfig.java
Expand Up @@ -16,17 +16,33 @@
package io.atomix.cluster; package io.atomix.cluster;


import io.atomix.utils.Config; import io.atomix.utils.Config;
import io.atomix.utils.net.Address;
import io.atomix.utils.net.MalformedAddressException;

import java.util.ArrayList;
import java.util.Collection;


/** /**
* Cluster configuration. * Cluster configuration.
*/ */
public class ClusterConfig implements Config { public class ClusterConfig implements Config {
private static final String DEFAULT_CLUSTER_NAME = "atomix"; private static final String DEFAULT_CLUSTER_NAME = "atomix";
private static final String DEFAULT_MULTICAST_IP = "230.0.0.1";
private static final int DEFAULT_MULTICAST_PORT = 54321;


private String name = DEFAULT_CLUSTER_NAME; private String name = DEFAULT_CLUSTER_NAME;
private NodeConfig localNode; private NodeConfig localNode;
private CoreConfig core = new CoreConfig(); private Collection<NodeConfig> nodes = new ArrayList<>();
private BootstrapConfig bootstrap = new BootstrapConfig(); private boolean multicastEnabled = false;
private Address multicastAddress;

public ClusterConfig() {
try {
multicastAddress = Address.from(DEFAULT_MULTICAST_IP, DEFAULT_MULTICAST_PORT);
} catch (MalformedAddressException e) {
multicastAddress = Address.from(DEFAULT_MULTICAST_PORT);
}
}


/** /**
* Returns the cluster name. * Returns the cluster name.
Expand Down Expand Up @@ -69,42 +85,62 @@ public ClusterConfig setLocalNode(NodeConfig localNode) {
} }


/** /**
* Returns the core configuration. * Returns the cluster nodes.
*
* @return the cluster nodes
*/
public Collection<NodeConfig> getNodes() {
return nodes;
}

/**
* Sets the cluster nodes.
*
* @param nodes the cluster nodes
* @return the cluster configuration
*/
public ClusterConfig setNodes(Collection<NodeConfig> nodes) {
this.nodes = nodes;
return this;
}

/**
* Returns whether multicast is enabled.
* *
* @return the core configuration. * @return whether multicast is enabled
*/ */
public CoreConfig getCoreConfig() { public boolean isMulticastEnabled() {
return core; return multicastEnabled;
} }


/** /**
* Sets the core configuration. * Sets whether multicast is enabled.
* *
* @param core the core configuration * @param multicastEnabled whether multicast is enabled
* @return the cluster configuration * @return the cluster configuration
*/ */
public ClusterConfig setCoreConfig(CoreConfig core) { public ClusterConfig setMulticastEnabled(boolean multicastEnabled) {
this.core = core; this.multicastEnabled = multicastEnabled;
return this; return this;
} }


/** /**
* Returns the bootstrap configuration. * Returns the multicast address.
* *
* @return the bootstrap configuration. * @return the multicast address
*/ */
public BootstrapConfig getBootstrapConfig() { public Address getMulticastAddress() {
return bootstrap; return multicastAddress;
} }


/** /**
* Sets the bootstrap configuration. * Sets the multicast address.
* *
* @param bootstrap the bootstrap configuration * @param multicastAddress the multicast address
* @return the cluster configuration * @return the cluster configuration
*/ */
public ClusterConfig setBootstrapConfig(BootstrapConfig bootstrap) { public ClusterConfig setMulticastAddress(Address multicastAddress) {
this.bootstrap = bootstrap; this.multicastAddress = multicastAddress;
return this; return this;
} }
} }
48 changes: 0 additions & 48 deletions cluster/src/main/java/io/atomix/cluster/CoreConfig.java

This file was deleted.

Expand Up @@ -15,16 +15,13 @@
*/ */
package io.atomix.cluster.impl; package io.atomix.cluster.impl;


import io.atomix.cluster.BootstrapConfig;
import io.atomix.cluster.ClusterMetadata; import io.atomix.cluster.ClusterMetadata;
import io.atomix.cluster.ClusterMetadataEventListener; import io.atomix.cluster.ClusterMetadataEventListener;
import io.atomix.cluster.ClusterMetadataService; import io.atomix.cluster.ClusterMetadataService;
import io.atomix.cluster.ManagedBootstrapMetadataService; import io.atomix.cluster.ManagedBootstrapMetadataService;
import io.atomix.cluster.Node;


import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;


import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.MoreObjects.toStringHelper;


Expand All @@ -35,10 +32,6 @@ public class DefaultBootstrapMetadataService implements ManagedBootstrapMetadata
private final ClusterMetadata metadata; private final ClusterMetadata metadata;
private final AtomicBoolean started = new AtomicBoolean(); private final AtomicBoolean started = new AtomicBoolean();


public DefaultBootstrapMetadataService(BootstrapConfig config) {
this(new ClusterMetadata(config.getNodes().stream().map(Node::new).collect(Collectors.toList())));
}

public DefaultBootstrapMetadataService(ClusterMetadata metadata) { public DefaultBootstrapMetadataService(ClusterMetadata metadata) {
this.metadata = metadata; this.metadata = metadata;
} }
Expand Down
Expand Up @@ -25,7 +25,6 @@
import io.atomix.cluster.ClusterMetadataEvent; import io.atomix.cluster.ClusterMetadataEvent;
import io.atomix.cluster.ClusterMetadataEventListener; import io.atomix.cluster.ClusterMetadataEventListener;
import io.atomix.cluster.ClusterMetadataService; import io.atomix.cluster.ClusterMetadataService;
import io.atomix.cluster.CoreConfig;
import io.atomix.cluster.ManagedCoreMetadataService; import io.atomix.cluster.ManagedCoreMetadataService;
import io.atomix.cluster.Node; import io.atomix.cluster.Node;
import io.atomix.cluster.NodeId; import io.atomix.cluster.NodeId;
Expand Down Expand Up @@ -97,10 +96,6 @@ public class DefaultCoreMetadataService
namedThreads("atomix-cluster-metadata-receiver", log)); namedThreads("atomix-cluster-metadata-receiver", log));
private ScheduledFuture<?> metadataFuture; private ScheduledFuture<?> metadataFuture;


public DefaultCoreMetadataService(CoreConfig config, MessagingService messagingService) {
this(ClusterMetadata.builder().withNodes(config.getNodes().stream().map(Node::new).collect(Collectors.toList())).build(), messagingService);
}

public DefaultCoreMetadataService(ClusterMetadata metadata, MessagingService messagingService) { public DefaultCoreMetadataService(ClusterMetadata metadata, MessagingService messagingService) {
metadata.nodes().forEach(node -> nodes.put(node.id(), new ReplicatedNode( metadata.nodes().forEach(node -> nodes.put(node.id(), new ReplicatedNode(
node.id(), node.id(),
Expand Down
1 change: 1 addition & 0 deletions config/src/test/resources/config.json
Expand Up @@ -7,6 +7,7 @@
], ],
"primitives": { "primitives": {
"foo": { "foo": {
"type": "consistent-map",
"serializer": { "serializer": {
"types": [ "types": [
{ {
Expand Down
1 change: 1 addition & 0 deletions config/src/test/resources/config.yaml
Expand Up @@ -4,6 +4,7 @@ primitive-types:
- io.atomix.core.map.ConsistentMapType - io.atomix.core.map.ConsistentMapType
primitives: primitives:
foo: foo:
type: consistent-map
serializer: serializer:
types: types:
- type: io.atomix.cluster.NodeId - type: io.atomix.cluster.NodeId
Binary file added core/data/partitions/1/core-partition-1-1.log
Binary file not shown.
Binary file added core/data/partitions/1/core-partition-1.conf
Binary file not shown.
Binary file added core/data/partitions/1/core-partition-1.meta
Binary file not shown.
Binary file added core/data/partitions/2/core-partition-2-1.log
Binary file not shown.
Binary file added core/data/partitions/2/core-partition-2.conf
Binary file not shown.
Binary file added core/data/partitions/2/core-partition-2.meta
Binary file not shown.
Binary file added core/data/partitions/3/core-partition-3-1.log
Binary file not shown.
Binary file added core/data/partitions/3/core-partition-3.conf
Binary file not shown.
Binary file added core/data/partitions/3/core-partition-3.meta
Binary file not shown.

0 comments on commit 14fe3df

Please sign in to comment.