Example #1
0
    /**
     * @param  string                    $host
     * @param  int                       $port
     * @param  int                       $sendTimeout     msec
     * @param  int                       $recvTimeout     msec
     * @param  bool                      $framedTransport
     * @return \Elasticsearch\RestClient
     */
    protected function _createClient($host, $port, $sendTimeout = null, $recvTimeout = null, $framedTransport = false)
    {
        $socket = new TSocket($host, $port, true);

        if (null !== $sendTimeout) {
            $socket->setSendTimeout($sendTimeout);
        }

        if (null !== $recvTimeout) {
            $socket->setRecvTimeout($recvTimeout);
        }

        if ($framedTransport) {
            $transport = new TFramedTransport($socket);
        } else {
            $transport = new TBufferedTransport($socket);
        }
        $protocol = new TBinaryProtocolAccelerated($transport);

        $client = new RestClient($protocol);

        $transport->open();

        return $client;
    }
 public function __construct($params)
 {
     $servers = $params['servers'];
     $sentTimeout = empty($params['send_timeout']) ? 5000 : $params['send_timeout'];
     //默认5秒
     $recvTimeout = empty($params['recv_timeout']) ? 5000 : $params['recv_timeout'];
     //默认5秒
     $succ = false;
     $i = -1;
     $retry = 3;
     //取消随机选择thrft server,而是按照优先级选择,如果专门提供给web的server挂了
     //再选择爬虫使用的server
     //shuffle($servers);
     while (!$succ && $retry--) {
         $i = ($i + 1) % count($servers);
         $server = $servers[$i];
         try {
             $socket = new TSocket($server['host'], $server['port']);
             $socket->setSendTimeout($sentTimeout);
             $socket->setRecvTimeout($recvTimeout);
             $this->_transport = new TBufferedTransport($socket);
             $protocol = new TBinaryProtocol($this->_transport);
             parent::__construct($protocol);
             $this->_transport->open();
             $succ = true;
         } catch (Exception $e) {
             if ($retry == 1) {
                 $logParams = array('host' => $server['host'], 'port' => $server['port'], 'sent_timeout' => $sentTimeout, 'recv_timeout' => $recvTimeout, 'message' => $e->getMessage());
                 $ci =& get_instance();
                 $ci->log->log('error', 'connect to thrift server failed', $logParams);
                 throw $e;
             }
         }
     }
 }
Example #3
0
 /**
  * Instanciate Socket Client
  *
  * @return Thrift\Transport\TSocket
  */
 protected function createSocket()
 {
     $nbHosts = count($this->config['hosts']);
     if ($nbHosts == 1) {
         $host = current($this->config['hosts']);
         $socket = new TSocket($host['host'], $host['port']);
         if (!empty($host['recvTimeout'])) {
             $socket->setRecvTimeout($host['recvTimeout']);
         }
         if (!empty($host['sendTimeout'])) {
             $socket->setSendTimeout($host['sendTimeout']);
         }
     } else {
         $hosts = array();
         $ports = array();
         foreach ($this->config['hosts'] as $host) {
             $hosts[] = $host['host'];
             $ports[] = $host['port'];
         }
         $socket = new TSocketPool($hosts, $ports);
         if (!empty($host['recvTimeout'])) {
             $socket->setRecvTimeout($host['recvTimeout']);
         }
         if (!empty($host['sendTimeout'])) {
             $socket->setSendTimeout($host['sendTimeout']);
         }
     }
     return $socket;
 }
Example #4
0
function register()
{
    $airavataconfig = parse_ini_file("airavata-client-properties.ini");
    $transport = new TSocket($airavataconfig['AIRAVATA_SERVER'], $airavataconfig['AIRAVATA_PORT']);
    $transport->setSendTimeout($airavataconfig['AIRAVATA_TIMEOUT']);
    $protocol = new TBinaryProtocol($transport);
    $transport->open();
    try {
        $airavataclient = new AiravataClient($protocol);
        $registeredModules = getRegisteredModules($airavataclient);
        $modules = getUnregisteredModules($registeredModules);
        // $modules = getModulesNames();
        echo var_dump($registeredModules);
        echo var_dump($modules);
        if (!empty($modules)) {
            $localhostId = registerLocalHost($airavataclient);
            $moduleids = registerApplicationModule($airavataclient, $modules);
            registerApplicationDeployments($airavataclient, $moduleids, $modules, $localhostId);
            registerApplicationInterfaces($airavataclient, $moduleids, $modules, $localhostId);
            // $host = $airavataclient->registerComputeResource();
        }
    } catch (InvalidRequestException $ire) {
        print 'InvalidRequestException: ' . $ire->getMessage() . "\n";
    } catch (AiravataClientException $ace) {
        print 'Airavata System Exception: ' . $ace->getMessage() . "\n";
    } catch (AiravataSystemException $ase) {
        print 'Airavata System Exception: ' . $ase->getMessage() . "\n";
    }
    $transport->close();
}
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //registering service provider
     $this->app['airavata'] = $this->app->share(function ($app) {
         try {
             $transport = new TSocket(Config::get('pga_config.airavata')['airavata-server'], Config::get('pga_config.airavata')['airavata-port']);
             $transport->setRecvTimeout(Config::get('pga_config.airavata')['airavata-timeout']);
             $transport->setSendTimeout(Config::get('pga_config.airavata')['airavata-timeout']);
             $protocol = new TBinaryProtocol($transport);
             $transport->open();
             $client = new AiravataClient($protocol);
         } catch (\Exception $ex) {
             throw new \Exception("Unable to instantiate Airavata Client", 0, $ex);
         }
         if (is_object($client)) {
             return $client;
         } else {
             throw new \Exception("Unable to instantiate Airavata Client");
         }
     });
     //registering alis
     $this->app->booting(function () {
         $loader = \Illuminate\Foundation\AliasLoader::getInstance();
         $loader->alias('Airavata', 'Airavata\\Facades\\Airavata');
     });
 }
 public function __construct($keyspace, $server, $credentials = null, $framed_transport = True, $send_timeout = null, $recv_timeout = null)
 {
     $this->server = $server;
     $server = explode(':', $server);
     $host = $server[0];
     if (count($server) == 2) {
         $port = (int) $server[1];
     } else {
         $port = self::DEFAULT_PORT;
     }
     $socket = new TSocket($host, $port);
     if ($send_timeout) {
         $socket->setSendTimeout($send_timeout);
     }
     if ($recv_timeout) {
         $socket->setRecvTimeout($recv_timeout);
     }
     if ($framed_transport) {
         $transport = new TFramedTransport($socket, true, true);
     } else {
         $transport = new TBufferedTransport($socket, 1024, 1024);
     }
     $this->client = new CassandraClient(new TBinaryProtocolAccelerated($transport));
     $transport->open();
     $this->set_keyspace($keyspace);
     if ($credentials) {
         $request = new AuthenticationRequest(array("credentials" => $credentials));
         $this->client->login($request);
     }
     $this->keyspace = $keyspace;
     $this->transport = $transport;
     $this->op_count = 0;
 }
 public function getUserAPIClient()
 {
     $transport = new TSocket($this->userapiServerHost, $this->userapiServerPort);
     $transport->setRecvTimeout(5000);
     $transport->setSendTimeout(5000);
     $protocol = new TBinaryProtocol($transport);
     $transport->open();
     return new UserAPIClient($protocol);
 }
Example #8
0
/**
 * @param string $host
 * @param int $port
 */
