view release on metacpan or search on metacpan
lib/AC/MrGamoo/API/Get.pm view on Meta::CPAN
open(F, $file) || return nbfd_reply(500, 'error', $fd, $proto, $req);
my $size = (stat($file))[7];
my $sha1 = sha1_file($file);
debug("get file '$file' size $size");
# send header
my $gb = ACPScriblReply->encode( { status_code => 200, status_message => 'OK', hash_sha1 => $sha1 } );
my $hdr = AC::MrGamoo::Protocol->encode_header(
type => $proto->{type},
msgidno => $proto->{msgidno},
is_reply => 1,
data_length => length($gb),
content_length => $size,
);
my $buf = $hdr . $gb;
syswrite( $fd, $buf );
# stream
AC::MrGamoo::Protocol->sendfile($fd, \*F, $size);
lib/AC/MrGamoo/API/HB.pm view on Meta::CPAN
my $req = shift;
my $content = shift;
unless( $proto->{want_reply} ){
$io->shut();
return;
}
my $response = AC::MrGamoo::Protocol->encode_reply( {
type => 'heartbeat_request',
msgid => $proto->{msgid},
is_reply => 1,
}, {
status_code => 200,
status_message => 'Honky Dory',
hostname => $HOSTNAME,
subsystem => 'mrgamoo',
environment => conf_value('environment'),
port => my_port(),
timestamp => time(),
sort_metric => loadave(),
lib/AC/MrGamoo/API/Simple.pm view on Meta::CPAN
my $proto = shift;
my $req = shift;
unless( $proto->{want_reply} ){
$io->shut();
return;
}
my $response = AC::MrGamoo::Protocol->encode_reply( {
type => $proto->{type},
msgid => $proto->{msgid},
is_reply => 1,
}, {
status_code => $code,
status_message => $msg,
} );
debug("sending $code reply for $proto->{type} on $io->{info}");
$io->write_and_shut( $response );
}
lib/AC/MrGamoo/API/Simple.pm view on Meta::CPAN
my $code = shift;
my $msg = shift;
my $fd = shift;
my $proto = shift;
my $req = shift;
return unless $proto->{want_reply};
my $response = AC::MrGamoo::Protocol->encode_reply( {
type => $proto->{type},
msgid => $proto->{msgid},
is_reply => 1,
}, {
status_code => $code,
status_message => $msg,
} );
debug("sending $code reply for $proto->{type} (from bkg)");
syswrite( $fd, $response );
}
lib/AC/MrGamoo/API/Xfer.pm view on Meta::CPAN
my $code = shift;
my $msg = shift;
my($addr, $port) = get_peer_addr_from_id( $req->{master} );
debug("sending xfer status update for $req->{copyid} => $code => $req->{master}");
debug("cannot find addr") unless $addr;
return unless $addr;
my $x = AC::MrGamoo::API::Client->new( $addr, $port, "xfer $req->{copyid}", {
type => 'mrgamoo_xferstatus',
msgidno => $MSGID++,
want_reply => 1,
}, {
jobid => $req->{jobid},
copyid => $req->{copyid},
status_code => $code,
status_message => $msg,
} );
debug("cannot create client") unless $x;
return unless $x;
lib/AC/MrGamoo/Client.pm view on Meta::CPAN
$r->{eu_print_stderr} = sub { print STDERR "@_\n" };
$r->{eu_print_stdout} = sub { print STDERR "@_\n" };
# run init section
my $h_init = $mr->get_code( 'init' );
my $initres = ($h_init ? $h_init->{code}() : undef) || {};
$me->{id} = unique();
my $req = AC::MrGamoo::Protocol->encode_request( {
type => 'mrgamoo_jobcreate',
msgidno => $^T,
want_reply => 1,
},{
jobid => $me->{id},
options => to_json( $r->{config} ),
initres => to_json( $initres, {allow_nonref => 1} ),
jobsrc => $mr->src(),
console => ($me->{console_port} ? ":$me->{console_port}" : ''),
traceinfo => $me->{traceinfo},
} );
lib/AC/MrGamoo/Client.pm view on Meta::CPAN
return $ok ? $me->{id} : undef;
}
sub abort {
my $me = shift;
return unless $me->{master};
my $res = $me->_submit_to( $me->{master}{addr}, $me->{master}{port}, AC::MrGamoo::Protocol->encode_request( {
type => 'mrgamoo_jobabort',
msgidno => $^T,
want_reply => 1,
}, {
jobid => $me->{id},
}));
}
################################################################
sub _pick_master_and_send {
my $me = shift;
my $req = shift;
my $seed = shift;
my @serverlist;
my $listreq = AC::MrGamoo::Protocol->encode_request( {
type => 'mrgamoo_status',
msgidno => $^T,
want_reply => 1,
}, {});
# get the full list of servers
# contact each seed passed in above, until we get a reply
for my $s ( @$seed ){
my($addr, $port) = split /:/, $s;
$me->{fdebug}->("attempting to fetch server list from $addr:$port");
eval {
alarm(1);
lib/AC/MrGamoo/EUConsole.pm view on Meta::CPAN
my $i = socket($fd, PF_INET, SOCK_DGRAM, 0);
$i = connect( $fd, sockaddr_in($port, $ip) );
unless( $i ){
verbose("cannot connect to user console: $!");
return;
}
return bless {
fd => $fd,
jobid => $jobid,
msgid => (time() & 0xFFFF),
}, $class;
}
sub send_msg {
my $me = shift;
my $type = shift;
my $msg = shift;
my $fd = $me->{fd};
return unless $fd;
my $req = AC::MrGamoo::Protocol->encode_request( {
type => 'mrgamoo_diagmsg',
want_reply => 0,
msgid => $me->{msgid}++,
}, {
jobid => $me->{jobid},
server_id => my_server_id(),
type => $type,
msg => $msg,
} );
send $fd, $req, 0;
}
lib/AC/MrGamoo/Job/Done.pm view on Meta::CPAN
for my $fi (@{$me->{tmp_file}}){
# debug("deleting $fi->{filename} from $fi->{server}");
$me->{statistics}{cleanup_files} ++;
AC::MrGamoo::Job::Request->new( $me,
id => unique(),
server => $fi->{server},
info => "delete $fi->{filename} from $fi->{server}",
proto => {
type => 'mrgamoo_filedel',
msgidno => $^T,
want_reply => 1,
},
request => {
filename => $fi->{filename},
},
);
}
$me->{tmp_file} = [];
}
lib/AC/MrGamoo/Job/Task.pm view on Meta::CPAN
my $job = shift;
my $server = $me->{server};
debug("starting task $job->{request}{jobid}/$me->{info}{id}/$me->{id} on $server");
# send request to server
my $ti = $me->{info};
my $x = $job->_send_request( $server, "task $me->{id}", {
type => 'mrgamoo_taskcreate',
msgidno => $^T,
want_reply => 1,
}, {
jobid => $job->{request}{jobid},
taskid => $me->{id},
jobsrc => $job->{request}{jobsrc},
options => $job->{request}{options},
initres => $job->{request}{initres},
console => ($job->{request}{console} || ''),
phase => $ti->{phase},
infile => $ti->{infile},
lib/AC/MrGamoo/Job/Task.pm view on Meta::CPAN
my $job = shift;
debug("aborting task $me->{id}");
AC::MrGamoo::Job::Request->new( $job,
id => unique(),
server => $me->{server},
info => "abort task $me->{id}",
proto => {
type => 'mrgamoo_taskabort',
msgidno => $^T,
want_reply => 1,
},
request => {
jobid => $job->{request}{jobid},
taskid => $me->{id},
},
);
delete $job->{"task_running"}{$me->{id}};
delete $job->{server_info}{$me->{server}}{"task_running"}{$me->{id}};
lib/AC/MrGamoo/Job/Xfer.pm view on Meta::CPAN
my $me = shift;
my $job = shift;
# send request to server
my $server = $me->{server};
my $filename = $me->{info}{filename};
debug("starting xfer $me->{id} on $server of $filename");
my $x = $job->_send_request( $server, "xfer $me->{id}", {
type => 'mrgamoo_filexfer',
msgidno => $^T,
want_reply => 1,
}, {
jobid => $job->{request}{jobid},
copyid => $me->{id},
filename => $filename,
dstname => ($me->{info}{dstname} || $filename),
location => ($job->{file_info}{$filename}{location} || $me->{info}{location}),
console => $job->{request}{console},
master => my_server_id(),
} );
lib/AC/MrGamoo/Kibitz/Client.pm view on Meta::CPAN
use AC::MrGamoo::Protocol;
use AC::DC::IO::TCP::Client;
use strict;
require "AC/protobuf/mrgamoo_status.pl";
our @ISA = 'AC::DC::IO::TCP::Client';
my $HDRSIZE = AC::MrGamoo::Protocol->header_size();
my $TIMEOUT = 3;
my $msgid = $$;
sub new {
my $class = shift;
# addr, port, ...
debug('starting kibitz status client');
my $me = $class->SUPER::new( @_ );
return unless $me;
$me->set_callback('timeout', \&timeout);
$me->set_callback('read', \&read);
$me->set_callback('shutdown', \&shutdown);
$me->start();
# build request
my $req = AC::MrGamoo::Protocol->encode_request( {
type => 'mrgamoo_status',
content_length => 0,
want_reply => 1,
msgid => $msgid++,
}, {
myself => AC::MrGamoo::Kibitz->about_myself(),
} );
# write request
$me->write( $req );
$me->timeout_rel($TIMEOUT);
return $me;
}
lib/AC/MrGamoo/Task.pm view on Meta::CPAN
use AC::MrGamoo::Config;
use AC::DC::IO::Forked;
use JSON;
use strict;
my $TSTART = $^T;
my $TIMEOUT = 3600;
my $MAXREQ = 2;
my $MAXRUNNING = 7; # tune me!
my %REGISTRY;
my $msgid = $$;
################################################################
# schedule periodic "cronjob"
AC::DC::Sched->new(
info => "task periodic",
freq => 5,
func => \&periodic,
);
lib/AC/MrGamoo/Task.pm view on Meta::CPAN
# don't kill the master with too many requests
# return if $me->{_status_underway} >= $MAXREQ;
my($addr, $port) = get_peer_addr_from_id( $me->{request}{master} );
return unless $addr;
debug("sending task status update $me->{request}{taskid} => $me->{status}{phase}");
my $x = AC::MrGamoo::API::Client->new( $addr, $port, "task $me->{request}{taskid}", {
type => 'mrgamoo_taskstatus',
msgidno => $msgid++,
want_reply => 0,
}, {
jobid => $me->{request}{jobid},
taskid => $me->{request}{taskid},
phase => $me->{status}{phase},
progress => $me->{status}{amt},
} );
return unless $x;
lib/AC/MrGamoo/Xfer.pm view on Meta::CPAN
my($addr, $port) = get_peer_addr_from_id( $loc );
unless( $addr ){
debug("cannot find addr for $loc");
return;
}
debug("connecting to $addr:$port");
my $req = AC::MrGamoo::Protocol->encode_request( {
type => 'scribl_get',
msgidno => $$,
want_reply => 1,
}, { filename => $srcname } );
my $p;
eval {
# connect
my $s = AC::MrGamoo::Protocol->connect_to_server( inet_aton($addr), $port );
return unless $s;
# send req