From 74c00ef32563876a90f0b25cd117bc45207652f5 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Thu, 2 Jan 2020 12:17:36 +0200 Subject: [PATCH 1/3] Deprecated memberHost/Port; added instead mappedHost/Port --- .../io/scalecube/cluster/ClusterConfig.java | 93 ++++++++++++++++--- .../io/scalecube/cluster/ClusterImpl.java | 4 +- .../io/scalecube/cluster/ClusterTest.java | 2 +- .../membership/MembershipProtocolTest.java | 11 +-- 4 files changed, 90 insertions(+), 20 deletions(-) diff --git a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java index 7926c543..533e8f9d 100644 --- a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java +++ b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java @@ -36,8 +36,8 @@ public final class ClusterConfig implements Cloneable { private MetadataDecoder metadataDecoder = MetadataDecoder.INSTANCE; private String memberAlias; - private String memberHost; - private Integer memberPort; + private String mappedHost; + private Integer mappedPort; private TransportConfig transportConfig = TransportConfig.defaultConfig(); private FailureDetectorConfig failureDetectorConfig = FailureDetectorConfig.defaultConfig(); @@ -152,28 +152,67 @@ public ClusterConfig metadataDecoder(MetadataDecoder metadataDecoder) { return c; } + /** + * Deprecated since {@code 2.4.10} in favor of {@link #mappedHost()}. + * + * @return member host + */ + @Deprecated public String memberHost() { - return memberHost; + return mappedHost; } /** - * Sets a memberHost. + * Returns mappedHost. {@code mappedHost} is a config property for container environments, it's + * being set for advertising to scalecube cluster some connectable hostname which maps to + * scalecube transport's hostname on which scalecube transport is listening. + * + * @return mapped host + */ + public String mappedHost() { + return mappedHost; + } + + /** + * Deprecated since {@code 2.4.10} in favor of {@link #mappedHost(String)}. * * @param memberHost member host * @return new {@code ClusterConfig} instance */ + @Deprecated public ClusterConfig memberHost(String memberHost) { ClusterConfig c = clone(); - c.memberHost = memberHost; + c.mappedHost = memberHost; + return c; + } + + /** + * Setter for mappedHost. {@code mappedHost} is a config property for container environments, it's + * being set for advertising to scalecube cluster some connectable hostname which maps to + * scalecube transport's hostname on which scalecube transport is listening. + * + * @param mappedHost mapped host + * @return new {@code ClusterConfig} instance + */ + public ClusterConfig mappedHost(String mappedHost) { + ClusterConfig c = clone(); + c.mappedHost = mappedHost; return c; } + /** + * Returns memberAlias. {@code memberAlias} is a config property which facilitates {@link + * io.scalecube.cluster.Member#toString()}. + * + * @return member alias. + */ public String memberAlias() { return memberAlias; } /** - * Sets a memberAlias. + * Setter for memberAlias. {@code memberAlias} is a config property which facilitates {@link + * io.scalecube.cluster.Member#toString()}. * * @param memberAlias member alias * @return new {@code ClusterConfig} instance @@ -184,19 +223,51 @@ public ClusterConfig memberAlias(String memberAlias) { return c; } + /** + * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort()}. + * + * @return member port + */ + @Deprecated public Integer memberPort() { - return memberPort; + return mappedPort; + } + + /** + * Returns mappedPort. {@code mappedPort} is a config property for container environments, it's + * being set for advertising to scalecube cluster a port which mapped to scalecube transport's + * listening port. + * + * @return mapped port + */ + public Integer mappedPort() { + return mappedPort; } /** - * Sets a memberPort. + * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort(Integer)}. * * @param memberPort member port * @return new {@code ClusterConfig} instance */ + @Deprecated public ClusterConfig memberPort(Integer memberPort) { ClusterConfig c = clone(); - c.memberPort = memberPort; + c.mappedPort = memberPort; + return c; + } + + /** + * Setter for mappedPort. {@code mappedPort} is a config property for container environments, it's + * being set for advertising to scalecube cluster a port which mapped to scalecube transport's + * listening port. + * + * @param mappedPort mapped port + * @return new {@code ClusterConfig} instance + */ + public ClusterConfig mappedPort(Integer mappedPort) { + ClusterConfig c = clone(); + c.mappedPort = mappedPort; return c; } @@ -286,8 +357,8 @@ public String toString() { .add("metadataEncoder=" + metadataEncoder) .add("metadataDecoder=" + metadataDecoder) .add("memberAlias='" + memberAlias + "'") - .add("memberHost='" + memberHost + "'") - .add("memberPort=" + memberPort) + .add("mappedHost='" + mappedHost + "'") + .add("mappedPort=" + mappedPort) .add("transportConfig=" + transportConfig) .add("failureDetectorConfig=" + failureDetectorConfig) .add("gossipConfig=" + gossipConfig) diff --git a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java index 85916193..fbec7c9f 100644 --- a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java @@ -354,11 +354,11 @@ private Flux listenMembership() { * @return local cluster member with cluster address and cluster member id */ private Member createLocalMember(Address address) { - int port = Optional.ofNullable(config.memberPort()).orElse(address.port()); + int port = Optional.ofNullable(config.mappedPort()).orElse(address.port()); // calculate local member cluster address Address memberAddress = - Optional.ofNullable(config.memberHost()) + Optional.ofNullable(config.mappedHost()) .map(host -> Address.create(host, port)) .orElseGet(() -> Address.create(address.host(), port)); diff --git a/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java b/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java index 3c880189..8218cd4b 100644 --- a/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java +++ b/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java @@ -138,7 +138,7 @@ public void testJoinLocalhostIgnoredWithOverride() throws InterruptedException { // Start seed node Cluster seedNode = - new ClusterImpl(new ClusterConfig().memberHost("localhost").memberPort(7878)) + new ClusterImpl(new ClusterConfig().mappedHost("localhost").mappedPort(7878)) .transport(opts -> opts.port(7878).connectTimeout(CONNECT_TIMEOUT)) .membership(opts -> opts.seedMembers(addresses)) .startAwait(); diff --git a/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java b/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java index 6372e7b4..981fe921 100644 --- a/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java +++ b/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java @@ -177,7 +177,6 @@ public void testLeaveClusterOnly() { assertTrue(cmAEvents.isEmpty()); } - @Test public void testLeaveClusterOnSuspectedNode() { final NetworkEmulatorTransport a = createTransport(); @@ -752,19 +751,19 @@ public void testOverrideMemberAddress() throws UnknownHostException { NetworkEmulatorTransport e = createTransport(); MembershipProtocolImpl cmA = - createMembership(a, testConfig(Collections.emptyList()).memberHost(localAddress)); + createMembership(a, testConfig(Collections.emptyList()).mappedHost(localAddress)); MembershipProtocolImpl cmB = createMembership( - b, testConfig(Collections.singletonList(a.address())).memberHost(localAddress)); + b, testConfig(Collections.singletonList(a.address())).mappedHost(localAddress)); MembershipProtocolImpl cmC = createMembership( - c, testConfig(Collections.singletonList(a.address())).memberHost(localAddress)); + c, testConfig(Collections.singletonList(a.address())).mappedHost(localAddress)); MembershipProtocolImpl cmD = createMembership( - d, testConfig(Collections.singletonList(b.address())).memberHost(localAddress)); + d, testConfig(Collections.singletonList(b.address())).mappedHost(localAddress)); MembershipProtocolImpl cmE = createMembership( - e, testConfig(Collections.singletonList(b.address())).memberHost(localAddress)); + e, testConfig(Collections.singletonList(b.address())).mappedHost(localAddress)); try { awaitSeconds(3); From 9e1e324deccc451495cc523232affa8ccc4d33b6 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Thu, 2 Jan 2020 12:34:37 +0200 Subject: [PATCH 2/3] Deprecated memberHost/Port; added instead mappedHost/Port --- .../io/scalecube/cluster/ClusterConfig.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java index 533e8f9d..cfc547a6 100644 --- a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java +++ b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java @@ -162,17 +162,6 @@ public String memberHost() { return mappedHost; } - /** - * Returns mappedHost. {@code mappedHost} is a config property for container environments, it's - * being set for advertising to scalecube cluster some connectable hostname which maps to - * scalecube transport's hostname on which scalecube transport is listening. - * - * @return mapped host - */ - public String mappedHost() { - return mappedHost; - } - /** * Deprecated since {@code 2.4.10} in favor of {@link #mappedHost(String)}. * @@ -186,6 +175,17 @@ public ClusterConfig memberHost(String memberHost) { return c; } + /** + * Returns mappedHost. {@code mappedHost} is a config property for container environments, it's + * being set for advertising to scalecube cluster some connectable hostname which maps to + * scalecube transport's hostname on which scalecube transport is listening. + * + * @return mapped host + */ + public String mappedHost() { + return mappedHost; + } + /** * Setter for mappedHost. {@code mappedHost} is a config property for container environments, it's * being set for advertising to scalecube cluster some connectable hostname which maps to @@ -223,16 +223,6 @@ public ClusterConfig memberAlias(String memberAlias) { return c; } - /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort()}. - * - * @return member port - */ - @Deprecated - public Integer memberPort() { - return mappedPort; - } - /** * Returns mappedPort. {@code mappedPort} is a config property for container environments, it's * being set for advertising to scalecube cluster a port which mapped to scalecube transport's @@ -245,29 +235,39 @@ public Integer mappedPort() { } /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort(Integer)}. + * Setter for mappedPort. {@code mappedPort} is a config property for container environments, it's + * being set for advertising to scalecube cluster a port which mapped to scalecube transport's + * listening port. * - * @param memberPort member port + * @param mappedPort mapped port * @return new {@code ClusterConfig} instance */ - @Deprecated - public ClusterConfig memberPort(Integer memberPort) { + public ClusterConfig mappedPort(Integer mappedPort) { ClusterConfig c = clone(); - c.mappedPort = memberPort; + c.mappedPort = mappedPort; return c; } /** - * Setter for mappedPort. {@code mappedPort} is a config property for container environments, it's - * being set for advertising to scalecube cluster a port which mapped to scalecube transport's - * listening port. + * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort()}. * - * @param mappedPort mapped port + * @return member port + */ + @Deprecated + public Integer memberPort() { + return mappedPort; + } + + /** + * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort(Integer)}. + * + * @param memberPort member port * @return new {@code ClusterConfig} instance */ - public ClusterConfig mappedPort(Integer mappedPort) { + @Deprecated + public ClusterConfig memberPort(Integer memberPort) { ClusterConfig c = clone(); - c.mappedPort = mappedPort; + c.mappedPort = memberPort; return c; } From 4bd74b1cfeefc2aa66978308fe99b15cc919cafc Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Thu, 2 Jan 2020 16:05:16 +0200 Subject: [PATCH 3/3] Renamed on containerHost/Port --- .../io/scalecube/cluster/ClusterConfig.java | 40 +++++++++---------- .../io/scalecube/cluster/ClusterImpl.java | 4 +- .../io/scalecube/cluster/ClusterTest.java | 2 +- .../membership/MembershipProtocolTest.java | 10 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java index cfc547a6..564f6112 100644 --- a/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java +++ b/cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java @@ -36,8 +36,8 @@ public final class ClusterConfig implements Cloneable { private MetadataDecoder metadataDecoder = MetadataDecoder.INSTANCE; private String memberAlias; - private String mappedHost; - private Integer mappedPort; + private String containerHost; + private Integer containerPort; private TransportConfig transportConfig = TransportConfig.defaultConfig(); private FailureDetectorConfig failureDetectorConfig = FailureDetectorConfig.defaultConfig(); @@ -153,17 +153,17 @@ public ClusterConfig metadataDecoder(MetadataDecoder metadataDecoder) { } /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedHost()}. + * Deprecated since {@code 2.4.10} in favor of {@link #containerHost()}. * * @return member host */ @Deprecated public String memberHost() { - return mappedHost; + return containerHost; } /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedHost(String)}. + * Deprecated since {@code 2.4.10} in favor of {@link #containerHost(String)}. * * @param memberHost member host * @return new {@code ClusterConfig} instance @@ -171,7 +171,7 @@ public String memberHost() { @Deprecated public ClusterConfig memberHost(String memberHost) { ClusterConfig c = clone(); - c.mappedHost = memberHost; + c.containerHost = memberHost; return c; } @@ -182,8 +182,8 @@ public ClusterConfig memberHost(String memberHost) { * * @return mapped host */ - public String mappedHost() { - return mappedHost; + public String containerHost() { + return containerHost; } /** @@ -194,9 +194,9 @@ public String mappedHost() { * @param mappedHost mapped host * @return new {@code ClusterConfig} instance */ - public ClusterConfig mappedHost(String mappedHost) { + public ClusterConfig containerHost(String mappedHost) { ClusterConfig c = clone(); - c.mappedHost = mappedHost; + c.containerHost = mappedHost; return c; } @@ -230,8 +230,8 @@ public ClusterConfig memberAlias(String memberAlias) { * * @return mapped port */ - public Integer mappedPort() { - return mappedPort; + public Integer containerPort() { + return containerPort; } /** @@ -242,24 +242,24 @@ public Integer mappedPort() { * @param mappedPort mapped port * @return new {@code ClusterConfig} instance */ - public ClusterConfig mappedPort(Integer mappedPort) { + public ClusterConfig containerPort(Integer mappedPort) { ClusterConfig c = clone(); - c.mappedPort = mappedPort; + c.containerPort = mappedPort; return c; } /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort()}. + * Deprecated since {@code 2.4.10} in favor of {@link #containerPort()}. * * @return member port */ @Deprecated public Integer memberPort() { - return mappedPort; + return containerPort; } /** - * Deprecated since {@code 2.4.10} in favor of {@link #mappedPort(Integer)}. + * Deprecated since {@code 2.4.10} in favor of {@link #containerPort(Integer)}. * * @param memberPort member port * @return new {@code ClusterConfig} instance @@ -267,7 +267,7 @@ public Integer memberPort() { @Deprecated public ClusterConfig memberPort(Integer memberPort) { ClusterConfig c = clone(); - c.mappedPort = memberPort; + c.containerPort = memberPort; return c; } @@ -357,8 +357,8 @@ public String toString() { .add("metadataEncoder=" + metadataEncoder) .add("metadataDecoder=" + metadataDecoder) .add("memberAlias='" + memberAlias + "'") - .add("mappedHost='" + mappedHost + "'") - .add("mappedPort=" + mappedPort) + .add("containerHost='" + containerHost + "'") + .add("containerPort=" + containerPort) .add("transportConfig=" + transportConfig) .add("failureDetectorConfig=" + failureDetectorConfig) .add("gossipConfig=" + gossipConfig) diff --git a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java index fbec7c9f..db96f09f 100644 --- a/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java @@ -354,11 +354,11 @@ private Flux listenMembership() { * @return local cluster member with cluster address and cluster member id */ private Member createLocalMember(Address address) { - int port = Optional.ofNullable(config.mappedPort()).orElse(address.port()); + int port = Optional.ofNullable(config.containerPort()).orElse(address.port()); // calculate local member cluster address Address memberAddress = - Optional.ofNullable(config.mappedHost()) + Optional.ofNullable(config.containerHost()) .map(host -> Address.create(host, port)) .orElseGet(() -> Address.create(address.host(), port)); diff --git a/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java b/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java index 8218cd4b..df8c50d1 100644 --- a/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java +++ b/cluster/src/test/java/io/scalecube/cluster/ClusterTest.java @@ -138,7 +138,7 @@ public void testJoinLocalhostIgnoredWithOverride() throws InterruptedException { // Start seed node Cluster seedNode = - new ClusterImpl(new ClusterConfig().mappedHost("localhost").mappedPort(7878)) + new ClusterImpl(new ClusterConfig().containerHost("localhost").containerPort(7878)) .transport(opts -> opts.port(7878).connectTimeout(CONNECT_TIMEOUT)) .membership(opts -> opts.seedMembers(addresses)) .startAwait(); diff --git a/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java b/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java index 981fe921..34e68106 100644 --- a/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java +++ b/cluster/src/test/java/io/scalecube/cluster/membership/MembershipProtocolTest.java @@ -751,19 +751,19 @@ public void testOverrideMemberAddress() throws UnknownHostException { NetworkEmulatorTransport e = createTransport(); MembershipProtocolImpl cmA = - createMembership(a, testConfig(Collections.emptyList()).mappedHost(localAddress)); + createMembership(a, testConfig(Collections.emptyList()).containerHost(localAddress)); MembershipProtocolImpl cmB = createMembership( - b, testConfig(Collections.singletonList(a.address())).mappedHost(localAddress)); + b, testConfig(Collections.singletonList(a.address())).containerHost(localAddress)); MembershipProtocolImpl cmC = createMembership( - c, testConfig(Collections.singletonList(a.address())).mappedHost(localAddress)); + c, testConfig(Collections.singletonList(a.address())).containerHost(localAddress)); MembershipProtocolImpl cmD = createMembership( - d, testConfig(Collections.singletonList(b.address())).mappedHost(localAddress)); + d, testConfig(Collections.singletonList(b.address())).containerHost(localAddress)); MembershipProtocolImpl cmE = createMembership( - e, testConfig(Collections.singletonList(b.address())).mappedHost(localAddress)); + e, testConfig(Collections.singletonList(b.address())).containerHost(localAddress)); try { awaitSeconds(3);