-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopologyUtils.java
More file actions
56 lines (50 loc) · 2.12 KB
/
TopologyUtils.java
File metadata and controls
56 lines (50 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package tech.stackable.hadoop;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TopologyUtils {
private static final Logger LOG = LoggerFactory.getLogger(TopologyUtils.class);
private static final String ADDRESS = "address";
private static final String STATUS = "status";
private static final String INGRESS_ADDRESSES = "ingressAddresses";
public static List<String> getIngressAddresses(GenericKubernetesResource listener) {
// suppress warning as we know the structure of our own listener resource
Object statusObj = listener.getAdditionalProperties().get(STATUS);
if (statusObj == null) {
LOG.warn("Listener {} has no status", listener.getMetadata().getName());
return Collections.emptyList();
}
@SuppressWarnings("unchecked")
Map<String, Object> status = (Map<String, Object>) statusObj;
Object addressesObj = status.get(INGRESS_ADDRESSES);
if (addressesObj == null) {
LOG.warn("Listener {} has no ingress addresses", listener.getMetadata().getName());
return Collections.emptyList();
}
@SuppressWarnings("unchecked")
List<Map<String, Object>> ingressAddresses = (List<Map<String, Object>>) addressesObj;
return ingressAddresses.stream()
.map(ingress -> (String) ingress.get(ADDRESS))
.collect(Collectors.toList());
}
public static int parseIntFromEnv(String varName, int defaultValue, String description) {
String value = System.getenv(varName);
if (value == null || value.isEmpty()) {
LOG.info("Set {} to default value {}", description, defaultValue);
return defaultValue;
}
try {
int parsed = Integer.parseInt(value);
LOG.info("Set {} to {} from environment variable {}", description, parsed, varName);
return parsed;
} catch (NumberFormatException e) {
LOG.warn(
"Invalid integer value '{}' for {} - using default: {}", value, varName, defaultValue);
return defaultValue;
}
}
}