1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(storidge): introduce endpoint extensions and proxy Storidge API (#1661)

This commit is contained in:
Anthony Lapenna 2018-02-23 03:10:26 +01:00 committed by GitHub
parent b5e256c967
commit eb43579378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 571 additions and 372 deletions

View file

@ -1,52 +0,0 @@
angular.module('extension.storidge')
.factory('StoridgeCluster', ['$http', 'StoridgeManager', function StoridgeClusterFactory($http, StoridgeManager) {
'use strict';
var service = {};
service.queryEvents = function() {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/events',
skipAuthorization: true,
timeout: 4500,
ignoreLoadingBar: true
});
};
service.queryVersion = function() {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/version',
skipAuthorization: true
});
};
service.queryInfo = function() {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/info',
skipAuthorization: true,
timeout: 4500,
ignoreLoadingBar: true
});
};
service.reboot = function() {
return $http({
method: 'POST',
url: StoridgeManager.StoridgeAPIURL() + '/cluster/reboot',
skipAuthorization: true
});
};
service.shutdown = function() {
return $http({
method: 'POST',
url: StoridgeManager.StoridgeAPIURL() + '/cluster/shutdown',
skipAuthorization: true
});
};
return service;
}]);

View file

@ -1,24 +0,0 @@
angular.module('extension.storidge')
.factory('StoridgeNodes', ['$http', 'StoridgeManager', function StoridgeNodesFactory($http, StoridgeManager) {
'use strict';
var service = {};
service.query = function() {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/nodes',
skipAuthorization: true
});
};
service.inspect = function(id) {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/nodes/' + id,
skipAuthorization: true
});
};
return service;
}]);

View file

@ -1,52 +0,0 @@
angular.module('extension.storidge')
.factory('StoridgeProfiles', ['$http', 'StoridgeManager', function StoridgeProfilesFactory($http, StoridgeManager) {
'use strict';
var service = {};
service.create = function(payload) {
return $http({
method: 'POST',
url: StoridgeManager.StoridgeAPIURL() + '/profiles',
data: payload,
headers: { 'Content-type': 'application/json' },
skipAuthorization: true
});
};
service.update = function(id, payload) {
return $http({
method: 'PUT',
url: StoridgeManager.StoridgeAPIURL() + '/profiles/' + id,
data: payload,
headers: { 'Content-type': 'application/json' },
skipAuthorization: true
});
};
service.query = function() {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/profiles',
skipAuthorization: true
});
};
service.inspect = function(id) {
return $http({
method: 'GET',
url: StoridgeManager.StoridgeAPIURL() + '/profiles/' + id,
skipAuthorization: true
});
};
service.delete = function(id) {
return $http({
method: 'DELETE',
url: StoridgeManager.StoridgeAPIURL() + '/profiles/' + id,
skipAuthorization: true
});
};
return service;
}]);

View file

@ -0,0 +1,20 @@
angular.module('extension.storidge')
.factory('Storidge', ['$resource', 'API_ENDPOINT_ENDPOINTS', 'EndpointProvider', function StoridgeFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
'use strict';
return $resource(API_ENDPOINT_ENDPOINTS + '/:endpointId/extensions/storidge/:resource/:id/:action', {
endpointId: EndpointProvider.endpointID
},
{
rebootCluster: { method: 'POST', params: { resource: 'cluster', action: 'reboot' } },
shutdownCluster: { method: 'POST', params: { resource: 'cluster', action: 'shutdown' } },
queryEvents: { method: 'GET', params: { resource: 'events' }, timeout: 4500, ignoreLoadingBar: true, isArray: true },
getVersion: { method: 'GET', params: { resource: 'version' } },
getInfo: { method: 'GET', params: { resource: 'info' }, timeout: 4500, ignoreLoadingBar: true },
queryNodes: { method: 'GET', params: { resource: 'nodes' } },
queryProfiles: { method: 'GET', params: { resource: 'profiles' } },
getProfile: { method: 'GET', params: { resource: 'profiles' } },
createProfile: { method: 'POST', params: { resource: 'profiles' } },
updateProfile: { method: 'PUT', params: { resource: 'profiles', id: '@name' } },
deleteProfile: { method: 'DELETE', params: { resource: 'profiles' } }
});
}]);

View file

