예제 #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;
    }
 /**
  * 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');
     });
 }
예제 #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;
 }
예제 #4
0
 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;
             }
         }
     }
 }
예제 #5
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();
}
 public function getAiravataClient()
 {
     $transport = new TSocket($this->airavataServerHost, $this->airavataServerPort);
     $protocol = new TBinaryProtocol($transport);
     $transport->open();
     return new AiravataClient($protocol);
 }
예제 #7
0
 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);
 }
예제 #9
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;
}
예제 #10
0
 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;
 }
예제 #12
0
 /**
  * 获得一个client
  */
 public static function getClient()
 {
     if (self::$client == NULL) {
         $socket = new TSocket(self::HOST, self::PORT);
         $socket->setRecvTimeout(10 * 1000);
         self::$transport = new TBufferedTransport($socket);
         $protocol = new TBinaryProtocol(self::$transport);
         self::$client = new \Hbase\HbaseClient($protocol);
     }
     return self::$client;
 }
예제 #13
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();
     }
 }
예제 #14
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();
    }
}
예제 #15
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;
}
예제 #16
0
 /**
  * Implementation of accept. If not client is accepted in the given time
  *
  * @return TSocket
  */
 protected function acceptImpl()
 {
     $handle = @stream_socket_accept($this->listener_, $this->acceptTimeout_ / 1000.0);
     if (!$handle) {
         return null;
     }
     $socket = new TSocket();
     $socket->setHandle($handle);
     return $socket;
 }
예제 #17
0
 /**
  * Connects the socket by iterating through all the servers in the pool
  * and trying to find one that works.
  */
 public function open()
 {
     // Check if we want order randomization
     if ($this->randomize_) {
         shuffle($this->servers_);
     }
     // Count servers to identify the "last" one
     $numServers = count($this->servers_);
     for ($i = 0; $i < $numServers; ++$i) {
         // This extracts the $host and $port variables
         extract($this->servers_[$i]);
         // Check APC cache for a record of this server being down
         $failtimeKey = 'thrift_failtime:' . $host . ':' . $port . '~';
         // Cache miss? Assume it's OK
         $lastFailtime = apc_fetch($failtimeKey);
         if ($lastFailtime === FALSE) {
             $lastFailtime = 0;
         }
         $retryIntervalPassed = false;
         // Cache hit...make sure enough the retry interval has elapsed
         if ($lastFailtime > 0) {
             $elapsed = time() - $lastFailtime;
             if ($elapsed > $this->retryInterval_) {
                 $retryIntervalPassed = true;
                 if ($this->debug_) {
                     call_user_func($this->debugHandler_, 'TSocketPool: retryInterval ' . '(' . $this->retryInterval_ . ') ' . 'has passed for host ' . $host . ':' . $port);
                 }
             }
         }
         // Only connect if not in the middle of a fail interval, OR if this
         // is the LAST server we are trying, just hammer away on it
         $isLastServer = false;
         if ($this->alwaysTryLast_) {
             $isLastServer = $i == $numServers - 1;
         }
         if ($lastFailtime === 0 || $isLastServer || $lastFailtime > 0 && $retryIntervalPassed) {
             // Set underlying TSocket params to this one
             $this->host_ = $host;
             $this->port_ = $port;
             // Try up to numRetries_ connections per server
             for ($attempt = 0; $attempt < $this->numRetries_; $attempt++) {
                 try {
                     // Use the underlying TSocket open function
                     parent::open();
                     // Only clear the failure counts if required to do so
                     if ($lastFailtime > 0) {
                         apc_store($failtimeKey, 0);
                     }
                     // Successful connection, return now
                     return;
                 } catch (TException $tx) {
                     // Connection failed
                 }
             }
             // Mark failure of this host in the cache
             $consecfailsKey = 'thrift_consecfails:' . $host . ':' . $port . '~';
             // Ignore cache misses
             $consecfails = apc_fetch($consecfailsKey);
             if ($consecfails === FALSE) {
                 $consecfails = 0;
             }
             // Increment by one
             $consecfails++;
             // Log and cache this failure
             if ($consecfails >= $this->maxConsecutiveFailures_) {
                 if ($this->debug_) {
                     call_user_func($this->debugHandler_, 'TSocketPool: marking ' . $host . ':' . $port . ' as down for ' . $this->retryInterval_ . ' secs ' . 'after ' . $consecfails . ' failed attempts.');
                 }
                 // Store the failure time
                 apc_store($failtimeKey, time());
                 // Clear the count of consecutive failures
                 apc_store($consecfailsKey, 0);
             } else {
                 apc_store($consecfailsKey, $consecfails);
             }
         }
     }
     // Oh no; we failed them all. The system is totally ill!
     $error = 'TSocketPool: All hosts in pool are down. ';
     $hosts = array();
     foreach ($this->servers_ as $server) {
         $hosts[] = $server['host'] . ':' . $server['port'];
     }
     $hostlist = implode(',', $hosts);
     $error .= '(' . $hostlist . ')';
     if ($this->debug_) {
         call_user_func($this->debugHandler_, $error);
     }
     throw new TException($error);
 }
