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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri May 27 06:56:54 CEST 2011


Author: dietmar
Date: 2011-05-27 06:56:54 +0200 (Fri, 27 May 2011)
New Revision: 6025

Added:
   pve-manager/pve2/lib/PVE/API2/Tasks.pm
Modified:
   pve-manager/pve2/lib/PVE/API2/Makefile.am
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/www/new/window/TaskViewer.js
Log:
improve task viewer


Modified: pve-manager/pve2/lib/PVE/API2/Makefile.am
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Makefile.am	2011-05-26 11:06:16 UTC (rev 6024)
+++ pve-manager/pve2/lib/PVE/API2/Makefile.am	2011-05-27 04:56:54 UTC (rev 6025)
@@ -5,6 +5,7 @@
 pvelib_DATA = 			\
 	Cluster.pm		\
 	Nodes.pm		\
+	Tasks.pm		\
 	Network.pm		\
 	Services.pm
 

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-26 11:06:16 UTC (rev 6024)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-27 04:56:54 UTC (rev 6025)
@@ -3,7 +3,6 @@
 use strict;
 use warnings;
 use POSIX;
-use File::ReadBackwards;
 use Filesys::Df;
 use Time::Local qw(timegm_nocheck);
 use PVE::pvecfg;
@@ -18,6 +17,7 @@
 use PVE::AccessControl;
 use PVE::API2::Services;
 use PVE::API2::Network;
+use PVE::API2::Tasks;
 use PVE::API2::Storage::Scan;
 use PVE::API2::Storage::Status;
 use PVE::API2::Qemu;
@@ -41,6 +41,11 @@
 });
 
 __PACKAGE__->register_method ({
+    subclass => "PVE::API2::Tasks",  
+    path => 'tasks',
+});
+
+__PACKAGE__->register_method ({
     subclass => "PVE::API2::Storage::Scan",  
     path => 'scan',
 });
@@ -251,190 +256,8 @@
 	}
     }});
 