function get_thrift($class, $host, $port, $timeout){
	$socket = new Thrift\Transport\TSocket($host, $port);  
	$socket->setSendTimeout( $timeout );
	$socket->setRecvTimeout( $timeout );
	$transport = new TBufferedTransport($socket);  
	$transport->open();
	$protocol = new TBinaryProtocol($transport);  
	$client = new $class($protocol);  
	return $client;
}
 private static function _loadClient()
 {
     $socket = new TSocket('182.92.223.200', 9091);
     $socket->setSendTimeout(20000);
     $socket->setRecvTimeout(8000000);
     $transport = new TBufferedTransport($socket);
     $protocol = new TBinaryProtocol($transport);
     $transport->open();
     self::$client = new \Thrift\MT4WebServiceClient($protocol);
     $socket->setDebug(TRUE);
 }
 /**
  * @param string $host
  * @param int    $port
  * @param int    $sendTimeout
  * @param int    $receiveTimeout
  *
  * @return TSocket
  * @author Mario Mueller
  */
 private static function createSocket($host, $port, $sendTimeout, $receiveTimeout)
 {
     $socket = new TSocket($host, $port, true);
     if (null !== $sendTimeout) {
         $socket->setSendTimeout($sendTimeout);
     }
     if (null !== $receiveTimeout) {
         $socket->setRecvTimeout($receiveTimeout);
     }
     return $socket;
 }
Example #11
0
 function __construct($host, $port, $timeout_ms = 300000, $do_open = true)
 {
     $socket = new TSocket($host, $port);
     $socket->setSendTimeout($timeout_ms);
     $socket->setRecvTimeout($timeout_ms);
     $this->transport = new TFramedTransport($socket);
     $protocol = new TBinaryProtocol($this->transport);
     parent::__construct($protocol);
     if ($do_open) {
         $this->open();
     }
 }
