aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@yahooinc.com>2023-02-24 15:25:09 +0100
committerValerij Fredriksen <valerijf@yahooinc.com>2023-02-24 15:25:09 +0100
commit8ef195669924b488974a3cd79858f28c22c7f564 (patch)
treeeb5ebdad9589b726a9c0c0daafe5f995fd8e4cb1
parent99d8d804a7e478900585fc60244b6cfbb999c3db (diff)
Allow patching account archive URI in /nodes/v2
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java14
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java8
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveApiTest.java67
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java3
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java20
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java5
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/responses/archives.json4
7 files changed, 92 insertions, 29 deletions
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 8de67e44700..75987d08dc2 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
@@ -186,9 +186,9 @@ public class NodesV2ApiHandler extends ThreadedHttpRequestHandler {
return new MessageResponse("Updated " + patcher.application());
}
}
- else if (path.matches("/nodes/v2/archive/{tenant}")) {
+ else if (path.matches("/nodes/v2/archive/account/{key}") || path.matches("/nodes/v2/archive/tenant/{key}") || path.matches("/nodes/v2/archive/{key}") /* TODO (freva): Remove March 2023 */) {
String uri = requiredField(toSlime(request), "uri", Inspector::asString);
- return setTenantArchiveUri(path.get("tenant"), Optional.of(uri));
+ return setArchiveUri(path.get("key"), Optional.of(uri), !path.getPath().segments().get(3).equals("account"));
}
else if (path.matches("/nodes/v2/upgrade/{nodeType}")) {
return setTargetVersions(path.get("nodeType"), toSlime(request));
@@ -229,7 +229,8 @@ public class NodesV2ApiHandler extends ThreadedHttpRequestHandler {
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/archive/account/{key}") || path.matches("/nodes/v2/archive/tenant/{key}") || path.matches("/nodes/v2/archive/{key}") /* TODO (freva): Remove March 2023) */)
+ return setArchiveUri(path.get("key"), Optional.empty(), !path.getPath().segments().get(3).equals("account"));
if (path.matches("/nodes/v2/upgrade/firmware")) return cancelFirmwareCheckResponse();
throw new NotFoundException("Nothing at path '" + request.getUri().getPath() + "'");
@@ -422,9 +423,10 @@ public class NodesV2ApiHandler extends ThreadedHttpRequestHandler {
return new MessageResponse("Will request firmware checks on all hosts.");
}
- private HttpResponse setTenantArchiveUri(String tenant, Optional<String> archiveUri) {
- nodeRepository.archiveUriManager().setArchiveUri(TenantName.from(tenant), archiveUri);
- return new MessageResponse(archiveUri.map(a -> "Updated").orElse("Removed") + " archive URI for " + tenant);
+ private HttpResponse setArchiveUri(String key, Optional<String> archiveUri, boolean isTenant) {
+ if (isTenant) nodeRepository.archiveUriManager().setArchiveUri(TenantName.from(key), archiveUri);
+ else nodeRepository.archiveUriManager().setArchiveUri(CloudAccount.from(key), archiveUri);
+ return new MessageResponse(archiveUri.map(a -> "Updated").orElse("Removed") + " archive URI for " + key);
}
private static String hostnamesAsString(List<Node> nodes) {
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
index f0f85b6523f..4f88a10dff0 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
@@ -2,6 +2,7 @@
package com.yahoo.vespa.hosted.provision.testutils;
import com.yahoo.config.provision.CloudAccount;
+import com.yahoo.config.provision.SystemName;
/**
* For running NodeRepository API with some mocked data.
@@ -11,12 +12,15 @@ import com.yahoo.config.provision.CloudAccount;
*/
public class ContainerConfig {
- public static String servicesXmlV2(int port, CloudAccount cloudAccount) {
+ public static String servicesXmlV2(int port, SystemName systemName, CloudAccount cloudAccount) {
return """
<container version='1.0'>
<config name="container.handler.threadpool">
<maxthreads>20</maxthreads>
</config>
+ <config name="cloud.config.configserver">
+ <system>%s</system>
+ </config>
<config name="config.provisioning.cloud">
<account>%s</account>
</config>
@@ -47,7 +51,7 @@ public class ContainerConfig {
<server id='myServer' port='%s'/>
</http>
</container>
- """.formatted(cloudAccount.value(), port);
+ """.formatted(systemName.value(), cloudAccount.value(), port);
}
}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveApiTest.java
new file mode 100644
index 00000000000..80d79b036e2
--- /dev/null
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/ArchiveApiTest.java
@@ -0,0 +1,67 @@
+// Copyright Yahoo. 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.application.container.handler.Request;
+import com.yahoo.config.provision.CloudAccount;
+import com.yahoo.config.provision.SystemName;
+import com.yahoo.text.Utf8;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Test of the REST APIs provided by the node repository.
+ *
+ * Note: This class is referenced from our operations documentation and must not be renamed/moved without updating that.
+ *
+ * @author bratseth
+ */
+public class ArchiveApiTest {
+
+ private RestApiTester tester;
+
+ @Before
+ public void createTester() {
+ tester = new RestApiTester(SystemName.Public, CloudAccount.from("111222333444"));
+ }
+
+ @After
+ public void closeTester() {
+ tester.close();
+ }
+
+ @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/tenant/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\"}");
+ assertResponse(new Request("http://localhost:8080/nodes/v2/archive/account/777888999000", Utf8.toBytes("{\"uri\": \"s3://acc-bucket\"}"), Request.Method.PATCH),
+ "{\"message\":\"Updated archive URI for 777888999000\"}");
+
+
+ tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "\"archiveUri\":\"ftp://host/dir/application3/instance3/id3/host4/\"", true);
+ tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost2.yahoo.com"), "\"archiveUri\":\"s3://acc-bucket/zoneapp/zoneapp/node-admin/dockerhost2/\"", true);
+ assertFile(new Request("http://localhost:8080/nodes/v2/archive"), "archives.json");
+
+ tester.assertResponse(new Request("http://localhost:8080/nodes/v2/archive/tenant/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);
+ tester.assertResponse(new Request("http://localhost:8080/nodes/v2/archive/account/777888999000", new byte[0], Request.Method.DELETE), "{\"message\":\"Removed archive URI for 777888999000\"}");
+ tester.assertPartialResponse(new Request("http://localhost:8080/nodes/v2/node/dockerhost2.yahoo.com"), "archiveUri", false);
+ }
+
+
+ private void assertFile(Request request, String file) throws IOException {
+ tester.assertFile(request, file);
+ }
+
+ private void assertResponse(Request request, String response) throws IOException {
+ tester.assertResponse(request, response);
+ }
+
+}
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
index 240d0daf96f..729b6b813cd 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.provision.restapi;
import com.yahoo.application.container.handler.Request;
import com.yahoo.config.provision.CloudAccount;
+import com.yahoo.config.provision.SystemName;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -16,7 +17,7 @@ public class LoadBalancersV1ApiTest {
@Before
public void createTester() {
- tester = new RestApiTester(CloudAccount.empty);
+ tester = new RestApiTester(SystemName.main, CloudAccount.empty);
}
@After
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 43676518330..c9e57c22d11 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
@@ -6,6 +6,7 @@ import com.yahoo.application.container.handler.Response;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.NodeType;
+import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.TenantName;
import com.yahoo.text.Utf8;
import com.yahoo.vespa.applicationmodel.HostName;
@@ -41,7 +42,7 @@ public class NodesV2ApiTest {
@Before
public void createTester() {
- tester = new RestApiTester(CloudAccount.from("111222333444"));
+ tester = new RestApiTester(SystemName.main, CloudAccount.from("111222333444"));
}
@After
@@ -990,23 +991,6 @@ public class NodesV2ApiTest {
}
@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/id3/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);
- }
-
- @Test
public void trusted_certificates_patch() throws IOException {
String url = "http://localhost:8080/nodes/v2/node/dockerhost1.yahoo.com";
tester.assertPartialResponse(new Request(url), "\"trustStore\":[]", false); // initially empty list
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java
index e424b04aeaf..47745d25467 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/RestApiTester.java
@@ -6,6 +6,7 @@ import com.yahoo.application.container.JDisc;
import com.yahoo.application.container.handler.Request;
import com.yahoo.application.container.handler.Response;
import com.yahoo.config.provision.CloudAccount;
+import com.yahoo.config.provision.SystemName;
import com.yahoo.io.IOUtils;
import com.yahoo.vespa.hosted.provision.testutils.ContainerConfig;
import org.junit.ComparisonFailure;
@@ -25,8 +26,8 @@ public class RestApiTester {
private final JDisc container;
- public RestApiTester(CloudAccount defaultCloudAccount) {
- container = JDisc.fromServicesXml(ContainerConfig.servicesXmlV2(0, defaultCloudAccount), Networking.disable);
+ public RestApiTester(SystemName systemName, CloudAccount defaultCloudAccount) {
+ container = JDisc.fromServicesXml(ContainerConfig.servicesXmlV2(0, systemName, defaultCloudAccount), Networking.disable);
}
public void close() {
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
index 1ce54b54f6a..738d8ee1bb3 100644
--- 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
@@ -7,6 +7,10 @@
{
"tenant": "tenant3",
"uri": "ftp://host/dir/"
+ },
+ {
+ "account": "777888999000",
+ "uri": "s3://acc-bucket/"
}
]
}