You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2015/05/21 23:12:28 UTC

incubator-slider git commit: SLIDER-878 complete move to BaseRestClient; add shortcut for the get operation there

Repository: incubator-slider
Updated Branches:
  refs/heads/feature/SLIDER-878-jersey-jdk8 e95d516a3 -> 8ceddfd7e


SLIDER-878 complete move to BaseRestClient; add shortcut for the get operation there


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/8ceddfd7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/8ceddfd7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/8ceddfd7

Branch: refs/heads/feature/SLIDER-878-jersey-jdk8
Commit: 8ceddfd7e8e2392cd121adc5dd8aab4993166e4a
Parents: e95d516
Author: Steve Loughran <st...@apache.org>
Authored: Thu May 21 22:12:18 2015 +0100
Committer: Steve Loughran <st...@apache.org>
Committed: Thu May 21 22:12:18 2015 +0100

----------------------------------------------------------------------
 .../slider/client/rest/BaseRestClient.java      | 15 +++++
 .../core/registry/retrieve/AMWebClient.java     | 65 ++++++++++++++------
 .../registry/retrieve/RegistryRetriever.java    | 45 +++-----------
 3 files changed, 71 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8ceddfd7/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 856fe4e..d936a22 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
@@ -75,6 +75,7 @@ public class BaseRestClient  {
       throws IOException {
     try {
       Preconditions.checkArgument(c != null);
+      log.debug("{}} {}", method, resource.getURI());
       return resource.accept(MediaType.APPLICATION_JSON_TYPE)
               .method(method.getVerb(), c);
     } catch (ClientHandlerException ex) {
@@ -101,6 +102,7 @@ public class BaseRestClient  {
       throws IOException {
     try {
       Preconditions.checkArgument(t != null);
+      log.debug("{}} {}", method, resource.getURI());
       resource.accept(MediaType.APPLICATION_JSON_TYPE);
       return resource.method(method.getVerb(), t);
     } catch (ClientHandlerException ex) {
@@ -113,6 +115,19 @@ public class BaseRestClient  {
     }
   }
 
+
+  /**
+   * Execute the  GET operation. Failures are raised as IOException subclasses
+   * @param resource resource to work against
+   * @param c class to build
+   * @param <T> type expected
+   * @return an instance of the type T
+   * @throws IOException on any failure
+   */
+  public <T> T get(WebResource resource, Class<T> c) throws IOException {
+    return exec(HttpVerb.GET, resource, c);
+  }
+
   /**
    * Create a Web resource from the client.
    *

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8ceddfd7/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 c6f0fe0..40fa217 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
@@ -19,6 +19,7 @@
 package org.apache.slider.core.registry.retrieve;
 
 import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.GenericType;
 import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
@@ -28,6 +29,7 @@ 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.HttpVerb;
 import org.apache.slider.core.restclient.UgiJerseyBinding;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -49,32 +51,15 @@ import java.net.URL;
 public class AMWebClient {
 
 
-  private Client client;
-  private BaseRestClient restClient;
+  private final BaseRestClient restClient;
   private static final Logger
       log = LoggerFactory.getLogger(AMWebClient.class);
 
-/*
-
-  static {
-    ClientConfig clientConfig = new DefaultClientConfig();
-    clientConfig.getFeatures().put(
-        JSONConfiguration.FEATURE_POJO_MAPPING,
-        Boolean.TRUE);
-    clientConfig.getProperties().put(
-        URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND,
-        true);
-    URLConnectionClientHandler handler = getUrlConnectionClientHandler();
-    client = new Client(handler, clientConfig);
-    client.setFollowRedirects(true);
-  }
-*/
 
   public AMWebClient(Configuration conf) {
     UgiJerseyBinding binding = new UgiJerseyBinding(conf);
-    client = binding.createJerseyClient();
 
-    restClient = new BaseRestClient(client);
+    restClient = new BaseRestClient(binding.createJerseyClient());
 
   }
 
@@ -128,4 +113,46 @@ public class AMWebClient {
     return restClient.resource(url);
   }
 
+  public BaseRestClient getRestClient() {
+    return restClient;
+  }
+
+  /**
+   * Execute the operation. Failures are raised as IOException subclasses
+   * @param method method to execute
+   * @param resource resource to work against
+   * @param c class to build
+   * @param <T> type expected
+   * @return an instance of the type T
+   * @throws IOException on any failure
+   */
+  public <T> T exec(HttpVerb method, WebResource resource, Class<T> c) throws IOException {
+    return restClient.exec(method, resource, c);
+  }
+
+  /**
+   * Execute the operation. Failures are raised as IOException subclasses
+   * @param method method to execute
+   * @param resource resource to work against
+   * @param t type to work with
+   * @param <T> type expected
+   * @return an instance of the type T
+   * @throws IOException on any failure
+   */
+  public <T> T exec(HttpVerb method, WebResource resource, GenericType<T> t)
+      throws IOException {
+    return restClient.exec(method, resource, t);
+  }
+
+  /**
+   * Execute the  GET operation. Failures are raised as IOException subclasses
+   * @param resource resource to work against
+   * @param c class to build
+   * @param <T> type expected
+   * @return an instance of the type T
+   * @throws IOException on any failure
+   */
+  public <T> T get(WebResource resource, Class<T> c) throws IOException {
+    return restClient.get(resource, c);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8ceddfd7/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 03564fa..b0eddb8 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
@@ -53,16 +53,16 @@ public class RegistryRetriever extends AMWebClient {
 
   /**
    * Retrieve from a service by locating the
-   * exported {@link CustomRegistryConstants#PUBLISHER_CONFIGURATIONS_API}
+   * exported {@link CustomRegistryConstants.PUBLISHER_CONFIGURATIONS_API}
    * and working off it.
    *
-   * @param conf
+   * @param conf configuration to work from
    * @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(Configuration conf, ServiceRecord record) throws RegistryIOException {
-    super(new Configuration());
+    super(conf);
     externalConfigurationURL = lookupRestAPI(record,
         PUBLISHER_CONFIGURATIONS_API, true);
     internalConfigurationURL = lookupRestAPI(record,
@@ -92,14 +92,8 @@ public class RegistryRetriever extends AMWebClient {
       FileNotFoundException, IOException {
 
     String confURL = getConfigurationURL(external);
-    try {
       WebResource webResource = resource(confURL);
-      log.debug("GET {}", confURL);
-      PublishedConfigSet configSet = webResource.get(PublishedConfigSet.class);
-      return configSet;
-    } catch (UniformInterfaceException e) {
-      throw ExceptionConverter.convertJerseyException("GET", confURL, e);
-    }
+    return get(webResource, PublishedConfigSet.class);
   }
 
   protected String getConfigurationURL(boolean external) throws FileNotFoundException {
@@ -127,14 +121,8 @@ public class RegistryRetriever extends AMWebClient {
       FileNotFoundException, IOException {
 
     String exportsUrl = getExportURL(external);
-    try {
-      WebResource webResource = resource(exportsUrl);
-      log.debug("GET {}", exportsUrl);
-      PublishedExportsSet exportSet = webResource.get(PublishedExportsSet.class);
-      return exportSet;
-    } catch (UniformInterfaceException e) {
-      throw ExceptionConverter.convertJerseyException("GET", exportsUrl, e);
-    }
+    WebResource webResource = resource(exportsUrl);
+    return get(webResource, PublishedExportsSet.class);
   }
 
 
@@ -154,14 +142,8 @@ public class RegistryRetriever extends AMWebClient {
       throw new FileNotFoundException("Unknown configuration " + name);
     }
     confURL = SliderUtils.appendToURL(confURL, name);
-    try {
-      WebResource webResource = resource(confURL);
-      PublishedConfiguration publishedConf =
-          webResource.get(PublishedConfiguration.class);
-      return publishedConf;
-    } catch (UniformInterfaceException e) {
-      throw ExceptionConverter.convertJerseyException("GET", confURL, e);
-    }
+    WebResource webResource = resource(confURL);
+    return get(webResource, PublishedConfiguration.class);
   }
 
   /**
@@ -180,15 +162,8 @@ public class RegistryRetriever extends AMWebClient {
     }
     String exportsURL = getExportURL(external);
     exportsURL = SliderUtils.appendToURL(exportsURL, name);
-    try {
-      WebResource webResource = resource(exportsURL);
-      PublishedExports publishedExports =
-          webResource.get(PublishedExports.class);
-      return publishedExports;
-    } catch (UniformInterfaceException e) {
-      throw ExceptionConverter.convertJerseyException("GET", exportsURL, e);
-    }
-  }
+    return get(resource(exportsURL), PublishedExports.class);
+ }
 
   @Override
   public String toString() {