Skip to content

Commit e96fbd7

Browse files
committed
code cleanup
1 parent 563edb1 commit e96fbd7

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

src/main/java/tech/stackable/hadoop/StackableTopologyProvider.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* An implementation of the org.apache.hadoop.net.DNSToSwitchMapping that is used to create a
1717
* topology out of dataNodes.
1818
*
19-
* <p>This class is intended to be run as part of the NameNode process and will be used by the
20-
* nameNode to retrieve topology strings for dataNodes.
19+
* <p>This class is intended to be run as part of the NameNode process (in the same namespace) and
20+
* will be used by the nameNode to retrieve topology strings for dataNodes.
2121
*/
2222
public class StackableTopologyProvider implements DNSToSwitchMapping {
2323
private final Logger LOG = LoggerFactory.getLogger(StackableTopologyProvider.class);
@@ -47,11 +47,10 @@ public StackableTopologyProvider() {
4747
@Override
4848
public void reloadCachedMappings() {
4949
// TODO: According to the upstream comment we should rebuild all cache entries after
50-
// invalidating them
51-
// this may mean trying to resolve ip addresses that do not exist any more and things like that
52-
// though and
53-
// require some more thought, so we will for now just invalidate the cache.
54-
this.cache.invalidateAll();
50+
// invalidating them. This may mean trying to resolve ip addresses that do not exist
51+
// any more and things like that though and require some more thought, so we will for
52+
// now just invalidate the cache.
53+
this.cache.invalidateAllTopologyKeys();
5554
}
5655

5756
@Override
@@ -73,10 +72,7 @@ private void logInitializationStatus() {
7372
labels.stream().map(TopologyLabel::getName).collect(Collectors.toList());
7473
LOG.info("Initialized with topology labels: {}", labelNames);
7574
}
76-
LOG.debug(
77-
"Client namespaces {} and configuration {}",
78-
client.getNamespace(),
79-
client.getConfiguration());
75+
LOG.debug("Client namespace {}", client.getNamespace());
8076
}
8177

8278
@Override
@@ -106,8 +102,7 @@ private List<String> createDefaultRackList(List<String> names) {
106102

107103
private List<String> tryResolveFromCache(List<String> names) {
108104
// We need to check if we have cached values for all dataNodes contained in this request.
109-
// Unless we can answer everything from the cache we have to talk to k8s anyway and can just
110-
// recalculate everything
105+
// Unless we can answer everything from the cache we will perform a full resolution.
111106
List<String> cached = names.stream().map(cache::getTopology).collect(Collectors.toList());
112107
LOG.debug("Cached topologyKeyCache values [{}]", cached);
113108

@@ -263,10 +258,10 @@ private String resolveListenerEndpoint(GenericKubernetesResource listener) {
263258
}
264259

265260
private GenericKubernetesResourceList fetchListeners() {
261+
// no version is specified here as we are not always going to be on v1alpha1
266262
ResourceDefinitionContext listenerCrd =
267263
new ResourceDefinitionContext.Builder()
268264
.withGroup("listeners.stackable.tech")
269-
.withVersion("v1alpha1")
270265
.withPlural("listeners")
271266
.withNamespaced(true)
272267
.build();
@@ -488,8 +483,10 @@ private Map<String, Map<String, String>> buildPodLabelMap(List<Pod> dataNodes) {
488483
Map<String, Map<String, String>> result = new HashMap<>();
489484
for (Pod pod : dataNodes) {
490485
Map<String, String> podLabels = pod.getMetadata().getLabels();
486+
LOG.debug("Labels for pod [{}]:[{}]....", pod.getMetadata().getName(), podLabels);
491487

492488
for (PodIP podIp : pod.getStatus().getPodIPs()) {
489+
LOG.debug("...assigned to pod IP [{}]", podIp.getIp());
493490
result.put(podIp.getIp(), podLabels);
494491
}
495492
}

src/main/java/tech/stackable/hadoop/TopologyCache.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.fabric8.kubernetes.api.model.Node;
77
import io.fabric8.kubernetes.api.model.Pod;
88
import java.util.List;
9-
import java.util.concurrent.ConcurrentMap;
109
import java.util.concurrent.TimeUnit;
1110

1211
/** Manages all caching layers for the topology provider. */
@@ -38,7 +37,7 @@ void putTopology(String key, String value) {
3837
topology.put(key, value);
3938
}
4039

41-
void invalidateAll() {
40+
void invalidateAllTopologyKeys() {
4241
topology.invalidateAll();
4342
}
4443

@@ -58,26 +57,14 @@ GenericKubernetesResource getListener(String name) {
5857
return listeners.getIfPresent(name);
5958
}
6059

61-
ConcurrentMap<String, GenericKubernetesResource> getListenerMap() {
62-
return listeners.asMap();
63-
}
64-
6560
void putListener(String name, GenericKubernetesResource listener) {
6661
listeners.put(name, listener);
6762
}
6863

69-
boolean hasAllListeners(List<String> names) {
70-
return names.stream().noneMatch(name -> listeners.getIfPresent(name) == null);
71-
}
72-
7364
Pod getPod(String name) {
7465
return pods.getIfPresent(name);
7566
}
7667

77-
ConcurrentMap<String, Pod> getPodMap() {
78-
return pods.asMap();
79-
}
80-
8168
void putPod(String name, Pod pod) {
8269
pods.put(name, pod);
8370
}

src/main/java/tech/stackable/hadoop/TopologyLabel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class TopologyLabel {
1111
private static final Logger LOG = LoggerFactory.getLogger(TopologyLabel.class);
1212
public static final String VARNAME_LABELS = "TOPOLOGY_LABELS";
13-
public static final String VARNAME_MAXLEVELS = "TOPOLOGY_MAX_LEVELS";
13+
public static final String VARNAME_MAX_LEVELS = "TOPOLOGY_MAX_LEVELS";
1414
private static final int MAX_LEVELS_DEFAULT = 2;
1515

1616
public enum Type {
@@ -32,7 +32,7 @@ public enum Type {
3232
String[] parts = config.toLowerCase(Locale.ROOT).split(":", 2);
3333

3434
if (parts.length != 2) {
35-
LOG.warn("Invalid topology label format '{}' - expected '[node|pod]:<labelname>'", config);
35+
LOG.warn("Invalid topology label format '{}' - expected '[node|pod]:<label>'", config);
3636
this.type = Type.UNDEFINED;
3737
this.name = null;
3838
return;
@@ -102,7 +102,7 @@ public static List<TopologyLabel> initializeTopologyLabels() {
102102

103103
if (labels.stream().anyMatch(TopologyLabel::isUndefined)) {
104104
LOG.error(
105-
"Invalid topology label configuration - labels must be in format '[pod|node]:<labelname>'");
105+
"Invalid topology label configuration - labels must be in format '[pod|node]:<label>'");
106106
throw new RuntimeException("Invalid topology label configuration");
107107
}
108108

@@ -111,6 +111,6 @@ public static List<TopologyLabel> initializeTopologyLabels() {
111111

112112
private static int getMaxLabels() {
113113
return TopologyUtils.parseIntFromEnv(
114-
VARNAME_MAXLEVELS, MAX_LEVELS_DEFAULT, "maximum topology levels");
114+
VARNAME_MAX_LEVELS, MAX_LEVELS_DEFAULT, "maximum topology levels");
115115
}
116116
}

src/main/java/tech/stackable/hadoop/TopologyUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static List<String> getIngressAddresses(GenericKubernetesResource listene
2929
public static int parseIntFromEnv(String varName, int defaultValue, String description) {
3030
String value = System.getenv(varName);
3131
if (value == null || value.isEmpty()) {
32+
LOG.info("Set {} to default value {}", description, defaultValue);
3233
return defaultValue;
3334
}
3435

0 commit comments

Comments
 (0)