2020-09-28 15:16:02 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* global angular */
|
|
|
|
|
/* global $ */
|
|
|
|
|
|
|
|
|
|
angular.module('Application').controller('ServicesController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
|
|
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
|
|
|
|
|
|
|
|
|
|
$scope.config = Client.getConfig();
|
|
|
|
|
$scope.servicesReady = false;
|
|
|
|
|
$scope.services = [];
|
|
|
|
|
$scope.hasRedisServices = false;
|
|
|
|
|
$scope.redisServicesExpanded = false;
|
|
|
|
|
$scope.memory = null;
|
|
|
|
|
|
|
|
|
|
function refresh(serviceName, callback) {
|
|
|
|
|
callback = callback || function () {};
|
|
|
|
|
|
|
|
|
|
Client.getService(serviceName, function (error, result) {
|
|
|
|
|
if (error) return console.log('Error getting status of ' + serviceName + ':' + error.message);
|
|
|
|
|
|
|
|
|
|
var service = $scope.services.find(function (s) { return s.name === serviceName; });
|
2024-04-10 12:17:14 +02:00
|
|
|
if (!service) callback(new Error('no such service' + serviceName)); // cannot happen
|
2020-09-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
service.status = result.status;
|
|
|
|
|
service.config = result.config;
|
|
|
|
|
service.memoryUsed = result.memoryUsed;
|
|
|
|
|
service.memoryPercent = result.memoryPercent;
|
2024-04-10 12:17:14 +02:00
|
|
|
service.defaultMemoryLimit = result.defaultMemoryLimit;
|
2020-09-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
callback(null, service);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 15:51:44 -07:00
|
|
|
function waitForActive(serviceName) {
|
|
|
|
|
refresh(serviceName, function (error, result) {
|
|
|
|
|
if (result.status === 'active') return;
|
2020-09-28 15:16:02 +02:00
|
|
|
|
2021-10-19 15:51:44 -07:00
|
|
|
setTimeout(function () { waitForActive(serviceName); }, 3000);
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-28 15:16:02 +02:00
|
|
|
|
2021-10-19 15:51:44 -07:00
|
|
|
$scope.restartService = function (serviceName) {
|
2020-09-28 15:16:02 +02:00
|
|
|
$scope.services.find(function (s) { return s.name === serviceName; }).status = 'starting';
|
|
|
|
|
|
|
|
|
|
Client.restartService(serviceName, function (error) {
|
2021-01-21 17:41:16 -08:00
|
|
|
if (error && error.statusCode === 404) {
|
|
|
|
|
Client.rebuildService(serviceName, function (error) {
|
|
|
|
|
if (error) return Client.error(error);
|
|
|
|
|
|
|
|
|
|
// show "busy" indicator for 3 seconds to show some ui activity
|
|
|
|
|
setTimeout(function () { waitForActive(serviceName); }, 3000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-01 22:49:22 +02:00
|
|
|
if (error) {
|
|
|
|
|
refresh(serviceName);
|
|
|
|
|
return Client.error(error);
|
|
|
|
|
}
|
2020-09-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
// show "busy" indicator for 3 seconds to show some ui activity
|
|
|
|
|
setTimeout(function () { waitForActive(serviceName); }, 3000);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.serviceConfigure = {
|
|
|
|
|
error: null,
|
|
|
|
|
busy: false,
|
|
|
|
|
service: null,
|
|
|
|
|
|
|
|
|
|
// form model
|
|
|
|
|
memoryLimit: 0,
|
|
|
|
|
memoryTicks: [],
|
|
|
|
|
|
2021-10-01 13:42:10 -07:00
|
|
|
recoveryMode: false,
|
|
|
|
|
|
2020-09-28 15:16:02 +02:00
|
|
|
show: function (service) {
|
|
|
|
|
$scope.serviceConfigure.reset();
|
|
|
|
|
|
|
|
|
|
$scope.serviceConfigure.service = service;
|
2021-10-01 13:42:10 -07:00
|
|
|
$scope.serviceConfigure.recoveryMode = !!service.config.recoveryMode;
|
2020-09-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
$scope.serviceConfigure.memoryTicks = [];
|
2024-04-10 10:01:11 +02:00
|
|
|
// we max system memory and current service memory for the case where the user configured the service on another server with more resources
|
|
|
|
|
var nearest256m = Math.ceil(Math.max($scope.memory.memory, service.config.memoryLimit) / (256*1024*1024)) * 256 * 1024 * 1024;
|
2024-04-10 12:17:14 +02:00
|
|
|
var startTick = service.defaultMemoryLimit;
|
2020-09-28 15:16:02 +02:00
|
|
|
|
2024-11-30 17:54:44 +01:00
|
|
|
// code below ensure we atleast have 2 ticks to keep the slider usable
|
|
|
|
|
$scope.serviceConfigure.memoryTicks.push(startTick); // start tick
|
|
|
|
|
for (var i = startTick * 2; i < nearest256m; i *= 2) {
|
2024-04-10 12:12:24 +02:00
|
|
|
$scope.serviceConfigure.memoryTicks.push(i);
|
2020-09-28 15:16:02 +02:00
|
|
|
}
|
2024-11-30 17:54:44 +01:00
|
|
|
$scope.serviceConfigure.memoryTicks.push(nearest256m); // end tick
|
2020-09-28 15:16:02 +02:00
|
|
|
|
2024-03-12 15:28:47 +01:00
|
|
|
// for firefox widget update
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.serviceConfigure.memoryLimit = service.config.memoryLimit;
|
|
|
|
|
}, 500);
|
|
|
|
|
|
2020-09-28 15:16:02 +02:00
|
|
|
$('#serviceConfigureModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
2021-10-01 13:42:10 -07:00
|
|
|
submit: function () {
|
2020-09-28 15:16:02 +02:00
|
|
|
$scope.serviceConfigure.busy = true;
|
|
|
|
|
$scope.serviceConfigure.error = null;
|
|
|
|
|
|
2021-10-01 13:42:10 -07:00
|
|
|
var data = {
|
2024-03-12 15:28:47 +01:00
|
|
|
memoryLimit: parseInt($scope.serviceConfigure.memoryLimit),
|
2021-10-01 13:42:10 -07:00
|
|
|
recoveryMode: $scope.serviceConfigure.recoveryMode
|
|
|
|
|
};
|
2020-10-21 22:31:29 -07:00
|
|
|
|
|
|
|
|
Client.configureService($scope.serviceConfigure.service.name, data, function (error) {
|
2020-09-28 15:16:02 +02:00
|
|
|
$scope.serviceConfigure.busy = false;
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.serviceConfigure.error = error.message;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 15:51:44 -07:00
|
|
|
if ($scope.serviceConfigure.recoveryMode === true) {
|
|
|
|
|
refresh($scope.serviceConfigure.service.name);
|
|
|
|
|
} else {
|
|
|
|
|
waitForActive($scope.serviceConfigure.service.name);
|
|
|
|
|
}
|
2020-09-28 15:16:02 +02:00
|
|
|
|
|
|
|
|
$('#serviceConfigureModal').modal('hide');
|
|
|
|
|
$scope.serviceConfigure.reset();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2020-12-04 17:36:38 +01:00
|
|
|
resetToDefaults: function () {
|
2024-04-10 12:17:14 +02:00
|
|
|
$scope.serviceConfigure.memoryLimit = $scope.serviceConfigure.service.defaultMemoryLimit;
|
2020-12-04 17:36:38 +01:00
|
|
|
},
|
|
|
|
|
|
2020-09-28 15:16:02 +02:00
|
|
|
reset: function () {
|
|
|
|
|
$scope.serviceConfigure.busy = false;
|
|
|
|
|
$scope.serviceConfigure.error = null;
|
|
|
|
|
$scope.serviceConfigure.service = null;
|
|
|
|
|
|
|
|
|
|
$scope.serviceConfigure.memoryLimit = 0;
|
|
|
|
|
$scope.serviceConfigure.memoryTicks = [];
|
|
|
|
|
|
|
|
|
|
$scope.serviceConfigureForm.$setPristine();
|
|
|
|
|
$scope.serviceConfigureForm.$setUntouched();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-15 11:38:51 -08:00
|
|
|
$scope.refreshAll = function (callback) {
|
|
|
|
|
Client.getServices(function (error, result) {
|
|
|
|
|
if (error) return Client.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.services = result.map(function (name) {
|
|
|
|
|
var displayName = name;
|
|
|
|
|
var isRedis = false;
|
|
|
|
|
|
|
|
|
|
if (name.indexOf('redis') === 0) {
|
|
|
|
|
isRedis = true;
|
|
|
|
|
var app = Client.getCachedAppSync(name.slice('redis:'.length));
|
|
|
|
|
if (app) {
|
|
|
|
|
displayName = 'Redis (' + (app.label || app.fqdn) + ')';
|
|
|
|
|
} else {
|
|
|
|
|
displayName = 'Redis (unknown app)';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
name: name,
|
|
|
|
|
displayName: displayName,
|
|
|
|
|
isRedis: isRedis
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
$scope.hasRedisServices = !!$scope.services.find(function (service) { return service.isRedis; });
|
|
|
|
|
|
|
|
|
|
// just kick off the status fetching
|
|
|
|
|
$scope.services.forEach(function (s) { refresh(s.name); });
|
|
|
|
|
|
|
|
|
|
if (callback) return callback();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-28 15:16:02 +02:00
|
|
|
Client.onReady(function () {
|
|
|
|
|
Client.memory(function (error, memory) {
|
|
|
|
|
if (error) console.error(error);
|
|
|
|
|
|
|
|
|
|
$scope.memory = memory;
|
|
|
|
|
|
2021-02-15 11:38:51 -08:00
|
|
|
$scope.refreshAll(function () {
|
2020-09-28 15:16:02 +02:00
|
|
|
$scope.servicesReady = true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}]);
|