예제 #18
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;
}
예제 #19
0
 /**
  * 处理受到的数据
  * @param TcpConnection $connection
  * @return void
  */
 public function onConnect($connection)
 {
     $socket = $connection->getSocket();
     $t_socket = new TSocket();
     $t_socket->setHandle($socket);
     $transport_name = '\\Thrift\\Transport\\' . $this->thriftTransport;
     $transport = new $transport_name($t_socket);
     $protocol_name = '\\Thrift\\Protocol\\' . $this->thriftProtocol;
     $protocol = new $protocol_name($transport);
     // 执行处理
     try {
         // 先初始化一个
         $protocol->fname == 'none';
         // 统计开始时间
         StatisticClient::tick();
         // 业务处理
         $this->processor->process($protocol, $protocol);
         StatisticClient::report($this->name, $protocol->fname, 1, 0, '', $this->statisticAddress);
     } catch (\Exception $e) {
         StatisticClient::report($this->name, $protocol->fname, 0, $e->getCode(), $e, $this->statisticAddress);
         ThriftWorker::log('CODE:' . $e->getCode() . ' MESSAGE:' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\nCLIENT_IP:" . $connection->getRemoteIp() . "\n");
         $connection->send($e->getMessage());
     }
 }
예제 #20
0
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);
// }
예제 #21
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);
}
예제 #22
0
파일: DalSocket.php 프로젝트: packaged/dal
 public function setSendTimeout($timeout)
 {
     $this->_sendTimeoutMs = $timeout;
     parent::setSendTimeout($timeout);
 }
예제 #23
0
error_reporting(E_ALL);
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);
예제 #24
0
require_once $GLOBALS['THRIFT_ROOT'] . '/Factory/TStringFuncFactory.php';
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);
예제 #25
0
 public function actionIndex1()
 {
     require_once dirname(\Yii::$app->basePath) . '/Hbase/Hbase.php';
     require_once dirname(\Yii::$app->basePath) . '/Hbase/Types.php';
     //'/Hbase/THBaseService.php';
     /*         * *
               Thrift Test
     
              */
     $host = '192.168.186.128';
     $port = 9090;
     $socket = new TSocket($host, $port);
     $socket->setRecvTimeout(10 * 1000);
     $transport = new TBufferedTransport($socket);
     $protocol = new TBinaryProtocol($transport);
     // Create a client
     $client = new \Hbase\HbaseClient($protocol);
     $transport->open();
     //获得数据表
     //$tables = $client->getTableNames();
     //创建一个表
     //定义列名
     $tableName = 'messages';
     //$aritcle = new \Hbase\ColumnDescriptor(array('name' => 'aritcle:'));
     //$author = new \Hbase\ColumnDescriptor(array('name' => 'author:'));
     //$columns = array($aritcle, $author);
     //try {
     //    $client->createTable($tableName, $columns);
     //} catch (\Hbase\AlreadyExists $ex) {
     //    echo '表已经存在,不能重复创建';
     //}
     //删除已经存在的表
     //向表内插入数据
     //for ($i = 0; $i < 10000; $i++) {
     //    $record = array(new \Hbase\Mutation(array('column' => 'aritcle:title', 'value' => $i)));
     //    $client->mutateRow($tableName, $i, $record,[]);
     //}
     //获得数据
     $arr = $client->get($tableName, 2, 'aritcle:title', []);
     // $arr = array
     foreach ($arr as $k => $v) {
         // $k = TCell
         echo "value = {$v->value} , <br>  ";
         echo "timestamp = {$v->timestamp}  <br>";
     }
     $transport->close();
     exit;
     //HOW TO GET
     $tableName = "test_table";
     $column_1 = new \TColumn();
     $column_1->family = 'cf1';
     $column_1->qualifier = 'q1';
     $column_2 = new \TColumn();
     $column_2->family = 'cf1';
     $column_2->qualifier = 'q2';
     $columnArray = array($column_1, $column_2);
     $get = new \TGet();
     $get->row = 'a';
     $get->columns = $columnArray;
     if ($client->exists($tableName, $get)) {
         echo 'Yes';
     } else {
         echo 'No';
     }
     exit;
     print_r($tables);
     exit;
     $arr = $client->get($tableName, $get);
     $results = $arr->columnValues;
     foreach ($results as $result) {
         $qualifier = (string) $result->qualifier;
         $value = $result->value;
         print_r($qualifier);
         print_r($value);
     }
     //HOW TO SCAN
     $scan = new \TScan();
     $scan->startRow = 'a';
     $scan->stopRow = 'z';
     $scan->columns = $columnArray;
     $num = 1000;
     $scanRets = $client->getScannerRows($scanId, $num);
     foreach ($scanRets as $scanRet) {
         $scan_row = $scanRet->row;
         $scan_cols = $scanRet->columnValues;
         print_r($scan_row);
         print_r($scan_cols);
     }
     $client->closeScanner($scanId);
     $transport->close();
     echo 11;
     exit;
 }