@ -1,22 +1,22 @@
angular.module('extension.storidge')
.factory('StoridgeClusterService', ['$q', 'StoridgeCluster', function StoridgeClusterServiceFactory($q, StoridgeCluster) {
.factory('StoridgeClusterService', ['$q', 'Storidge', function StoridgeClusterServiceFactory($q, Storidge) {
'use strict';
var service = {};
service.reboot = function() {
return StoridgeCluster.reboot();
return Storidge.rebootCluster().$promise;
};
service.shutdown = function() {
return StoridgeCluster.shutdown();
return Storidge.shutdownCluster().$promise;
};
service.info = function() {
var deferred = $q.defer();
StoridgeCluster.queryInfo()
.then(function success(response) {
var info = new StoridgeInfoModel(response.data);
Storidge.getInfo().$promise
.then(function success(data) {
var info = new StoridgeInfoModel(data);
deferred.resolve(info);
})
.catch(function error(err) {
@ -29,9 +29,9 @@ angular.module('extension.storidge')
service.version = function() {
var deferred = $q.defer();
StoridgeCluster.queryVersion()
.then(function success(response) {
var version = response.data.version;
Storidge.getVersion().$promise
.then(function success(data) {
var version = data.version;
deferred.resolve(version);
})
.catch(function error(err) {
@ -44,9 +44,9 @@ angular.module('extension.storidge')
service.events = function() {
var deferred = $q.defer();
StoridgeCluster.queryEvents()
.then(function success(response) {
var events = response.data.map(function(item) {
Storidge.queryEvents().$promise
.then(function success(data) {
var events = data.map(function(item) {
return new StoridgeEventModel(item);
});
deferred.resolve(events);

View file

@ -1,48 +0,0 @@
angular.module('extension.storidge')
.factory('StoridgeManager', ['$q', 'LocalStorage', 'SystemService', function StoridgeManagerFactory($q, LocalStorage, SystemService) {
'use strict';
var service = {
API: ''
};
service.init = function() {
var deferred = $q.defer();
var storedAPIURL = LocalStorage.getStoridgeAPIURL();
if (storedAPIURL) {
service.API = storedAPIURL;
deferred.resolve();
} else {
SystemService.info()
.then(function success(data) {
var endpointAddress = LocalStorage.getEndpointPublicURL();
var storidgeAPIURL = '';
if (endpointAddress) {
storidgeAPIURL = 'http://' + endpointAddress + ':8282';
} else {
var managerIP = data.Swarm.NodeAddr;
storidgeAPIURL = 'http://' + managerIP + ':8282';
}
service.API = storidgeAPIURL;
LocalStorage.storeStoridgeAPIURL(storidgeAPIURL);
deferred.resolve();
})
.catch(function error(err) {
deferred.reject({ msg: 'Unable to retrieve Storidge API URL', err: err });
});
}
return deferred.promise;
};
service.reset = function() {
LocalStorage.clearStoridgeAPIURL();
};
service.StoridgeAPIURL = function() {
return service.API;
};
return service;
}]);

View file

@ -1,14 +1,14 @@
angular.module('extension.storidge')
.factory('StoridgeNodeService', ['$q', 'StoridgeNodes', function StoridgeNodeServiceFactory($q, StoridgeNodes) {
.factory('StoridgeNodeService', ['$q', 'Storidge', function StoridgeNodeServiceFactory($q, Storidge) {
'use strict';
var service = {};
service.nodes = function() {
var deferred = $q.defer();
StoridgeNodes.query()
.then(function success(response) {
var nodeData = response.data.nodes;
Storidge.queryNodes().$promise
.then(function success(data) {
var nodeData = data.nodes;
var nodes = [];
for (var key in nodeData) {

View file

@ -1,28 +1,28 @@
angular.module('extension.storidge')
.factory('StoridgeProfileService', ['$q', 'StoridgeProfiles', function StoridgeProfileServiceFactory($q, StoridgeProfiles) {
.factory('StoridgeProfileService', ['$q', 'Storidge', function StoridgeProfileServiceFactory($q, Storidge) {
'use strict';
var service = {};
service.create = function(model) {
var payload = new StoridgeCreateProfileRequest(model);
return StoridgeProfiles.create(payload);
return Storidge.createProfile(payload).$promise;
};
service.update = function(model) {
var payload = new StoridgeCreateProfileRequest(model);
return StoridgeProfiles.update(model.Name, payload);
return Storidge.updateProfile(payload).$promise;
};
service.delete = function(profileName) {
return StoridgeProfiles.delete(profileName);
return Storidge.deleteProfile({ id: profileName }).$promise;
};
service.profile = function(profileName) {
var deferred = $q.defer();
StoridgeProfiles.inspect(profileName)
.then(function success(response) {
var profile = new StoridgeProfileModel(profileName, response.data);
Storidge.getProfile({ id: profileName }).$promise
.then(function success(data) {
var profile = new StoridgeProfileModel(profileName, data);
deferred.resolve(profile);
})
.catch(function error(err) {
@ -35,9 +35,9 @@ angular.module('extension.storidge')
service.profiles = function() {
var deferred = $q.defer();
StoridgeProfiles.query()
.then(function success(response) {
var profiles = response.data.profiles.map(function (item) {
Storidge.queryProfiles().$promise
.then(function success(data) {
var profiles = data.profiles.map(function (item) {
return new StoridgeProfileListModel(item);
});
deferred.resolve(profiles);

View file

@ -1,6 +1,6 @@
angular.module('extension.storidge')
.controller('StoridgeClusterController', ['$q', '$scope', '$state', 'Notifications', 'StoridgeClusterService', 'StoridgeNodeService', 'StoridgeManager', 'ModalService',
function ($q, $scope, $state, Notifications, StoridgeClusterService, StoridgeNodeService, StoridgeManager, ModalService) {
.controller('StoridgeClusterController', ['$q', '$scope', '$state', 'Notifications', 'StoridgeClusterService', 'StoridgeNodeService', 'ModalService',
function ($q, $scope, $state, Notifications, StoridgeClusterService, StoridgeNodeService, ModalService) {
$scope.state = {
shutdownInProgress: false,
@ -44,30 +44,20 @@ function ($q, $scope, $state, Notifications, StoridgeClusterService, StoridgeNod
function shutdownCluster() {
$scope.state.shutdownInProgress = true;
StoridgeClusterService.shutdown()
.then(function success(data) {
Notifications.success('Cluster successfully shutdown');
$state.go('docker.dashboard');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to shutdown cluster');
})
.finally(function final() {
$scope.state.shutdownInProgress = false;
Notifications.success('Cluster successfully shutdown');
$state.go('docker.dashboard');
});
}
function rebootCluster() {
$scope.state.rebootInProgress = true;
StoridgeClusterService.reboot()
.then(function success(data) {
Notifications.success('Cluster successfully rebooted');
$state.reload();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to reboot cluster');
})
.finally(function final() {
$scope.state.rebootInProgress = false;
Notifications.success('Cluster successfully rebooted');
$state.reload();
});
}
@ -87,11 +77,5 @@ function ($q, $scope, $state, Notifications, StoridgeClusterService, StoridgeNod
});
}
StoridgeManager.init()
.then(function success() {
initView();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to communicate with Storidge API');
});
initView();
}]);

View file

@ -1,6 +1,6 @@
angular.module('extension.storidge')
.controller('StoridgeMonitorController', ['$q', '$scope', '$interval', '$document', 'Notifications', 'StoridgeClusterService', 'StoridgeChartService', 'StoridgeManager', 'ModalService',
function ($q, $scope, $interval, $document, Notifications, StoridgeClusterService, StoridgeChartService, StoridgeManager, ModalService) {
.controller('StoridgeMonitorController', ['$q', '$scope', '$interval', '$document', 'Notifications', 'StoridgeClusterService', 'StoridgeChartService', 'ModalService',
function ($q, $scope, $interval, $document, Notifications, StoridgeClusterService, StoridgeChartService, ModalService) {
$scope.$on('$destroy', function() {
stopRepeater();
@ -98,11 +98,5 @@ function ($q, $scope, $interval, $document, Notifications, StoridgeClusterServic
});
}
StoridgeManager.init()
.then(function success() {
initView();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to communicate with Storidge API');
});
initView();
}]);

View file

@ -1,6 +1,6 @@
angular.module('extension.storidge')
.controller('StoridgeCreateProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService', 'StoridgeManager',
function ($scope, $state, $transition$, Notifications, StoridgeProfileService, StoridgeManager) {
.controller('StoridgeCreateProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService',
function ($scope, $state, $transition$, Notifications, StoridgeProfileService) {
$scope.state = {
NoLimit: true,
@ -62,11 +62,5 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService, S
$scope.model = profile;
}
StoridgeManager.init()
.then(function success() {
initView();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to communicate with Storidge API');
});
initView();
}]);

View file

@ -1,6 +1,6 @@
angular.module('extension.storidge')
.controller('StoridgeProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService', 'StoridgeManager', 'ModalService',
function ($scope, $state, $transition$, Notifications, StoridgeProfileService, StoridgeManager, ModalService) {
.controller('StoridgeProfileController', ['$scope', '$state', '$transition$', 'Notifications', 'StoridgeProfileService', 'ModalService',
function ($scope, $state, $transition$, Notifications, StoridgeProfileService, ModalService) {
$scope.state = {
NoLimit: false,
@ -88,11 +88,6 @@ function ($scope, $state, $transition$, Notifications, StoridgeProfileService, S
});
}
StoridgeManager.init()
.then(function success() {
initView();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to communicate with Storidge API');
});
initView();
}]);

View file

@ -1,6 +1,6 @@
angular.module('extension.storidge')
.controller('StoridgeProfilesController', ['$q', '$scope', '$state', 'Notifications', 'StoridgeProfileService', 'StoridgeManager',
function ($q, $scope, $state, Notifications, StoridgeProfileService, StoridgeManager) {
.controller('StoridgeProfilesController', ['$q', '$scope', '$state', 'Notifications', 'StoridgeProfileService',
function ($q, $scope, $state, Notifications, StoridgeProfileService) {
$scope.state = {
actionInProgress: false
@ -60,11 +60,5 @@ function ($q, $scope, $state, Notifications, StoridgeProfileService, StoridgeMan
});
}
StoridgeManager.init()
.then(function success() {
initView();
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to communicate with Storidge API');
});
initView();
}]);