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/01/21 18:55:43 UTC

[01/10] incubator-slider git commit: SLIDER-719 we MAY now have Jersey and SPNEGO hooked up, but tests need to verify this properly

Repository: incubator-slider
Updated Branches:
  refs/heads/develop 901f38cd3 -> 1282802fd


SLIDER-719 we MAY now have Jersey and SPNEGO hooked up, but tests need to verify this properly


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

Branch: refs/heads/develop
Commit: c97f760310b1eccd8f92268f9fa33ad1925f4aec
Parents: 61f4743
Author: Steve Loughran <st...@apache.org>
Authored: Mon Jan 19 14:32:48 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 14:50:23 2015 +0000

----------------------------------------------------------------------
 .../core/restclient/UgiJerseyBinding.java       | 21 +++++++++++++++++++-
 .../restclient/UrlConnectionOperations.java     | 14 +++++++++++--
 .../slider/agent/rest/RestTestDelegates.groovy  | 18 ++++++++---------
 .../slider/agent/rest/TestStandaloneREST.groovy |  2 +-
 .../apache/slider/test/SliderTestUtils.groovy   |  1 -
 .../funtest/lifecycle/AgentWebPagesIT.groovy    |  5 ++++-
 6 files changed, 46 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/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 6af8e23..6f002ab 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
@@ -21,6 +21,7 @@ package org.apache.slider.core.restclient;
 import com.google.common.base.Preconditions;
 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.authentication.client.AuthenticationException;
 
 import java.io.IOException;
