Commit 5e55293b by Johannes Edmeier

Fix using objects as arguments for jmx operations

With this commit objects are passed now correctly to jolokia. The object's needs to be written in json, which is validated for well- formedness. From now on the attributes are read autmatically when the bean gets selected and I fixed that errors weren't displayed. fixes #301
parent e0bd77bf
...@@ -18,17 +18,15 @@ ...@@ -18,17 +18,15 @@
var angular = require('angular'); var angular = require('angular');
module.exports = { module.exports = {
bindings: { bindings: {
value: '=model', value: '<sbaValue',
disabled: '<disabled', disabled: '<sbaDisabled',
type: '@type' type: '@sbaType',
onChange: '&sbaChange'
}, },
controller: function ($scope) { controller: function () {
'ngInject'; 'ngInject';
var ctrl = this; var ctrl = this;
ctrl.jsonEdited = function () {
ctrl.value = angular.fromJson($scope.json);
};
ctrl.$onInit = function () { ctrl.$onInit = function () {
ctrl.inputType = (function () { ctrl.inputType = (function () {
...@@ -50,7 +48,7 @@ module.exports = { ...@@ -50,7 +48,7 @@ module.exports = {
default: default:
return null; return null;
} }
}()); } ());
ctrl.selectOptions = (function () { ctrl.selectOptions = (function () {
switch (ctrl.type) { switch (ctrl.type) {
...@@ -64,10 +62,23 @@ module.exports = { ...@@ -64,10 +62,23 @@ module.exports = {
})(); })();
ctrl.isObject = ctrl.selectOptions === null && ctrl.inputType === null; ctrl.isObject = ctrl.selectOptions === null && ctrl.inputType === null;
};
ctrl.$onChanges = function () {
if (ctrl.isObject) { if (ctrl.isObject) {
$scope.$watch('$ctrl.value', function (value) { ctrl.json = angular.toJson(ctrl.value, true);
ctrl.json = angular.toJson(value, true); }
}); };
ctrl.valueChanged = function () {
ctrl.onChange({ value: ctrl.value, error: null });
};
ctrl.jsonChanged = function () {
try {
ctrl.onChange({ value: angular.fromJson(ctrl.json), error: null });
} catch (error) {
ctrl.onChange({ value: null, error: error });
} }
}; };
}, },
......
<input ng-show="$ctrl.inputType" class="input-xxlarge" type="{{$ctrl.inputType}}" ng-model="$ctrl.value" ng-disabled="$ctrl.disabled" /> <input ng-show="$ctrl.inputType" class="input-xxlarge" type="{{$ctrl.inputType}}" ng-model="$ctrl.value" ng-readonly="$ctrl.disabled"
<select ng-show="$ctrl.selectOptions" class="input-xxlarge" ng-model="$ctrl.value" ng-disabled="$ctrl.disabled"> ng-change="$ctrl.valueChanged()"></input>
<select ng-show="$ctrl.selectOptions" class="input-xxlarge" ng-model="$ctrl.value" ng-readonly="$ctrl.disabled" ng-change="$ctrl.valueChanged()">
<option ng-repeat="opt in $ctrl.selectOptions" value="{{opt}}" ng-selected="$ctrl.value == opt">{{opt}}</option> <option ng-repeat="opt in $ctrl.selectOptions" value="{{opt}}" ng-selected="$ctrl.value == opt">{{opt}}</option>
</select> </select>
<textarea ng-show="$ctrl.isObject" style="word-break: break-all;" class="input-xxlarge" rows="6" ng-model="$ctrl.json" ng-blur="$ctrl.jsonEdited" ng-disabled="$ctrl.disabled" /> <textarea ng-show="$ctrl.isObject" style="word-break: break-all;" class="input-xxlarge" rows="6" ng-model="$ctrl.json" ng-change="$ctrl.jsonChanged()"
ng-readonly="$ctrl.disabled"></textarea>
\ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
'use strict'; 'use strict';
var angular = require('angular');
module.exports = { module.exports = {
bindings: { bindings: {
bean: '<bean', bean: '<bean',
...@@ -24,19 +25,32 @@ module.exports = { ...@@ -24,19 +25,32 @@ module.exports = {
'ngInject'; 'ngInject';
var ctrl = this; var ctrl = this;
ctrl.attributeValues = {};
ctrl.attributeErrors = {};
ctrl.error = null;
ctrl.invocation = null; ctrl.invocation = null;
ctrl.$onChanges = function () {
if (ctrl.bean) {
ctrl.initAttributes();
ctrl.readAttributeValues();
} else {
ctrl.attributes = {};
ctrl.error = null;
}
};
ctrl.initAttributes = function () {
ctrl.attributes = {};
angular.forEach(ctrl.bean.attributes, function (descriptor, name) {
ctrl.attributes[name] = { value: null, error: null, descriptor: descriptor };
});
};
ctrl.readAttributeValues = function () { ctrl.readAttributeValues = function () {
ctrl.readingAttributes = true; ctrl.readingAttributes = true;
ctrl.error = null; ctrl.error = null;
ctrl.attributeErrors = {};
ctrl.attributeValues = {};
ApplicationJmx.readAllAttr(ctrl.application, ctrl.bean).then( ApplicationJmx.readAllAttr(ctrl.application, ctrl.bean).then(
function (response) { function (response) {
ctrl.attributeValues = response.value; angular.forEach(response.value, function (value, name) {
ctrl.attributes[name].value = value;
});
ctrl.readingAttributes = false; ctrl.readingAttributes = false;
} }
).catch(function (response) { ).catch(function (response) {
...@@ -45,11 +59,16 @@ module.exports = { ...@@ -45,11 +59,16 @@ module.exports = {
}); });
}; };
ctrl.writeAttributeValue = function (name, value) { ctrl.updateAttributeValue = function (name, value, error) {
ctrl.attributeErrors[name] = null; ctrl.attributes[name].value = value;
ApplicationJmx.writeAttr(ctrl.application, ctrl.bean, name, value).catch( ctrl.attributes[name].error = error;
};
ctrl.writeAttributeValue = function (name) {
ctrl.attributes[name].error = null;
ApplicationJmx.writeAttr(ctrl.application, ctrl.bean, name, ctrl.attributes[name].value).catch(
function (response) { function (response) {
ctrl.attributeErrors[name] = response.error; ctrl.attributes[name].error = response.error;
}); });
}; };
......
<h3 ng-bind="$ctrl.bean.name"><br/><small ng-bind="$ctrl.bean.description"></small></h3> <h3 ng-bind="$ctrl.bean.name"><br/><small ng-bind="$ctrl.bean.description"></small></h3>
<div ng-show="error" class="alert alert-error"> <b>Error:</b> {{$ctrl.error}}</div> <div ng-show="$ctrl.error" class="alert alert-error"> <b>Error:</b> {{$ctrl.error}}</div>
<dl> <dl>
<dt>Id</dt> <dt>Id</dt>
<dd style="word-break: break-all;" ng-bind="$ctrl.bean.id"></dd> <dd style="word-break: break-all;" ng-bind="$ctrl.bean.id"></dd>
<dt ng-repeat-start="(name, value) in $ctrl.bean.nameProps" ng-bind="name"></dt> <dt ng-repeat-start="(name, value) in $ctrl.bean.nameProps" ng-bind="name"></dt>
<dd ng-repeat-end ng-bind="value"></dd> <dd ng-repeat-end ng-bind="value"></dd>
</dl> </dl>
<form class="form-horizontal"> <form class="form-horizontal">
<fieldset ng-show="$ctrl.bean.attributes"> <fieldset ng-show="$ctrl.bean.attributes">
<legend>Attributes <legend>Attributes
<button class="btn" ng-click="$ctrl.readAttributeValues()">read</button> <button class="btn" ng-click="$ctrl.readAttributeValues()">reload</button>
<span ng-show="$ctrl.readingAttributes"><i class="fa fa-spinner fa-pulse"></i></span> <span ng-show="$ctrl.readingAttributes"><i class="fa fa-spinner fa-pulse"></i></span>
</legend> </legend>
<div class="control-group" ng-repeat="(name, attribute) in $ctrl.bean.attributes track by name" ng-class="{error: $ctrl.attributeErrors[attribute.name]}"> <div class="control-group" ng-repeat="(name, attribute) in $ctrl.attributes track by name" ng-class="{error: attribute.error}">
<label class="control-label" for="{{name}}" style="word-break: break-all;"> <label class="control-label" for="{{name}}" style="word-break: break-all;">
{{name}} {{name}}
<br/><small class="muted" ng-bind="attribute.type"></small> <br/><small class="muted" ng-bind="attribute.descriptor.type"></small>
</label> </label>
<div class="controls"> <div class="controls">
<div class="input-prepend"> <div class="input-prepend">
<button class="btn" type="button" ng-click="$ctrl.writeAttributeValue(name, $ctrl.attributeValues[name])" ng-disabled="!attribute.rw">write</button> <button class="btn" type="button" ng-click="$ctrl.writeAttributeValue(name)" ng-disabled="!attribute.descriptor.rw">write</button>
<sba-java-type-input type="{{attribute.type}}" model="$ctrl.attributeValues[name]" disabled="!attribute.rw"></sba-java-type-input> <sba-java-type-input sba-type="{{attribute.descriptor.type}}" sba-value="attribute.value" sba-change="$ctrl.updateAttributeValue(name, value, error)"
</div> sba-disabled="!attribute.descriptor.rw"></sba-java-type-input>
<span class="help-block" ng-bind="attribute.desc"></span> </div>
<span class="help-inline" ng-bind="$ctrl.attributeErrors[name]"></span> <span class="help-block" ng-bind="attribute.descriptor.desc"></span>
</div> <span class="help-inline" ng-bind="attribute.error"></span>
</div> </div>
</fieldset> </div>
<fieldset ng-show="$ctrl.bean.operations"> </fieldset>
<legend>Operations</legend> <fieldset ng-show="$ctrl.bean.operations">
<div class="control-group" ng-if="!$ctrl.invocation"> <legend>Operations</legend>
<button ng-repeat="(name, op) in $ctrl.bean.operations track by name" class="btn btn-block" style="text-align: left; padding: 8px 15px;" ng-click="$ctrl.doInvoke(name, op)"> <div class="control-group" ng-if="!$ctrl.invocation">
<button ng-repeat="(name, op) in $ctrl.bean.operations track by name" class="btn btn-block" style="text-align: left; padding: 8px 15px;"
ng-click="$ctrl.doInvoke(name, op)">
<b ng-bind="name"></b> <b ng-bind="name"></b>
<span ng-if="!op.length">(<span ng-repeat-start="arg in op.args" data-toggle="tooltip" title="{{arg.desc}}">{{arg.type}} {{arg.name}}</span><span ng-repeat-end ng-if="!$last">, </span> )</span> <span ng-if="!op.length">(<span ng-repeat-start="arg in op.args" data-toggle="tooltip" title="{{arg.desc}}">{{arg.type}} {{arg.name}}</span><span ng-repeat-end ng-if="!$last">, </span> )</span>
<br/> <br/>
...@@ -38,9 +40,9 @@ ...@@ -38,9 +40,9 @@
<span class="help-block"><small class="muted" ng-show="op.length > 0">overloaded</small></span> <span class="help-block"><small class="muted" ng-show="op.length > 0">overloaded</small></span>
<span class="help-block" ng-bind="op.desc"></span> <span class="help-block" ng-bind="op.desc"></span>
</button> </button>
</div> </div>
<div ng-if="$ctrl.invocation"> <div ng-if="$ctrl.invocation">
<sba-jmx-invocation operation-name="$ctrl.invocation.name" operation-descriptor="$ctrl.invocation.operation" on-cancel="$ctrl.cancelInvoke()" /> <sba-jmx-invocation operation-name="$ctrl.invocation.name" operation-descriptor="$ctrl.invocation.operation" on-cancel="$ctrl.cancelInvoke()"></sba-jmx-invocation>
</div> </div>
</fieldset> </fieldset>
</form> </form>
\ No newline at end of file
...@@ -23,10 +23,21 @@ module.exports = { ...@@ -23,10 +23,21 @@ module.exports = {
var ctrl = this; var ctrl = this;
ctrl.$onInit = function () { ctrl.$onInit = function () {
ctrl.arguments = new Array(ctrl.invocation.descriptor.args.length); ctrl.arguments = new Array(ctrl.invocation.descriptor.args.length);
ctrl.errors = new Array(ctrl.invocation.descriptor.args.length);
}; };
ctrl.applyParameters = function () { ctrl.applyParameters = function () {
ctrl.invocation.arguments = ctrl.arguments; var hasError = ctrl.arguments.find(function (arg) {
ctrl.invocation.proceedJmxInvocation(); return arg !== null && arg.error !== null;
});
if (!hasError) {
ctrl.invocation.arguments = ctrl.arguments.map(function (arg) {
return arg.value;
});
ctrl.invocation.proceedJmxInvocation();
}
};
ctrl.updateArg = function (index, value, error) {
ctrl.arguments[index] = { value: value, error: error };
}; };
}, },
template: require('./jmxInvokeInputParameters.tpl.html') template: require('./jmxInvokeInputParameters.tpl.html')
......
<form class="form"> <form class="form">
<p>Please input the arguments for {{$ctrl.invocation.signature}} <small class="muted">: {{$ctrl.invocation.descriptor.ret}}</small></p> <p>Please input the arguments for {{$ctrl.invocation.signature}} <small class="muted">: {{$ctrl.invocation.descriptor.ret}}</small></p>
<div class="control-group" ng-repeat="arg in $ctrl.invocation.descriptor.args"> <div class="control-group" ng-repeat="arg in $ctrl.invocation.descriptor.args" ng-class="{ error : $ctrl.arguments[$index].error }">
<label class="control-label" for="{{arg.name}}" style="word-break: break-all;">{{arg.name}} <small class="muted" style="word-break: break-all;" ng-bind="arg.type"></small></label> <label class="control-label" for="{{arg.name}}" style="word-break: break-all;">{{arg.name}} <small class="muted" style="word-break: break-all;" ng-bind="arg.type"></small></label>
<div class="controls"> <div class="controls">
<sba-java-type-input type="{{arg.type}}" decription="{{arg.desc}}" model="$ctrl.arguments[$index]" /> <sba-java-type-input sba-type="{{arg.type}}" sba-decription="{{arg.desc}}" sba-change="$ctrl.updateArg($index, value, error)"></sba-java-type-input>
</div> <span class="help-inline" ng-bind="$ctrl.arguments[$index].error"></span>
</div> </div>
<button class="btn btn-primary" ng-click="$ctrl.applyParameters()">Execute</button> </div>
</form> <button class="btn btn-primary" ng-click="$ctrl.applyParameters()">Execute</button>
</form>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment