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 |
|
|
25 |
|
my $dataset = getOption (\@crabCfg, "datasetpath"); |
26 |
|
my $psetName = getOption (\@crabCfg, "pset"); |
27 |
|
my $jsonFileName = getOption (\@crabCfg, "lumi_mask"); |
28 |
< |
my $submissionLogName = getOption (\@crabCfg, "ui_working_dir"); |
28 |
< |
$submissionLogName .= "/log/crab.log"; |
28 |
> |
my $workingDir = getOption (\@crabCfg, "ui_working_dir"); |
29 |
|
|
30 |
|
print "Ntuple format (BEAN): "; |
31 |
|
my $format = <STDIN>; |
39 |
|
|
40 |
|
my $status = "created"; |
41 |
|
$status = "submitted" if $arg =~ m/-submit/; |
42 |
< |
my $results = dbInsert ($dataset, $ENV{"USER"}, $format, "", 0, 0, $status, $comment, $psetName, $crabCfgName, $jsonFileName, $submissionLogName); |
42 |
> |
my $results = dbInsert ($dataset, "$ENV{'USER'}\@$ENV{'HOSTNAME'}", $format, "", 0, 0, $status, $comment, $psetName, $crabCfgName, $jsonFileName, $workingDir); |
43 |
|
} |
44 |
|
elsif ($arg =~ m/-submit/) |
45 |
|
{ |
52 |
|
close (ID_FILE); |
53 |
|
$id =~ s/(.*)\n/$1/; |
54 |
|
} |
55 |
– |
my $submissionLogName = $workingDir . "/log/crab.log"; |
55 |
|
|
56 |
|
system ("crab $arg"); |
57 |
|
|
58 |
< |
my $results = dbUpdate ($id, "submitted", $submissionLogName, $ENV{"USER"}) if $id > -1; |
58 |
> |
my $results = dbUpdate ($id, "submitted", "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
59 |
|
} |
60 |
|
elsif ($arg =~ m/-report/) |
61 |
|
{ |
72 |
|
|
73 |
|
system ("crab $arg"); |
74 |
|
|
75 |
< |
my $results = dbReport ($id, "complete", $lumiSummaryName, $ENV{"USER"}) if $id > -1; |
75 |
> |
my $results = dbReport ($id, "complete", $lumiSummaryName, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
76 |
|
} |
77 |
|
elsif ($arg =~ m/-status/) |
78 |
|
{ |
88 |
|
my $currentStatusName = "$workingDir/log/.currentStatus"; |
89 |
|
unlink ($currentStatusName) if -e $currentStatusName; |
90 |
|
system ("crab $arg | tee $currentStatusName"); |
91 |
< |
my $results = dbStatus ($id, $currentStatusName, $ENV{"USER"}) if $id > -1; |
91 |
> |
my $results = dbStatus ($id, $currentStatusName, "$ENV{'USER'}\@$ENV{'HOSTNAME'}") if $id > -1; |
92 |
|
unlink ($currentStatusName); |
93 |
|
} |
94 |
+ |
elsif ($arg =~ m/-kill/) |
95 |
+ |
{ |
96 |
+ |
my $workingDir = getWorkingDir (\@ARGV); |
97 |
+ |
my $id = -1; |
98 |
+ |
if (-e "$workingDir/log/.osuID") |
99 |
+ |
{ |
100 |
+ |
open (ID_FILE, "<$workingDir/log/.osuID"); |
101 |
+ |
$id = <ID_FILE>; |
102 |
+ |
close (ID_FILE); |
103 |
+ |
$id =~ s/(.*)\n/$1/; |
104 |
+ |
} |
105 |
+ |
|
106 |
+ |
print "Are you cancelling this task? (y/N): "; |
107 |
+ |
my $response = <STDIN>; |
108 |
+ |
$response =~ s/\n//g; |
109 |
+ |
deleteEntry ($id) if lc ($response) eq "y"; |
110 |
+ |
system ("crab $arg"); |
111 |
+ |
} |
112 |
|
else |
113 |
|
{ |
114 |
|
system ("crab $arg"); |
168 |
|
dbInsert |
169 |
|
{ |
170 |
|
my $dataset = shift; |
171 |
< |
my $user = shift; |
171 |
> |
my $userAndHost = shift; |
172 |
|
my $format = shift; |
173 |
|
my $location = shift; |
174 |
|
my $nFiles = shift; |
178 |
|
my $psetName = shift; |
179 |
|
my $crabCfgName = shift; |
180 |
|
my $jsonFileName = shift; |
181 |
< |
my $submissionLogName = shift; |
181 |
> |
my $workingDir = shift; |
182 |
> |
|
183 |
> |
my $user = $userAndHost; |
184 |
> |
$user =~ s/@.*$//; |
185 |
|
|
186 |
|
open (PY_CONFIG, "<$psetName"); |
187 |
|
my @pset = <PY_CONFIG>; |
195 |
|
my @jsonFile = <JSON_FILE>; |
196 |
|
close (JSON_FILE); |
197 |
|
my $jsonFile = join ("", @jsonFile); |
178 |
– |
open (SUBMISSION_LOG, "<$submissionLogName"); |
179 |
– |
my @submissionLog = <SUBMISSION_LOG>; |
180 |
– |
close (SUBMISSION_LOG); |
181 |
– |
my $submissionLog = join ("", @submissionLog); |
198 |
|
|
199 |
|
$dataset = addSlashes ($dataset); |
200 |
|
$user = addSlashes ($user); |
202 |
|
$pset = addSlashes ($pset); |
203 |
|
$crabCfg = addSlashes ($crabCfg); |
204 |
|
$jsonFile = addSlashes ($jsonFile); |
189 |
– |
$submissionLog = addSlashes ($submissionLog); |
205 |
|
$location = addSlashes ($location); |
206 |
|
$status = addSlashes ($status); |
207 |
|
$comment = addSlashes ($comment); |
214 |
|
my $id = 1; |
215 |
|
$id = $row[0] + 1 if $results->numrows (); |
216 |
|
|
202 |
– |
my $workingDir = $submissionLogName; |
203 |
– |
$workingDir =~ s/(.*)\/log\/crab\.log/$1/; |
217 |
|
open (ID_FILE, ">$workingDir/log/.osuID"); |
218 |
|
print ID_FILE "$id\n"; |
219 |
|
close (ID_FILE); |
220 |
|
|
221 |
< |
$query = "insert into ntuple (id, dataset, creationTime, lastUpdateTime, lastUpdateUser, user, format, location, nFiles, sizeInGB, status, comment, pset, crabCfg, jsonFile, submissionLog) values ($id, '$dataset', now(), now(), '$user', '$user', '$format', '$location', $nFiles, $sizeInGB, '$status', '$comment', '$pset', '$crabCfg', '$jsonFile', '$submissionLog')"; |
221 |
> |
$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')"; |
222 |
|
$results = $db->query ($query); |
223 |
|
|
224 |
|
return $results; |
229 |
|
{ |
230 |
|
my $id = shift; |
231 |
|
my $status = shift; |
219 |
– |
my $submissionLogName = shift; |
232 |
|
my $user = shift; |
233 |
|
|
222 |
– |
open (SUBMISSION_LOG, "<$submissionLogName"); |
223 |
– |
my @submissionLog = <SUBMISSION_LOG>; |
224 |
– |
close (SUBMISSION_LOG); |
225 |
– |
my $submissionLog = join ("", @submissionLog); |
226 |
– |
|
227 |
– |
$submissionLog = addSlashes ($submissionLog); |
234 |
|
$status = addSlashes ($status); |
235 |
|
$user = addSlashes ($user); |
236 |
|
|
237 |
|
my $results; |
238 |
< |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', status='$status', submissionLog='$submissionLog' where id=$id"; |
238 |
> |
my $query = "update ntuple set lastUpdateTime=now(), lastUpdateUser='$user', status='$status' where id=$id"; |
239 |
|
$db->selectdb ("ntuple"); |
240 |
|
$results = $db->query ($query); |
241 |
|
|
287 |
|
$db->selectdb ("ntuple"); |
288 |
|
$results = $db->query ($query); |
289 |
|
|
290 |
+ |
return $results; |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
sub |
294 |
+ |
deleteEntry |
295 |
+ |
{ |
296 |
+ |
my $id = shift; |
297 |
+ |
|
298 |
+ |
my $results; |
299 |
+ |
my $query = "delete from ntuple where id=$id"; |
300 |
+ |
$db->selectdb ("ntuple"); |
301 |
+ |
$results = $db->query ($query); |
302 |
+ |
|
303 |
|
return $results; |
304 |
|
} |