]> err.no Git - varnish/commitdiff
Added possibility to add nodes to a group without have the settings of the group...
authorpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Feb 2009 11:45:30 +0000 (11:45 +0000)
committerpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Feb 2009 11:45:30 +0000 (11:45 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3792 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/webgui/Varnish/NodeManager.pm
varnish-tools/webgui/Varnish/RequestHandler.pm
varnish-tools/webgui/templates/node_management.tmpl

index 1bd315bcdc31f0f6ef32fbe24dd4ba15e98c3ea6..a2cd5d6b9feb483c5a47697f3a69ba8585a3c3a2 100644 (file)
@@ -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);
                        }
                }
index 358c72e7eaac9406892cd73ed938ede5a0af8d61..87d40cd6c7cd88d7cf84e65a8c430fe45c6c8cbf 100644 (file)
@@ -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();
index 056f424b6a07027dcbe5d73767fae422b3fae08e..6356520b2884255afbc51347ca6cdadb2773aa35 100644 (file)
@@ -43,6 +43,9 @@ document.getElementById('group_name').focus();
 <td class="header">Address</td>
 <td class="header">Port</td>
 <td class="header">Management<br/>port</td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td class="header">Inheritance<br/>settings</td>
+</TMPL_IF>
 <td></td></tr>
 <TMPL_LOOP NAME=NODE_INFOS>
 <TMPL_IF NAME=__ODD__>
@@ -88,6 +91,9 @@ value="<TMPL_VAR NAME=ID>">
 <td><input type="text" name="address" value="<TMPL_VAR NAME=ADDRESS>"/></td>
 <td><input type="text" name="port" value="<TMPL_VAR NAME=PORT>" size=5/></td>
 <td><input type="text" name="management_port" value="<TMPL_VAR NAME=MANAGEMENT_PORT>"/></td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td></td>
+</TMPL_IF>
 <td>
 <input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>">
 <input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
@@ -105,6 +111,9 @@ value="<TMPL_VAR NAME=ID>">
 <td><TMPL_VAR NAME=ADDRESS></td>
 <td><TMPL_VAR NAME=PORT></td>
 <td><a href="/management_console?node_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=MANAGEMENT_PORT></a></td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td></td>
+</TMPL_IF>
 <TMPL_UNLESS NAME=RESTRICTED>
 <td>
 <form action="node_management" method="POST">
@@ -154,8 +163,14 @@ value="<TMPL_VAR NAME=ID>">
 <td><input type="text" name="address"/></td>
 <td><input type="text" name="port" size=5/></td>
 <td><input type="text" name="management_port" value="<TMPL_VAR NAME=DEFAULT_MANAGEMENT_PORT>"/></td>
-<TMPL_IF NAME=SHOW_INHERIT_SETTINGS>
-<td colspan=3> <input type="checkbox" name="inherit_settings" value="true" <TMPL_IF NAME=INHERIT_SETTINGS>checked</TMPL_IF>>Group inherit<br/> settings</td>
+<TMPL_IF NAME=SHOW_INHERITANCE_SETTINGS>
+<td> 
+<select name="inheritance">
+<TMPL_LOOP NAME=INHERITANCE_SETTINGS>
+<option value="<TMPL_VAR NAME=VALUE>" <TMPL_IF NAME=SELECTED>selected</TMPL_IF>><TMPL_VAR NAME=NAME></option>
+</TMPL_LOOP>
+</select>
+</td>
 </TMPL_IF>
 <td>
 <input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>"/>