diff options
author | toby <smorgrav@yahoo-inc.com> | 2017-10-03 12:24:33 +0200 |
---|---|---|
committer | toby <smorgrav@yahoo-inc.com> | 2017-10-10 13:39:36 +0200 |
commit | 5f0cdc5c18c74ea9ead5f2f3f03e57874935aa5e (patch) | |
tree | 88609292d47a3bac89603d6bb82045292de0fdf0 /controller-server | |
parent | ad3dc7890a7bc72ba16998ff448d39061f5937d0 (diff) |
Add getNodeList to configserverclient
Diffstat (limited to 'controller-server')
2 files changed, 23 insertions, 57 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ClusterInfoMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ClusterInfoMaintainer.java index 5aef1512d63..2b31a909e59 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ClusterInfoMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ClusterInfoMaintainer.java @@ -1,24 +1,21 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.maintenance; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.Zone; import com.yahoo.vespa.curator.Lock; import com.yahoo.vespa.hosted.controller.Application; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeList; import com.yahoo.vespa.hosted.controller.application.ClusterInfo; import com.yahoo.vespa.hosted.controller.application.Deployment; import java.io.IOException; -import java.net.URI; import java.time.Duration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -37,24 +34,24 @@ public class ClusterInfoMaintainer extends Maintainer { this.controller = controller; } - private static String clusterid(NodeRepositoryJsonModel.Node node) { + private static String clusterid(NodeList.Node node) { return node.membership.clusterId; } - private Map<ClusterSpec.Id, ClusterInfo> getClusterInfo(NodeRepositoryJsonModel nodes) { + private Map<ClusterSpec.Id, ClusterInfo> getClusterInfo(NodeList nodes) { Map<ClusterSpec.Id, ClusterInfo> infoMap = new HashMap<>(); // Group nodes by clusterid - Map<String, List<NodeRepositoryJsonModel.Node>> clusters = nodes.nodes.stream() + Map<String, List<NodeList.Node>> clusters = nodes.nodes.stream() .filter(node -> node.membership != null) .collect(Collectors.groupingBy(ClusterInfoMaintainer::clusterid)); // For each cluster - get info for (String id : clusters.keySet()) { - List<NodeRepositoryJsonModel.Node> clusterNodes = clusters.get(id); + List<NodeList.Node> clusterNodes = clusters.get(id); //Assume they are all equal and use first node as a representatitve for the cluster - NodeRepositoryJsonModel.Node node = clusterNodes.get(0); + NodeList.Node node = clusterNodes.get(0); // Add to map List<String> hostnames = clusterNodes.stream().map(node1 -> node1.hostname).collect(Collectors.toList()); @@ -65,58 +62,21 @@ public class ClusterInfoMaintainer extends Maintainer { return infoMap; } - // TODO use appId in url - private NodeRepositoryJsonModel getApplicationNodes(ApplicationId appId, Zone zone) { - NodeRepositoryJsonModel nodesResponse = null; - ObjectMapper mapper = new ObjectMapper(); - for (URI uri : controller.getConfigServerUris(zone.environment(), zone.region())) { - try { - nodesResponse = mapper.readValue(uri.toURL(), NodeRepositoryJsonModel.class); - break; - } catch (IOException ioe) { - //TODO - } - } - return nodesResponse; - } - @Override protected void maintain() { for (Application application : controller().applications().asList()) { Lock lock = controller().applications().lock(application.id()); for (Deployment deployment : application.deployments().values()) { - NodeRepositoryJsonModel appNodes = getApplicationNodes(application.id(), deployment.zone()); - Map<ClusterSpec.Id, ClusterInfo> clusterInfo = getClusterInfo(appNodes); - Application app = application.with(deployment.withClusterInfo(clusterInfo)); - controller.applications().store(app, lock); - } - } - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static class NodeRepositoryJsonModel { - - @JsonProperty("nodes") - public List<Node> nodes; - - @JsonIgnoreProperties(ignoreUnknown = true) - public static class Node { - @JsonProperty("hostname") - public String hostname; - @JsonProperty("flavor") - public String flavor; - @JsonProperty("membership") - public Membership membership; - @JsonProperty("cost") - public int cost; - - @JsonIgnoreProperties(ignoreUnknown = true) - public static class Membership { - @JsonProperty("clustertype") - public String clusterType; - @JsonProperty("clusterid") - public String clusterId; + DeploymentId deploymentId = new DeploymentId(application.id(), deployment.zone()); + try { + NodeList nodes = controller().applications().configserverClient().getNodeList(deploymentId); + Map<ClusterSpec.Id, ClusterInfo> clusterInfo = getClusterInfo(nodes); + Application app = application.with(deployment.withClusterInfo(clusterInfo)); + controller.applications().store(app, lock); + } catch (IOException ioe) { + Logger.getLogger(ClusterInfoMaintainer.class.getName()).fine(ioe.getMessage()); + } } } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java index 13525969358..c45a3c6790b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ConfigServerClientMock.java @@ -9,6 +9,7 @@ import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServerClient; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Log; +import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeList; import com.yahoo.vespa.hosted.controller.api.integration.configserver.PrepareResponse; import com.yahoo.vespa.hosted.controller.api.application.v4.model.DeployOptions; import com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus; @@ -21,6 +22,7 @@ import com.yahoo.vespa.serviceview.bindings.ApplicationView; import com.yahoo.vespa.serviceview.bindings.ClusterView; import com.yahoo.vespa.serviceview.bindings.ServiceView; +import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -211,4 +213,8 @@ public class ConfigServerClientMock extends AbstractComponent implements ConfigS : result; } + @Override + public NodeList getNodeList(DeploymentId deployment) throws IOException { + return new NodeList(); + } } |