parent
0a91a1d9d8
commit
f6cca81178
6 changed files with 31 additions and 22 deletions
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* Helper service for working with the registry's container. Only works in enterprise.
|
||||
*/
|
||||
angular.module('quay').factory('ContainerService', ['ApiService', '$timeout',
|
||||
angular.module('quay').factory('ContainerService', ['ApiService', '$timeout', 'Restangular',
|
||||
|
||||
function(ApiService, $timeout) {
|
||||
function(ApiService, $timeout, Restangular) {
|
||||
var containerService = {};
|
||||
containerService.restartContainer = function(callback) {
|
||||
ApiService.scShutdownContainer(null, null).then(function(resp) {
|
||||
|
@ -11,25 +11,34 @@ function(ApiService, $timeout) {
|
|||
}, ApiService.errorDisplay('Cannot restart container. Please report this to support.'))
|
||||
};
|
||||
|
||||
containerService.scheduleStatusCheck = function(callback) {
|
||||
containerService.scheduleStatusCheck = function(callback, opt_config) {
|
||||
$timeout(function() {
|
||||
containerService.checkStatus(callback);
|
||||
containerService.checkStatus(callback, opt_config);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
containerService.checkStatus = function(callback, force_ssl) {
|
||||
containerService.checkStatus = function(callback, opt_config) {
|
||||
var errorHandler = function(resp) {
|
||||
if (resp.status == 404 || resp.status == 502) {
|
||||
// Container has not yet come back up, so we schedule another check.
|
||||
containerService.scheduleStatusCheck(callback);
|
||||
containerService.scheduleStatusCheck(callback, opt_config);
|
||||
return;
|
||||
}
|
||||
|
||||
return ApiService.errorDisplay('Cannot load status. Please report this to support')(resp);
|
||||
};
|
||||
|
||||
ApiService.scRegistryStatus(null, null)
|
||||
.then(callback, errorHandler, /* background */true, /* force ssl*/force_ssl);
|
||||
// If config is specified, override the API base URL from this point onward.
|
||||
// TODO(jschorr): Find a better way than this. This is safe, since this will only be called
|
||||
// for a restart, but it is still ugly.
|
||||
if (opt_config && opt_config['SERVER_HOSTNAME']) {
|
||||
var scheme = opt_config['PREFERRED_URL_SCHEME'] || 'http';
|
||||
var baseUrl = scheme + '://' + opt_config['SERVER_HOSTNAME'] + '/api/v1/';
|
||||
Restangular.setBaseUrl(baseUrl);
|
||||
}
|
||||
|
||||
ApiService.scRegistryStatus(null, null, /* background */true)
|
||||
.then(callback, errorHandler);
|
||||
};
|
||||
|
||||
return containerService;
|
||||
|
|
Reference in a new issue