SLIDER-51 add ability to retrieve single property from config file (and minor method name fix)
git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1594681 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java b/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java
index 26bb3ef..8f8abe9 100644
--- a/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java
+++ b/slider-core/src/main/java/org/apache/slider/core/registry/docstore/PublishedConfiguration.java
@@ -159,7 +159,7 @@
return sb.toString();
}
- public PublishedConfigurationOutputter creatOutputter(ConfigFormat format) {
+ public PublishedConfigurationOutputter createOutputter(ConfigFormat format) {
return PublishedConfigurationOutputter.createOutputter(format, this);
}
}
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java
index c9b8838..fc487fe 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/web/rest/publisher/PublisherResource.java
@@ -36,6 +36,9 @@
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 @@
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;
+ }
+
}
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 bcda69a..0100d7a 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
@@ -111,6 +111,10 @@
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 @@
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
+
}
}