-__PACKAGE__->register_method({
-    name => 'tasks', 
-    path => 'tasks', 
-    method => 'GET',
-    permissions => { user => 'all' },
-    description => "Read task list (finished tasks).",
-    proxyto => 'node',
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    start => {
-		type => 'integer',
-		minimum => 0,
-		optional => 1,
-	    },
-	    limit => {
-		type => 'integer',
-		minimum => 0,
-		optional => 1,
-	    },
-	    userfilter => {
-		type => 'string',
-		optional => 1,
-	    },
-	    errors => {
-		type => 'boolean',
-		optional => 1,
-	    },
-	},
-    },
-    returns => {
-	type => 'array',
-	items => {
-	    type => "object",
-	    properties => {
-		upid => { type => 'string' },
-	    },
-	},
-	links => [ { rel => 'child', href => "{upid}" } ],
-    },
-    code => sub {
-	my ($param) = @_;
 
-	my $rpcenv = PVE::RPCEnvironment::get();
-	my $user = $rpcenv->get_user();
-
-	my $res = [];
-
-	my $filename = "/var/log/pve/tasks/index";
-
-	my $node = $param->{node};
-	my $start = $param->{start} || 0;
-	my $limit = $param->{limit} || 50;
-	my $userfilter = $param->{userfilter};
-	my $errors = $param->{errors};
-
-	my $count = 0;
-	my $line;
-
-	my $autitor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
-
-	my $parse_line = sub {
-	    if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
-		my $upid = $1;
-		my $endtime = $3;
-		my $status = $5;
-		if ((my $task = PVE::Tools::upid_decode($upid, 1))) {
-		    return if $userfilter && $task->{user} !~ m/\Q$userfilter\E/i;
-		    next if !($autitor || $user eq $task->{user});
-
-		    return if $errors && $status && $status eq 'OK';
-
-		    return if $count++ < $start;
-		    return if $limit <= 0;
-
-		    $task->{upid} = $upid;
-		    $task->{endtime} = hex($endtime) if $endtime;
-		    $task->{status} = $status if $status;
-		    push @$res, $task;
-		    $limit--;
-		}
-	    }
-	};
-
-	if (my $bw = File::ReadBackwards->new($filename)) {	
-	    while (defined ($line = $bw->readline)) {
-		&$parse_line();
-	    }
-	    $bw->close();
-	}
-	if (my $bw = File::ReadBackwards->new("$filename.1")) {	
-	    while (defined ($line = $bw->readline)) {
-		&$parse_line();
-	    }
-	    $bw->close();
-	}
-
-	$rpcenv->set_result_count($count);
-
-	return $res;
-    }});
-
 __PACKAGE__->register_method({
-    name => 'read_task_log', 
-    path => 'tasks/{upid}', 
-    method => 'GET',
-    permissions => { user => 'all' },
-    protected => 1,
-    description => "Read task log.",
-    proxyto => 'node',
-    parameters => {
-    	additionalProperties => 0,
-	properties => {
-	    node => get_standard_option('pve-node'),
-	    upid => { type => 'string' },
-	    start => {
-		type => 'integer',
-		minimum => 0,
-		optional => 1,
-	    },
-	    limit => {
-		type => 'integer',
-		minimum => 0,
-		optional => 1,
-	    },
-	},
-    },
-    returns => {
-	type => 'array',
-	items => { 
-	    type => "object",
-	    properties => {
-		n => {
-		  description=>  "Line number",
-		  type=> 'integer',
-		},
-		t => {
-		  description=>  "Line text",
-		  type => 'string',
-		}
-	    }
-	}
-    },
-    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;
-
-	my $lines = [];
-
-	my $rpcenv = PVE::RPCEnvironment::get();
-	my $user = $rpcenv->get_user();
-	my $node = $param->{node};
-
-	my $autitor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
-	die "Permission check failed\n"
-	    if !($autitor || $user eq $task->{user});
-
-	my $fh = IO::File->new($filename, "r");
-	raise_param_exc({ upid => "no such task - unable to open file - $!" }) if !$fh;
-
-	my $start = $param->{start} || 0;
-	my $limit = $param->{limit} || 50;
-	my $count = 0;
-	my $line;
-
-	while (defined ($line = <$fh>)) {
-	    next if $count++ < $start;
-	    next if $limit <= 0;
-	    chomp $line;
-	    push @$lines, { n => $count, t => $line};
-	    $limit--;
-	}
-
-	close($fh);
-
-	$rpcenv->set_result_count($count);
-	    
-	return $lines;
-    }});
-
-__PACKAGE__->register_method({
     name => 'rrd', 
     path => 'rrd', 
     method => 'GET',

Added: pve-manager/pve2/lib/PVE/API2/Tasks.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Tasks.pm	                        (rev 0)
+++ pve-manager/pve2/lib/PVE/API2/Tasks.pm	2011-05-27 04:56:54 UTC (rev 6025)
@@ -0,0 +1,238 @@
+package PVE::API2::Tasks;
+
+use strict;
+use warnings;
+use POSIX;
+use IO::File;
+use File::ReadBackwards;
+use PVE::Tools;
+use PVE::SafeSyslog;
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::AccessControl;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+    name => 'node_tasks', 
+    path => '', 
+    method => 'GET',
+    permissions => { user => 'all' },
+    description => "Read task list for one node (finished tasks).",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    start => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	    limit => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	    userfilter => {
+		type => 'string',
+		optional => 1,
+	    },
+	    errors => {
+		type => 'boolean',
+		optional => 1,
+	    },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => {
+	    type => "object",
+	    properties => {
+		upid => { type => 'string' },
+	    },
+	},
+	links => [ { rel => 'child', href => "{upid}" } ],
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+
+	my $res = [];
+
+	my $filename = "/var/log/pve/tasks/index";
+
+	my $node = $param->{node};
+	my $start = $param->{start} || 0;
+	my $limit = $param->{limit} || 50;
+	my $userfilter = $param->{userfilter};
+	my $errors = $param->{errors};
+
+	my $count = 0;
+	my $line;
+
+	my $auditor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
+
+	my $parse_line = sub {
+	    if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
+		my $upid = $1;
+		my $endtime = $3;
+		my $status = $5;
+		if ((my $task = PVE::Tools::upid_decode($upid, 1))) {
+		    return if $userfilter && $task->{user} !~ m/\Q$userfilter\E/i;
+		    next if !($auditor || $user eq $task->{user});
+
+		    return if $errors && $status && $status eq 'OK';
+
+		    return if $count++ < $start;
+		    return if $limit <= 0;
+
+		    $task->{upid} = $upid;
+		    $task->{endtime} = hex($endtime) if $endtime;
+		    $task->{status} = $status if $status;
+		    push @$res, $task;
+		    $limit--;
+		}
+	    }
+	};
+
+	if (my $bw = File::ReadBackwards->new($filename)) {	
+	    while (defined ($line = $bw->readline)) {
+		&$parse_line();
+	    }
+	    $bw->close();
+	}
+	if (my $bw = File::ReadBackwards->new("$filename.1")) {	
+	    while (defined ($line = $bw->readline)) {
+		&$parse_line();
+	    }
+	    $bw->close();
+	}
+
+	$rpcenv->set_result_count($count);
+
+	return $res;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'read_task_log', 
+    path => '{upid}/log', 
+    method => 'GET',
+    permissions => { user => 'all' },
+    protected => 1,
+    description => "Read task log.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    upid => { type => 'string' },
+	    start => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	    limit => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => { 
+	    type => "object",
+	    properties => {
+		n => {
+		  description=>  "Line number",
+		  type=> 'integer',
+		},
+		t => {
+		  description=>  "Line text",
+		  type => 'string',
+		}
+	    }
+	}
+    },
+    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;
+
+	my $lines = [];
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	my $node = $param->{node};
+
+	my $auditor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
+	die "Permission check failed\n"
+	    if !($auditor || $user eq $task->{user});
+
+	my $fh = IO::File->new($filename, "r");
+	raise_param_exc({ upid => "no such task - unable to open file - $!" }) if !$fh;
+
+	my $start = $param->{start} || 0;
+	my $limit = $param->{limit} || 50;
+	my $count = 0;
+	my $line;
+
+	while (defined ($line = <$fh>)) {
+	    next if $count++ < $start;
+	    next if $limit <= 0;
+	    chomp $line;
+	    push @$lines, { n => $count, t => $line};
+	    $limit--;
+	}
+
+	close($fh);
+
+	$rpcenv->set_result_count($count);
+	    
+	return $lines;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'read_task_status', 
+    path => '{upid}/status', 
+    method => 'GET',
+    permissions => { user => 'all' },
+    protected => 1,
+    description => "Read task status.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    upid => { type => 'string' },
+	},
+    },
+    returns => {
+	type => "object",
+	properties => {},
+    },
+    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;
+
+	my $lines = [];
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	my $node = $param->{node};
+
+	my $auditor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
+	die "Permission check failed\n"
+	    if !($auditor || $user eq $task->{user});
+
+	$task->{upid} = $param->{upid}; # include upid
+
+	return $task;
+    }});