@@ -33,7 +34,7 @@ import java.net.URL;
  *   Usage: create an instance, then when creating a Jersey <code>Client</code>
  *   pass in to the constructor the handler provided by {@link #getHandler()}
  *
- * @see https://jersey.java.net/apidocs/1.17/jersey/com/sun/jersey/client/urlconnection/HttpURLConnectionFactory.html
+ * see <a href="https://jersey.java.net/apidocs/1.17/jersey/com/sun/jersey/client/urlconnection/HttpURLConnectionFactory.html">Jersey docs</a>
  */
 public class UgiJerseyBinding implements
     HttpURLConnectionFactory {
@@ -52,6 +53,15 @@ public class UgiJerseyBinding implements
   }
 
   /**
+   * Create an instance off the configuration. The SPNEGO policy
+   * is derived from the current UGI settings.
+   * @param conf config
+   */
+  public UgiJerseyBinding(Configuration conf) {
+    this(new UrlConnectionOperations(conf));
+  }
+
+  /**
    * Get a URL connection. 
    * @param url
    * @return the connection
@@ -74,6 +84,15 @@ public class UgiJerseyBinding implements
   public URLConnectionClientHandler getHandler() {
     return handler;
   }
+  
+  /**
+   * Get the SPNEGO flag (as found in the operations instance
+   * @return the spnego policy
+   */
+  public boolean isUseSpnego() {
+    return operations.isUseSpnego();
+  }
+
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
index c51914a..65a4117 100644
--- a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
+++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.hdfs.web.URLConnectionFactory;
 import org.apache.hadoop.net.NetUtils;
+import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.authentication.client.AuthenticationException;
 import org.apache.hadoop.yarn.webapp.ForbiddenException;
 import org.apache.hadoop.yarn.webapp.NotFoundException;
@@ -48,10 +49,19 @@ public class UrlConnectionOperations extends Configured  {
 
   private boolean useSpnego = false;
 
+  /**
+   * Create an instance off the configuration. The SPNEGO policy
+   * is derived from the current UGI settings.
+   * @param conf config
+   */
   public UrlConnectionOperations(Configuration conf) {
     super(conf);
     connectionFactory = URLConnectionFactory
         .newDefaultURLConnectionFactory(conf);
+    if (UserGroupInformation.isSecurityEnabled()) {
+      log.debug("SPNEGO is enabled");
+      setUseSpnego(true);
+    }
   }
 
 
@@ -66,10 +76,10 @@ public class UrlConnectionOperations extends Configured  {
   /**
    * Opens a url with read and connect timeouts
    *
-   * @param url
-   *          to open
+   * @param url to open
    * @return URLConnection
    * @throws IOException
+   * @throws AuthenticationException authentication failure
    */
   public HttpURLConnection openConnection(URL url) throws
       IOException,

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
index 0826204..bf009c2 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
@@ -97,15 +97,6 @@ class RestTestDelegates extends SliderTestUtils {
     assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING)
   }
 
-
-  public void testRestletOperations() throws Throwable {
-    Client client = createJerseyClient()
-    String path = appendToURL(application, LIVE_RESOURCES)
-    WebResource webResource = client.resource(path)
-    webResource.type(MediaType.APPLICATION_JSON)
-               .get(ConfTree.class);
-  }
-  
   public void testLiveContainers() throws Throwable {
     describe "Application REST ${LIVE_CONTAINERS}"
 
@@ -202,6 +193,15 @@ class RestTestDelegates extends SliderTestUtils {
     TEST_GLOBAL_OPTION_PRESENT
   }
 
+
+  public void testRestletGetOperations() throws Throwable {
+    Client client = createJerseyClient()
+    String path = appendToURL(application, LIVE_RESOURCES)
+    WebResource webResource = client.resource(path)
+    webResource.type(MediaType.APPLICATION_JSON)
+               .get(ConfTree.class);
+  }
+
   public void testPing() {
     // GET
     String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index 22bc4ae..fd676df 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -90,7 +90,7 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     RestTestDelegates proxied = new RestTestDelegates(appmaster)
     RestTestDelegates direct = new RestTestDelegates(realappmaster)
     
-    direct.testRestletOperations();
+    direct.testRestletGetOperations();
     proxied.testCodahaleOperations()
     direct.testCodahaleOperations()
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 9dd2828..df62057 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -605,7 +605,6 @@ class SliderTestUtils extends Assert {
   public static synchronized void initHttpTestSupport(Configuration conf) {
     connectionOperations = new UrlConnectionOperations(conf);
     jerseyBinding = new UgiJerseyBinding(connectionOperations)
-    
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c97f7603/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
index de8dcdf..95352d0 100644
--- a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
+++ b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
@@ -108,6 +108,9 @@ public class AgentWebPagesIT extends AgentCommandTestBase
 
     proxied.testRESTModel()
 
+    direct.testRestletGetOperations()
+    proxied.testRestletGetOperations()
+
     // PUT & POST &c direct
     direct.testPing()
     if (!wsBackDoorRequired) {
@@ -116,7 +119,7 @@ public class AgentWebPagesIT extends AgentCommandTestBase
     }
     
     direct.logCodahaleMetrics();
-    
+
     // finally, stop the AM
     direct.testStop();
   }


[07/10] incubator-slider git commit: SLIDER-719 PUT with Jersey

Posted by st...@apache.org.
SLIDER-719 PUT with Jersey


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

Branch: refs/heads/develop
Commit: dff5985d891714e6fee5b01b7e857973c0a52825
Parents: 79d0e14
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 18:45:34 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 18:46:16 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 81 ++++++++++++++++----
 .../slider/agent/rest/TestStandaloneREST.groovy |  7 +-
 2 files changed, 72 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/dff5985d/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index cb89bff..a0fc144 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -23,6 +23,7 @@ import com.sun.jersey.api.client.WebResource
 import com.sun.jersey.api.client.UniformInterfaceException
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
+import org.apache.hadoop.yarn.webapp.NotFoundException
 import org.apache.slider.api.StateValues
 import org.apache.slider.api.types.SerializedComponentInformation
 import org.apache.slider.api.types.SerializedContainerInformation
@@ -31,12 +32,12 @@ import org.apache.slider.core.conf.ConfTree
 import org.apache.slider.core.conf.ConfTreeOperations
 import org.apache.slider.core.restclient.HttpOperationResponse
 import org.apache.slider.core.restclient.HttpVerb
-import org.apache.slider.core.restclient.UrlConnectionOperations
 import org.apache.slider.server.appmaster.web.rest.RestPaths
 import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource
 import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource
 import org.apache.slider.test.Outcome
 import org.apache.slider.test.SliderTestUtils
+import org.glassfish.grizzly.servlet.ver25.WebResourceCollectionType
 
 import javax.ws.rs.core.MediaType
 
@@ -61,12 +62,17 @@ class JerseyTestDelegates extends SliderTestUtils {
   final String appmaster;
   final String application;
   final Client jersey;
+  final WebResource amResource
+  final WebResource appResource
   
 
   JerseyTestDelegates(String appmaster, Client jersey) {
-    this.appmaster = appmaster
-    this.application = appendToURL(appmaster, RestPaths.SLIDER_PATH_APPLICATION)
     this.jersey = jersey
+    this.appmaster = appmaster
+    application = appendToURL(appmaster, SLIDER_PATH_APPLICATION)
+    amResource = jersey.resource(appmaster)
+    amResource.type(MediaType.APPLICATION_JSON)
+    appResource = amResource.path(SLIDER_PATH_APPLICATION)
   }
 
   /**
@@ -86,10 +92,43 @@ class JerseyTestDelegates extends SliderTestUtils {
    * @return
    */
   public <T> T jExec(HttpVerb  method, String subpath, Class<T> c) {
-    assert c
-    def appPath = appendToURL(SLIDER_PATH_APPLICATION, subpath)
-    WebResource webResource = buildResource(appPath)
-    (T) webResource.method(method.verb, c)
+    WebResource resource = applicationResource(subpath)
+    jExec(method, resource, c)
+  }
+
+  public <T> T jExec(HttpVerb method, WebResource resource, Class<T> c) {
+    try {
+      assert c
+      (T) resource.method(method.verb, c)
+    } catch (UniformInterfaceException ex) {
+      uprateFaults(method, resource, ex)
+    }
+  }
+
+  /**
+   * Create a resource under the application path
+   * @param subpath
+   * @return
+   */
+  public WebResource applicationResource(String subpath) {
+    return appResource.path(subpath)
+  }
+
+  /**
+   * Convert faults to exceptions; pass through 200 responses
+   * @param method
+   * @param webResource
+   * @param ex
+   * @return
+   */
+  public uprateFaults(
+      HttpVerb method,
+      WebResource webResource,
+      UniformInterfaceException ex) {
+    uprateFaults(method.verb,
+        webResource.URI.toString(),
+        ex.response.status,
+        ex.response.toString())
   }
 
   /**
@@ -218,7 +257,7 @@ class JerseyTestDelegates extends SliderTestUtils {
           SerializedContainerInformation
       )
       fail("expected an error, got $result")
-    } catch (UniformInterfaceException e) {
+    } catch (NotFoundException e) {
       // expected
     }
 
@@ -320,17 +359,20 @@ class JerseyTestDelegates extends SliderTestUtils {
     def pinged = jExec(HttpVerb.GET, ACTION_PING, PingResource)
     log.info "Ping GET: $pinged"
     // HEAD
-    jExec(HttpVerb.HEAD, ACTION_PING, PingResource)
+//    jExec(HttpVerb.HEAD, ACTION_PING, PingResource)
     jExec(HttpVerb.PUT, ACTION_PING, PingResource)
     jExec(HttpVerb.DELETE, ACTION_PING, PingResource)
     jExec(HttpVerb.POST, ACTION_PING, PingResource)
+    pingPut(ACTION_PING, "ping-text")
 
   }
 
-  private HttpOperationResponse pingAction(
-      HttpVerb verb, String subpath, String payload) {
+  private PingResource pingPut(String subpath, String payload) {
     def pinged
-    jExec(verb,subpath, PingResource)
+    def actionPing = applicationResource(ACTION_PING)
+    def response = actionPing.put(PingResource, payload)
+    
+/*
     def outcome = ops.execHttpOperation(
         verb,
         pingUrl,
@@ -347,6 +389,8 @@ class JerseyTestDelegates extends SliderTestUtils {
              0, "${bytes.length} bytes of data from ping $verb.verb"
     }
     return outcome
+*/
+    return response
   }
 
   /**
@@ -354,6 +398,8 @@ class JerseyTestDelegates extends SliderTestUtils {
    * Important: once executed, the AM is no longer there.
    * This must be the last test in the sequence.
    */
+/*
+
   public void testStop() {
     String target = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_STOP)
     describe "Stop URL $target"
@@ -384,6 +430,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     }
     
   }
+*/
 
   /**
    * Probe that spins until the url specified by "url") refuses
@@ -391,6 +438,7 @@ class JerseyTestDelegates extends SliderTestUtils {
    * @param args argument map
    * @return the outcome
    */
+/*
   Outcome probePingFailing(Map args) {
     String ping = args["url"]
     URL pingUrl = new URL(ping)
@@ -402,14 +450,17 @@ class JerseyTestDelegates extends SliderTestUtils {
       return Outcome.Success
     }
   }
+*/
 
-  public void suite() {
+  public void testSuiteGetOperations() {
 
     testCodahaleOperations()
     testLiveResources()
     testLiveContainers();
-    testPing();
-
     testRESTModel()
   }
+
+  public void testSuiteComplexVerbs() {
+    testPing();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/dff5985d/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index a53f546..5e00da5 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -90,7 +90,12 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
 
     JerseyTestDelegates proxyJerseyTests =
         new JerseyTestDelegates(proxyAM, createJerseyClient())
-    proxyJerseyTests.suite()
+    proxyJerseyTests.testSuiteGetOperations()
+
+    JerseyTestDelegates directJerseyTests =
+        new JerseyTestDelegates(directAM, createJerseyClient())
+    directJerseyTests.testSuiteGetOperations()
+    directJerseyTests.testSuiteComplexVerbs()
     
     RestTestDelegates proxied = new RestTestDelegates(proxyAM)
     RestTestDelegates direct = new RestTestDelegates(directAM)


[02/10] incubator-slider git commit: SLIDER-719: bonding jersey to UrlConnectionOperations

Posted by st...@apache.org.
SLIDER-719: bonding jersey to UrlConnectionOperations


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

Branch: refs/heads/develop
Commit: 61f4743f83d73e255eee5744be3e72bbb9c60754
Parents: 901f38c
Author: Steve Loughran <st...@apache.org>
Authored: Fri Jan 16 16:57:09 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 14:50:23 2015 +0000

----------------------------------------------------------------------
 pom.xml                                         |  5 +-
 .../core/restclient/UgiJerseyBinding.java       | 79 ++++++++++++++++++++
 .../restclient/UrlConnectionOperations.java     |  2 +-
 .../slider/agent/rest/RestTestDelegates.groovy  | 20 ++++-
 .../slider/agent/rest/TestStandaloneREST.groovy |  7 +-
 .../agent/TestAgentAMManagementWS.groovy        |  4 +-
 .../publisher/TestPublisherRestResources.groovy |  2 +-
 .../apache/slider/test/SliderTestUtils.groovy   | 61 ++++++++++++---
 .../funtest/lifecycle/AgentWebPagesIT.groovy    |  3 +-
 9 files changed, 159 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index cf989e4..b206d66 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,6 +154,7 @@
     <gson.version>2.2.2</gson.version>
     <guice.version>3.0</guice.version>
     <httpclient.version>3.1</httpclient.version>
+    <httpclient4.version>4.2.5</httpclient4.version>
 
     <jackson.version>1.9.13</jackson.version>
     <jcommander.version>1.30</jcommander.version>
@@ -645,13 +646,13 @@
       <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpclient</artifactId>
-        <version>4.2.5</version>
+        <version>${httpclient4.version}</version>
       </dependency>
 
       <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpcore</artifactId>
-        <version>4.2.5</version>
+        <version>${httpclient4.version}</version>
       </dependency>
   
       <!-- ======================================================== -->

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/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
new file mode 100644
index 0000000..6af8e23
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UgiJerseyBinding.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.core.restclient;
+
+import com.google.common.base.Preconditions;
+import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
+import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
+import org.apache.hadoop.security.authentication.client.AuthenticationException;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * Class to bond to a Jersey client, for UGI integration and SPNEGO.
+ * <p>
+ *   Usage: create an instance, then when creating a Jersey <code>Client</code>
+ *   pass in to the constructor the handler provided by {@link #getHandler()}
+ *
+ * @see https://jersey.java.net/apidocs/1.17/jersey/com/sun/jersey/client/urlconnection/HttpURLConnectionFactory.html
+ */
+public class UgiJerseyBinding implements
+    HttpURLConnectionFactory {
+  private final UrlConnectionOperations operations;
+  private final URLConnectionClientHandler handler;
+
+  /**
+   * Construct an instance
+   * @param operations operations instance
+   */
+  @SuppressWarnings("ThisEscapedInObjectConstruction")
+  public UgiJerseyBinding(UrlConnectionOperations operations) {
+    Preconditions.checkArgument(operations != null, "Null operations");
+    this.operations = operations;
+    handler = new URLConnectionClientHandler(this);
+  }
+
+  /**
+   * Get a URL connection. 
+   * @param url
+   * @return the connection
+   * @throws IOException any problem. {@link AuthenticationException} 
+   * errors are wrapped
+   */
+  @Override
+  public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
+    try {
+      return operations.openConnection(url);
+    } catch (AuthenticationException e) {
+      throw new IOException(e);
+    }
+  }
+
+  public UrlConnectionOperations getOperations() {
+    return operations;
+  }
+
+  public URLConnectionClientHandler getHandler() {
+    return handler;
+  }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
index fa0da5a..c51914a 100644
--- a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
+++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
@@ -40,7 +40,7 @@ import java.net.URL;
  * Operations on the JDK UrlConnection class. This uses WebHDFS
  * methods to set up the operations.
  */
-public class UrlConnectionOperations extends Configured {
+public class UrlConnectionOperations extends Configured  {
   private static final Logger log =
       LoggerFactory.getLogger(UrlConnectionOperations.class);
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
index 3431175..0826204 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
@@ -18,6 +18,8 @@
 
 package org.apache.slider.agent.rest
 
+import com.sun.jersey.api.client.Client
+import com.sun.jersey.api.client.WebResource
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.hadoop.yarn.webapp.NotFoundException
@@ -27,9 +29,11 @@ import org.apache.slider.api.types.SerializedContainerInformation
 import org.apache.slider.core.conf.AggregateConf
 import org.apache.slider.core.conf.ConfTree
 import org.apache.slider.core.conf.ConfTreeOperations
+import org.apache.slider.core.registry.docstore.PublishedConfiguration
 import org.apache.slider.core.restclient.HttpOperationResponse
 import org.apache.slider.core.restclient.HttpVerb
 import org.apache.slider.core.restclient.UrlConnectionOperations
+import org.apache.slider.server.appmaster.web.rest.RestPaths
 import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource
 import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource
 import org.apache.slider.test.Outcome
@@ -53,11 +57,14 @@ class RestTestDelegates extends SliderTestUtils {
   public static final String TEST_GLOBAL_OPTION_PRESENT = "present"
 
   final String appmaster;
+  final String application;
 
   RestTestDelegates(String appmaster) {
     this.appmaster = appmaster
+    application = appendToURL(appmaster, RestPaths.SLIDER_PATH_APPLICATION)
   }
 
+  
   public void testCodahaleOperations() throws Throwable {
     describe "Codahale operations"
     getWebPage(appmaster)
@@ -89,6 +96,15 @@ class RestTestDelegates extends SliderTestUtils {
     assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_COMPLETED)
     assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING)
   }
+
+
+  public void testRestletOperations() throws Throwable {
+    Client client = createJerseyClient()
+    String path = appendToURL(application, LIVE_RESOURCES)
+    WebResource webResource = client.resource(path)
+    webResource.type(MediaType.APPLICATION_JSON)
+               .get(ConfTree.class);
+  }
   
   public void testLiveContainers() throws Throwable {
     describe "Application REST ${LIVE_CONTAINERS}"
@@ -211,7 +227,7 @@ class RestTestDelegates extends SliderTestUtils {
       HttpVerb verb,
       URL pingUrl,
       String payload) {
-    return pingAction(connectionFactory, verb, pingUrl, payload)
+    return pingAction(connectionOperations, verb, pingUrl, payload)
   }
 
   private HttpOperationResponse pingAction(
@@ -244,7 +260,7 @@ class RestTestDelegates extends SliderTestUtils {
     String target = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_STOP)
     describe "Stop URL $target"
     URL targetUrl = new URL(target)
-    def outcome = connectionFactory.execHttpOperation(
+    def outcome = connectionOperations.execHttpOperation(
         HttpVerb.POST,
         targetUrl,
         new byte[0],

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index a3378a8..22bc4ae 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -62,14 +62,14 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     def realappmaster = report.originalTrackingUrl
 
     // set up url config to match
-    initConnectionFactory(launcher.configuration)
+    initHttpTestSupport(launcher.configuration)
 
 
-    execHttpRequest(WEB_STARTUP_TIME) {
+    execOperation(WEB_STARTUP_TIME) {
       GET(realappmaster)
     }
     
-    execHttpRequest(WEB_STARTUP_TIME) {
+    execOperation(WEB_STARTUP_TIME) {
       def metrics = GET(realappmaster, SYSTEM_METRICS)
       log.info metrics
     }
@@ -90,6 +90,7 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     RestTestDelegates proxied = new RestTestDelegates(appmaster)
     RestTestDelegates direct = new RestTestDelegates(realappmaster)
     
+    direct.testRestletOperations();
     proxied.testCodahaleOperations()
     direct.testCodahaleOperations()
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestAgentAMManagementWS.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestAgentAMManagementWS.groovy b/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestAgentAMManagementWS.groovy
index 2e2e62b..7eb1d17 100644
--- a/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestAgentAMManagementWS.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/providers/agent/TestAgentAMManagementWS.groovy
@@ -153,7 +153,7 @@ class TestAgentAMManagementWS extends AgentTestBase {
       log.info("tracking URL is $proxyAM")
 
       // spin awaiting the agent web page coming up.
-      execHttpRequest(WEB_STARTUP_TIME) {
+      execOperation(WEB_STARTUP_TIME) {
         GET(proxyAM)
       }
 
@@ -173,7 +173,7 @@ class TestAgentAMManagementWS extends AgentTestBase {
       log.info "AM live, now fetching agent at $agent_url"
       
       // spin awaiting the agent web page coming up.
-      execHttpRequest(WEB_STARTUP_TIME) {
+      execOperation(WEB_STARTUP_TIME) {
         GET(agent_url)
       }
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy b/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy
index e3f38eb..29f0510 100644
--- a/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy
@@ -107,7 +107,7 @@ class TestPublisherRestResources extends AgentTestBase {
     webResource = client.resource(sliderConfigset + "dummy-site");
 
 
-    execHttpRequest(30000) {
+    execOperation(30000) {
       GET(sliderConfigset)
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 2c6b5fe..9dd2828 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -18,6 +18,10 @@
 
 package org.apache.slider.test
 
+import com.sun.jersey.api.client.Client
+import com.sun.jersey.api.client.config.ClientConfig
+import com.sun.jersey.api.client.config.DefaultClientConfig
+import com.sun.jersey.api.json.JSONConfiguration
 import groovy.json.JsonOutput
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
@@ -55,6 +59,7 @@ import org.apache.slider.core.main.ServiceLaunchException
 import org.apache.slider.core.main.ServiceLauncher
 import org.apache.slider.core.persist.JsonSerDeser
 import org.apache.slider.core.registry.docstore.PublishedConfigSet
+import org.apache.slider.core.restclient.UgiJerseyBinding
 import org.apache.slider.core.restclient.UrlConnectionOperations
 import org.apache.slider.server.appmaster.web.HttpCacheHeaders
 import org.apache.slider.server.appmaster.web.rest.RestPaths
@@ -450,7 +455,8 @@ class SliderTestUtils extends Assert {
   }
 
   /**
-   * Fetch a web page 
+   * Fetch a web page using HttpClient 3.1.
+   * This <i>DOES NOT</i> work with secure connections.
    * @param url URL
    * @return the response body
    */
@@ -478,6 +484,9 @@ class SliderTestUtils extends Assert {
 
   /**
    * Fetches a web page asserting that the response code is between 200 and 400.
+   * This <i>DOES NOT</i> work with secure connections.
+   * <p>
+   * 
    * Will error on 400 and 500 series response codes and let 200 and 300 through. 
    * @param url URL to get as string
    * @return body of response
@@ -548,7 +557,7 @@ class SliderTestUtils extends Assert {
   /**
    * Fetches a web page asserting that the response code is between 200 and 400.
    * Will error on 400 and 500 series response codes and let 200 and 300 through.
-   *
+   * <p>
    * if security is enabled, this uses SPNEGO to auth
    * @param page
    * @return body of response
@@ -559,13 +568,14 @@ class SliderTestUtils extends Assert {
   }
 
   /**
-   * Execute any of the http requests, swallowing exceptions until
-   * eventually they time out
+   * Execute any operation provided as a closure which returns a string, swallowing exceptions until
+   * eventually they time out.
+   * 
    * @param timeout
    * @param operation
    * @return
    */
-  public static String execHttpRequest(int timeout, Closure operation) {
+  public static String execOperation(int timeout, Closure operation) {
     Duration duration = new Duration(timeout).start()
     Exception ex = new IOException("limit exceeded before starting");
     while (!duration.limitExceeded) {
@@ -581,12 +591,41 @@ class SliderTestUtils extends Assert {
     throw ex;
   } 
 
-  static UrlConnectionOperations connectionFactory
+  /**
+  * Static factory for URL connections
+   */
+  static UrlConnectionOperations connectionOperations
+  static UgiJerseyBinding jerseyBinding;
 
-  public static def initConnectionFactory(Configuration conf) {
-    connectionFactory = new UrlConnectionOperations(conf);
+  
+  /**
+   * Static initializer of the connection operations
+   * @param conf config
+   */
+  public static synchronized void initHttpTestSupport(Configuration conf) {
+    connectionOperations = new UrlConnectionOperations(conf);
+    jerseyBinding = new UgiJerseyBinding(connectionOperations)
+    
   }
 
+  /**
+   * Check for the HTTP support being initialized
+   */
+  public static synchronized void assertHttpSupportInitialized() {
+    assert connectionOperations 
+    assert jerseyBinding 
+  }
+  
+  /**
+   * Create Jersey client
+   * @return
+   */
+  public static Client createJerseyClient() {
+    assertHttpSupportInitialized()
+    ClientConfig clientConfig = new DefaultClientConfig();
+    clientConfig.features[JSONConfiguration.FEATURE_POJO_MAPPING] =Boolean.TRUE;
+    return new Client(jerseyBinding.handler, clientConfig);
+  }
 
   /**
    * Fetches a web page asserting that the response code is between 200 and 400.
@@ -594,7 +633,7 @@ class SliderTestUtils extends Assert {
    * 
    * if security is enabled, this uses SPNEGO to auth
    * <p>
-   *   Relies on {@link #initConnectionFactory(org.apache.hadoop.conf.Configuration)} 
+   *   Relies on {@link #initHttpTestSupport(org.apache.hadoop.conf.Configuration)} 
    *   to have been called.
    *   
    * @param path path to page
@@ -603,11 +642,11 @@ class SliderTestUtils extends Assert {
    */
   public static String getWebPage(String path, Closure connectionChecks = null) {
     assert path
-    assert null != connectionFactory
+    assertHttpSupportInitialized()
 
     log.info("Fetching HTTP content at " + path);
     URL url = new URL(path)
-    def outcome = connectionFactory.execGet(url)
+    def outcome = connectionOperations.execGet(url)
     String body = new String(outcome.data)
     return body;
   }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/61f4743f/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
index ce1d955..de8dcdf 100644
--- a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
+++ b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
@@ -29,7 +29,6 @@ import org.apache.slider.common.tools.ConfigHelper
 import org.apache.slider.funtest.framework.AgentCommandTestBase
 import org.apache.slider.funtest.framework.FuntestProperties
 import org.apache.slider.funtest.framework.SliderShell
-import org.apache.slider.server.appmaster.web.rest.RestPaths
 import org.junit.After
 import org.junit.Before
 import org.junit.Test
@@ -82,7 +81,7 @@ public class AgentWebPagesIT extends AgentCommandTestBase
 
     def conf = SLIDER_CONFIG
 
-    initConnectionFactory(conf)
+    initHttpTestSupport(conf)
 
     def appId = ensureYarnApplicationIsUp(launchReportFile)
     assert appId


[09/10] incubator-slider git commit: SLIDER-719 REST client tested on secure clusters. The jersey + httpclient combination does not work, but the others do

Posted by st...@apache.org.
SLIDER-719 REST client tested on secure clusters. The jersey + httpclient combination does not work, but the others do


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

Branch: refs/heads/develop
Commit: 0097ce923a217db00095fba6273ce7f339064cb7
Parents: 4418179
Author: Steve Loughran <st...@apache.org>
Authored: Wed Jan 21 17:54:39 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Wed Jan 21 17:54:39 2015 +0000

----------------------------------------------------------------------
 pom.xml                                         |  6 ++
 slider-core/pom.xml                             |  6 ++
 .../core/restclient/HttpOperationResponse.java  |  5 ++
 .../restclient/UrlConnectionOperations.java     |  2 +
 .../rest/application/ApplicationResource.java   |  1 -
 .../agent/rest/JerseyTestDelegates.groovy       | 25 ++++--
 .../slider/agent/rest/RestTestDelegates.groovy  | 20 ++++-
 .../slider/agent/rest/TestStandaloneREST.groovy | 91 +++++++++++++++++---
 .../apache/slider/test/SliderTestUtils.groovy   | 44 ++++++++--
 .../funtest/lifecycle/AgentWebPagesIT.groovy    | 62 +++++++++----
 10 files changed, 212 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b206d66..5c18f77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1204,6 +1204,12 @@
       </dependency>
 
       <dependency>
+        <groupId>com.sun.jersey.contribs</groupId>
+        <artifactId>jersey-apache-client</artifactId>
+        <version>${jersey.version}</version>
+      </dependency>
+
+      <dependency>
         <groupId>com.sun.jersey</groupId>
         <artifactId>jersey-json</artifactId>
         <version>${jersey.version}</version>

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/pom.xml
----------------------------------------------------------------------
diff --git a/slider-core/pom.xml b/slider-core/pom.xml
index be4d95c..43a1193 100644
--- a/slider-core/pom.xml
+++ b/slider-core/pom.xml
@@ -407,6 +407,12 @@
     </dependency>
 
     <dependency>
+      <groupId>com.sun.jersey.contribs</groupId>
+      <artifactId>jersey-apache-client</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>com.google.inject</groupId>
       <artifactId>guice</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/main/java/org/apache/slider/core/restclient/HttpOperationResponse.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/HttpOperationResponse.java b/slider-core/src/main/java/org/apache/slider/core/restclient/HttpOperationResponse.java
index a5357a2..0266223 100644
--- a/slider-core/src/main/java/org/apache/slider/core/restclient/HttpOperationResponse.java
+++ b/slider-core/src/main/java/org/apache/slider/core/restclient/HttpOperationResponse.java
@@ -18,12 +18,17 @@
 
 package org.apache.slider.core.restclient;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * A response for use as a return value from operations
  */
 public class HttpOperationResponse {
   
   public int responseCode;
+  public long lastModified;
   public String contentType;
   public byte[] data;
+  public Map<String, List<String>> headers;
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
index 65a4117..6e29c55 100644
--- a/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
+++ b/slider-core/src/main/java/org/apache/slider/core/restclient/UrlConnectionOperations.java
@@ -133,7 +133,9 @@ public class UrlConnectionOperations extends Configured  {
       }
       
       resultCode = conn.getResponseCode();
+      outcome.lastModified = conn.getLastModified();
       outcome.contentType = conn.getContentType();
+      outcome.headers = conn.getHeaderFields();
       InputStream stream = conn.getErrorStream();
       if (stream == null) {
         stream = conn.getInputStream();

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java
index d72a486..c2c83a0 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/application/ApplicationResource.java
@@ -366,7 +366,6 @@ public class ApplicationResource extends AbstractSliderResource {
   
   @HEAD
   @Path(ACTION_PING)
-  @Produces({APPLICATION_JSON})
   public Object actionPingHead(@Context HttpServletRequest request,
       @Context UriInfo uriInfo) {
     mark("HEAD", SLIDER_SUBPATH_APPLICATION, ACTION_PING);

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index 0699800..09788e1 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -19,8 +19,10 @@
 package org.apache.slider.agent.rest
 
 import com.sun.jersey.api.client.Client
-import com.sun.jersey.api.client.WebResource
+import com.sun.jersey.api.client.ClientResponse
 import com.sun.jersey.api.client.UniformInterfaceException
+import com.sun.jersey.api.client.WebResource
+import com.sun.jersey.client.impl.ClientRequestImpl
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.hadoop.yarn.webapp.NotFoundException
@@ -30,14 +32,10 @@ import org.apache.slider.api.types.SerializedContainerInformation
 import org.apache.slider.core.conf.AggregateConf
 import org.apache.slider.core.conf.ConfTree
 import org.apache.slider.core.conf.ConfTreeOperations
-import org.apache.slider.core.restclient.HttpOperationResponse
 import org.apache.slider.core.restclient.HttpVerb
-import org.apache.slider.server.appmaster.web.rest.RestPaths
 import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource
 import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource
-import org.apache.slider.test.Outcome
 import org.apache.slider.test.SliderTestUtils
-import org.glassfish.grizzly.servlet.ver25.WebResourceCollectionType
 
 import javax.ws.rs.core.MediaType
 
@@ -99,6 +97,7 @@ class JerseyTestDelegates extends SliderTestUtils {
   public <T> T jExec(HttpVerb method, WebResource resource, Class<T> c) {
     try {
       assert c
+      resource.accept(MediaType.APPLICATION_JSON_TYPE)
       (T) resource.method(method.verb, c)
     } catch (UniformInterfaceException ex) {
       uprateFaults(method, resource, ex)
@@ -203,8 +202,21 @@ class JerseyTestDelegates extends SliderTestUtils {
     return tree
   }
 
+
+  public void testMimeTypes() throws Throwable {
+    describe "Mime Types"
+
+    WebResource resource = applicationResource(LIVE_RESOURCES)
+    def response = resource.get(ClientResponse)
+    response.headers.each {key, val -> log.info("$key: $val")}
+    log.info response.toString()
+    assert response.type.equals(MediaType.APPLICATION_JSON_TYPE)
+  }
+  
+  
   public void testLiveResources() throws Throwable {
     describe "Live Resources"
+
     ConfTreeOperations tree = jGetConfigTree(LIVE_RESOURCES)
 
     log.info tree.toString()
@@ -267,7 +279,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     Map<String, SerializedComponentInformation> components =
         jFetchType(LIVE_COMPONENTS, HashMap)
     // two components
-    assert components.size() == 1
+    assert components.size() >= 1
     log.info "${components}"
 
     SerializedComponentInformation amComponentInfo =
@@ -451,6 +463,7 @@ class JerseyTestDelegates extends SliderTestUtils {
   public void testSuiteGetOperations() {
 
     testCodahaleOperations()
+    testMimeTypes()
     testLiveResources()
     testLiveContainers();
     testRESTModel()

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
index dd23926..f90e1ad 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
@@ -18,18 +18,18 @@
 
 package org.apache.slider.agent.rest
 
-import com.sun.jersey.api.client.Client
+import com.sun.jersey.api.client.ClientResponse
 import com.sun.jersey.api.client.WebResource
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.hadoop.yarn.webapp.NotFoundException
+import org.apache.http.entity.ContentType
 import org.apache.slider.api.StateValues
 import org.apache.slider.api.types.SerializedComponentInformation
 import org.apache.slider.api.types.SerializedContainerInformation
 import org.apache.slider.core.conf.AggregateConf
 import org.apache.slider.core.conf.ConfTree
 import org.apache.slider.core.conf.ConfTreeOperations
-import org.apache.slider.core.registry.docstore.PublishedConfiguration
 import org.apache.slider.core.restclient.HttpOperationResponse
 import org.apache.slider.core.restclient.HttpVerb
 import org.apache.slider.core.restclient.UrlConnectionOperations
@@ -40,6 +40,7 @@ import org.apache.slider.test.Outcome
 import org.apache.slider.test.SliderTestUtils
 
 import javax.ws.rs.core.MediaType
+import java.nio.charset.Charset
 
 import static org.apache.slider.api.ResourceKeys.COMPONENT_INSTANCES
 import static org.apache.slider.api.StatusKeys.*
@@ -80,6 +81,18 @@ class RestTestDelegates extends SliderTestUtils {
     log.info getWebPage(appmaster, SYSTEM_METRICS)
   }
 
+
+  public void testMimeTypes() throws Throwable {
+    describe "Mime Types"
+    HttpOperationResponse response= executeGet(
+        appendToURL(appmaster,
+        SLIDER_PATH_APPLICATION, LIVE_RESOURCES))
+    response.headers.each { key, val -> log.info("$key $val")}
+    log.info "Content type: ${response.contentType}"
+    assert response.contentType.contains(MediaType.APPLICATION_JSON_TYPE.toString())
+  }
+
+  
   public void testLiveResources() throws Throwable {
     describe "Live Resources"
     ConfTreeOperations tree = fetchConfigTree(appmaster, LIVE_RESOURCES)
@@ -140,7 +153,7 @@ class RestTestDelegates extends SliderTestUtils {
     Map<String, SerializedComponentInformation> components =
         fetchType(HashMap, appmaster, LIVE_COMPONENTS)
     // two components
-    assert components.size() == 1
+    assert components.size() >= 1
     log.info "${components}"
 
     SerializedComponentInformation amComponentInfo =
@@ -301,6 +314,7 @@ class RestTestDelegates extends SliderTestUtils {
   public void testSuiteGetOperations() {
 
     testCodahaleOperations()
+    testMimeTypes()
     testLiveResources()
     testLiveContainers();
     testRESTModel()

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index 9cea46c..0abf264 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -18,20 +18,28 @@
 
 package org.apache.slider.agent.rest
 
+import com.sun.jersey.api.client.Client
+import com.sun.jersey.api.client.config.ClientConfig
+import com.sun.jersey.api.json.JSONConfiguration
+import com.sun.jersey.client.apache.ApacheHttpClient
+import com.sun.jersey.client.apache.ApacheHttpClientHandler
+import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
+import org.apache.commons.httpclient.HttpClient
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
 import org.apache.hadoop.yarn.api.records.ApplicationReport
 import org.apache.slider.agent.AgentMiniClusterTestBase
+import org.apache.slider.client.SliderClient
 import org.apache.slider.common.SliderXmlConfKeys
 import org.apache.slider.common.params.Arguments
-import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource
-import org.apache.slider.client.SliderClient
 import org.apache.slider.core.main.ServiceLauncher
-
-import static org.apache.slider.server.appmaster.web.rest.RestPaths.*;
+import org.apache.slider.core.restclient.HttpOperationResponse
 import org.junit.Test
 
-import static org.apache.slider.server.appmaster.management.MetricsKeys.*
+import static org.apache.slider.server.appmaster.management.MetricsKeys.METRICS_LOGGING_ENABLED
+import static org.apache.slider.server.appmaster.management.MetricsKeys.METRICS_LOGGING_LOG_INTERVAL
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.*
 
 @CompileStatic
 @Slf4j
@@ -59,8 +67,9 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     addToTeardown(client);
 
     ApplicationReport report = waitForClusterLive(client)
+    def proxyAM = report.trackingUrl
     def directAM = report.originalTrackingUrl
-
+    
     // set up url config to match
     initHttpTestSupport(launcher.configuration)
 
@@ -73,9 +82,8 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
       def metrics = GET(directAM, SYSTEM_METRICS)
       log.info metrics
     }
-    
-    def proxyAM = report.trackingUrl
 
+    
     GET(proxyAM)
 
     log.info GET(proxyAM, SYSTEM_PING)
@@ -87,33 +95,88 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
         SliderXmlConfKeys.X_DEV_INSECURE_WS,
         true)
 
+    describe "Direct response headers from AM Web resources"
+    def liveResUrl = appendToURL(directAM,
+        SLIDER_PATH_APPLICATION, LIVE_RESOURCES);
+    HttpOperationResponse response = executeGet(liveResUrl)
+    response.headers.each { key, val -> log.info("$key $val") }
+    log.info "Content type: ${response.contentType}"
+
+    describe "proxied response headers from AM Web resources"
+    response = executeGet(appendToURL(proxyAM,
+        SLIDER_PATH_APPLICATION, LIVE_RESOURCES))
+    response.headers.each { key, val -> log.info("$key $val") }
+    log.info "Content type: ${response.contentType}"
 
+    
+    
+    describe "Proxy Jersey Tests"
     JerseyTestDelegates proxyJerseyTests =
-        new JerseyTestDelegates(proxyAM, createJerseyClient())
+        new JerseyTestDelegates(proxyAM, createUGIJerseyClient())
     proxyJerseyTests.testSuiteGetOperations()
 
+    describe "Direct Jersey Tests"
+
     JerseyTestDelegates directJerseyTests =
-        new JerseyTestDelegates(directAM, createJerseyClient())
+        new JerseyTestDelegates(directAM, createUGIJerseyClient())
     directJerseyTests.testSuiteGetOperations()
     directJerseyTests.testSuiteComplexVerbs()
-    
-    RestTestDelegates proxied = new RestTestDelegates(proxyAM)
+
+    describe "Direct Tests"
+
     RestTestDelegates direct = new RestTestDelegates(directAM)
-    
-    proxied.testSuiteGetOperations()
     direct.testSuiteGetOperations()
     direct.testSuiteComplexVerbs()
+
+    describe "Proxy Tests"
+
+    RestTestDelegates proxied = new RestTestDelegates(proxyAM)
+    proxied.testSuiteGetOperations()
     if (!wsBackDoorRequired) {
       // and via the proxy
       proxied.testSuiteComplexVerbs()
     }
     
+
+/*    DISABLED: this client does not pass the tests.
+    
+    // http client direct
+    describe "Proxied Jersey Apache HttpClient"
+    JerseyTestDelegates proxiedHttpClientJersey =
+        new JerseyTestDelegates(proxyAM, createJerseyClientHttpClient())
+    proxiedHttpClientJersey.testSuiteGetOperations()
+    
+    describe "Direct Jersey Apache HttpClient"
+    JerseyTestDelegates directHttpClientJersey =
+        new JerseyTestDelegates(directAM, createJerseyClientHttpClient())
+    directHttpClientJersey.testSuiteGetOperations()
+    directHttpClientJersey.testSuiteComplexVerbs()
+    */
+    createJerseyClientHttpClient()
+    // log the metrics to show what's up
     direct.logCodahaleMetrics();
 
     // this MUST be the final test
     direct.testStop();
   }
 
+  /**
+   * Create Jersey client with URL handling by way
+   * of the Apache HttpClient classes. 
+   * @return a Jersey client
+   */
+  public static Client createJerseyClientHttpClient() {
 
+    def httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
+    httpclient.httpConnectionManager.params.connectionTimeout = 10000;
+    ClientConfig clientConfig = new DefaultApacheHttpClientConfig();
+    clientConfig.features[JSONConfiguration.FEATURE_POJO_MAPPING] = Boolean.TRUE;
+
+    def handler = new ApacheHttpClientHandler(httpclient, clientConfig);
+
+    def client = new ApacheHttpClient(handler)
+    client.followRedirects = true
+    return client;
+  }
  
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 897d7e3..1ed340f 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client
 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.URLConnectionClientHandler
 import groovy.json.JsonOutput
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
@@ -34,11 +35,11 @@ import org.apache.hadoop.fs.FileStatus
 import org.apache.hadoop.fs.FileSystem as HadoopFS
 import org.apache.hadoop.fs.Path
 import org.apache.hadoop.net.NetUtils
+import org.apache.hadoop.registry.client.types.ServiceRecord
 import org.apache.hadoop.service.ServiceStateException
 import org.apache.hadoop.util.Shell
 import org.apache.hadoop.yarn.api.records.ApplicationReport
 import org.apache.hadoop.yarn.conf.YarnConfiguration
-import org.apache.hadoop.registry.client.types.ServiceRecord
 import org.apache.hadoop.yarn.webapp.ForbiddenException
 import org.apache.hadoop.yarn.webapp.NotFoundException
 import org.apache.slider.api.ClusterDescription
@@ -59,6 +60,7 @@ import org.apache.slider.core.main.ServiceLaunchException
 import org.apache.slider.core.main.ServiceLauncher
 import org.apache.slider.core.persist.JsonSerDeser
 import org.apache.slider.core.registry.docstore.PublishedConfigSet
+import org.apache.slider.core.restclient.HttpOperationResponse
 import org.apache.slider.core.restclient.UgiJerseyBinding
 import org.apache.slider.core.restclient.UrlConnectionOperations
 import org.apache.slider.server.appmaster.web.HttpCacheHeaders
@@ -616,17 +618,41 @@ class SliderTestUtils extends Assert {
   }
   
   /**
-   * Create Jersey client
+   * Create Jersey client with UGI integration
    * @return
    */
-  public static Client createJerseyClient() {
+  public static Client createUGIJerseyClient() {
     assertHttpSupportInitialized()
-    ClientConfig clientConfig = new DefaultClientConfig();
-    clientConfig.features[JSONConfiguration.FEATURE_POJO_MAPPING] =Boolean.TRUE;
+    ClientConfig clientConfig = createJerseyClientConfig()
     return new Client(jerseyBinding.handler, clientConfig);
   }
 
   /**
+   * Create Jersey client with URL handling by way
+   * of the java.net classes. This DOES NOT have any SPNEGO
+   * integration. If used to query a secure cluster via the
+   * RM Proxy, it MUST fail.
+   * @return a basic Jersey client
+   */
+  public static Client createBasicJerseyClient() {
+    ClientConfig clientConfig = createJerseyClientConfig()
+    return new Client(new URLConnectionClientHandler(),
+        clientConfig);
+  }
+
+
+  /**
+   * Create a jersey client config with the settings needed for tests
+   * (e.g. POJO mappings)
+   * @return a client config
+   */
+  public static ClientConfig createJerseyClientConfig() {
+    ClientConfig clientConfig = new DefaultClientConfig();
+    clientConfig.features[JSONConfiguration.FEATURE_POJO_MAPPING] = Boolean.TRUE;
+    return clientConfig
+  }
+
+  /**
    * Fetches a web page asserting that the response code is between 200 and 400.
    * Will error on 400 and 500 series response codes and let 200 and 300 through.
    * 
@@ -640,14 +666,18 @@ class SliderTestUtils extends Assert {
    * @return body of response
    */
   public static String getWebPage(String path, Closure connectionChecks = null) {
+    HttpOperationResponse outcome = executeGet(path)
+    return new String(outcome.data);
+  }
+
+  public static HttpOperationResponse executeGet(String path) {
     assert path
     assertHttpSupportInitialized()
 
     log.info("Fetching HTTP content at $path");
     URL url = new URL(path)
     def outcome = connectionOperations.execGet(url)
-    String body = new String(outcome.data)
-    return body;
+    return outcome
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0097ce92/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
index 95352d0..2d1c863 100644
--- a/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
+++ b/slider-funtest/src/test/groovy/org/apache/slider/funtest/lifecycle/AgentWebPagesIT.groovy
@@ -20,6 +20,9 @@ package org.apache.slider.funtest.lifecycle
 
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
+import org.apache.hadoop.security.UserGroupInformation
+import org.apache.hadoop.yarn.webapp.ForbiddenException
+import org.apache.slider.agent.rest.JerseyTestDelegates
 import org.apache.slider.agent.rest.RestTestDelegates
 import org.apache.slider.common.SliderExitCodes
 import org.apache.slider.common.SliderXmlConfKeys
@@ -72,7 +75,7 @@ public class AgentWebPagesIT extends AgentCommandTestBase
     SliderShell shell = createTemplatedSliderApplication(CLUSTER,
         APP_TEMPLATE,
         APP_RESOURCE2,
-        [Arguments.ARG_OPTION,
+        [ARG_OPTION,
          RestTestDelegates.TEST_GLOBAL_OPTION,
          RestTestDelegates.TEST_GLOBAL_OPTION_PRESENT],
         launchReportFile)
@@ -92,34 +95,55 @@ public class AgentWebPagesIT extends AgentCommandTestBase
     def report = loadAppReport(liveReportFile)
     assert report.url
 
-    def appmaster = report.url
+    def proxyAM = report.url
 
     // get the root page, 
-    getWebPage(appmaster)
+    getWebPage(proxyAM)
     
-    def realappmaster = report.origTrackingUrl;
+    def directAM = report.origTrackingUrl;
     // now attempt direct-to-AM pings
-    RestTestDelegates proxied = new RestTestDelegates(appmaster)
-    RestTestDelegates direct = new RestTestDelegates(realappmaster)
+    RestTestDelegates direct = new RestTestDelegates(directAM)
 
-    proxied.testCodahaleOperations()
-    direct.testCodahaleOperations()
-    proxied.testLiveResources()
+    direct.testSuiteGetOperations()
+    direct.testSuiteComplexVerbs()
 
-    proxied.testRESTModel()
+    // and via the proxy
+    RestTestDelegates proxied = new RestTestDelegates(proxyAM)
+    proxied.testSuiteGetOperations()
+    if (!wsBackDoorRequired) {
+      proxied.testSuiteComplexVerbs()
+    }
+    proxied.logCodahaleMetrics();
 
-    direct.testRestletGetOperations()
-    proxied.testRestletGetOperations()
+    describe "Proxy Jersey Tests"
 
-    // PUT & POST &c direct
-    direct.testPing()
-    if (!wsBackDoorRequired) {
-      // and via the proxy
-      proxied.testRESTModel()
+    JerseyTestDelegates proxyJerseyTests =
+        new JerseyTestDelegates(proxyAM, createUGIJerseyClient())
+    proxyJerseyTests.testSuiteGetOperations()
+
+    describe "Direct Jersey Tests"
+    JerseyTestDelegates directJerseyTests =
+        new JerseyTestDelegates(directAM, createUGIJerseyClient())
+    directJerseyTests.testSuiteGetOperations()
+    directJerseyTests.testSuiteComplexVerbs()
+    
+    if (UserGroupInformation.securityEnabled) {
+      describe "Insecure Proxy Tests against a secure cluster"
+
+      try {
+        String rootpage = fetchWebPageRaisedErrorCodes(proxyAM);
+        fail(" expected a 401, got $rootpage")
+      } catch (ForbiddenException expected) {
+        // expected
+      }
+      
+      // these tests use the Jersey client without the Hadoop-specific
+      // SPNEGO
+      JerseyTestDelegates baseicJerseyClientTests =
+          new JerseyTestDelegates(proxyAM, createBasicJerseyClient())
+      baseicJerseyClientTests.testSuiteGetOperations()
     }
     
-    direct.logCodahaleMetrics();
-
     // finally, stop the AM
     direct.testStop();
   }


[03/10] incubator-slider git commit: SLIDER-719 factoring out jersey tests into own class

Posted by st...@apache.org.
SLIDER-719 factoring out jersey tests into own class


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

Branch: refs/heads/develop
Commit: 54f1f12510cd5720fa59f2acb083f3b2193a9757
Parents: c0a39d9
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 14:48:17 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 14:50:24 2015 +0000

----------------------------------------------------------------------
 .../slider/agent/rest/JerseyTestDelegates.groovy      | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/54f1f125/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index 2f20bf5..32ca2cc 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -101,17 +101,17 @@ class JerseyTestDelegates extends SliderTestUtils {
   public void testCodahaleOperations() throws Throwable {
     describe "Codahale operations"
     
-    getWebPage(appmaster)
-    getWebPage(appmaster, SYSTEM_THREADS)
-    getWebPage(appmaster, SYSTEM_HEALTHCHECK)
-    getWebPage(appmaster, SYSTEM_PING)
-    getWebPage(appmaster, SYSTEM_METRICS_JSON)
+    jerseyGet(appmaster)
+    jerseyGet(appmaster, SYSTEM_THREADS)
+    jerseyGet(appmaster, SYSTEM_HEALTHCHECK)
+    jerseyGet(appmaster, SYSTEM_PING)
+    jerseyGet(appmaster, SYSTEM_METRICS_JSON)
   }
   
   public void logCodahaleMetrics() {
     // query Coda Hale metrics
-    log.info getWebPage(appmaster, SYSTEM_HEALTHCHECK)
-    log.info getWebPage(appmaster, SYSTEM_METRICS)
+    log.info jerseyGet(appmaster, SYSTEM_HEALTHCHECK)
+    log.info jerseyGet(appmaster, SYSTEM_METRICS)
   }
 
   public void testLiveResources() throws Throwable {


[05/10] incubator-slider git commit: SLIDER-719 initial jersey tests standalone

Posted by st...@apache.org.
SLIDER-719 initial jersey tests standalone


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

Branch: refs/heads/develop
Commit: 72e47903eca51ca54b9e53b05816eea32ebe08ca
Parents: 54f1f12
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 17:04:49 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 17:04:49 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 116 +++++++++++++------
 .../slider/agent/rest/TestStandaloneREST.groovy |  34 ++++--
 2 files changed, 105 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/72e47903/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index 32ca2cc..a06be23 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -20,6 +20,7 @@ package org.apache.slider.agent.rest
 
 import com.sun.jersey.api.client.Client
 import com.sun.jersey.api.client.WebResource
+import com.sun.jersey.api.client.UniformInterfaceException
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.hadoop.yarn.webapp.NotFoundException
@@ -65,20 +66,42 @@ class JerseyTestDelegates extends SliderTestUtils {
 
   JerseyTestDelegates(String appmaster, Client jersey) {
     this.appmaster = appmaster
-    application = appendToURL(appmaster, RestPaths.SLIDER_PATH_APPLICATION)
+    this.application = appendToURL(appmaster, RestPaths.SLIDER_PATH_APPLICATION)
     this.jersey = jersey
   }
 
   /**
    * <T> T get(Class<T> c)
-   * Get operation against the EM
+   * Get operation against a path under the Application
+   * @param subpath path
+   * @return
+   */
+  public <T> T jGetApplicationResource(String subpath, Class<T> c) {
+    assert c
+    def appPath = appendToURL(SLIDER_PATH_APPLICATION, subpath)
+    WebResource webResource = buildResource(appPath)
+    (T)webResource.get(c)
+  }
+
+  /**
+   * <T> T get(Class<T> c)
+   * Get operation against a path under the AM
    * @param path path
    * @return
    */
-  public <T> T jerseyGet(String path, Class<T> c) {
+  public <T> T jGetAMResource(String path, Class<T> c) {
     assert c
     WebResource webResource = buildResource(path)
-    webResource.get(c)
+    (T)webResource.get(c)
+  }
+
+  /**
+   * Get operation against a path under the AM
+   * @param path path
+   * @return the string value
+   */
+  public String jerseyGet(String path) {
+    return jGetAMResource(path, String.class)
   }
 
   /**
@@ -88,7 +111,7 @@ class JerseyTestDelegates extends SliderTestUtils {
    */
   public WebResource buildResource(String path) {
     assert path
-    String fullpath = appendToURL(application, path)
+    String fullpath = appendToURL(appmaster, path)
     WebResource webResource = jersey.resource(fullpath)
     webResource.type(MediaType.APPLICATION_JSON)
     log.info("HTTP operation against $fullpath");
@@ -96,27 +119,39 @@ class JerseyTestDelegates extends SliderTestUtils {
   }
 
   public void testJerseyGetConftree() throws Throwable {
-    jerseyGet(LIVE_RESOURCES, ConfTree.class);
+    jGetApplicationResource(LIVE_RESOURCES, ConfTree.class);
   }
   public void testCodahaleOperations() throws Throwable {
     describe "Codahale operations"
     
-    jerseyGet(appmaster)
-    jerseyGet(appmaster, SYSTEM_THREADS)
-    jerseyGet(appmaster, SYSTEM_HEALTHCHECK)
-    jerseyGet(appmaster, SYSTEM_PING)
-    jerseyGet(appmaster, SYSTEM_METRICS_JSON)
+    jerseyGet("/")
+    jerseyGet(SYSTEM_THREADS)
+    jerseyGet(SYSTEM_HEALTHCHECK)
+    jerseyGet(SYSTEM_PING)
+    jerseyGet(SYSTEM_METRICS_JSON)
   }
   
   public void logCodahaleMetrics() {
     // query Coda Hale metrics
-    log.info jerseyGet(appmaster, SYSTEM_HEALTHCHECK)
-    log.info jerseyGet(appmaster, SYSTEM_METRICS)
+    log.info jerseyGet(SYSTEM_HEALTHCHECK)
+    log.info jerseyGet(SYSTEM_METRICS)
   }
 
-  public void testLiveResources() throws Throwable {
+  public <T> T fetchJType(
+      String subpath, Class<T> clazz) {
+    (T)jGetApplicationResource(subpath, clazz)
+  }
+
+  public ConfTreeOperations jGetConfigTree(
+      String path) {
+    ConfTree ctree = jGetApplicationResource(path, ConfTree)
+    ConfTreeOperations tree = new ConfTreeOperations(ctree)
+    return tree
+  }
+
+    public void testLiveResources() throws Throwable {
     describe "Live Resources"
-    ConfTreeOperations tree = fetchConfigTree(appmaster, LIVE_RESOURCES)
+    ConfTreeOperations tree = jGetConfigTree(LIVE_RESOURCES)
 
     log.info tree.toString()
     def liveAM = tree.getComponent(COMPONENT_AM)
@@ -135,7 +170,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "Application REST ${LIVE_CONTAINERS}"
 
     Map<String, SerializedContainerInformation> containers =
-        fetchType(HashMap, appmaster, LIVE_CONTAINERS)
+        jGetApplicationResource(LIVE_CONTAINERS, HashMap)
     assert containers.size() == 1
     log.info "${containers}"
     SerializedContainerInformation amContainerInfo =
@@ -155,16 +190,20 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "containers"
 
     SerializedContainerInformation retrievedContainerInfo =
-        fetchType(SerializedContainerInformation, appmaster,
-            LIVE_CONTAINERS + "/${amContainerId}")
+        fetchJType(
+            LIVE_CONTAINERS + "/${amContainerId}",
+            SerializedContainerInformation
+        )
     assert retrievedContainerInfo.containerId == amContainerId
 
     // fetch missing
     try {
-      def result = fetchType(SerializedContainerInformation, appmaster,
-          LIVE_CONTAINERS + "/unknown")
+      def result = fetchJType(
+          LIVE_CONTAINERS + "/unknown",
+          SerializedContainerInformation
+      )
       fail("expected an error, got $result")
-    } catch (NotFoundException e) {
+    } catch (UniformInterfaceException e) {
       // expected
     }
 
@@ -172,7 +211,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "components"
 
     Map<String, SerializedComponentInformation> components =
-        fetchType(HashMap, appmaster, LIVE_COMPONENTS)
+        fetchJType(LIVE_COMPONENTS, HashMap)
     // two components
     assert components.size() == 1
     log.info "${components}"
@@ -180,10 +219,10 @@ class JerseyTestDelegates extends SliderTestUtils {
     SerializedComponentInformation amComponentInfo =
         (SerializedComponentInformation) components[COMPONENT_AM]
 
-    SerializedComponentInformation amFullInfo = fetchType(
-        SerializedComponentInformation,
-        appmaster,
-        LIVE_COMPONENTS + "/${COMPONENT_AM}")
+    SerializedComponentInformation amFullInfo = fetchJType(
+        LIVE_COMPONENTS + "/${COMPONENT_AM}",
+        SerializedComponentInformation
+    )
 
     assert amFullInfo.containers.size() == 1
     assert amFullInfo.containers[0] == amContainerId
@@ -202,14 +241,14 @@ class JerseyTestDelegates extends SliderTestUtils {
         MODEL,
         ApplicationResource.MODEL_ENTRIES)
 
-    def unresolvedConf = fetchType(AggregateConf, appmaster, MODEL_DESIRED)
+    def unresolvedConf = fetchJType(MODEL_DESIRED, AggregateConf)
 //    log.info "Unresolved \n$unresolvedConf"
     def unresolvedAppConf = unresolvedConf.appConfOperations
 
     def sam = "slider-appmaster"
     assert unresolvedAppConf.getComponentOpt(sam,
         TEST_GLOBAL_OPTION, "") == ""
-    def resolvedConf = fetchType(AggregateConf, appmaster, MODEL_RESOLVED)
+    def resolvedConf = fetchJType(MODEL_RESOLVED, AggregateConf)
 //    log.info "Resolved \n$resolvedConf"
     assert resolvedConf.appConfOperations.getComponentOpt(
         sam, TEST_GLOBAL_OPTION, "") == TEST_GLOBAL_OPTION_PRESENT
@@ -240,7 +279,10 @@ class JerseyTestDelegates extends SliderTestUtils {
     // GET
     String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
     describe "ping to AM URL $appmaster, ping URL $ping"
-    def pinged = fetchType(PingResource, appmaster, ACTION_PING + "?body=hello")
+    def pinged = fetchJType(
+        ACTION_PING + "?body=hello",
+        PingResource
+    )
     log.info "Ping GET: $pinged"
 
     URL pingUrl = new URL(ping)
@@ -313,10 +355,9 @@ class JerseyTestDelegates extends SliderTestUtils {
         [url: ping],
         true,
         "AM failed to shut down") {
-      def pinged = fetchType(
-          PingResource,
-          appmaster,
-          ACTION_PING + "?body=hello")
+      def pinged = fetchJType(ACTION_PING + "?body=hello",
+          PingResource
+      )
       fail("AM didn't shut down; Ping GET= $pinged")
     }
     
@@ -340,4 +381,13 @@ class JerseyTestDelegates extends SliderTestUtils {
     }
   }
 
+  public void suite() {
+
+    testRestletGetOperations();
+    testCodahaleOperations()
+    testLiveResources()
+    testLiveContainers();
+
+    testRESTModel()
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/72e47903/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index fd676df..a53f546 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -59,36 +59,41 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     addToTeardown(client);
 
     ApplicationReport report = waitForClusterLive(client)
-    def realappmaster = report.originalTrackingUrl
+    def directAM = report.originalTrackingUrl
 
     // set up url config to match
     initHttpTestSupport(launcher.configuration)
 
 
     execOperation(WEB_STARTUP_TIME) {
-      GET(realappmaster)
+      GET(directAM)
     }
     
     execOperation(WEB_STARTUP_TIME) {
-      def metrics = GET(realappmaster, SYSTEM_METRICS)
+      def metrics = GET(directAM, SYSTEM_METRICS)
       log.info metrics
     }
     
-    def appmaster = report.trackingUrl
+    def proxyAM = report.trackingUrl
 
-    GET(appmaster)
+    GET(proxyAM)
 
-    log.info GET(appmaster, SYSTEM_PING)
-    log.info GET(appmaster, SYSTEM_THREADS)
-    log.info GET(appmaster, SYSTEM_HEALTHCHECK)
-    log.info GET(appmaster, SYSTEM_METRICS_JSON)
+    log.info GET(proxyAM, SYSTEM_PING)
+    log.info GET(proxyAM, SYSTEM_THREADS)
+    log.info GET(proxyAM, SYSTEM_HEALTHCHECK)
+    log.info GET(proxyAM, SYSTEM_METRICS_JSON)
 
     def wsBackDoorRequired = conf.getBoolean(
         SliderXmlConfKeys.X_DEV_INSECURE_WS,
         true)
+
+
+    JerseyTestDelegates proxyJerseyTests =
+        new JerseyTestDelegates(proxyAM, createJerseyClient())
+    proxyJerseyTests.suite()
     
-    RestTestDelegates proxied = new RestTestDelegates(appmaster)
-    RestTestDelegates direct = new RestTestDelegates(realappmaster)
+    RestTestDelegates proxied = new RestTestDelegates(proxyAM)
+    RestTestDelegates direct = new RestTestDelegates(directAM)
     
     direct.testRestletGetOperations();
     proxied.testCodahaleOperations()
@@ -96,7 +101,7 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
 
     describe "base entry lists"
 
-    assertPathServesList(appmaster, LIVE, ApplicationResource.LIVE_ENTRIES)
+    assertPathServesList(proxyAM, LIVE, ApplicationResource.LIVE_ENTRIES)
 
     // now some REST gets
     describe "Application REST ${LIVE_RESOURCES}"
@@ -114,7 +119,12 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     }
     
     direct.logCodahaleMetrics();
+
+    // this MUST be the final test
     direct.testStop();
+    
+    
+    
   }
 
 


[08/10] incubator-slider git commit: SLIDER-719 jersey ping test supports PUT/DELETE/GET/HEAD/POST

Posted by st...@apache.org.
SLIDER-719 jersey ping test supports PUT/DELETE/GET/HEAD/POST


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

Branch: refs/heads/develop
Commit: 4418179aa645a6bb6d4c8cf4fdae76468b9d1d8d
Parents: dff5985
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 19:06:37 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 19:06:37 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 42 +++++++++-----------
 .../slider/agent/rest/RestTestDelegates.groovy  | 21 +++++-----
 .../slider/agent/rest/TestStandaloneREST.groovy | 26 ++----------
 3 files changed, 35 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4418179a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index a0fc144..0699800 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -363,34 +363,30 @@ class JerseyTestDelegates extends SliderTestUtils {
     jExec(HttpVerb.PUT, ACTION_PING, PingResource)
     jExec(HttpVerb.DELETE, ACTION_PING, PingResource)
     jExec(HttpVerb.POST, ACTION_PING, PingResource)
-    pingPut(ACTION_PING, "ping-text")
-
+    ping(HttpVerb.PUT, ACTION_PING, "ping-text")
+    ping(HttpVerb.POST, ACTION_PING, "ping-text")
+    ping(HttpVerb.DELETE, ACTION_PING, "ping-text")
   }
 
-  private PingResource pingPut(String subpath, String payload) {
-    def pinged
+  /**
+   * Execute a ping; assert that a response came back with the relevant
+   * verb if the verb has a response body
+   * @param method method to invoke
+   * @param subpath ping path
+   * @param payload payload
+   * @return the resource if the verb has a response
+   */
+  private PingResource ping(HttpVerb method, String subpath, Object payload) {
     def actionPing = applicationResource(ACTION_PING)
-    def response = actionPing.put(PingResource, payload)
-    
-/*
-    def outcome = ops.execHttpOperation(
-        verb,
-        pingUrl,
-        payload.bytes,
-        MediaType.TEXT_PLAIN)
-    byte[] bytes = outcome.data
-    if (verb.hasResponseBody()) {
-      assert bytes.length > 0, "0 bytes from ping $verb.verb"
-      pinged = deser(PingResource, bytes)
-      log.info "Ping $verb.verb: $pinged"
-      assert verb.verb == pinged.verb
+    def upload = method.hasUploadBody() ? payload : null
+    if (method.hasResponseBody()) {
+      def pinged = actionPing.method(method.verb, PingResource, upload)
+      assert method.verb == pinged.verb
+      return pinged
     } else {
-      assert bytes.length ==
-             0, "${bytes.length} bytes of data from ping $verb.verb"
+      actionPing.method(method.verb, upload)
+      return null
     }
-    return outcome
-*/
-    return response
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4418179a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
index bf009c2..dd23926 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestTestDelegates.groovy
@@ -193,15 +193,6 @@ class RestTestDelegates extends SliderTestUtils {
     TEST_GLOBAL_OPTION_PRESENT
   }
 
-
-  public void testRestletGetOperations() throws Throwable {
-    Client client = createJerseyClient()
-    String path = appendToURL(application, LIVE_RESOURCES)
-    WebResource webResource = client.resource(path)
-    webResource.type(MediaType.APPLICATION_JSON)
-               .get(ConfTree.class);
-  }
-
   public void testPing() {
     // GET
     String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
@@ -306,4 +297,16 @@ class RestTestDelegates extends SliderTestUtils {
     }
   }
 
+
+  public void testSuiteGetOperations() {
+
+    testCodahaleOperations()
+    testLiveResources()
+    testLiveContainers();
+    testRESTModel()
+  }
+
+  public void testSuiteComplexVerbs() {
+    testPing();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/4418179a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
index 5e00da5..9cea46c 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/TestStandaloneREST.groovy
@@ -100,36 +100,18 @@ class TestStandaloneREST extends AgentMiniClusterTestBase {
     RestTestDelegates proxied = new RestTestDelegates(proxyAM)
     RestTestDelegates direct = new RestTestDelegates(directAM)
     
-    direct.testRestletGetOperations();
-    proxied.testCodahaleOperations()
-    direct.testCodahaleOperations()
-
-    describe "base entry lists"
-
-    assertPathServesList(proxyAM, LIVE, ApplicationResource.LIVE_ENTRIES)
-
-    // now some REST gets
-    describe "Application REST ${LIVE_RESOURCES}"
-    proxied.testLiveResources()
-
-    proxied.testRESTModel()
-    
-    // PUT & POST &c must go direct for now
-    direct.testPing()
-    // PUT & POST &c direct
-    direct.testPing()
+    proxied.testSuiteGetOperations()
+    direct.testSuiteGetOperations()
+    direct.testSuiteComplexVerbs()
     if (!wsBackDoorRequired) {
       // and via the proxy
-      proxied.testRESTModel()
+      proxied.testSuiteComplexVerbs()
     }
     
     direct.logCodahaleMetrics();
 
     // this MUST be the final test
     direct.testStop();
-    
-    
-    
   }
 
 


[04/10] incubator-slider git commit: SLIDER-719 factoring out jersey tests into own class

Posted by st...@apache.org.
SLIDER-719 factoring out jersey tests into own class


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

Branch: refs/heads/develop
Commit: c0a39d926b231167199655290bcbb43972cb86b2
Parents: c97f760
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 10:32:24 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 14:50:24 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 343 +++++++++++++++++++
 .../apache/slider/test/SliderTestUtils.groovy   |   5 +-
 2 files changed, 345 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c0a39d92/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
new file mode 100644
index 0000000..2f20bf5
--- /dev/null
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -0,0 +1,343 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.agent.rest
+
+import com.sun.jersey.api.client.Client
+import com.sun.jersey.api.client.WebResource
+import groovy.transform.CompileStatic
+import groovy.util.logging.Slf4j
+import org.apache.hadoop.yarn.webapp.NotFoundException
+import org.apache.slider.api.StateValues
+import org.apache.slider.api.types.SerializedComponentInformation
+import org.apache.slider.api.types.SerializedContainerInformation
+import org.apache.slider.core.conf.AggregateConf
+import org.apache.slider.core.conf.ConfTree
+import org.apache.slider.core.conf.ConfTreeOperations
+import org.apache.slider.core.restclient.HttpOperationResponse
+import org.apache.slider.core.restclient.HttpVerb
+import org.apache.slider.core.restclient.UrlConnectionOperations
+import org.apache.slider.server.appmaster.web.rest.RestPaths
+import org.apache.slider.server.appmaster.web.rest.application.ApplicationResource
+import org.apache.slider.server.appmaster.web.rest.application.resources.PingResource
+import org.apache.slider.test.Outcome
+import org.apache.slider.test.SliderTestUtils
+
+import javax.ws.rs.core.MediaType
+
+import static org.apache.slider.api.ResourceKeys.COMPONENT_INSTANCES
+import static org.apache.slider.api.StatusKeys.*
+import static org.apache.slider.common.SliderKeys.COMPONENT_AM
+import static org.apache.slider.server.appmaster.web.rest.RestPaths.*
+
+/**
+ * This class contains parts of tests that can be run
+ * against a deployed AM: local or remote.
+ * It uses Jersey ... and must be passed a client that is either secure
+ * or not
+ * 
+ */
+@CompileStatic
+@Slf4j
+class JerseyTestDelegates extends SliderTestUtils {
+  public static final String TEST_GLOBAL_OPTION = "test.global.option"
+  public static final String TEST_GLOBAL_OPTION_PRESENT = "present"
+
+  final String appmaster;
+  final String application;
+  final Client jersey;
+  
+
+  JerseyTestDelegates(String appmaster, Client jersey) {
+    this.appmaster = appmaster
+    application = appendToURL(appmaster, RestPaths.SLIDER_PATH_APPLICATION)
+    this.jersey = jersey
+  }
+
+  /**
+   * <T> T get(Class<T> c)
+   * Get operation against the EM
+   * @param path path
+   * @return
+   */
+  public <T> T jerseyGet(String path, Class<T> c) {
+    assert c
+    WebResource webResource = buildResource(path)
+    webResource.get(c)
+  }
+
+  /**
+   * Build a resource against a path under the AM API
+   * @param path path
+   * @return a resource for use
+   */
+  public WebResource buildResource(String path) {
+    assert path
+    String fullpath = appendToURL(application, path)
+    WebResource webResource = jersey.resource(fullpath)
+    webResource.type(MediaType.APPLICATION_JSON)
+    log.info("HTTP operation against $fullpath");
+    return webResource
+  }
+
+  public void testJerseyGetConftree() throws Throwable {
+    jerseyGet(LIVE_RESOURCES, ConfTree.class);
+  }
+  public void testCodahaleOperations() throws Throwable {
+    describe "Codahale operations"
+    
+    getWebPage(appmaster)
+    getWebPage(appmaster, SYSTEM_THREADS)
+    getWebPage(appmaster, SYSTEM_HEALTHCHECK)
+    getWebPage(appmaster, SYSTEM_PING)
+    getWebPage(appmaster, SYSTEM_METRICS_JSON)
+  }
+  
+  public void logCodahaleMetrics() {
+    // query Coda Hale metrics
+    log.info getWebPage(appmaster, SYSTEM_HEALTHCHECK)
+    log.info getWebPage(appmaster, SYSTEM_METRICS)
+  }
+
+  public void testLiveResources() throws Throwable {
+    describe "Live Resources"
+    ConfTreeOperations tree = fetchConfigTree(appmaster, LIVE_RESOURCES)
+
+    log.info tree.toString()
+    def liveAM = tree.getComponent(COMPONENT_AM)
+    def desiredInstances = liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES);
+    assert desiredInstances ==
+           liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_ACTUAL)
+
+    assert 1 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_STARTED)
+    assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_REQUESTING)
+    assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_FAILED)
+    assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_COMPLETED)
+    assert 0 == liveAM.getMandatoryOptionInt(COMPONENT_INSTANCES_RELEASING)
+  }
+
+  public void testLiveContainers() throws Throwable {
+    describe "Application REST ${LIVE_CONTAINERS}"
+
+    Map<String, SerializedContainerInformation> containers =
+        fetchType(HashMap, appmaster, LIVE_CONTAINERS)
+    assert containers.size() == 1
+    log.info "${containers}"
+    SerializedContainerInformation amContainerInfo =
+        (SerializedContainerInformation) containers.values()[0]
+    assert amContainerInfo.containerId
+
+    def amContainerId = amContainerInfo.containerId
+    assert containers[amContainerId]
+
+    assert amContainerInfo.component == COMPONENT_AM
+    assert amContainerInfo.createTime > 0
+    assert amContainerInfo.exitCode == null
+    assert amContainerInfo.output == null
+    assert amContainerInfo.released == null
+    assert amContainerInfo.state == StateValues.STATE_LIVE
+
+    describe "containers"
+
+    SerializedContainerInformation retrievedContainerInfo =
+        fetchType(SerializedContainerInformation, appmaster,
+            LIVE_CONTAINERS + "/${amContainerId}")
+    assert retrievedContainerInfo.containerId == amContainerId
+
+    // fetch missing
+    try {
+      def result = fetchType(SerializedContainerInformation, appmaster,
+          LIVE_CONTAINERS + "/unknown")
+      fail("expected an error, got $result")
+    } catch (NotFoundException e) {
+      // expected
+    }
+
+
+    describe "components"
+
+    Map<String, SerializedComponentInformation> components =
+        fetchType(HashMap, appmaster, LIVE_COMPONENTS)
+    // two components
+    assert components.size() == 1
+    log.info "${components}"
+
+    SerializedComponentInformation amComponentInfo =
+        (SerializedComponentInformation) components[COMPONENT_AM]
+
+    SerializedComponentInformation amFullInfo = fetchType(
+        SerializedComponentInformation,
+        appmaster,
+        LIVE_COMPONENTS + "/${COMPONENT_AM}")
+
+    assert amFullInfo.containers.size() == 1
+    assert amFullInfo.containers[0] == amContainerId
+
+  }
+
+  /**
+   * Test the rest model. For this to work the cluster has to be configured
+   * with the global option
+   * @param appmaster
+   */
+  public void testRESTModel() {
+    describe "model"
+
+    assertPathServesList(appmaster,
+        MODEL,
+        ApplicationResource.MODEL_ENTRIES)
+
+    def unresolvedConf = fetchType(AggregateConf, appmaster, MODEL_DESIRED)
+//    log.info "Unresolved \n$unresolvedConf"
+    def unresolvedAppConf = unresolvedConf.appConfOperations
+
+    def sam = "slider-appmaster"
+    assert unresolvedAppConf.getComponentOpt(sam,
+        TEST_GLOBAL_OPTION, "") == ""
+    def resolvedConf = fetchType(AggregateConf, appmaster, MODEL_RESOLVED)
+//    log.info "Resolved \n$resolvedConf"
+    assert resolvedConf.appConfOperations.getComponentOpt(
+        sam, TEST_GLOBAL_OPTION, "") == TEST_GLOBAL_OPTION_PRESENT
+
+    def unresolved = fetchTypeList(ConfTree, appmaster,
+        [MODEL_DESIRED_APPCONF, MODEL_DESIRED_RESOURCES])
+    assert unresolved[MODEL_DESIRED_APPCONF].components[sam]
+    [TEST_GLOBAL_OPTION] == null
+
+
+    def resolved = fetchTypeList(ConfTree, appmaster,
+        [MODEL_RESOLVED_APPCONF, MODEL_RESOLVED_RESOURCES])
+    assert resolved[MODEL_RESOLVED_APPCONF].components[sam]
+    [TEST_GLOBAL_OPTION] ==
+    TEST_GLOBAL_OPTION_PRESENT
+  }
+
+
+  public void testRestletGetOperations() throws Throwable {
+    Client client = createJerseyClient()
+    String path = appendToURL(application, LIVE_RESOURCES)
+    WebResource webResource = client.resource(path)
+    webResource.type(MediaType.APPLICATION_JSON)
+               .get(ConfTree.class);
+  }
+
+  public void testPing() {
+    // GET
+    String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
+    describe "ping to AM URL $appmaster, ping URL $ping"
+    def pinged = fetchType(PingResource, appmaster, ACTION_PING + "?body=hello")
+    log.info "Ping GET: $pinged"
+
+    URL pingUrl = new URL(ping)
+    def message = "hello"
+
+    // HEAD
+    pingAction(HttpVerb.HEAD, pingUrl, message)
+
+    // Other verbs
+    pingAction(HttpVerb.POST, pingUrl, message)
+    pingAction(HttpVerb.PUT, pingUrl, message)
+    pingAction(HttpVerb.DELETE, pingUrl, message)
+
+  }
+
+
+  private HttpOperationResponse pingAction(
+      HttpVerb verb,
+      URL pingUrl,
+      String payload) {
+    return pingAction(connectionOperations, verb, pingUrl, payload)
+  }
+
+  private HttpOperationResponse pingAction(
+      UrlConnectionOperations ops, HttpVerb verb, URL pingUrl, String payload) {
+    def pinged
+    def outcome = ops.execHttpOperation(
+        verb,
+        pingUrl,
+        payload.bytes,
+        MediaType.TEXT_PLAIN)
+    byte[] bytes = outcome.data
+    if (verb.hasResponseBody()) {
+      assert bytes.length > 0, "0 bytes from ping $verb.verb"
+      pinged = deser(PingResource, bytes)
+      log.info "Ping $verb.verb: $pinged"
+      assert verb.verb == pinged.verb
+    } else {
+      assert bytes.length ==
+             0, "${bytes.length} bytes of data from ping $verb.verb"
+    }
+    return outcome
+  }
+
+  /**
+   * Test the stop command.
+   * Important: once executed, the AM is no longer there.
+   * This must be the last test in the sequence.
+   */
+  public void testStop() {
+    String target = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_STOP)
+    describe "Stop URL $target"
+    URL targetUrl = new URL(target)
+    def outcome = connectionOperations.execHttpOperation(
+        HttpVerb.POST,
+        targetUrl,
+        new byte[0],
+        MediaType.TEXT_PLAIN)
+    log.info "Stopped: $outcome"
+
+    // await the shutdown
+    sleep(1000)
+    
+    // now a ping is expected to fail
+    String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
+    URL pingUrl = new URL(ping)
+
+    repeatUntilSuccess("probe for missing registry entry",
+        this.&probePingFailing, 30000, 500,
+        [url: ping],
+        true,
+        "AM failed to shut down") {
+      def pinged = fetchType(
+          PingResource,
+          appmaster,
+          ACTION_PING + "?body=hello")
+      fail("AM didn't shut down; Ping GET= $pinged")
+    }
+    
+  }
+
+  /**
+   * Probe that spins until the url specified by "url") refuses
+   * connections
+   * @param args argument map
+   * @return the outcome
+   */
+  Outcome probePingFailing(Map args) {
+    String ping = args["url"]
+    URL pingUrl = new URL(ping)
+    try {
+      def response = pingAction(HttpVerb.HEAD, pingUrl, "should not be running")
+      return Outcome.Retry
+    } catch (IOException e) {
+      // expected
+      return Outcome.Success
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c0a39d92/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index df62057..897d7e3 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -643,7 +643,7 @@ class SliderTestUtils extends Assert {
     assert path
     assertHttpSupportInitialized()
 
-    log.info("Fetching HTTP content at " + path);
+    log.info("Fetching HTTP content at $path");
     URL url = new URL(path)
     def outcome = connectionOperations.execGet(url)
     String body = new String(outcome.data)
@@ -675,8 +675,7 @@ class SliderTestUtils extends Assert {
     log.info("Asserting component $component expected count $expected}",)
     int actual = extractLiveContainerCount(clusterDescription, component)
     if (expected != actual) {
-      log.warn(
-          "$component actual=$actual, expected $expected in \n$clusterDescription")
+      log.warn("$component actual=$actual, expected $expected in \n$clusterDescription")
     }
     assert expected == actual
   }


[10/10] incubator-slider git commit: Merge branch 'feature/SLIDER-719_Create_slider_REST_client_library' into develop

Posted by st...@apache.org.
Merge branch 'feature/SLIDER-719_Create_slider_REST_client_library' into develop


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

Branch: refs/heads/develop
Commit: 1282802fd66924effb0e4c22b93295734fe203a0
Parents: 901f38c 0097ce9
Author: Steve Loughran <st...@apache.org>
Authored: Wed Jan 21 17:54:48 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Wed Jan 21 17:54:48 2015 +0000

----------------------------------------------------------------------
 pom.xml                                         |  11 +-
 slider-core/pom.xml                             |   6 +
 .../core/restclient/HttpOperationResponse.java  |   5 +
 .../core/restclient/UgiJerseyBinding.java       |  98 ++++
 .../restclient/UrlConnectionOperations.java     |  18 +-
 .../rest/application/ApplicationResource.java   |   1 -
 .../agent/rest/JerseyTestDelegates.groovy       | 475 +++++++++++++++++++
 .../slider/agent/rest/RestTestDelegates.groovy  |  41 +-
 .../slider/agent/rest/TestStandaloneREST.groovy | 131 +++--
 .../agent/TestAgentAMManagementWS.groovy        |   4 +-
 .../publisher/TestPublisherRestResources.groovy |   2 +-
 .../apache/slider/test/SliderTestUtils.groovy   | 101 +++-
 .../funtest/lifecycle/AgentWebPagesIT.groovy    |  62 ++-
 13 files changed, 872 insertions(+), 83 deletions(-)
----------------------------------------------------------------------



[06/10] incubator-slider git commit: SLIDER-719 jersey tests about to migrate to WebTarget

Posted by st...@apache.org.
SLIDER-719 jersey tests about to migrate to WebTarget


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

Branch: refs/heads/develop
Commit: 79d0e14f1d63b1e1a41edb77dce191238fb52eea
Parents: 72e4790
Author: Steve Loughran <st...@apache.org>
Authored: Tue Jan 20 17:47:51 2015 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Jan 20 17:47:51 2015 +0000

----------------------------------------------------------------------
 .../agent/rest/JerseyTestDelegates.groovy       | 120 +++++++++++--------
 1 file changed, 71 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/79d0e14f/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
----------------------------------------------------------------------
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
index a06be23..cb89bff 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/rest/JerseyTestDelegates.groovy
@@ -23,7 +23,6 @@ import com.sun.jersey.api.client.WebResource
 import com.sun.jersey.api.client.UniformInterfaceException
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
-import org.apache.hadoop.yarn.webapp.NotFoundException
 import org.apache.slider.api.StateValues
 import org.apache.slider.api.types.SerializedComponentInformation
 import org.apache.slider.api.types.SerializedContainerInformation
@@ -77,10 +76,20 @@ class JerseyTestDelegates extends SliderTestUtils {
    * @return
    */
   public <T> T jGetApplicationResource(String subpath, Class<T> c) {
+    return (T)jExec(HttpVerb.GET, subpath, c)
+  }
+
+  /**
+   * <T> T get(Class<T> c)
+   * Get operation against a path under the Application
+   * @param subpath path
+   * @return
+   */
+  public <T> T jExec(HttpVerb  method, String subpath, Class<T> c) {
     assert c
     def appPath = appendToURL(SLIDER_PATH_APPLICATION, subpath)
     WebResource webResource = buildResource(appPath)
-    (T)webResource.get(c)
+    (T) webResource.method(method.verb, c)
   }
 
   /**
@@ -137,7 +146,13 @@ class JerseyTestDelegates extends SliderTestUtils {
     log.info jerseyGet(SYSTEM_METRICS)
   }
 
-  public <T> T fetchJType(
+  /**
+   * Fetch a typed entry <i>under the application path</i>
+   * @param subpath
+   * @param clazz
+   * @return
+   */
+  public <T> T jFetchType(
       String subpath, Class<T> clazz) {
     (T)jGetApplicationResource(subpath, clazz)
   }
@@ -149,7 +164,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     return tree
   }
 
-    public void testLiveResources() throws Throwable {
+  public void testLiveResources() throws Throwable {
     describe "Live Resources"
     ConfTreeOperations tree = jGetConfigTree(LIVE_RESOURCES)
 
@@ -190,7 +205,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "containers"
 
     SerializedContainerInformation retrievedContainerInfo =
-        fetchJType(
+        jFetchType(
             LIVE_CONTAINERS + "/${amContainerId}",
             SerializedContainerInformation
         )
@@ -198,7 +213,7 @@ class JerseyTestDelegates extends SliderTestUtils {
 
     // fetch missing
     try {
-      def result = fetchJType(
+      def result = jFetchType(
           LIVE_CONTAINERS + "/unknown",
           SerializedContainerInformation
       )
@@ -211,7 +226,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     describe "components"
 
     Map<String, SerializedComponentInformation> components =
-        fetchJType(LIVE_COMPONENTS, HashMap)
+        jFetchType(LIVE_COMPONENTS, HashMap)
     // two components
     assert components.size() == 1
     log.info "${components}"
@@ -219,7 +234,7 @@ class JerseyTestDelegates extends SliderTestUtils {
     SerializedComponentInformation amComponentInfo =
         (SerializedComponentInformation) components[COMPONENT_AM]
 
-    SerializedComponentInformation amFullInfo = fetchJType(
+    SerializedComponentInformation amFullInfo = jFetchType(
         LIVE_COMPONENTS + "/${COMPONENT_AM}",
         SerializedComponentInformation
     )
@@ -230,6 +245,39 @@ class JerseyTestDelegates extends SliderTestUtils {
   }
 
   /**
+   * Assert that a path resolves to an array list that contains
+   * those entries (and only those entries) expected
+   * @param appmaster AM ref
+   * @param path path under AM
+   * @param entries entries to assert the presence of
+   */
+  public void assertPathServesList(
+      String appmaster,
+      String path,
+      List<String> entries) {
+    def list = jFetchType(path, ArrayList)
+    assert list.size() == entries.size()
+    assert entries.containsAll(list)
+  }
+
+  /**
+   * Fetch a list of URLs, all of which must be of the same type
+   * @param clazz class of resolved values
+   * @param appmaster URL to app master
+   * @param subpaths list of subpaths
+   * @return a map of paths to values
+   */
+  public <T> Map<String, T> fetchTypeList(
+      Class<T> clazz, String appmaster, List<String> subpaths
+                                         ) {
+    Map<String, T> results = [:]
+    subpaths.each { String it ->
+      results[it] = (jFetchType(it, clazz))
+    }
+    return results;
+  }
+
+  /**
    * Test the rest model. For this to work the cluster has to be configured
    * with the global option
    * @param appmaster
@@ -241,14 +289,14 @@ class JerseyTestDelegates extends SliderTestUtils {
         MODEL,
         ApplicationResource.MODEL_ENTRIES)
 
-    def unresolvedConf = fetchJType(MODEL_DESIRED, AggregateConf)
+    def unresolvedConf = jFetchType(MODEL_DESIRED, AggregateConf)
 //    log.info "Unresolved \n$unresolvedConf"
     def unresolvedAppConf = unresolvedConf.appConfOperations
 
     def sam = "slider-appmaster"
     assert unresolvedAppConf.getComponentOpt(sam,
         TEST_GLOBAL_OPTION, "") == ""
-    def resolvedConf = fetchJType(MODEL_RESOLVED, AggregateConf)
+    def resolvedConf = jFetchType(MODEL_RESOLVED, AggregateConf)
 //    log.info "Resolved \n$resolvedConf"
     assert resolvedConf.appConfOperations.getComponentOpt(
         sam, TEST_GLOBAL_OPTION, "") == TEST_GLOBAL_OPTION_PRESENT
@@ -261,54 +309,28 @@ class JerseyTestDelegates extends SliderTestUtils {
 
     def resolved = fetchTypeList(ConfTree, appmaster,
         [MODEL_RESOLVED_APPCONF, MODEL_RESOLVED_RESOURCES])
-    assert resolved[MODEL_RESOLVED_APPCONF].components[sam]
-    [TEST_GLOBAL_OPTION] ==
-    TEST_GLOBAL_OPTION_PRESENT
-  }
-
-
-  public void testRestletGetOperations() throws Throwable {
-    Client client = createJerseyClient()
-    String path = appendToURL(application, LIVE_RESOURCES)
-    WebResource webResource = client.resource(path)
-    webResource.type(MediaType.APPLICATION_JSON)
-               .get(ConfTree.class);
+    assert resolved[MODEL_RESOLVED_APPCONF].
+               components[sam][TEST_GLOBAL_OPTION] == TEST_GLOBAL_OPTION_PRESENT
   }
 
   public void testPing() {
     // GET
-    String ping = appendToURL(appmaster, SLIDER_PATH_APPLICATION, ACTION_PING)
-    describe "ping to AM URL $appmaster, ping URL $ping"
-    def pinged = fetchJType(
-        ACTION_PING + "?body=hello",
-        PingResource
-    )
+    describe "pinging"
+    
+    def pinged = jExec(HttpVerb.GET, ACTION_PING, PingResource)
     log.info "Ping GET: $pinged"
-
-    URL pingUrl = new URL(ping)
-    def message = "hello"
-
     // HEAD
-    pingAction(HttpVerb.HEAD, pingUrl, message)
-
-    // Other verbs
-    pingAction(HttpVerb.POST, pingUrl, message)
-    pingAction(HttpVerb.PUT, pingUrl, message)
-    pingAction(HttpVerb.DELETE, pingUrl, message)
+    jExec(HttpVerb.HEAD, ACTION_PING, PingResource)
+    jExec(HttpVerb.PUT, ACTION_PING, PingResource)
+    jExec(HttpVerb.DELETE, ACTION_PING, PingResource)
+    jExec(HttpVerb.POST, ACTION_PING, PingResource)
 
   }
 
-
-  private HttpOperationResponse pingAction(
-      HttpVerb verb,
-      URL pingUrl,
-      String payload) {
-    return pingAction(connectionOperations, verb, pingUrl, payload)
-  }
-
   private HttpOperationResponse pingAction(
-      UrlConnectionOperations ops, HttpVerb verb, URL pingUrl, String payload) {
+      HttpVerb verb, String subpath, String payload) {
     def pinged
+    jExec(verb,subpath, PingResource)
     def outcome = ops.execHttpOperation(
         verb,
         pingUrl,
@@ -355,7 +377,7 @@ class JerseyTestDelegates extends SliderTestUtils {
         [url: ping],
         true,
         "AM failed to shut down") {
-      def pinged = fetchJType(ACTION_PING + "?body=hello",
+      def pinged = jFetchType(ACTION_PING + "?body=hello",
           PingResource
       )
       fail("AM didn't shut down; Ping GET= $pinged")
@@ -383,10 +405,10 @@ class JerseyTestDelegates extends SliderTestUtils {
 
   public void suite() {
 
-    testRestletGetOperations();
     testCodahaleOperations()
     testLiveResources()
     testLiveContainers();
+    testPing();
 
     testRESTModel()
   }