[pve-devel] [PATCH ha-manager v4 4/4] refactor select_service_method

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jul 18 11:17:50 CEST 2016


factor out the default group generation and the priority group
generation.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes since v3:
* new in this version

 src/PVE/HA/Manager.pm | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index 6f6fdab..439a750 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -70,8 +70,8 @@ sub flush_master_status {
     $haenv->write_manager_status($ms);
 } 
 
-sub select_service_node {
-    my ($groups, $online_node_usage, $service_conf, $current_node, $try_next, $tried_nodes) = @_;
+sub get_service_group {
+    my ($groups, $online_node_usage, $service_conf) = @_;
 
     my $group = {};
     # add all online nodes to default group to allow try_next when no group set
@@ -83,6 +83,13 @@ sub select_service_node {
     $group =  $groups->{ids}->{$service_conf->{group}} if $service_conf->{group} && 
 	$groups->{ids}->{$service_conf->{group}};
 
+    return $group;
+}
+
+# groups available nodes with their priority as group index
+sub get_node_priority_groups {
+    my ($group, $online_node_usage) = @_;
+
     my $pri_groups = {};
     my $group_members = {};
     foreach my $entry (keys %{$group->{nodes}}) {
@@ -95,7 +102,6 @@ sub select_service_node {
 	$group_members->{$node} = $pri;
     }
 
-    
     # add non-group members to unrestricted groups (priority -1)
     if (!$group->{restricted}) {
 	my $pri = -1;
@@ -106,6 +112,16 @@ sub select_service_node {
 	}
     }
 
+    return ($pri_groups, $group_members);
+}
+
+sub select_service_node {
+    my ($groups, $online_node_usage, $service_conf, $current_node, $try_next, $tried_nodes) = @_;
+
+    my $group = get_service_group($groups, $online_node_usage, $service_conf);
+
+    my ($pri_groups, $group_members) = get_node_priority_groups($group, $online_node_usage);
+
     my @pri_list = sort {$b <=> $a} keys %$pri_groups;
     return undef if !scalar(@pri_list);
 
-- 
2.1.4





More information about the pve-devel mailing list