⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teardown.xpl

📁 OpenCDN内容分发系统
💻 XPL
字号:
<?xml version="1.0"?><!DOCTYPE methoddef SYSTEM "rpc-method.dtd"><methoddef><name>Teardown</name><version>1.0</version><signature>string struct</signature><help>Description:    Teardown Request from Portal to the RRDM, which invokes                a NoRelay Request for nodes which relay the program.Arguments:      A structure with                KEY                VALUE                Program            The program URI whose distribution has to be stopped                Requester          An identifier for logging purposesReturn:         A struct whith key/values:                ret_code           shows the kind of response                ret_val            explains the outcome                Postreq_Res        result of postrequisite CGI invocation</help><code language="perl"><![CDATA[#!/usr/bin/perluse File::Flock;#################################################################################   Sub Name:       Teardown##   Description:    Teardown Request from Portal to the RRDM, which invokes#                   a NoRelay Request for nodes which relay the program.##   Arguments:      A structure with#                   KEY         TYPE    VALUE#                   Program     string  The program URI whose distribution has to be stopped#                   Requester   string  An identifier for logging purposes##   Return:         A struct whith key/values:#                   ret_code    int     shows the kind of response#                   ret_val     string  explains the outcome#                   Postreq_Res string  result of postrequisite CGI invocation################################################################################sub Teardown{use RPC::XML::Client;use LWP::UserAgent;use etc::CommConf qw($rrdm_addr);use CommLib qw(children_wait chk_resp);my $att_ref     = pop @_;my $program     = $$att_ref{Program};my $prog_lock   = undef;my $requester   = $$att_ref{Requester};my $postreq_res = undef;my ($FP, $node, $ret_code, $ret_val, $pid, $cico, $count) =   ('', '', '', '', '', '', '');my %children;my ($root, @roots) = ('', ());my $i, $ua, $r, $res;node_log ( "+++ Teardown method entered for program $program on behalf of $requester", 1, 'r');if (!$program) {  ($ret_code, $ret_val) = ('405',    'Invalid TearDown parameters. Please notify developers about how this occurred.');  node_log ($ret_val, 1, 'r');  return { ret_code => $ret_code, ret_val => $ret_val, Postreq_Res => $postreq_res};}# Gets data from Core Servermy $postreq   = &RRDMlib::origins("{'$program'}{'postreq'}");my $surro_ref = &RRDMlib::surro("{'$program'}");if (defined $main::forked) {                  # don't serve the same program twice  $prog_lock = $program;  $prog_lock =~ tr/\//_/;                     # translates / in _  lock ("teardown_$prog_lock");  node_log ( "* ... lock on $program acquired by pid $$", 3, 'r');}if ( %{$surro_ref} ) {  if ($postreq) {                             # Tryes to fulfill a postrequisite    $ua   = LWP::UserAgent->new;    $r    = HTTP::Request->new(POST=>$postreq);    $res  = $ua->request ($r);             # invokes the postrequisite CGI    $postreq_res = $res->content;    unless ($res->is_success) {               # Prerequisite failed.      node_log ("Postrequisite $postreq failed: $postreq_res", 1, 'r');    } else {      node_log ("Postrequisite $postreq successfull", 1, 'r');    }  }  # Finds root (FH) nodes for this Program  my ( $roots_IP_r, $roots_port_r ) = &RRDMlib::Find_Roots ($program);  if ( @$roots_IP_r ) {   # Exist peers data for this Program    node_log ( "    - roots: @$roots_IP_r", 1, 'r');    foreach $root (@$roots_IP_r) {      if ($pid = fork ) {        $cico++;        $children{$pid} = "$root:$$roots_port_r[$count]";        node_log ("    - Forked PID $pid for root node $root, cico $cico",                  1, 'r');      }      else {                                       # This is the child process        my $cli   = RPC::XML::Client->new("http://$root:$$roots_port_r[$count]",                                   'useragent', ['timeout', 60]);        ($ret_code, $ret_val) = chk_resp ($cli, $root, 'r');        unless ($ret_code) {             # Do the request          $res = $cli->send_request('NoRelay',                           { Program   => $program,                             Postreq   => $postreq,                             AuthToken => $RRDMlib::auth_token });          ($ret_code, $ret_val) = chk_resp ($res, $root, 'r');          if ($ret_code ne '200' && $ret_code ne '220') {            &RRDMlib::show_ret ($mret_ref);      # Unsuccesful return code.                                                 # Back-propagate err mess            $ret_val  = "Teardown of $root for $program UNsuccessful: ";          } else {                               # Teardown successful            $ret_val  = "Teardown of $root for $program successful: ";          }          $ret_val .= ' ' . $ret_code . ' ' . ${$$mret_ref{ret_val}};          node_log ($ret_val, 1, 'r');        } else {                                   # childrace didnt suceeded          node_log ("? Teardown did not opened client for $root", 1, 'r');        }        exit;                                      # exits form the child process      }                                            # end of child branch      $count++;                                    # Increments root node counter    }                                              # next root node for program    node_log ("    waiting for ($cico) root children to return...", 2, 'r');    children_wait (\%children, 'r');    node_log (" root children returned!", 3, 'r');    $ret_code = '200';    $ret_val = "Teardown for $program successfully completed";    # Deletes peers data for this Program    &RRDMlib::Prog_Peers_Del ($program);  } else {    $ret_code = '515';    $ret_val = "TearDown error: no peers data for program $program";    node_log ($ret_val, 1, 'r');  }                                                # exit from if peers  # Deletes surrogate data for this Program  &RRDMlib::Prog_Surro_Del ($program);  &RRDMlib::node_log ( " Surrogate data for $program deleted", 1, 'r');}else {  $ret_code = '415';  $ret_val = "TearDown error: no RRDM data for program $program";  node_log ($ret_val, 1, 'r');}if (defined $main::forked) {  node_log ( "  * ... lock on $program released by pid $$", 3, 'r');  unlock("teardown_$prog_lock");}#&RRDMlib::show_table ('surro');                 # prints surrogates tablereturn { ret_code => $ret_code, ret_val => $ret_val, Postreq_Res => $postreq_res};}__END__]]></code></methoddef>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -