From 6f12901db6b9e4936a0931e232dfd23868c80d63 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Sun, 18 Jun 2023 20:56:52 +0200 Subject: Handle application id strings with both 3 and 5 parts Trying to migrate to using application ids serialized to a string with 3 parts only, support both formats for now --- orchestrator/pom.xml | 5 ++++ .../resources/InstanceRequestHandler.java | 33 ++++++++++++++++++---- .../resources/InstanceRequestHandlerTest.java | 30 ++++++++++++-------- 3 files changed, 50 insertions(+), 18 deletions(-) (limited to 'orchestrator') diff --git a/orchestrator/pom.xml b/orchestrator/pom.xml index bd9c7ed977a..6ae24d2782e 100644 --- a/orchestrator/pom.xml +++ b/orchestrator/pom.xml @@ -137,6 +137,11 @@ junit-jupiter test + + org.junit.jupiter + junit-jupiter-params + test + org.junit.vintage junit-vintage-engine diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceRequestHandler.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceRequestHandler.java index 67899849def..3b3e3ce7eea 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceRequestHandler.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceRequestHandler.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.yahoo.component.annotation.Inject; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.ThreadedHttpRequestHandler; import com.yahoo.jrt.slobrok.api.Mirror; import com.yahoo.restapi.RestApi; @@ -27,6 +28,7 @@ import com.yahoo.vespa.orchestrator.status.HostInfos; import com.yahoo.vespa.orchestrator.status.StatusService; import com.yahoo.vespa.service.manager.MonitorManager; import com.yahoo.vespa.service.manager.UnionMonitorManager; +import com.yahoo.vespa.service.model.ApplicationInstanceGenerator; import com.yahoo.vespa.service.monitor.ServiceMonitor; import com.yahoo.vespa.service.monitor.SlobrokApi; @@ -54,18 +56,21 @@ public class InstanceRequestHandler extends RestApiRequestHandler getAllInstances(RestApi.RequestContext context) { - return serviceMonitor.getAllApplicationInstanceReferences().stream().sorted().toList(); + private List getAllInstances(RestApi.RequestContext context) { + return serviceMonitor.getAllApplicationInstanceReferences().stream() + .map(OrchestratorUtil::toApplicationId) + .sorted() + .toList(); } private InstanceStatusResponse getInstance(RestApi.RequestContext context) { String instanceIdString = context.pathParameters().getStringOrThrow("instanceId"); - ApplicationInstanceReference instanceId = parseInstanceId(instanceIdString); + ApplicationInstanceReference instanceId = getApplicationInstanceReference(instanceIdString); ApplicationInstance applicationInstance = serviceMonitor.getApplication(OrchestratorUtil.toApplicationId(instanceId)) @@ -113,6 +121,19 @@ public class InstanceRequestHandler extends RestApiRequestHandler getSlobrokEntries(RestApi.RequestContext context) { String instanceId = context.pathParameters().getStringOrThrow("instanceId"); String pattern = context.queryParameters().getString("pattern").orElse(null); - ApplicationInstanceReference reference = parseInstanceId(instanceId); + ApplicationInstanceReference reference = getApplicationInstanceReference(instanceId); ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference); if (pattern == null) { @@ -140,7 +161,7 @@ public class InstanceRequestHandler extends RestApiRequestHandler ENTRIES = Arrays.asList( new Mirror.Entry("name1", "tcp/spec:1"), new Mirror.Entry("name2", "tcp/spec:2")); private static final ClusterId CLUSTER_ID = new ClusterId("cluster-id"); + private static final Zone zone = Zone.defaultZone(); private final SlobrokApi slobrokApi = mock(SlobrokApi.class); private final UnionMonitorManager rootManager = mock(UnionMonitorManager.class); private final RestApiTestDriver testDriver = - RestApiTestDriver.newBuilder(ctx -> new InstanceRequestHandler(ctx, null, null, slobrokApi, rootManager)) + RestApiTestDriver.newBuilder(ctx -> new InstanceRequestHandler(ctx, null, null, slobrokApi, rootManager, zone)) .build(); @Test @@ -55,16 +61,16 @@ class InstanceRequestHandlerTest { testGetSlobrokEntriesWith(null, InstanceRequestHandler.DEFAULT_SLOBROK_PATTERN); } - @Test - void testGetServiceStatusInfo() { + @ParameterizedTest + @ValueSource(strings = { APPLICATION_INSTANCE_REFERENCE, APPLICATION_INSTANCE_REFERENCE_LONG }) + void testGetServiceStatusInfo(String reference) { ServiceType serviceType = new ServiceType("serviceType"); ConfigId configId = new ConfigId("configId"); ServiceStatus serviceStatus = ServiceStatus.UP; when(rootManager.getStatus(APPLICATION_ID, CLUSTER_ID, serviceType, configId)) .thenReturn(new ServiceStatusInfo(serviceStatus)); - - String uriPath = String.format("/orchestrator/v1/instances/%s/serviceStatusInfo", APPLICATION_INSTANCE_REFERENCE); + String uriPath = String.format("/orchestrator/v1/instances/%s/serviceStatusInfo", reference); HttpRequest request = HttpRequestBuilder.create(GET, uriPath) .withQueryParameter("clusterId", CLUSTER_ID.s()) .withQueryParameter("serviceType", serviceType.s()) @@ -79,9 +85,10 @@ class InstanceRequestHandlerTest { assertEquals(serviceStatus, actualServiceStatus); } - @Test - void testBadRequest() { - String uriPath = String.format("/orchestrator/v1/instances/%s/serviceStatusInfo", APPLICATION_INSTANCE_REFERENCE); + @ParameterizedTest + @ValueSource(strings = { APPLICATION_INSTANCE_REFERENCE, APPLICATION_INSTANCE_REFERENCE_LONG }) + void testBadRequest(String reference) { + String uriPath = String.format("/orchestrator/v1/instances/%s/serviceStatusInfo", reference); HttpRequest request = HttpRequestBuilder.create(GET, uriPath) .withQueryParameter("clusterId", CLUSTER_ID.s()) .build(); @@ -89,12 +96,11 @@ class InstanceRequestHandlerTest { assertEquals(400, response.getStatus()); } - private void testGetSlobrokEntriesWith(String pattern, String expectedLookupPattern) - throws Exception{ + private void testGetSlobrokEntriesWith(String pattern, String expectedLookupPattern) throws Exception { when(slobrokApi.lookup(APPLICATION_ID, expectedLookupPattern)) .thenReturn(ENTRIES); - String uriPath = String.format("/orchestrator/v1/instances/%s/slobrok", APPLICATION_INSTANCE_REFERENCE); + String uriPath = String.format("/orchestrator/v1/instances/%s/slobrok", APPLICATION_INSTANCE_REFERENCE_LONG); var builder = HttpRequestBuilder.create(GET, uriPath); if (pattern != null) { builder.withQueryParameter("pattern", pattern); -- cgit v1.2.3