Modified: pve-manager/pve2/www/new/window/TaskViewer.js
===================================================================
--- pve-manager/pve2/www/new/window/TaskViewer.js	2011-05-26 11:06:16 UTC (rev 6024)
+++ pve-manager/pve2/www/new/window/TaskViewer.js	2011-05-27 04:56:54 UTC (rev 6025)
@@ -28,36 +28,67 @@
                 type: 'pve',
 		startParam: 'start',
 		limitParam: 'limit',
-                url: "/api2/json/nodes/" + task.node + "/tasks/" + me.upid
+                url: "/api2/json/nodes/" + task.node + "/tasks/" + me.upid + "/log"
 	    },
 	});
 
+	var statstore = Ext.create('PVE.data.ObjectStore', {
+            url: "/api2/json/nodes/" + task.node + "/tasks/" + me.upid + "/status",
+	    interval: 1000
+	    //rows: me.rows
+	});
+
+	me.on('destroy', statstore.stopUpdate);	
+
+	statstore.startUpdate();
+
 	Ext.applyIf(me, {
 	    title: "Task viewer: " + task.desc,
 	    width: 800,
 	    height: 400,
 	    layout: 'fit',
-	    items: {
-		xtype: 'gridpanel',
-		features: [ {ftype: 'selectable'}],
-		store: store,
-		stateful: false,
-		border: false,
-		tbar: [ 'test' ],
-		verticalScrollerType: 'paginggridscroller',
-		loadMask: true,
-		disableSelection: true,
-		invalidateScrollerOnRefresh: false,
-		viewConfig: {
-		    trackOver: false,
-		    stripeRows: false
-		},
-		hideHeaders: true,
-		columns: [ 
-		    //{ header: "Line", dataIndex: 'n', width: 50 },
-		    { header: "Text", dataIndex: 't', flex: 1 } 
+	    modal: true,
+	    bodyPadding: 5,
+	    items: [{
+		xtype: 'tabpanel',
+		region: 'center',
+		items: [
+		    {
+			title: 'Output',
+			border: false,
+			xtype: 'gridpanel',
+			features: [ {ftype: 'selectable'}],
+			store: store,
+			stateful: false,
+			//tbar: [ 'test' ],
+			verticalScrollerType: 'paginggridscroller',
+			loadMask: true,
+			disableSelection: true,
+			invalidateScrollerOnRefresh: false,
+			viewConfig: {
+			    trackOver: false,
+			    stripeRows: false
+			},
+			hideHeaders: true,
+			columns: [ 
+			    //{ header: "Line", dataIndex: 'n', width: 50 },
+			    { header: "Text", dataIndex: 't', flex: 1 } 
+			]
+		    },
+		    {
+			title: 'Status',
+			xtype: 'pveObjectGrid',
+			layout: 'fit',
+			tbar: [ 
+			    {
+				text: 'Stop'
+			    }
+			],
+			rstore: statstore,
+			border: false
+		    }
 		]
-	    }
+	    }]
         });
 
         me.callParent();




More information about the pve-devel mailing list