Finalize rename addon -> service

This commit is contained in:
Johannes Zellner
2018-12-10 11:35:53 +01:00
parent 97120a6b04
commit 3d6413ae05
2 changed files with 69 additions and 64 deletions

View File

@@ -7,23 +7,30 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
$scope.config = Client.getConfig();
$scope.ready = false;
$scope.addons = {};
$scope.services = [];
$scope.isRebootRequired = false;
function refresh(addonName, callback) {
function refresh(serviceName, callback) {
callback = callback || function () {};
Client.getService(addonName, function (error, result) {
Client.getService(serviceName, function (error, result) {
if (error) Client.error(error);
else $scope.addons[addonName] = result;
callback();
var service = $scope.services.find(function (s) { return s.name === serviceName; });
if (!service) $scope.services.push(result);
service.status = result.status;
service.config = result.config;
service.memoryUsed = result.memoryUsed;
service.memoryPercent = result.memoryPercent;
callback(null, service);
});
}
function refreshAll() {
Object.keys($scope.addons).forEach(function (a) {
refresh(a);
$scope.services.forEach(function (s) {
refresh(s.name);
});
}
@@ -48,79 +55,79 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
}
};
$scope.restartAddon = function (addonName) {
function waitForActive(addonName) {
refresh(addonName, function () {
if ($scope.addons[addonName].status === 'active') return;
$scope.restartService = function (serviceName) {
function waitForActive(serviceName) {
refresh(serviceName, function (error, result) {
if (result.status === 'active') return;
setTimeout(function () { waitForActive(addonName); }, 1000);
setTimeout(function () { waitForActive(serviceName); }, 1000);
});
}
Client.restartService(addonName, function (error) {
Client.restartService(serviceName, function (error) {
if (error) return Client.error(error);
waitForActive(addonName);
waitForActive(serviceName);
});
};
$scope.addonConfigure = {
$scope.serviceConfigure = {
error: null,
busy: false,
addon: null,
service: null,
// form model
memoryLimit: 0,
memoryTicks: [],
show: function (addon) {
$scope.addonConfigure.reset();
show: function (service) {
$scope.serviceConfigure.reset();
$scope.addonConfigure.addon = addon;
$scope.addonConfigure.memoryLimit = addon.config.memory;
$scope.serviceConfigure.service = service;
$scope.serviceConfigure.memoryLimit = service.config.memory;
// TODO improve those
$scope.addonConfigure.memoryTicks = [];
$scope.serviceConfigure.memoryTicks = [];
// create ticks starting from manifest memory limit. the memory limit here is currently split into ram+swap (and thus *2 below)
// TODO: the *2 will overallocate since 4GB is max swap that cloudron itself allocates
$scope.addonConfigure.memoryTicks = [];
$scope.serviceConfigure.memoryTicks = [];
var npow2 = Math.pow(2, Math.ceil(Math.log($scope.config.memory)/Math.log(2)));
for (var i = 256; i <= (npow2*2/1024/1024); i *= 2) {
$scope.addonConfigure.memoryTicks.push(i * 1024 * 1024);
$scope.serviceConfigure.memoryTicks.push(i * 1024 * 1024);
}
$('#addonConfigureModal').modal('show');
$('#serviceConfigureModal').modal('show');
},
submit: function (memoryLimit) {
$scope.addonConfigure.busy = true;
$scope.addonConfigure.error = null;
$scope.serviceConfigure.busy = true;
$scope.serviceConfigure.error = null;
Client.configureService($scope.addonConfigure.addon.name, memoryLimit, function (error) {
$scope.addonConfigure.busy = false;
Client.configureService($scope.serviceConfigure.service.name, memoryLimit, function (error) {
$scope.serviceConfigure.busy = false;
if (error) {
$scope.addonConfigure.error = error.message;
$scope.serviceConfigure.error = error.message;
return;
}
refresh($scope.addonConfigure.addon.name);
refresh($scope.serviceConfigure.service.name);
$('#addonConfigureModal').modal('hide');
$scope.addonConfigure.reset();
$('#serviceConfigureModal').modal('hide');
$scope.serviceConfigure.reset();
});
},
reset: function () {
$scope.addonConfigure.busy = false;
$scope.addonConfigure.error = null;
$scope.addonConfigure.addon = null;
$scope.serviceConfigure.busy = false;
$scope.serviceConfigure.error = null;
$scope.serviceConfigure.service = null;
$scope.addonConfigure.memoryLimit = 0;
$scope.addonConfigure.memoryTicks = [];
$scope.serviceConfigure.memoryLimit = 0;
$scope.serviceConfigure.memoryTicks = [];
$scope.addonConfigureForm.$setPristine();
$scope.addonConfigureForm.$setUntouched();
$scope.serviceConfigureForm.$setPristine();
$scope.serviceConfigureForm.$setUntouched();
}
};
@@ -133,9 +140,7 @@ angular.module('Application').controller('SystemController', ['$scope', '$locati
Client.getServices(function (error, result) {
if (error) return Client.error(error);
result.forEach(function (a) {
$scope.addons[a] = { name: a };
});
$scope.services = result.map(function (serviceName) { return { name: serviceName }; });
// just kick off the status fetching
refreshAll();