You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/05/29 16:53:50 UTC
[1/9] incubator-brooklyn git commit: Move util test specs to util/
Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 75194760d -> fc3851b3d
Move util test specs to util/
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/438f2db4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/438f2db4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/438f2db4
Branch: refs/heads/master
Commit: 438f2db4df5805fc947f422e2c5d6bd06b807c66
Parents: 711fb60
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon May 18 12:08:31 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:38:52 2015 +0100
----------------------------------------------------------------------
.../src/test/javascript/specs/brooklyn-spec.js | 129 ----------------
.../javascript/specs/brooklyn-utils-spec.js | 151 -------------------
.../test/javascript/specs/util/brooklyn-spec.js | 129 ++++++++++++++++
.../specs/util/brooklyn-utils-spec.js | 151 +++++++++++++++++++
4 files changed, 280 insertions(+), 280 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/438f2db4/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js b/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
deleted file mode 100644
index 3fcfcc2..0000000
--- a/usage/jsgui/src/test/javascript/specs/brooklyn-spec.js
+++ /dev/null
@@ -1,129 +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.
- */
-define([
- "brooklyn", "backbone"
-], function (B, Backbone) {
-
- describe("view", function () {
- describe("form", function() {
- var formTemplate = _.template('<form>' +
- '<input name="id" type="text"/>' +
- '<input name="initialvalue" type="text" value="present"/>' +
- '<button type="submit" class="submit">Submit</button>' +
- '</form>');
-
- it("should set existing values on the model", function() {
- var form = new B.view.Form({template: formTemplate, onSubmit: function() {}});
- expect(form.model.get("initialvalue")).toBe("present");
- expect(form.model.get("id")).toBe("");
- });
-
- it("should maintain a model as inputs change", function () {
- var form = new B.view.Form({
- template: formTemplate,
- onSubmit: function() {}
- });
- // simulate id entry
- form.$("[name=id]").val("987");
- form.$("[name=id]").trigger("change");
- expect(form.model.get("id")).toBe("987");
- });
-
- it("should call the onSubmit callback when the form is submitted", function () {
- var wasCalled = false;
- var onSubmit = function (model) {
- wasCalled = true;
- };
- var form = new B.view.Form({
- template: formTemplate,
- onSubmit: onSubmit
- });
- console.log(form.$(".submit"));
- form.$("form").trigger("submit");
- expect(wasCalled).toBe(true);
- });
-
- it("should fail if called without template or onSubmit", function () {
- try {
- new B.view.Form({template: ""});
- fail;
- } catch (e) {
- // expected
- }
- try {
- new B.view.Form({onSubmit: function() {}});
- fail;
- } catch (e) {
- // expected
- }
-
- });
- });
- });
-
- describe("_.stripComments", function () {
- it("should strip a basic comment", function () {
- var text = "<p>abc</p>\n <!-- comment-here --> <p>cba</p>";
- expect(_.stripComments(text)).toBe("<p>abc</p>\n <p>cba</p>");
- });
-
- it("should return an empty string for an empty comment", function () {
- expect(_.stripComments("<!---->")).toBe("");
- expect(_.stripComments("<!-- -->")).toBe("");
- });
-
- it("should strip multiple comments", function () {
- var text = "a<!-- one -->b<!--two-->c<!-- three -->";
- expect(_.stripComments(text)).toBe("abc");
- });
-
- it("should strip trailing newlines", function () {
- expect(_.stripComments("<!-- a -->\nb")).toBe("b");
- expect(_.stripComments("<!-- a -->\rb")).toBe("b");
- });
-
- it("should leave text with no comments untouched", function () {
- var text = "<p>abc</p>";
- expect(_.stripComments(text)).toBe(text);
- });
-
- it("should remove the Apache license header from an HTML template", function () {
- var text = "<!--\n" +
- "Licensed to the Apache Software Foundation (ASF) under one\n" +
- "or more contributor license agreements. See the NOTICE file\n" +
- "distributed with this work for additional information\n" +
- "regarding copyright ownership. The ASF licenses this file\n" +
- "to you under the Apache License, Version 2.0 (the\n" +
- "\"License\"); you may not use this file except in compliance\n" +
- "with the License. You may obtain a copy of the License at\n" +
- "\n" +
- "http://www.apache.org/licenses/LICENSE-2.0\n" +
- "\n" +
- "Unless required by applicable law or agreed to in writing,\n" +
- "software distributed under the License is distributed on an\n" +
- "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
- "KIND, either express or implied. See the License for the\n" +
- "specific language governing permissions and limitations\n" +
- "under the License.\n" +
- "-->\n" +
- "real content";
- expect(_.stripComments(text)).toBe("real content");
- });
- });
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/438f2db4/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js b/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
deleted file mode 100644
index 4c21f50..0000000
--- a/usage/jsgui/src/test/javascript/specs/brooklyn-utils-spec.js
+++ /dev/null
@@ -1,151 +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.
- */
-define([
- 'brooklyn-utils', "backbone"
-], function (Util, Backbone) {
-
- describe('Rounding numbers', function () {
-
- var round = Util.roundIfNumberToNumDecimalPlaces;
-
- it("should round in the correct direction", function() {
- // unchanged
- expect(round(1, 2)).toBe(1);
- expect(round(1.1, 1)).toBe(1.1);
- expect(round(1.9, 1)).toBe(1.9);
- expect(round(1.123123123, 6)).toBe(1.123123);
- expect(round(-22.222, 3)).toBe(-22.222);
-
- // up
- expect(round(1.9, 0)).toBe(2);
- expect(round(1.5, 0)).toBe(2);
- expect(round(1.49, 1)).toBe(1.5);
-
- // down
- expect(round(1.01, 1)).toBe(1.0);
- expect(round(1.49, 0)).toBe(1);
- expect(round(1.249, 1)).toBe(1.2);
- expect(round(1.0000000000000000000001, 0)).toBe(1);
- });
-
- it("should round negative numbers correctly", function() {
- // up
- expect(round(-10, 0)).toBe(-10);
- expect(round(-10.49999, 0)).toBe(-10);
-
- // down
- expect(round(-10.5, 0)).toBe(-11);
- expect(round(-10.50001, 0)).toBe(-11);
- expect(round(-10.49999, 1)).toBe(-10.5);
- });
-
- it("should ignore non-numeric values", function() {
- expect(round("xyz", 1)).toBe("xyz");
- expect(round("2.4", 0)).toBe("2.4");
- expect(round({a: 2}, 0)).toEqual({a: 2});
- });
-
- it("should ignore negative mantissas", function() {
- expect(round(10.5, -1)).toBe(10.5);
- expect(round(100, -1)).toBe(100);
- expect(round(0, -1)).toBe(0);
- });
-
- });
-
- describe("pathOf", function() {
-
- it("should extract the path component of a URI", function() {
- expect(Util.pathOf("http://www.example.com/path/to/resource#more?a=b&c=d")).toBe("/path/to/resource");
- });
-
- it("should return an empty path for an empty URL", function() {
- expect(Util.pathOf("")).toBe("");
- });
-
- it("should handle input without domain", function() {
- expect(Util.pathOf("/a/b/c/d#e")).toBe("/a/b/c/d");
- })
- });
-
- describe("inputValue", function () {
- it("should return inputs as strings", function () {
- expect(Util.inputValue($('<input type="text" value="bob"/>'))).toBe("bob");
- expect(Util.inputValue($('<textarea rows="10" cols="5">content</textarea>'))).toBe("content");
- });
-
- it("should return true/false for checkboxes", function () {
- var input = $('<input type="checkbox" checked/>');
- expect(Util.inputValue(input)).toBe(true);
- input = $('<input type="checkbox" />');
- expect(Util.inputValue(input)).toBe(false);
- });
- });
-
- describe("bindModelFromForm", function () {
- // pretend to be a Backbone model without bringing in Backbone as a dependency
- var TestModel = Backbone.Model.extend({
- urlRoot: function () {
- return "/foo/bar/";
- }
- });
- var form = $("<form>" +
- "<input name='id' type='input' value='text'/>" +
- "<input name='bool' type='checkbox' checked/>" +
- "</form>");
-
- it("should create a new model if given a constructor", function () {
- var model = Util.bindModelFromForm(TestModel, form);
- expect(model instanceof TestModel).toBe(true);
- expect(model.url()).toBe("/foo/bar/text");
- var inputs = model.attributes;
- expect(_.keys(inputs).length).toBe(2);
- expect(inputs.id).toBe("text");
- expect(inputs.bool).toBe(true);
- });
-
- it("should update an existing model", function () {
- var model = new TestModel({initialAttribute: "xyz"});
- Util.bindModelFromForm(model, form);
- var inputs = model.attributes;
- expect(_.keys(inputs).length).toBe(3);
- expect(inputs.id).toBe("text");
- expect(inputs.bool).toBe(true);
- expect(inputs.initialAttribute).toBe("xyz");
- });
- });
-
- describe("extractError", function () {
- it("should extract the response message", function () {
- var m = Util.extractError({ responseText: '{"message": "hello"}'}, "default");
- expect(m).toBe("hello");
- });
-
- it("should return the default on invalid JSON", function () {
- var m = Util.extractError({ responseText: "<html></html>"}, "default");
- expect(m).toBe("default");
- });
-
- it("should return the default if the response has no message", function () {
- var m = Util.extractError({ a: '{"b": "c"}'}, "default");
- expect(m).toBe("default");
- });
- });
-
-});
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/438f2db4/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
new file mode 100644
index 0000000..3fcfcc2
--- /dev/null
+++ b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+define([
+ "brooklyn", "backbone"
+], function (B, Backbone) {
+
+ describe("view", function () {
+ describe("form", function() {
+ var formTemplate = _.template('<form>' +
+ '<input name="id" type="text"/>' +
+ '<input name="initialvalue" type="text" value="present"/>' +
+ '<button type="submit" class="submit">Submit</button>' +
+ '</form>');
+
+ it("should set existing values on the model", function() {
+ var form = new B.view.Form({template: formTemplate, onSubmit: function() {}});
+ expect(form.model.get("initialvalue")).toBe("present");
+ expect(form.model.get("id")).toBe("");
+ });
+
+ it("should maintain a model as inputs change", function () {
+ var form = new B.view.Form({
+ template: formTemplate,
+ onSubmit: function() {}
+ });
+ // simulate id entry
+ form.$("[name=id]").val("987");
+ form.$("[name=id]").trigger("change");
+ expect(form.model.get("id")).toBe("987");
+ });
+
+ it("should call the onSubmit callback when the form is submitted", function () {
+ var wasCalled = false;
+ var onSubmit = function (model) {
+ wasCalled = true;
+ };
+ var form = new B.view.Form({
+ template: formTemplate,
+ onSubmit: onSubmit
+ });
+ console.log(form.$(".submit"));
+ form.$("form").trigger("submit");
+ expect(wasCalled).toBe(true);
+ });
+
+ it("should fail if called without template or onSubmit", function () {
+ try {
+ new B.view.Form({template: ""});
+ fail;
+ } catch (e) {
+ // expected
+ }
+ try {
+ new B.view.Form({onSubmit: function() {}});
+ fail;
+ } catch (e) {
+ // expected
+ }
+
+ });
+ });
+ });
+
+ describe("_.stripComments", function () {
+ it("should strip a basic comment", function () {
+ var text = "<p>abc</p>\n <!-- comment-here --> <p>cba</p>";
+ expect(_.stripComments(text)).toBe("<p>abc</p>\n <p>cba</p>");
+ });
+
+ it("should return an empty string for an empty comment", function () {
+ expect(_.stripComments("<!---->")).toBe("");
+ expect(_.stripComments("<!-- -->")).toBe("");
+ });
+
+ it("should strip multiple comments", function () {
+ var text = "a<!-- one -->b<!--two-->c<!-- three -->";
+ expect(_.stripComments(text)).toBe("abc");
+ });
+
+ it("should strip trailing newlines", function () {
+ expect(_.stripComments("<!-- a -->\nb")).toBe("b");
+ expect(_.stripComments("<!-- a -->\rb")).toBe("b");
+ });
+
+ it("should leave text with no comments untouched", function () {
+ var text = "<p>abc</p>";
+ expect(_.stripComments(text)).toBe(text);
+ });
+
+ it("should remove the Apache license header from an HTML template", function () {
+ var text = "<!--\n" +
+ "Licensed to the Apache Software Foundation (ASF) under one\n" +
+ "or more contributor license agreements. See the NOTICE file\n" +
+ "distributed with this work for additional information\n" +
+ "regarding copyright ownership. The ASF licenses this file\n" +
+ "to you under the Apache License, Version 2.0 (the\n" +
+ "\"License\"); you may not use this file except in compliance\n" +
+ "with the License. You may obtain a copy of the License at\n" +
+ "\n" +
+ "http://www.apache.org/licenses/LICENSE-2.0\n" +
+ "\n" +
+ "Unless required by applicable law or agreed to in writing,\n" +
+ "software distributed under the License is distributed on an\n" +
+ "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+ "KIND, either express or implied. See the License for the\n" +
+ "specific language governing permissions and limitations\n" +
+ "under the License.\n" +
+ "-->\n" +
+ "real content";
+ expect(_.stripComments(text)).toBe("real content");
+ });
+ });
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/438f2db4/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js b/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
new file mode 100644
index 0000000..4c21f50
--- /dev/null
+++ b/usage/jsgui/src/test/javascript/specs/util/brooklyn-utils-spec.js
@@ -0,0 +1,151 @@
+/*
+ * 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.
+ */
+define([
+ 'brooklyn-utils', "backbone"
+], function (Util, Backbone) {
+
+ describe('Rounding numbers', function () {
+
+ var round = Util.roundIfNumberToNumDecimalPlaces;
+
+ it("should round in the correct direction", function() {
+ // unchanged
+ expect(round(1, 2)).toBe(1);
+ expect(round(1.1, 1)).toBe(1.1);
+ expect(round(1.9, 1)).toBe(1.9);
+ expect(round(1.123123123, 6)).toBe(1.123123);
+ expect(round(-22.222, 3)).toBe(-22.222);
+
+ // up
+ expect(round(1.9, 0)).toBe(2);
+ expect(round(1.5, 0)).toBe(2);
+ expect(round(1.49, 1)).toBe(1.5);
+
+ // down
+ expect(round(1.01, 1)).toBe(1.0);
+ expect(round(1.49, 0)).toBe(1);
+ expect(round(1.249, 1)).toBe(1.2);
+ expect(round(1.0000000000000000000001, 0)).toBe(1);
+ });
+
+ it("should round negative numbers correctly", function() {
+ // up
+ expect(round(-10, 0)).toBe(-10);
+ expect(round(-10.49999, 0)).toBe(-10);
+
+ // down
+ expect(round(-10.5, 0)).toBe(-11);
+ expect(round(-10.50001, 0)).toBe(-11);
+ expect(round(-10.49999, 1)).toBe(-10.5);
+ });
+
+ it("should ignore non-numeric values", function() {
+ expect(round("xyz", 1)).toBe("xyz");
+ expect(round("2.4", 0)).toBe("2.4");
+ expect(round({a: 2}, 0)).toEqual({a: 2});
+ });
+
+ it("should ignore negative mantissas", function() {
+ expect(round(10.5, -1)).toBe(10.5);
+ expect(round(100, -1)).toBe(100);
+ expect(round(0, -1)).toBe(0);
+ });
+
+ });
+
+ describe("pathOf", function() {
+
+ it("should extract the path component of a URI", function() {
+ expect(Util.pathOf("http://www.example.com/path/to/resource#more?a=b&c=d")).toBe("/path/to/resource");
+ });
+
+ it("should return an empty path for an empty URL", function() {
+ expect(Util.pathOf("")).toBe("");
+ });
+
+ it("should handle input without domain", function() {
+ expect(Util.pathOf("/a/b/c/d#e")).toBe("/a/b/c/d");
+ })
+ });
+
+ describe("inputValue", function () {
+ it("should return inputs as strings", function () {
+ expect(Util.inputValue($('<input type="text" value="bob"/>'))).toBe("bob");
+ expect(Util.inputValue($('<textarea rows="10" cols="5">content</textarea>'))).toBe("content");
+ });
+
+ it("should return true/false for checkboxes", function () {
+ var input = $('<input type="checkbox" checked/>');
+ expect(Util.inputValue(input)).toBe(true);
+ input = $('<input type="checkbox" />');
+ expect(Util.inputValue(input)).toBe(false);
+ });
+ });
+
+ describe("bindModelFromForm", function () {
+ // pretend to be a Backbone model without bringing in Backbone as a dependency
+ var TestModel = Backbone.Model.extend({
+ urlRoot: function () {
+ return "/foo/bar/";
+ }
+ });
+ var form = $("<form>" +
+ "<input name='id' type='input' value='text'/>" +
+ "<input name='bool' type='checkbox' checked/>" +
+ "</form>");
+
+ it("should create a new model if given a constructor", function () {
+ var model = Util.bindModelFromForm(TestModel, form);
+ expect(model instanceof TestModel).toBe(true);
+ expect(model.url()).toBe("/foo/bar/text");
+ var inputs = model.attributes;
+ expect(_.keys(inputs).length).toBe(2);
+ expect(inputs.id).toBe("text");
+ expect(inputs.bool).toBe(true);
+ });
+
+ it("should update an existing model", function () {
+ var model = new TestModel({initialAttribute: "xyz"});
+ Util.bindModelFromForm(model, form);
+ var inputs = model.attributes;
+ expect(_.keys(inputs).length).toBe(3);
+ expect(inputs.id).toBe("text");
+ expect(inputs.bool).toBe(true);
+ expect(inputs.initialAttribute).toBe("xyz");
+ });
+ });
+
+ describe("extractError", function () {
+ it("should extract the response message", function () {
+ var m = Util.extractError({ responseText: '{"message": "hello"}'}, "default");
+ expect(m).toBe("hello");
+ });
+
+ it("should return the default on invalid JSON", function () {
+ var m = Util.extractError({ responseText: "<html></html>"}, "default");
+ expect(m).toBe("default");
+ });
+
+ it("should return the default if the response has no message", function () {
+ var m = Util.extractError({ a: '{"b": "c"}'}, "default");
+ expect(m).toBe("default");
+ });
+ });
+
+});
[3/9] incubator-brooklyn git commit: EffectorUtils rethrows
PropagatedRuntimeExceptions where possible
Posted by sj...@apache.org.
EffectorUtils rethrows PropagatedRuntimeExceptions where possible
Rather than wrapping in more PropagatedRuntimeExceptions
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/5031d4f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/5031d4f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/5031d4f4
Branch: refs/heads/master
Commit: 5031d4f49ace3468db842b82297cd7cef679ad15
Parents: 7519476
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Thu May 14 19:47:34 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:38:52 2015 +0100
----------------------------------------------------------------------
.../brooklyn/management/internal/EffectorUtils.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/5031d4f4/core/src/main/java/brooklyn/management/internal/EffectorUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/EffectorUtils.java b/core/src/main/java/brooklyn/management/internal/EffectorUtils.java
index c14b98c..556ca23 100644
--- a/core/src/main/java/brooklyn/management/internal/EffectorUtils.java
+++ b/core/src/main/java/brooklyn/management/internal/EffectorUtils.java
@@ -259,8 +259,16 @@ public class EffectorUtils {
}
public static void handleEffectorException(Entity entity, Effector<?> effector, Throwable throwable) {
- log.warn("Error invoking "+effector.getName()+" at "+entity+": "+Exceptions.collapseText(throwable));
- throw new PropagatedRuntimeException("Error invoking "+effector.getName()+" at "+entity, throwable);
+ String message = "Error invoking " + effector.getName() + " at " + entity;
+ // Avoid throwing a PropagatedRuntimeException that just repeats the last PropagatedRuntimeException.
+ if (throwable instanceof PropagatedRuntimeException &&
+ throwable.getMessage() != null &&
+ throwable.getMessage().startsWith(message)) {
+ throw PropagatedRuntimeException.class.cast(throwable);
+ } else {
+ log.warn(message + ": " + Exceptions.collapseText(throwable));
+ throw new PropagatedRuntimeException(message, throwable);
+ }
}
public static <T> Task<T> invokeEffectorAsync(Entity entity, Effector<T> eff, Map<String,?> parameters) {
[4/9] incubator-brooklyn git commit: Fix router-spec for browser.
Posted by sj...@apache.org.
Fix router-spec for browser.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/df9f8bd3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/df9f8bd3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/df9f8bd3
Branch: refs/heads/master
Commit: df9f8bd3f028c5420d5aca9c08ad4cf1501bbc87
Parents: 438f2db
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon May 18 12:36:58 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:38:53 2015 +0100
----------------------------------------------------------------------
usage/jsgui/src/test/javascript/specs/router-spec.js | 4 ++--
usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js | 1 -
2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/df9f8bd3/usage/jsgui/src/test/javascript/specs/router-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/router-spec.js b/usage/jsgui/src/test/javascript/specs/router-spec.js
index 0041373..8f54bb8 100644
--- a/usage/jsgui/src/test/javascript/specs/router-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/router-spec.js
@@ -17,8 +17,8 @@
* under the License.
*/
define([
- "brooklyn", "router", "model/ha"
-], function (Brooklyn, Router, ha) {
+ "brooklyn", "router"
+], function (Brooklyn, Router) {
var View = Backbone.View.extend({
render:function () {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/df9f8bd3/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
index 3fcfcc2..4098235 100644
--- a/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
+++ b/usage/jsgui/src/test/javascript/specs/util/brooklyn-spec.js
@@ -54,7 +54,6 @@ define([
template: formTemplate,
onSubmit: onSubmit
});
- console.log(form.$(".submit"));
form.$("form").trigger("submit");
expect(wasCalled).toBe(true);
});
[8/9] incubator-brooklyn git commit: Set blocking details when
copying JMX resources
Posted by sj...@apache.org.
Set blocking details when copying JMX resources
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/eca81924
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/eca81924
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/eca81924
Branch: refs/heads/master
Commit: eca81924f0c11d1082ba6a845d71a5e9ac27c2b6
Parents: 6e1cb1f
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri May 29 14:38:35 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:45:04 2015 +0100
----------------------------------------------------------------------
.../main/java/brooklyn/entity/java/JmxSupport.java | 10 ++++++++--
.../java/brooklyn/entity/java/JmxmpSslSupport.java | 15 ++++++++++-----
2 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eca81924/software/base/src/main/java/brooklyn/entity/java/JmxSupport.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/java/JmxSupport.java b/software/base/src/main/java/brooklyn/entity/java/JmxSupport.java
index 2930f40..a6133a9 100644
--- a/software/base/src/main/java/brooklyn/entity/java/JmxSupport.java
+++ b/software/base/src/main/java/brooklyn/entity/java/JmxSupport.java
@@ -46,6 +46,7 @@ import brooklyn.util.jmx.jmxrmi.JmxRmiAgent;
import brooklyn.util.maven.MavenArtifact;
import brooklyn.util.maven.MavenRetriever;
import brooklyn.util.net.Urls;
+import brooklyn.util.task.Tasks;
import brooklyn.util.text.Strings;
import com.google.common.base.Preconditions;
@@ -320,8 +321,13 @@ public class JmxSupport implements UsesJmx {
/** installs files needed for JMX, to the runDir given in constructor, assuming the runDir has been created */
public void install() {
if (EnumSet.of(JmxAgentModes.JMXMP_AND_RMI, JmxAgentModes.JMXMP, JmxAgentModes.JMX_RMI_CUSTOM_AGENT).contains(getJmxAgentMode())) {
- getMachine().get().copyTo(ResourceUtils.create(this).getResourceFromUrl(
- getJmxAgentJarUrl()), getJmxAgentJarDestinationFilePath());
+ Tasks.setBlockingDetails("Copying JMX agent jar to server.");
+ try {
+ getMachine().get().copyTo(ResourceUtils.create(this).getResourceFromUrl(
+ getJmxAgentJarUrl()), getJmxAgentJarDestinationFilePath());
+ } finally {
+ Tasks.resetBlockingDetails();
+ }
}
if (isSecure()) {
getJmxSslSupport().install();
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eca81924/software/base/src/main/java/brooklyn/entity/java/JmxmpSslSupport.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/java/JmxmpSslSupport.java b/software/base/src/main/java/brooklyn/entity/java/JmxmpSslSupport.java
index b652abb..4a4faf8 100644
--- a/software/base/src/main/java/brooklyn/entity/java/JmxmpSslSupport.java
+++ b/software/base/src/main/java/brooklyn/entity/java/JmxmpSslSupport.java
@@ -32,6 +32,7 @@ import brooklyn.util.crypto.SecureKeys;
import brooklyn.util.exceptions.Exceptions;
import brooklyn.util.jmx.jmxmp.JmxmpAgent;
import brooklyn.util.net.Urls;
+import brooklyn.util.task.Tasks;
import com.google.common.base.Preconditions;
@@ -96,11 +97,15 @@ public class JmxmpSslSupport {
ByteArrayOutputStream agentTrustStoreBytes = new ByteArrayOutputStream();
agentTrustStore.store(agentTrustStoreBytes, "".toCharArray());
- // install the truststore and keystore
- jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentKeyStoreBytes.toByteArray()), getJmxSslKeyStoreFilePath());
- jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentTrustStoreBytes.toByteArray()), getJmxSslTrustStoreFilePath());
-
- // and rely on JmxSupport to install the agent
+ // install the truststore and keystore and rely on JmxSupport to install the agent
+ Tasks.setBlockingDetails("Copying keystore and truststore to the server.");
+ try {
+ jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentKeyStoreBytes.toByteArray()), getJmxSslKeyStoreFilePath());
+ jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentTrustStoreBytes.toByteArray()), getJmxSslTrustStoreFilePath());
+ } finally {
+ Tasks.resetBlockingDetails();
+ }
+
} catch (Exception e) {
throw Exceptions.propagate(e);
}
[6/9] incubator-brooklyn git commit: JcloudsLocationResolver
extensible
Posted by sj...@apache.org.
JcloudsLocationResolver extensible
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/326583f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/326583f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/326583f1
Branch: refs/heads/master
Commit: 326583f144114140ec6c9f3e0ec926e24d01f624
Parents: cf49a2b
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri May 22 15:32:11 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:45:01 2015 +0100
----------------------------------------------------------------------
.../basic/LocalhostLocationResolver.java | 3 ++-
.../jclouds/JcloudsLocationResolver.java | 20 ++++++++++++--------
.../jclouds/BrooklynMachinePoolLiveTest.java | 2 +-
3 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/326583f1/core/src/main/java/brooklyn/location/basic/LocalhostLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/LocalhostLocationResolver.java b/core/src/main/java/brooklyn/location/basic/LocalhostLocationResolver.java
index 08963a4..6451ed1 100644
--- a/core/src/main/java/brooklyn/location/basic/LocalhostLocationResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/LocalhostLocationResolver.java
@@ -58,7 +58,8 @@ public class LocalhostLocationResolver extends AbstractLocationResolver implemen
protected SpecParser getSpecParser() {
return new AbstractLocationResolver.SpecParser(getPrefix()).setExampleUsage("\"localhost\" or \"localhost(displayName=abc)\"");
}
-
+
+ @Override
protected Map<String, Object> getFilteredLocationProperties(String provider, String namedLocation, Map<String, ?> globalProperties) {
return new LocalhostPropertiesFromBrooklynProperties().getLocationProperties("localhost", namedLocation, globalProperties);
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/326583f1/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationResolver.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationResolver.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationResolver.java
index 5d42da3..3a90653 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationResolver.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationResolver.java
@@ -50,7 +50,7 @@ public class JcloudsLocationResolver implements LocationResolver {
public static final Logger log = LoggerFactory.getLogger(JcloudsLocationResolver.class);
- public static final String JCLOUDS = "jclouds";
+ private static final String JCLOUDS = "jclouds";
public static final Map<String,ProviderMetadata> PROVIDERS = getProvidersMap();
public static final Map<String,ApiMetadata> APIS = getApisMap();
@@ -83,15 +83,15 @@ public class JcloudsLocationResolver implements LocationResolver {
this.managementContext = checkNotNull(managementContext, "managementContext");
}
- protected static class JcloudsSpecParser {
+ protected class JcloudsSpecParser {
String providerOrApi;
String parameter;
- public static JcloudsSpecParser parse(String spec, boolean dryrun) {
+ public JcloudsSpecParser parse(String spec, boolean dryrun) {
JcloudsSpecParser result = new JcloudsSpecParser();
int split = spec.indexOf(':');
if (split<0) {
- if (spec.equalsIgnoreCase(JCLOUDS)) {
+ if (spec.equalsIgnoreCase(getPrefix())) {
if (dryrun) return null;
throw new IllegalArgumentException("Cannot use '"+spec+"' as a location ID; it is insufficient. "+
"Try jclouds:aws-ec2 (for example).");
@@ -102,7 +102,7 @@ public class JcloudsLocationResolver implements LocationResolver {
result.providerOrApi = spec.substring(0, split);
result.parameter = spec.substring(split+1);
int numJcloudsPrefixes = 0;
- while (result.providerOrApi.equalsIgnoreCase(JCLOUDS)) {
+ while (result.providerOrApi.equalsIgnoreCase(getPrefix())) {
//strip any number of jclouds: prefixes, for use by static "resolve" method
numJcloudsPrefixes++;
result.providerOrApi = result.parameter;
@@ -152,7 +152,7 @@ public class JcloudsLocationResolver implements LocationResolver {
public JcloudsLocation newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry registry) {
Map globalProperties = registry.getProperties();
- JcloudsSpecParser details = JcloudsSpecParser.parse(spec, false);
+ JcloudsSpecParser details = new JcloudsSpecParser().parse(spec, false);
String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName());
boolean isProvider = details.isProvider();
@@ -193,7 +193,7 @@ public class JcloudsLocationResolver implements LocationResolver {
}
}
- return managementContext.getLocationManager().createLocation(LocationSpec.create(JcloudsLocation.class)
+ return managementContext.getLocationManager().createLocation(LocationSpec.create(getLocationClass())
.configure(LocationConfigUtils.finalAndOriginalSpecs(spec, jcloudsProperties, globalProperties, namedLocation))
.configure(jcloudsProperties) );
}
@@ -210,11 +210,15 @@ public class JcloudsLocationResolver implements LocationResolver {
public String getPrefix() {
return JCLOUDS;
}
+
+ protected Class<? extends JcloudsLocation> getLocationClass() {
+ return JcloudsLocation.class;
+ }
@Override
public boolean accepts(String spec, LocationRegistry registry) {
if (BasicLocationRegistry.isResolverPrefixForSpec(this, spec, true)) return true;
- JcloudsSpecParser details = JcloudsSpecParser.parse(spec, true);
+ JcloudsSpecParser details = new JcloudsSpecParser().parse(spec, true);
if (details==null) return false;
if (details.isProvider() || details.isApi()) return true;
return false;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/326583f1/locations/jclouds/src/test/java/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java
index 3504570..7a52f04 100644
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java
+++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/BrooklynMachinePoolLiveTest.java
@@ -98,6 +98,6 @@ public class BrooklynMachinePoolLiveTest {
private JcloudsLocation resolve(String spec) {
- return (JcloudsLocation) managementContext.getLocationRegistry().resolve(JcloudsLocationResolver.JCLOUDS+":"+spec);
+ return (JcloudsLocation) managementContext.getLocationRegistry().resolve(new JcloudsLocationResolver().getPrefix() + ":" + spec);
}
}
[5/9] incubator-brooklyn git commit: Rejig LoggingFilter.
Posted by sj...@apache.org.
Rejig LoggingFilter.
Log requests that take longer than five seconds and log all non-HEAD/GET
requests (rather than only log POST, PUT and DELETE).
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/cf49a2b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/cf49a2b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/cf49a2b1
Branch: refs/heads/master
Commit: cf49a2b1729f8e19cd2c68131cccdde171205f61
Parents: df9f8bd
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon May 18 15:30:09 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:43:12 2015 +0100
----------------------------------------------------------------------
.../brooklyn/rest/filter/LoggingFilter.java | 41 +++++++++++---------
1 file changed, 22 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cf49a2b1/usage/rest-server/src/main/java/brooklyn/rest/filter/LoggingFilter.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/filter/LoggingFilter.java b/usage/rest-server/src/main/java/brooklyn/rest/filter/LoggingFilter.java
index b57ff72..bbe5d37 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/filter/LoggingFilter.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/filter/LoggingFilter.java
@@ -21,6 +21,7 @@ package brooklyn.rest.filter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -48,13 +49,15 @@ public class LoggingFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(BrooklynLogging.REST);
- /** Methods logged at debug rather than trace. */
- private static final Set<String> INTERESTING_METHODS = Sets.newHashSet("POST", "PUT", "DELETE");
+ /** Methods logged at trace. */
+ private static final Set<String> UNINTERESTING_METHODS = Sets.newHashSet("GET", "HEAD");
/** Headers whose values will not be logged. */
private static final Set<String> CENSORED_HEADERS = Sets.newHashSet("Authorization");
- @Override
+ /** Log all requests that take this time or longer to complete. */
+ private static final Duration REQUEST_DURATION_LOG_POINT = Duration.FIVE_SECONDS;
+
public void init(FilterConfig config) throws ServletException {
}
@@ -68,26 +71,25 @@ public class LoggingFilter implements Filter {
HttpServletResponse httpResponse = (HttpServletResponse) response;
String rid = RequestTaggingFilter.getTag();
- boolean isInteresting = INTERESTING_METHODS.contains(httpRequest.getMethod()),
- shouldLog = (isInteresting && LOG.isDebugEnabled()) || LOG.isTraceEnabled(),
- requestErrored = false;
- Stopwatch timer = Stopwatch.createUnstarted();
- try {
- if (shouldLog) {
- String message = "Request {} starting: {} {} from {}";
- Object[] args = new Object[]{rid, httpRequest.getMethod(), httpRequest.getRequestURI(), httpRequest.getRemoteAddr()};
- if (isInteresting) {
- LOG.debug(message, args);
- } else {
- LOG.trace(message, args);
- }
+ boolean isInteresting = !UNINTERESTING_METHODS.contains(httpRequest.getMethod().toUpperCase());
+ boolean shouldLog = (isInteresting && LOG.isDebugEnabled()) || LOG.isTraceEnabled();
+ boolean requestErrored = false;
+ if (shouldLog) {
+ String message = "Request {} starting: {} {} from {}";
+ Object[] args = new Object[]{rid, httpRequest.getMethod(), httpRequest.getRequestURI(), httpRequest.getRemoteAddr()};
+ if (isInteresting) {
+ LOG.debug(message, args);
+ } else {
+ LOG.trace(message, args);
}
+ }
- timer.start();
+ Stopwatch timer = Stopwatch.createStarted();
+ try {
chain.doFilter(request, response);
-
} catch (Throwable e) {
requestErrored = true;
+ isInteresting = true;
LOG.warn("Request " + rid + " ("+httpRequest.getMethod()+" "+httpRequest.getRequestURI()+" from "+httpRequest.getRemoteAddr()+") failed: " + e, e);
// Propagate for handling by other filter
throw Exceptions.propagate(e);
@@ -96,7 +98,8 @@ public class LoggingFilter implements Filter {
// This logging must not happen before chain.doFilter, or FormMapProvider will not work as expected.
// Getting the parameter map consumes the request body and only resource methods using @FormParam
// will work as expected.
- if (requestErrored || shouldLog) {
+ isInteresting |= (timer.elapsed(TimeUnit.SECONDS) - REQUEST_DURATION_LOG_POINT.toSeconds()) > 0;
+ if (shouldLog) {
boolean includeHeaders = requestErrored || httpResponse.getStatus() / 100 == 5 || LOG.isTraceEnabled();
String message = getRequestCompletedMessage(includeHeaders, Duration.of(timer), rid, httpRequest, httpResponse);
if (requestErrored || isInteresting) {
[2/9] incubator-brooklyn git commit: PropagatedRuntimeException logs
(at trace) if it's wrapping itself
Posted by sj...@apache.org.
PropagatedRuntimeException logs (at trace) if it's wrapping itself
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/711fb60a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/711fb60a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/711fb60a
Branch: refs/heads/master
Commit: 711fb60a10ca3f5cf77c7220f016bc1d2bbe9572
Parents: 5031d4f
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Thu May 14 19:50:52 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:38:52 2015 +0100
----------------------------------------------------------------------
.../exceptions/PropagatedRuntimeException.java | 25 ++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/711fb60a/utils/common/src/main/java/brooklyn/util/exceptions/PropagatedRuntimeException.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/exceptions/PropagatedRuntimeException.java b/utils/common/src/main/java/brooklyn/util/exceptions/PropagatedRuntimeException.java
index 8327d21..07f4ca7 100644
--- a/utils/common/src/main/java/brooklyn/util/exceptions/PropagatedRuntimeException.java
+++ b/utils/common/src/main/java/brooklyn/util/exceptions/PropagatedRuntimeException.java
@@ -18,36 +18,53 @@
*/
package brooklyn.util.exceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/** Indicates a runtime exception which has been propagated via {@link Exceptions#propagate} */
public class PropagatedRuntimeException extends RuntimeException {
private static final long serialVersionUID = 3959054308510077172L;
+ private static final Logger LOG = LoggerFactory.getLogger(PropagatedRuntimeException.class);
- final boolean causeEmbeddedInMessage;
+ private final boolean causeEmbeddedInMessage;
/** Callers should typically *not* attempt to summarise the cause in the message here; use toString() to get extended information */
public PropagatedRuntimeException(String message, Throwable cause) {
super(message, cause);
+ warnIfWrapping(cause);
causeEmbeddedInMessage = message.endsWith(Exceptions.collapseText(getCause()));
}
public PropagatedRuntimeException(String message, Throwable cause, boolean causeEmbeddedInMessage) {
super(message, cause);
+ warnIfWrapping(cause);
this.causeEmbeddedInMessage = causeEmbeddedInMessage;
}
public PropagatedRuntimeException(Throwable cause) {
super("" /* do not use default message as that destroys the toString */, cause);
+ warnIfWrapping(cause);
causeEmbeddedInMessage = false;
}
+ private void warnIfWrapping(Throwable cause) {
+ if (LOG.isTraceEnabled() && cause instanceof PropagatedRuntimeException) {
+ LOG.trace("Wrapping a PropagatedRuntimeException in another PropagatedRuntimeException. Call chain:", new Exception());
+ }
+ }
+
@Override
public String toString() {
- if (causeEmbeddedInMessage) return super.toString();
- else return Exceptions.appendSeparator(super.toString(), Exceptions.collapseText(getCause()));
+ if (causeEmbeddedInMessage) {
+ return super.toString();
+ } else {
+ return Exceptions.appendSeparator(super.toString(), Exceptions.collapseText(getCause()));
+ }
}
-
+
public boolean isCauseEmbeddedInMessage() {
return causeEmbeddedInMessage;
}
+
}
[7/9] incubator-brooklyn git commit: Expose predicate for finding
machines when rebinding
Posted by sj...@apache.org.
Expose predicate for finding machines when rebinding
Exposes the predicate to subclasses of JcloudsLocation
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6e1cb1fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6e1cb1fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6e1cb1fa
Branch: refs/heads/master
Commit: 6e1cb1fa321599cdf348cb1dca2bf9173913acf4
Parents: 326583f
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri May 29 14:44:14 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 14:45:04 2015 +0100
----------------------------------------------------------------------
.../location/jclouds/JcloudsLocation.java | 125 ++++++++++++-------
1 file changed, 83 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6e1cb1fa/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index d0cc0ce..cb973ce 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1608,50 +1608,25 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
*/
public JcloudsSshMachineLocation rebindMachine(ConfigBag setup) throws NoMachinesAvailableException {
try {
- if (setup.getDescription()==null) setCreationString(setup);
-
- final String rawId = (String) setup.getStringKey("id");
- final String rawHostname = (String) setup.getStringKey("hostname");
+ if (setup.getDescription() == null) setCreationString(setup);
String user = checkNotNull(getUser(setup), "user");
- final String rawRegion = (String) setup.getStringKey("region");
-
- LOG.info("Rebinding to VM {} ({}@{}), in jclouds location for provider {}",
- new Object[] {rawId!=null ? rawId : "<lookup>",
- user,
- (rawHostname != null ? rawHostname : "<unspecified>"),
- getProvider()});
-
+ String rawId = (String) setup.getStringKey("id");
+ String rawHostname = (String) setup.getStringKey("hostname");
+ Predicate<ComputeMetadata> predicate = getRebindToMachinePredicate(setup);
+ LOG.info("Rebinding to VM {} ({}@{}), in jclouds location for provider {} matching {}", new Object[]{
+ rawId != null ? rawId : "<lookup>",
+ user,
+ rawHostname != null ? rawHostname : "<unspecified>",
+ getProvider(),
+ predicate
+ });
ComputeService computeService = getConfig(COMPUTE_SERVICE_REGISTRY).findComputeService(setup, true);
-
- Set<? extends NodeMetadata> candidateNodes = computeService.listNodesDetailsMatching(new Predicate<ComputeMetadata>() {
- @Override
- public boolean apply(ComputeMetadata input) {
- // ID exact match
- if (rawId!=null) {
- if (rawId.equals(input.getId())) return true;
- // AWS format
- if (rawRegion!=null && (rawRegion+"/"+rawId).equals(input.getId())) return true;
- }
- // else do node metadata lookup
- if (!(input instanceof NodeMetadata)) return false;
- if (rawHostname!=null && rawHostname.equalsIgnoreCase( ((NodeMetadata)input).getHostname() )) return true;
- if (rawHostname!=null && ((NodeMetadata)input).getPublicAddresses().contains(rawHostname)) return true;
-
- if (rawId!=null && rawId.equalsIgnoreCase( ((NodeMetadata)input).getHostname() )) return true;
- if (rawId!=null && ((NodeMetadata)input).getPublicAddresses().contains(rawId)) return true;
- // don't do private IP's because those might be repeated
-
- if (rawId!=null && rawId.equalsIgnoreCase( ((NodeMetadata)input).getProviderId() )) return true;
- if (rawHostname!=null && rawHostname.equalsIgnoreCase( ((NodeMetadata)input).getProviderId() )) return true;
-
- return false;
- }
- });
-
- if (candidateNodes.isEmpty())
- throw new IllegalArgumentException("Jclouds node not found for rebind, looking for id="+rawId+" and hostname="+rawHostname);
- if (candidateNodes.size()>1)
- throw new IllegalArgumentException("Jclouds node for rebind matching multiple, looking for id="+rawId+" and hostname="+rawHostname+": "+candidateNodes);
+ Set<? extends NodeMetadata> candidateNodes = computeService.listNodesDetailsMatching(predicate);
+ if (candidateNodes.isEmpty()) {
+ throw new IllegalArgumentException("Jclouds node not found for rebind with predicate " + predicate);
+ } else if (candidateNodes.size() > 1) {
+ throw new IllegalArgumentException("Jclouds node for rebind matched multiple with " + predicate + ": " + candidateNodes);
+ }
NodeMetadata node = Iterables.getOnlyElement(candidateNodes);
String pkd = LocationConfigUtils.getOsCredential(setup).checkNoErrors().logAnyWarnings().getPrivateKeyData();
@@ -1676,6 +1651,72 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
return rebindMachine(setup);
}
+ /**
+ * @return a predicate that returns true if a {@link ComputeMetadata} instance is suitable for
+ * rebinding to given the configuration in {@link ConfigBag config}.
+ */
+ protected Predicate<ComputeMetadata> getRebindToMachinePredicate(ConfigBag config) {
+ return new RebindToMachinePredicate(config);
+ }
+
+ /**
+ * Determines whether a machine may be rebinded to by comparing the given id, hostname and region
+ * against the node's id, hostname, provider id and public addresses.
+ */
+ private static class RebindToMachinePredicate implements Predicate<ComputeMetadata> {
+
+ final String rawId;
+ final String rawHostname;
+ final String rawRegion;
+
+ public RebindToMachinePredicate(ConfigBag config) {
+ rawId = (String) config.getStringKey("id");
+ rawHostname = (String) config.getStringKey("hostname");
+ rawRegion = (String) config.getStringKey("region");
+ }
+
+ @Override
+ public boolean apply(ComputeMetadata input) {
+ // ID exact match
+ if (rawId != null) {
+ // Second is AWS format
+ if (rawId.equals(input.getId()) || rawRegion != null && (rawRegion + "/" + rawId).equals(input.getId())) {
+ return true;
+ }
+ }
+
+ // else do node metadata lookup
+ if (input instanceof NodeMetadata) {
+ NodeMetadata node = NodeMetadata.class.cast(input);
+ if (rawHostname != null && rawHostname.equalsIgnoreCase(node.getHostname()))
+ return true;
+ if (rawHostname != null && node.getPublicAddresses().contains(rawHostname))
+ return true;
+ if (rawId != null && rawId.equalsIgnoreCase(node.getHostname()))
+ return true;
+ if (rawId != null && node.getPublicAddresses().contains(rawId))
+ return true;
+ // don't do private IPs because they might be repeated
+ if (rawId != null && rawId.equalsIgnoreCase(node.getProviderId()))
+ return true;
+ if (rawHostname != null && rawHostname.equalsIgnoreCase(node.getProviderId()))
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this)
+ .omitNullValues()
+ .add("id", rawId)
+ .add("hostname", rawHostname)
+ .add("region", rawRegion)
+ .toString();
+ }
+ }
+
// -------------- create the SshMachineLocation instance, and connect to it etc ------------------------
/** @deprecated since 0.7.0 use {@link #registerJcloudsSshMachineLocation(ComputeService, NodeMetadata, LoginCredentials, Optional, ConfigBag)} */
[9/9] incubator-brooklyn git commit: This closes #655
Posted by sj...@apache.org.
This closes #655
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fc3851b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fc3851b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fc3851b3
Branch: refs/heads/master
Commit: fc3851b3d65017556c809847a759352cd8d7162a
Parents: 7519476 eca8192
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri May 29 15:53:18 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Fri May 29 15:53:18 2015 +0100
----------------------------------------------------------------------
.../basic/LocalhostLocationResolver.java | 3 +-
.../management/internal/EffectorUtils.java | 12 +-
.../location/jclouds/JcloudsLocation.java | 125 +++++++++------
.../jclouds/JcloudsLocationResolver.java | 20 ++-
.../jclouds/BrooklynMachinePoolLiveTest.java | 2 +-
.../java/brooklyn/entity/java/JmxSupport.java | 10 +-
.../brooklyn/entity/java/JmxmpSslSupport.java | 15 +-
.../src/test/javascript/specs/brooklyn-spec.js | 129 ----------------
.../javascript/specs/brooklyn-utils-spec.js | 151 -------------------
.../src/test/javascript/specs/router-spec.js | 4 +-
.../test/javascript/specs/util/brooklyn-spec.js | 128 ++++++++++++++++
.../specs/util/brooklyn-utils-spec.js | 151 +++++++++++++++++++
.../brooklyn/rest/filter/LoggingFilter.java | 41 ++---
.../exceptions/PropagatedRuntimeException.java | 25 ++-
14 files changed, 450 insertions(+), 366 deletions(-)
----------------------------------------------------------------------