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 2016/02/01 18:51:36 UTC
[17/50] brooklyn-ui git commit: add renderer hints to core,
example for ROOT_URL, and code to display sensor actions nicely in web console
add renderer hints to core, example for ROOT_URL, and code to display sensor actions nicely in web console
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/c43e60dc
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/c43e60dc
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/c43e60dc
Branch: refs/heads/0.4.0
Commit: c43e60dc41e82d225e7a25c648a28ff616e4e7e8
Parents: 10c5d2b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Sun May 6 05:57:25 2012 +0300
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Sun May 6 05:57:25 2012 +0300
----------------------------------------------------------------------
.../web/console/EntityController.groovy | 20 +++++++++++
.../web/console/TestWebApplication.groovy | 9 +++--
.../web/console/entity/SensorSummary.groovy | 11 ++++--
.../grails-app/views/detail/_main.gsp | 2 +-
.../grails-app/views/detail/_main.haml | 2 +-
.../console/detail-tab/detail-tabs/sensors.js | 36 ++++++++++++++------
6 files changed, 63 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy b/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
index ed119cc..121546e 100644
--- a/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
+++ b/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
@@ -158,6 +158,26 @@ class EntityController {
render(status: 404, text: '{message: "Entity with specified id '+params.id+'does not exist"}')
}
}
+ def sensor = {
+ if (!params.entityId) {
+ render(status: 400, text: '{message: "You must provide an entityId"}')
+ }
+ if (!params.sensorId) {
+ render(status: 400, text: '{message: "You must provide a sensorId"}')
+ }
+
+ try {
+ Entity ent = entityService.getEntity(params.entityId);
+ def v = ent.getAttribute(ent.getSensors().get(params.sensorId));
+ try { render(v as JSON) }
+ catch (Exception e) {
+ //not json, just return as text
+ render(text: ""+v)
+ }
+ } catch (NoSuchEntity e) {
+ render(status: 404, text: '{message: "Entity with specified id '+params.entityId+'does not exist"}')
+ }
+ }
def activity = {
if (!params.id) {
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
index 6612c7f..8c120d6 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
@@ -22,12 +22,16 @@ import brooklyn.location.basic.SimulatedLocation
import brooklyn.management.Task
import brooklyn.policy.Policy
import brooklyn.policy.basic.GeneralPurposePolicy
+import brooklyn.util.BrooklynLanguageExtensions;
import brooklyn.util.internal.TimeExtras;
import brooklyn.util.task.ScheduledTask
import brooklyn.web.console.entity.TestEffector
// TODO remove these test classes as soon as the group agrees they're unnecessary!
private class TestWebApplication extends AbstractApplication {
+
+ static { BrooklynLanguageExtensions.reinit() }
+
TestWebApplication(Map props=[:]) {
super(props)
displayName = "Application";
@@ -218,7 +222,7 @@ private class TestWebApplication extends AbstractApplication {
this.policies = testPolicies;
// Stealing the sensors from TomcatNode
- this.sensors.putAll(new TomcatServer().sensors)
+ this.sensors.putAll(new TomcatServer().sensors);
List<ParameterType<?>> parameterTypeList = new ArrayList<ParameterType<?>>()
ParameterType tomcatStartLocation = new BasicParameterType("Location", new ArrayList<String>().class)
@@ -251,7 +255,8 @@ private class TestWebApplication extends AbstractApplication {
description: "This updates sensor values",
{ updateSensorsWithRandoms(TestTomcatEntity.this); }));
- updateSensorsWithRandoms(this);
+ updateSensorsWithRandoms(this);
+ setAttribute(sensors.get("webapp.url"), "http://localhost:8080/my-web-app-here");
}
public <T> Task<T> invoke(Effector<T> eff, Map<String, ?> parameters) {
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/grails-app/utils/brooklyn/web/console/entity/SensorSummary.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/SensorSummary.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/SensorSummary.groovy
index 3fb56b4..5826ef7 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/SensorSummary.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/SensorSummary.groovy
@@ -3,6 +3,8 @@ package brooklyn.web.console.entity
import java.text.DateFormat
import java.text.SimpleDateFormat
+import brooklyn.config.render.RendererHints
+import brooklyn.config.render.RendererHints.NamedActionWithUrl
import brooklyn.event.Sensor
import brooklyn.event.SensorEvent
@@ -18,7 +20,7 @@ public class SensorSummary {
public final String description
public final String value
public final String timestamp
- public final String actions
+ public final Set actions
// formatter is not thread-safe; use thread-local storage
private static final ThreadLocal<DateFormat> formatter = new ThreadLocal<DateFormat>() {
@@ -34,7 +36,12 @@ public class SensorSummary {
this.description = sensor.description
this.value = value
this.timestamp = formatter.get().format(new Date())
- this.actions = [ "open": "http://www.google.com/" ]
+ this.actions = [];
+ for (NamedActionWithUrl h: RendererHints.getHintsFor(sensor, NamedActionWithUrl)) {
+ String target = h.getUrlFromValue(value);
+ if (target)
+ actions << [name: h.actionName, url: target]
+ }
}
public SensorSummary(SensorEvent event) {
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/grails-app/views/detail/_main.gsp
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/views/detail/_main.gsp b/usage/web-console/grails-app/views/detail/_main.gsp
index c6e7eca..6a1f3ad 100644
--- a/usage/web-console/grails-app/views/detail/_main.gsp
+++ b/usage/web-console/grails-app/views/detail/_main.gsp
@@ -32,7 +32,7 @@
<table class='tab-content-table' id='sensor-data'></table>
</div>
<div class='sensor-bottom-buttons'>
- <a href='javascript:Brooklyn.sensors.update();'>RELOAD</a>
+ <a href='javascript:Brooklyn.sensors.updateSensors();'>RELOAD</a>
<a href='javascript:Brooklyn.sensors.toggleShowEmptySensors();'>FILTER</a>
</div>
</div>
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/grails-app/views/detail/_main.haml
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/views/detail/_main.haml b/usage/web-console/grails-app/views/detail/_main.haml
index 869917d..e90d4b5 100644
--- a/usage/web-console/grails-app/views/detail/_main.haml
+++ b/usage/web-console/grails-app/views/detail/_main.haml
@@ -22,7 +22,7 @@
.sensor-table
%table{:id=>"sensor-data", :class=>"tab-content-table"}
.sensor-bottom-buttons
- %a{:href=>"javascript:Brooklyn.sensors.update();"}RELOAD
+ %a{:href=>"javascript:Brooklyn.sensors.updateSensors();"}RELOAD
%a{:href=>"javascript:Brooklyn.sensors.toggleShowEmptySensors();"}FILTER
#effectors{:tabindex=>"2"}
%g:render{:template=>"detail-tabs/effectors"}
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/c43e60dc/usage/web-console/web-app/js/console/detail-tab/detail-tabs/sensors.js
----------------------------------------------------------------------
diff --git a/usage/web-console/web-app/js/console/detail-tab/detail-tabs/sensors.js b/usage/web-console/web-app/js/console/detail-tab/detail-tabs/sensors.js
index a4c8f82..440e004 100644
--- a/usage/web-console/web-app/js/console/detail-tab/detail-tabs/sensors.js
+++ b/usage/web-console/web-app/js/console/detail-tab/detail-tabs/sensors.js
@@ -1,25 +1,30 @@
Brooklyn.sensors = (function() {
+ var parent;
+
function SensorsTab() {
this.id = 'sensors';
- this.update = function() {
- if (typeof this.entity_id !== 'undefined') {
- $.getJSON("../entity/sensors?id=" + this.entity_id, this.updateTableData).error(
- function() {$(Brooklyn.eventBus).trigger('update_failed', "Could not get sensor data.");}
- );
- }
- };
+ parent = this;
+ this.update = function() { updateSensors(); }
this.updateTableData = function(json) {
for (i in json) {
- json[i].actionHtml = '<a href="www.google.com" target="_new">Open</a>';
json[i].nameWithToolTip = '<div title="'+json[i].description+'">'+json[i].name+'</div>';
+ var actions = json[i].actions;
+ json[i].actionHtml = '';
+ for (ai in actions) {
+ json[i].actionHtml = json[i].actionHtml + ' <b><a href="'+
+ actions[ai].url+'" target="_new">'+
+ actions[ai].name+'</a></b> ';
+ }
+ if (typeof parent.entity_id !== 'undefined') {
+ json[i].actionHtml = json[i].actionHtml + ' <a href="'+
+ '../entity/sensor?entityId='+parent.entity_id+'&sensorId='+json[i].name+'" target="_new">JSON</a> ';
+ }
+ // others, e.g. little graphs
}
- console.log("sensors update");
- console.log(json);
var table = Brooklyn.util.getDataTable('#sensor-data');
- console.log(table);
table.fnClearTable(false);
table.fnAddData(json);
@@ -49,6 +54,14 @@ Brooklyn.sensors = (function() {
table.fnFilter( '.+', 1, true );
}
+ function updateSensors() {
+ if (typeof parent.entity_id !== 'undefined') {
+ $.getJSON("../entity/sensors?id=" + parent.entity_id, parent.updateTableData).error(
+ function() {$(Brooklyn.eventBus).trigger('update_failed', "Could not get sensor data.");}
+ );
+ }
+ }
+
var showEmptySensors = false;
function toggleShowEmptySensors() {
setShowEmptySensors(!showEmptySensors)
@@ -62,6 +75,7 @@ Brooklyn.sensors = (function() {
return {
init: init,
+ updateSensors: updateSensors,
toggleShowEmptySensors: toggleShowEmptySensors,
setSensorEmptyFilter: setShowEmptySensors
};