You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/02/18 11:48:30 UTC
[1/2] incubator-brooklyn git commit: Adds getConfig method to server
REST API to allow client code to read properties
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 2835106ac -> 6c72bd4c7
Adds getConfig method to server REST API to allow client code to read properties
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/b0b2de49
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/b0b2de49
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/b0b2de49
Branch: refs/heads/master
Commit: b0b2de49983c35262d2f398edb4276c594943390
Parents: ddf0a44
Author: Martin Harris <gi...@nakomis.com>
Authored: Mon Feb 16 11:13:03 2015 +0000
Committer: Martin Harris <gi...@nakomis.com>
Committed: Mon Feb 16 11:13:03 2015 +0000
----------------------------------------------------------------------
.../main/java/brooklyn/rest/api/ServerApi.java | 15 ++++++++
.../brooklyn/rest/resources/ServerResource.java | 11 ++++++
.../rest/resources/ServerResourceTest.java | 40 +++++++++++++++++++-
3 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b0b2de49/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
index 6621ce1..624c9db 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
@@ -26,6 +26,7 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@@ -38,6 +39,8 @@ import brooklyn.rest.domain.HighAvailabilitySummary;
import brooklyn.rest.domain.VersionSummary;
import com.google.common.annotations.Beta;
+import com.wordnik.swagger.core.ApiError;
+import com.wordnik.swagger.core.ApiErrors;
import com.wordnik.swagger.core.ApiOperation;
import com.wordnik.swagger.core.ApiParam;
@@ -87,6 +90,18 @@ public interface ServerApi {
multiValueResponse = false)
public String getStatus();
+ @GET
+ @Path("/config/{configKey}")
+ @ApiOperation(value = "Get the value of the specified config key from brooklyn properties")
+ @ApiErrors(value = {
+ // TODO: This should probably return a 404 if the key is not present, and should return a predictable
+ // value if the value is not set. Behaviour should be consistent with EntityConfigApi.get()
+ @ApiError(code = 204, reason = "Could not find config key")
+ })
+ public String getConfig(
+ @ApiParam(value = "Config key ID", required = true)
+ @PathParam("configKey") String configKey);
+
@Deprecated /** @deprecated since 0.7.0 use /ha/states */
@GET
@Path("/highAvailability")
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b0b2de49/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
index 2ee3f9c..b6ed8ec 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
@@ -33,6 +33,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.basic.ConfigKeys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -238,6 +240,15 @@ public class ServerResource extends AbstractBrooklynRestResource implements Serv
return getHighAvailabilityNodeState().toString();
}
+ @Override
+ public String getConfig(String configKey) {
+ if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ALL_SERVER_INFO, null)) {
+ throw WebResourceUtils.unauthorized("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user());
+ }
+ ConfigKey<String> config = ConfigKeys.newStringConfigKey(configKey);
+ return mgmt().getConfig().getConfig(config);
+ }
+
@Deprecated
@Override
public HighAvailabilitySummary getHighAvailability() {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/b0b2de49/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
index d7411c3..26491b3 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
@@ -21,10 +21,16 @@ package brooklyn.rest.resources;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicInteger;
+import brooklyn.config.BrooklynProperties;
+import brooklyn.management.internal.ManagementContextInternal;
+import com.google.common.collect.ImmutableMap;
+import com.sun.jersey.api.client.UniformInterfaceException;
+import com.sun.jersey.api.client.WebResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
@@ -97,5 +103,37 @@ public class ServerResourceTest extends BrooklynRestResourceTest {
assertFalse(getManagementContext().isRunning());
}});
}
-
+
+ @Test
+ void testGetConfig() throws Exception {
+ ((ManagementContextInternal)getManagementContext()).getBrooklynProperties().put("foo.bar.baz", "quux");
+ try {
+ assertEquals(client().resource("/v1/server/config/foo.bar.baz").get(String.class), "quux");
+ } finally {
+ ((ManagementContextInternal)getManagementContext()).getBrooklynProperties().remove("foo.bar.baz");
+ }
+ }
+
+ @Test
+ void testGetMissingConfigThrowsException() throws Exception {
+ final String key = "foo.bar.baz";
+ BrooklynProperties properties = ((ManagementContextInternal)getManagementContext()).getBrooklynProperties();
+ Object existingValue = null;
+ boolean keyAlreadyPresent = false;
+ String response = null;
+ if (properties.containsKey(key)) {
+ existingValue = properties.remove(key);
+ keyAlreadyPresent = true;
+ }
+ try {
+ response = client().resource("/v1/server/config/" + key).get(String.class);
+ Asserts.fail("Expected call to /v1/server/config/" + key + " to fail with status 404, instead server returned " + response);
+ } catch (UniformInterfaceException e) {
+ assertEquals(e.getResponse().getStatus(), 204);
+ } finally {
+ if (keyAlreadyPresent) {
+ properties.put(key, existingValue);
+ }
+ }
+ }
}
[2/2] incubator-brooklyn git commit: This closes #509
Posted by al...@apache.org.
This closes #509
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6c72bd4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6c72bd4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6c72bd4c
Branch: refs/heads/master
Commit: 6c72bd4c7e5c2096920cd1c6709bf486a6a430d9
Parents: 2835106 b0b2de4
Author: Aled Sage <al...@gmail.com>
Authored: Wed Feb 18 10:48:16 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Feb 18 10:48:16 2015 +0000
----------------------------------------------------------------------
----------------------------------------------------------------------