-
Notifications
You must be signed in to change notification settings - Fork 0
/
condor_plugin.pl
76 lines (62 loc) · 1.98 KB
/
condor_plugin.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Storable::CouchDB;
use Condor::QueueParser;
open(FH, '<input.txt');
my @condor_q = <FH>;
close(FH);
sub main {
my %schedds_map;
my $condor_parser = Condor::QueueParser->new();
%schedds_map = $condor_parser->load_schedds_xml(\@condor_q);
%schedds_map = $condor_parser->convert_to_compatible_xml(\%schedds_map);
%schedds_map = $condor_parser->xml_to_hrefs(\%schedds_map);
add_generic_fields(\%schedds_map);
populate_couch(\%schedds_map);
}
sub add_generic_fields {
my $schedds_map_href = shift;
my %schedds_map = %{$schedds_map_href};
my %condor_state_map = {
'0' => 'unexpanded' ,
'1' => 'idle' ,
'2' => 'running' ,
'3' => 'removed' ,
'4' => 'completed' ,
'5' => 'held' ,
'6' => 'submission_err'
};
foreach my $schedd (keys %schedds_map) {
foreach my $job (@{$schedds_map{$schedd}{'href'}{'c'}}) {
# Make assignment of specific to generic job attributes
# Those have to be : submit_time, local_user, dn, status
$job->{'dn'} = $job->{'x509userproxysubject'};
# my $user = split('@', $job{'User'}{'s'});
# $job{'local_user'} = $user[0];
$job->{'status'} = $condor_state_map{$job->{'JobStatus'}};
# $job{'status'} = ;
}
}
}
#upload what we got to couch :
# THIS IS THE INSERT METHOD!!
sub populate_couch {
my $schedds_map_href = shift;
my %schedds_map = %{$schedds_map_href};
my $couch = Storable::CouchDB->new('uri' => 'http://samircury.iriscouch.com', 'db' => 'teste6' );
foreach my $schedd (keys %schedds_map) {
foreach my $job (@{$schedds_map{$schedd}{'href'}{'c'}}) {
my $global_jobid = $job->{'GlobalJobId'};
if (not $global_jobid) {
warn("Couldnt find a job name for a job in schedd $schedd");
next;
}
my $answer = $couch->store($global_jobid , $job) ;
#check if the insertion was fine, die if not?
}
}
}
# WE SHOULD CHECK WHETER THERE WAS AN ENTEREDCURRENTSTATUS LOWER AND UPDATE IT IF NOT
main();