Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 412DF17E84 for ; Wed, 18 Feb 2015 10:46:15 +0000 (UTC) Received: (qmail 63236 invoked by uid 500); 18 Feb 2015 10:46:15 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 63212 invoked by uid 500); 18 Feb 2015 10:46:15 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 63203 invoked by uid 99); 18 Feb 2015 10:46:15 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2015 10:46:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 18 Feb 2015 10:45:52 +0000 Received: (qmail 62203 invoked by uid 99); 18 Feb 2015 10:45:49 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Feb 2015 10:45:49 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CEE1AE0777; Wed, 18 Feb 2015 10:45:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 18 Feb 2015 10:45:49 -0000 Message-Id: <3e81a94714fc4b3fbccce587e9a82d14@git.apache.org> In-Reply-To: <21eb17e812b141f78f8a219c98a0e765@git.apache.org> References: <21eb17e812b141f78f8a219c98a0e765@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] incubator-brooklyn git commit: Adds getConfig method to server REST API to allow client code to read properties X-Virus-Checked: Checked by ClamAV on apache.org 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/5ee01b8a Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5ee01b8a Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5ee01b8a Branch: refs/heads/master Commit: 5ee01b8a774c8dd0f09bdef5dfe55d8efde88df5 Parents: e0cc1a6 Author: Martin Harris Authored: Mon Feb 16 11:13:03 2015 +0000 Committer: Aled Sage Committed: Wed Feb 18 10:45:37 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/5ee01b8a/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/5ee01b8a/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 caacc29..6f8465e 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; @@ -253,6 +255,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 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/5ee01b8a/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); + } + } + } }