From 8e1417b4e9c313e9b5ff42eb545c49a8e5e0afad Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Wed, 11 Oct 2023 10:26:44 +0300 Subject: [PATCH] refactor(docker/containers): remove EndpointProvider from container service [EE-6180] (#10392) --- app/docker/rest/container.js | 7 +- app/docker/services/containerService.js | 82 +++++++++---------- app/docker/services/imageService.js | 4 +- .../console/containerConsoleController.js | 12 +-- .../create/createContainerController.js | 12 +-- .../containers/edit/containerController.js | 12 +-- .../inspect/containerInspectController.js | 5 +- .../logs/containerLogsController.js | 17 +++- .../stats/containerStatsController.js | 13 +-- .../views/dashboard/dashboardController.js | 4 +- app/docker/views/host/host-view-controller.js | 5 +- .../node-details-view-controller.js | 7 +- .../nodes/node-details/node-details-view.html | 3 - .../views/services/edit/serviceController.js | 2 +- .../views/services/servicesController.js | 2 +- .../views/volumes/edit/volumeController.js | 5 +- app/portainer/services/api/stackService.js | 6 +- .../stacks/create/createStackController.js | 2 +- .../views/stacks/edit/stackController.js | 6 +- .../views/templates/templatesController.js | 2 +- 20 files changed, 102 insertions(+), 106 deletions(-) diff --git a/app/docker/rest/container.js b/app/docker/rest/container.js index a33ecb3c4..d9f746b00 100644 --- a/app/docker/rest/container.js +++ b/app/docker/rest/container.js @@ -3,14 +3,13 @@ import { genericHandler, logsHandler } from './response/handlers'; angular.module('portainer.docker').factory('Container', [ '$resource', 'API_ENDPOINT_ENDPOINTS', - 'EndpointProvider', - function ContainerFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) { + function ContainerFactory($resource, API_ENDPOINT_ENDPOINTS) { 'use strict'; return $resource( - API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/containers/:id/:action', + API_ENDPOINT_ENDPOINTS + '/:environmentId/docker/containers/:id/:action', { name: '@name', - endpointId: EndpointProvider.endpointID, + environmentId: '@environmentId', }, { query: { diff --git a/app/docker/services/containerService.js b/app/docker/services/containerService.js index 0a4592c77..a3382036c 100644 --- a/app/docker/services/containerService.js +++ b/app/docker/services/containerService.js @@ -16,25 +16,25 @@ import { formatLogs } from '../helpers/logHelper'; angular.module('portainer.docker').factory('ContainerService', ContainerServiceFactory); /* @ngInject */ -function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { +function ContainerServiceFactory($q, Container, $timeout) { const service = { - killContainer: withEndpointId(killContainer), - pauseContainer: withEndpointId(pauseContainer), - renameContainer: withEndpointId(renameContainer), - restartContainer: withEndpointId(restartContainer), - resumeContainer: withEndpointId(resumeContainer), - startContainer: withEndpointId(startContainer), - stopContainer: withEndpointId(stopContainer), - recreateContainer: withEndpointId(recreateContainer), - remove: withEndpointId(removeContainer), + killContainer, + pauseContainer, + renameContainer, + restartContainer, + resumeContainer, + startContainer, + stopContainer, + recreateContainer, + remove: removeContainer, updateRestartPolicy, updateLimits, }; - service.container = function (id) { + service.container = function (environmentId, id) { var deferred = $q.defer(); - Container.get({ id: id }) + Container.get({ environmentId, id }) .$promise.then(function success(data) { var container = new ContainerDetailsViewModel(data); deferred.resolve(container); @@ -46,9 +46,9 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.containers = function (all, filters) { + service.containers = function (environmentId, all, filters) { var deferred = $q.defer(); - Container.query({ all: all, filters: filters }) + Container.query({ environmentId, all, filters }) .$promise.then(function success(data) { var containers = data.map(function (item) { return new ContainerViewModel(item); @@ -62,11 +62,11 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.resizeTTY = function (id, width, height, timeout) { + service.resizeTTY = function (environmentId, id, width, height, timeout) { var deferred = $q.defer(); $timeout(function () { - Container.resize({}, { id: id, height: height, width: width }) + Container.resize({}, { environmentId, id, width, height }) .$promise.then(function success(data) { if (data.message) { deferred.reject({ msg: 'Unable to resize tty of container ' + id, err: data.message }); @@ -82,13 +82,13 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - function updateRestartPolicy(id, restartPolicy, maximumRetryCounts) { - return Container.update({ id: id }, { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }).$promise; + function updateRestartPolicy(environmentId, id, restartPolicy, maximumRetryCounts) { + return Container.update({ environmentId, id }, { RestartPolicy: { Name: restartPolicy, MaximumRetryCount: maximumRetryCounts } }).$promise; } - function updateLimits(id, config) { + function updateLimits(environmentId, id, config) { return Container.update( - { id: id }, + { environmentId, id }, { // MemorySwap: must be set // -1: non limits, 0: treated as unset(cause update error). @@ -100,9 +100,9 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { ).$promise; } - service.createContainer = function (configuration) { + service.createContainer = function (environmentId, configuration) { var deferred = $q.defer(); - Container.create(configuration) + Container.create({ environmentId }, configuration) .$promise.then(function success(data) { deferred.resolve(data); }) @@ -112,14 +112,14 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.createAndStartContainer = function (configuration) { + service.createAndStartContainer = function (environmentId, configuration) { var deferred = $q.defer(); var container; service - .createContainer(configuration) + .createContainer(environmentId, configuration) .then(function success(data) { container = data; - return service.startContainer(container.Id); + return service.startContainer(environmentId, container.Id); }) .then(function success() { deferred.resolve(container); @@ -130,10 +130,10 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.createExec = function (execConfig) { + service.createExec = function (environmentId, execConfig) { var deferred = $q.defer(); - Container.exec({}, execConfig) + Container.exec({ environmentId }, execConfig) .$promise.then(function success(data) { if (data.message) { deferred.reject({ msg: data.message, err: data.message }); @@ -148,7 +148,7 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.logs = function (id, stdout, stderr, timestamps, since, tail, stripHeaders) { + service.logs = function (environmentId, id, stdout, stderr, timestamps, since, tail, stripHeaders) { var deferred = $q.defer(); var parameters = { @@ -160,7 +160,7 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { tail: tail || 'all', }; - Container.logs(parameters) + Container.logs(environmentId, parameters) .$promise.then(function success(data) { var logs = formatLogs(data.logs, { stripHeaders, withTimestamps: !!timestamps }); deferred.resolve(logs); @@ -172,10 +172,10 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.containerStats = function (id) { + service.containerStats = function (environmentId, id) { var deferred = $q.defer(); - Container.stats({ id: id }) + Container.stats({ environmentId, id }) .$promise.then(function success(data) { var containerStats = new ContainerStatsViewModel(data); deferred.resolve(containerStats); @@ -187,25 +187,17 @@ function ContainerServiceFactory($q, Container, $timeout, EndpointProvider) { return deferred.promise; }; - service.containerTop = function (id) { - return Container.top({ id: id }).$promise; + service.containerTop = function (environmentId, id) { + return Container.top({ environmentId, id }).$promise; }; - service.inspect = function (id) { - return Container.inspect({ id: id }).$promise; + service.inspect = function (environmentId, id) { + return Container.inspect({ environmentId, id }).$promise; }; - service.prune = function (filters) { - return Container.prune({ filters: filters }).$promise; + service.prune = function (environmentId, filters) { + return Container.prune({ environmentId, filters }).$promise; }; return service; - - function withEndpointId(func) { - return function (...args) { - const endpointId = EndpointProvider.endpointID(); - - return func(endpointId, ...args); - }; - } } diff --git a/app/docker/services/imageService.js b/app/docker/services/imageService.js index fc29d0602..1f37555fa 100644 --- a/app/docker/services/imageService.js +++ b/app/docker/services/imageService.js @@ -33,11 +33,11 @@ angular.module('portainer.docker').factory('ImageService', [ return deferred.promise; }; - service.images = function (withUsage) { + service.images = function ({ environmentId, withUsage } = {}) { var deferred = $q.defer(); $q.all({ - containers: withUsage ? ContainerService.containers(1) : [], + containers: withUsage ? ContainerService.containers(environmentId, 1) : [], images: Image.query({}).$promise, }) .then(function success(data) { diff --git a/app/docker/views/containers/console/containerConsoleController.js b/app/docker/views/containers/console/containerConsoleController.js index bc4bf14d7..553c6e19e 100644 --- a/app/docker/views/containers/console/containerConsoleController.js +++ b/app/docker/views/containers/console/containerConsoleController.js @@ -15,6 +15,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ 'LocalStorage', 'CONSOLE_COMMANDS_LABEL_PREFIX', 'SidebarService', + 'endpoint', function ( $scope, $state, @@ -27,7 +28,8 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ HttpRequestHelper, LocalStorage, CONSOLE_COMMANDS_LABEL_PREFIX, - SidebarService + SidebarService, + endpoint ) { var socket, term; @@ -58,7 +60,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ let attachId = $transition$.params().id; - ContainerService.container(attachId) + ContainerService.container(endpoint.Id, attachId) .then((details) => { if (!details.State.Running) { Notifications.error('Failure', details, 'Container ' + attachId + ' is not running!'); @@ -79,7 +81,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ .map((k) => k + '=' + params[k]) .join('&'); - initTerm(url, ContainerService.resizeTTY.bind(this, attachId)); + initTerm(url, ContainerService.resizeTTY.bind(this, endpoint.Id, attachId)); }) .catch(function error(err) { Notifications.error('Error', err, 'Unable to retrieve container details'); @@ -104,7 +106,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ Cmd: commandStringToArray(command), }; - ContainerService.createExec(execConfig) + ContainerService.createExec(endpoint.Id, execConfig) .then(function success(data) { const params = { endpointId: $state.params.endpointId, @@ -217,7 +219,7 @@ angular.module('portainer.docker').controller('ContainerConsoleController', [ $scope.initView = function () { HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName); - return ContainerService.container($transition$.params().id) + return ContainerService.container(endpoint.Id, $transition$.params().id) .then(function success(data) { var container = data; $scope.container = container; diff --git a/app/docker/views/containers/create/createContainerController.js b/app/docker/views/containers/create/createContainerController.js index 97a0abcab..0c939508a 100644 --- a/app/docker/views/containers/create/createContainerController.js +++ b/app/docker/views/containers/create/createContainerController.js @@ -528,7 +528,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [ function removeNewContainer() { return findCurrentContainer().then(function onContainerLoaded(container) { if (container && (!oldContainer || container.Id !== oldContainer.Id)) { - return ContainerService.remove(container, true); + return ContainerService.remove(endpoint.Id, container, true); } }); } @@ -537,7 +537,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [ if (!oldContainer) { return; } - return ContainerService.renameContainer(oldContainer.Id, oldContainer.Names[0]); + return ContainerService.renameContainer(endpoint.Id, oldContainer.Id, oldContainer.Names[0]); } function confirmCreateContainer(container) { @@ -573,11 +573,11 @@ angular.module('portainer.docker').controller('CreateContainerController', [ if (oldContainer.State !== 'running') { return $q.when(); } - return ContainerService.stopContainer(oldContainer.Id); + return ContainerService.stopContainer(endpoint.Id, oldContainer.Id); } function renameContainer() { - return ContainerService.renameContainer(oldContainer.Id, oldContainer.Names[0] + '-old'); + return ContainerService.renameContainer(endpoint.Id, oldContainer.Id, oldContainer.Names[0] + '-old'); } function pullImageIfNeeded() { @@ -587,7 +587,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [ function createNewContainer() { return $async(async () => { const config = prepareConfiguration(); - return await ContainerService.createAndStartContainer(config); + return await ContainerService.createAndStartContainer(endpoint.Id, config); }); } @@ -639,7 +639,7 @@ angular.module('portainer.docker').controller('CreateContainerController', [ return; } - ContainerService.remove(oldContainer, true).then(notifyOnRemoval).catch(notifyOnRemoveError); + ContainerService.remove(endpoint.Id, oldContainer, true).then(notifyOnRemoval).catch(notifyOnRemoveError); return deferred.promise; diff --git a/app/docker/views/containers/edit/containerController.js b/app/docker/views/containers/edit/containerController.js index 01c200131..e96e48a10 100644 --- a/app/docker/views/containers/edit/containerController.js +++ b/app/docker/views/containers/edit/containerController.js @@ -99,7 +99,7 @@ angular.module('portainer.docker').controller('ContainerController', [ HttpRequestHelper.setPortainerAgentTargetHeader(nodeName); $scope.nodeName = nodeName; - ContainerService.container($transition$.params().id) + ContainerService.container(endpoint.Id, $transition$.params().id) .then(function success(data) { var container = data; $scope.container = container; @@ -158,7 +158,7 @@ angular.module('portainer.docker').controller('ContainerController', [ }; function executeContainerAction(id, action, successMessage, errorMessage) { - action(id) + action(endpoint.Id, id) .then(function success() { Notifications.success(successMessage, id); update(); @@ -210,7 +210,7 @@ angular.module('portainer.docker').controller('ContainerController', [ $scope.container.edit = false; return; } - ContainerService.renameContainer($transition$.params().id, container.newContainerName) + ContainerService.renameContainer(endpoint.Id, $transition$.params().id, container.newContainerName) .then(function success() { container.Name = container.newContainerName; Notifications.success('Container successfully renamed', container.Name); @@ -292,7 +292,7 @@ angular.module('portainer.docker').controller('ContainerController', [ }; function removeContainer(cleanAssociatedVolumes) { - ContainerService.remove($scope.container, cleanAssociatedVolumes) + ContainerService.remove(endpoint.Id, $scope.container.Id, cleanAssociatedVolumes) .then(function success() { Notifications.success('Success', 'Container successfully removed'); $state.go('docker.containers', {}, { reload: true }); @@ -306,7 +306,7 @@ angular.module('portainer.docker').controller('ContainerController', [ var container = $scope.container; $scope.state.recreateContainerInProgress = true; - return ContainerService.recreateContainer(container.Id, pullImage).then(notifyAndChangeView).catch(notifyOnError); + return ContainerService.recreateContainer(endpoint.Id, container.Id, pullImage).then(notifyAndChangeView).catch(notifyOnError); function notifyAndChangeView() { Notifications.success('Success', 'Container successfully re-created'); @@ -333,7 +333,7 @@ angular.module('portainer.docker').controller('ContainerController', [ function updateRestartPolicy(restartPolicy, maximumRetryCount) { maximumRetryCount = restartPolicy === 'on-failure' ? maximumRetryCount : undefined; - return ContainerService.updateRestartPolicy($scope.container.Id, restartPolicy, maximumRetryCount).then(onUpdateSuccess).catch(notifyOnError); + return ContainerService.updateRestartPolicy(endpoint.Id, $scope.container.Id, restartPolicy, maximumRetryCount).then(onUpdateSuccess).catch(notifyOnError); function onUpdateSuccess() { $scope.container.HostConfig.RestartPolicy = { diff --git a/app/docker/views/containers/inspect/containerInspectController.js b/app/docker/views/containers/inspect/containerInspectController.js index 823f9d2b6..45e8d111a 100644 --- a/app/docker/views/containers/inspect/containerInspectController.js +++ b/app/docker/views/containers/inspect/containerInspectController.js @@ -4,7 +4,8 @@ angular.module('portainer.docker').controller('ContainerInspectController', [ 'Notifications', 'ContainerService', 'HttpRequestHelper', - function ($scope, $transition$, Notifications, ContainerService, HttpRequestHelper) { + 'endpoint', + function ($scope, $transition$, Notifications, ContainerService, HttpRequestHelper, endpoint) { $scope.state = { DisplayTextView: false, }; @@ -12,7 +13,7 @@ angular.module('portainer.docker').controller('ContainerInspectController', [ function initView() { HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName); - ContainerService.inspect($transition$.params().id) + ContainerService.inspect(endpoint.Id, $transition$.params().id) .then(function success(d) { $scope.containerInfo = d; }) diff --git a/app/docker/views/containers/logs/containerLogsController.js b/app/docker/views/containers/logs/containerLogsController.js index e63ea2233..a9b4d60cc 100644 --- a/app/docker/views/containers/logs/containerLogsController.js +++ b/app/docker/views/containers/logs/containerLogsController.js @@ -7,7 +7,8 @@ angular.module('portainer.docker').controller('ContainerLogsController', [ 'ContainerService', 'Notifications', 'HttpRequestHelper', - function ($scope, $transition$, $interval, ContainerService, Notifications, HttpRequestHelper) { + 'endpoint', + function ($scope, $transition$, $interval, ContainerService, Notifications, HttpRequestHelper, endpoint) { $scope.state = { refreshRate: 3, lineCount: 100, @@ -39,6 +40,7 @@ angular.module('portainer.docker').controller('ContainerLogsController', [ var refreshRate = $scope.state.refreshRate; $scope.repeater = $interval(function () { ContainerService.logs( + endpoint.Id, $transition$.params().id, 1, 1, @@ -58,7 +60,16 @@ angular.module('portainer.docker').controller('ContainerLogsController', [ } function startLogPolling(skipHeaders) { - ContainerService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount, skipHeaders) + ContainerService.logs( + endpoint.Id, + $transition$.params().id, + 1, + 1, + $scope.state.displayTimestamps ? 1 : 0, + moment($scope.state.sinceTimestamp).unix(), + $scope.state.lineCount, + skipHeaders + ) .then(function success(data) { $scope.logs = data; setUpdateRepeater(skipHeaders); @@ -71,7 +82,7 @@ angular.module('portainer.docker').controller('ContainerLogsController', [ function initView() { HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName); - ContainerService.container($transition$.params().id) + ContainerService.container(endpoint.Id, $transition$.params().id) .then(function success(data) { var container = data; $scope.container = container; diff --git a/app/docker/views/containers/stats/containerStatsController.js b/app/docker/views/containers/stats/containerStatsController.js index 48803264f..107a08f11 100644 --- a/app/docker/views/containers/stats/containerStatsController.js +++ b/app/docker/views/containers/stats/containerStatsController.js @@ -10,7 +10,8 @@ angular.module('portainer.docker').controller('ContainerStatsController', [ 'ChartService', 'Notifications', 'HttpRequestHelper', - function ($q, $scope, $transition$, $document, $interval, ContainerService, ChartService, Notifications, HttpRequestHelper) { + 'endpoint', + function ($q, $scope, $transition$, $document, $interval, ContainerService, ChartService, Notifications, HttpRequestHelper, endpoint) { $scope.state = { refreshRate: '5', networkStatsUnavailable: false, @@ -95,8 +96,8 @@ angular.module('portainer.docker').controller('ContainerStatsController', [ function startChartUpdate(networkChart, cpuChart, memoryChart, ioChart) { $q.all({ - stats: ContainerService.containerStats($transition$.params().id), - top: ContainerService.containerTop($transition$.params().id), + stats: ContainerService.containerStats(endpoint.Id, $transition$.params().id), + top: ContainerService.containerTop(endpoint.Id, $transition$.params().id), }) .then(function success(data) { var stats = data.stats; @@ -123,8 +124,8 @@ angular.module('portainer.docker').controller('ContainerStatsController', [ var refreshRate = $scope.state.refreshRate; $scope.repeater = $interval(function () { $q.all({ - stats: ContainerService.containerStats($transition$.params().id), - top: ContainerService.containerTop($transition$.params().id), + stats: ContainerService.containerStats(endpoint.Id, $transition$.params().id), + top: ContainerService.containerTop(endpoint.Id, $transition$.params().id), }) .then(function success(data) { var stats = data.stats; @@ -163,7 +164,7 @@ angular.module('portainer.docker').controller('ContainerStatsController', [ function initView() { HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName); - ContainerService.container($transition$.params().id) + ContainerService.container(endpoint.Id, $transition$.params().id) .then(function success(data) { $scope.container = data; }) diff --git a/app/docker/views/dashboard/dashboardController.js b/app/docker/views/dashboard/dashboardController.js index 62864b215..d8eb9f64d 100644 --- a/app/docker/views/dashboard/dashboardController.js +++ b/app/docker/views/dashboard/dashboardController.js @@ -79,8 +79,8 @@ angular.module('portainer.docker').controller('DashboardController', [ $scope.showStacks = await shouldShowStacks(); $scope.showEnvUrl = endpoint.Type !== PortainerEndpointTypes.EdgeAgentOnDockerEnvironment && endpoint.Type !== PortainerEndpointTypes.EdgeAgentOnKubernetesEnvironment; $q.all({ - containers: ContainerService.containers(1), - images: ImageService.images(false), + containers: ContainerService.containers(endpoint.Id, 1), + images: ImageService.images(), volumes: VolumeService.volumes(), networks: NetworkService.networks(true, true, true), services: endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER' ? ServiceService.services() : [], diff --git a/app/docker/views/host/host-view-controller.js b/app/docker/views/host/host-view-controller.js index 73a83985d..807b446b1 100644 --- a/app/docker/views/host/host-view-controller.js +++ b/app/docker/views/host/host-view-controller.js @@ -4,9 +4,8 @@ angular.module('portainer.docker').controller('HostViewController', [ 'Notifications', 'StateManager', 'AgentService', - 'ContainerService', 'Authentication', - function HostViewController($q, SystemService, Notifications, StateManager, AgentService, ContainerService, Authentication) { + function HostViewController($q, SystemService, Notifications, StateManager, AgentService, Authentication) { var ctrl = this; this.$onInit = initView; @@ -32,12 +31,10 @@ angular.module('portainer.docker').controller('HostViewController', [ $q.all({ version: SystemService.version(), info: SystemService.info(), - jobs: ctrl.state.isAdmin ? ContainerService.containers(true, { label: ['io.portainer.job.endpoint'] }) : [], }) .then(function success(data) { ctrl.engineDetails = buildEngineDetails(data); ctrl.hostDetails = buildHostDetails(data.info); - ctrl.jobs = data.jobs; if (ctrl.state.isAgent && agentApiVersion > 1 && ctrl.state.enableHostManagementFeatures) { return AgentService.hostInfo(ctrl.endpoint.Id).then(function onHostInfoLoad(agentHostInfo) { diff --git a/app/docker/views/nodes/node-details/node-details-view-controller.js b/app/docker/views/nodes/node-details/node-details-view-controller.js index d3fb439f6..74cae7222 100644 --- a/app/docker/views/nodes/node-details/node-details-view-controller.js +++ b/app/docker/views/nodes/node-details/node-details-view-controller.js @@ -4,9 +4,8 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [ 'NodeService', 'StateManager', 'AgentService', - 'ContainerService', 'Authentication', - function NodeDetailsViewController($q, $stateParams, NodeService, StateManager, AgentService, ContainerService, Authentication) { + function NodeDetailsViewController($q, $stateParams, NodeService, StateManager, AgentService, Authentication) { var ctrl = this; ctrl.$onInit = initView; @@ -22,19 +21,15 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [ ctrl.state.isAdmin = Authentication.isAdmin(); ctrl.state.enableHostManagementFeatures = ctrl.endpoint.SecuritySettings.enableHostManagementFeatures; - var fetchJobs = ctrl.state.isAdmin && ctrl.state.isAgent; - var nodeId = $stateParams.id; $q.all({ node: NodeService.node(nodeId), - jobs: fetchJobs ? ContainerService.containers(true, { label: ['io.portainer.job.endpoint'] }) : [], }).then(function (data) { var node = data.node; ctrl.originalNode = node; ctrl.hostDetails = buildHostDetails(node); ctrl.engineDetails = buildEngineDetails(node); ctrl.nodeDetails = buildNodeDetails(node); - ctrl.jobs = data.jobs; if (ctrl.state.isAgent) { var agentApiVersion = applicationState.endpoint.agentApiVersion; ctrl.state.agentApiVersion = agentApiVersion; diff --git a/app/docker/views/nodes/node-details/node-details-view.html b/app/docker/views/nodes/node-details/node-details-view.html index 571d2dde0..4887f42db 100644 --- a/app/docker/views/nodes/node-details/node-details-view.html +++ b/app/docker/views/nodes/node-details/node-details-view.html @@ -7,10 +7,7 @@ devices="$ctrl.devices" refresh-url="docker.nodes.node" browse-url="docker.nodes.node.browse" - is-job-enabled="$ctrl.state.isAdmin && $ctrl.state.isAgent" host-features-enabled="$ctrl.state.enableHostManagementFeatures" - job-url="docker.nodes.node.job" - jobs="$ctrl.jobs" > diff --git a/app/docker/views/services/edit/serviceController.js b/app/docker/views/services/edit/serviceController.js index 2d1b60ae7..dace78d40 100644 --- a/app/docker/views/services/edit/serviceController.js +++ b/app/docker/views/services/edit/serviceController.js @@ -736,7 +736,7 @@ angular.module('portainer.docker').controller('ServiceController', [ return $q.all({ volumes: VolumeService.volumes(), tasks: TaskService.tasks({ service: [service.Name] }), - containers: agentProxy ? ContainerService.containers() : [], + containers: agentProxy ? ContainerService.containers(endpoint.Id) : [], nodes: NodeService.nodes(), secrets: apiVersion >= 1.25 ? SecretService.secrets() : [], configs: apiVersion >= 1.3 ? ConfigService.configs(endpoint.Id) : [], diff --git a/app/docker/views/services/servicesController.js b/app/docker/views/services/servicesController.js index d3b0c58a4..bb4d192bb 100644 --- a/app/docker/views/services/servicesController.js +++ b/app/docker/views/services/servicesController.js @@ -20,7 +20,7 @@ angular.module('portainer.docker').controller('ServicesController', [ .all({ services: ServiceService.services(), tasks: TaskService.tasks(), - containers: agentProxy ? ContainerService.containers(1) : [], + containers: agentProxy ? ContainerService.containers(endpoint.Id, 1) : [], nodes: NodeService.nodes(), }) .then(function success(data) { diff --git a/app/docker/views/volumes/edit/volumeController.js b/app/docker/views/volumes/edit/volumeController.js index 8500feaca..78d7279c5 100644 --- a/app/docker/views/volumes/edit/volumeController.js +++ b/app/docker/views/volumes/edit/volumeController.js @@ -9,7 +9,8 @@ angular.module('portainer.docker').controller('VolumeController', [ 'ContainerService', 'Notifications', 'HttpRequestHelper', - function ($scope, $state, $transition$, VolumeService, ContainerService, Notifications, HttpRequestHelper) { + 'endpoint', + function ($scope, $state, $transition$, VolumeService, ContainerService, Notifications, HttpRequestHelper, endpoint) { $scope.resourceType = ResourceControlType.Volume; $scope.onUpdateResourceControlSuccess = function () { @@ -46,7 +47,7 @@ angular.module('portainer.docker').controller('VolumeController', [ $scope.volume = volume; var containerFilter = { volume: [volume.Id] }; - return ContainerService.containers(1, containerFilter); + return ContainerService.containers(endpoint.Id, 1, containerFilter); }) .then(function success(data) { var dataContainers = $scope.isCioDriver ? data.containers : data; diff --git a/app/portainer/services/api/stackService.js b/app/portainer/services/api/stackService.js index 5f7a1fef3..9f1985fd2 100644 --- a/app/portainer/services/api/stackService.js +++ b/app/portainer/services/api/stackService.js @@ -126,10 +126,10 @@ angular.module('portainer.app').factory('StackService', [ return deferred.promise; }; - service.externalComposeStacks = function () { + service.externalComposeStacks = function (environmentId) { var deferred = $q.defer(); - ContainerService.containers(1) + ContainerService.containers(environmentId, 1) .then(function success(containers) { deferred.resolve(StackHelper.getExternalStacksFromContainers(containers)); }) @@ -160,7 +160,7 @@ angular.module('portainer.app').factory('StackService', [ $q.all({ stacks: Stack.query({ filters: filters }).$promise, - externalStacks: includeExternalStacks ? service.externalComposeStacks() : [], + externalStacks: includeExternalStacks ? service.externalComposeStacks(endpointId) : [], }) .then(function success(data) { var stacks = data.stacks.map(function (item) { diff --git a/app/portainer/views/stacks/create/createStackController.js b/app/portainer/views/stacks/create/createStackController.js index 23491d1fe..797afa525 100644 --- a/app/portainer/views/stacks/create/createStackController.js +++ b/app/portainer/views/stacks/create/createStackController.js @@ -345,7 +345,7 @@ angular $scope.composeSyntaxMaxVersion = endpoint.ComposeSyntaxMaxVersion; try { - const containers = await ContainerService.containers(true); + const containers = await ContainerService.containers(endpoint.Id, true); $scope.containerNames = ContainerHelper.getContainerNames(containers); } catch (err) { Notifications.error('Failure', err, 'Unable to retrieve Containers'); diff --git a/app/portainer/views/stacks/edit/stackController.js b/app/portainer/views/stacks/edit/stackController.js index 046aebd26..385b7101f 100644 --- a/app/portainer/views/stacks/edit/stackController.js +++ b/app/portainer/views/stacks/edit/stackController.js @@ -332,7 +332,7 @@ angular.module('portainer.app').controller('StackController', [ $q.all({ stack: StackService.stack(id), groups: GroupService.groups(), - containers: ContainerService.containers(true), + containers: ContainerService.containers(endpoint.Id, true), }) .then(function success(data) { var stack = data.stack; @@ -386,7 +386,7 @@ angular.module('portainer.app').controller('StackController', [ return $q.all({ services: ServiceService.services(stackFilter), tasks: TaskService.tasks(stackFilter), - containers: agentProxy ? ContainerService.containers(1) : [], + containers: agentProxy ? ContainerService.containers(endpoint.Id, 1) : [], nodes: NodeService.nodes(), }); } @@ -419,7 +419,7 @@ angular.module('portainer.app').controller('StackController', [ }; return $q.all({ - containers: ContainerService.containers(1, stackFilter), + containers: ContainerService.containers(endpoint.Id, 1, stackFilter), }); } diff --git a/app/portainer/views/templates/templatesController.js b/app/portainer/views/templates/templatesController.js index 7f9b2a680..a19124a7e 100644 --- a/app/portainer/views/templates/templatesController.js +++ b/app/portainer/views/templates/templatesController.js @@ -110,7 +110,7 @@ angular.module('portainer.app').controller('TemplatesController', [ return ImageService.pullImage(template.RegistryModel, true); }) .then(function success() { - return ContainerService.createAndStartContainer(templateConfiguration); + return ContainerService.createAndStartContainer(endpoint.Id, templateConfiguration); }) .then(function success(data) { const resourceControl = data.Portainer.ResourceControl;