summaryrefslogtreecommitdiffstats
path: root/orchestrator
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2019-01-31 14:32:38 +0100
committerHåkon Hallingstad <hakon@verizonmedia.com>2019-01-31 14:32:38 +0100
commit166b1d959dbea3f3dec5ad26ad60c1c59e2bea85 (patch)
tree3a62c132a78b46f7054845bb13d100750087f18e /orchestrator
parent2f05c797b69f0a261a347d769301a856a117170b (diff)
Health rest API
Makes a new REST API /orchestrator/v1/health/<ApplicationId> that shows the list of services that are monitored for health. This information is currently a bit difficult to infer from /orchestrator/v1/instances/<ApplicationInstanceReference> since it is the combined view of health and Slobrok. There are already APIs for Slobrok. Example content: $ curl -s localhost:19071/orchestrator/v1/health/hosted-vespa:zone-config-serve\ rs:default|jq . { "services": [ { "clusterId": "zone-config-servers", "serviceType": "configserver", "configId": "zone-config-servers/cfg6", "status": { "serviceStatus": "UP", "lastChecked": 1548939111.708718, "since": 1548939051.686223, "endpoint": "http://cfg4.prod.cd-us-central-1.vespahosted.ne1.yahoo.com:19071/state/v1/health" } }, ... ] } This view is slightly different from the application model view, just because that's exactly how the health monitoring is structured (individual monitors against endpoints). The "endpoint" information will also be added to /instances if the status comes from health and not Slobrok.
Diffstat (limited to 'orchestrator')
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ApplicationServices.java16
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/HealthResource.java84
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ServiceResource.java25
3 files changed, 125 insertions, 0 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ApplicationServices.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ApplicationServices.java
new file mode 100644
index 00000000000..0601291d853
--- /dev/null
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ApplicationServices.java
@@ -0,0 +1,16 @@
+// Copyright 2019 Oath Inc. 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.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+/**
+ * @author hakonhall
+ */
+@JsonInclude(value = JsonInclude.Include.NON_NULL)
+public class ApplicationServices {
+ @JsonProperty("services")
+ public List<ServiceResource> services;
+}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/HealthResource.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/HealthResource.java
new file mode 100644
index 00000000000..47f2f063540
--- /dev/null
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/HealthResource.java
@@ -0,0 +1,84 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.orchestrator.resources;
+
+import com.google.inject.Inject;
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.container.jaxrs.annotation.Component;
+import com.yahoo.vespa.applicationmodel.ServiceStatusInfo;
+import com.yahoo.vespa.orchestrator.restapi.wire.ApplicationReferenceList;
+import com.yahoo.vespa.orchestrator.restapi.wire.UrlReference;
+import com.yahoo.vespa.service.manager.HealthMonitorApi;
+import com.yahoo.vespa.service.monitor.ServiceId;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author hakonhall
+ */
+@Path("/v1/health")
+public class HealthResource {
+ private final UriInfo uriInfo;
+ private final HealthMonitorApi healthMonitorApi;
+
+ @Inject
+ public HealthResource(@Context UriInfo uriInfo, @Component HealthMonitorApi healthMonitorApi) {
+ this.uriInfo = uriInfo;
+ this.healthMonitorApi = healthMonitorApi;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApplicationReferenceList getAllInstances() {
+ List<ApplicationId> applications = new ArrayList<>(healthMonitorApi.getMonitoredApplicationIds());
+ applications.sort(Comparator.comparing(ApplicationId::serializedForm));
+
+ ApplicationReferenceList list = new ApplicationReferenceList();
+ list.applicationList = applications.stream().map(applicationId -> {
+ UrlReference reference = new UrlReference();
+ reference.url = uriInfo.getBaseUriBuilder()
+ .path(HealthResource.class)
+ .path(applicationId.serializedForm())
+ .build()
+ .toString();
+ return reference;
+ }).collect(Collectors.toList());
+
+ return list;
+ }
+
+ @GET
+ @Path("/{applicationId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApplicationServices getInstance(@PathParam("applicationId") String applicationIdString) {
+ ApplicationId applicationId = ApplicationId.fromSerializedForm(applicationIdString);
+
+ Map<ServiceId, ServiceStatusInfo> services = healthMonitorApi.getServices(applicationId);
+
+ List<ServiceResource> serviceResources = services.entrySet().stream().map(entry -> {
+ ServiceResource serviceResource = new ServiceResource();
+ serviceResource.clusterId = entry.getKey().getClusterId();
+ serviceResource.serviceType = entry.getKey().getServiceType();
+ serviceResource.configId = entry.getKey().getConfigId();
+ serviceResource.serviceStatusInfo = entry.getValue();
+ return serviceResource;
+ })
+ .sorted(Comparator.comparing(resource -> resource.serviceType.s()))
+ .collect(Collectors.toList());
+
+ ApplicationServices applicationServices = new ApplicationServices();
+ applicationServices.services = serviceResources;
+ return applicationServices;
+ }
+
+}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ServiceResource.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ServiceResource.java
new file mode 100644
index 00000000000..7823f3ca6cd
--- /dev/null
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/ServiceResource.java
@@ -0,0 +1,25 @@
+// Copyright 2019 Oath Inc. 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.vespa.applicationmodel.ClusterId;
+import com.yahoo.vespa.applicationmodel.ConfigId;
+import com.yahoo.vespa.applicationmodel.ServiceStatusInfo;
+import com.yahoo.vespa.applicationmodel.ServiceType;
+
+/**
+ * @author hakonhall
+ */
+public class ServiceResource {
+ @JsonProperty("clusterId")
+ public ClusterId clusterId;
+
+ @JsonProperty("serviceType")
+ public ServiceType serviceType;
+
+ @JsonProperty("configId")
+ public ConfigId configId;
+
+ @JsonProperty("status")
+ public ServiceStatusInfo serviceStatusInfo;
+}