Useful methods for working with the Brooklyn API programatically.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/d1733900
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/d1733900
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/d1733900
Branch: refs/heads/master
Commit: d173390039887e2da6717f5ca0d1b4c91fb8657b
Parents: 6528d25
Author: Sam Corbett
Authored: Wed Feb 3 17:09:17 2016 +
Committer: Sam Corbett
Committed: Wed Feb 3 17:09:17 2016 +
--
rest/rest-client/pom.xml| 5 +
.../brooklyn/rest/client/BrooklynApiUtil.java | 154 +++
.../rest/client/BrooklynApiUtilTest.java| 129
3 files changed, 288 insertions(+)
--
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d1733900/rest/rest-client/pom.xml
--
diff --git a/rest/rest-client/pom.xml b/rest/rest-client/pom.xml
index 5b27148..f3fa883 100644
--- a/rest/rest-client/pom.xml
+++ b/rest/rest-client/pom.xml
@@ -144,6 +144,11 @@
${project.version}
test
+
+com.google.mockwebserver
+mockwebserver
+test
+
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d1733900/rest/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiUtil.java
--
diff --git
a/rest/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiUtil.java
b/rest/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiUtil.java
new file mode 100644
index 000..ce57da5
--- /dev/null
+++
b/rest/rest-client/src/main/java/org/apache/brooklyn/rest/client/BrooklynApiUtil.java
@@ -0,0 +1,154 @@
+/*
+ * 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 static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Date;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.ws.rs.core.Response;
+
+import org.apache.brooklyn.rest.api.EffectorApi;
+import org.apache.brooklyn.rest.domain.Status;
+import org.apache.brooklyn.rest.domain.TaskSummary;
+import org.apache.brooklyn.util.repeat.Repeater;
+import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableMap;
+
+public class BrooklynApiUtil {
+
+private static final Logger LOG =
LoggerFactory.getLogger(BrooklynApiUtil.class);
+private static final Duration DEFAULT_POLL_PERIOD = Duration.FIVE_SECONDS;
+private static final Duration DEFAULT_TIMEOUT = Duration.FIVE_MINUTES;
+
+private BrooklynApiUtil() {}
+
+/**
+ * Deploys the blueprint and returns the task summary.
+ * @throws Exception If the response from the server when deploying was
{@link #isUnhealthyResponse unhealthy}.
+ */
+public static TaskSummary deployBlueprint(BrooklynApi api, String
blueprint) throws Exception {
+Response r = api.getApplicationApi().createFromYaml(blueprint);
+if (isUnhealthyResponse(r)) {
+throw new Exception("Unexpected response deploying blueprint to
server: " + r.getStatus());
+} else {
+LOG.debug("Server response to deploy blueprint: " + r.getStatus());
+}
+return BrooklynApi.getEntity(r, TaskSummary.class);
+}
+
+/**
+ * Waits for the application with the given ID to be running.
+ *
+ * @throws IllegalStateException If the application was not running after
{@link #DEFAULT_TIMEOUT}.
+ */
+public static void waitForRunningAndThrowOtherwise(BrooklynApi api, String
applicationId, String taskId) throws IllegalStateException {
+waitForRunningAndThrowOtherwise(api,