Repository: incubator-slider Updated Branches: refs/heads/feature/SLIDER-878-jersey-jdk8 6263573dc -> e95d516a3
SLIDER-878 move AMWebClient to using BaseRestClient for its REST operations. This drops the http/https logic Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/e95d516a Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/e95d516a Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/e95d516a Branch: refs/heads/feature/SLIDER-878-jersey-jdk8 Commit: e95d516a336ad1a09418559733cd6d8ee8f16a2e Parents: 6263573 Author: Steve Loughran <[email protected]> Authored: Thu May 21 21:57:33 2015 +0100 Committer: Steve Loughran <[email protected]> Committed: Thu May 21 21:57:33 2015 +0100 ---------------------------------------------------------------------- .../funtest/accumulo/AccumuloBasicIT.groovy | 4 +- .../org/apache/slider/client/SliderClient.java | 8 ++-- .../slider/client/rest/BaseRestClient.java | 19 ++------- .../core/registry/retrieve/AMWebClient.java | 27 ++++++++----- .../registry/retrieve/RegistryRetriever.java | 14 +++---- .../core/restclient/UgiJerseyBinding.java | 42 ++++++++++++++++---- .../TestStandaloneYarnRegistryAM.groovy | 2 +- 7 files changed, 67 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/app-packages/accumulo/src/test/groovy/org/apache/slider/funtest/accumulo/AccumuloBasicIT.groovy ---------------------------------------------------------------------- diff --git a/app-packages/accumulo/src/test/groovy/org/apache/slider/funtest/accumulo/AccumuloBasicIT.groovy b/app-packages/accumulo/src/test/groovy/org/apache/slider/funtest/accumulo/AccumuloBasicIT.groovy index f0504e4..56014d7 100644 --- a/app-packages/accumulo/src/test/groovy/org/apache/slider/funtest/accumulo/AccumuloBasicIT.groovy +++ b/app-packages/accumulo/src/test/groovy/org/apache/slider/funtest/accumulo/AccumuloBasicIT.groovy @@ -174,7 +174,9 @@ class AccumuloBasicIT extends AccumuloAgentCommandTestBase { SliderKeys.APP_TYPE, clusterName); ServiceRecord instance = sliderClient.resolve(path) - RegistryRetriever retriever = new RegistryRetriever(instance) + RegistryRetriever retriever = new RegistryRetriever( + sliderClient.config, + instance) PublishedConfiguration configuration = retriever.retrieveConfiguration( retriever.getConfigurations(true), exportName, true) return configuration http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java index 98f1344..4380173 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java @@ -3937,7 +3937,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe ServiceRecord instance = lookupServiceRecord(registryArgs); - RegistryRetriever retriever = new RegistryRetriever(instance); + RegistryRetriever retriever = new RegistryRetriever(getConfig(), instance); PublishedConfigSet configurations = retriever.getConfigurations(!registryArgs.internal); PrintStream out = null; @@ -3977,7 +3977,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe throws YarnException, IOException { ServiceRecord instance = lookupServiceRecord(registryArgs); - RegistryRetriever retriever = new RegistryRetriever(instance); + RegistryRetriever retriever = new RegistryRetriever(getConfig(), instance); PublishedExportsSet exports = retriever.getExports(!registryArgs.internal); PrintStream out = null; @@ -4025,7 +4025,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe throws YarnException, IOException { ServiceRecord instance = lookupServiceRecord(registryArgs); - RegistryRetriever retriever = new RegistryRetriever(instance); + RegistryRetriever retriever = new RegistryRetriever(getConfig(), instance); boolean external = !registryArgs.internal; PublishedConfigSet configurations = retriever.getConfigurations(external); @@ -4050,7 +4050,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe throws YarnException, IOException { ServiceRecord instance = lookupServiceRecord(registryArgs); - RegistryRetriever retriever = new RegistryRetriever(instance); + RegistryRetriever retriever = new RegistryRetriever(getConfig(), instance); boolean external = !registryArgs.internal; PublishedExportsSet exports = retriever.getExports(external); http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java b/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java index b0e64ac..856fe4e 100644 --- a/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/rest/BaseRestClient.java @@ -119,7 +119,7 @@ public class BaseRestClient { * @param u the URI of the resource. * @return the Web resource. */ - protected WebResource resource(URI u) { + public WebResource resource(URI u) { return client.resource(u); } @@ -130,21 +130,8 @@ public class BaseRestClient { * @return the Web resource. */ - protected WebResource resource(String url) { - WebResource resource = client.resource(url); - return resource; + public WebResource resource(String url) { + return client.resource(url); } - protected WebResource jsonResource(String url) { - WebResource resource = resource(url); - resource.type(MediaType.APPLICATION_JSON); - return resource; - } - - - protected WebResource jsonResource(URI u) { - WebResource resource = resource(u); - resource.type(MediaType.APPLICATION_JSON); - return resource; - } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/AMWebClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/AMWebClient.java b/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/AMWebClient.java index dd9af16..c6f0fe0 100644 --- a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/AMWebClient.java +++ b/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/AMWebClient.java @@ -27,6 +27,8 @@ import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory; import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.security.ssl.SSLFactory; +import org.apache.slider.client.rest.BaseRestClient; +import org.apache.slider.core.restclient.UgiJerseyBinding; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,10 +47,14 @@ import java.net.URL; * the redirection and security logic properly */ public class AMWebClient { - private static final Client client; + + + private Client client; + private BaseRestClient restClient; private static final Logger log = LoggerFactory.getLogger(AMWebClient.class); +/* static { ClientConfig clientConfig = new DefaultClientConfig(); @@ -62,15 +68,17 @@ public class AMWebClient { client = new Client(handler, clientConfig); client.setFollowRedirects(true); } +*/ + + public AMWebClient(Configuration conf) { + UgiJerseyBinding binding = new UgiJerseyBinding(conf); + client = binding.createJerseyClient(); + + restClient = new BaseRestClient(client); - /** - * Get the Jersey Client - * @return the client - */ - public static Client getClient() { - return client; } + private static URLConnectionClientHandler getUrlConnectionClientHandler() { return new URLConnectionClientHandler(new HttpURLConnectionFactory() { @Override @@ -107,7 +115,7 @@ public class AMWebClient { c.setHostnameVerifier(hv); } catch (Exception e) { log.info("Unable to configure HTTPS connection from " - + "configuration. Leveraging JDK properties."); + + "configuration. Using JDK properties."); } } @@ -117,8 +125,7 @@ public class AMWebClient { } public WebResource resource(String url) { - WebResource resource = client.resource(url); - return resource; + return restClient.resource(url); } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/RegistryRetriever.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/RegistryRetriever.java b/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/RegistryRetriever.java index 6c665a2..03564fa 100644 --- a/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/RegistryRetriever.java +++ b/slider-core/src/main/java/org/apache/slider/core/registry/retrieve/RegistryRetriever.java @@ -21,6 +21,7 @@ package org.apache.slider.core.registry.retrieve; import com.beust.jcommander.Strings; import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.registry.client.exceptions.RegistryIOException; import org.apache.hadoop.registry.client.types.ServiceRecord; import static org.apache.slider.client.ClientRegistryBinder.*; @@ -50,23 +51,18 @@ public class RegistryRetriever extends AMWebClient { private final String externalExportsURL; private final String internalExportsURL; - public RegistryRetriever(String externalConfigurationURL, String internalConfigurationURL, - String externalExportsURL, String internalExportsURL) { - this.externalConfigurationURL = externalConfigurationURL; - this.internalConfigurationURL = internalConfigurationURL; - this.externalExportsURL = externalExportsURL; - this.internalExportsURL = internalExportsURL; - } - /** * Retrieve from a service by locating the * exported {@link CustomRegistryConstants#PUBLISHER_CONFIGURATIONS_API} * and working off it. + * + * @param conf * @param record service record * @throws RegistryIOException the address type of the endpoint does * not match that expected (i.e. not a list of URLs), missing endpoint... */ - public RegistryRetriever(ServiceRecord record) throws RegistryIOException { + public RegistryRetriever(Configuration conf, ServiceRecord record) throws RegistryIOException { + super(new Configuration()); externalConfigurationURL = lookupRestAPI(record, PUBLISHER_CONFIGURATIONS_API, true); internalConfigurationURL = lookupRestAPI(record, http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java index d19c621..bf71861 100644 --- a/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java +++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java @@ -19,23 +19,19 @@ package org.apache.slider.core.restclient; import com.google.common.base.Preconditions; -import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.UniformInterfaceException; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.json.JSONConfiguration; import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory; import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.fs.PathAccessDeniedException; -import org.apache.hadoop.fs.PathIOException; -import org.apache.hadoop.fs.PathNotFoundException; import org.apache.hadoop.security.authentication.client.AuthenticationException; -import org.apache.hadoop.yarn.webapp.ForbiddenException; -import org.apache.hadoop.yarn.webapp.NotFoundException; import org.apache.slider.core.exceptions.ExceptionConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.servlet.http.HttpServletResponse; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -123,6 +119,36 @@ public class UgiJerseyBinding implements return ExceptionConverter.convertJerseyException(verb.getVerb(), url, ex); } + + /** + * Create the standard Jersey client Config + * @return the recommended Jersey Client config + */ + public ClientConfig createJerseyClientConfig() { + ClientConfig clientConfig = new DefaultClientConfig(); + clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); + return clientConfig; + } + + /** + * Create a jersey client bonded to this handler, using the + * supplied client config + * @param clientConfig client configuratin + * @return a new client instance to use + */ + public Client createJerseyClient(ClientConfig clientConfig) { + return new Client(getHandler(), clientConfig); + } + + /** + * Create a jersey client bonded to this handler, using the + * client config created with {@link #createJerseyClientConfig()} + * @return a new client instance to use + */ + public Client createJerseyClient() { + return createJerseyClient(createJerseyClientConfig()); + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/e95d516a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy index 62a8c40..139860a 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneYarnRegistryAM.groovy @@ -357,7 +357,7 @@ class TestStandaloneYarnRegistryAM extends AgentMiniClusterTestBase { describe "Registry Retrieval Class" // retrieval - RegistryRetriever retriever = new RegistryRetriever(serviceRecord) + RegistryRetriever retriever = new RegistryRetriever(launcher.configuration, serviceRecord) log.info retriever.toString() assert retriever.hasConfigurations(true)