Example #12
0
function register()
{
    $gatewayId = $GLOBALS['AIRAVATA_GATEWAY'];
    $transport = new TSocket($GLOBALS['AIRAVATA_SERVER'], $GLOBALS['AIRAVATA_PORT']);
    $transport->setSendTimeout($GLOBALS['AIRAVATA_TIMEOUT']);
    $transport->setRecvTimeout($GLOBALS['AIRAVATA_TIMEOUT']);
    $protocol = new TBinaryProtocol($transport);
    try {
        $transport->open();
        $airavataclient = new AiravataClient($protocol);
        if (!$airavataclient->isGatewayExist($gatewayId)) {
            $gateway = new Gateway();
            $gateway->gatewayId = $gatewayId;
            $gateway->gatewayName = "GeanApp_GateWaay";
            $gateway->domain = $GLOBALS['AIRAVATA_SERVER'];
            $gateway->emailAddress = $GLOBALS['AIRAVATA_EMAIL'];
            $airavataclient->addGateway($gateway);
            registerComputeResourceHost($airavataclient, $GLOBALS['COMPUTE_RESOURCE']);
        } else {
            if (isGatewayRegistered($airavataclient, $gatewayId)) {
                $cmrf = $airavataclient->getGatewayResourceProfile($gatewayId)->computeResourcePreferences;
                registerComputeResourceHost($airavataclient, getUnRegisteredHost($airavataclient, $cmrf));
            } else {
                registerComputeResourceHost($airavataclient, $GLOBALS['COMPUTE_RESOURCE']);
            }
        }
        $hostIds = getHostIds($airavataclient, $gatewayId);
        $registeredModules = getRegisteredModules($airavataclient, $gatewayId);
        $modulesHost = getUnregisteredModules($airavataclient, $registeredModules);
        foreach ($modulesHost as $hostName => $modules) {
            if (!empty($modules)) {
                $moduleids = registerApplicationModule($gatewayId, $airavataclient, $modules);
                registerApplicationDeployments($gatewayId, $airavataclient, $moduleids, $modules, $hostIds[$hostName]);
                registerApplicationInterfaces($gatewayId, $airavataclient, $moduleids, $modules, $hostName);
            }
        }
        $transport->close();
    } catch (InvalidRequestException $ire) {
        echo 'InvalidRequestException: ' . $ire->getMessage();
    } catch (AiravataClientException $ace) {
        echo 'Airavata System Exception: ' . $ace->getMessage();
    } catch (AiravataSystemException $ase) {
        echo 'Airavata System Exception: ' . $ase->getMessage();
    } catch (TException $tx) {
        echo 'There is some connection problem, please check if airavata is runnig properly and try again later';
    } catch (\Exception $e) {
        echo 'Exception: ' . $e->getMessage();
    }
}
Example #13
0
function getClient($host, $port)
{
    $t1 = microtime(true);
    $socket = new TSocket($host, $port);
    $socket->setSendTimeout(10000);
    $socket->setRecvTimeout(10000);
    $transport = new TBufferedTransport($socket, 1024, 1024);
    $transport->open();
    $protocol = new TBinaryProtocol($transport);
    $client = new \KrunchyKreme\KrunchyKremeClient($protocol);
    $t2 = microtime(true);
    $timeTaken = round($t2 - $t1, 3);
    echo 'Time taken to connect: ' . $timeTaken . "\n";
    return $client;
}
Example #14
0
require_once $GLOBALS['THRIFT_ROOT'] . '/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Protocol/TBinaryProtocol.php';
require_once 'thrift/lib/HBase/Hbase.php';
require_once 'thrift/lib/HBase/Types.php';
use Thrift\Transport\TSocket;
use Thrift\Transport\TBufferedTransport;
use Thrift\Protocol\TBinaryProtocol;
use Hbase\HbaseClient;
//use Hbase\ColumnDescriptor;
use Hbase\Mutation;
use Hbase\TScan;
$socket = new TSocket('localhost', 9090);
$socket->setSendTimeout(10000);
// Ten seconds (too long for production, but this is just a demo ;)
$socket->setRecvTimeout(20000);
// Twenty seconds
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new HbaseClient($protocol);
try {
    $transport->open();
    $table = 'note';
    $filter = "QualifierFilter(>=, 'binary:1500')";
    // greater than 1500
    $scan = new TScan(array('startRow' => 'rowkey-1', 'stopRow' => 'rowkey-2', 'filterString' => $filter, 'sortColumns' => true));
    $scanid = $client->scannerOpenWithScan($table, $scan, null);
    $rowresult = $client->scannerGet($scanid);
    // print_r($rowresult);
require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/Core.php';
$GLOBALS['AIRAVATA_ROOT'] = 'lib/Airavata/';
// $GLOBALS['AIRAVATA_ROOT'] = $airavataconfig['AIRAVATA_PHP_STUBS_DIR'];
require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Airavata.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Error/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/Workspace/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/Workspace/Experiment/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/AppCatalog/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/AppCatalog/ComputeResource/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/AppCatalog/AppDeployment/Types.php';
require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/AppCatalog/AppInterface/Types.php';
use Airavata\API\Error\AiravataClientException;
use Airavata\API\Error\AiravataSystemException;
use Airavata\API\Error\InvalidRequestException;
use Airavata\Client\AiravataClientFactory;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TBufferedTransport;
use Thrift\Transport\TSocket;
use Airavata\API\AiravataClient;
$transport = new TSocket($airavataconfig['AIRAVATA_SERVER'], $airavataconfig['AIRAVATA_PORT']);
$transport->setRecvTimeout($airavataconfig['AIRAVATA_TIMEOUT']);
$transport->setSendTimeout($airavataconfig['AIRAVATA_TIMEOUT']);
$protocol = new TBinaryProtocol($transport);
$transport->open();
$airavataclient = new AiravataClient($protocol);
// function sampleDisabled()
// {
// 	echo "The execution of this script is disabled so the XSEDE 14 tutorial will remain coherent. The code is complete and will illustrate the usage of the API. \n";
// 	exit(0);
// }
/**
 * Return an Airavata client
 * @return AiravataClient
 */
function get_airavata_client()
{
    try {
        $transport = new TSocket(AIRAVATA_SERVER, AIRAVATA_PORT);
        $transport->setRecvTimeout(AIRAVATA_TIMEOUT);
        $transport->setSendTimeout(AIRAVATA_TIMEOUT);
        $protocol = new TBinaryProtocol($transport);
        $transport->open();
        $client = new AiravataClient($protocol);
    } catch (Exception $e) {
        print_error_message('<p>There was a problem connecting to Airavata.
            Please try again later or submit a bug report using the link in the Help menu.</p>' . '<p>' . $e->getMessage() . '</p>');
    }
    return $client;
}
Example #17
0
 public function setSendTimeout($timeout)
 {
     $this->_sendTimeoutMs = $timeout;
     parent::setSendTimeout($timeout);
 }
Example #18
0
require_once __DIR__ . '/Thrift/ClassLoader/ThriftClassLoader.php';
require_once __DIR__ . '/Gen/TTGService.php';
require_once __DIR__ . '/Gen/Types.php';
use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TBufferedTransport;
// Load
$loader = new ThriftClassLoader();
$loader->registerNamespace('Thrift', __DIR__ . '/');
$loader->registerDefinition('TTG', __DIR__ . '/Gen');
$loader->register();
// Init
$socket = new TSocket('127.0.0.1', 9090);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocol($transport);
$client = new TTGServiceClient($protocol);
// Config
$socket->setSendTimeout(30 * 1000);
$socket->setRecvTimeout(30 * 1000);
// Connect
$transport->open();
// Create request
$request = new Request();
$request->studentID = 100;
// Call...
$response = $client->getStudentInfo($request);
// Print response...
var_dump($response);
// Close
$transport->close();
Example #19
0
function getOutput($expId)
{
    $transport = new TSocket($GLOBALS['AIRAVATA_SERVER'], $GLOBALS['AIRAVATA_PORT']);
    $transport->setSendTimeout($GLOBALS['AIRAVATA_TIMEOUT']);
    $protocol = new TBinaryProtocol($transport);
    $errors = array('CANCELED' => "Experiment Cancelled", 'SUSPENDED' => "Experiment Suspended", 'FAILED' => "Experiment Failed");
    try {
        $airavataclient = new AiravataClient($protocol);
        $transport->open();
        while (($status = get_experiment_status($airavataclient, $expId)) != "COMPLETED") {
            if (isset($errors[$status])) {
                $transport->close();
                return "{\"error\":\"" . $errors[$status] . "\"}";
                exit;
            }
            sleep(1);
        }
        $outputs = $airavataclient->getExperimentOutputs($expId);
        $transport->close();
        $outputData = array();
        if (!empty($outputs[0]->value)) {
            $out = json_decode($outputs[0]->value);
            $out->Computational_Host = $GLOBALS["RESOURCE_HOST"];
            $outputData["output"] = json_encode($out);
        } else {
            $outputData["error"] = $outputs[1]->value;
        }
    } catch (InvalidRequestException $ire) {
        $outputData["error"] = 'InvalidRequestException: ' . $ire->getMessage();
    } catch (AiravataClientException $ace) {
        $outputData["error"] = 'Airavata System Exception: ' . $ace->getMessage();
    } catch (AiravataSystemException $ase) {
        $outputData["error"] = 'Airavata System Exception: ' . $ase->getMessage();
    } catch (TException $tx) {
        $outputData["error"] = 'Exception: ' . $tx->getMessage();
    } catch (ExperimentNotFoundException $enf) {
        $outputData["error"] = 'ExperimentNotFoundException: ' . $enf->getMessage();
    } catch (TTransportException $tte) {
        $outputData["error"] = 'TTransportException: ' . $tte->getMessage();
    } catch (\Exception $e) {
        $outputData["error"] = 'Exception: ' . $e->getMessage();
    }
    return json_encode($outputData);
}