| 1 | package Gearman::Driver::Console::Client; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use POE qw(Wheel::ReadLine); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::Telnet; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | with qw(MooseX::Getopt); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Gearman::Driver::Console::Client - Console client with readline | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | If you got many worker servers and want to change processes at once | ||||||||||||||||||||||||||||
| 15 | on all servers while runtime, this tool comes in handy: | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | usage: gearman_driver_console.pl [long options...] | ||||||||||||||||||||||||||||
| 18 | --server A list of servers to connect to: "host1 host2 host3:47301 host4:47302" | ||||||||||||||||||||||||||||
| 19 | --history Readline history, defaults to $HOME/.gearman_driver_history | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | $ ~/Gearman-Driver$ gearman_driver.pl --console_port 47301 & | ||||||||||||||||||||||||||||
| 22 | [1] 89053 | ||||||||||||||||||||||||||||
| 23 | $ ~/Gearman-Driver$ gearman_driver.pl --console_port 47302 & | ||||||||||||||||||||||||||||
| 24 | [2] 89066 | ||||||||||||||||||||||||||||
| 25 | $ ~/Gearman-Driver$ gearman_driver.pl --console_port 47303 & | ||||||||||||||||||||||||||||
| 26 | [3] 89079 | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | $ ~/Gearman-Driver$ gearman_driver_console.pl --server "localhost:47301 localhost:47302 localhost:47303" | ||||||||||||||||||||||||||||
| 29 | console> status | ||||||||||||||||||||||||||||
| 30 | localhost:47301> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 31 | localhost:47301> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 32 | localhost:47301> . | ||||||||||||||||||||||||||||
| 33 | localhost:47302> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 34 | localhost:47302> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 35 | localhost:47302> . | ||||||||||||||||||||||||||||
| 36 | localhost:47303> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 37 | localhost:47303> GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 38 | localhost:47303> . | ||||||||||||||||||||||||||||
| 39 | console> show GDExamples::Convert::convert_to_jpeg | ||||||||||||||||||||||||||||
| 40 | localhost:47301> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 41 | localhost:47301> 89061 | ||||||||||||||||||||||||||||
| 42 | localhost:47301> 89063 | ||||||||||||||||||||||||||||
| 43 | localhost:47301> 89062 | ||||||||||||||||||||||||||||
| 44 | localhost:47301> . | ||||||||||||||||||||||||||||
| 45 | localhost:47302> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 46 | localhost:47302> 89074 | ||||||||||||||||||||||||||||
| 47 | localhost:47302> 89075 | ||||||||||||||||||||||||||||
| 48 | localhost:47302> 89076 | ||||||||||||||||||||||||||||
| 49 | localhost:47302> . | ||||||||||||||||||||||||||||
| 50 | localhost:47303> GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 | ||||||||||||||||||||||||||||
| 51 | localhost:47303> 89088 | ||||||||||||||||||||||||||||
| 52 | localhost:47303> 89089 | ||||||||||||||||||||||||||||
| 53 | localhost:47303> 89087 | ||||||||||||||||||||||||||||
| 54 | localhost:47303> . | ||||||||||||||||||||||||||||
| 55 | console> shutdown | ||||||||||||||||||||||||||||
| 56 | [1] Done gearman_driver.pl --console_port 47301 | ||||||||||||||||||||||||||||
| 57 | [2]- Done gearman_driver.pl --console_port 47302 | ||||||||||||||||||||||||||||
| 58 | [3]+ Done gearman_driver.pl --console_port 47303 | ||||||||||||||||||||||||||||
| 59 | $ ~/Gearman-Driver$ | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | has 'server' => ( | |||||||||||||||||||||||||||
| 64 | documentation => 'A list of servers to connect to: "host1 host2 host3:47301 host4:47302"', | ||||||||||||||||||||||||||||
| 65 | is => 'rw', | ||||||||||||||||||||||||||||
| 66 | isa => 'Str', | ||||||||||||||||||||||||||||
| 67 | required => 1, | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | has 'telnet' => ( | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 1 | handles => { | |||||||||||||||||||||||||||
| 73 | add_telnet => 'set', | ||||||||||||||||||||||||||||
| 74 | get_telnet => 'get', | ||||||||||||||||||||||||||||
| 75 | servers => 'keys', | ||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||
| 78 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 79 | traits => [qw(NoGetopt Hash)], | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | has 'history' => ( | |||||||||||||||||||||||||||
| 83 | default => "$ENV{HOME}/.gearman_driver_history", | ||||||||||||||||||||||||||||
| 84 | documentation => 'Readline history, defaults to $HOME/.gearman_driver_history', | ||||||||||||||||||||||||||||
| 85 | is => 'rw', | ||||||||||||||||||||||||||||
| 86 | isa => 'Str', | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | has 'session' => ( | |||||||||||||||||||||||||||
| 90 | is => 'ro', | ||||||||||||||||||||||||||||
| 91 | isa => 'POE::Session', | ||||||||||||||||||||||||||||
| 92 | traits => [qw(NoGetopt)], | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | foreach my $server ( split /\s+/, $self->server ) { | |||||||||||||||||||||||||||
| 99 | 0 | my ( $host, $port ) = split /:/, $server; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | $port ||= 47300; | ||||||||||||||||||||||||||
|
Condition0%0/2
$port ||= 47300
MC/DC0%0/1
$port ||= 47300
$port
Truth table0%0/2
A
A= $port
| |||||||||||||||||||||||||||||
| 101 | 0 | my $telnet = Net::Telnet->new( | |||||||||||||||||||||||||||
| 102 | host => $host, | ||||||||||||||||||||||||||||
| 103 | port => $port, | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | 0 | $telnet->open; | |||||||||||||||||||||||||||
| 106 | 0 | $self->add_telnet( $server => $telnet ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | $self->{session} = POE::Session->create( | |||||||||||||||||||||||||||
| 110 | object_states => [ | ||||||||||||||||||||||||||||
| 111 | $self => { | ||||||||||||||||||||||||||||
| 112 | _start => '_start', | ||||||||||||||||||||||||||||
| 113 | got_user_input => '_handle_user_input', | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | ] | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | POE::Kernel->run(); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub _handle_user_input { | ||||||||||||||||||||||||||
|
Subroutine
_handle_user_input: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 122 | 0 | my ( $self, $input, $exception ) = @_[ OBJECT, ARG0, ARG1 ]; | |||||||||||||||||||||||||||
| 123 | 0 | my $console = $_[HEAP]{console}; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless ( defined $input ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $console->put("$exception caught. B'bye!"); | |||||||||||||||||||||||||||
| 127 | 0 | $_[KERNEL]->signal( $_[KERNEL], "UIDESTROY" ); | |||||||||||||||||||||||||||
| 128 | 0 | $console->write_history( $self->history ); | |||||||||||||||||||||||||||
| 129 | 0 | return; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | $console->addhistory($input); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | my ( $command, $pipe ) = split /\|/, $input; | |||||||||||||||||||||||||||
| 135 | 0 | my @lines = (); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | foreach my $server ( sort $self->servers ) { | |||||||||||||||||||||||||||
| 138 | 0 | my $telnet = $self->get_telnet($server); | |||||||||||||||||||||||||||
| 139 | 0 | $telnet->print($command); | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | while ( my $line = $telnet->getline() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($pipe) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | push @lines, "$server> $line"; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||
| 145 | 0 | print "$server> $line"; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | last if $line eq ".\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($pipe) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 0 | open CMD, "|$pipe"; | |||||||||||||||||||||||||||
| 153 | 0 | print CMD $_ foreach @lines; | |||||||||||||||||||||||||||
| 154 | 0 | close CMD; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( $input eq 'quit' || $input eq 'shutdown' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input eq "quit" or $input eq "shutdown"
MC/DC0%0/2
$input eq "quit" or $input eq "shutdown"
$input eq "quit"
$input eq "shutdown"
Truth table0%0/3
A or B
A= $input eq "quit"B= $input eq "shutdown"
| |||||||||||||||||||||||||||||
| 158 | 0 | $console->write_history( $self->history ); | |||||||||||||||||||||||||||
| 159 | 0 | $_[KERNEL]->signal( $_[KERNEL], "UIDESTROY" ); | |||||||||||||||||||||||||||
| 160 | 0 | return; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | $console->get("console> "); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 167 | 0 | $_[HEAP]{console} = POE::Wheel::ReadLine->new( InputEvent => 'got_user_input' ); | |||||||||||||||||||||||||||
| 168 | 0 | $_[HEAP]{console}->read_history( $_[OBJECT]->history ); | |||||||||||||||||||||||||||
| 169 | 0 | $_[HEAP]{console}->get("console> "); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | See L<Gearman::Driver>. | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | See L<Gearman::Driver>. | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =over 4 | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =item * L<Gearman::Driver> | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =item * L<Gearman::Driver::Adaptor> | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =item * L<Gearman::Driver::Console> | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =item * L<Gearman::Driver::Console::Basic> | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =item * L<Gearman::Driver::Job> | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =item * L<Gearman::Driver::Job::Method> | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =item * L<Gearman::Driver::Loader> | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =item * L<Gearman::Driver::Observer> | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =item * L<Gearman::Driver::Worker> | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =item * L<Gearman::Driver::Worker::Base> | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =back | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 1 | 1; | |||||||||||||||||||||||||||