diff options
author | Martin Polden <mpolden@mpolden.no> | 2018-03-06 09:55:10 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2018-03-06 09:55:10 +0100 |
commit | 740ac77765fc90ad412b2acfea45dafd824581d6 (patch) | |
tree | b539497566fbc6765d70dd94f40d54fee0c64b4f | |
parent | 1081ee11b211b66a54a5983f7e5057e14190815d (diff) |
Cleanup
6 files changed, 85 insertions, 90 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/serviceview/StateResource.java b/configserver/src/main/java/com/yahoo/vespa/serviceview/StateResource.java index cd7559e775a..d1e9ed93679 100644 --- a/configserver/src/main/java/com/yahoo/vespa/serviceview/StateResource.java +++ b/configserver/src/main/java/com/yahoo/vespa/serviceview/StateResource.java @@ -1,12 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.serviceview; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; +import com.yahoo.container.jaxrs.annotation.Component; +import com.yahoo.vespa.serviceview.bindings.ApplicationView; +import com.yahoo.vespa.serviceview.bindings.ConfigClient; +import com.yahoo.vespa.serviceview.bindings.HealthClient; +import com.yahoo.vespa.serviceview.bindings.ModelResponse; +import com.yahoo.vespa.serviceview.bindings.StateClient; +import org.glassfish.jersey.client.proxy.WebResourceFactory; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -18,15 +19,12 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; - -import com.yahoo.container.jaxrs.annotation.Component; -import com.yahoo.vespa.serviceview.bindings.ApplicationView; -import com.yahoo.vespa.serviceview.bindings.ConfigClient; -import com.yahoo.vespa.serviceview.bindings.HealthClient; -import com.yahoo.vespa.serviceview.bindings.ModelResponse; -import com.yahoo.vespa.serviceview.bindings.StateClient; - -import org.glassfish.jersey.client.proxy.WebResourceFactory; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; /** @@ -38,6 +36,7 @@ import org.glassfish.jersey.client.proxy.WebResourceFactory; public class StateResource implements StateClient { private static final String SINGLE_API_LINK = "url"; + private final int restApiPort; private final String host; private final UriInfo uriInfo; @@ -55,7 +54,7 @@ public class StateResource implements StateClient { public StateResource(@Component ConfigServerLocation configServer, @Context UriInfo ui) { this.restApiPort = configServer.restApiPort; - host = "localhost"; + this.host = "localhost"; this.uriInfo = ui; } @@ -87,7 +86,7 @@ public class StateResource implements StateClient { @Produces(MediaType.TEXT_HTML) public interface HtmlProxyHack { @GET - public String proxy(); + String proxy(); } @GET @@ -113,9 +112,7 @@ public class StateResource implements StateClient { HtmlProxyHack resource = WebResourceFactory.newResource(HtmlProxyHack.class, target); return resource.proxy(); } finally { - if (client != null) { - client.close(); - } + client.close(); } } @@ -132,14 +129,10 @@ public class StateResource implements StateClient { Client client = ClientBuilder.newClient(); try { WebTarget target = client.target("http://" + host + ":" + restApiPort + "/"); - ConfigClient resource = WebResourceFactory.newResource(ConfigClient.class, target); - return resource.getServiceModel(tenant, application, environment, region, instance); } finally { - if (client != null) { - client.close(); - } + client.close(); } } @@ -165,9 +158,7 @@ public class StateResource implements StateClient { rewriteResourceLinks(apiResult, model, s, applicationIdentifier(tenantName, applicationName, environmentName, regionName, instanceName), identifier); return apiResult; } finally { - if (client != null) { - client.close(); - } + client.close(); } } @@ -180,8 +171,11 @@ public class StateResource implements StateClient { } private String applicationIdentifier(String tenant, String application, String environment, String region, String instance) { - return new StringBuilder("tenant/").append(tenant).append("/application/").append(application).append("/environment/") - .append(environment).append("/region/").append(region).append("/instance/").append(instance).toString(); + return "tenant/" + tenant + + "/application/" + application + + "/environment/" + environment + + "/region/" + region + + "/instance/" + instance; } private void rewriteResourceLinks(Object apiResult, diff --git a/configserver/src/test/java/com/yahoo/vespa/serviceview/ServiceModelTest.java b/configserver/src/test/java/com/yahoo/vespa/serviceview/ServiceModelTest.java index 6371ee25a8c..c7b08c08387 100644 --- a/configserver/src/test/java/com/yahoo/vespa/serviceview/ServiceModelTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/serviceview/ServiceModelTest.java @@ -1,32 +1,33 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.serviceview; -import static org.junit.Assert.*; - -import java.util.Arrays; - import com.yahoo.vespa.defaults.Defaults; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - import com.yahoo.vespa.serviceview.bindings.ApplicationView; import com.yahoo.vespa.serviceview.bindings.HostService; import com.yahoo.vespa.serviceview.bindings.ModelResponse; import com.yahoo.vespa.serviceview.bindings.ServicePort; import com.yahoo.vespa.serviceview.bindings.ServiceView; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; /** * Functional tests for the programmatic view of cloud.config.model. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class ServiceModelTest { - ServiceModel model; + private ServiceModel model; @Before - public void setUp() throws Exception { + public void setUp() { ModelResponse model = syntheticModelResponse(); this.model = new ServiceModel(model); } @@ -46,7 +47,7 @@ public class ServiceModelTest { ServicePort port = new ServicePort(); port.number = Defaults.getDefaults().vespaWebServicePort(); port.tags = "state http"; - service0.ports = Arrays.asList(new ServicePort[] { port }); + service0.ports = Collections.singletonList(port); } com.yahoo.vespa.serviceview.bindings.Service service1 = new com.yahoo.vespa.serviceview.bindings.Service(); { @@ -59,7 +60,7 @@ public class ServiceModelTest { ServicePort port = new ServicePort(); port.number = 4090; port.tags = "state http"; - service1.ports = Arrays.asList(new ServicePort[] { port }); + service1.ports = Collections.singletonList(port); } com.yahoo.vespa.serviceview.bindings.Service service2 = new com.yahoo.vespa.serviceview.bindings.Service(); { @@ -72,15 +73,15 @@ public class ServiceModelTest { ServicePort port = new ServicePort(); port.number = 5000; port.tags = "state http"; - service2.ports = Arrays.asList(new ServicePort[] { port }); + service2.ports = Collections.singletonList(port); } - h.services = Arrays.asList(new com.yahoo.vespa.serviceview.bindings.Service[] { service0, service1, service2 }); - model.hosts = Arrays.asList(new HostService[] { h }); + h.services = Arrays.asList(service0, service1, service2); + model.hosts = Collections.singletonList(h); return model; } @After - public void tearDown() throws Exception { + public void tearDown() { model = null; } diff --git a/configserver/src/test/java/com/yahoo/vespa/serviceview/StateResourceTest.java b/configserver/src/test/java/com/yahoo/vespa/serviceview/StateResourceTest.java index 5e4cdd1a6c9..794b825db6e 100644 --- a/configserver/src/test/java/com/yahoo/vespa/serviceview/StateResourceTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/serviceview/StateResourceTest.java @@ -1,33 +1,31 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.serviceview; -import static org.junit.Assert.*; +import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.container.jaxrs.annotation.Component; +import com.yahoo.vespa.serviceview.bindings.ApplicationView; +import com.yahoo.vespa.serviceview.bindings.HealthClient; +import com.yahoo.vespa.serviceview.bindings.ModelResponse; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import javax.ws.rs.client.Client; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; import java.net.URI; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.ws.rs.client.Client; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.UriInfo; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.container.jaxrs.annotation.Component; -import com.yahoo.vespa.serviceview.bindings.ApplicationView; -import com.yahoo.vespa.serviceview.bindings.HealthClient; -import com.yahoo.vespa.serviceview.bindings.ModelResponse; +import static org.junit.Assert.assertEquals; /** * Functional test for {@link StateResource}. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class StateResourceTest { @@ -51,14 +49,14 @@ public class StateResourceTest { HashMap<Object, Object> dummyHealthData = new HashMap<>(); HashMap<String, String> dummyLink = new HashMap<>(); dummyLink.put("url", BASE_URI); - dummyHealthData.put("resources", Arrays.asList(dummyLink)); + dummyHealthData.put("resources", Collections.singletonList(dummyLink)); Mockito.when(healthClient.getHealthInfo()).thenReturn(dummyHealthData); return healthClient; } } - StateResource testResource; - ServiceModel correspondingModel; + private StateResource testResource; + private ServiceModel correspondingModel; @Before public void setUp() throws Exception { @@ -70,7 +68,7 @@ public class StateResourceTest { } @After - public void tearDown() throws Exception { + public void tearDown() { testResource = null; correspondingModel = null; } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/Authorizer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/Authorizer.java index 9541364a5e8..ec49560ebd9 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/Authorizer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/Authorizer.java @@ -167,7 +167,7 @@ public class Authorizer implements BiPredicate<Principal, URI> { path = path.substring(0, path.length() - 1); } int lastSeparator = path.lastIndexOf("/"); - if (lastSeparator == - 1) { + if (lastSeparator == -1) { return path; } return path.substring(lastSeparator + 1, path.length()); 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 index b31afcd4df1..bc40586b473 100644 --- a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java +++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/ConfigClient.java @@ -10,16 +10,16 @@ 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> + * @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); + 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/StateClient.java b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java index fcb5058920a..5e5ee023d84 100644 --- a/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java +++ b/serviceview/src/main/java/com/yahoo/vespa/serviceview/bindings/StateClient.java @@ -1,39 +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.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; +import java.util.HashMap; +/** + * @author Steinar Knutsen + */ public interface StateClient { @GET @Path("v1/") @Produces(MediaType.APPLICATION_JSON) - public ApplicationView getDefaultUserInfo(); + 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); + 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); + 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); } |