summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2017-10-27 16:30:47 +0200
committerGitHub <noreply@github.com>2017-10-27 16:30:47 +0200
commit85cf841e3f599130e11d6f283e23708c6741cb57 (patch)
tree4bd9af33ae2cadd58792a975e6ddc712940fff4c
parent2a8303d4a44321d54f86e03ce22264eeac6b644b (diff)
parent9f9d1fe8d282040acbdfe81520c01b836f932543 (diff)
Merge pull request #3930 from vespa-engine/hakonhall/rest-api-for-service-status
REST API for service status
-rw-r--r--orchestrator-restapi/src/main/java/com/yahoo/vespa/orchestrator/restapi/wire/SlobrokEntryResponse.java41
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java49
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/SlobrokEntryResponse.java22
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/InstanceResourceTest.java62
4 files changed, 132 insertions, 42 deletions
diff --git a/orchestrator-restapi/src/main/java/com/yahoo/vespa/orchestrator/restapi/wire/SlobrokEntryResponse.java b/orchestrator-restapi/src/main/java/com/yahoo/vespa/orchestrator/restapi/wire/SlobrokEntryResponse.java
new file mode 100644
index 00000000000..5efdd2581a9
--- /dev/null
+++ b/orchestrator-restapi/src/main/java/com/yahoo/vespa/orchestrator/restapi/wire/SlobrokEntryResponse.java
@@ -0,0 +1,41 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.orchestrator.restapi.wire;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Objects;
+
+public class SlobrokEntryResponse {
+ @JsonProperty("name")
+ public final String name;
+
+ @JsonProperty("spec")
+ public final String spec;
+
+ public SlobrokEntryResponse(String name, String spec) {
+ this.name = name;
+ this.spec = spec;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ SlobrokEntryResponse that = (SlobrokEntryResponse) o;
+ return Objects.equals(name, that.name) &&
+ Objects.equals(spec, that.spec);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, spec);
+ }
+
+ @Override
+ public String toString() {
+ return "SlobrokEntryResponse{" +
+ "name='" + name + '\'' +
+ ", spec='" + spec + '\'' +
+ '}';
+ }
+}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java
index 4b24c17381e..c16256df73d 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java
@@ -6,9 +6,13 @@ import com.yahoo.container.jaxrs.annotation.Component;
import com.yahoo.jrt.slobrok.api.Mirror;
import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
+import com.yahoo.vespa.applicationmodel.ConfigId;
import com.yahoo.vespa.applicationmodel.HostName;
+import com.yahoo.vespa.applicationmodel.ServiceStatus;
+import com.yahoo.vespa.applicationmodel.ServiceType;
import com.yahoo.vespa.orchestrator.InstanceLookupService;
import com.yahoo.vespa.orchestrator.OrchestratorUtil;
+import com.yahoo.vespa.orchestrator.restapi.wire.SlobrokEntryResponse;
import com.yahoo.vespa.orchestrator.status.HostStatus;
import com.yahoo.vespa.orchestrator.status.StatusService;
import com.yahoo.vespa.service.monitor.SlobrokMonitorManager;
@@ -41,6 +45,8 @@ import static com.yahoo.vespa.orchestrator.OrchestratorUtil.parseAppInstanceRefe
@Path("/v1/instances")
public class InstanceResource {
+ public static final String DEFAULT_SLOBROK_PATTERN = "**";
+
private final StatusService statusService;
private final SlobrokMonitorManager slobrokMonitorManager;
private final InstanceLookupService instanceLookupService;
@@ -87,21 +93,50 @@ public class InstanceResource {
ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference);
if (pattern == null) {
- pattern = "**";
+ pattern = DEFAULT_SLOBROK_PATTERN;
}
List<Mirror.Entry> entries = slobrokMonitorManager.lookup(applicationId, pattern);
- return entries.stream().map(SlobrokEntryResponse::fromMirrorEntry)
+ return entries.stream()
+ .map(entry -> new SlobrokEntryResponse(entry.getName(), entry.getSpec()))
.collect(Collectors.toList());
}
- private ApplicationInstanceReference parseInstanceId(@PathParam("instanceId") String instanceIdString) {
- ApplicationInstanceReference instanceId;
+ @GET
+ @Path("/{instanceId}/serviceStatus")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ServiceStatus getServiceStatus(
+ @PathParam("instanceId") String instanceId,
+ @QueryParam("serviceType") String serviceTypeString,
+ @QueryParam("configId") String configIdString) {
+ ApplicationInstanceReference reference = parseInstanceId(instanceId);
+ ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference);
+
+ if (serviceTypeString == null) {
+ throwBadRequest("Missing serviceType query parameter");
+ }
+
+ if (configIdString == null) {
+ throwBadRequest("Missing configId query parameter");
+ }
+
+ ServiceType serviceType = new ServiceType(serviceTypeString);
+ ConfigId configId = new ConfigId(configIdString);
+
+ return slobrokMonitorManager.getStatus(applicationId, serviceType, configId);
+ }
+
+ static ApplicationInstanceReference parseInstanceId(String instanceIdString) {
try {
- instanceId = parseAppInstanceReference(instanceIdString);
+ return parseAppInstanceReference(instanceIdString);
} catch (IllegalArgumentException e) {
- throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
+ throwBadRequest(e.getMessage());
+ return null; // Necessary for compiler
}
- return instanceId;
+ }
+
+ static void throwBadRequest(String message) {
+ throw new WebApplicationException(
+ Response.status(Response.Status.BAD_REQUEST).entity(message).build());
}
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/SlobrokEntryResponse.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/SlobrokEntryResponse.java
deleted file mode 100644
index 685f1fa1a8a..00000000000
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/SlobrokEntryResponse.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.vespa.orchestrator.resources;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.yahoo.jrt.slobrok.api.Mirror;
-
-public class SlobrokEntryResponse {
- @JsonProperty("name")
- public final String name;
-
- @JsonProperty("spec")
- public final String spec;
-
- static SlobrokEntryResponse fromMirrorEntry(Mirror.Entry entry) {
- return new SlobrokEntryResponse(entry.getName(), entry.getSpec());
- }
-
- private SlobrokEntryResponse(String name, String spec) {
- this.name = name;
- this.spec = spec;
- }
-}
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/InstanceResourceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/InstanceResourceTest.java
index 1d9ec2bccd1..42b5b70ab55 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/InstanceResourceTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/InstanceResourceTest.java
@@ -4,9 +4,14 @@ package com.yahoo.vespa.orchestrator.resources;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.jrt.slobrok.api.Mirror;
+import com.yahoo.vespa.applicationmodel.ConfigId;
+import com.yahoo.vespa.applicationmodel.ServiceStatus;
+import com.yahoo.vespa.applicationmodel.ServiceType;
+import com.yahoo.vespa.orchestrator.restapi.wire.SlobrokEntryResponse;
import com.yahoo.vespa.service.monitor.SlobrokMonitorManager;
import org.junit.Test;
+import javax.ws.rs.WebApplicationException;
import java.util.Arrays;
import java.util.List;
@@ -16,28 +21,59 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class InstanceResourceTest {
+ private static final String APPLICATION_INSTANCE_REFERENCE = "tenant:app:prod:us-west-1:instance";
+ private static final ApplicationId APPLICATION_ID = ApplicationId.from(
+ "tenant", "app", "instance");
+ private static final List<Mirror.Entry> ENTRIES = Arrays.asList(
+ new Mirror.Entry("name1", "spec1"),
+ new Mirror.Entry("name2", "spec2"));
+
+ private final SlobrokMonitorManager slobrokMonitorManager = mock(SlobrokMonitorManager.class);
+ private final InstanceResource resource = new InstanceResource(
+ null,
+ null,
+ slobrokMonitorManager);
+
@Test
public void testGetSlobrokEntries() throws Exception {
- SlobrokMonitorManager slobrokMonitorManager = mock(SlobrokMonitorManager.class);
- InstanceResource resource = new InstanceResource(
- null,
- null,
- slobrokMonitorManager);
+ testGetSlobrokEntriesWith("foo", "foo");
+ }
- ApplicationId applicationId = ApplicationId.from("tenant", "app", "instance");
- String pattern = "foo";
+ @Test
+ public void testGetSlobrokEntriesWithoutPattern() throws Exception {
+ testGetSlobrokEntriesWith(null, InstanceResource.DEFAULT_SLOBROK_PATTERN);
+ }
- List<Mirror.Entry> entries = Arrays.asList(
- new Mirror.Entry("name1", "spec1"),
- new Mirror.Entry("name2", "spec2"));
+ @Test
+ public void testGetServiceStatus() {
+ ServiceType serviceType = new ServiceType("serviceType");
+ ConfigId configId = new ConfigId("configId");
+ ServiceStatus serviceStatus = ServiceStatus.UP;
+ when(slobrokMonitorManager.getStatus(APPLICATION_ID, serviceType, configId))
+ .thenReturn(serviceStatus);
+ ServiceStatus actualServiceStatus = resource.getServiceStatus(
+ APPLICATION_INSTANCE_REFERENCE,
+ serviceType.s(),
+ configId.s());
+ verify(slobrokMonitorManager).getStatus(APPLICATION_ID, serviceType, configId);
+ assertEquals(serviceStatus, actualServiceStatus);
+ }
+
+ @Test(expected = WebApplicationException.class)
+ public void testBadRequest() {
+ resource.getServiceStatus(APPLICATION_INSTANCE_REFERENCE, null, null);
+ }
- when(slobrokMonitorManager.lookup(applicationId, pattern)).thenReturn(entries);
+ private void testGetSlobrokEntriesWith(String pattern, String expectedLookupPattern)
+ throws Exception{
+ when(slobrokMonitorManager.lookup(APPLICATION_ID, expectedLookupPattern))
+ .thenReturn(ENTRIES);
List<SlobrokEntryResponse> response = resource.getSlobrokEntries(
- "tenant:app:prod:us-west-1:instance",
+ APPLICATION_INSTANCE_REFERENCE,
pattern);
- verify(slobrokMonitorManager).lookup(applicationId, pattern);
+ verify(slobrokMonitorManager).lookup(APPLICATION_ID, expectedLookupPattern);
ObjectMapper mapper = new ObjectMapper();
String actualJson = mapper.writeValueAsString(response);