10 |
|
sub dbInsert; |
11 |
|
sub addSlashes; |
12 |
|
sub getOption; |
13 |
+ |
sub deleteEntry; |
14 |
|
|
15 |
|
our $db = Mysql->connect ("cmshead.mps.ohio-state.edu", "ntuple", "osuT3User") or die "Failed to connect to Tier 3, stopped"; |
16 |
|
|
26 |
|
my $psetName = getOption (\@crabCfg, "pset"); |
27 |
|
my $jsonFileName = getOption (\@crabCfg, "lumi_mask"); |
28 |
|
my $workingDir = getOption (\@crabCfg, "ui_working_dir"); |
29 |
+ |
my $publishName = ""; |
30 |
+ |
$publishName = getOption (\@crabCfg, "publish_data_name") if getOption (\@crabCfg, "publish_data") eq "1"; |
31 |
+ |
my $stageOutLocation = getOption (\@crabCfg, "storage_element"); |
32 |
|
|
33 |
|
print "Ntuple format (BEAN): "; |
34 |
|
my $format = <STDIN>; |
38 |
|
my $comment = <STDIN>; |
39 |
|
$comment =~ s/\n//g; |
40 |
|
|
41 |
< |
system ("crab $arg"); |
41 |
> |
system ("rm -f .crabSubmit.log ; crab $arg 2>&1 | tee .crabSubmit.log"); |
42 |
|
|
43 |
|
my $status = "created"; |
44 |
|
$status = "submitted" if $arg =~ m/-submit/; |
45 |
< |
my $results = dbInsert ($dataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $format, "", 0, 0, $status, $comment, $psetName, $crabCfgName, $jsonFileName, $workingDir); |
45 |
> |
my $hostname = `/bin/hostname`; |
46 |
> |
$hostname =~ s/[\f\n\r]//g; |
47 |
> |
my $results = dbInsert ($dataset, "$ENV{'USER'}\@$hostname", $format, "", 0, 0, $status, $comment, $psetName, $crabCfgName, $jsonFileName, $workingDir, $publishName, $stageOutLocation); |
48 |
|
} |
49 |
|
elsif ($arg =~ m/-submit/) |
50 |
|
{ |
57 |
|
close (ID_FILE); |
58 |
|
$id =~ s/(.*)\n/$1/; |
59 |
|
} |
60 |
+ |
my $logFile = $workingDir . "/log/crabSubmit.log"; |
61 |
|
|
62 |
< |
system ("crab $arg"); |
62 |
> |
system ("crab $arg 2>&1 | tee -a .crabSubmit.log ; if [ -e \"$workingDir/log/crabSubmit.log\" ] ; then rm -f .crabSubmit.log ; else mv -f .crabSubmit.log $workingDir/log/crabSubmit.log ; fi"); |
63 |
|
|
64 |
< |
my $results = dbUpdate ($id, "submitted", "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
64 |
> |
my $hostname = `/bin/hostname`; |
65 |
> |
$hostname =~ s/[\f\n\r]//g; |
66 |
> |
my $results = dbUpdate ($id, "submitted", "$ENV{'USER'}\@$hostname", $logFile) if $id > -1; |
67 |
|
} |
68 |
|
elsif ($arg =~ m/-report/) |
69 |
|
{ |
80 |
|
|
81 |
|
system ("crab $arg"); |
82 |
|
|
83 |
< |
my $results = dbReport ($id, "complete", $lumiSummaryName, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
83 |
> |
my $hostname = `/bin/hostname`; |
84 |
> |
$hostname =~ s/[\f\n\r]//g; |
85 |
> |
my $results = dbReport ($id, $lumiSummaryName, "$ENV{'USER'}\@$hostname") if $id > -1; |
86 |
|
} |
87 |
|
elsif ($arg =~ m/-status/) |
88 |
|
{ |
98 |
|
my $currentStatusName = "$workingDir/log/.currentStatus"; |
99 |
|
unlink ($currentStatusName) if -e $currentStatusName; |
100 |
|
system ("crab $arg | tee $currentStatusName"); |
101 |
< |
my $results = dbStatus ($id, $currentStatusName, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
101 |
> |
my $hostname = `/bin/hostname`; |
102 |
> |
$hostname =~ s/[\f\n\r]//g; |
103 |
> |
my $results = dbStatus ($id, $currentStatusName, "$ENV{'USER'}\@$hostname") if $id > -1; |
104 |
|
unlink ($currentStatusName); |
105 |
|
} |
106 |
+ |
elsif ($arg =~ m/-kill/) |
107 |
+ |
{ |
108 |
+ |
my $workingDir = getWorkingDir (\@ARGV); |
109 |
+ |
my $id = -1; |
110 |
+ |
if (-e "$workingDir/log/.osuID") |
111 |
+ |
{ |
112 |
+ |
open (ID_FILE, "<$workingDir/log/.osuID"); |
113 |
+ |
$id = <ID_FILE>; |
114 |
+ |
close (ID_FILE); |
115 |
+ |
$id =~ s/(.*)\n/$1/; |
116 |
+ |
} |
117 |
+ |
|
118 |
+ |
print "Are you cancelling this task? (y/N): "; |
119 |
+ |
my $response = <STDIN>; |
120 |
+ |
$response =~ s/\n//g; |
121 |
+ |
deleteEntry ($id) if lc ($response) eq "y"; |
122 |
+ |
system ("crab $arg"); |
123 |
+ |
} |
124 |
|
else |
125 |
|
{ |
126 |
|
system ("crab $arg"); |
155 |
|
my $optionValue; |
156 |
|
foreach my $line (@$file) |
157 |
|
{ |
158 |
+ |
next if ($line =~ m/^[ \t\n]*#/); |
159 |
|
next if (!($line =~ m/$option *= *[^ \t\n]*/)); |
160 |
|
$optionValue = $line; |
161 |
|
$optionValue =~ s/.*$option *= *([^ \t\n]*).*\n/$1/; |
192 |
|
my $crabCfgName = shift; |
193 |
|
my $jsonFileName = shift; |
194 |
|
my $workingDir = shift; |
195 |
+ |
my $publishName = shift; |
196 |
+ |
my $stageOutLocation = shift; |
197 |
|
|
198 |
|
my $user = $userAndHost; |
199 |
|
$user =~ s/@.*$//; |
220 |
|
$location = addSlashes ($location); |
221 |
|
$status = addSlashes ($status); |
222 |
|
$comment = addSlashes ($comment); |
223 |
+ |
$publishName = addSlashes ($publishName); |
224 |
+ |
$stageOutLocation = addSlashes ($stageOutLocation); |
225 |
|
|
226 |
|
my $results; |
227 |
|
my $query = "select max(id) from ntuple"; |
235 |
|
print ID_FILE "$id\n"; |
236 |
|
close (ID_FILE); |
237 |
|
|
238 |
< |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$location', $nFiles, $sizeInGB, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile')"; |
238 |
> |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, publishName, stageOutLocation, published) values ($id, '$dataset', now(), now(), '$userAndHost', '$user', '$format', '$location', $nFiles, $sizeInGB, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$publishName', '$stageOutLocation', 0)"; |
239 |
|
$results = $db->query ($query); |
240 |
|
|
241 |
|
return $results; |
247 |
|
my $id = shift; |
248 |
|
my $status = shift; |
249 |
|
my $user = shift; |
250 |
+ |
my $logName = shift; |
251 |
+ |
|
252 |
+ |
open (LOG, "<$logName"); |
253 |
+ |
my @log = <LOG>; |
254 |
+ |
close (LOG); |
255 |
+ |
my $log = join ("", @log); |
256 |
|
|
257 |
|
$status = addSlashes ($status); |
258 |
|
$user = addSlashes ($user); |
259 |
+ |
$log = addSlashes ($log); |
260 |
|
|
261 |
|
my $results; |
262 |
< |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', status='$status' where id=$id"; |
262 |
> |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', status='$status', submissionLog='$log' where id=$id"; |
263 |
|
$db->selectdb ("ntuple"); |
264 |
|
$results = $db->query ($query); |
265 |
|
|
293 |
|
dbReport |
294 |
|
{ |
295 |
|
my $id = shift; |
253 |
– |
my $status = shift; |
296 |
|
my $lumiSummaryName = shift; |
297 |
|
my $user = shift; |
298 |
|
|
302 |
|
my $lumiSummary = join ("", @lumiSummary); |
303 |
|
|
304 |
|
$lumiSummary = addSlashes ($lumiSummary); |
263 |
– |
$status = addSlashes ($status); |
305 |
|
$user = addSlashes ($user); |
306 |
|
|
307 |
|
my $results; |
308 |
< |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', status='$status', lumiSummary='$lumiSummary' where id=$id"; |
308 |
> |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', lumiSummary='$lumiSummary' where id=$id"; |
309 |
> |
$db->selectdb ("ntuple"); |
310 |
> |
$results = $db->query ($query); |
311 |
> |
|
312 |
> |
return $results; |
313 |
> |
} |
314 |
> |
|
315 |
> |
sub |
316 |
> |
deleteEntry |
317 |
> |
{ |
318 |
> |
my $id = shift; |
319 |
> |
|
320 |
> |
my $results; |
321 |
> |
my $query = "delete from ntuple where id=$id"; |
322 |
|
$db->selectdb ("ntuple"); |
323 |
|
$results = $db->query ($query); |
324 |
|
|