Skip to content

Commit

Permalink
Change terminology for cluster membership: rename ClusterService to C…
Browse files Browse the repository at this point in the history
…lusterMembershipService and Node to Member.
  • Loading branch information
kuujo committed Apr 26, 2018
1 parent 71166d8 commit 7c179dc
Show file tree
Hide file tree
Showing 155 changed files with 1,848 additions and 1,849 deletions.
68 changes: 34 additions & 34 deletions agent/src/main/java/io/atomix/agent/AtomixAgent.java
Expand Up @@ -15,9 +15,9 @@
*/
package io.atomix.agent;

import io.atomix.cluster.Node;
import io.atomix.cluster.NodeConfig;
import io.atomix.cluster.NodeId;
import io.atomix.cluster.Member;
import io.atomix.cluster.MemberConfig;
import io.atomix.cluster.MemberId;
import io.atomix.core.Atomix;
import io.atomix.core.AtomixConfig;
import io.atomix.rest.ManagedRestService;
Expand Down Expand Up @@ -48,22 +48,22 @@ public class AtomixAgent {
private static final Logger LOGGER = LoggerFactory.getLogger(AtomixAgent.class);

public static void main(String[] args) throws Exception {
Function<Node.Type, ArgumentType<NodeConfig>> nodeArgumentType = (type) -> (ArgumentParser argumentParser, Argument argument, String value) -> {
return new NodeConfig()
Function<Member.Type, ArgumentType<MemberConfig>> nodeArgumentType = (type) -> (ArgumentParser argumentParser, Argument argument, String value) -> {
return new MemberConfig()
.setId(parseNodeId(value))
.setType(type)
.setAddress(parseAddress(value));
};

ArgumentType<Node.Type> typeArgumentType = (argumentParser, argument, value) -> Node.Type.valueOf(value.toUpperCase());
ArgumentType<Member.Type> typeArgumentType = (argumentParser, argument, value) -> Member.Type.valueOf(value.toUpperCase());
ArgumentType<Address> addressArgumentType = (argumentParser, argument, value) -> Address.from(value);
ArgumentType<File> fileArgumentType = (argumentParser, argument, value) -> new File(value);

ArgumentParser parser = ArgumentParsers.newArgumentParser("AtomixServer")
.defaultHelp(true)
.description("Atomix server");
parser.addArgument("node")
.type(nodeArgumentType.apply(Node.Type.PERSISTENT))
.type(nodeArgumentType.apply(Member.Type.PERSISTENT))
.nargs("?")
.metavar("NAME@HOST:PORT")
.required(false)
Expand All @@ -73,23 +73,23 @@ public static void main(String[] args) throws Exception {
parser.addArgument("--type", "-t")
.type(typeArgumentType)
.metavar("TYPE")
.choices(Node.Type.PERSISTENT, Node.Type.EPHEMERAL)
.setDefault(Node.Type.PERSISTENT)
.choices(Member.Type.PERSISTENT, Member.Type.EPHEMERAL)
.setDefault(Member.Type.PERSISTENT)
.help("Indicates the local node type.");
parser.addArgument("--config", "-c")
.metavar("FILE|JSON|YAML")
.required(false)
.help("The Atomix configuration. Can be specified as a file path or JSON/YAML string.");
parser.addArgument("--core-nodes", "-n")
.nargs("*")
.type(nodeArgumentType.apply(Node.Type.PERSISTENT))
.type(nodeArgumentType.apply(Member.Type.PERSISTENT))
.metavar("NAME@HOST:PORT")
.required(false)
.help("The set of core nodes, if any. When bootstrapping a new cluster, if the local node is a core node " +
"then it should be present in the core configuration as well.");
parser.addArgument("--bootstrap-nodes", "-b")
.nargs("*")
.type(nodeArgumentType.apply(Node.Type.EPHEMERAL))
.type(nodeArgumentType.apply(Member.Type.EPHEMERAL))
.metavar("NAME@HOST:PORT")
.required(false)
.help("The set of bootstrap nodes. If core nodes are provided, the cluster will be bootstrapped from the " +
Expand Down Expand Up @@ -119,10 +119,10 @@ public static void main(String[] args) throws Exception {
}

final String configString = namespace.get("config");
final NodeConfig localNode = namespace.get("node");
final Node.Type localNodeType = namespace.get("type");
final List<NodeConfig> coreNodes = namespace.getList("core_nodes");
final List<NodeConfig> bootstrapNodes = namespace.getList("bootstrap_nodes");
final MemberConfig localNode = namespace.get("node");
final Member.Type localNodeType = namespace.get("type");
final List<MemberConfig> coreNodes = namespace.getList("core_nodes");
final List<MemberConfig> bootstrapNodes = namespace.getList("bootstrap_nodes");
final boolean multicastEnabled = namespace.getBoolean("multicast");
final Address multicastAddress = namespace.get("multicast_address");
final Integer httpPort = namespace.getInt("http_port");
Expand All @@ -135,14 +135,14 @@ public static void main(String[] args) throws Exception {
config.getClusterConfig().getNodes().stream()
.filter(node -> node.getId().equals(localNode.getId()))
.findAny()
.ifPresent(localNodeConfig -> {
.ifPresent(localMemberConfig -> {
if (localNodeType == null) {
localNode.setType(localNodeConfig.getType());
localNode.setType(localMemberConfig.getType());
}
localNode.setAddress(localNodeConfig.getAddress());
localNode.setZone(localNodeConfig.getZone());
localNode.setRack(localNodeConfig.getRack());
localNode.setHost(localNodeConfig.getHost());
localNode.setAddress(localMemberConfig.getAddress());
localNode.setZone(localMemberConfig.getZone());
localNode.setRack(localMemberConfig.getRack());
localNode.setHost(localMemberConfig.getHost());
});
}
builder = Atomix.builder(config);
Expand All @@ -155,22 +155,22 @@ public static void main(String[] args) throws Exception {
// If a local node was provided, add the local node to the builder.
if (localNode != null) {
localNode.setType(localNodeType);
Node node = new Node(localNode);
builder.withLocalNode(node);
LOGGER.info("node: {}", node);
Member member = new Member(localNode);
builder.withLocalNode(member);
LOGGER.info("node: {}", member);
}

// If a cluster configuration was provided, add all the cluster nodes to the builder.
if (coreNodes != null || bootstrapNodes != null) {
List<Node> nodes = Stream.concat(
List<Member> members = Stream.concat(
coreNodes != null ? coreNodes.stream() : Stream.empty(),
bootstrapNodes != null ? bootstrapNodes.stream() : Stream.empty())
.map(node -> Node.builder(node.getId())
.map(node -> Member.builder(node.getId())
.withType(node.getType())
.withAddress(node.getAddress())
.build())
.collect(Collectors.toList());
builder.withNodes(nodes);
builder.withNodes(members);
}

// Enable multicast if provided.
Expand All @@ -185,16 +185,16 @@ public static void main(String[] args) throws Exception {

atomix.start().join();

LOGGER.info("Atomix listening at {}:{}", atomix.clusterService().getLocalNode().address().host(), atomix.clusterService().getLocalNode().address().port());
LOGGER.info("Atomix listening at {}:{}", atomix.membershipService().getLocalMember().address().host(), atomix.membershipService().getLocalMember().address().port());

ManagedRestService rest = RestService.builder()
.withAtomix(atomix)
.withAddress(Address.from(atomix.clusterService().getLocalNode().address().host(), httpPort))
.withAddress(Address.from(atomix.membershipService().getLocalMember().address().host(), httpPort))
.build();

rest.start().join();

LOGGER.info("HTTP server listening at {}:{}", atomix.clusterService().getLocalNode().address().address().getHostAddress(), httpPort);
LOGGER.info("HTTP server listening at {}:{}", atomix.membershipService().getLocalMember().address().address().getHostAddress(), httpPort);

synchronized (Atomix.class) {
while (atomix.isRunning()) {
Expand All @@ -215,15 +215,15 @@ private static AtomixConfig loadConfig(String config) {
}
}

static NodeId parseNodeId(String address) {
static MemberId parseNodeId(String address) {
int endIndex = address.indexOf('@');
if (endIndex > 0) {
return NodeId.from(address.substring(0, endIndex));
return MemberId.from(address.substring(0, endIndex));
} else {
try {
return NodeId.from(Address.from(address).host());
return MemberId.from(Address.from(address).host());
} catch (MalformedAddressException e) {
return NodeId.from(address);
return MemberId.from(address);
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions agent/src/test/java/io/atomix/agent/AtomixAgentTest.java
Expand Up @@ -16,8 +16,8 @@
package io.atomix.agent;

import com.google.common.base.Joiner;
import io.atomix.cluster.Node;
import io.atomix.cluster.NodeId;
import io.atomix.cluster.Member;
import io.atomix.cluster.MemberId;
import io.atomix.core.Atomix;
import io.atomix.core.map.ConsistentMap;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -48,11 +48,11 @@ public class AtomixAgentTest {

@Test
public void testParseNodeId() throws Exception {
assertEquals(NodeId.from("127.0.0.1"), AtomixAgent.parseNodeId("127.0.0.1"));
assertEquals(NodeId.from("foo"), AtomixAgent.parseNodeId("foo"));
assertEquals(NodeId.from("127.0.0.1"), AtomixAgent.parseNodeId("127.0.0.1:1234"));
assertEquals(NodeId.from("foo"), AtomixAgent.parseNodeId("foo@127.0.0.1:1234"));
assertEquals(NodeId.from("foo"), AtomixAgent.parseNodeId("foo@127.0.0.1"));
assertEquals(MemberId.from("127.0.0.1"), AtomixAgent.parseNodeId("127.0.0.1"));
assertEquals(MemberId.from("foo"), AtomixAgent.parseNodeId("foo"));
assertEquals(MemberId.from("127.0.0.1"), AtomixAgent.parseNodeId("127.0.0.1:1234"));
assertEquals(MemberId.from("foo"), AtomixAgent.parseNodeId("foo@127.0.0.1:1234"));
assertEquals(MemberId.from("foo"), AtomixAgent.parseNodeId("foo@127.0.0.1"));
}

@Test
Expand Down Expand Up @@ -113,16 +113,16 @@ private void testFormCluster(String path) throws Exception {
Thread.sleep(5000);

Atomix client1 = Atomix.builder(path)
.withLocalNode(Node.builder("client1")
.withType(Node.Type.EPHEMERAL)
.withLocalNode(Member.builder("client1")
.withType(Member.Type.EPHEMERAL)
.withAddress("localhost:5003")
.build())
.build();
client1.start().join();

Atomix client2 = Atomix.builder(path)
.withLocalNode(Node.builder("client2")
.withType(Node.Type.EPHEMERAL)
.withLocalNode(Member.builder("client2")
.withType(Member.Type.EPHEMERAL)
.withAddress("localhost:5004")
.build())
.build();
Expand Down Expand Up @@ -193,16 +193,16 @@ public void testFormDataCluster() throws Exception {
Thread.sleep(10000);

Atomix client1 = Atomix.builder(Joiner.on('\n').join(config))
.withLocalNode(Node.builder("client1")
.withType(Node.Type.EPHEMERAL)
.withLocalNode(Member.builder("client1")
.withType(Member.Type.EPHEMERAL)
.withAddress("localhost:5003")
.build())
.build();
client1.start().join();

Atomix client2 = Atomix.builder(Joiner.on('\n').join(config))
.withLocalNode(Node.builder("client2")
.withType(Node.Type.EPHEMERAL)
.withLocalNode(Member.builder("client2")
.withType(Member.Type.EPHEMERAL)
.withAddress("localhost:5004")
.build())
.build();
Expand Down

0 comments on commit 7c179dc

Please sign in to comment.