return "$nodename/$service_type:$id";
}
-sub is_on_node {
- my ($class, $haenv, $node, $id) = @_;
-
- my $service_type = $class->type();
- my $hardware = $haenv->hardware();
- my $ss = $hardware->read_service_status($node);
-
- return defined($ss->{"$service_type:$id"}) ? 1 : 0;
-}
-
sub start {
my ($class, $haenv, $id) = @_;
- my $service_type = $class->type();
+ my $sid = $class->type() . ":$id";
my $nodename = $haenv->nodename();
my $hardware = $haenv->hardware();
my $ss = $hardware->read_service_status($nodename);
+ if (my $lock = $hardware->service_has_lock($sid)) {
+ $haenv->log('err', "service '$sid' locked ($lock), unable to start!");
+ return;
+ }
+
$haenv->sleep(2);
- $ss->{"$service_type:$id"} = 1;
+ $ss->{$sid} = 1;
$hardware->write_service_status($nodename, $ss);
sub shutdown {
my ($class, $haenv, $id) = @_;
- my $service_type = $class->type();
+ my $sid = $class->type() . ":$id";
my $nodename = $haenv->nodename();
my $hardware = $haenv->hardware();
my $ss = $hardware->read_service_status($nodename);
+ if (my $lock = $hardware->service_has_lock($sid)) {
+ $haenv->log('err', "service '$sid' locked ($lock), unable to shutdown!");
+ return;
+ }
+
$haenv->sleep(2);
- $ss->{"$service_type:$id"} = 0;
+ $ss->{$sid} = 0;
$hardware->write_service_status($nodename, $ss);
}
my $cmd = $online ? "migrate" : "relocate";
$haenv->log("info", "service $sid - start $cmd to node '$target'");
+ if (my $lock = $hardware->service_has_lock($sid)) {
+ $haenv->log('err', "service '$sid' locked ($lock), unable to $cmd!");
+ return;
+ }
+
# explicitly shutdown if $online isn't true (relocate)
if (!$online && $class->check_running($haenv, $id)) {
$haenv->log("info", "stopping service $sid (relocate)");
$haenv->sleep(2); # (live) migration time
}
- $haenv->change_service_location($sid, $nodename, $target);
+ $hardware->change_service_location($sid, $nodename, $target);
$haenv->log("info", "service $sid - end $cmd to node '$target'");
# ensure that the old node doesn't has the service anymore
delete $ss->{$sid};
$hardware->write_service_status($nodename, $ss);
+
+ # check if resource really moved
+ return defined($ss->{$sid}) ? 0 : 1;
}
+sub remove_locks {
+ my ($self, $haenv, $id, $locks, $service_node) = @_;
+
+ my $sid = $self->type() . ":$id";
+ my $hardware = $haenv->hardware();
+
+ foreach my $lock (@$locks) {
+ if (my $removed_lock = $hardware->unlock_service($sid, $lock)) {
+ return $removed_lock;
+ }
+ }
+
+ return undef;
+}
+
1;