--- trunk/Estraier.pm 2006/05/08 21:33:37 132 +++ trunk/Estraier.pm 2006/05/09 12:21:26 134 @@ -1700,6 +1700,127 @@ return $self->{inform}->{links}; } +=head2 master + +Set actions on Hyper Estraier node master (C process) + + $node->master( + action => 'sync' + ); + +All available actions are documented in +L + +=cut + +my $estmaster_rest = { + shutdown => { + status => 202, + }, + sync => { + status => 202, + }, + backup => { + status => 202, + }, + userlist => { + status => 200, + returns => qw/name passwd flags fname misc/, + }, + useradd => { + required => qw/name passwd flags/, + optional => qw/fname misc/, + status => 200, + }, + userdel => { + required => qw/name/, + status => 200, + }, + nodelist => { + status => 200, + returns => qw/name label doc_num word_num size/, + }, + nodeadd => { + required => qw/name/, + optional => qw/label/, + status => 200, + }, + nodedel => { + required => qw/name/, + status => 200, + }, + nodeclr => { + required => qw/name/, + status => 200, + }, + nodertt => { + status => 200, + }, +}; + +sub master { + my $self = shift; + + my $args = {@_}; + + # have action? + my $action = $args->{action} || croak "need action, available: ", + join(", ",keys %{ $estmaster_rest }); + + # check if action is valid + my $rest = $estmaster_rest->{$action}; + croak "action '$action' is not supported, available actions: ", + join(", ",keys %{ $estmaster_rest }) unless ($rest); + + croak "BUG: action '$action' needs return status" unless ($rest->{status}); + + my @args; + + if ($rest->{required} || $rest->{optional}) { + + map { + croak "need parametar '$_' for action '$action'" unless ($args->{$_}); + push @args, $_ . '=' . uri_escape( $args->{$_} ); + } ( keys %{ $rest->{required} } ); + + map { + push @args, $_ . '=' . uri_escape( $args->{$_} ) if ($args->{$_}); + } ( keys %{ $rest->{optional} } ); + + } + + my $uri = new URI( $self->{url} ); + + my $resbody; + + if ($self->shuttle_url( + 'http://' . $uri->host_port . '/master?action=' . $action , + 'application/x-www-form-urlencoded', + join('&', @args), + \$resbody, + 1, + ) == $rest->{status}) { + return 0E0 unless ($rest->{returns}); + + if (wantarray) { + + my @results; + + foreach my $line ( split(/[\r\n]/,$resbody) ) { + my @e = split(/\t/, $line); + my $row; + map { $row->{$_} = shift @e; } @{ $rest->{returns} }; + push @results, $row; + } + + return @results; + } else { + + carp "calling master action '$action', but not expecting array back, returning whole body"; + return $resbody; + } + } +} =head1 PRIVATE METHODS