public function getRpc() { if ($this->_rpc) { return $this->_rpc; } $scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http'; $target = sprintf('%s://%s/plugins/json-rpc/v1/', $scheme, $_SERVER['HTTP_HOST']); $oauth_consumer = $this->getOAuthConsumer(); $connection = Tivoka::connect($target); $connection->setOAuthConsumer($oauth_consumer); $this->_rpc = $connection; return $connection; }
/** * Send this request to a remote server directly * @param string $target The URL of the remote server */ public function send($target) { Tivoka::connect($target)->send($this); }
/** * Construct a native client * @access private * @param string $target URL */ public function __construct($target) { $this->connection = Tivoka::connect($target); }
function runPendingProcess() { global $conn; $pid_query = "select * from process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum OR idProcessNumMaster is null)"; $rswrk = $conn->Execute($pid_query); $num_process_running = $rswrk->RecordCount(); spool_video_all_folders(); spool_document(); downloadPendingImages(); checkFinishedTraining(); addNewConcept(); $log = ""; if ($num_process_running) { ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - INIZIO echo "{$num_process_running} Processes running. <br>"; while (!$rswrk->EOF) { //PsExec("ls /var/www/octo/"); echo "Stampa controllo esecuzione processo <br>"; $pid = $rswrk->fields("OSProcessId"); //verifica timeout $to_time = time(); $from_time = strtotime($rswrk->fields("start")); $second_in_execution = round(abs($to_time - $from_time)); echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>"; switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile $timeout_limit = 60 * 60; //60 minuti break; case "2": //caso di un web service http $timeout_limit = 2 * 60; //2 minuti break; case "3": //caso di un JSONRPC $timeout_limit = 60 * 60; //60 minuti break; } if ($second_in_execution > $timeout_limit) { echo "Processo andato in timeout (più di {$timeout_limit} secondi). Fermato."; //setProcessEnd($rswrk->fields("processId")); setProcessStatus($rswrk->fields("processId"), 6); } else { switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile echo "Controllo esecuzione eseguibile<br>"; //eseguo la chiamata per verificare se il processo è ancora in esecuzione $exeCall = "ps --pid " . $pid; $result = exec($exeCall); //echo "primo <pre>".$result."</pre>"; if ($result == " PID TTY TIME CMD") { //il processo non è più attivo. lo blocco dal gestionale $log_terminate = "Il processo non è più " . $pid . " attivo "; add_log('runPendingProcess:finishing', $log_terminate); setProcessEnd($rswrk->fields("processId")); } else { echo "il processo " . $pid . " attivo<br>"; } break; case "2": //caso di un web service http echo "Controllo esecuzione web service http<br>"; $to_time = time(); $from_time = strtotime($rswrk->fields("start")); $second_in_execution = round(abs($to_time - $from_time)); echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>"; if ($second_in_execution > 120) { echo "Processo andato in timeout (più di 120 secondi). Fermato."; //setProcessEnd($rswrk->fields("processId")); setProcessStatus($rswrk->fields("processId"), 6); } break; case "3": //caso di un JSONRPC echo "Controllo esecuzione web service JSON-RPC (con getResults)<br>"; $processId = (int) $rswrk->fields("processId"); $target = EW_VIDEODROME_SERVER_URL; $request = Tivoka::createRequest(56, 'getResults', array('processId' => $processId)); Tivoka::connect($target)->send($request); if ($request->isError()) { // an error occured var_dump($request->error); var_dump($request->errorMessage); var_dump($request->response); } else { echo "<br>Stato processo: " . $request->result['status'] . "<br> log: "; var_dump($request->result); } switch (strtolower($request->result['status'])) { case "completed": echo "<br>PROCESSO COMPLETATO "; echo "Output:<pre>"; var_dump($request->result['output']); echo "</pre>"; setProcessOutput($rswrk->fields("processId"), $request->result['output']); setProcessEnd($rswrk->fields("processId")); break; case 'not found': echo "<br>PROCESSO NON TROVATO (FERMATO) "; setProcessEnd($processId); break; default: echo "Process running"; } break; } } $rswrk->MoveNext(); } } ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - FINE echo "terminato controllo processi in esecuzione"; echo "limite processi in parallelo: " . EW_MAX_PROCESS_IN_EXECUTION; if ($num_process_running < EW_MAX_PROCESS_IN_EXECUTION) { // caso di nessun processo in esecuzione->quindi cerco se ce n'è qualcuno da eseguire $select_query = "SELECT * FROM process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE idProcessStatus =1 OR idProcessStatus =8 ORDER BY process.priority,idProcessNum"; $rswrk = $conn->Execute($select_query); while (!$rswrk->EOF) { // esiste un processo da eseguire //controllo se il processo non è un sotto processo di una coda già in esecuzione $pending_previous = ew_ExecuteScalar("SELECT count(*) FROM process WHERE idProcessNumMaster = '" . $rswrk->fields('idProcessNumMaster') . "' AND (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum)"); if ($pending_previous) { $rswrk->MoveNext(); continue; } //metto il servizio su starting $query_update_status = "UPDATE process set idProcessStatus = 2, start = now() WHERE idProcessNum = " . $rswrk->fields("idProcessNum"); $conn->Execute($query_update_status); add_log('runPendingProcess:starting process', "INIZIALIZZATO PROCESSO " . $rswrk->fields("idProcessNum")); //aumento il numero di processi in esecuzione $num_process_running++; //caso del processo master di un multiprocess if ($rswrk->fields('idProcessNumMaster') == $rswrk->fields('idProcessNum')) { echo "Pipeline id " . $rswrk->fields("idProcessNum") . " running"; runPendingProcess(); return; } switch ($rswrk->fields('idProcessType')) { case "1": //caso di un eseguibile $command_to_append = "lynx -dump http://" . EW_ABS_HOST . "/eutv-tools/process/service/lib/setProcessEnd.php?processId=" . $rswrk->fields("processId"); $command_complete = "( " . $rswrk->fields("command") . " ; " . $command_to_append . " )"; $log .= "<br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command executed is: " . $command_complete . " on server " . $rswrk->fields("server") . "<br><br>."; $result = PsExec($command_complete); //aggiorno l'OSProcessId eseguito $query_update_status = "UPDATE process set OSProcessId ='" . $result . "' WHERE idProcessNum = " . $rswrk->fields("idProcessNum"); $conn->Execute($query_update_status); break; case "2": //caso di un web service http add_log('runPendingProcess:startingwebservice', "URL executed:" . $rswrk->fields("command")); $runCall = "" . $rswrk->fields("command"); $log .= "\n<br><br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command (service) executed is: " . $rswrk->fields("command") . " of service " . $rswrk->fields("service") . "."; $runCall = str_replace(" ", "%20", $runCall); $log .= "Calling service: " . $runCall; //$result = ""; $result = file_get_contents($runCall); $log .= $result; break; case "3": //caso di un JSONRPC add_log('runPendingProcess:startingwebserviceJSONRPC', "URL executed:" . $rswrk->fields("server")); $method = ""; //caricamento parametri processo $sSqlWrk = "SELECT * from processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . ""; $rswrk_params = $conn->Execute($sSqlWrk); while (!$rswrk_params->EOF) { //recupero il valore della variabile $value = $rswrk_params->fields('value'); //recupero il nome della variabile $var_name = $rswrk_params->fields('code'); if ($var_name == "method") { $method = $value; } else { echo "ANALISI parametro {$var_name} con valore {$value}<br><br>"; //faccio alcuni controlli if ($value == "true") { echo "Parametro {$var_name} di tipologia true<br>"; $value = true; } elseif ($value == "false") { echo "Parametro {$var_name} di tipologia false<br>"; $value = false; } elseif (is_numeric($value)) { echo "Parametro {$var_name} di tipologia int<br>"; $value = (int) $value; } elseif ($value == 'MEDIA_NAME_DB') { echo "<br>Entrato valore speciale MEDIA_NAME_DB"; $id_media = ew_ExecuteScalar("SELECT value FROM processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . " AND code = 'id_media'"); echo "<br>Recuperato id_media{$id_media} "; $conn->Execute("SET SESSION group_concat_max_len = 1000000;"); $list_image = ew_ExecuteScalar("SELECT GROUP_CONCAT(distinct thumbnail) FROM " . EW_CONN_DB_MEDIA . ".annotations WHERE id_media = '{$id_media}'"); //echo "<br>Recuperata lista immagini <em>$list_image</em>"; if ($list_image != "") { $array_images = explode(',', $list_image); } else { $array_images = array(); } echo "<br><br>Array immagini:<br><em>" . serialize($array_images) . "</em><br><br><br>"; $value = $array_images; } } echo "<br><br>Inserisco il parametro {$var_name} con valore:<br><em>" . serialize($value) . "</em><br><br><br>"; $params_input[$var_name] = $value; $rswrk_params->MoveNext(); } //eseguo l'analisi $params_input['processId'] = (int) $rswrk->fields("processId"); $target = EW_VIDEODROME_SERVER_URL; echo "<br>Method: {$method}<br>Params: <pre>"; var_dump($params_input); echo "</pre>"; $request = Tivoka::createRequest(1, $method, $params_input); start_crono('analysis'); add_log('analyzeBowImage:analysis', "Analysis started. Method: {$method} - Params input: " . serialize($params_input)); Tivoka::connect($target)->send($request); if ($request->isError()) { // an error occured var_dump($request->error); var_dump($request->errorMessage); var_dump($request->response); } else { if ($debug) { var_dump($request->result); } } // the result ?> </pre><br /><br /> <?php break; default: } echo $log; add_log('runPendingProcess:starting REPORT', $log); //se sono al numero massimo di processi in esecuzione contemporanea non ne eseguo più if ($num_process_running >= EW_MAX_PROCESS_IN_EXECUTION) { echo "Numero di processi massimi in esecuzione"; break; } //ho eseguito il primo programma in esecuzione $rswrk->MoveNext(); } if ($rswrk->RecordCount() == 0) { echo "<br><br>No process pending."; //sendTweet(date(DATE_RFC822)." - No process pending"); syncroNewConcept(); } /*$log_activity = "INSERT INTO logs (type,text) VALUES ('runPendingProcess:test_cron','test call');"; $conn->Execute($log_activity); */ } //fine caso di esecuzione processo }
<pre> <?php include '../include.php'; $target = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/server.php'; $request = Tivoka::createRequest('1', 'demo.substract', array(43, 1)); $greeting = Tivoka::createRequest('2', 'demo.sayHello'); Tivoka::connect($target)->send($request, $greeting); /* * Display the Results... */ /* * Display reponse */ if ($request->isError()) { // an error occured var_dump($request->error); var_dump($request->errorMessage); var_dump($request->reponse); } else { var_dump($request->result); } // the result if ($greeting->isError()) { // an error occured var_dump($greeting->error); var_dump($greeting->errorMessage); var_dump($greeting->response); } else { var_dump($greeting->result); } // the result