aboutsummaryrefslogtreecommitdiffstats
path: root/serviceview
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /serviceview
Publish
Diffstat (limited to 'serviceview')
-rw-r--r--serviceview/OWNERS1
-rw-r--r--serviceview/pom.xml39
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ApplicationView.java13
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ClusterView.java20
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java25
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HealthClient.java23
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HostService.java19
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ModelResponse.java17
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/Service.java23
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServicePort.java43
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServiceView.java20
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java39
-rw-r--r--serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/package-info.java11
-rw-r--r--serviceview/src/test/java/com/yahoo/vespa/serviceview/bindings/ServicePortTest.java78
14 files changed, 371 insertions, 0 deletions
diff --git a/serviceview/OWNERS b/serviceview/OWNERS
new file mode 100644
index 00000000000..e0a00db5f4f
--- /dev/null
+++ b/serviceview/OWNERS
@@ -0,0 +1 @@
+musum
diff --git a/serviceview/pom.xml b/serviceview/pom.xml
new file mode 100644
index 00000000000..bdca519f2b6
--- /dev/null
+++ b/serviceview/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>parent</artifactId>
+ <version>6-SNAPSHOT</version>
+ <relativePath>../parent/pom.xml</relativePath>
+ </parent>
+ <artifactId>serviceview</artifactId>
+ <packaging>container-plugin</packaging>
+ <version>6-SNAPSHOT</version>
+ <name>serviceview</name>
+ <description>REST API that is shared between the Vespa Config Server and others.</description>
+ <dependencies>
+ <dependency>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>container-dev</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.yahoo.vespa</groupId>
+ <artifactId>bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ApplicationView.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ApplicationView.java
new file mode 100644
index 00000000000..6edb36c5e0d
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ApplicationView.java
@@ -0,0 +1,13 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+/**
+ * All clusters of a deployed application.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class ApplicationView {
+ public List<ClusterView> clusters;
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ClusterView.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ClusterView.java
new file mode 100644
index 00000000000..4122e9f1bd8
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ClusterView.java
@@ -0,0 +1,20 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+/**
+ * The response binding for a complete cluster.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class ClusterView {
+ public String name;
+ public String type;
+ @JsonInclude(value = Include.NON_NULL)
+ public String url;
+ public List<ServiceView> services;
+} \ No newline at end of file
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java
new file mode 100644
index 00000000000..9fbdf385b83
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java
@@ -0,0 +1,25 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+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.MediaType;
+
+/**
+ * Client to fetch the model config from the configserver.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public interface ConfigClient {
+
+ @GET
+ @Path("/config/v2/tenant/{tenantName}/application/{applicationName}/environment/{environmentName}/region/{regionName}/instance/{instanceName}/cloud.config.model")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ModelResponse getServiceModel(@PathParam("tenantName") String tenantName,
+ @PathParam("applicationName") String applicationName,
+ @PathParam("environmentName") String environmentName,
+ @PathParam("regionName") String regionName,
+ @PathParam("instanceName") String instanceName);
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HealthClient.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HealthClient.java
new file mode 100644
index 00000000000..a27081cbdc1
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HealthClient.java
@@ -0,0 +1,23 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.HashMap;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Client to fetch the model config from the configserver.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public interface HealthClient {
+
+ @SuppressWarnings("rawtypes")
+ @GET
+ @Path("")
+ @Produces(MediaType.APPLICATION_JSON)
+ public HashMap getHealthInfo();
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HostService.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HostService.java
new file mode 100644
index 00000000000..0651cf0ac8d
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HostService.java
@@ -0,0 +1,19 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * View of {@link com.yahoo.cloud.config.ModelConfig.Hosts}.
+ *
+ * @author mortent
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class HostService {
+
+ public String name;
+ public List<Service> services;
+
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ModelResponse.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ModelResponse.java
new file mode 100644
index 00000000000..4a0a4696fd4
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ModelResponse.java
@@ -0,0 +1,17 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * View of {@link com.yahoo.cloud.config.ModelConfig}.
+ *
+ * @author mortent
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ModelResponse {
+ public List<HostService> hosts;
+ public String vespaVersion;
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/Service.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/Service.java
new file mode 100644
index 00000000000..b6d0239b114
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/Service.java
@@ -0,0 +1,23 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * View of {@link com.yahoo.cloud.config.ModelConfig.Hosts.Services}.
+ *
+ * @author mortent
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Service {
+ public String name;
+ public String type;
+ public String configid;
+ public String clustertype;
+ public String clustername;
+ public long index;
+ public List<ServicePort> ports;
+
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServicePort.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServicePort.java
new file mode 100644
index 00000000000..7172fa98add
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServicePort.java
@@ -0,0 +1,43 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.google.common.base.Splitter;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+/**
+ * View of {@link com.yahoo.cloud.config.ModelConfig.Hosts.Services.Ports}.
+ *
+ * @author mortent
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+@JsonIgnoreProperties(value = { "splitOnSpace" }, ignoreUnknown = true)
+public class ServicePort {
+ public int number;
+ public String tags;
+ private static final Splitter splitOnSpace = Splitter.on(' ');
+
+ /**
+ * Return true if all argument tags are present for this port.
+ *
+ * @param tag
+ * one or more tag names to check for
+ * @return true if all argument tags are present for this port, false
+ * otherwise
+ */
+ public boolean hasTags(@NonNull String... tag) {
+ if (tags == null) {
+ return false;
+ }
+ List<String> isTaggedWith = splitOnSpace.splitToList(tags);
+ for (String t : tag) {
+ if (!isTaggedWith.contains(t)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServiceView.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServiceView.java
new file mode 100644
index 00000000000..f0d47d2e335
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServiceView.java
@@ -0,0 +1,20 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+/**
+ * The response wrapper for the link to a single service state API.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class ServiceView {
+ public String url;
+ public String serviceType;
+ public String serviceName;
+ public String configId;
+ public String host;
+ @JsonInclude(value = Include.NON_NULL)
+ public String legacyStatusPages;
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java
new file mode 100644
index 00000000000..8f8effff0ba
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java
@@ -0,0 +1,39 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import java.util.HashMap;
+
+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.MediaType;
+
+public interface StateClient {
+
+ @GET
+ @Path("v1/")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApplicationView getDefaultUserInfo();
+
+ @GET
+ @Path("v1/tenant/{tenantName}/application/{applicationName}/environment/{environmentName}/region/{regionName}/instance/{instanceName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public ApplicationView getUserInfo(@PathParam("tenantName") String tenantName,
+ @PathParam("applicationName") String applicationName,
+ @PathParam("environmentName") String environmentName,
+ @PathParam("regionName") String regionName,
+ @PathParam("instanceName") String instanceName);
+
+ @SuppressWarnings("rawtypes")
+ @GET
+ @Path("v1/tenant/{tenantName}/application/{applicationName}/environment/{environmentName}/region/{regionName}/instance/{instanceName}/service/{serviceIdentifier}/{apiParams: .*}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public HashMap singleService(@PathParam("tenantName") String tenantName,
+ @PathParam("applicationName") String applicationName,
+ @PathParam("environmentName") String environmentName,
+ @PathParam("regionName") String regionName,
+ @PathParam("instanceName") String instanceName,
+ @PathParam("serviceIdentifier") String identifier,
+ @PathParam("apiParams") String apiParams);
+}
diff --git a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/package-info.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/package-info.java
new file mode 100644
index 00000000000..73e025f5532
--- /dev/null
+++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/package-info.java
@@ -0,0 +1,11 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+/**
+ * The API bindings for the serviceview and underlying state APIs.
+ *
+ * <p>Do note this package is in its prototyping stage and classes <i>will</i>
+ * be renamed and moved around a little.</p>
+ */
+@ExportPackage
+package com.yahoo.vespa.serviceview.bindings;
+
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/serviceview/src/test/java/com/yahoo/vespa/serviceview/bindings/ServicePortTest.java b/serviceview/src/test/java/com/yahoo/vespa/serviceview/bindings/ServicePortTest.java
new file mode 100644
index 00000000000..6044d3dc498
--- /dev/null
+++ b/serviceview/src/test/java/com/yahoo/vespa/serviceview/bindings/ServicePortTest.java
@@ -0,0 +1,78 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.serviceview.bindings;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * Functional test of tag checking.
+ *
+ * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ */
+public class ServicePortTest {
+
+ @Test
+ public final void testNullTags() {
+ ServicePort s = new ServicePort();
+ s.tags = null;
+ assertFalse(s.hasTags("http"));
+ }
+
+ @Test
+ public final void testEmptyTags() {
+ ServicePort s = new ServicePort();
+ s.tags = "";
+ assertFalse(s.hasTags("http"));
+ }
+
+ @Test
+ public final void testSubsetInArgs() {
+ ServicePort s = new ServicePort();
+ s.tags = "http state status";
+ assertTrue(s.hasTags("http", "state"));
+ }
+
+ @Test
+ public final void testSupersetInArgs() {
+ ServicePort s = new ServicePort();
+ s.tags = "http";
+ assertFalse(s.hasTags("http", "rpc"));
+ }
+
+ @Test
+ public final void testIdenticalInArgs() {
+ ServicePort s = new ServicePort();
+ s.tags = "http rpc";
+ assertTrue(s.hasTags("http", "rpc"));
+ }
+
+ @Test
+ public final void testDisjunctBetweenArgsAndTags() {
+ ServicePort s = new ServicePort();
+ s.tags = "http state moo";
+ assertFalse(s.hasTags("http", "state", "rpc"));
+ }
+
+ @Test
+ public final void testTagNameStartsWithOther() {
+ ServicePort s = new ServicePort();
+ s.tags = "http state moo";
+ assertFalse(s.hasTags("htt"));
+ }
+
+ @Test
+ public final void testTagNameEndsWithOther() {
+ ServicePort s = new ServicePort();
+ s.tags = "http state moo";
+ assertFalse(s.hasTags("tp"));
+ }
+
+ @Test
+ public final void testTagNameIsSubstringofOther() {
+ ServicePort s = new ServicePort();
+ s.tags = "http state moo";
+ assertFalse(s.hasTags("tt"));
+ }
+
+}