diff options
author | Martin Polden <martin.polden@gmail.com> | 2017-02-22 10:27:38 +0100 |
---|---|---|
committer | Martin Polden <martin.polden@gmail.com> | 2017-02-22 10:27:38 +0100 |
commit | 7a6c3fc0bac3e26174e5dfc7cec9646bbad18a09 (patch) | |
tree | a4ea5b028d9575fcccccb5a2aebb13708af4639d /node-repository | |
parent | 0e632860a368a0e86408e5bbf0351e9639dcdb89 (diff) |
Remove /nodes/v1
Diffstat (limited to 'node-repository')
3 files changed, 0 insertions, 242 deletions
diff --git a/node-repository/src/main/config/node-repository.xml b/node-repository/src/main/config/node-repository.xml index 3dc85374e33..aadca9187b6 100644 --- a/node-repository/src/main/config/node-repository.xml +++ b/node-repository/src/main/config/node-repository.xml @@ -10,10 +10,6 @@ <components bundle="node-repository" /> </rest-api> -<handler id="com.yahoo.vespa.hosted.provision.restapi.v1.NodesApiHandler" bundle="node-repository"> - <binding>http://*/nodes/v1/</binding> -</handler> - <handler id="com.yahoo.vespa.hosted.provision.restapi.v2.NodesApiHandler" bundle="node-repository"> <binding>http://*/nodes/v2/*</binding> </handler> diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v1/NodesApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v1/NodesApiHandler.java deleted file mode 100644 index 1df61f1c6f7..00000000000 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v1/NodesApiHandler.java +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.provision.restapi.v1; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ClusterMembership; -import com.yahoo.config.provision.NodeType; -import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.jdisc.LoggingRequestHandler; -import com.yahoo.container.logging.AccessLog; -import com.yahoo.jdisc.Response; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Slime; -import com.yahoo.vespa.config.SlimeUtils; -import com.yahoo.vespa.hosted.provision.Node; -import com.yahoo.vespa.hosted.provision.NodeRepository; -import com.yahoo.vespa.hosted.provision.node.Allocation; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.Executor; - -/** - * The implementation of the /nodes/v1 API. - * This dumps the content of the node repository on request, possibly with a host filter to return just the single - * matching node. - * - * @author bratseth - */ -public class - NodesApiHandler extends LoggingRequestHandler { - - private final NodeRepository nodeRepository; - - public NodesApiHandler(Executor executor, AccessLog accessLog, NodeRepository nodeRepository) { - super(executor, accessLog); - this.nodeRepository = nodeRepository; - } - - @Override - public HttpResponse handle(HttpRequest request) { - return new NodesResponse(Response.Status.OK, - Optional.ofNullable(request.getProperty("hostname")), nodeRepository); - } - - private static class NodesResponse extends HttpResponse { - - /** If present only the node with this hostname will be present in the response */ - private final Optional<String> hostnameFilter; - private final NodeRepository nodeRepository; - - public NodesResponse(int status, Optional<String> hostnameFilter, NodeRepository nodeRepository) { - super(status); - this.hostnameFilter = hostnameFilter; - this.nodeRepository = nodeRepository; - } - - @Override - public void render(OutputStream stream) throws IOException { - stream.write(toJson()); - } - - @Override - public String getContentType() { - return "application/json"; - } - - private byte[] toJson() throws IOException { - Slime slime = new Slime(); - toSlime(slime.setObject()); - return SlimeUtils.toJsonBytes(slime); - } - - private void toSlime(Cursor root) { - for (Node.State state : Node.State.values()) - toSlime(state, root); - } - - private void toSlime(Node.State state, Cursor object) { - Cursor nodeArray = null; // create if there are nodes - for (NodeType type : NodeType.values()) { - List<Node> nodes = nodeRepository.getNodes(type, state); - for (Node node : nodes) { - if (hostnameFilter.isPresent() && !node.hostname().equals(hostnameFilter.get())) continue; - if (nodeArray == null) - nodeArray = object.setArray(state.name()); - toSlime(node, nodeArray.addObject()); - } - } - } - - private void toSlime(Node node, Cursor object) { - object.setString("id", node.openStackId()); - object.setString("hostname", node.hostname()); - object.setString("flavor", node.flavor().name()); - Optional<Allocation> allocation = node.allocation(); - if (! allocation.isPresent()) return; - toSlime(allocation.get().owner(), object.setObject("owner")); - toSlime(allocation.get().membership(), object.setObject("membership")); - object.setLong("restartGeneration", allocation.get().restartGeneration().wanted()); - } - - private void toSlime(ApplicationId id, Cursor object) { - object.setString("tenant", id.tenant().value()); - object.setString("application", id.application().value()); - object.setString("instance", id.instance().value()); - } - - private void toSlime(ClusterMembership membership, Cursor object) { - object.setString("clustertype", membership.cluster().type().name()); - object.setString("clusterid", membership.cluster().id().value()); - object.setLong("index", membership.index()); - object.setBool("retired", membership.retired()); - } - - } - -}
\ No newline at end of file diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v1/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v1/RestApiTest.java deleted file mode 100644 index 48696714d69..00000000000 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v1/RestApiTest.java +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.provision.restapi.v1; - -import com.yahoo.application.container.JDisc; -import com.yahoo.application.Networking; - -import com.yahoo.application.container.handler.Request; -import com.yahoo.application.container.handler.Response; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ApplicationName; -import com.yahoo.config.provision.Capacity; -import com.yahoo.config.provision.ClusterSpec; -import com.yahoo.config.provision.HostSpec; -import com.yahoo.config.provision.InstanceName; -import com.yahoo.config.provision.NodeType; -import com.yahoo.config.provision.TenantName; -import com.yahoo.config.provision.Zone; -import com.yahoo.transaction.NestedTransaction; -import com.yahoo.vespa.curator.mock.MockCurator; -import com.yahoo.vespa.hosted.provision.Node; -import com.yahoo.vespa.hosted.provision.NodeRepository; -import com.yahoo.config.provision.NodeFlavors; -import com.yahoo.vespa.hosted.provision.provisioning.NodeRepositoryProvisioner; -import com.yahoo.vespa.hosted.provision.testutils.FlavorConfigBuilder; -import com.yahoo.vespa.hosted.provision.testutils.MockNameResolver; -import org.junit.Test; - -import java.time.Clock; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import static org.junit.Assert.assertEquals; - -/** - * @author bratseth - */ -public class RestApiTest { - - private static final String servicesXml = - "<jdisc version=\"1.0\">" + - " <component id=\"com.yahoo.vespa.hosted.provision.restapi.v1.RestApiTest$MockNodeRepository\"/>" + - " <handler id=\"com.yahoo.vespa.hosted.provision.restapi.v1.NodesApiHandler\">" + - " <binding>http://*/nodes/v1/</binding>" + - " </handler>" + - "</jdisc>"; - - @Test - public void testTopLevelRequest() throws Exception { - try (JDisc container = JDisc.fromServicesXml(servicesXml, Networking.disable)) { - Response response = container.handleRequest(new Request("http://localhost:8080/nodes/v1/")); - - assertEquals("{\"provisioned\":[{\"id\":\"node6\",\"hostname\":\"host6.yahoo.com\",\"flavor\":\"default\"}],\"reserved\":[{\"id\":\"node2\",\"hostname\":\"host2.yahoo.com\",\"flavor\":\"default\",\"owner\":{\"tenant\":\"tenant1\",\"application\":\"application1\",\"instance\":\"instance1\"},\"membership\":{\"clustertype\":\"container\",\"clusterid\":\"id1\",\"index\":1,\"retired\":false},\"restartGeneration\":0},{\"id\":\"node1\",\"hostname\":\"host1.yahoo.com\",\"flavor\":\"default\",\"owner\":{\"tenant\":\"tenant1\",\"application\":\"application1\",\"instance\":\"instance1\"},\"membership\":{\"clustertype\":\"container\",\"clusterid\":\"id1\",\"index\":0,\"retired\":false},\"restartGeneration\":0}],\"active\":[{\"id\":\"node3\",\"hostname\":\"host3.yahoo.com\",\"flavor\":\"default\",\"owner\":{\"tenant\":\"tenant2\",\"application\":\"application2\",\"instance\":\"instance2\"},\"membership\":{\"clustertype\":\"content\",\"clusterid\":\"id2\",\"index\":0,\"retired\":false},\"restartGeneration\":0},{\"id\":\"node4\",\"hostname\":\"host4.yahoo.com\",\"flavor\":\"default\",\"owner\":{\"tenant\":\"tenant2\",\"application\":\"application2\",\"instance\":\"instance2\"},\"membership\":{\"clustertype\":\"content\",\"clusterid\":\"id2\",\"index\":1,\"retired\":false},\"restartGeneration\":0}],\"failed\":[{\"id\":\"node5\",\"hostname\":\"host5.yahoo.com\",\"flavor\":\"default\"}]}", - response.getBodyAsString()); - } - } - - @Test - public void testSingleNodeRequest() throws Exception { - try (JDisc container = JDisc.fromServicesXml(servicesXml, Networking.disable)) { - Response response1 = container.handleRequest(new Request("http://localhost:8080/nodes/v1/?hostname=host1.yahoo.com")); - assertEquals("{\"reserved\":[{\"id\":\"node1\",\"hostname\":\"host1.yahoo.com\",\"flavor\":\"default\",\"owner\":{\"tenant\":\"tenant1\",\"application\":\"application1\",\"instance\":\"instance1\"},\"membership\":{\"clustertype\":\"container\",\"clusterid\":\"id1\",\"index\":0,\"retired\":false},\"restartGeneration\":0}]}", - response1.getBodyAsString()); - - Response response2 = container.handleRequest(new Request("http://localhost:8080/nodes/v1/?hostname=host6.yahoo.com")); - assertEquals("{\"provisioned\":[{\"id\":\"node6\",\"hostname\":\"host6.yahoo.com\",\"flavor\":\"default\"}]}", - response2.getBodyAsString()); - - Response response3 = container.handleRequest(new Request("http://localhost:8080/nodes/v1/?hostname=nonexisting-host.yahoo.com")); - assertEquals("{}", - response3.getBodyAsString()); - } - } - - // Instantiated by DI from application package above - @SuppressWarnings("unused") - public static class MockNodeRepository extends NodeRepository { - - private static final NodeFlavors flavors = FlavorConfigBuilder.createDummies("default"); - - public MockNodeRepository() throws Exception { - super(flavors, new MockCurator(), Clock.systemUTC(), Zone.defaultZone(), - new MockNameResolver().mockAnyLookup()); - populate(); - } - - private void populate() { - NodeRepositoryProvisioner provisioner = new NodeRepositoryProvisioner(this, flavors, Zone.defaultZone()); - - NodeFlavors flavors = FlavorConfigBuilder.createDummies("default"); - List<Node> nodes = new ArrayList<>(); - nodes.add(createNode("node1", "host1.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes.add(createNode("node2", "host2.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes.add(createNode("node3", "host3.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes.add(createNode("node4", "host4.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes.add(createNode("node5", "host5.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes.add(createNode("node6", "host6.yahoo.com", Optional.empty(), flavors.getFlavorOrThrow("default"), NodeType.tenant)); - nodes = addNodes(nodes); - nodes.remove(5); - nodes = setDirty(nodes); - setReady(nodes); - fail("host5.yahoo.com"); - - ApplicationId app1 = ApplicationId.from(TenantName.from("tenant1"), ApplicationName.from("application1"), InstanceName.from("instance1")); - ClusterSpec cluster1 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("id1"), Optional.empty()); - provisioner.prepare(app1, cluster1, Capacity.fromNodeCount(2), 1, null); - - ApplicationId app2 = ApplicationId.from(TenantName.from("tenant2"), ApplicationName.from("application2"), InstanceName.from("instance2")); - ClusterSpec cluster2 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("id2"), Optional.empty()); - List<HostSpec> hosts = provisioner.prepare(app2, cluster2, Capacity.fromNodeCount(2), 1, null); - NestedTransaction transaction = new NestedTransaction(); - provisioner.activate(transaction, app2, hosts); - transaction.commit(); - } - - } - -} |