Changeset 71d0868 in tol for tolsh/tolsh.vfs/lib/tolcomm


Ignore:
Timestamp:
Dec 15, 2009, 1:39:04 PM (17 years ago)
Author:
Jorge Pérez <josp.jorge@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
bc98cf7
Parents:
e213da6
Message:

fix #812 : ps_runtol tcl client side, RemoteTOL tol cliente side of RUNTOL request

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1810 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tolsh/tolsh.vfs/lib/tolcomm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tolsh/tolsh.vfs/lib/tolcomm/rmtps_client.tcl

    re213da6 r71d0868  
    1010package provide rmtps_client 1.0
    1111
    12 package require tlogger
     12package require base64
     13
     14if { [ catch { package require tlogger } ] } {
     15  namespace eval tlogger {
     16    variable _level "error"
     17
     18    proc init { svc {logfile ""} } {
     19    }
     20   
     21    proc level { svc l } {
     22      variable _level $l
     23    }
     24
     25    proc log { l msg } {
     26      variable _level
     27
     28      if { $l eq $_level } {
     29        puts $msg
     30      }
     31    }
     32  }
     33}
    1334
    1435###############################################################################
    … …  
    159180}
    160181
     182proc ask_server_channel { chan request } {
     183
     184  usado sobre todo para pedir la razon del fallo
     185
     186  el timeout quizas deba cerrar el channel, esa peticion se cancela
     187
     188  file channels puedo usarlo para verificar si un socket existe.
     189}
     190
    161191###############################################################################
    162192#
    … …  
    270300  # Answer from server must be an integer value
    271301  #
    272   if {$result eq "" || ![string is integer $result]} {
     302  if { $result eq "" || ![string is integer $result] ||
     303      ![string is boolean $result] } {
    273304    set result -1
    274305  } else {
    … …  
    358389}
    359390
     391
     392###############################################################################
     393#
     394#  ps_runtol -- execute a TOL process on a remote host
     395#
     396#   Arguments --
     397#
     398#     host        - computer (remote host) where RmtPS_Server is running
     399#     port        - port where the server socket is listening
     400#     cmdln_args  - TOL arguments
     401#
     402#   Return --
     403#
     404#     PID of the process if cmdline could be executed
     405#     0 if the command line could not be executed
     406#
     407###############################################################################
     408proc ::rmtps_client::ps_runtol { host port cmdln_args } {
     409
     410  log "debug" "enter ps_runtol $host $port $cmdln_args"
     411
     412  # send request to server
     413  #
     414  set cmdln64 [ base64::encode -wrapchar "" $cmdln_args ]
     415  #set cmdln64 $cmdln_args
     416  set result [ask_server $host $port "RUNTOL $cmdln64"]
     417  # Make sure that 0 or PID>0 is returned
     418  #
     419  if {![string is integer $result] || $result<0} {
     420    set result 0
     421  }
     422
     423  log "debug" "leave ps_runtol $host $port $cmdln_args : $result"
     424
     425  set result
     426}
     427
    360428###############################################################################
    361429#
  • tolsh/tolsh.vfs/lib/tolcomm/rmtps_client.tol

    re213da6 r71d0868  
    1010 *  Argumentos:
    1111 *
    12  *    Host:
    13  *    Port:
     12 *    Host: host que aloja al servidor RMTPS
     13 *   
     14 *    Port: puerto donde el servidor RMPTS esta escuchando
    1415 *
    1516 *  Resultado:
    … …  
    3738 *  Argumentos:
    3839 *
    39  *    Host:
    40  *    Port:
     40 *    Host: host que aloja al servidor RMTPS
     41 *   
     42 *    Port: puerto donde el servidor RMPTS esta escuchando
     43 *
    4144 *    CmdLine:
    4245 *
    … …  
    6568
    6669/**
     70 *  RemoteTOL -- Invoca un proceso TOL remoto
     71 *
     72 *  Argumentos:
     73 *
     74 *    Host: host que aloja al servidor RMTPS
     75 *   
     76 *    Port: puerto donde el servidor RMPTS esta escuchando
     77 *
     78 *    Args:
     79 *
     80 *  Resultado:
     81 *
     82 *    PID del proceso TOL lanzado o 0 si algun error ha ocurrido
     83 * 
     84 */
     85Real RemoteTOL(Text Host, Real Port, Set Args )
     86{
     87
     88  Text cmd = "::rmtps_client::ps_runtol";
     89  Text port = FormatReal(Port, "%.0lf");
     90  Text project = Args[ 1 ];
     91  Set tolargs = Args[ 2 ];
     92  Set cmdln_args = If( project=="", Copy( Empty ),
     93                       [[ "-project", project ]] );
     94  Set EvalSet( tolargs, Real( Set item ) {
     95      Text type = Name( item[ 1 ] );
     96      Case( type=="expr", {
     97          Set Append( cmdln_args, [[ "-expr", item[ 1 ] ]] );
     98          Real 0
     99        },
     100        type=="file", {
     101          Real idx_rel = FindIndexByName( item, "relative" );
     102          Set Append( cmdln_args,
     103                      If( idx_rel, {
     104                          Set [[ "-relative", item[ idx_rel ],
     105                                 "-file", item[ 1 ] ]]
     106                        }, {
     107                          Set [[ "-file", item[ 1 ] ]]
     108                        } ) );
     109          Real 0
     110        } ,
     111        1, {
     112          Warning( "RemoteTOL: tipo de elemento desconocido '"
     113                   + type + "' debe "
     114                   "ser 'expr' o 'file'" );
     115          Real 0
     116        } );
     117        Real 0
     118    } );
     119  Set tcl_args = [[ cmd, host, port ]] << [[ cmdln_args ]];
     120  //Set View( tcl_args, "Std" );
     121  Set result = Tcl_EvalEx( tcl_args );
     122  Real If(result["status"], Eval(result["result"]),{
     123      WriteLn("RemoteTOL: "+result["result"],"E");
     124      Real 0
     125    })
     126};
     127PutDescription("Ejecuta en proceso TOL remoto. Args es un conjunto con los "
     128               "argumentos a pasar a TOL en la linea de comandos.\n"
     129               "Los elementos de Args son interpretados por el servidor de "
     130               "procesos TOL y se traducen en argumentos de linea de comandos "
     131               "al proceso TOL que se invoca. Los argumentos son:\n"
     132               "\tText project = nombre del proyecto que se cargara\n"
     133               "\tSet tolargs = conjunto de elementos a evaluar.\n"
     134               "El conjunto tolargs contiene expresiones TOL o archivos a "
     135               "evaluar en la linea de comandos. Cada uno de los "
     136               "elementos es un conjunto con los siguientes elementos con "
     137               "nombre:\n"
     138               "\tText tolargs[1] : contiene la expresion o el nombre del "
     139               "\tarchivo a evaluar. El nombre de tolargs[1] debe ser expr o "
     140               "\tfile. Si el nombre es expr el valor se considera una "
     141               "\texpresion TOL. Si el nombre es file el valor se considera "
     142               "\tel nombre de un archivo a evaluar."
     143               "\tText relative = nombre de proyecto respecto al cual se "
     144               "\tcargara el archivo TOL. Este campo es opcional y solo se "
     145               "\tconsidera cuando el tolargs[1] es un archivo. Por omision "
     146               "\tel archivo se toma trelativo al argumento project.\n\n"
     147               "Retorna el PID del proceso TOL ejecutado o 0 si algun error "
     148               "ocurrio durante el intento de ejecucion. "
     149               "Necesita que un servidor RmtPS_Server este escuchando en el "
     150               "puerto Port del ordenador Host",
     151               RemoteTOL);
     152
     153/**
    67154 *  RemoteAlive -- Verifica, en remoto, si un proceso continua vivo
    68155 *
    69156 *  Argumentos:
     157 *
     158 *    Host: host que aloja al servidor RMTPS
     159 *   
     160 *    Port: puerto donde el servidor RMPTS esta escuchando
    70161 *
    71162 *    Host:
    … …  
    108199 *  Argumentos:
    109200 *
     201 *    Host: host que aloja al servidor RMTPS
     202 *   
     203 *    Port: puerto donde el servidor RMPTS esta escuchando
     204 *
    110205 *    Host:
    111206 *    Port:
Note: See TracChangeset for help on using the changeset viewer.