]> git.proxmox.com Git - pve-ha-manager.git/blob - src/PVE/HA/Env.pm
CRM: release lock on shutdown request
[pve-ha-manager.git] / src / PVE / HA / Env.pm
1 package PVE::HA::Env;
2
3 use strict;
4 use warnings;
5
6 use PVE::SafeSyslog;
7 use PVE::Tools;
8
9 # abstract out the cluster environment for a single node
10
11 sub new {
12 my ($this, $baseclass, $node, @args) = @_;
13
14 my $class = ref($this) || $this;
15
16 my $plug = $baseclass->new($node, @args);
17
18 my $self = bless { plug => $plug }, $class;
19
20 return $self;
21 }
22
23 sub nodename {
24 my ($self) = @_;
25
26 return $self->{plug}->nodename();
27 }
28
29 # manager status is stored on cluster, protected by ha_manager_lock
30 sub read_manager_status {
31 my ($self) = @_;
32
33 return $self->{plug}->read_manager_status();
34 }
35
36 sub write_manager_status {
37 my ($self, $status_obj) = @_;
38
39 return $self->{plug}->write_manager_status($status_obj);
40 }
41
42 # lrm status is written by LRM, protected by ha_agent_lock,
43 # but can be read by any node (CRM)
44
45 sub read_lrm_status {
46 my ($self, $node) = @_;
47
48 return $self->{plug}->read_lrm_status($node);
49 }
50
51 sub write_lrm_status {
52 my ($self, $status_obj) = @_;
53
54 return $self->{plug}->write_lrm_status($status_obj);
55 }
56
57 # check if we do node shutdown
58 # we used this to decide if services should be stopped or freezed
59 sub is_node_shutdown {
60 my ($self) = @_;
61
62 return $self->{plug}->is_node_shutdown();
63 }
64
65 # implement a way to send commands to the CRM master
66 sub queue_crm_commands {
67 my ($self, $cmd) = @_;
68
69 return $self->{plug}->queue_crm_commands($cmd);
70 }
71
72 sub read_crm_commands {
73 my ($self) = @_;
74
75 return $self->{plug}->read_crm_commands();
76 }
77
78 sub service_config_exists {
79 my ($self) = @_;
80
81 return $self->{plug}->service_config_exists();
82 }
83
84 sub read_service_config {
85 my ($self) = @_;
86
87 return $self->{plug}->read_service_config();
88 }
89
90 sub change_service_location {
91 my ($self, $sid, $current_node, $new_node) = @_;
92
93 return $self->{plug}->change_service_location($sid, $current_node, $new_node);
94 }
95
96 sub read_group_config {
97 my ($self) = @_;
98
99 return $self->{plug}->read_group_config();
100 }
101
102 # this should return a hash containing info
103 # what nodes are members and online.
104 sub get_node_info {
105 my ($self) = @_;
106
107 return $self->{plug}->get_node_info();
108 }
109
110 sub log {
111 my ($self, $level, @args) = @_;
112
113 return $self->{plug}->log($level, @args);
114 }
115
116 # acquire a cluster wide manager lock
117 sub get_ha_manager_lock {
118 my ($self) = @_;
119
120 return $self->{plug}->get_ha_manager_lock();
121 }
122
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
132 # acquire a cluster wide node agent lock
133 sub get_ha_agent_lock {
134 my ($self, $node) = @_;
135
136 return $self->{plug}->get_ha_agent_lock($node);
137 }
138
139 # return true when cluster is quorate
140 sub quorate {
141 my ($self) = @_;
142
143 return $self->{plug}->quorate();
144 }
145
146 # return current time
147 # overwrite that if you want to simulate
148 sub get_time {
149 my ($self) = @_;
150
151 return $self->{plug}->get_time();
152 }
153
154 sub sleep {
155 my ($self, $delay) = @_;
156
157 return $self->{plug}->sleep($delay);
158 }
159
160 sub sleep_until {
161 my ($self, $end_time) = @_;
162
163 return $self->{plug}->sleep_until($end_time);
164 }
165
166 sub loop_start_hook {
167 my ($self, @args) = @_;
168
169 return $self->{plug}->loop_start_hook(@args);
170 }
171
172 sub loop_end_hook {
173 my ($self, @args) = @_;
174
175 return $self->{plug}->loop_end_hook(@args);
176 }
177
178 sub watchdog_open {
179 my ($self) = @_;
180
181 # Note: when using /dev/watchdog, make sure perl does not close
182 # the handle automatically at exit!!
183
184 return $self->{plug}->watchdog_open();
185 }
186
187 sub watchdog_update {
188 my ($self, $wfh) = @_;
189
190 return $self->{plug}->watchdog_update($wfh);
191 }
192
193 sub watchdog_close {
194 my ($self, $wfh) = @_;
195
196 return $self->{plug}->watchdog_close($wfh);
197 }
198
199 sub exec_resource_agent {
200 my ($self, $sid, $service_config, $cmd, @params) = @_;
201
202 return $self->{plug}->exec_resource_agent($sid, $service_config, $cmd, @params)
203 }
204
205 # hack to support regression tests
206 sub can_fork {
207 my ($self) = @_;
208
209 return $self->{plug}->can_fork();
210 }
211
212 1;