You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/11/05 18:29:40 UTC
[1/9] incubator-brooklyn git commit: HTTP connection pooling for
BrooklynApi clients
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master f52d9e052 -> 40de86652
HTTP connection pooling for BrooklynApi clients
- introduce factories to create clients
- PoolingBrooklynApiFactory uses PoolingHttpClientConnectionManager
- DefaultBrooklynApiFactory replaces the old BrooklynApi constructors
using a new ApacheHttpClient4Executor for each client
- deprecate existing BrooklynApi constructors
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/971c217d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/971c217d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/971c217d
Branch: refs/heads/master
Commit: 971c217d220986aece361b312b0793e4239d3d26
Parents: 48e4fe3
Author: googlielmo <gu...@cloudsoftcorp.com>
Authored: Wed Nov 4 14:30:05 2015 +0100
Committer: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Committed: Wed Nov 4 15:43:12 2015 +0100
----------------------------------------------------------------------
.../brooklyn/rest/client/BrooklynApi.java | 52 ++++++++-
.../rest/client/BrooklynApiFactory.java | 29 +++++
.../rest/client/DefaultBrooklynApiFactory.java | 50 +++++++++
.../rest/client/PoolingBrooklynApiFactory.java | 108 +++++++++++++++++++
.../ApplicationResourceIntegrationTest.java | 5 +-
.../rest/client/BrooklynApiRestClientTest.java | 5 +-
6 files changed, 245 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
index fa3b7ee..184b659 100644
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
@@ -33,7 +33,7 @@ import javax.ws.rs.core.Response;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.*;
import org.jboss.resteasy.client.ClientExecutor;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
@@ -76,27 +76,63 @@ public class BrooklynApi {
private final ClientExecutor clientExecutor;
private static final Logger LOG = LoggerFactory.getLogger(BrooklynApi.class);
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(URL endpoint) {
this(checkNotNull(endpoint, "endpoint").toString());
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(String endpoint) {
// username/password cannot be null, but credentials can
this(endpoint, null);
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(URL endpoint, String username, String password) {
this(endpoint.toString(), new UsernamePasswordCredentials(username, password));
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(String endpoint, String username, String password) {
this(endpoint, new UsernamePasswordCredentials(username, password));
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(URL endpoint, @Nullable Credentials credentials) {
this(endpoint.toString(), credentials);
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(String endpoint, @Nullable Credentials credentials) {
try {
new URL(checkNotNull(endpoint, "endpoint"));
@@ -114,11 +150,23 @@ public class BrooklynApi {
}
}
+ /**
+ * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
+ * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
+ * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ */
+ @Deprecated
public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
this.target = checkNotNull(endpoint, "endpoint").toString();
this.clientExecutor = checkNotNull(clientExecutor, "clientExecutor");
}
+ // to be used by factories
+ BrooklynApi(ClientExecutor clientExecutor, URL endpoint) {
+ this.target = checkNotNull(endpoint, "endpoint").toString();
+ this.clientExecutor = checkNotNull(clientExecutor, "clientExecutor");
+ }
+
@SuppressWarnings("unchecked")
private <T> T proxy(Class<T> clazz) {
final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
@@ -252,7 +300,7 @@ public class BrooklynApi {
}
/**
- * @deprecated Use {@link #getEntity(Response, GenericType)} instead.
+ * @deprecated since 0.9.0. Use {@link #getEntity(Response, GenericType)} instead.
*/
@Deprecated
public static <T> T getEntityGeneric(Response response, GenericType<T> type) {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
new file mode 100644
index 0000000..b32c227
--- /dev/null
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.rest.client;
+
+import java.net.URL;
+
+/**
+ * Creates {@link BrooklynApi} instances.
+ */
+public interface BrooklynApiFactory {
+
+ BrooklynApi getBrooklynApi(URL endpoint, String username, String password);
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
new file mode 100644
index 0000000..48e0eeb
--- /dev/null
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.rest.client;
+
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.jboss.resteasy.client.ClientExecutor;
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
+
+import java.net.URL;
+
+/**
+ * BrooklynApi factory.
+ * <p/>
+ * This Factory creates BrooklynApi instances that use an {@link ApacheHttpClient4Executor}
+ */
+public class DefaultBrooklynApiFactory implements BrooklynApiFactory {
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public BrooklynApi getBrooklynApi(URL endpoint, String username, String password) {
+ ClientExecutor clientExecutor;
+ if (username != null) {
+ DefaultHttpClient httpClient = new DefaultHttpClient();
+ httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
+ clientExecutor = new ApacheHttpClient4Executor(httpClient);
+ } else {
+ clientExecutor = ClientRequest.getDefaultExecutor();
+ }
+ return new BrooklynApi(clientExecutor, endpoint);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
new file mode 100644
index 0000000..f58f4f5
--- /dev/null
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.rest.client;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.jboss.resteasy.client.ClientExecutor;
+import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
+
+import java.net.URL;
+
+/**
+ * BrooklynApi factory.
+ * <p/>
+ * This Factory uses a {@link PoolingHttpClientConnectionManager} to reuse HTTP connections.
+ */
+public class PoolingBrooklynApiFactory implements BrooklynApiFactory {
+
+ private Supplier<PoolingHttpClientConnectionManager> connectionManagerSupplier = Suppliers.memoize(new Supplier<PoolingHttpClientConnectionManager>() {
+ @Override
+ public PoolingHttpClientConnectionManager get() {
+ PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
+ connManager.setMaxTotal(maxPoolSize);
+ connManager.setDefaultMaxPerRoute(maxPoolSize);
+ return connManager;
+ }
+ });
+
+ private Supplier<RequestConfig> reqConfSupplier = Suppliers.memoize(new Supplier<RequestConfig>() {
+ @Override
+ public RequestConfig get() {
+
+ return RequestConfig.custom()
+ .setConnectTimeout(timeOutInMillis)
+ .setConnectionRequestTimeout(timeOutInMillis)
+ .build();
+ }
+ });
+
+ protected final int maxPoolSize;
+ protected final int timeOutInMillis;
+
+ @SuppressWarnings("deprecation")
+ private ClientExecutor getPoolingClientExecutor(Credentials credentials) {
+ CredentialsProvider provider = new BasicCredentialsProvider();
+ provider.setCredentials(AuthScope.ANY, credentials);
+
+ CloseableHttpClient httpClient = HttpClients.custom()
+ .setDefaultCredentialsProvider(provider)
+ .setDefaultRequestConfig(reqConfSupplier.get())
+ .setConnectionManager(connectionManagerSupplier.get())
+ .build();
+
+ return new ApacheHttpClient4Executor(httpClient);
+ }
+
+ /**
+ * Creates a new PoolingBrooklynApiFactory with a max pool size of 20
+ * connections, and a connection timeout of 5000 milliseconds
+ */
+ public PoolingBrooklynApiFactory() {
+ this(20, 5000);
+ }
+
+ /**
+ * Creates a new PoolingBrooklynApiFactory
+ * @param maxPoolSize the maximum size of the pool
+ * @param timeOutInMillis connection timeout in milliseconds
+ */
+ public PoolingBrooklynApiFactory(int maxPoolSize, int timeOutInMillis) {
+ this.maxPoolSize = maxPoolSize;
+ this.timeOutInMillis = timeOutInMillis;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public BrooklynApi getBrooklynApi(URL endpoint, String username, String password) {
+ UsernamePasswordCredentials credentials =
+ (username != null) ? new UsernamePasswordCredentials(username, password)
+ : null;
+ return new BrooklynApi(getPoolingClientExecutor(credentials), endpoint);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
index 61facc7..7015113 100644
--- a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
+++ b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
@@ -22,6 +22,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
+import java.net.URL;
import java.util.Collection;
import javax.ws.rs.core.Response;
@@ -88,7 +89,9 @@ public class ApplicationResourceIntegrationTest {
.managementContext(getManagementContext())
.start();
- api = new BrooklynApi("http://localhost:" + server.getConnectors()[0].getPort() + "/");
+ DefaultBrooklynApiFactory defaultBrooklynApiFactory = new DefaultBrooklynApiFactory();
+
+ api = defaultBrooklynApiFactory.getBrooklynApi(new URL("http://localhost:" + server.getConnectors()[0].getPort() + "/"), null, null);
}
@AfterClass(alwaysRun = true)
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/971c217d/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
index 62c95b6..abc3bfe 100644
--- a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
+++ b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.brooklyn.rest.client;
+import java.net.URL;
import java.util.List;
import java.util.Map;
@@ -70,7 +71,9 @@ public class BrooklynApiRestClientTest {
.securityProvider(TestSecurityProvider.class)
.start();
- api = new BrooklynApi("http://localhost:" + server.getConnectors()[0].getPort() + "/",
+ DefaultBrooklynApiFactory defaultBrooklynApiFactory = new DefaultBrooklynApiFactory();
+
+ api = defaultBrooklynApiFactory.getBrooklynApi(new URL("http://localhost:" + server.getConnectors()[0].getPort() + "/"),
TestSecurityProvider.USER, TestSecurityProvider.PASSWORD);
}
[8/9] incubator-brooklyn git commit: This closes #1003
Posted by he...@apache.org.
This closes #1003
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/4f479ddf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/4f479ddf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/4f479ddf
Branch: refs/heads/master
Commit: 4f479ddf99bf81b360b38d14041e9e8285b3f4ea
Parents: 8ef608d 19c215b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Nov 5 09:28:06 2015 -0800
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Nov 5 09:28:06 2015 -0800
----------------------------------------------------------------------
.../vault/VaultAppIdExternalConfigSupplier.java | 71 ++++++
.../vault/VaultExternalConfigSupplier.java | 114 ++++++++++
.../vault/VaultTokenExternalConfigSupplier.java | 23 ++
.../VaultUserPassExternalConfigSupplier.java | 39 ++++
.../VaultExternalConfigSupplierLiveTest.java | 151 +++++++++++++
docs/guide/ops/externalized-configuration.md | 225 +++++++++++++++++++
docs/guide/ops/index.md | 1 +
7 files changed, 624 insertions(+)
----------------------------------------------------------------------
[3/9] incubator-brooklyn git commit: Per client HTTP connection
pooling
Posted by he...@apache.org.
Per client HTTP connection pooling
Implementation with static factory method
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/934bb74f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/934bb74f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/934bb74f
Branch: refs/heads/master
Commit: 934bb74f77a53eaaea0ea6e3425bd6b40c02d454
Parents: 971c217
Author: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Authored: Thu Nov 5 12:45:30 2015 +0100
Committer: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Committed: Thu Nov 5 12:45:30 2015 +0100
----------------------------------------------------------------------
.../brooklyn/rest/client/BrooklynApi.java | 172 ++++++++++++++-----
.../rest/client/BrooklynApiFactory.java | 29 ----
.../rest/client/DefaultBrooklynApiFactory.java | 50 ------
.../rest/client/PoolingBrooklynApiFactory.java | 108 ------------
.../ApplicationResourceIntegrationTest.java | 4 +-
.../rest/client/BrooklynApiRestClientTest.java | 4 +-
6 files changed, 131 insertions(+), 236 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
index 184b659..e848f99 100644
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
@@ -30,12 +30,18 @@ import java.net.URL;
import javax.annotation.Nullable;
import javax.ws.rs.core.Response;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.impl.client.*;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.jboss.resteasy.client.ClientExecutor;
-import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
@@ -68,18 +74,18 @@ import com.wordnik.swagger.core.ApiOperation;
/**
* @author Adam Lowe
- */
+ */
@SuppressWarnings("deprecation")
public class BrooklynApi {
private final String target;
private final ClientExecutor clientExecutor;
+ private final int maxPoolSize;
+ private final int timeOutInMillis;
private static final Logger LOG = LoggerFactory.getLogger(BrooklynApi.class);
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String)} instead
*/
@Deprecated
public BrooklynApi(URL endpoint) {
@@ -87,9 +93,7 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String)} instead
*/
@Deprecated
public BrooklynApi(String endpoint) {
@@ -98,9 +102,7 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String, String, String)} instead
*/
@Deprecated
public BrooklynApi(URL endpoint, String username, String password) {
@@ -108,9 +110,7 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String, String, String)} instead
*/
@Deprecated
public BrooklynApi(String endpoint, String username, String password) {
@@ -118,9 +118,7 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String, String, String)} instead
*/
@Deprecated
public BrooklynApi(URL endpoint, @Nullable Credentials credentials) {
@@ -128,43 +126,131 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @deprecated since 0.9.0. Use {@link BrooklynApi#newInstance(String, String, String)} instead
*/
@Deprecated
public BrooklynApi(String endpoint, @Nullable Credentials credentials) {
+ this(endpoint, credentials, 20, 5000);
+ }
+
+ /**
+ * Creates a BrooklynApi using a custom ClientExecutor
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @param clientExecutor the ClientExecutor
+ * @see #getClientExecutor(org.apache.http.auth.Credentials)
+ */
+ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
+ this.target = checkNotNull(endpoint, "endpoint").toString();
+ this.maxPoolSize = -1;
+ this.timeOutInMillis = -1;
+ this.clientExecutor = checkNotNull(clientExecutor, "clientExecutor");
+ }
+
+ /**
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @param credentials user credentials or null
+ * @param maxPoolSize maximum pool size
+ * @param timeOutInMillis connection timeout in milliseconds
+ */
+ public BrooklynApi(String endpoint, @Nullable Credentials credentials, int maxPoolSize, int timeOutInMillis) {
try {
new URL(checkNotNull(endpoint, "endpoint"));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
-
this.target = endpoint;
- if (credentials != null) {
- DefaultHttpClient httpClient = new DefaultHttpClient();
- httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
- this.clientExecutor = new ApacheHttpClient4Executor(httpClient);
- } else {
- this.clientExecutor = ClientRequest.getDefaultExecutor();
+ this.maxPoolSize = maxPoolSize;
+ this.timeOutInMillis = timeOutInMillis;
+ this.clientExecutor = getClientExecutor(credentials);
+ }
+
+ private Supplier<PoolingHttpClientConnectionManager> connectionManagerSupplier = Suppliers.memoize(new Supplier<PoolingHttpClientConnectionManager>() {
+ @Override
+ public PoolingHttpClientConnectionManager get() {
+ PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
+ connManager.setMaxTotal(maxPoolSize);
+ connManager.setDefaultMaxPerRoute(maxPoolSize);
+ return connManager;
}
+ });
+
+ private Supplier<RequestConfig> reqConfSupplier = Suppliers.memoize(new Supplier<RequestConfig>() {
+ @Override
+ public RequestConfig get() {
+ return RequestConfig.custom()
+ .setConnectTimeout(timeOutInMillis)
+ .setConnectionRequestTimeout(timeOutInMillis)
+ .build();
+ }
+ });
+
+ /**
+ * Creates a ClientExecutor for this BrooklynApi
+ */
+ protected ClientExecutor getClientExecutor(Credentials credentials) {
+ CredentialsProvider provider = new BasicCredentialsProvider();
+ if (credentials != null) provider.setCredentials(AuthScope.ANY, credentials);
+
+ CloseableHttpClient httpClient = HttpClients.custom()
+ .setDefaultCredentialsProvider(provider)
+ .setDefaultRequestConfig(reqConfSupplier.get())
+ .setConnectionManager(connectionManagerSupplier.get())
+ .build();
+
+ return new ApacheHttpClient4Executor(httpClient);
}
/**
- * @deprecated since 0.9.0. Use {@link BrooklynApiFactory#getBrooklynApi(java.net.URL, String, String)} instead
- * @see org.apache.brooklyn.rest.client.DefaultBrooklynApiFactory
- * @see org.apache.brooklyn.rest.client.PoolingBrooklynApiFactory
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @return a new BrooklynApi instance
*/
- @Deprecated
- public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
- this.target = checkNotNull(endpoint, "endpoint").toString();
- this.clientExecutor = checkNotNull(clientExecutor, "clientExecutor");
+ public static BrooklynApi newInstance(String endpoint) {
+ return new BrooklynApi(endpoint, null);
}
- // to be used by factories
- BrooklynApi(ClientExecutor clientExecutor, URL endpoint) {
- this.target = checkNotNull(endpoint, "endpoint").toString();
- this.clientExecutor = checkNotNull(clientExecutor, "clientExecutor");
+ /**
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @param maxPoolSize maximum connection pool size
+ * @param timeOutInMillis connection timeout in millisecond
+ * @return a new BrooklynApi instance
+ */
+ public static BrooklynApi newInstance(String endpoint, int maxPoolSize, int timeOutInMillis) {
+ return new BrooklynApi(endpoint, null, maxPoolSize, timeOutInMillis);
+ }
+
+ /**
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @param username for authentication
+ * @param password for authentication
+ * @return a new BrooklynApi instance
+ */
+ public static BrooklynApi newInstance(String endpoint, String username, String password) {
+ return new BrooklynApi(endpoint, new UsernamePasswordCredentials(username, password));
+ }
+
+ /**
+ * Creates a BrooklynApi using an HTTP connection pool
+ *
+ * @param endpoint the Brooklyn endpoint
+ * @param username for authentication
+ * @param password for authentication
+ * @param maxPoolSize maximum connection pool size
+ * @param timeOutInMillis connection timeout in millisecond
+ * @return a new BrooklynApi instance
+ */
+ public static BrooklynApi newInstance(String endpoint, String username, String password, int maxPoolSize, int timeOutInMillis) {
+ return new BrooklynApi(endpoint, new UsernamePasswordCredentials(username, password), maxPoolSize, timeOutInMillis);
}
@SuppressWarnings("unchecked")
@@ -172,7 +258,7 @@ public class BrooklynApi {
final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
@Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
Object result1 = method.invoke(result0, args);
Class<?> type = String.class;
@@ -191,11 +277,11 @@ public class BrooklynApi {
e = ((InvocationTargetException)e).getTargetException();
}
throw Exceptions.propagate(e);
- }
+ }
}
-
+
private boolean isStatusCodeHealthy(int code) { return (code>=200 && code<=299); }
-
+
private Class<?> getClassFromMethodAnnotationOrDefault(Method method, Class<?> def){
Class<?> type;
try{
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
deleted file mode 100644
index b32c227..0000000
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiFactory.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.client;
-
-import java.net.URL;
-
-/**
- * Creates {@link BrooklynApi} instances.
- */
-public interface BrooklynApiFactory {
-
- BrooklynApi getBrooklynApi(URL endpoint, String username, String password);
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
deleted file mode 100644
index 48e0eeb..0000000
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/DefaultBrooklynApiFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.client;
-
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.jboss.resteasy.client.ClientExecutor;
-import org.jboss.resteasy.client.ClientRequest;
-import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
-
-import java.net.URL;
-
-/**
- * BrooklynApi factory.
- * <p/>
- * This Factory creates BrooklynApi instances that use an {@link ApacheHttpClient4Executor}
- */
-public class DefaultBrooklynApiFactory implements BrooklynApiFactory {
-
- @SuppressWarnings("deprecation")
- @Override
- public BrooklynApi getBrooklynApi(URL endpoint, String username, String password) {
- ClientExecutor clientExecutor;
- if (username != null) {
- DefaultHttpClient httpClient = new DefaultHttpClient();
- httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
- clientExecutor = new ApacheHttpClient4Executor(httpClient);
- } else {
- clientExecutor = ClientRequest.getDefaultExecutor();
- }
- return new BrooklynApi(clientExecutor, endpoint);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
deleted file mode 100644
index f58f4f5..0000000
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/PoolingBrooklynApiFactory.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.rest.client;
-
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.jboss.resteasy.client.ClientExecutor;
-import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
-
-import java.net.URL;
-
-/**
- * BrooklynApi factory.
- * <p/>
- * This Factory uses a {@link PoolingHttpClientConnectionManager} to reuse HTTP connections.
- */
-public class PoolingBrooklynApiFactory implements BrooklynApiFactory {
-
- private Supplier<PoolingHttpClientConnectionManager> connectionManagerSupplier = Suppliers.memoize(new Supplier<PoolingHttpClientConnectionManager>() {
- @Override
- public PoolingHttpClientConnectionManager get() {
- PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
- connManager.setMaxTotal(maxPoolSize);
- connManager.setDefaultMaxPerRoute(maxPoolSize);
- return connManager;
- }
- });
-
- private Supplier<RequestConfig> reqConfSupplier = Suppliers.memoize(new Supplier<RequestConfig>() {
- @Override
- public RequestConfig get() {
-
- return RequestConfig.custom()
- .setConnectTimeout(timeOutInMillis)
- .setConnectionRequestTimeout(timeOutInMillis)
- .build();
- }
- });
-
- protected final int maxPoolSize;
- protected final int timeOutInMillis;
-
- @SuppressWarnings("deprecation")
- private ClientExecutor getPoolingClientExecutor(Credentials credentials) {
- CredentialsProvider provider = new BasicCredentialsProvider();
- provider.setCredentials(AuthScope.ANY, credentials);
-
- CloseableHttpClient httpClient = HttpClients.custom()
- .setDefaultCredentialsProvider(provider)
- .setDefaultRequestConfig(reqConfSupplier.get())
- .setConnectionManager(connectionManagerSupplier.get())
- .build();
-
- return new ApacheHttpClient4Executor(httpClient);
- }
-
- /**
- * Creates a new PoolingBrooklynApiFactory with a max pool size of 20
- * connections, and a connection timeout of 5000 milliseconds
- */
- public PoolingBrooklynApiFactory() {
- this(20, 5000);
- }
-
- /**
- * Creates a new PoolingBrooklynApiFactory
- * @param maxPoolSize the maximum size of the pool
- * @param timeOutInMillis connection timeout in milliseconds
- */
- public PoolingBrooklynApiFactory(int maxPoolSize, int timeOutInMillis) {
- this.maxPoolSize = maxPoolSize;
- this.timeOutInMillis = timeOutInMillis;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public BrooklynApi getBrooklynApi(URL endpoint, String username, String password) {
- UsernamePasswordCredentials credentials =
- (username != null) ? new UsernamePasswordCredentials(username, password)
- : null;
- return new BrooklynApi(getPoolingClientExecutor(credentials), endpoint);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
index 7015113..645fd8b 100644
--- a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
+++ b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/ApplicationResourceIntegrationTest.java
@@ -89,9 +89,7 @@ public class ApplicationResourceIntegrationTest {
.managementContext(getManagementContext())
.start();
- DefaultBrooklynApiFactory defaultBrooklynApiFactory = new DefaultBrooklynApiFactory();
-
- api = defaultBrooklynApiFactory.getBrooklynApi(new URL("http://localhost:" + server.getConnectors()[0].getPort() + "/"), null, null);
+ api = BrooklynApi.newInstance("http://localhost:" + server.getConnectors()[0].getPort() + "/");
}
@AfterClass(alwaysRun = true)
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/934bb74f/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
index abc3bfe..f952c01 100644
--- a/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
+++ b/usage/rest-client/src/test/java/org/apache/brooklyn/rest/client/BrooklynApiRestClientTest.java
@@ -71,9 +71,7 @@ public class BrooklynApiRestClientTest {
.securityProvider(TestSecurityProvider.class)
.start();
- DefaultBrooklynApiFactory defaultBrooklynApiFactory = new DefaultBrooklynApiFactory();
-
- api = defaultBrooklynApiFactory.getBrooklynApi(new URL("http://localhost:" + server.getConnectors()[0].getPort() + "/"),
+ api = BrooklynApi.newInstance("http://localhost:" + server.getConnectors()[0].getPort() + "/",
TestSecurityProvider.USER, TestSecurityProvider.PASSWORD);
}
[4/9] incubator-brooklyn git commit: Add Vault external configuration
supplier
Posted by he...@apache.org.
Add Vault external configuration supplier
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/78339994
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/78339994
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/78339994
Branch: refs/heads/master
Commit: 783399941cdc508f696dbc70360be5c38c08a3c3
Parents: 9bb0d71
Author: Richard Downer <ri...@apache.org>
Authored: Thu Nov 5 16:07:54 2015 +0000
Committer: Richard Downer <ri...@apache.org>
Committed: Thu Nov 5 16:07:54 2015 +0000
----------------------------------------------------------------------
.../vault/VaultAppIdExternalConfigSupplier.java | 71 +++++++++
.../vault/VaultExternalConfigSupplier.java | 114 ++++++++++++++
.../vault/VaultTokenExternalConfigSupplier.java | 23 +++
.../VaultUserPassExternalConfigSupplier.java | 39 +++++
.../VaultExternalConfigSupplierLiveTest.java | 151 +++++++++++++++++++
5 files changed, 398 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/78339994/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultAppIdExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultAppIdExternalConfigSupplier.java b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultAppIdExternalConfigSupplier.java
new file mode 100644
index 0000000..6e9cd8b
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultAppIdExternalConfigSupplier.java
@@ -0,0 +1,71 @@
+package org.apache.brooklyn.core.config.external.vault;
+
+import com.google.api.client.util.Lists;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonObject;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.List;
+import java.util.Map;
+
+public class VaultAppIdExternalConfigSupplier extends VaultExternalConfigSupplier {
+
+ private static final Logger LOG = LoggerFactory.getLogger(VaultAppIdExternalConfigSupplier.class);
+
+ protected VaultAppIdExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) {
+ super(managementContext, name, config);
+ }
+
+ protected String initAndLogIn(Map<String, String> config) {
+ List<String> errors = Lists.newArrayListWithCapacity(1);
+ String appId = config.get("appId");
+ if (Strings.isBlank(appId)) errors.add("missing configuration 'appId'");
+ if (!errors.isEmpty()) {
+ String message = String.format("Problem configuration Vault external config supplier '%s': %s",
+ name, Joiner.on(System.lineSeparator()).join(errors));
+ throw new IllegalArgumentException(message);
+ }
+
+ String userId = getUserId(config);
+
+ LOG.info("Config supplier named {} using Vault at {} appID {} userID {} path {}", new Object[] {
+ name, endpoint, appId, userId, path });
+
+ String path = "v1/auth/app-id/login";
+ ImmutableMap<String, String> requestData = ImmutableMap.of("app_id", appId, "user_id", userId);
+ ImmutableMap<String, String> headers = MINIMAL_HEADERS;
+ JsonObject response = apiPost(path, headers, requestData);
+ return response.getAsJsonObject("auth").get("client_token").getAsString();
+ }
+
+ private String getUserId(Map<String, String> config) {
+ String userId = config.get("userId");
+ if (Strings.isBlank(userId))
+ userId = getUserIdFromMacAddress();
+ return userId;
+ }
+
+ private static String getUserIdFromMacAddress() {
+ byte[] mac;
+ try {
+ InetAddress ip = InetAddress.getLocalHost();
+ NetworkInterface network = NetworkInterface.getByInetAddress(ip);
+ mac = network.getHardwareAddress();
+ } catch (Throwable t) {
+ throw Exceptions.propagate(t);
+ }
+ StringBuilder sb = new StringBuilder();
+ for (byte aMac : mac) {
+ sb.append(String.format("%02x", aMac));
+ }
+ return sb.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/78339994/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
new file mode 100644
index 0000000..031ee8e
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplier.java
@@ -0,0 +1,114 @@
+package org.apache.brooklyn.core.config.external.vault;
+
+import com.google.api.client.util.Lists;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.core.config.external.AbstractExternalConfigSupplier;
+import org.apache.brooklyn.util.core.http.HttpTool;
+import org.apache.brooklyn.util.core.http.HttpToolResponse;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.net.Urls;
+import org.apache.brooklyn.util.text.Strings;
+import org.apache.http.client.HttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.Map;
+
+public abstract class VaultExternalConfigSupplier extends AbstractExternalConfigSupplier {
+ public static final String CHARSET_NAME = "UTF-8";
+ public static final ImmutableMap<String, String> MINIMAL_HEADERS = ImmutableMap.of(
+ "Content-Type", "application/json; charset=" + CHARSET_NAME,
+ "Accept", "application/json",
+ "Accept-Charset", CHARSET_NAME);
+ private static final Logger LOG = LoggerFactory.getLogger(VaultExternalConfigSupplier.class);
+ protected final Map<String, String> config;
+ protected final String name;
+ protected final HttpClient httpClient;
+ protected final Gson gson;
+ protected final String endpoint;
+ protected final String path;
+ protected final String token;
+ protected final ImmutableMap<String, String> headersWithToken;
+
+ public VaultExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) {
+ super(managementContext, name);
+ this.config = config;
+ this.name = name;
+ httpClient = HttpTool.httpClientBuilder().build();
+ gson = new GsonBuilder().create();
+
+ List<String> errors = Lists.newArrayListWithCapacity(2);
+ endpoint = config.get("endpoint");
+ if (Strings.isBlank(endpoint)) errors.add("missing configuration 'endpoint'");
+ path = config.get("path");
+ if (Strings.isBlank(path)) errors.add("missing configuration 'path'");
+ if (!errors.isEmpty()) {
+ String message = String.format("Problem configuration Vault external config supplier '%s': %s",
+ name, Joiner.on(System.lineSeparator()).join(errors));
+ throw new IllegalArgumentException(message);
+ }
+
+ token = initAndLogIn(config);
+ headersWithToken = ImmutableMap.<String, String>builder()
+ .putAll(MINIMAL_HEADERS)
+ .put("X-Vault-Token", token)
+ .build();
+ }
+
+ protected abstract String initAndLogIn(Map<String, String> config);
+
+ @Override
+ public String get(String key) {
+ JsonObject response = apiGet(Urls.mergePaths("v1", path), headersWithToken);
+ return response.getAsJsonObject("data").get(key).getAsString();
+ }
+
+ protected JsonObject apiGet(String path, ImmutableMap<String, String> headers) {
+ try {
+ String uri = Urls.mergePaths(endpoint, path);
+ LOG.info("Vault request - GET: {}", uri);
+ LOG.info("Vault request - headers: {}", headers.toString());
+ HttpToolResponse response = HttpTool.httpGet(httpClient, Urls.toUri(uri), headers);
+ LOG.info("Vault response - code: {} {}", new Object[]{Integer.toString(response.getResponseCode()), response.getReasonPhrase()});
+ LOG.info("Vault response - headers: {}", response.getHeaderLists().toString());
+ String responseBody = new String(response.getContent(), CHARSET_NAME);
+ LOG.info("Vault response - body: {}", responseBody);
+ if (HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
+ return gson.fromJson(responseBody, JsonObject.class);
+ } else {
+ throw new IllegalStateException("HTTP request returned error");
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+
+ protected JsonObject apiPost(String path, ImmutableMap<String, String> headers, ImmutableMap<String, String> requestData) {
+ try {
+ String body = gson.toJson(requestData);
+ String uri = Urls.mergePaths(endpoint, path);
+ LOG.info("Vault request - POST: {}", uri);
+ LOG.info("Vault request - headers: {}", headers.toString());
+ LOG.info("Vault request - body: {}", body);
+ HttpToolResponse response = HttpTool.httpPost(httpClient, Urls.toUri(uri), headers, body.getBytes(CHARSET_NAME));
+ LOG.info("Vault response - code: {} {}", new Object[]{Integer.toString(response.getResponseCode()), response.getReasonPhrase()});
+ LOG.info("Vault response - headers: {}", response.getHeaderLists().toString());
+ String responseBody = new String(response.getContent(), CHARSET_NAME);
+ LOG.info("Vault response - body: {}", responseBody);
+ if (HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
+ return gson.fromJson(responseBody, JsonObject.class);
+ } else {
+ throw new IllegalStateException("HTTP request returned error");
+ }
+ } catch (UnsupportedEncodingException e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/78339994/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultTokenExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultTokenExternalConfigSupplier.java b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultTokenExternalConfigSupplier.java
new file mode 100644
index 0000000..ed994b4
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultTokenExternalConfigSupplier.java
@@ -0,0 +1,23 @@
+package org.apache.brooklyn.core.config.external.vault;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
+import org.apache.brooklyn.util.text.Strings;
+
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class VaultTokenExternalConfigSupplier extends VaultExternalConfigSupplier {
+ public VaultTokenExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) {
+ super(managementContext, name, config);
+ }
+
+ @Override
+ protected String initAndLogIn(Map<String, String> config) {
+ String tokenProperty = config.get("token");
+ checkArgument(Strings.isNonBlank(tokenProperty), "property not set: token");
+ return tokenProperty;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/78339994/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultUserPassExternalConfigSupplier.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultUserPassExternalConfigSupplier.java b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultUserPassExternalConfigSupplier.java
new file mode 100644
index 0000000..c43ab90
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/config/external/vault/VaultUserPassExternalConfigSupplier.java
@@ -0,0 +1,39 @@
+package org.apache.brooklyn.core.config.external.vault;
+
+import com.google.api.client.util.Lists;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.gson.JsonObject;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.util.text.Strings;
+
+import java.util.List;
+import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class VaultUserPassExternalConfigSupplier extends VaultExternalConfigSupplier {
+ public VaultUserPassExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) {
+ super(managementContext, name, config);
+ }
+
+ @Override
+ protected String initAndLogIn(Map<String, String> config) {
+ List<String> errors = Lists.newArrayListWithCapacity(2);
+ String username = config.get("username");
+ if (Strings.isBlank(username)) errors.add("missing configuration 'username'");
+ String password = config.get("password");
+ if (Strings.isBlank(username)) errors.add("missing configuration 'password'");
+ if (!errors.isEmpty()) {
+ String message = String.format("Problem configuration Vault external config supplier '%s': %s",
+ name, Joiner.on(System.lineSeparator()).join(errors));
+ throw new IllegalArgumentException(message);
+ }
+
+ String path = "v1/auth/userpass/login/" + username;
+ ImmutableMap<String, String> requestData = ImmutableMap.of("password", password);
+ ImmutableMap<String, String> headers = MINIMAL_HEADERS;
+ JsonObject response = apiPost(path, headers, requestData);
+ return response.getAsJsonObject("auth").get("client_token").getAsString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/78339994/core/src/test/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplierLiveTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplierLiveTest.java b/core/src/test/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplierLiveTest.java
new file mode 100644
index 0000000..a3b7eae
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/config/external/vault/VaultExternalConfigSupplierLiveTest.java
@@ -0,0 +1,151 @@
+package org.apache.brooklyn.core.config.external.vault;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.brooklyn.core.config.external.ExternalConfigSupplier;
+import org.apache.brooklyn.util.text.Strings;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Test the operation of the Vault external configuration supplier.
+ *
+ * <p>To run this test, you must have a working Vault server, and set a number of properties to allow the test to
+ * query your Vault server.</p>
+ *
+ * <p>You should start, initialise and unseal your vault according to the Vault documentation. Then you should insert
+ * a secret into Vault:</p>
+ *
+ * <p><tt>vault write secret/test password=foobar</tt></p>
+ *
+ * <p>Then set system properties so that the test can reach Vault and knows about the secret:</p>
+ *
+ * <p><tt>-Dtest.brooklyn.vault.endpoint=http://127.0.0.1:8200<br />
+ * -Dtest.brooklyn.vault.path=secret/test<br />
+ * -Dtest.brooklyn.vault.propertyName=password<br />
+ * -Dtest.brooklyn.vault.propertyExpectedValue=foobar</tt></p>
+ *
+ * <p>You will also need to configure authentication methods for the individual tests. Refer to the "see also" section
+ * to find each method that needs further configuration.</p>
+ *
+ * @see #testAppIdAuthenticationWithAutomaticUserId()
+ */
+public class VaultExternalConfigSupplierLiveTest {
+
+ private String endpoint;
+ private String path;
+ private String propertyName;
+ private String propertyExpectedValue;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ endpoint = getTestProperty("endpoint");
+ path = getTestProperty("path");
+ propertyName = getTestProperty("propertyName");
+ propertyExpectedValue = getTestProperty("propertyExpectedValue");
+ }
+
+ private String getTestProperty(String name) {
+ String propName = "test.brooklyn.vault." + name;
+ String propVal = System.getProperty(propName);
+ if (Strings.isBlank(propVal))
+ throw new IllegalArgumentException(propName + " is not set");
+ return propVal;
+ }
+
+ /**
+ * Test using a hard-coded authentication token.
+ *
+ * <p>This provider does not do authentication, but instead uses a known token for authentication. When Vault is
+ * initialised, it will give you an <em>Initial Root Token</em>, which can be used for this test. However,
+ * obviously, passing around a well-known root token is A Bad Idea for use in production, and would largely undo all
+ * the useful security that vault provides.</p>
+ *
+ * <p>Set these system properties:</p>
+ *
+ * <p><tt>-Dtest.brooklyn.vault.token=1091fc84-70c1-b266-b99f-781684dd0d2b</tt></p>
+ */
+ @Test(groups = "Live")
+ public void testHardCodedToken() {
+ String token = getTestProperty("token");
+ ExternalConfigSupplier ecs = new VaultTokenExternalConfigSupplier(null, "test",
+ ImmutableMap.of("endpoint", endpoint, "token", token, "path", path));
+ assertEquals(ecs.get(propertyName), propertyExpectedValue);
+ }
+
+ /**
+ * Test using the "userpass" authentication backend.
+ *
+ * <p>Configure Vault to enable userpass and add a new user ID with password:</p>
+ *
+ * <p><tt>vault auth-enable userpass<br>
+ * vault write auth/userpass/users/brooklynTest password=s3kr1t policies=root # the "root" policy allows unrestricted access, you will want to use a different policy for real use
+ * </tt></p>
+ *
+ * <p>Set these system properties:</p>
+ *
+ * <p><tt>-Dtest.brooklyn.vault.username=brooklynTest<br />
+ * -Dtest.brooklyn.vault.password=s3kr1t</tt></p>
+ */
+ @Test(groups = "Live")
+ public void testUserPassAuthentication() {
+ String username = getTestProperty("username");
+ String password = getTestProperty("password");
+ ExternalConfigSupplier ecs = new VaultUserPassExternalConfigSupplier(null, "test",
+ ImmutableMap.of("endpoint", endpoint, "username", username, "password", password, "path", path));
+ assertEquals(ecs.get(propertyName), propertyExpectedValue);
+ }
+
+ /**
+ * Test using the "App ID" authentication backend, with a MAC-address based user ID.
+ *
+ * <p>First, determine the MAC address of your system. This is system dependent, but a good guess will be to
+ * inspect the routing table to determine the default route, and take the MAC address of the interface that the
+ * default route would use. Express the MAC address as a series of 12 low-case hexadecimal digits, without any
+ * symbols.</p>
+ *
+ * <p>Configure Vault to enable App-ID, add a new app ID, and authorise the MAC address to the app ID:</p>
+ *
+ * <p><tt>/vault auth-enable app-id<br>
+ * vault write auth/app-id/map/app-id/brooklyn value=root display_name=Brooklyn # the app ID here is "brooklyn"; the "root" policy allows unrestricted access, you will want to use a different policy for real use
+ * vault write auth/app-id/map/user-id/0c4de9bca2db value=brooklyn
+ * </tt></p>
+ *
+ * <p>Set these system properties:</p>
+ *
+ * <p><tt>-Dtest.brooklyn.vault.appId=brooklyn</tt></p>
+ */
+ @Test(groups = "Live")
+ public void testAppIdAuthenticationWithAutomaticUserId() {
+ String appId = getTestProperty("appId");
+ ExternalConfigSupplier ecs = new VaultAppIdExternalConfigSupplier(null, "test",
+ ImmutableMap.of("endpoint", endpoint, "appId", appId, "path", path));
+ assertEquals(ecs.get(propertyName), propertyExpectedValue);
+ }
+
+ /**
+ * Test using the "App ID" authentication backend, with an explicitly-given user ID.
+ *
+ * <p>Configure Vault to enable App-ID, add a new app ID, and authorise your chosen user ID to the app ID:</p>
+ *
+ * <p><tt>/vault auth-enable app-id<br>
+ * vault write auth/app-id/map/app-id/brooklyn value=root display_name=Brooklyn # the app ID here is "brooklyn"; the "root" policy allows unrestricted access, you will want to use a different policy for real use
+ * vault write auth/app-id/map/user-id/testUser value=brooklyn
+ * </tt></p>
+ *
+ * <p>Set these system properties:</p>
+ *
+ * <p><tt>-Dtest.brooklyn.vault.appId=brooklyn<br />
+ * -Dtest.brooklyn.vault.userId=testUser</tt></p>
+ */
+ @Test(groups = "Live")
+ public void testAppIdAuthenticationWithExplicitUserId() {
+ String appId = getTestProperty("appId");
+ String userId = getTestProperty("userId");
+ ExternalConfigSupplier ecs = new VaultAppIdExternalConfigSupplier(null, "test",
+ ImmutableMap.of("endpoint", endpoint, "appId", appId, "path", path, "userId", userId));
+ assertEquals(ecs.get(propertyName), propertyExpectedValue);
+ }
+
+}
\ No newline at end of file
[2/9] incubator-brooklyn git commit: Update Tomcat's webapp.url
sensor to show the public hostname
Posted by he...@apache.org.
Update Tomcat's webapp.url sensor to show the public hostname
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/50194ae7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/50194ae7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/50194ae7
Branch: refs/heads/master
Commit: 50194ae71a9925e9b33747b1f52b1bc783f038a9
Parents: a504093
Author: Valentin Aitken <va...@cloudsoftcorp.com>
Authored: Thu Oct 15 16:29:11 2015 +0300
Committer: Valentin Aitken <va...@cloudsoftcorp.com>
Committed: Thu Nov 5 08:50:54 2015 +0200
----------------------------------------------------------------------
.../apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50194ae7/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java
index 2a149e7..7791418 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java
@@ -24,7 +24,9 @@ import java.io.File;
import java.net.URI;
import java.util.Set;
+import com.google.common.net.HostAndPort;
import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.location.access.BrooklynAccessUtils;
import org.apache.brooklyn.entity.java.JavaSoftwareProcessSshDriver;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.util.core.task.DynamicTasks;
@@ -93,11 +95,13 @@ public abstract class JavaWebAppSshDriver extends JavaSoftwareProcessSshDriver i
if (isProtocolEnabled("https")) {
Integer port = getHttpsPort();
checkNotNull(port, "HTTPS_PORT sensors not set; is an acceptable port available?");
- return String.format("https://%s:%s/", getSubnetHostname(), port);
+ HostAndPort accessibleAddress = BrooklynAccessUtils.getBrooklynAccessibleAddress(getEntity(), port);
+ return String.format("https://%s:%s/", accessibleAddress.getHostText(), accessibleAddress.getPort());
} else if (isProtocolEnabled("http")) {
Integer port = getHttpPort();
checkNotNull(port, "HTTP_PORT sensors not set; is an acceptable port available?");
- return String.format("http://%s:%s/", getSubnetHostname(), port);
+ HostAndPort accessibleAddress = BrooklynAccessUtils.getBrooklynAccessibleAddress(getEntity(), port);
+ return String.format("http://%s:%s/", accessibleAddress.getHostText(), accessibleAddress.getPort());
} else {
throw new IllegalStateException("HTTP and HTTPS protocols not enabled for "+entity+"; enabled protocols are "+getEnabledProtocols());
}
[6/9] incubator-brooklyn git commit: Address comments
Posted by he...@apache.org.
Address comments
* Fix incorrect deprecation comment
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/9d85ca71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/9d85ca71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/9d85ca71
Branch: refs/heads/master
Commit: 9d85ca7192c7d6d2d6a344d8d9ffdbcac31dc892
Parents: 934bb74
Author: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Authored: Thu Nov 5 17:44:05 2015 +0100
Committer: Guglielmo Nigri <gu...@cloudsoftcorp.com>
Committed: Thu Nov 5 17:44:05 2015 +0100
----------------------------------------------------------------------
.../main/java/org/apache/brooklyn/rest/client/BrooklynApi.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9d85ca71/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
index e848f99..0f3fab3 100644
--- a/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
+++ b/usage/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApi.java
@@ -74,7 +74,7 @@ import com.wordnik.swagger.core.ApiOperation;
/**
* @author Adam Lowe
- */
+ */
@SuppressWarnings("deprecation")
public class BrooklynApi {
@@ -386,7 +386,7 @@ public class BrooklynApi {
}
/**
- * @deprecated since 0.9.0. Use {@link #getEntity(Response, GenericType)} instead.
+ * @deprecated since 0.8.0-incubating. Use {@link #getEntity(Response, GenericType)} instead.
*/
@Deprecated
public static <T> T getEntityGeneric(Response response, GenericType<T> type) {
[9/9] incubator-brooklyn git commit: This closes #959
Posted by he...@apache.org.
This closes #959
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/40de8665
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/40de8665
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/40de8665
Branch: refs/heads/master
Commit: 40de86652af4c09a16bd48d8536858f9aa5090d3
Parents: 4f479dd 50194ae
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Nov 5 09:29:00 2015 -0800
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Nov 5 09:29:00 2015 -0800
----------------------------------------------------------------------
.../apache/brooklyn/entity/webapp/JavaWebAppSshDriver.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
[7/9] incubator-brooklyn git commit: This closes #1000
Posted by he...@apache.org.
This closes #1000
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8ef608d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8ef608d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8ef608d6
Branch: refs/heads/master
Commit: 8ef608d6e18f591ffef4969e59bfdf1e7bb79e29
Parents: f52d9e0 9d85ca7
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Nov 5 09:26:45 2015 -0800
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Nov 5 09:26:45 2015 -0800
----------------------------------------------------------------------
.../brooklyn/rest/client/BrooklynApi.java | 168 +++++++++++++++++--
.../ApplicationResourceIntegrationTest.java | 3 +-
.../rest/client/BrooklynApiRestClientTest.java | 3 +-
3 files changed, 155 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
[5/9] incubator-brooklyn git commit: Add documentation for
externalized configuration
Posted by he...@apache.org.
Add documentation for externalized configuration
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/19c215b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/19c215b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/19c215b7
Branch: refs/heads/master
Commit: 19c215b798edaafe4798fbb82bcc7797960b4960
Parents: 7833999
Author: Richard Downer <ri...@apache.org>
Authored: Thu Nov 5 16:08:14 2015 +0000
Committer: Richard Downer <ri...@apache.org>
Committed: Thu Nov 5 16:08:14 2015 +0000
----------------------------------------------------------------------
docs/guide/ops/externalized-configuration.md | 225 ++++++++++++++++++++++
docs/guide/ops/index.md | 1 +
2 files changed, 226 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/19c215b7/docs/guide/ops/externalized-configuration.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/externalized-configuration.md b/docs/guide/ops/externalized-configuration.md
new file mode 100644
index 0000000..3a80499
--- /dev/null
+++ b/docs/guide/ops/externalized-configuration.md
@@ -0,0 +1,225 @@
+---
+title: Externalized Configuration
+layout: website-normal
+---
+
+Sometimes it is useful that configuration in a blueprint, or in Brooklyn itself, is not given explicitly, but is instead
+replaced with a reference to some other storage system. For example, it is undesirable for a blueprint to contain a
+plain-text password for a production system, especially if (as we often recommend) the blueprints are kept in the
+developer's source code control system.
+
+To handle this problem, Apache Brooklyn supports externalized configuration. This allows a blueprint to refer to
+a piece of information that is stored elsewhere. `brooklyn.properties` defines the external suppliers of configuration
+information. At runtime, when Brooklyn finds a reference to externalized configuration in a blueprint, it consults
+`brooklyn.properties` for information about the supplier, and then requests that the supplier return the information
+required by the blueprint.
+
+Take, as a simple example, a web app which connects to a database. In development, the developer is running a local
+instance of PostgreSQL with a simple username and password. But in production, an enterprise-grade cluster of PostgreSQL
+is used, and a dedicated service is used to provide passwords. The same blueprint can be used to service both groups
+of users, with `brooklyn.properties` changing the behaviour depending on the deployment environment.
+
+Here is the blueprint:
+
+{% highlight yaml %}
+name: MyApplication
+services:
+- type: brooklyn.entity.webapp.jboss.JBoss7Server
+ name: AppServer HelloWorld
+ brooklyn.config:
+ wars.root: http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.6.0/brooklyn-example-hello-world-sql-webapp-0.6.0.war
+ http.port: 8080+
+ java.sysprops:
+ brooklyn.example.db.url: $brooklyn:formatString("jdbc:postgresql://%s/myappdb?user=%s\\&password=%s",
+ external("servers", "postgresql"), external("credentials", "postgresql-user"), external("credentials", "postgresql-password"))
+{% endhighlight %}
+
+You can see that when we are building up the JDBC URL, we are using the `external` function. This takes two parameters:
+the first is the name of the configuration supplier, the second is the name of a key that is stored by the configuration
+supplier. In this case we are using two different suppliers: `servers` to store the location of the server, and
+`credentials` which is a security-optimized supplier of secrets.
+
+Developers would add lines like this to the `brooklyn.properties` file on their workstation:
+
+{% highlight properties %}
+brooklyn.external.servers=org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier
+brooklyn.external.servers.postgresql=127.0.0.1
+brooklyn.external.credentials=org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier
+brooklyn.external.credentials.postgresql-user=admin
+brooklyn.external.credentials.postgresql-password=admin
+{% endhighlight %}
+
+In this case, all of the required information is included in-line in the local `brooklyn.properties`.
+
+Whereas in production, `brooklyn.properties` might look like this:
+
+{% highlight properties %}
+brooklyn.external.servers=org.apache.brooklyn.core.config.external.PropertiesFileExternalConfigSupplier
+brooklyn.external.servers.propertiesUrl=https://ops.example.com/servers.properties
+brooklyn.external.credentials=org.apache.brooklyn.core.config.external.vault.VaultAppIdExternalConfigSupplier
+brooklyn.external.credentials.endpoint=https://vault.example.com
+brooklyn.external.credentials.path=secret/enterprise-postgres
+brooklyn.external.credentials.appId=MyApp
+{% endhighlight %}
+
+In this case, the list of servers is stored in a properties file located on an Operations Department web server, and the
+credentials are stored in an instance of [Vault](https://www.vaultproject.io/).
+
+## Defining Suppliers
+
+External configuration suppliers are defined in `brooklyn.properties`. The minimal definition is of the form:
+
+brooklyn.external.*supplierName* = *className*
+
+This defines a supplier named *supplierName*. Brooklyn will attempt to instantiate *className*; it is this class which
+will provide the behaviour of how to retrieve data from the supplier. Brooklyn includes a number of supplier
+implementations; see below for more details.
+
+Suppliers may require additional configuration options. These are given as additional properties in
+`brooklyn.properties`:
+
+{% highlight properties %}
+brooklyn.external.supplierName = className
+brooklyn.external.supplierName.firstConfig = value
+brooklyn.external.supplierName.secondConfig = value
+{% endhighlight %}
+
+## Referring to External Configuration in Blueprints
+
+Externalized configuration adds a new function to the Brooklyn blueprint language DSL, `$brooklyn:external`. This
+function takes two parameters:
+
+1. supplier
+2. key
+
+When resolving the external reference, Brooklyn will first identify the *supplier* of the information, then it will
+give the supplier the *key*. The returned value will be substituted into the blueprint.
+
+You can use `$brooklyn:external` directly:
+
+{% highlight yaml %}
+name: MyApplication
+brooklyn.config:
+ example: $brooklyn:external("supplier", "key")
+{% endhighlight %}
+
+or embed the `external` function inside another `$brooklyn` DSL function, such as `$brooklyn:formatString`:
+
+{% highlight yaml %}
+name: MyApplication
+brooklyn.config:
+ example: $brooklyn:formatString("%s", external("supplier", "key"))
+{% endhighlight %}
+
+## Suppliers available with Brooklyn
+
+Brooklyn ships with a number of external configuration suppliers ready to use.
+
+### In-place
+
+**InPlaceExternalConfigSupplier** embeds the configuration keys and values as properties inside `brooklyn.properties`.
+For example:
+
+{% highlight properties %}
+brooklyn.external.servers=org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier
+brooklyn.external.servers.postgresql=127.0.0.1
+{% endhighlight %}
+
+Then, a blueprint which referred to `$brooklyn:external("servers", "postgresql")` would receive the value `127.0.0.1`.
+
+### Properties file
+
+**PropertiesFileExternalConfigSupplier** loads a properties file from a URL, and uses the keys and values in this
+file to respond to configuration lookups.
+
+Given this configuration:
+
+{% highlight properties %}
+brooklyn.external.servers=org.apache.brooklyn.core.config.external.PropertiesFileExternalConfigSupplier
+brooklyn.external.servers.propertiesUrl=https://ops.example.com/servers.properties
+{% endhighlight %}
+
+This would cause the supplier to download the given URL. Assuming that the file contained this entry:
+
+{% highlight properties %}
+postgresql=127.0.0.1
+{% endhighlight %}
+
+Then, a blueprint which referred to `$brooklyn:external("servers", "postgresql")` would receive the value `127.0.0.1`.
+
+### Vault
+
+[Vault](https://www.vaultproject.io) is a server-based tool for managing secrets. Brooklyn provides suppliers that are
+able to query the Vault REST API for configuration values. The different suppliers implement alternative authentication
+options that Vault provides.
+
+For *all* of the authentication methods, you must always set these properties in `brooklyn.properties`:
+
+{% highlight properties %}
+brooklyn.external.supplierName.endpoint=<Vault HTTP/HTTPs endpoint>
+brooklyn.external.supplierName.path=<path to a Vault object>
+{% endhighlight %}
+
+For example, if the path is set to `secret/brooklyn`, then attempting to retrieve the key `foo` would cause Brooklyn
+to retrieve the value of the `foo` key on the `secret/brooklyn` object. This value can be set using the Vault CLI
+like this:
+
+{% highlight bash %}
+vault write secret/brooklyn foo=bar
+{% endhighlight %}
+
+#### Authentication by username and password
+
+The `userpass` plugin for Vault allows authentication with username and password.
+
+{% highlight properties %}
+brooklyn.external.supplierName=org.apache.brooklyn.core.config.external.vault.VaultUserPassExternalConfigSupplier
+brooklyn.external.supplierName.username=fred
+brooklyn.external.supplierName.password=s3kr1t
+{% endhighlight %}
+
+#### Authentication using App ID
+
+The `app_id` plugin for Vault allows you to specify an "app ID", and then designate particular "user IDs" to be part
+of the app. Typically the app ID would be known and shared, but user ID would be autogenerated on the client in some
+way. Brooklyn implements this by determining the MAC address of the server running Brooklyn (expressed as 12 lower
+case hexadecimal digits without separators) and passing this as the user ID.
+
+{% highlight properties %}
+brooklyn.external.supplierName=org.apache.brooklyn.core.config.external.vault.VaultAppIdExternalConfigSupplier
+brooklyn.external.supplierName.appId=MyApp
+{% endhighlight %}
+
+If you do not wish to use the MAC address as the user ID, you can override it with your own choice of user ID:
+
+{% highlight properties %}
+brooklyn.external.supplierName.userId=server3.cluster2.europe
+{% endhighlight %}
+
+#### Authentication by fixed token
+
+If you have a fixed token string, then you can use the *VaultTokenExternalConfigSupplier* class and provide the token
+in `brooklyn.properties`:
+
+{% highlight properties %}
+brooklyn.external.supplierName=org.apache.brooklyn.core.config.external.vault.VaultTokenExternalConfigSupplier
+brooklyn.external.supplierName.token=1091fc84-70c1-b266-b99f-781684dd0d2b
+{% endhighlight %}
+
+This supplier is suitable for "smoke testing" the Vault supplier using the Initial Root Token or similar. However it
+is not suitable for production use as it is inherently insecure - should the token be compromised, an attacker could
+have complete access to your Vault, and the cleanup operation would be difficult. Instead you should use one of the
+other suppliers.
+
+## Writing Custom External Configuration Suppliers
+
+Supplier implementations must conform to the brooklyn.config.external.ExternalConfigSupplier interface, which is very
+simple:
+
+{% highlight java %}
+String getName();
+String get(String key);
+{% endhighlight %}
+
+Classes implementing this interface can be placed in the `lib/dropins` folder of Brooklyn, and then the supplier
+defined in `brooklyn.properties` as normal.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/19c215b7/docs/guide/ops/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/ops/index.md b/docs/guide/ops/index.md
index 1f74074..bf40c1b 100644
--- a/docs/guide/ops/index.md
+++ b/docs/guide/ops/index.md
@@ -10,6 +10,7 @@ children:
- catalog/
- rest.md
- logging.md
+- externalized-configuration.md
- requirements.md
- production-installation.md
- troubleshooting/