1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-05 13:55:21 +02:00

feat(jobs): add the ability to run a job on a target endpoint #2374

* feat(jobs): adding the ability to run scripts on endpoints

fix(job): click on containerId in JobsDatatable redirects to container's logs
refactor(job): remove the jobs datatable settings + texts changes on JobCreation view
fix(jobs): jobs payloads are now following API rules and case
feat(jobs): adding the capability to run scripts on hosts

* feat(jobs): adding the ability to purge jobs containers

* refactor(job): apply review changes

* feat(job-creation): store image name in local storage

* feat(host): disable job exec link in non-agent Swarm setup

* feat(host): only display execute job in agent setups or standalone

* feat(job): job execution overhaul

* docs(swagger): update EndpointJob documentation
This commit is contained in:
baron_l 2018-10-28 07:06:50 +01:00 committed by Anthony Lapenna
parent 6ab510e5cb
commit 354fda31f1
37 changed files with 739 additions and 100 deletions

View file

@ -1,19 +1,19 @@
angular.module('portainer.docker').controller('NodeBrowserController', [
'NodeService', 'HttpRequestHelper', '$stateParams',
function NodeBrowserController(NodeService, HttpRequestHelper, $stateParams) {
'$stateParams', 'NodeService', 'HttpRequestHelper', 'Notifications',
function NodeBrowserController($stateParams, NodeService, HttpRequestHelper, Notifications) {
var ctrl = this;
ctrl.$onInit = $onInit;
function $onInit() {
ctrl.nodeId = $stateParams.id;
loadNode();
}
function loadNode() {
NodeService.node(ctrl.nodeId).then(function onNodeLoaded(node) {
NodeService.node(ctrl.nodeId)
.then(function onNodeLoaded(node) {
HttpRequestHelper.setPortainerAgentTargetHeader(node.Hostname);
ctrl.node = node;
})
.catch(function onError(err) {
Notifications.error('Unable to retrieve host information', err);
});
}
}

View file

@ -1,35 +1,46 @@
angular.module('portainer.docker').controller('NodeDetailsViewController', [
'$stateParams', 'NodeService', 'StateManager', 'AgentService',
function NodeDetailsViewController($stateParams, NodeService, StateManager, AgentService) {
'$q', '$stateParams', 'NodeService', 'StateManager', 'AgentService', 'ContainerService', 'Authentication',
function NodeDetailsViewController($q, $stateParams, NodeService, StateManager, AgentService, ContainerService, Authentication) {
var ctrl = this;
ctrl.$onInit = initView;
ctrl.state = {
isAgent: false
isAgent: false,
isAdmin: false
};
function initView() {
var applicationState = StateManager.getState();
ctrl.state.isAgent = applicationState.endpoint.mode.agentProxy;
ctrl.state.isAdmin = Authentication.getUserDetails().role === 1;
var fetchJobs = ctrl.state.isAdmin && ctrl.state.isAgent;
var nodeId = $stateParams.id;
NodeService.node(nodeId).then(function(node) {
$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;
if (agentApiVersion < 2) {
return;
}
AgentService.hostInfo(node.Hostname)
.then(function onHostInfoLoad(agentHostInfo) {
ctrl.devices = agentHostInfo.PCIDevices;
ctrl.disks = agentHostInfo.PhysicalDisks;
});
.then(function onHostInfoLoad(agentHostInfo) {
ctrl.devices = agentHostInfo.PCIDevices;
ctrl.disks = agentHostInfo.PhysicalDisks;
});
}
});
}
@ -68,12 +79,12 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
function transformPlugins(pluginsList, type) {
return pluginsList
.filter(function(plugin) {
return plugin.Type === type;
})
.map(function(plugin) {
return plugin.Name;
});
.filter(function(plugin) {
return plugin.Type === type;
})
.map(function(plugin) {
return plugin.Name;
});
}
}
]);

View file

@ -5,12 +5,14 @@
engine-details="$ctrl.engineDetails"
disks="$ctrl.disks"
devices="$ctrl.devices"
refresh-url="docker.nodes.node"
browse-url="docker.nodes.node.browse"
is-job-enabled="$ctrl.state.isAdmin && $ctrl.state.isAgent"
job-url="docker.nodes.node.job"
jobs="$ctrl.jobs"
>
<swarm-node-details-panel
details="$ctrl.nodeDetails"
original-node="$ctrl.originalNode"
></swarm-node-details-panel>
</host-overview>
</host-overview>

View file

@ -0,0 +1,20 @@
angular.module('portainer.docker').controller('NodeJobController', [
'$stateParams', 'NodeService', 'HttpRequestHelper', 'Notifications',
function NodeJobController($stateParams, NodeService, HttpRequestHelper, Notifications) {
var ctrl = this;
ctrl.$onInit = $onInit;
function $onInit() {
ctrl.nodeId = $stateParams.id;
NodeService.node(ctrl.nodeId)
.then(function onNodeLoaded(node) {
HttpRequestHelper.setPortainerAgentTargetHeader(node.Hostname);
ctrl.node = node;
})
.catch(function onError(err) {
Notifications.error('Unable to retrieve host information', err);
});
}
}
]);

View file

@ -0,0 +1,18 @@
<rd-header>
<rd-header-title title-text="Host job execution"></rd-header-title>
<rd-header-content>
<a ui-sref="docker.swarm">Swarm</a> &gt; <a ui-sref="docker.nodes.node({ id: $ctrl.nodeId })">{{ $ctrl.node.Hostname }}</a> &gt; execute job
</rd-header-content>
</rd-header>
<div class="row">
<div class="col-sm-12">
<rd-widget>
<rd-widget-body>
<execute-job-form
node-name="$ctrl.node.Hostname"
></execute-job-form>
</rd-widget-body>
</rd-widget>
</div>
</div>

View file

@ -0,0 +1,4 @@
angular.module('portainer.docker').component('nodeJobView', {
templateUrl: 'app/docker/views/nodes/node-job/node-job.html',
controller: 'NodeJobController'
});