Changeset 824
- Timestamp:
- 09/25/09 08:08:32 (2 months ago)
- Location:
- trunk/lib
- Files:
-
- 4 modified
-
Perlbal.pm (modified) (1 diff)
-
Perlbal/Plugin/Vhosts.pm (modified) (1 diff)
-
Perlbal/Pool.pm (modified) (1 diff)
-
Perlbal/Service.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Perlbal.pm
r812 r824 975 975 } 976 976 977 sub MANAGE_dumpconfig { 978 my $mc = shift; 979 980 while (my ($name, $pool) = each %pool) { 981 $mc->out("CREATE POOL $name"); 982 983 if ($pool->can("dumpconfig")) { 984 foreach my $line ($pool->dumpconfig) { 985 $mc->out(" $line"); 986 } 987 } else { 988 my $class = ref($pool); 989 $mc->out(" # Pool class '$class' is unable to dump config."); 990 } 991 } continue { 992 $mc->out(""); 993 } 994 995 while (my ($name, $service) = each %service) { 996 $mc->out("CREATE SERVICE $name"); 997 998 if ($service->can("dumpconfig")) { 999 foreach my $line ($service->dumpconfig) { 1000 $mc->out(" $line"); 1001 } 1002 } else { 1003 my $class = ref($service); 1004 $mc->out(" # Service class '$class' is unable to dump config."); 1005 } 1006 1007 my $state = $service->{enabled} ? "ENABLE" : "DISABLE"; 1008 $mc->out("$state $name"); 1009 } continue { 1010 $mc->out(""); 1011 } 1012 1013 return $mc->ok 1014 } 1015 977 1016 sub MANAGE_reproxy_state { 978 1017 my $mc = shift; -
trunk/lib/Perlbal/Plugin/Vhosts.pm
r801 r824 74 74 delete $Services{"$svc"}; 75 75 return 1; 76 } 77 78 sub dumpconfig { 79 my ($class, $svc) = @_; 80 81 my $vhosts = $svc->{extra_config}->{_vhosts}; 82 83 return unless $vhosts; 84 85 my @return; 86 87 while (my ($vhost, $target) = each %$vhosts) { 88 push @return, "VHOST $vhost = $target"; 89 } 90 91 return @return; 76 92 } 77 93 -
trunk/lib/Perlbal/Pool.pm
r759 r824 95 95 } 96 96 97 sub dumpconfig { 98 my Perlbal::Pool $self = shift; 99 my $name = $self->{name}; 100 101 my @return; 102 103 if (my $nodefile = $self->{'nodefile'}) { 104 push @return, "SET nodefile = $nodefile"; 105 } else { 106 foreach my $node (@{$self->{nodes}}) { 107 my ($ip, $port) = @$node; 108 push @return, "POOL ADD $name $ip:$port"; 109 } 110 } 111 return @return; 112 } 113 97 114 # returns string of balance method 98 115 sub balance_method { -
trunk/lib/Perlbal/Service.pm
r806 r824 403 403 return $mc->ok; 404 404 }, 405 dumper => sub { 406 my ($self, $val) = @_; 407 return join(', ', @$val); 408 }, 405 409 }, 406 410 … … 449 453 return $mc->ok; 450 454 }, 455 dumper => sub { 456 my ($self, $val) = @_; 457 return $val->name; 458 } 451 459 }, 452 460 … … 639 647 $ctx->{last_created} = $self->name; 640 648 return Perlbal::run_manage_command($cmd, undef, $ctx); 649 } 650 651 sub dumpconfig { 652 my $self = shift; 653 654 my @return; 655 656 my %my_tunables = %$tunables; 657 658 my $dump = sub { 659 my $setting = shift; 660 }; 661 662 foreach my $skip (qw(role listen pool)) { 663 delete $my_tunables{$skip}; 664 } 665 666 my $role = $self->{role}; 667 668 foreach my $setting ("role", "listen", "pool", sort keys %my_tunables) { 669 my $attrs = $tunables->{$setting}; 670 my $value = $self->{$setting}; 671 672 my $check_role = $attrs->{check_role}; 673 my $check_type = $attrs->{check_type}; 674 my $default = $attrs->{default}; 675 my $required = $attrs->{required}; 676 677 next if ($check_role && $check_role ne '*' && $check_role ne $role); 678 679 if ($check_type && $check_type eq 'size') { 680 $default = $1 if $default =~ /^(\d+)b$/i; 681 $default = $1 * 1024 if $default =~ /^(\d+)k$/i; 682 $default = $1 * 1024 * 1024 if $default =~ /^(\d+)m$/i; 683 } 684 685 if (!$required) { 686 next unless defined $value; 687 next if (defined $default && $value eq $default); 688 } 689 690 if (my $dumper = $attrs->{dumper}) { 691 $value = $dumper->($self, $value); 692 } 693 694 if ($check_type && $check_type eq 'bool') { 695 $value = 'on' if $value; 696 } 697 698 push @return, "SET $setting = $value"; 699 } 700 701 my $plugins = $self->{plugins}; 702 703 foreach my $plugin (keys %$plugins) { 704 local $@; 705 706 my $class = "Perlbal::Plugin::$plugin"; 707 my $cv = $class->can('dumpconfig'); 708 709 if ($cv) { 710 eval { push @return, $class->dumpconfig($self) }; 711 if ($@) { 712 push @return, "# Plugin '$plugin' threw an exception while being dumped."; 713 } 714 } else { 715 push @return, "# Plugin '$plugin' isn't capable of dumping config."; 716 } 717 } 718 719 return @return; 641 720 } 642 721
