diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-01-29 13:51:04 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-01-29 13:51:04 +0100 |
commit | 52a4be8cccbdae9454d08a958e90e4eecc45a896 (patch) | |
tree | ad475699ad6c9de0b88c5a00ba98bedb179870e5 /orchestrator | |
parent | f27ddf9d7c74f7278111c1e3e28c5f7e9ea8f2fd (diff) |
Remove unnecessary maps
Diffstat (limited to 'orchestrator')
-rw-r--r-- | orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfos.java | 4 | ||||
-rw-r--r-- | orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java | 26 |
2 files changed, 8 insertions, 22 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfos.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfos.java index cb3f9cb8afe..fe78a41672b 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfos.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/HostInfos.java @@ -19,6 +19,10 @@ public class HostInfos { this.hostInfos = Map.copyOf(hostInfos); } + public HostInfos() { + this.hostInfos = Map.of(); + } + /** Get all suspended hostnames. */ public Set<HostName> suspendedHostsnames() { return hostInfos.entrySet().stream() diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java index 4f96c4e1e0e..c4a23baae2e 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java @@ -21,8 +21,6 @@ import org.apache.zookeeper.data.Stat; import javax.inject.Inject; import java.time.Duration; import java.time.Instant; -import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -260,37 +258,21 @@ public class ZookeeperStatusService implements StatusService { return hostInfosCache.getHostInfos(applicationInstanceReference).get(hostName); } - private Set<HostName> hostsDownFor(ApplicationInstanceReference application) { - try { - if (curator.framework().checkExists().forPath(hostsAllowedDownPath(application)) == null) - return Collections.emptySet(); - - return curator.framework().getChildren().forPath(hostsAllowedDownPath(application)) - .stream().map(HostName::new) - .collect(Collectors.toUnmodifiableSet()); - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - /** Do not call this directly: should be called behind a cache. */ private HostInfos getHostInfosFromZk(ApplicationInstanceReference application) { - Map<HostName, HostInfo> hostInfos; String hostsRootPath = hostsPath(application); if (uncheck(() -> curator.framework().checkExists().forPath(hostsRootPath)) == null) { - hostInfos = new HashMap<>(); + return new HostInfos(); } else { List<String> hostnames = uncheck(() -> curator.framework().getChildren().forPath(hostsRootPath)); - hostInfos = new HashMap<>(hostnames.stream().collect(Collectors.toMap( + Map<HostName, HostInfo> hostInfos = hostnames.stream().collect(Collectors.toMap( hostname -> new HostName(hostname), hostname -> { byte[] bytes = uncheck(() -> curator.framework().getData().forPath(hostsRootPath + "/" + hostname)); return WireHostInfo.deserialize(bytes); - }))); + })); + return new HostInfos(hostInfos); } - - return new HostInfos(hostInfos); } private <T> T uncheck(SupplierThrowingException<T> supplier) { |