SLIDER-713: I'm not sure that Jersey is handling PUT the way it is meant to


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

Branch: refs/heads/develop
Commit: c394aef473136db7d3072f8f70ae8a658a494710
Parents: 2dc7b33
Author: Steve Loughran <[email protected]>
Authored: Tue Feb 17 21:12:42 2015 +0000
Committer: Steve Loughran <[email protected]>
Committed: Tue Feb 17 21:12:42 2015 +0000

----------------------------------------------------------------------
 .../rest/SliderApplicationApiRestClient.java    | 11 +++---
 .../rest/AbstractAppApiTestDelegates.groovy     | 37 +++++++++++++++++---
 .../rest/RestAPIClientTestDelegates.groovy      | 18 ++++++++--
 3 files changed, 54 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c394aef4/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java
----------------------------------------------------------------------
diff --git 
a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java
 
b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java
index 4d09d95..29c6bc6 100644
--- 
a/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java
+++ 
b/slider-core/src/main/java/org/apache/slider/client/rest/SliderApplicationApiRestClient.java
@@ -171,15 +171,16 @@ public class SliderApplicationApiRestClient extends 
BaseRestClient
   public void putDesiredResources(ConfTree updated) throws IOException {
     WebResource resource = applicationResource(MODEL_DESIRED_RESOURCES);
     try {
+      resource.accept(MediaType.APPLICATION_JSON_TYPE);
       // entity to put
       resource.entity(updated, MediaType.APPLICATION_JSON_TYPE);
-      
+
       // put operation. The result is discarded; it does help validate
       // that the operation returned a JSON data structure as well as a 200
       // response.
-      //resource.put(ConfTree.class);
-      resource.put(ClientResponse.class);
-      } catch (ClientHandlerException ex) {
+      resource.put(ConfTree.class);
+      //ClientResponse response = resource.put(ClientResponse.class);
+    } catch (ClientHandlerException ex) {
         throw ExceptionConverter.convertJerseyException("PUT",
             resource.getURI().toString(),
             ex);
@@ -288,7 +289,7 @@ public class SliderApplicationApiRestClient extends 
BaseRestClient
     pingResource.type(MediaType.APPLICATION_JSON_TYPE);
     Form f = new Form();
     f.add("text", text);
-    return pingResource.post(PingInformation.class, f);
+    return pingResource.put(PingInformation.class, f);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c394aef4/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy
 
b/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy
index 724a4d2..2196f81 100644
--- 
a/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy
+++ 
b/slider-core/src/test/groovy/org/apache/slider/agent/rest/AbstractAppApiTestDelegates.groovy
@@ -174,6 +174,7 @@ public abstract class AbstractAppApiTestDelegates extends 
AbstractRestTestDelega
     
     appAPI.ping("hello")
   }
+  
   /**
    * Test the stop command.
    * Important: once executed, the AM is no longer there.
@@ -228,15 +229,41 @@ public abstract class AbstractAppApiTestDelegates extends 
AbstractRestTestDelega
   }
 
   public void testFlexOperation() {
-    // no-op flex; get current state and push out again.
+    // get current state
     def current = appAPI.getDesiredResources()
 
+    // create a guaranteed unique field
     def uuid = UUID.randomUUID()
-    current.set("yarn.test.noop", uuid)
+    def field = "yarn.test.flex.uuid"
+    current.set(field, uuid)
     appAPI.putDesiredResources(current.confTree)
-    
-    
-    
+    repeatUntilSuccess("probe for liveness",
+        this.&probeForResolveConfValues, 
+        5000, 200,
+        [
+            "key": field,
+            "val": uuid
+        ],
+        true,
+        "Flex resources failed to propagate") {
+      def resolved = appAPI.getResolvedResources()
+      fail("Did not find field $field=$uuid in\n$resolved")
+    }
+  }
+
+  /**
+   * Probe that spins until the field has desired value
+   * in the resolved resource
+   * @param args argument map. key=field, val=value
+   * @return the outcome
+   */
+  Outcome probeForResolveConfValues(Map args) {
+    assert args["key"]
+    assert args["val"]
+    String key = args["key"]
+    String val  = args["val"]
+    def resolved = appAPI.getResolvedResources()
+    return Outcome.fromBool(resolved.get(key)==val)
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c394aef4/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy
----------------------------------------------------------------------
diff --git 
a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy
 
b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy
index 99129e5..79bb16a 100644
--- 
a/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.groovy
+++ 
b/slider-core/src/test/groovy/org/apache/slider/agent/rest/RestAPIClientTestDelegates.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.filter.LoggingFilter
 import groovy.transform.CompileStatic
 import groovy.util.logging.Slf4j
 import org.apache.slider.client.rest.SliderApplicationApiRestClient
@@ -35,6 +36,7 @@ import static 
org.apache.slider.server.appmaster.web.rest.RestPaths.SLIDER_PATH_
 @CompileStatic
 @Slf4j
 class RestAPIClientTestDelegates extends AbstractAppApiTestDelegates {
+  private SliderApplicationApiRestClient restClient
 
   /**
    * constructor
@@ -48,8 +50,20 @@ class RestAPIClientTestDelegates extends 
AbstractAppApiTestDelegates {
     WebResource amResource = jersey.resource(appmaster)
     amResource.type(MediaType.APPLICATION_JSON)
     def appResource = amResource.path(SLIDER_PATH_APPLICATION);
-    appAPI = new SliderApplicationApiRestClient(jersey, appResource)
+    // test runs log
+    jersey.addFilter(new LoggingFilter(System.out));
+    restClient = new SliderApplicationApiRestClient(
+        jersey,
+        appResource)
+    appAPI = restClient
   }
 
-
+  @Override
+  void testPing() {
+    super.testPing()
+    // test the other verbs
+    restClient.pingPut("Put!")
+    restClient.pingGet("Get!")
+    restClient.pingPost("Post!")
+  }
 }

Reply via email to