[pve-devel] r6033 - in pve-manager/pve2: lib/PVE/API2 www/new/window

svn-commits at proxmox.com svn-commits at proxmox.com
Fri May 27 13:22:37 CEST 2011


Author: dietmar
Date: 2011-05-27 13:22:37 +0200 (Fri, 27 May 2011)
New Revision: 6033

Modified:
   pve-manager/pve2/lib/PVE/API2/Tasks.pm
   pve-manager/pve2/www/new/window/TaskViewer.js
Log:
impl. task stop, cleanups


Modified: pve-manager/pve2/lib/PVE/API2/Tasks.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Tasks.pm	2011-05-27 09:12:23 UTC (rev 6032)
+++ pve-manager/pve2/lib/PVE/API2/Tasks.pm	2011-05-27 11:22:37 UTC (rev 6033)
@@ -119,6 +119,76 @@
     }});
 
 __PACKAGE__->register_method({
+    name => 'upid_index', 
+    path => '{upid}', 
+    method => 'GET',
+    description => '', # index helper
+    permissions => { user => 'all' },
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    upid => { type => 'string' },
+	}
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {},
+	},
+	links => [ { rel => 'child', href => "{name}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	return [
+	    { name => 'log' },
+	    { name => 'status' }
+	    ];
+    }});
+
+__PACKAGE__->register_method({
+    name => 'stop_task', 
+    path => '{upid}', 
+    method => 'DELETE',
+    description => 'Stop a task.',
+    permissions => { user => 'all' },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    upid => { type => 'string' },
+	}
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+
+	my ($task, $filename) = PVE::Tools::upid_decode($param->{upid}, 1);
+	raise_param_exc({ upid => "unable to parse worker upid" }) if !$task;
+	raise_param_exc({ upid => "no such task" }) if ! -f $filename;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	my $node = $param->{node};
+
+	my $sysadmin = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Console' ]);
+	die "Permission check failed\n"
+	    if !($sysadmin || $user eq $task->{user});
+
+	my $pstart = PVE::ProcFSTools::read_proc_starttime($task->{pid});
+	$task->{status} = ($pstart && ($pstart == $task->{pstart})) ?
+	    'running' : 'stopped';
+
+	die "not implemented - fixme"; 
+
+	return undef;
+    }});
+
+__PACKAGE__->register_method({
     name => 'read_task_log', 
     path => '{upid}/log', 
     method => 'GET',
@@ -228,6 +298,7 @@
 
 	my ($task, $filename) = PVE::Tools::upid_decode($param->{upid}, 1);
 	raise_param_exc({ upid => "unable to parse worker upid" }) if !$task;
+	raise_param_exc({ upid => "no such task" }) if ! -f $filename;
 
 	my $lines = [];
 

Modified: pve-manager/pve2/www/new/window/TaskViewer.js
===================================================================
--- pve-manager/pve2/www/new/window/TaskViewer.js	2011-05-27 09:12:23 UTC (rev 6032)
+++ pve-manager/pve2/www/new/window/TaskViewer.js	2011-05-27 11:22:37 UTC (rev 6033)
@@ -11,11 +11,39 @@
 	if (!me.upid)
 	    throw "no task specified";
 
-	//console.log("TEST " + me.upid);
-
 	var task = PVE.Utils.parse_task_upid(me.upid);
-	//console.dir(task);
 
+	var rows = {
+	    status: {
+		header: 'Status',
+		defaultValue: 'unknown'
+	    },
+	    type: {
+		header: 'Task type',
+		required: true
+	    },
+	    user: {
+		header: 'User name',
+		required: true 
+	    },
+	    node: {
+		header: 'Node',
+		required: true 
+	    },
+	    pid: {
+		header: 'Process ID',
+		required: true
+	    },
+	    starttime: {
+		header: 'Start time',
+		required: true, 
+		renderer: PVE.Utils.render_timestamp
+	    },
+	    upid: {
+		header: 'Unique task ID'
+	    }
+	};
+
 	var store = Ext.create('Ext.data.Store', {
  	    model: Ext.define('pve-string-list', {
 		extend: 'Ext.data.Model',
@@ -34,12 +62,55 @@
 
 	var statstore = Ext.create('PVE.data.ObjectStore', {
             url: "/api2/json/nodes/" + task.node + "/tasks/" + me.upid + "/status",
-	    interval: 1000
-	    //rows: me.rows
+	    interval: 1000,
+	    rows: rows,
 	});
 
 	me.on('destroy', statstore.stopUpdate);	
 
+	var stop_task = function() {
+	    me.setLoading(true, true);
+	    PVE.Utils.API2Request({
+		url: "/nodes/" + task.node + "/tasks/" + me.upid,
+		method: 'DELETE',
+		callback: function() {
+		    me.setLoading(false);
+		},
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		}
+	    });
+	};
+
+	var stop_btn1 = new Ext.Button({
+	    text: 'Stop',
+	    disabled: true,
+	    handler: stop_task
+	});
+	var stop_btn2 = new Ext.Button({
+	    text: 'Stop',
+	    disabled: true,
+	    handler: stop_task
+	});
+
+	var statgrid = Ext.create('PVE.grid.ObjectGrid', {
+	    title: 'Status',
+	    layout: 'fit',
+	    tbar: [ stop_btn1 ],
+	    rstore: statstore,
+	    rows: rows,
+	    border: false
+	});
+
+	me.mon(statstore, 'load', function() {
+	    var status = statgrid.getObjectValue('status');
+	    if (status === 'stopped')
+	    	statstore.stopUpdate();
+
+	    stop_btn1.setDisabled(status !== 'running');
+	    stop_btn2.setDisabled(status !== 'running');
+	});
+
 	statstore.startUpdate();
 
 	Ext.applyIf(me, {
@@ -55,6 +126,7 @@
 		items: [
 		    {
 			title: 'Output',
+			tbar: [ stop_btn2 ],
 			border: false,
 			xtype: 'gridpanel',
 			features: [ {ftype: 'selectable'}],
@@ -75,18 +147,7 @@
 			    { header: "Text", dataIndex: 't', flex: 1 } 
 			]
 		    },
-		    {
-			title: 'Status',
-			xtype: 'pveObjectGrid',
-			layout: 'fit',
-			tbar: [ 
-			    {
-				text: 'Stop'
-			    }
-			],
-			rstore: statstore,
-			border: false
-		    }
+		    statgrid
 		]
 	    }]
         });




More information about the pve-devel mailing list