22"""
33
44import os
5+ import stat
56from time import sleep
67import subprocess
78import json
@@ -26,6 +27,7 @@ class OARPlugin(SGELikeBatchManagerBase):
2627
2728 # Addtional class variables
2829 _max_jobname_len = 15
30+ _oarsub_args = ''
2931
3032 def __init__ (self , ** kwargs ):
3133 template = """
@@ -53,9 +55,10 @@ def _is_pending(self, taskid):
5355 stderr = subprocess .PIPE
5456 )
5557 o , e = proc .communicate ()
58+ parsed_result = json .loads (o )[taskid ].lower ()
59+ is_pending = 'error' not in parsed_result
5660
57- parsed_result = json .loads (o )[taskid ]
58- return 'error' not in parsed_result
61+ return is_pending
5962
6063 def _submit_batchtask (self , scriptfile , node ):
6164 cmd = CommandLine ('oarsub' , environ = os .environ .data ,
@@ -72,10 +75,7 @@ def _submit_batchtask(self, scriptfile, node):
7275 oarsubargs = node .plugin_args ['oarsub_args' ]
7376 else :
7477 oarsubargs += (" " + node .plugin_args ['oarsub_args' ])
75- if '-o' not in oarsubargs :
76- oarsubargs = '%s -o %s' % (oarsubargs , path )
77- if '-E' not in oarsubargs :
78- oarsubargs = '%s -E %s' % (oarsubargs , path )
78+
7979 if node ._hierarchy :
8080 jobname = '.' .join ((os .environ .data ['LOGNAME' ],
8181 node ._hierarchy ,
@@ -87,12 +87,28 @@ def _submit_batchtask(self, scriptfile, node):
8787 jobnameitems .reverse ()
8888 jobname = '.' .join (jobnameitems )
8989 jobname = jobname [0 :self ._max_jobname_len ]
90+
91+ if '-O' not in oarsubargs :
92+ oarsubargs = '%s -O %s' % (
93+ oarsubargs ,
94+ os .path .join (path , jobname + '.stdout' )
95+ )
96+ if '-E' not in oarsubargs :
97+ oarsubargs = '%s -E %s' % (
98+ oarsubargs ,
99+ os .path .join (path , jobname + '.stderr' )
100+ )
101+ if '-J' not in oarsubargs :
102+ oarsubargs = '%s -J' % (oarsubargs )
103+
104+ os .chmod (scriptfile , stat .S_IEXEC | stat .S_IREAD | stat .S_IWRITE )
90105 cmd .inputs .args = '%s -n %s -S %s' % (
91106 oarsubargs ,
92107 jobname ,
93108 scriptfile
94109 )
95110
111+ print cmd .inputs .args
96112 oldlevel = iflogger .level
97113 iflogger .setLevel (logging .getLevelName ('CRITICAL' ))
98114 tries = 0
@@ -106,7 +122,7 @@ def _submit_batchtask(self, scriptfile, node):
106122 # sleep 2 seconds and try again.
107123 else :
108124 iflogger .setLevel (oldlevel )
109- raise RuntimeError ('\n ' .join ((('Could not submit pbs task'
125+ raise RuntimeError ('\n ' .join ((('Could not submit OAR task'
110126 ' for node %s' ) % node ._id ,
111127 str (e ))))
112128 else :
@@ -126,5 +142,4 @@ def _submit_batchtask(self, scriptfile, node):
126142 taskid = json .loads (o )['job_id' ]
127143 self ._pending [taskid ] = node .output_dir ()
128144 logger .debug ('submitted OAR task: %s for node %s' % (taskid , node ._id ))
129-
130145 return taskid
0 commit comments