]>
Commit | Line | Data |
---|---|---|
95ca6580 DM |
1 | package PVE::HA::Env; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::SafeSyslog; | |
158bd429 | 7 | use PVE::Tools; |
95ca6580 | 8 | |
498246b9 | 9 | # abstract out the cluster environment for a single node |
95ca6580 DM |
10 | |
11 | sub new { | |
3c36cbca | 12 | my ($this, $baseclass, $node, @args) = @_; |
95ca6580 DM |
13 | |
14 | my $class = ref($this) || $this; | |
15 | ||
3c36cbca DM |
16 | my $plug = $baseclass->new($node, @args); |
17 | ||
18 | my $self = bless { plug => $plug }, $class; | |
95ca6580 DM |
19 | |
20 | return $self; | |
21 | } | |
22 | ||
7e0a7262 DM |
23 | sub nodename { |
24 | my ($self) = @_; | |
25 | ||
3c36cbca | 26 | return $self->{plug}->nodename(); |
7e0a7262 DM |
27 | } |
28 | ||
dd9c0c9d TL |
29 | sub hardware { |
30 | my ($self) = @_; | |
31 | ||
32 | return $self->{plug}->hardware(); | |
33 | } | |
34 | ||
158bd429 DM |
35 | # manager status is stored on cluster, protected by ha_manager_lock |
36 | sub read_manager_status { | |
37 | my ($self) = @_; | |
38 | ||
3c36cbca | 39 | return $self->{plug}->read_manager_status(); |
158bd429 DM |
40 | } |
41 | ||
42 | sub write_manager_status { | |
43 | my ($self, $status_obj) = @_; | |
44 | ||
3c36cbca | 45 | return $self->{plug}->write_manager_status($status_obj); |
158bd429 DM |
46 | } |
47 | ||
c4a221bc DM |
48 | # lrm status is written by LRM, protected by ha_agent_lock, |
49 | # but can be read by any node (CRM) | |
50 | ||
51 | sub read_lrm_status { | |
52 | my ($self, $node) = @_; | |
53 | ||
54 | return $self->{plug}->read_lrm_status($node); | |
55 | } | |
56 | ||
57 | sub write_lrm_status { | |
58 | my ($self, $status_obj) = @_; | |
59 | ||
60 | return $self->{plug}->write_lrm_status($status_obj); | |
61 | } | |
62 | ||
cde77779 DM |
63 | # check if we do node shutdown |
64 | # we used this to decide if services should be stopped or freezed | |
65 | sub is_node_shutdown { | |
d42219a3 TL |
66 | my ($self) = @_; |
67 | ||
cde77779 | 68 | return $self->{plug}->is_node_shutdown(); |
d42219a3 TL |
69 | } |
70 | ||
3b996922 DM |
71 | # implement a way to send commands to the CRM master |
72 | sub queue_crm_commands { | |
73 | my ($self, $cmd) = @_; | |
74 | ||
75 | return $self->{plug}->queue_crm_commands($cmd); | |
76 | } | |
77 | ||
78 | sub read_crm_commands { | |
79 | my ($self) = @_; | |
80 | ||
81 | return $self->{plug}->read_crm_commands(); | |
82 | } | |
83 | ||
f7ccd1b3 DM |
84 | sub read_service_config { |
85 | my ($self) = @_; | |
86 | ||
3c36cbca | 87 | return $self->{plug}->read_service_config(); |
f7ccd1b3 DM |
88 | } |
89 | ||
8456bde2 | 90 | sub change_service_location { |
6da27e23 | 91 | my ($self, $sid, $current_node, $new_node) = @_; |
8456bde2 | 92 | |
6da27e23 | 93 | return $self->{plug}->change_service_location($sid, $current_node, $new_node); |
8456bde2 DM |
94 | } |
95 | ||
abc920b4 DM |
96 | sub read_group_config { |
97 | my ($self) = @_; | |
98 | ||
99 | return $self->{plug}->read_group_config(); | |
100 | } | |
101 | ||
91dab9ce DM |
102 | # this should return a hash containing info |
103 | # what nodes are members and online. | |
104 | sub get_node_info { | |
105 | my ($self) = @_; | |
106 | ||
3c36cbca | 107 | return $self->{plug}->get_node_info(); |
91dab9ce DM |
108 | } |
109 | ||
95ca6580 | 110 | sub log { |
f25a336a | 111 | my ($self, $level, @args) = @_; |
95ca6580 | 112 | |
3c36cbca | 113 | return $self->{plug}->log($level, @args); |
95ca6580 DM |
114 | } |
115 | ||
63f6a08c | 116 | # acquire a cluster wide manager lock |
95ca6580 DM |
117 | sub get_ha_manager_lock { |
118 | my ($self) = @_; | |
119 | ||
3c36cbca DM |
120 | return $self->{plug}->get_ha_manager_lock(); |
121 | } | |
122 | ||
de002253 TL |
123 | # release the cluster wide manager lock. |
124 | # when released another CRM may step up and get the lock, thus this should only | |
125 | # get called when shutting down/deactivating the current master | |
126 | sub release_ha_manager_lock { | |
127 | my ($self) = @_; | |
128 | ||
129 | return $self->{plug}->release_ha_manager_lock(); | |
130 | } | |
131 | ||
63f6a08c | 132 | # acquire a cluster wide node agent lock |
3c36cbca | 133 | sub get_ha_agent_lock { |
3c36cbca DM |
134 | my ($self, $node) = @_; |
135 | ||
f5c29173 | 136 | return $self->{plug}->get_ha_agent_lock($node); |
95ca6580 DM |
137 | } |
138 | ||
ff165cd8 TL |
139 | # release the respective node agent lock. |
140 | # this should only get called if the nodes LRM gracefully shuts down with | |
141 | # all services already cleanly stopped! | |
142 | sub release_ha_agent_lock { | |
143 | my ($self) = @_; | |
144 | ||
145 | return $self->{plug}->release_ha_agent_lock(); | |
146 | } | |
147 | ||
0d00a7da DM |
148 | # return true when cluster is quorate |
149 | sub quorate { | |
150 | my ($self) = @_; | |
151 | ||
3c36cbca | 152 | return $self->{plug}->quorate(); |
0d00a7da DM |
153 | } |
154 | ||
95ca6580 DM |
155 | # return current time |
156 | # overwrite that if you want to simulate | |
157 | sub get_time { | |
158 | my ($self) = @_; | |
159 | ||
3c36cbca | 160 | return $self->{plug}->get_time(); |
95ca6580 DM |
161 | } |
162 | ||
163 | sub sleep { | |
164 | my ($self, $delay) = @_; | |
165 | ||
3c36cbca | 166 | return $self->{plug}->sleep($delay); |
95ca6580 DM |
167 | } |
168 | ||
f25a336a DM |
169 | sub sleep_until { |
170 | my ($self, $end_time) = @_; | |
171 | ||
3c36cbca | 172 | return $self->{plug}->sleep_until($end_time); |
f25a336a DM |
173 | } |
174 | ||
95ca6580 | 175 | sub loop_start_hook { |
3c36cbca | 176 | my ($self, @args) = @_; |
95ca6580 | 177 | |
3c36cbca | 178 | return $self->{plug}->loop_start_hook(@args); |
95ca6580 DM |
179 | } |
180 | ||
181 | sub loop_end_hook { | |
3c36cbca DM |
182 | my ($self, @args) = @_; |
183 | ||
184 | return $self->{plug}->loop_end_hook(@args); | |
95ca6580 DM |
185 | } |
186 | ||
9329c1e2 DM |
187 | sub watchdog_open { |
188 | my ($self) = @_; | |
189 | ||
b6044542 DM |
190 | # Note: when using /dev/watchdog, make sure perl does not close |
191 | # the handle automatically at exit!! | |
192 | ||
9329c1e2 DM |
193 | return $self->{plug}->watchdog_open(); |
194 | } | |
195 | ||
196 | sub watchdog_update { | |
197 | my ($self, $wfh) = @_; | |
198 | ||
199 | return $self->{plug}->watchdog_update($wfh); | |
200 | } | |
201 | ||
202 | sub watchdog_close { | |
203 | my ($self, $wfh) = @_; | |
204 | ||
205 | return $self->{plug}->watchdog_close($wfh); | |
206 | } | |
207 | ||
a28fa330 | 208 | sub after_fork { |
0d1d32fb DM |
209 | my ($self) = @_; |
210 | ||
a28fa330 | 211 | return $self->{plug}->after_fork(); |
0d1d32fb DM |
212 | } |
213 | ||
a28fa330 TL |
214 | # maximal number of workers to fork, |
215 | # return 0 as a hack to support regression tests | |
216 | sub get_max_workers { | |
a2aae08a TL |
217 | my ($self) = @_; |
218 | ||
a28fa330 | 219 | return $self->{plug}->get_max_workers(); |
a2aae08a TL |
220 | } |
221 | ||
95ca6580 | 222 | 1; |