You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by jm...@apache.org on 2014/05/14 21:22:15 UTC

svn commit: r1594681 - in /incubator/slider/trunk/slider-core/src: main/java/org/apache/slider/core/registry/docstore/ main/java/org/apache/slider/server/appmaster/web/rest/publisher/ test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/

Author: jmaron
Date: Wed May 14 19:22:15 2014
New Revision: 1594681

URL: http://svn.apache.org/r1594681
Log:
SLIDER-51 add ability to retrieve single property from config file (and minor method name fix)

Modified:
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java
    incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java?rev=1594681&r1=1594680&r2=1594681&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java Wed May 14 19:22:15 2014
@@ -159,7 +159,7 @@ public class PublishedConfiguration {
     return sb.toString();
   }
   
-  public PublishedConfigurationOutputter creatOutputter(ConfigFormat format) {
+  public PublishedConfigurationOutputter createOutputter(ConfigFormat format) {
     return PublishedConfigurationOutputter.createOutputter(format, this);
   }
 }

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java?rev=1594681&r1=1594680&r2=1594681&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java Wed May 14 19:22:15 2014
@@ -36,6 +36,9 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
 import static  org.apache.slider.server.appmaster.web.rest.RestPaths.*;
 
 /**
@@ -136,9 +139,30 @@ public class PublisherResource {
     PublishedConfiguration publishedConfig =
         getConfigurationInstance(config, uriInfo, res);
     PublishedConfigurationOutputter outputter =
-        publishedConfig.creatOutputter(format);
+        publishedConfig.createOutputter(format);
     return outputter.asString();
   }
 
+  @GET
+  @Path("/{config}/{propertyName}")
+  @Produces({MediaType.APPLICATION_JSON})
+  public Map<String,String> getConfigurationProperty(
+      @PathParam("propertyName") String propertyName,
+      @PathParam("config") String config,
+      @Context UriInfo uriInfo,
+      @Context HttpServletResponse res) {
+    PublishedConfiguration publishedConfig =
+        getConfigurationInstance(config, uriInfo, res);
+    String propVal = publishedConfig.entries.get(propertyName);
+    if (propVal == null) {
+      log.info("Configuration property {} not found in configuration {}",
+               propertyName, config);
+      throw new NotFoundException("Property not found: " + propertyName);
+    }
+    Map<String,String> rtnVal = new HashMap<>();
+    rtnVal.put(propertyName, propVal);
 
+    return rtnVal;
+  }
+  
 }

Modified: incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy?rev=1594681&r1=1594680&r2=1594681&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy (original)
+++ incubator/slider/trunk/slider-core/src/test/groovy/org/apache/slider/server/appmaster/web/rest/publisher/TestPublisherRestResources.groovy Wed May 14 19:22:15 2014
@@ -111,6 +111,10 @@ class TestPublisherRestResources extends
     assert entries.get("prop1").equals("val1")
     assert entries.get("prop2").equals("val2")
 
+    webResource = client.resource(publisher_url + "/dummy-site/prop1");
+    Map<String,String> val = webResource.type(MediaType.APPLICATION_JSON).get(Map.class);
+    assert "val1".equals(val.get("prop1"))
+
     // some negative tests...
     webResource = client.resource(appendToURL(publisher_url,
         "/foobar-site"));
@@ -118,6 +122,11 @@ class TestPublisherRestResources extends
     ClientResponse response = webResource.type(MediaType.APPLICATION_JSON)
                          .get(ClientResponse.class);
     assert response.getStatus() == 404
+
+    webResource = client.resource(publisher_url + "/dummy-site/missing.prop");
+    response = webResource.type(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+    assert response.getStatus() == 404
+
  }
 
 }