jmxCtrl.js 4.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed 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.
 */
'use strict';

module.exports = function ($scope, $modal, $log, application, ApplicationJMX) {
    $scope.error = null;
    $scope.domains = [];

    ApplicationJMX.list(application)
        .then(function (domains) {
            $scope.domains = domains;
        })
        .catch(function (response) {
            $scope.error = response.error;
            $log.error(response.stacktrace);
        });

    $scope.readAllAttr = function (bean) {
        bean.error = null;
        ApplicationJMX.readAllAttr(application, bean)
            .then(
                function (response) {
                    for (var name in response.value) {
                        bean.attributes[name].error = null;
                        bean.attributes[name].value = response.value[name];
                        bean.attributes[name].jsonValue = JSON.stringify(response.value[
                            name], null, '   ');
                    }
                })
            .catch(function (response) {
                bean.error = response.error;
                $log.error(response.stacktrace);
            });
    };

    $scope.writeAttr = function (bean, name, attr) {
        attr.error = null;
        ApplicationJMX.writeAttr(application, bean, name, attr.value)
            .catch(
                function (response) {
                    attr.error = response.error;
                    $log.error(response.stacktrace);
                });
    };

    $scope.invoke = function () {
        $scope.invocation.state = 'executing';

        ApplicationJMX.invoke(application, $scope.invocation.bean, $scope.invocation.opname,
                $scope.invocation.args)
            .then(
                function (response) {
                    $scope.invocation.state = 'success';
                    $scope.invocation.result = response.value;
                })
            .catch(function (response) {
                $scope.invocation.state = 'error';
                $scope.invocation.error = response.error;
                $scope.invocation.stacktrace = response.stacktrace;
            });

        $modal.open({
                templateUrl: 'invocationResultDialog.html',
                scope: $scope
            })
            .result.then(function () {
                $scope.invocation = null;
            });
    };

    $scope.prepareInvoke = function (bean, name, op) {
        $scope.invocation = {
            bean: bean,
            opname: name,
            opdesc: op,
            args: [],
            state: 'prepare'
        };

        if (op instanceof Array) {
            $modal.open({
                    templateUrl: 'invocationVariantDialog.html',
                    scope: $scope
                })
                .result.then(function (chosenOp) {
                    $scope.prepareInvoke(bean, name, chosenOp);
                })
                .catch(function () {
                    $scope.invocation = null;
                });
        } else {
105 106 107 108 109 110 111 112 113 114 115
            var signature = '(';
            for (var i in op.args) {
                if (i > 0) {
                    signature += ',';
                }
                signature += op.args[i].type;
                $scope.invocation.args[i] = null;
            }
            signature += ')';
            $scope.invocation.opname = name + signature;

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
            if (op.args.length === 0) {
                $scope.invoke();
            } else {
                $modal.open({
                        templateUrl: 'invocationPrepareDialog.html',
                        scope: $scope
                    })
                    .result.then(function () {
                        $scope.invoke();
                    })
                    .catch(function () {
                        $scope.invocation = null;
                    });
            }
        }
    };
};