Re: RFC: enable bibsched scripting capabilities [draft patch]

2013-06-27 Thread Alexander Wagner

On 27.06.2013 16:28, Ferran Jorba wrote:

Hi!

[...]

One very curious behaviour is that the first task after midnight
switches to SCHEDULED state but doesn't run.


Strange indeed. However, the guys at RWTH had something similar with a
cron job that seemed to put bibsched to manual operation. I'm not sure
if it still persists, but it's nasty as well.


I get the friendly daily mail as such:

  Emergency from http://ddd.uab.cat: BibSched halted: Process bibsort
  (task_id: 140997) was launched but seems not to be able to reach
  RUNNING status.

Anyhow, I needed a mechanism to automate my daily manual task to put
bibsched into manual mode, know which is the task in SCHEDULED state,
run it and put bibsched back to automatic mode.


Out of sheer curiosity: does putting bibsched to manual and run the task
really put to running status? I wonder how that could work. Sounds like
a deeper problem, cause (without knowing the internals of bibsched) this
is exactly what bibsched is supposed to do automagically, right? It
shounds a bit strange, that hooking up a scheduler with another
scheduler (cron, I guess ;) makes the first one working.


I have been patching bibsched to allow, at least, those basic scripting
capabilities.  I don't know how many more tasks do I need (acKnowledge
errors, maybe?).  I'm unsure on the names I have choosen.


How compares bibsched --mode to bibsched stop/start?

Do you know how much of your stuff could be accomplished by these
bibtasklet stuff?

--

Kind regards,

Alexander Wagner
Subject Specialist
Central Library
52425 Juelich

mail : a.wag...@fz-juelich.de
phone: +49 2461 61-1586
Fax  : +49 2461 61-6103
www.fz-juelich.de/zb/DE/zb-fi




Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt,
Prof. Dr. Sebastian M. Schmidt




RFC: enable bibsched scripting capabilities [draft patch]

2013-06-27 Thread Ferran Jorba
Hi all,

since our 1.1 migration we've had some misterious behaviours with
bibsched that, apparently, nobody else has.  It may be related to having
more than one Invenio in a single system, but I haven't been able to
prove it.

One very curious behaviour is that the first task after midnight
switches to SCHEDULED state but doesn't run.  On the test server it
happens to Traces, and on the production it happens to DDD.  No matter
how many hours I spend (and I have spent many!) finding why and how, the
mystery continues.

I get the friendly daily mail as such:

 Emergency from http://ddd.uab.cat: BibSched halted: Process bibsort
 (task_id: 140997) was launched but seems not to be able to reach
 RUNNING status.

Anyhow, I needed a mechanism to automate my daily manual task to put
bibsched into manual mode, know which is the task in SCHEDULED state,
run it and put bibsched back to automatic mode.

I have been patching bibsched to allow, at least, those basic scripting
capabilities.  I don't know how many more tasks do I need (acKnowledge
errors, maybe?).  I'm unsure on the names I have choosen.

As I feel that it may be useful to somebody else, so I submit it for
your consideration.

Comments welcome,

Ferran
BibSched: enable scripting commands [DRAFT]

BibSched is a curses commands with only a few command-line options.  This
first patch adds a new command (appropiately called command) with two
options:

 --mode=[automatic, manual]
 --key=k:task_id

The first one allows to swith from manual to automatic modes, and the second
allows to apply commads to tasks.  Currently only one is implemented: R for
run.
---
 modules/bibsched/lib/bibsched.py |  155 +
 1 files changed, 138 insertions(+), 17 deletions(-)

diff --git a/modules/bibsched/lib/bibsched.py b/modules/bibsched/lib/bibsched.py
index 01314ae..dfba9fb 100644
--- a/modules/bibsched/lib/bibsched.py
+++ b/modules/bibsched/lib/bibsched.py
@@ -31,6 +31,7 @@ import getopt
 from itertools import chain
 from socket import gethostname
 from subprocess import Popen
+from cStringIO import StringIO
 import signal
 
 from invenio.bibtask_config import \
@@ -281,9 +282,78 @@ def bibsched_send_signal(proc, task_id, sig):
 return False
 return False
 
