/
Scheduler.pm
202 lines (174 loc) · 5.66 KB
/
Scheduler.pm
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Copyright (C) 2015-2016 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
package OpenQA::Scheduler;
use strict;
use warnings;
use base qw/Net::DBus::Object/;
use Net::DBus::Exporter qw/org.opensuse.openqa.Scheduler/;
use Net::DBus::Reactor;
use Data::Dump qw/pp/;
use OpenQA::IPC;
use OpenQA::Scheduler::FakeApp;
use OpenQA::Scheduler::Scheduler qw//;
use OpenQA::Scheduler::Locks qw//;
use OpenQA::Utils qw/log_debug/;
use OpenQA::ServerStartup;
# monkey patching for debugging IPC
sub _is_method_allowed {
my ($self, $method) = @_;
my $ret = $self->SUPER::_is_method_allowed($method);
if ($ret) {
log_debug "scheduler IPC calling $method";
}
return $ret;
}
our $fakeapp;
sub run {
$fakeapp = OpenQA::Scheduler::FakeApp->new;
OpenQA::ServerStartup::read_config($fakeapp);
OpenQA::ServerStartup::setup_logging($fakeapp);
OpenQA::Scheduler->new();
log_debug("Scheduler started");
Net::DBus::Reactor->main->run;
}
sub new {
my ($class) = @_;
$class = ref $class || $class;
# register @ IPC - we use DBus reactor here for symplicity
my $ipc = OpenQA::IPC->ipc;
return unless $ipc;
my $service = $ipc->register_service('scheduler');
my $self = $class->SUPER::new($service, '/Scheduler');
$self->{ipc} = $ipc;
bless $self, $class;
return $self;
}
# Scheduler ABI goes here
## Assets
dbus_method('asset_delete', [['dict', 'string', 'string']], ['uint32']);
sub asset_delete {
my ($self, $args) = @_;
my $rs = OpenQA::Scheduler::Scheduler::asset_delete(%$args);
return $rs;
}
dbus_method('asset_get', [['dict', 'string', 'string']], [['dict', 'string', 'string']]);
sub asset_get {
my ($self, $args) = @_;
my $rs = OpenQA::Scheduler::Scheduler::asset_get(%$args);
return {} unless $rs && $rs->first;
my %rs = $rs->first->get_columns;
return \%rs;
}
dbus_method('asset_list', [['dict', 'string', 'string']], [['array', ['dict', 'string', 'string']]]);
sub asset_list {
my ($self, $args) = @_;
my $rs = OpenQA::Scheduler::Scheduler::asset_list(%$args);
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
return [$rs->all];
}
dbus_method('asset_register', [['dict', 'string', 'string']], ['uint32']);
sub asset_register {
my ($self, $args) = @_;
my $rs = OpenQA::Scheduler::Scheduler::asset_register(%$args);
return 0 unless $rs;
return $rs->id;
}
## Jobs
dbus_method('job_duplicate', [['dict', 'string', 'string']], ['uint32']);
sub job_duplicate {
my ($self, $args) = @_;
my $res = OpenQA::Scheduler::Scheduler::job_duplicate(%$args);
return 0 unless $res;
return $res;
}
dbus_method('job_grab', [['dict', 'string', ['variant']]], [['dict', 'string', ['variant']]]);
sub job_grab {
my ($self, $args) = @_;
return OpenQA::Scheduler::Scheduler::job_grab(%$args);
}
dbus_method('job_notify_workers');
sub job_notify_workers {
my ($self) = @_;
OpenQA::Scheduler::Scheduler::job_notify_workers;
}
dbus_method('job_restart', [['array', 'uint32']], [['array', 'uint32']]);
sub job_restart {
my ($self, $args) = @_;
my @res = OpenQA::Scheduler::Scheduler::job_restart($args);
return \@res;
}
dbus_method('job_update_status', ['uint32', ['dict', 'string', ['variant']]], ['uint32']);
sub job_update_status {
my ($self, $jobid, $status) = @_;
}
dbus_method('job_set_waiting', ['uint32'], ['uint32']);
sub job_set_waiting {
my ($self, $args) = @_;
return OpenQA::Scheduler::Scheduler::job_set_waiting($args);
}
dbus_method('job_set_running', ['uint32'], ['uint32']);
sub job_set_running {
my ($self, $args) = @_;
return OpenQA::Scheduler::Scheduler::job_set_running($args);
}
## Worker auth
dbus_method('validate_workerid', ['uint32'], ['bool']);
sub validate_workerid {
my ($self, $args) = @_;
my $res = OpenQA::Scheduler::Scheduler::_validate_workerid($args);
return 1 if ($res);
return 0;
}
## Lock API
dbus_method('mutex_create', ['string', 'uint32'], ['bool']);
sub mutex_create {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::create(@args);
return 0 unless $res;
return 1;
}
dbus_method('mutex_lock', ['string', 'uint32', 'string'], ['int32']);
sub mutex_lock {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::lock(@args);
return $res;
}
dbus_method('mutex_unlock', ['string', 'uint32'], ['int32']);
sub mutex_unlock {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::unlock(@args);
return $res;
}
dbus_method('barrier_create', ['string', 'uint32', 'uint32'], ['bool']);
sub barrier_create {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::barrier_create(@args);
return 0 unless $res;
return 1;
}
dbus_method('barrier_wait', ['string', 'uint32', 'string'], ['int32']);
sub barrier_wait {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::barrier_wait(@args);
return $res;
}
dbus_method('barrier_destroy', ['string', 'uint32', 'string'], ['bool']);
sub barrier_destroy {
my ($self, @args) = @_;
my $res = OpenQA::Scheduler::Locks::barrier_destroy(@args);
return 0 unless $res;
return 1;
}
1;