applicationJmx.js 3.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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';

18
module.exports = function ($rootScope, Abbreviator, jolokia, $q) {
19
    this.list = function (app) {
20
        return jolokia.list('api/applications/' + app.id + '/jolokia/')
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
            .then(function (response) {
                var domains = [];
                for (var rDomainName in response.value) {
                    var rDomain = response.value[rDomainName];
                    var domain = {
                        name: rDomainName,
                        beans: []
                    };

                    for (var rBeanName in rDomain) {
                        var rBean = rDomain[rBeanName];
                        var bean = {
                            id: domain.name + ':' + rBeanName,
                            name: '',
                            nameProps: {},
                            description: rBean.desc,
                            operations: rBean.op,
                            attributes: rBean.attr
                        };
                        var name = '';
                        var type = '';
                        var parts = rBeanName.split(',');
                        for (var i in parts) {
                            var tokens = parts[i].split('=');
                            if (tokens[0].toLowerCase() === 'name') {
                                name = tokens[1];
                            } else {
                                bean.nameProps[tokens[0]] = tokens[1];
                                if ((tokens[0].toLowerCase() === 'type' || tokens[0].toLowerCase() ===
                                        'j2eetype') && type.length === 0) {
                                    type = tokens[1];
                                }
                            }
                        }

                        if (name.length !== 0) {
                            bean.name = name;
                        }
                        if (type.length !== 0) {
                            if (bean.name !== 0) {
                                bean.name += ' ';
                            }
                            bean.name += '[' + Abbreviator.abbreviate(type, '.', 25, 1,
                                1) + ']';
                        }

                        if (bean.name.length === 0) {
                            bean.name = rBeanName;
                        }

                        domain.beans.push(bean);
                    }

                    domains.push(domain);
                }

                return domains;
            }, function (response) {
79
                return $q.reject(response);
80 81 82 83
            });
    };

    this.readAllAttr = function (app, bean) {
84
        return jolokia.read('api/applications/' + app.id + '/jolokia/', bean.id);
85 86 87
    };

    this.writeAttr = function (app, bean, attr, val) {
88
        return jolokia.writeAttr('api/applications/' + app.id + '/jolokia/', bean.id, attr, val);
89 90 91
    };

    this.invoke = function (app, bean, opname, args) {
92
        return jolokia.exec('api/applications/' + app.id + '/jolokia/', bean.id, opname, args);
93 94
    };
};