Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.

Commit 01fbf73

Browse files
committed
Reduce fetching of /info and /configprops
/info and /configprops are from now on only fetched in the overview on first render and whenever the status of an application changes. closes #95
1 parent f6f9552 commit 01fbf73

3 files changed

Lines changed: 62 additions & 67 deletions

File tree

spring-boot-admin-server-ui/app/js/controller/appsCtrl.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717

1818
module.exports = function ($scope, application) {
1919
$scope.application = application;
20+
if (!application.capablities) {
21+
application.getCapabilities();
22+
}
2023
};

spring-boot-admin-server-ui/app/js/controller/overviewCtrl.js

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,47 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
2626
Notification.notify(title, options);
2727
};
2828

29-
$scope.loadData = function () {
30-
Application.query(function (applications) {
31-
function refresh(app) {
32-
app.refreshing = true;
33-
app.info = {};
34-
35-
//find application in known applications and copy state --> less flickering
36-
for (var j = 0; $scope.applications && j < $scope.applications.length; j++) {
37-
if (app.id === $scope.applications[j].id) {
38-
app.infoShort = $scope.applications[j].infoShort;
39-
app.infoDetails = $scope.applications[j].infoDetails;
40-
app.version = $scope.applications[j].version;
41-
//issue notifiaction on state change
42-
if (app.statusInfo.status !== $scope.applications[j].statusInfo.status) {
43-
createNote(app);
44-
}
45-
break;
46-
}
29+
var refresh = function(app) {
30+
app.info = {};
31+
app.needRefresh = true;
32+
//find application in known applications and copy state --> less flickering
33+
for (var j = 0; $scope.applications && j < $scope.applications.length; j++) {
34+
if (app.id === $scope.applications[j].id) {
35+
app.infoShort = $scope.applications[j].infoShort;
36+
app.infoDetails = $scope.applications[j].infoDetails;
37+
app.version = $scope.applications[j].version;
38+
app.capabilities = $scope.applications[j].capabilities;
39+
if (app.statusInfo.status !== $scope.applications[j].statusInfo.status) {
40+
createNote(app); //issue notifiaction on state change
41+
} else {
42+
app.needRefresh = false; //if state hasn't change don't fetch info
4743
}
48-
app.getInfo().then(function(info) {
49-
app.version = info.version;
50-
app.infoDetails = null;
51-
app.infoShort = '';
52-
delete info.version;
53-
var infoYml = $filter('yaml')(info);
54-
if (infoYml !== '{}\n') {
55-
app.infoShort = $filter('limitLines')(infoYml, 3);
56-
if (app.infoShort !== infoYml) {
57-
app.infoDetails = $filter('limitLines')(infoYml, 32000, 3);
58-
}
59-
}
60-
}).finally(function(){
61-
app.refreshing = false;
62-
});
44+
break;
6345
}
46+
}
47+
if (app.needRefresh) {
48+
app.refreshing = true;
49+
app.getCapabilities();
50+
app.getInfo().then(function(info) {
51+
app.version = info.version;
52+
app.infoDetails = null;
53+
app.infoShort = '';
54+
delete info.version;
55+
var infoYml = $filter('yaml')(info);
56+
if (infoYml !== '{}\n') {
57+
app.infoShort = $filter('limitLines')(infoYml, 3);
58+
if (app.infoShort !== infoYml) {
59+
app.infoDetails = $filter('limitLines')(infoYml, 32000, 3);
60+
}
61+
}
62+
}).finally(function(){
63+
app.refreshing = false;
64+
});
65+
}
66+
};
6467

68+
$scope.loadData = function () {
69+
Application.query(function (applications) {
6570
for (var i = 0; i < applications.length; i++) {
6671
refresh(applications[i]);
6772
}
@@ -103,8 +108,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
103108
//initial load
104109
$scope.loadData();
105110

106-
// reload site every 30 seconds
107-
$interval(function () {
111+
// reload site every 10 seconds
112+
var intervalPromise = $interval(function () {
108113
$scope.loadData();
109114
}, 10000);
115+
116+
$scope.$on('$destroy', function () { $interval.cancel(intervalPromise); });
110117
};

spring-boot-admin-server-ui/app/js/service/application.js

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616
'use strict';
17-
var angular = require('angular');
1817

1918
module.exports = function ($resource, $http, $q) {
2019

@@ -26,43 +25,14 @@ module.exports = function ($resource, $http, $q) {
2625
}
2726
};
2827

29-
var getCapabilities = function(application) {
30-
application.capabilities = {};
31-
if (application.managementUrl) {
32-
$http.get('api/applications/' + application.id + '/configprops').success(function(configprops) {
33-
application.capabilities.logfile = isEndpointPresent('logfileMvcEndpoint', configprops);
34-
application.capabilities.activiti = isEndpointPresent('processEngineEndpoint', configprops);
35-
application.capabilities.restart = isEndpointPresent('restartEndpoint', configprops);
36-
application.capabilities.refresh = isEndpointPresent('refreshEndpoint', configprops);
37-
application.capabilities.pause = isEndpointPresent('pauseEndpoint', configprops);
38-
application.capabilities.resume = isEndpointPresent('resumeEndpoint', configprops);
39-
});
40-
}
41-
};
4228

4329
var Application = $resource(
4430
'api/applications/:id', { id: '@id' }, {
45-
query: { method: 'GET',
46-
isArray: true,
47-
transformResponse: function(data) {
48-
var apps = angular.fromJson(data);
49-
for (var i = 0; i < apps.length; i++) {
50-
getCapabilities(apps[i]);
51-
}
52-
return apps;
53-
}
54-
},
55-
get: { method: 'GET',
56-
transformResponse: function(data) {
57-
var app = angular.fromJson(data);
58-
getCapabilities(app);
59-
return app;
60-
}
61-
},
31+
query: { method: 'GET', isArray: true },
32+
get: { method: 'GET' },
6233
remove: { method: 'DELETE' }
6334
});
6435

65-
6636
var convert = function (request, isArray) {
6737
isArray = isArray || false;
6838
var deferred = $q.defer();
@@ -79,6 +49,21 @@ module.exports = function ($resource, $http, $q) {
7949
return deferred.promise;
8050
};
8151

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

0 commit comments

Comments
 (0)