line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTCondor::Queue::Parser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
42666
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
131398
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use JSON::XS; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: parses multible schedds condor_q output, so you don't have to. Serves output in many formats. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my $class = shift; |
12
|
|
|
|
|
|
|
my $self = bless { @_ }, $class; |
13
|
|
|
|
|
|
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %schedds_map; |
17
|
|
|
|
|
|
|
my $schedd; |
18
|
|
|
|
|
|
|
my @submitter_xml; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub load_schedds_xml { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
my $condor_q = shift; |
23
|
|
|
|
|
|
|
my @text = @{$condor_q}; |
24
|
|
|
|
|
|
|
my %schedds_map; |
25
|
|
|
|
|
|
|
my $schedd; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
die("Got no input. Check condor_q -xml output") if (scalar(@text) < 1); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
foreach my $line (@text) { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ($line =~ m/^--.*Schedd\:(.*)\s\:(.*)/) { |
33
|
|
|
|
|
|
|
# $2 is useful but not used -- IP |
34
|
|
|
|
|
|
|
$schedd = $1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
if ($line =~ m/\/) { |
37
|
|
|
|
|
|
|
# New scheed, record previous in the map and reset everything |
38
|
|
|
|
|
|
|
$schedds_map{$schedd}{'xml'} = \@submitter_xml; |
39
|
|
|
|
|
|
|
@submitter_xml = (); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
push(@submitter_xml, $line); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
return %schedds_map; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub convert_to_compatible_xml { |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
my $schedds_map_href = shift; |
48
|
|
|
|
|
|
|
my %schedds_map = %{$schedds_map_href}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
foreach my $schedd (keys %schedds_map) { |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
die("There's no XML in the provided schedds_map , verify") if not $schedds_map{$schedd}{'xml'}; |
53
|
|
|
|
|
|
|
my @real_xml=(); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
foreach my $line (@{$schedds_map{$schedd}{'xml'}}) { |
56
|
|
|
|
|
|
|
chomp $line; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# Machine |
60
|
|
|
|
|
|
|
if ( $line =~ m/\\<.*\>(.*)\<.*\>\<\/a\>/ ) { |
61
|
|
|
|
|
|
|
push(@real_xml, "<$1> $2 $1>" ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($line =~ m/\\\<\/a\>/) { |
64
|
|
|
|
|
|
|
push(@real_xml, "<$1> $2 $1>" ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
|
|
|
|
|
|
push (@real_xml, $line); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$schedds_map{$schedd}{'xml'} = \@real_xml; |
72
|
|
|
|
|
|
|
# Check if there's any big difference on using the |
73
|
|
|
|
|
|
|
# Below or not, and how compatible it is with the API |
74
|
|
|
|
|
|
|
# my $job_data = XMLin($xml); |
75
|
|
|
|
|
|
|
# $self->{'schedds_map'}{$schedd}{'href'} = $job_data; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
return %schedds_map; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub xml_to_hrefs{ |
81
|
|
|
|
|
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
my $schedds_map_href = shift; |
83
|
|
|
|
|
|
|
my %schedds_map = %{$schedds_map_href}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
foreach my $schedd (keys %schedds_map) { |
86
|
|
|
|
|
|
|
die ('Provide an xml in %schedds_map{$schedd}{xml} ') if not defined $schedds_map{$schedd}{'xml'} ; |
87
|
|
|
|
|
|
|
my $xml = "@{$schedds_map{$schedd}{'xml'}}"; |
88
|
|
|
|
|
|
|
my $job_data = XMLin($xml); |
89
|
|
|
|
|
|
|
$schedds_map{$schedd}{'href'} = $job_data; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
return %schedds_map; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub schedd_json { |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
my $schedds_map_href = shift; |
97
|
|
|
|
|
|
|
my $schedd = shift; |
98
|
|
|
|
|
|
|
my %schedds_map = %{$schedds_map_href}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
die("Which schedd?") if not $schedd; |
101
|
|
|
|
|
|
|
die('Come on, ask me something that exists, populate $schedds_map{$schedd}') if not $schedds_map{$schedd}{'href'}; |
102
|
|
|
|
|
|
|
my $coder = JSON::XS->new->ascii->pretty->allow_nonref; |
103
|
|
|
|
|
|
|
my $json = $coder->encode($schedds_map{$schedd}{'href'}); |
104
|
|
|
|
|
|
|
return $json; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |