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

18
module.exports = function ($resource, $http, $q) {
19

20
    var isEndpointPresent = function(endpoint, configprops) {
21
        if (configprops[endpoint]) {
22 23 24
           return true;
        } else {
           return false;
25 26 27
        }
    };

28

29 30
    var Application = $resource(
        'api/applications/:id', { id: '@id' }, {
31 32
            query: { method: 'GET', isArray: true },
            get: { method: 'GET' },
33 34 35
            remove: { method: 'DELETE' }
    });

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    var convert = function (request, isArray) {
        isArray = isArray || false;
        var deferred = $q.defer();
        request.success(function(response) {
            var result = response;
            delete result['_links'];
            if (isArray) {
                result = response.content || response;
            }
            deferred.resolve(result);
        }).error(function(response) {
            deferred.reject(response);
        });
        return deferred.promise;
    };

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    Application.prototype.getCapabilities = function() {
        var application = this;
        this.capabilities = {};
        if (this.managementUrl) {
            $http.get('api/applications/' + application.id + '/configprops').success(function(configprops) {
                application.capabilities.logfile = isEndpointPresent('logfileMvcEndpoint', configprops);
                application.capabilities.activiti = isEndpointPresent('processEngineEndpoint', configprops);
                application.capabilities.restart = isEndpointPresent('restartEndpoint', configprops);
                application.capabilities.refresh = isEndpointPresent('refreshEndpoint', configprops);
                application.capabilities.pause = isEndpointPresent('pauseEndpoint', configprops);
                application.capabilities.resume = isEndpointPresent('resumeEndpoint', configprops);
            });
        }
    };

67
    Application.prototype.getHealth = function () {
68
        return convert($http.get('api/applications/' + this.id + '/health'));
69 70 71
    };

    Application.prototype.getInfo = function () {
72
        return convert($http.get('api/applications/' + this.id + '/info'));
73 74 75
    };

    Application.prototype.getMetrics = function () {
76
        return convert($http.get('api/applications/' + this.id + '/metrics'));
77 78
    };

79
    Application.prototype.getEnv = function (key) {
80
        return convert($http.get('api/applications/' + this.id + '/env' + (key ? '/' + key : '' )));
81 82 83
    };

    Application.prototype.setEnv = function (map) {
84
        return convert($http.post('api/applications/' + this.id + '/env', '', {params: map}));
85 86 87
    };

    Application.prototype.resetEnv = function () {
88
        return convert($http.post('api/applications/' + this.id + '/env/reset'));
89 90
    };

91
    Application.prototype.refresh = function () {
92
        return convert($http.post('api/applications/' + this.id + '/refresh'));
93 94
    };

95
    Application.prototype.getThreadDump = function () {
96
        return convert($http.get('api/applications/' + this.id + '/dump'), true);
97 98 99
    };

    Application.prototype.getTraces = function () {
100
        return convert($http.get('api/applications/' + this.id + '/trace'), true);
101 102
    };

103
    Application.prototype.getActiviti = function () {
104
        return convert($http.get('api/applications/' + this.id + '/activiti'));
105 106 107
    };

    return Application;
108
};