Skip to content

Commit c78ef9d

Browse files
committed
Logging of cluster discovery improper addresses
Add a warning message if some of the obtained cluster addresses are invalid and skipped from the processing. Follows on: #194
1 parent 4cbb457 commit c78ef9d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main/java/org/tarantool/cluster/TarantoolClusterStoredFunctionDiscoverer.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import org.tarantool.TarantoolClient;
44
import org.tarantool.TarantoolClientOps;
55
import org.tarantool.TarantoolClusterClientConfig;
6+
import org.tarantool.logging.Logger;
7+
import org.tarantool.logging.LoggerFactory;
68
import org.tarantool.util.StringUtils;
79

810
import java.util.LinkedHashSet;
911
import java.util.List;
1012
import java.util.Set;
11-
import java.util.stream.Collectors;
1213

1314
/**
1415
* A cluster nodes discoverer based on calling a predefined function
@@ -19,6 +20,8 @@
1920
*/
2021
public class TarantoolClusterStoredFunctionDiscoverer implements TarantoolClusterDiscoverer {
2122

23+
private static final Logger LOGGER = LoggerFactory.getLogger(TarantoolClusterStoredFunctionDiscoverer.class);
24+
2225
private TarantoolClient client;
2326
private String entryFunction;
2427

@@ -57,12 +60,24 @@ private Set<String> checkAndFilterAddresses(List<?> result) {
5760
throw new IllegalDiscoveryFunctionResult("The first value must be an array of strings");
5861
}
5962

60-
return ((List<Object>) result.get(0)).stream()
61-
.filter(item -> item instanceof String)
62-
.map(Object::toString)
63-
.filter(s -> !StringUtils.isBlank(s))
64-
.filter(this::isAddress)
65-
.collect(Collectors.toCollection(LinkedHashSet::new));
63+
LinkedHashSet<String> passed = new LinkedHashSet<>();
64+
LinkedHashSet<String> skipped = new LinkedHashSet<>();
65+
for (Object item : ((List<Object>) result.get(0))) {
66+
if (!(item instanceof String)) {
67+
skipped.add(item.toString());
68+
continue;
69+
}
70+
String s = item.toString();
71+
if (!StringUtils.isBlank(s) && isAddress(s)) {
72+
passed.add(s);
73+
} else {
74+
skipped.add(s);
75+
}
76+
}
77+
if (!skipped.isEmpty()) {
78+
LOGGER.warn("Some of the addresses were skipped because of unsupported format: {0}", skipped);
79+
}
80+
return passed;
6681
}
6782

6883
/**

0 commit comments

Comments
 (0)