Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated memberHost/Port; added instead mappedHost/Port #286

Merged
merged 3 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 82 additions & 11 deletions cluster-api/src/main/java/io/scalecube/cluster/ClusterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 containerHost;
private Integer containerPort;

private TransportConfig transportConfig = TransportConfig.defaultConfig();
private FailureDetectorConfig failureDetectorConfig = FailureDetectorConfig.defaultConfig();
Expand Down Expand Up @@ -152,28 +152,67 @@ public ClusterConfig metadataDecoder(MetadataDecoder metadataDecoder) {
return c;
}

/**
* Deprecated since {@code 2.4.10} in favor of {@link #containerHost()}.
*
* @return member host
*/
@Deprecated
public String memberHost() {
return memberHost;
return containerHost;
}

/**
* Sets a memberHost.
* Deprecated since {@code 2.4.10} in favor of {@link #containerHost(String)}.
*
* @param memberHost member host
* @return new {@code ClusterConfig} instance
*/
@Deprecated
public ClusterConfig memberHost(String memberHost) {
ClusterConfig c = clone();
c.memberHost = memberHost;
c.containerHost = 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 containerHost() {
return containerHost;
}

/**
* 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 containerHost(String mappedHost) {
ClusterConfig c = clone();
c.containerHost = 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
Expand All @@ -184,19 +223,51 @@ public ClusterConfig memberAlias(String memberAlias) {
return c;
}

/**
* 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 containerPort() {
return containerPort;
}

/**
* 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 containerPort(Integer mappedPort) {
ClusterConfig c = clone();
c.containerPort = mappedPort;
return c;
}

/**
* Deprecated since {@code 2.4.10} in favor of {@link #containerPort()}.
*
* @return member port
*/
@Deprecated
public Integer memberPort() {
return memberPort;
return containerPort;
}

/**
* Sets a memberPort.
* Deprecated since {@code 2.4.10} in favor of {@link #containerPort(Integer)}.
*
* @param memberPort member port
* @return new {@code ClusterConfig} instance
*/
@Deprecated
public ClusterConfig memberPort(Integer memberPort) {
ClusterConfig c = clone();
c.memberPort = memberPort;
c.containerPort = memberPort;
return c;
}

Expand Down Expand Up @@ -286,8 +357,8 @@ public String toString() {
.add("metadataEncoder=" + metadataEncoder)
.add("metadataDecoder=" + metadataDecoder)
.add("memberAlias='" + memberAlias + "'")
.add("memberHost='" + memberHost + "'")
.add("memberPort=" + memberPort)
.add("containerHost='" + containerHost + "'")
.add("containerPort=" + containerPort)
.add("transportConfig=" + transportConfig)
.add("failureDetectorConfig=" + failureDetectorConfig)
.add("gossipConfig=" + gossipConfig)
Expand Down
4 changes: 2 additions & 2 deletions cluster/src/main/java/io/scalecube/cluster/ClusterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ private Flux<MembershipEvent> 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.containerPort()).orElse(address.port());

// calculate local member cluster address
Address memberAddress =
Optional.ofNullable(config.memberHost())
Optional.ofNullable(config.containerHost())
.map(host -> Address.create(host, port))
.orElseGet(() -> Address.create(address.host(), port));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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().containerHost("localhost").containerPort(7878))
.transport(opts -> opts.port(7878).connectTimeout(CONNECT_TIMEOUT))
.membership(opts -> opts.seedMembers(addresses))
.startAwait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public void testLeaveClusterOnly() {
assertTrue(cmAEvents.isEmpty());
}


@Test
public void testLeaveClusterOnSuspectedNode() {
final NetworkEmulatorTransport a = createTransport();
Expand Down Expand Up @@ -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()).containerHost(localAddress));
MembershipProtocolImpl cmB =
createMembership(
b, testConfig(Collections.singletonList(a.address())).memberHost(localAddress));
b, testConfig(Collections.singletonList(a.address())).containerHost(localAddress));
MembershipProtocolImpl cmC =
createMembership(
c, testConfig(Collections.singletonList(a.address())).memberHost(localAddress));
c, testConfig(Collections.singletonList(a.address())).containerHost(localAddress));
MembershipProtocolImpl cmD =
createMembership(
d, testConfig(Collections.singletonList(b.address())).memberHost(localAddress));
d, testConfig(Collections.singletonList(b.address())).containerHost(localAddress));
MembershipProtocolImpl cmE =
createMembership(
e, testConfig(Collections.singletonList(b.address())).memberHost(localAddress));
e, testConfig(Collections.singletonList(b.address())).containerHost(localAddress));

try {
awaitSeconds(3);
Expand Down