diff options
author | Valerij Fredriksen <valerij92@gmail.com> | 2021-02-26 14:57:11 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerij92@gmail.com> | 2021-02-26 14:58:20 +0100 |
commit | 1454578133592494bfda4b2a07df51e66d7e03e6 (patch) | |
tree | 432d8442e4f0a076f28612fdf69290276a57fbd6 /node-repository | |
parent | 3638d921339bb210e68c10f74017009d5510d211 (diff) |
Add REST API to query and update archive URIs
Diffstat (limited to 'node-repository')
5 files changed, 70 insertions, 1 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveResponse.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveResponse.java new file mode 100644 index 00000000000..486139ad1f4 --- /dev/null +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveResponse.java @@ -0,0 +1,23 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.provision.restapi; + +import com.yahoo.restapi.SlimeJsonResponse; +import com.yahoo.slime.Cursor; +import com.yahoo.vespa.hosted.provision.NodeRepository; + +/** + * Returns tenant archive URIs. + * + * @author freva + */ +public class ArchiveResponse extends SlimeJsonResponse { + + public ArchiveResponse(NodeRepository nodeRepository) { + Cursor archivesArray = slime.setObject().setArray("archives"); + nodeRepository.archiveUris().getArchiveUris().forEach((tenant, uri) -> { + Cursor archiveObject = archivesArray.addObject(); + archiveObject.setString("tenant", tenant.value()); + archiveObject.setString("uri", uri); + }); + } +} diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java index 765e26ab487..62c7f40f7da 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java @@ -111,13 +111,14 @@ public class NodesV2ApiHandler extends LoggingRequestHandler { private HttpResponse handleGET(HttpRequest request) { Path path = new Path(request.getUri()); String pathS = request.getUri().getPath(); - if (path.matches( "/nodes/v2")) return new ResourceResponse(request.getUri(), "state", "node", "command", "maintenance", "upgrade", "application"); + if (path.matches( "/nodes/v2")) return new ResourceResponse(request.getUri(), "state", "node", "command", "maintenance", "upgrade", "application", "archive", "locks"); if (path.matches( "/nodes/v2/node")) return new NodesResponse(ResponseType.nodeList, request, orchestrator, nodeRepository); if (pathS.startsWith("/nodes/v2/node/")) return new NodesResponse(ResponseType.singleNode, request, orchestrator, nodeRepository); if (path.matches( "/nodes/v2/state")) return new NodesResponse(ResponseType.stateList, request, orchestrator, nodeRepository); if (pathS.startsWith("/nodes/v2/state/")) return new NodesResponse(ResponseType.nodesInStateList, request, orchestrator, nodeRepository); if (path.matches( "/nodes/v2/acl/{hostname}")) return new NodeAclResponse(request, nodeRepository, path.get("hostname")); if (path.matches( "/nodes/v2/command")) return new ResourceResponse(request.getUri(), "restart", "reboot"); + if (path.matches( "/nodes/v2/archive")) return new ArchiveResponse(nodeRepository); if (path.matches( "/nodes/v2/locks")) return new LocksResponse(); if (path.matches( "/nodes/v2/maintenance")) return new JobsResponse(nodeRepository.jobControl()); if (path.matches( "/nodes/v2/upgrade")) return new UpgradeResponse(nodeRepository.infrastructureVersions(), nodeRepository.osVersions(), nodeRepository.containerImages()); @@ -176,6 +177,10 @@ public class NodesV2ApiHandler extends LoggingRequestHandler { return new MessageResponse("Updated " + patcher.application()); } } + else if (path.matches("/nodes/v2/archive/{tenant}")) { + String uri = requiredField(toSlime(request), "uri", Inspector::asString); + return setTenantArchiveUri(path.get("tenant"), Optional.of(uri)); + } else if (path.matches("/nodes/v2/upgrade/{nodeType}")) { return setTargetVersions(path.get("nodeType"), toSlime(request)); } @@ -206,6 +211,7 @@ public class NodesV2ApiHandler extends LoggingRequestHandler { private HttpResponse handleDELETE(HttpRequest request) { Path path = new Path(request.getUri()); if (path.matches("/nodes/v2/node/{hostname}")) return deleteNode(path.get("hostname")); + if (path.matches("/nodes/v2/archive/{tenant}")) return setTenantArchiveUri(path.get("tenant"), Optional.empty()); if (path.matches("/nodes/v2/upgrade/firmware")) return cancelFirmwareCheckResponse(); throw new NotFoundException("Nothing at path '" + request.getUri().getPath() + "'"); @@ -412,6 +418,11 @@ public class NodesV2ApiHandler extends LoggingRequestHandler { return new MessageResponse("Will request firmware checks on all hosts."); } + private HttpResponse setTenantArchiveUri(String tenant, Optional<String> archiveUri) { + nodeRepository.archiveUris().setArchiveUri(TenantName.from(tenant), archiveUri); + return new MessageResponse(archiveUri.map(a -> "Updated").orElse("Removed") + " archive URI for " + tenant); + } + private static String hostnamesAsString(List<Node> nodes) { return nodes.stream().map(Node::hostname).sorted().collect(Collectors.joining(", ")); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java index dce2d6f90c6..6b4a57310e7 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java @@ -1003,6 +1003,23 @@ public class NodesV2ApiTest { tester.assertPartialResponse(new Request(url), "exclusiveTo", false); } + @Test + public void archive_uris() throws IOException { + tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "archiveUri", false); + tester.assertResponse(new Request("http://localhost:8080/nodes/v2/archive"), "{\"archives\":[]}"); + + assertResponse(new Request("http://localhost:8080/nodes/v2/archive/tenant3", Utf8.toBytes("{\"uri\": \"ftp://host/dir\"}"), Request.Method.PATCH), + "{\"message\":\"Updated archive URI for tenant3\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/archive/tenant2", Utf8.toBytes("{\"uri\": \"s3://my-bucket/dir\"}"), Request.Method.PATCH), + "{\"message\":\"Updated archive URI for tenant2\"}"); + + tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "\"archiveUri\":\"ftp://host/dir/application3/instance3/host4/\"", true); + assertFile(new Request("http://localhost:8080/nodes/v2/archive"), "archives.json"); + + tester.assertResponse(new Request("http://localhost:8080/nodes/v2/archive/tenant3", new byte[0], Request.Method.DELETE), "{\"message\":\"Removed archive URI for tenant3\"}"); + tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "archiveUri", false); + } + private static String asDockerNodeJson(String hostname, String parentHostname, String... ipAddress) { return asDockerNodeJson(hostname, NodeType.tenant, parentHostname, ipAddress); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/archives.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/archives.json new file mode 100644 index 00000000000..1ce54b54f6a --- /dev/null +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/archives.json @@ -0,0 +1,12 @@ +{ + "archives": [ + { + "tenant": "tenant2", + "uri": "s3://my-bucket/dir/" + }, + { + "tenant": "tenant3", + "uri": "ftp://host/dir/" + } + ] +} diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/root.json b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/root.json index cc91314df84..91b513cd9bc 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/root.json +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/root.json @@ -17,6 +17,12 @@ }, { "url":"http://localhost:8080/nodes/v2/application/" + }, + { + "url":"http://localhost:8080/nodes/v2/archive/" + }, + { + "url":"http://localhost:8080/nodes/v2/locks/" } ] }
\ No newline at end of file |