From 75eba31f21267a5cf0115ae56ecf4a6e5e4c81df Mon Sep 17 00:00:00 2001 From: petter Date: Fri, 20 Feb 2009 11:45:30 +0000 Subject: [PATCH] Added possibility to add nodes to a group without have the settings of the group or node altered, which can be usefull to group node logically if the web GUI is used as a monitoring tool. Also fixed a logical bug in the settings inheritance code. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3792 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-tools/webgui/Varnish/NodeManager.pm | 26 ++++++----- .../webgui/Varnish/RequestHandler.pm | 45 ++++++++++++++----- .../webgui/templates/node_management.tmpl | 19 +++++++- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/varnish-tools/webgui/Varnish/NodeManager.pm b/varnish-tools/webgui/Varnish/NodeManager.pm index 1bd315bc..a2cd5d6b 100644 --- a/varnish-tools/webgui/Varnish/NodeManager.pm +++ b/varnish-tools/webgui/Varnish/NodeManager.pm @@ -21,12 +21,14 @@ use List::Util qw(first); $vcl_info->{'vcl'} = $master->get_vcl($name); } - my $previous_active_vcl; + my $slave_active_vcl = ""; + my $discard_slave_active_vcl = 0; my $vcl_infos_ref = $slave->get_vcl_infos(); for my $vcl_info (@$vcl_infos_ref) { my $name = $vcl_info->{'name'}; if ($vcl_info->{'active'}) { - $previous_active_vcl = $name; + $slave_active_vcl = $name; + $discard_slave_active_vcl = 1; } else { $slave->discard_vcl($name); @@ -39,16 +41,20 @@ use List::Util qw(first); $slave->save_vcl($name, $vcl); if ($vcl_info->{'active'}) { $slave->make_vcl_active($name); - if ($previous_active_vcl) { - $slave->discard_vcl($previous_active_vcl); - } + } + if ($slave_active_vcl eq $name) { + $discard_slave_active_vcl = 0; } } + if ($discard_slave_active_vcl) { + $slave->discard_vcl($slave_active_vcl); + } } - + sub add_node { - my ($self, $node, $use_as_group_defaults) = @_; + my ($self, $node, $inheritance) = @_; + $inheritance ||= 0; my $management = $node->get_management(); if (!$management->ping()) { return set_error($self, "Could not connect to management port: " @@ -57,12 +63,12 @@ use List::Util qw(first); Varnish::DB->add_node($node); my $group_id = $node->get_group_id(); - if ($group_id > 0) { + if ($group_id > 0 && $inheritance) { my $group = get_group($self, $group_id); - if ($use_as_group_defaults) { + if ($inheritance == 1) { _clone_unit($node, $group); } - else { + elsif ($inheritance == 2) { _clone_unit($group, $node); } } diff --git a/varnish-tools/webgui/Varnish/RequestHandler.pm b/varnish-tools/webgui/Varnish/RequestHandler.pm index 358c72e7..87d40cd6 100644 --- a/varnish-tools/webgui/Varnish/RequestHandler.pm +++ b/varnish-tools/webgui/Varnish/RequestHandler.pm @@ -743,7 +743,7 @@ FIND_ACTIVE_VCL: $param{'address'} = $$parameter_ref{'address'} || ""; $param{'port'} ||= ""; $param{'management_port'} ||= ""; - $param{'inherit_settings'} ||= ""; + $param{'inheritance'} ||= 0; $param{'edit_node'} ||= -1; my $template = "node_management.tmpl"; @@ -760,8 +760,8 @@ FIND_ACTIVE_VCL: $tmpl_var{'show_group'} = 0; $tmpl_var{'show_add_node'} = 1; $tmpl_var{'show_node_in_backend_health'} = 1; - $tmpl_var{'inherit_settings'} = 0; - $tmpl_var{'show_inherit_settings'} = 1; + $tmpl_var{'show_inheritance_settings'} = 1; + $tmpl_var{'inheritance_settings'} = []; my $error = ""; my $status = ""; @@ -833,18 +833,21 @@ FIND_ACTIVE_VCL: group_id => $param{'group_id'}, management_port => $param{'management_port'} }); - my $inherit_settings = $param{'inherit_settings'} ne ""; - Varnish::NodeManager->add_node($node, $inherit_settings); + Varnish::NodeManager->add_node($node, $param{'inheritance'}); $status .= "Node " . $node->get_name() . " added successfully."; my $group = Varnish::NodeManager->get_group($param{'group_id'}); my $group_name = ($group ? $group->get_name() : ""); + my $inheritance = ($param{'inheritance'} == 0 ? "None" : + $param{'inheritance'} == 1 ? "Group inherited node" : + "Node inherited group"); log_info("[" . $node->get_name() . "] [Added node]" . " [name=" . $node->get_name() . "]" . " [address=" . $node->get_address() . "]" . " [port=" . $node->get_port() . "]" . " [group=" . $group_name . "]" - . " [management_port=" . $node->get_management_port() . "]"); + . " [management_port=" . $node->get_management_port() . "]" + . " [settings_inheritance=$inheritance]"); } else { $error .= "Not enough information to add node:\n"; @@ -955,9 +958,6 @@ FIND_ACTIVE_VCL: if ($tmpl_var{'group_id'} != -1) { $group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); $nodes_ref = Varnish::NodeManager->get_nodes($group); - if ($tmpl_var{'group_id'} == 0) { - $tmpl_var{'show_inherit_settings'} = 0; - } } else { $nodes_ref = Varnish::NodeManager->get_nodes(); @@ -989,14 +989,35 @@ FIND_ACTIVE_VCL: } push @{$tmpl_var{'node_infos'}}, $node_info_ref; } - if (@$nodes_ref == 0) { - $tmpl_var{'inherit_settings'} = 1; - } } else { $tmpl_var{'add_group'} = 1; } + if ($tmpl_var{'group_id'} > 0) { + my @inheritance_settings; + push @inheritance_settings, { + value => 2, + name => "Node inherits group", + selected => @{$tmpl_var{'node_infos'}} > 0, + }; + push @inheritance_settings, { + value => 1, + name => "Group inherits node", + selected => @{$tmpl_var{'node_infos'}} == 0, + }; + push @inheritance_settings, { + value => 0, + name => "No inheritance", + selected => 0, + }; + $tmpl_var{'inheritance_settings'} = \@inheritance_settings; + } + else { + $tmpl_var{'show_inheritance_settings'} = 0; + } + + my $selected_group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); if ($selected_group) { $tmpl_var{'group_name'} = $selected_group->get_name(); diff --git a/varnish-tools/webgui/templates/node_management.tmpl b/varnish-tools/webgui/templates/node_management.tmpl index 056f424b..6356520b 100644 --- a/varnish-tools/webgui/templates/node_management.tmpl +++ b/varnish-tools/webgui/templates/node_management.tmpl @@ -43,6 +43,9 @@ document.getElementById('group_name').focus(); Address Port Management
port + +Inheritance
settings +
@@ -88,6 +91,9 @@ value=""> + + + @@ -105,6 +111,9 @@ value=""> + + +
@@ -154,8 +163,14 @@ value=""> - - checked>Group inherit
settings + + + + -- 2.39.5