+def parse_report_queue_status():
+'''Get queue status parting the output of report_queue_status.
+
+Returns: a dictionary with the numeric task_id as key and a
+dictionary for each value
+'''
+# print "calling report_queue_status..."
+out = StringIO()
+report_queue_status(verbose=True, status=('WAITING', 'RUNNING', 'SCHEDULED'), stream=out)
+report = out.getvalue()
+tasks = {}
+for line in report.split('\n'):
+fields = {}
+if '"' in line:
+words = line.split('"')
+while words:
+word = words.pop(0)
+if word.endswith('='):
+key = word[:-1].split()[-1]
+value = words.pop(0)
+fields[key] = value
+key = int(fields['ID'])
+tasks[key] = fields
+return tasks
+
+
+def command(opt="", arg=""):
+'''Check command parameters and call Manager with the appropiate values'''
+
+print "opt = [%s] arg = [%s]" % (opt, arg)
+if opt in ('-m', '--mode'):
+arg = arg.upper()
+if 'AUTOMATIC'.startswith(arg):
+mode = 'A'
+elif 'MANUAL'.startswith(arg):
+mode = 'M'
+else:
+mode = None
+print >>sys.stderr,'Unknown mode: %s' % (arg)
+sys.exit(1)
+if mode:
+print 'Manager, mode = %s' % (mode)
+print 'redirect...'
+# old_stdout, old_stderr = redirect_stdout_and_stderr()
+old_stdout = sys.stdout
+Manager(old_stdout, mode)
+elif opt in ('-k', '--key'):
+if arg.count(':') != 1:
+print >>sys.stderr, "Error: syntax: K:task_id"
+sys.exit(1)
+else:
+(cmd, task_id) = arg.split(':')
+if len(cmd) == 1:
+cmd = cmd.upper()
+else:
+print >>sys.stderr, "Error: Key must be single character"
+sys.exit(1)
+if not task_id.isdigit():
+prit >>sys.stderr, "Error: task id not numeric"
+sys.exit(1)
+print 'Manager, command = %s. [%s] [%s]' % (arg, cmd, task_id)
+print 'redirect...'
+# old_stdout, old_stderr = redirect_stdout_and_stderr()
+old_stdout = sys.stdout
+task_id = int(task_id)
+if cmd == "R":
+Manager(old_stdout, cmd, task_id)
+
+
 
 class Manager(object):
-def __init__(self, old_stdout):
+def __init__(self, old_stdout, key='', task_id=0):
 import curses
 import curses.panel
 from curses.wrapper import wrapper
@@ -316,8 +386,40 @@ class Manager(object):
 self.header_lines = 3
   

xslt error with oai_repository_server [bonus: Inspirehep xslt configuration issue]

2013-06-27 Thread Theodoros Theodoropoulos

Hello everyone,

I got an issue that appears when a user tries to access /oai2d?verb=... 
part of my site.


The xslt is not properly loaded and (in Firefox) the user gets:
Error loading stylesheet: An unknown error has occurred (805303f4)
http://xxx.yyy.zzz/css/oai2.xsl.v1.0

Of course, the xml is produced as it should be, and if I select to see 
the html source, all the xml tags are properly shown.
Also, the oai2.xsl.v1.0 url is correct, accessible and one can download 
the actual file if one copy-pastes the full url in a browser, however, 
strangely enough, the xslt is not automatically loaded and the above 
error is produced.


I identified the issue in oai_repository_server.py, in the part where 
the oai2.xsl.v1.0 is loaded. So, If I change CFG_SITE_URL to 
CFG_SITE_SECURE_URL [*], the issue is resolved!


FYI, Internet Explorer is 'smarter' and since it cannot load the xslt, 
it displays the xml data. But if you try with Firefox, you will see the 
error.


Apologies if this is handled in some other way (ie with a directive in 
apache configuration), I just thought I should mention it...


Best regards,
Theodoros

ps. While playing around to see how other cern sites behave, I got this 
error while trying "http://inspirehep.net/oai2d?verb=Identify":
Error loading stylesheet: A network error occurred loading an XSLT 
stylesheet:http://inspirehep.net/css/oai2.xsl.v1.0
Which is obviously a configuration issue (the file does not exist in 
that path), unrelated to what i experience. I'm mentioning it in case 
you want to fix it :)



[*] Of course, one has to import the relevant variable from 
invenio.config too...