diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-07-09 09:04:34 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-07-09 15:31:49 +0200 |
commit | 8c4858b1ecff262a71083e5e083f341784599dd8 (patch) | |
tree | aea896afbc8186a6c523e93f53ec824ddffd2da1 /controller-api | |
parent | c389e0c7e67410a6601cb80d77c80b3c1df3740b (diff) |
Combine NodeRepositoryClientInterface and NodeRepository
Diffstat (limited to 'controller-api')
2 files changed, 79 insertions, 59 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java index 95544c23db5..916a388692e 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/NodeRepository.java @@ -5,8 +5,13 @@ import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeList; +import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryNode; +import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeState; +import java.util.Collection; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -17,8 +22,38 @@ import java.util.stream.Collectors; */ public interface NodeRepository { + void addNodes(ZoneId zone, Collection<NodeRepositoryNode> nodes); + + void deleteNode(ZoneId zone, String hostname); + + void setState(ZoneId zone, NodeState nodeState, String nodename); + + NodeRepositoryNode getNode(ZoneId zone, String hostname); + + NodeList listNodes(ZoneId zone); + + NodeList listNodes(ZoneId zone, ApplicationId application); + /** List all nodes in zone owned by given application */ - List<Node> list(ZoneId zone, ApplicationId application); + default List<Node> list(ZoneId zone, ApplicationId application) { + return listNodes(zone, application).nodes().stream() + .map(n -> new Node(com.yahoo.config.provision.HostName.from(n.getHostname()), + fromJacksonState(n.getState()), + fromJacksonType(n.getType()), Optional.of(application), + Version.fromString(n.getVespaVersion()), + Version.fromString(n.getWantedVespaVersion()), + Version.fromString(n.getCurrentOsVersion()), + Version.fromString(n.getWantedOsVersion()), + fromBoolean(n.getAllowedToBeDown()), + n.getCurrentRestartGeneration(), + n.getRestartGeneration(), + n.getCurrentRebootGeneration(), + n.getRebootGeneration(), + n.getCanonicalFlavor(), + n.getMembership().clusterid, + clusterTypeOf(n.getMembership().clustertype))) + .collect(Collectors.toUnmodifiableList()); + } /** List all nodes in states, in zone owned by given application */ default List<Node> list(ZoneId zone, ApplicationId application, Set<Node.State> states) { @@ -39,4 +74,47 @@ public interface NodeRepository { /** Cancels firmware checks on all hosts in the given zone. */ void cancelFirmwareCheck(ZoneId zone); + + + private Node.ClusterType clusterTypeOf(String type) { + switch (type) { + case "admin": return Node.ClusterType.admin; + case "content": return Node.ClusterType.content; + case "container": return Node.ClusterType.container; + default: throw new IllegalArgumentException("Unknown cluster type '" + type + "'."); + } + } + + // Convert Jackson type to config.provision type + private static NodeType fromJacksonType(com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeType nodeType) { + switch (nodeType) { + case tenant: return NodeType.tenant; + case host: return NodeType.host; + case proxy: return NodeType.proxy; + case proxyhost: return NodeType.proxyhost; + case config: return NodeType.config; + case confighost: return NodeType.confighost; + default: throw new IllegalArgumentException("Unknown type: " + nodeType); + } + } + + private static com.yahoo.vespa.hosted.controller.api.integration.configserver.Node.State fromJacksonState(NodeState state) { + switch (state) { + case provisioned: return Node.State.provisioned; + case ready: return Node.State.ready; + case reserved: return Node.State.reserved; + case active: return Node.State.active; + case inactive: return Node.State.inactive; + case dirty: return Node.State.dirty; + case failed: return Node.State.failed; + case parked: return Node.State.parked; + default: throw new IllegalArgumentException("Unknown state: " + state); + } + } + + private static Node.ServiceState fromBoolean(Boolean allowedDown) { + return (allowedDown == null) + ? Node.ServiceState.unorchestrated + : allowedDown ? Node.ServiceState.allowedDown : Node.ServiceState.expectedUp; + } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryClientInterface.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryClientInterface.java deleted file mode 100644 index 4b495ebf331..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeRepositoryClientInterface.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.controller.api.integration.noderepository; - -import com.yahoo.config.provision.zone.ZoneId; - -import java.io.IOException; -import java.util.Collection; - -/** - * A complete client for the node repository REST API. - * - * @author smorgrav - * @author bjorncs - */ -// TODO: Get rid of all the checked exceptions -// TODO: Replace remaining controller-server usages of this with -// com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository and move this package back to internal -// repo -public interface NodeRepositoryClientInterface { - - enum WantTo { - Retire, - Deprovision - } - - void addNodes(ZoneId zone, Collection<NodeRepositoryNode> nodes) throws IOException; - - NodeRepositoryNode getNode(ZoneId zone, String hostname) throws IOException; - - void deleteNode(ZoneId zone, String hostname) throws IOException; - - NodeList listNodes(ZoneId zone, boolean recursive) throws IOException; - - NodeList listNodes(ZoneId zone, String tenant, String applicationId, String instance) throws IOException; - - String resetFailureInformation(ZoneId zone, String nodename) throws IOException; - - String restart(ZoneId zone, String nodename) throws IOException; - - String reboot(ZoneId zone, String nodename) throws IOException; - - String cancelReboot(ZoneId zone, String nodename) throws IOException; - - String wantTo(ZoneId zone, String nodename, WantTo... actions) throws IOException; - - String cancelRestart(ZoneId zone, String nodename) throws IOException; - - String setHardwareFailureDescription(ZoneId zone, String nodename, String hardwareFailureDescription) throws IOException; - - void setState(ZoneId zone, NodeState nodeState, String nodename) throws IOException; - - String enableMaintenanceJob(ZoneId zone, String jobName) throws IOException; - - String disableMaintenanceJob(ZoneId zone, String jobName) throws IOException; - - MaintenanceJobList listMaintenanceJobs(ZoneId zone) throws IOException; - -} |