Skip to content

Commit c308eb3

Browse files
committed
Fix server ip resolution
1 parent 95e97ac commit c308eb3

1 file changed

Lines changed: 51 additions & 34 deletions

File tree

server/src/main/java/io/appulse/epmd/java/server/SubcommandServer.java

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
import picocli.CommandLine.Option;
8484
import picocli.CommandLine.ParentCommand;
8585

86+
/**
87+
* EPMD server command.
88+
*/
8689
@Slf4j
8790
@NoArgsConstructor
8891
@Command(
@@ -128,7 +131,9 @@ public class SubcommandServer implements Runnable {
128131
names = { "-u", "--unsafe-commands" },
129132
description = {
130133
"Start the epmd program with relaxed command checking. This affects the following:",
131-
"With relaxed command checking, the epmd daemon can be killed from the localhost with i.e. epmd -kill even if there are active nodes registered. Normally only daemons with an empty node database can be killed with the epmd \"kill\" command.",
134+
"With relaxed command checking, the epmd daemon can be killed from the localhost with i.e. " +
135+
"epmd -kill even if there are active nodes registered. Normally only daemons with an empty node " +
136+
"database can be killed with the epmd \"kill\" command.",
132137
"With relaxed command checking enabled, you can forcibly unregister live nodes by \"stop\" command."
133138
}
134139
)
@@ -155,37 +160,6 @@ public class SubcommandServer implements Runnable {
155160
.ifPresent(it -> this.ips = it);
156161
}
157162

158-
private void setupEnvironmentVariables () {
159-
if (new SubcommandServer().ips.equals(ips)) {
160-
ips = ofNullable(System.getProperty("ERL_EPMD_ADDRESS"))
161-
.map(it -> it.split(","))
162-
.map(it -> Stream.of(it)
163-
.map(String::trim)
164-
.filter(ip -> !ip.isEmpty())
165-
.map(ip -> {
166-
try {
167-
return InetAddress.getByName(ip);
168-
} catch (UnknownHostException ex) {
169-
throw new IllegalArgumentException("Invalid host " + ip, ex);
170-
}
171-
})
172-
.collect(toSet()))
173-
.map(it -> {
174-
it.add(LOOPBACK_ADDRESS);
175-
return it;
176-
})
177-
.orElse(ips);
178-
}
179-
ips.add(LOOPBACK_ADDRESS);
180-
181-
if (!unsafe) {
182-
val string = ofNullable(System.getProperty("ERL_EPMD_RELAXED_COMMAND_CHECK"))
183-
.filter(it -> !it.isEmpty())
184-
.orElse("true");
185-
unsafe = Boolean.valueOf(string);
186-
}
187-
}
188-
189163
@Override
190164
@SneakyThrows
191165
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@@ -243,19 +217,62 @@ public void run () {
243217
}
244218
}
245219

246-
private Collection<Node> getNodes () {
220+
/**
221+
* Gets all registered and alive nodes in the server.
222+
*
223+
* @return all alive nodes
224+
*/
225+
public Collection<Node> getNodes () {
247226
nodes.entrySet()
248227
.removeIf(entry -> !entry.getValue().isAlive());
249228

250229
return nodes.values();
251230
}
252231

253-
private Optional<Node> getNode (String name) {
232+
/**
233+
* Returns a registered node, only if it is alive.
234+
*
235+
* @param name the node's name
236+
*
237+
* @return the registered and alive node
238+
*/
239+
public Optional<Node> getNode (String name) {
254240
return ofNullable(name)
255241
.map(nodes::get)
256242
.filter(Node::isAlive);
257243
}
258244

245+
private void setupEnvironmentVariables () {
246+
if (new SubcommandServer().ips.equals(ips)) { // checks it is not set
247+
ips = ofNullable(System.getProperty("ERL_EPMD_ADDRESS"))
248+
.map(it -> it.split(","))
249+
.map(it -> Stream.of(it)
250+
.map(String::trim)
251+
.filter(ip -> !ip.isEmpty())
252+
.map(ip -> {
253+
try {
254+
return InetAddress.getByName(ip);
255+
} catch (UnknownHostException ex) {
256+
throw new IllegalArgumentException("Invalid host " + ip, ex);
257+
}
258+
})
259+
.collect(toSet()))
260+
.map(it -> {
261+
it.add(LOOPBACK_ADDRESS);
262+
return it;
263+
})
264+
.orElse(ips);
265+
}
266+
ips.add(LOOPBACK_ADDRESS);
267+
268+
if (!unsafe) {
269+
val string = ofNullable(System.getProperty("ERL_EPMD_RELAXED_COMMAND_CHECK"))
270+
.filter(it -> !it.isEmpty())
271+
.orElse("true");
272+
unsafe = Boolean.valueOf(string);
273+
}
274+
}
275+
259276
@Value
260277
private class ServerHandler implements Runnable {
261278

0 commit comments

Comments
 (0)