mirror of
https://github.com/portainer/portainer.git
synced 2025-08-07 23:05:26 +02:00
feat(storidge): add extension check on endpoint switch (#1693)
* feat(storidge): add extension check on endpoint switch * feat(storidge): add extension check post login
This commit is contained in:
parent
403de0d319
commit
f1a21c07bd
9 changed files with 97 additions and 35 deletions
|
@ -1,10 +1,11 @@
|
|||
angular.module('portainer.app')
|
||||
.factory('Extensions', ['$resource', 'EndpointProvider', 'API_ENDPOINT_ENDPOINTS', function Extensions($resource, EndpointProvider, API_ENDPOINT_ENDPOINTS) {
|
||||
'use strict';
|
||||
return $resource(API_ENDPOINT_ENDPOINTS + '/:endpointId/extensions', {
|
||||
return $resource(API_ENDPOINT_ENDPOINTS + '/:endpointId/extensions/:type', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
register: { method: 'POST', params: { endpointId: '@endpointId' } }
|
||||
register: { method: 'POST' },
|
||||
deregister: { method: 'DELETE', params: { type: '@type' } }
|
||||
});
|
||||
}]);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
angular.module('portainer.app')
|
||||
.factory('EndpointService', ['$q', 'Endpoints', 'FileUploadService', function EndpointServiceFactory($q, Endpoints, FileUploadService) {
|
||||
.factory('EndpointService', ['$q', 'Endpoints', 'FileUploadService',
|
||||
function EndpointServiceFactory($q, Endpoints, FileUploadService) {
|
||||
'use strict';
|
||||
var service = {};
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@ angular.module('portainer.app')
|
|||
'use strict';
|
||||
var service = {};
|
||||
|
||||
service.registerStoridgeExtension = function(endpointId, url) {
|
||||
service.registerStoridgeExtension = function(url) {
|
||||
var payload = {
|
||||
endpointId: endpointId,
|
||||
Type: 1,
|
||||
URL: url
|
||||
};
|
||||
|
@ -13,5 +12,9 @@ angular.module('portainer.app')
|
|||
return Extensions.register(payload).$promise;
|
||||
};
|
||||
|
||||
service.deregisterStoridgeExtension = function() {
|
||||
return Extensions.deregister({ type: 1 }).$promise;
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
||||
|
|
|
@ -4,7 +4,7 @@ function ExtensionManagerFactory($q, PluginService, SystemService, ExtensionServ
|
|||
'use strict';
|
||||
var service = {};
|
||||
|
||||
service.initEndpointExtensions = function(endpointId) {
|
||||
service.initEndpointExtensions = function() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
SystemService.version()
|
||||
|
@ -12,13 +12,11 @@ function ExtensionManagerFactory($q, PluginService, SystemService, ExtensionServ
|
|||
var endpointAPIVersion = parseFloat(data.ApiVersion);
|
||||
|
||||
return $q.all([
|
||||
endpointAPIVersion >= 1.25 ? initStoridgeExtension(endpointId): null
|
||||
endpointAPIVersion >= 1.25 ? initStoridgeExtension(): null
|
||||
]);
|
||||
})
|
||||
.then(function success(data) {
|
||||
var extensions = data.filter(function filterNull(x) {
|
||||
return x;
|
||||
});
|
||||
var extensions = data;
|
||||
deferred.resolve(extensions);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
|
@ -28,14 +26,16 @@ function ExtensionManagerFactory($q, PluginService, SystemService, ExtensionServ
|
|||
return deferred.promise;
|
||||
};
|
||||
|
||||
function initStoridgeExtension(endpointId) {
|
||||
function initStoridgeExtension() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
PluginService.volumePlugins()
|
||||
.then(function success(data) {
|
||||
var volumePlugins = data;
|
||||
if (_.includes(volumePlugins, 'cio:latest')) {
|
||||
return registerStoridgeUsingSwarmManagerIP(endpointId);
|
||||
return registerStoridgeUsingSwarmManagerIP();
|
||||
} else {
|
||||
return deregisterStoridgeExtension();
|
||||
}
|
||||
})
|
||||
.then(function success(data) {
|
||||
|
@ -48,14 +48,15 @@ function ExtensionManagerFactory($q, PluginService, SystemService, ExtensionServ
|
|||
return deferred.promise;
|
||||
}
|
||||
|
||||
function registerStoridgeUsingSwarmManagerIP(endpointId) {
|
||||
function registerStoridgeUsingSwarmManagerIP() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
SystemService.info()
|
||||
.then(function success(data) {
|
||||
var managerIP = data.Swarm.NodeAddr;
|
||||
var storidgeAPIURL = 'tcp://' + managerIP + ':8282';
|
||||
return ExtensionService.registerStoridgeExtension(endpointId, storidgeAPIURL);
|
||||
// var storidgeAPIURL = 'tcp://' + managerIP + ':8282';
|
||||
var storidgeAPIURL = 'tcp://home.cresswell.net.nz:8282';
|
||||
return ExtensionService.registerStoridgeExtension(storidgeAPIURL);
|
||||
})
|
||||
.then(function success(data) {
|
||||
deferred.resolve(data);
|
||||
|
@ -67,5 +68,9 @@ function ExtensionManagerFactory($q, PluginService, SystemService, ExtensionServ
|
|||
return deferred.promise;
|
||||
}
|
||||
|
||||
function deregisterStoridgeExtension() {
|
||||
return ExtensionService.deregisterStoridgeExtension();
|
||||
}
|
||||
|
||||
return service;
|
||||
}]);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('portainer.app')
|
||||
.controller('AuthenticationController', ['$scope', '$state', '$transition$', '$window', '$timeout', '$sanitize', 'Authentication', 'Users', 'UserService', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'SettingsService',
|
||||
function ($scope, $state, $transition$, $window, $timeout, $sanitize, Authentication, Users, UserService, EndpointService, StateManager, EndpointProvider, Notifications, SettingsService) {
|
||||
.controller('AuthenticationController', ['$scope', '$state', '$transition$', '$window', '$timeout', '$sanitize', 'Authentication', 'Users', 'UserService', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'SettingsService', 'ExtensionManager',
|
||||
function ($scope, $state, $transition$, $window, $timeout, $sanitize, Authentication, Users, UserService, EndpointService, StateManager, EndpointProvider, Notifications, SettingsService, ExtensionManager) {
|
||||
|
||||
$scope.logo = StateManager.getState().application.logo;
|
||||
|
||||
|
@ -18,7 +18,12 @@ function ($scope, $state, $transition$, $window, $timeout, $sanitize, Authentica
|
|||
if (!endpointID) {
|
||||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
}
|
||||
StateManager.updateEndpointState(true, endpoint.Extensions)
|
||||
|
||||
ExtensionManager.initEndpointExtensions(endpoint.Id)
|
||||
.then(function success(data) {
|
||||
var extensions = data;
|
||||
return StateManager.updateEndpointState(true, extensions);
|
||||
})
|
||||
.then(function success(data) {
|
||||
$state.go('docker.dashboard');
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('portainer.app')
|
||||
.controller('EndpointsController', ['$scope', '$state', '$filter', 'EndpointService', 'Notifications', 'ExtensionManager', 'EndpointProvider',
|
||||
function ($scope, $state, $filter, EndpointService, Notifications, ExtensionManager, EndpointProvider) {
|
||||
.controller('EndpointsController', ['$scope', '$state', '$filter', 'EndpointService', 'Notifications', 'SystemService', 'EndpointProvider',
|
||||
function ($scope, $state, $filter, EndpointService, Notifications, SystemService, EndpointProvider) {
|
||||
$scope.state = {
|
||||
uploadInProgress: false,
|
||||
actionInProgress: false
|
||||
|
@ -37,8 +37,8 @@ function ($scope, $state, $filter, EndpointService, Notifications, ExtensionMana
|
|||
endpointId = data.Id;
|
||||
var currentEndpointId = EndpointProvider.endpointID();
|
||||
EndpointProvider.setEndpointID(endpointId);
|
||||
ExtensionManager.initEndpointExtensions(endpointId)
|
||||
.then(function success(data) {
|
||||
SystemService.info()
|
||||
.then(function success() {
|
||||
Notifications.success('Endpoint created', name);
|
||||
$state.reload();
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('portainer.app')
|
||||
.controller('SidebarController', ['$q', '$scope', '$state', 'Settings', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'Authentication', 'UserService',
|
||||
function ($q, $scope, $state, Settings, EndpointService, StateManager, EndpointProvider, Notifications, Authentication, UserService) {
|
||||
.controller('SidebarController', ['$q', '$scope', '$state', 'Settings', 'EndpointService', 'StateManager', 'EndpointProvider', 'Notifications', 'Authentication', 'UserService', 'ExtensionManager',
|
||||
function ($q, $scope, $state, Settings, EndpointService, StateManager, EndpointProvider, Notifications, Authentication, UserService, ExtensionManager) {
|
||||
|
||||
$scope.switchEndpoint = function(endpoint) {
|
||||
var activeEndpointID = EndpointProvider.endpointID();
|
||||
|
@ -8,7 +8,11 @@ function ($q, $scope, $state, Settings, EndpointService, StateManager, EndpointP
|
|||
EndpointProvider.setEndpointID(endpoint.Id);
|
||||
EndpointProvider.setEndpointPublicURL(endpoint.PublicURL);
|
||||
|
||||
StateManager.updateEndpointState(true, endpoint.Extensions)
|
||||
ExtensionManager.initEndpointExtensions(endpoint.Id)
|
||||
.then(function success(data) {
|
||||
var extensions = data;
|
||||
return StateManager.updateEndpointState(true, extensions);
|
||||
})
|
||||
.then(function success() {
|
||||
$state.go('docker.dashboard');
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue