From 72231250ed81e10d66bfe70701e64fa5fe50f712 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 15 Jun 2016 23:09:44 +0200 Subject: Publish --- serviceview/OWNERS | 1 + serviceview/pom.xml | 39 +++++++++++ .../serviceview/bindings/ApplicationView.java | 13 ++++ .../vespa/serviceview/bindings/ClusterView.java | 20 ++++++ .../vespa/serviceview/bindings/ConfigClient.java | 25 +++++++ .../vespa/serviceview/bindings/HealthClient.java | 23 +++++++ .../vespa/serviceview/bindings/HostService.java | 19 ++++++ .../vespa/serviceview/bindings/ModelResponse.java | 17 +++++ .../yahoo/vespa/serviceview/bindings/Service.java | 23 +++++++ .../vespa/serviceview/bindings/ServicePort.java | 43 ++++++++++++ .../vespa/serviceview/bindings/ServiceView.java | 20 ++++++ .../vespa/serviceview/bindings/StateClient.java | 39 +++++++++++ .../vespa/serviceview/bindings/package-info.java | 11 +++ .../serviceview/bindings/ServicePortTest.java | 78 ++++++++++++++++++++++ 14 files changed, 371 insertions(+) create mode 100644 serviceview/OWNERS create mode 100644 serviceview/pom.xml create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ApplicationView.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ClusterView.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HealthClient.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/HostService.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ModelResponse.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/Service.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServicePort.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ServiceView.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java create mode 100644 serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/package-info.java create mode 100644 serviceview/src/test/java/com/yahoo/vespa/serviceview/bindings/ServicePortTest.java (limited to 'serviceview') 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 @@ + + + + 4.0.0 + + + com.yahoo.vespa + parent + 6-SNAPSHOT + ../parent/pom.xml + + serviceview + container-plugin + 6-SNAPSHOT + serviceview + REST API that is shared between the Vespa Config Server and others. + + + com.yahoo.vespa + container-dev + ${project.version} + provided + + + junit + junit + test + + + + + + com.yahoo.vespa + bundle-plugin + true + + + + 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 Steinar Knutsen + */ +public class ApplicationView { + public List 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 Steinar Knutsen + */ +public class ClusterView { + public String name; + public String type; + @JsonInclude(value = Include.NON_NULL) + public String url; + public List 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 Steinar Knutsen + */ +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 Steinar Knutsen + */ +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 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 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 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 Steinar Knutsen + */ +@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 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 Steinar Knutsen + */ +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. + * + *

Do note this package is in its prototyping stage and classes will + * be renamed and moved around a little.

+ */ +@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 Steinar Knutsen + */ +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")); + } + +} -- cgit v1.2.3