[pve-devel] [PATCH ha-manager 04/10] Status: factor out new service state calculation

Dietmar Maurer dietmar at proxmox.com
Thu Dec 22 10:08:41 CET 2016


I agree that it is worth to factor out code to compute the service state,
but this method returns much more than that. What for? IMHO this
is not really required and confusing..

> +sub get_current_service_state {
> +    my ($sid, $sc, $ss) = @_;
> +
> +    my $data = { id => "service:$sid", type => 'service', sid => $sid };
> +
> +    if ($ss) {
> +	my $req = $sc->{state} || 'ignore';
> +	my $cur = $ss->{state};
> +	my $state = $cur;
> +
> +	# give fast feedback to the user
> +	if ($cur eq 'stopped') {
> +	    if ($req eq 'started') {
> +		$state = 'starting';
> +	    } elsif ($req eq 'disabled') {
> +		$state = 'disabled';
> +	    }
> +	} elsif ($cur eq 'started') {
> +	    if ($req eq 'stopped' || $req eq 'disabled') {
> +		$state = 'stopping';
> +	    }
> +	    $state = 'starting' if !$ss->{running};
> +	} elsif ($cur eq 'error') {
> +	    if ($req eq 'disabled') {
> +		$state = 'clearing error flag';
> +	    }
> +	}
> +
> +	$data->{node} = $ss->{node};
> +	$data->{status} =  "$sid ($ss->{node}, $state)"; # backward compatibility
> +	$data->{state} = $state;
> +	$data->{crm_state} = $ss->{state};
> +    } else {
> +	$data->{node} = $sc->{node};
> +	$data->{state} = 'queued';
> +	$data->{status} = "$sid ($sc->{node}, queued)"; # backward compatibility
> +    }
> +
> +    # also return common resource attributes
> +    if (defined($sc)) {
> +	$data->{request_state} = $sc->{state};
> +	foreach my $key (qw(group max_restart max_relocate comment)) {
> +	    $data->{$key} = $sc->{$key} if defined($sc->{$key});
> +	}
> +    }
> +
> +    return $data;
> +}
> +




More information about the pve-devel mailing list