Repository: airavata Updated Branches: refs/heads/master bf37ea8ec -> 5b6e610b2
Improvements to the PHP Client - AIRAVATA-1064 Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/1441a831 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/1441a831 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/1441a831 Branch: refs/heads/master Commit: 1441a8317967fc0f8b84b515d4d87dd78ca3e31a Parents: e8a6d41 Author: Suresh Marru <[email protected]> Authored: Thu Mar 13 07:19:19 2014 -0400 Committer: Suresh Marru <[email protected]> Committed: Thu Mar 13 07:19:19 2014 -0400 ---------------------------------------------------------------------- .../client-samples/GetAiravataVersion.php | 17 + .../client-samples/airavata-client-sample.php | 73 ++ .../lib/AiravataClientFactory.php | 45 ++ .../airavata-php-sdk/lib/Thrift/Thrift.php | 789 +++++++++++++++++++ .../airavata-php-sdk/lib/Thrift/autoload.php | 51 ++ 5 files changed, 975 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/1441a831/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/GetAiravataVersion.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/GetAiravataVersion.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/GetAiravataVersion.php new file mode 100644 index 0000000..12e0b8a --- /dev/null +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/GetAiravataVersion.php @@ -0,0 +1,17 @@ +<?php + +//use Airavata\Client; + +ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . "../lib" . PATH_SEPARATOR . + "../lib/Thrift" . PATH_SEPARATOR . "../lib/Airavata/" . PATH_SEPARATOR); +require_once 'autoload.php'; + +require_once 'AiravataClientFactory.php'; + +use Airavata\Client\AiravataClientFactory; + +$airavataClientFactory = new AiravataClientFactory(array('airavataServerHost' => "gw111.iu.xsede.org", 'airavataServerPort' => "8930")); + +$airavata = $airavataClientFactory->getAiravataClient(); + +echo "Airavata Server Version is: " . $airavata->GetAPIVersion(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1441a831/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/airavata-client-sample.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/airavata-client-sample.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/airavata-client-sample.php new file mode 100644 index 0000000..90ae37a --- /dev/null +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/client-samples/airavata-client-sample.php @@ -0,0 +1,73 @@ +<?php +namespace Airavata\Client\Samples; + +$GLOBALS['THRIFT_ROOT'] = '../lib/Thrift/'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TTransport.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TSocket.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TProtocol.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TBinaryProtocol.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TException.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TApplicationException.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TProtocolException.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Base/TBase.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TType.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TMessageType.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Factory/TStringFuncFactory.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/TStringFunc.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/Core.php'; + +$GLOBALS['AIRAVATA_ROOT'] = '../lib/Airavata/'; +require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Airavata.php'; +require_once $GLOBALS['AIRAVATA_ROOT'] . 'Model/Workspace/Experiment/Types.php'; +require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Error/Types.php'; + +use Airavata\Model\Workspace\Experiment\ComputationalResourceScheduling; +use Airavata\Model\Workspace\Experiment\DataObjectType; +use Airavata\Model\Workspace\Experiment\UserConfigurationData; +use Thrift\Protocol\TBinaryProtocol; +use Thrift\Transport\TSocket; +use Airavata\API\AiravataClient; +use Airavata\Model\Workspace\Experiment\Experiment; + +$transport = new TSocket('gw111.iu.xsede.org', 8930); +$protocol = new TBinaryProtocol($transport); + +$airavataclient = new AiravataClient($protocol); +$transport->open(); + +echo "Airavata Server Version is: " . $airavataclient->GetAPIVersion(); + +//Create a Experiment +$experiment = new Experiment(); +$experiment->name = "Test Experiment"; +$experiment->userName = "TestUser"; +$experiment->projectID = "TestProject"; + +$experimentInputs = new DataObjectType; +$experimentInputs->key = "echo_input"; +$experimentInputs->value = "echo_output=Hello World"; + +$experiment->applicationId = "SimpleEcho2"; +$experiment->experimentInputs = $experimentInputs; + +$scheduling = new ComputationalResourceScheduling; +$scheduling->resourceHostId = "gsissh-trestles"; + +$userConfigData = new UserConfigurationData; +$userConfigData->computationalResourceScheduling = $scheduling; +$experiment->userConfigurationData = $userConfigData; + + +try { + + echo "Experiment Id created is: " . $airavataclient->createExperiment($experiment); + +} catch (TException $texp) { + print 'Exception: ' . $texp->getMessage()."\n"; +} catch (AiravataSystemException $ase) { + print 'Airavata System Exception: ' . $ase->getMessage()."\n"; +} +$transport->close(); + +?> + http://git-wip-us.apache.org/repos/asf/airavata/blob/1441a831/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/AiravataClientFactory.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/AiravataClientFactory.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/AiravataClientFactory.php new file mode 100644 index 0000000..7af7562 --- /dev/null +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/AiravataClientFactory.php @@ -0,0 +1,45 @@ +<?php + +namespace Airavata\Client; + +$GLOBALS['THRIFT_ROOT'] = 'Thrift/'; +//require_once $GLOBALS['THRIFT_ROOT'] . 'Thrift.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TTransport.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Transport/TSocket.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TProtocol.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Protocol/TBinaryProtocol.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TException.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Exception/TTransportException.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TType.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Type/TMessageType.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'Factory/TStringFuncFactory.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/TStringFunc.php'; +require_once $GLOBALS['THRIFT_ROOT'] . 'StringFunc/Core.php'; + +$GLOBALS['AIRAVATA_ROOT'] = 'Airavata/'; +require_once $GLOBALS['AIRAVATA_ROOT'] . 'API/Airavata.php'; + +use Thrift\Protocol\TBinaryProtocol; +use Thrift\Transport\TSocket; +use Airavata\API\AiravataClient; + +class AiravataClientFactory +{ + + private $airavataServerHost; + private $airavataServerPort; + + public function __construct($options) + { + $this->airavataServerHost = isset($options['airavataServerHost']) ? $options['airavataServerHost'] : null; + $this->airavataServerPort = isset($options['airavataServerPort']) ? $options['airavataServerPort'] : null; + } + + public function getAiravataClient() + { + $transport = new TSocket('$airavataServerHost', '$airavataServerPort'); + $protocol = new TBinaryProtocol($transport); + + return new AiravataClient($protocol); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/1441a831/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/Thrift.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/Thrift.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/Thrift.php new file mode 100644 index 0000000..c845395 --- /dev/null +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/Thrift.php @@ -0,0 +1,789 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * @package thrift + */ + + +/** + * Data types that can be sent via Thrift + */ +class TType { + const STOP = 0; + const VOID = 1; + const BOOL = 2; + const BYTE = 3; + const I08 = 3; + const DOUBLE = 4; + const I16 = 6; + const I32 = 8; + const I64 = 10; + const STRING = 11; + const UTF7 = 11; + const STRUCT = 12; + const MAP = 13; + const SET = 14; + const LST = 15; // N.B. cannot use LIST keyword in PHP! + const UTF8 = 16; + const UTF16 = 17; +} + +/** + * Message types for RPC + */ +class TMessageType { + const CALL = 1; + const REPLY = 2; + const EXCEPTION = 3; + const ONEWAY = 4; +} + +/** + * NOTE(mcslee): This currently contains a ton of duplicated code from TBase + * because we need to save CPU cycles and this is not yet in an extension. + * Ideally we'd multiply-inherit TException from both Exception and Base, but + * that's not possible in PHP and there are no modules either, so for now we + * apologetically take a trip to HackTown. + * + * Can be called with standard Exception constructor (message, code) or with + * Thrift Base object constructor (spec, vals). + * + * @param mixed $p1 Message (string) or type-spec (array) + * @param mixed $p2 Code (integer) or values (array) + */ +class TException extends Exception { + function __construct($p1=null, $p2=0) { + if (is_array($p1) && is_array($p2)) { + $spec = $p1; + $vals = $p2; + foreach ($spec as $fid => $fspec) { + $var = $fspec['var']; + if (isset($vals[$var])) { + $this->$var = $vals[$var]; + } + } + } else { + parent::__construct($p1, $p2); + } + } + + static $tmethod = array(TType::BOOL => 'Bool', + TType::BYTE => 'Byte', + TType::I16 => 'I16', + TType::I32 => 'I32', + TType::I64 => 'I64', + TType::DOUBLE => 'Double', + TType::STRING => 'String'); + + private function _readMap(&$var, $spec, $input) { + $xfer = 0; + $ktype = $spec['ktype']; + $vtype = $spec['vtype']; + $kread = $vread = null; + if (isset(TBase::$tmethod[$ktype])) { + $kread = 'read'.TBase::$tmethod[$ktype]; + } else { + $kspec = $spec['key']; + } + if (isset(TBase::$tmethod[$vtype])) { + $vread = 'read'.TBase::$tmethod[$vtype]; + } else { + $vspec = $spec['val']; + } + $var = array(); + $_ktype = $_vtype = $size = 0; + $xfer += $input->readMapBegin($_ktype, $_vtype, $size); + for ($i = 0; $i < $size; ++$i) { + $key = $val = null; + if ($kread !== null) { + $xfer += $input->$kread($key); + } else { + switch ($ktype) { + case TType::STRUCT: + $class = $kspec['class']; + $key = new $class(); + $xfer += $key->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($key, $kspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($key, $kspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($key, $kspec, $input, true); + break; + } + } + if ($vread !== null) { + $xfer += $input->$vread($val); + } else { + switch ($vtype) { + case TType::STRUCT: + $class = $vspec['class']; + $val = new $class(); + $xfer += $val->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($val, $vspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($val, $vspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($val, $vspec, $input, true); + break; + } + } + $var[$key] = $val; + } + $xfer += $input->readMapEnd(); + return $xfer; + } + + private function _readList(&$var, $spec, $input, $set=false) { + $xfer = 0; + $etype = $spec['etype']; + $eread = $vread = null; + if (isset(TBase::$tmethod[$etype])) { + $eread = 'read'.TBase::$tmethod[$etype]; + } else { + $espec = $spec['elem']; + } + $var = array(); + $_etype = $size = 0; + if ($set) { + $xfer += $input->readSetBegin($_etype, $size); + } else { + $xfer += $input->readListBegin($_etype, $size); + } + for ($i = 0; $i < $size; ++$i) { + $elem = null; + if ($eread !== null) { + $xfer += $input->$eread($elem); + } else { + $espec = $spec['elem']; + switch ($etype) { + case TType::STRUCT: + $class = $espec['class']; + $elem = new $class(); + $xfer += $elem->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($elem, $espec, $input); + break; + case TType::LST: + $xfer += $this->_readList($elem, $espec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($elem, $espec, $input, true); + break; + } + } + if ($set) { + $var[$elem] = true; + } else { + $var []= $elem; + } + } + if ($set) { + $xfer += $input->readSetEnd(); + } else { + $xfer += $input->readListEnd(); + } + return $xfer; + } + + protected function _read($class, $spec, $input) { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + if (isset($spec[$fid])) { + $fspec = $spec[$fid]; + $var = $fspec['var']; + if ($ftype == $fspec['type']) { + $xfer = 0; + if (isset(TBase::$tmethod[$ftype])) { + $func = 'read'.TBase::$tmethod[$ftype]; + $xfer += $input->$func($this->$var); + } else { + switch ($ftype) { + case TType::STRUCT: + $class = $fspec['class']; + $this->$var = new $class(); + $xfer += $this->$var->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($this->$var, $fspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($this->$var, $fspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($this->$var, $fspec, $input, true); + break; + } + } + } else { + $xfer += $input->skip($ftype); + } + } else { + $xfer += $input->skip($ftype); + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + private function _writeMap($var, $spec, $output) { + $xfer = 0; + $ktype = $spec['ktype']; + $vtype = $spec['vtype']; + $kwrite = $vwrite = null; + if (isset(TBase::$tmethod[$ktype])) { + $kwrite = 'write'.TBase::$tmethod[$ktype]; + } else { + $kspec = $spec['key']; + } + if (isset(TBase::$tmethod[$vtype])) { + $vwrite = 'write'.TBase::$tmethod[$vtype]; + } else { + $vspec = $spec['val']; + } + $xfer += $output->writeMapBegin($ktype, $vtype, count($var)); + foreach ($var as $key => $val) { + if (isset($kwrite)) { + $xfer += $output->$kwrite($key); + } else { + switch ($ktype) { + case TType::STRUCT: + $xfer += $key->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($key, $kspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($key, $kspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($key, $kspec, $output, true); + break; + } + } + if (isset($vwrite)) { + $xfer += $output->$vwrite($val); + } else { + switch ($vtype) { + case TType::STRUCT: + $xfer += $val->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($val, $vspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($val, $vspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($val, $vspec, $output, true); + break; + } + } + } + $xfer += $output->writeMapEnd(); + return $xfer; + } + + private function _writeList($var, $spec, $output, $set=false) { + $xfer = 0; + $etype = $spec['etype']; + $ewrite = null; + if (isset(TBase::$tmethod[$etype])) { + $ewrite = 'write'.TBase::$tmethod[$etype]; + } else { + $espec = $spec['elem']; + } + if ($set) { + $xfer += $output->writeSetBegin($etype, count($var)); + } else { + $xfer += $output->writeListBegin($etype, count($var)); + } + foreach ($var as $key => $val) { + $elem = $set ? $key : $val; + if (isset($ewrite)) { + $xfer += $output->$ewrite($elem); + } else { + switch ($etype) { + case TType::STRUCT: + $xfer += $elem->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($elem, $espec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($elem, $espec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($elem, $espec, $output, true); + break; + } + } + } + if ($set) { + $xfer += $output->writeSetEnd(); + } else { + $xfer += $output->writeListEnd(); + } + return $xfer; + } + + protected function _write($class, $spec, $output) { + $xfer = 0; + $xfer += $output->writeStructBegin($class); + foreach ($spec as $fid => $fspec) { + $var = $fspec['var']; + if ($this->$var !== null) { + $ftype = $fspec['type']; + $xfer += $output->writeFieldBegin($var, $ftype, $fid); + if (isset(TBase::$tmethod[$ftype])) { + $func = 'write'.TBase::$tmethod[$ftype]; + $xfer += $output->$func($this->$var); + } else { + switch ($ftype) { + case TType::STRUCT: + $xfer += $this->$var->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($this->$var, $fspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($this->$var, $fspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($this->$var, $fspec, $output, true); + break; + } + } + $xfer += $output->writeFieldEnd(); + } + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } + +} + +/** + * Base class from which other Thrift structs extend. This is so that we can + * cut back on the size of the generated code which is turning out to have a + * nontrivial cost just to load thanks to the wondrously abysmal implementation + * of PHP. Note that code is intentionally duplicated in here to avoid making + * function calls for every field or member of a container.. + */ +abstract class TBase { + + static $tmethod = array(TType::BOOL => 'Bool', + TType::BYTE => 'Byte', + TType::I16 => 'I16', + TType::I32 => 'I32', + TType::I64 => 'I64', + TType::DOUBLE => 'Double', + TType::STRING => 'String'); + + abstract function read($input); + + abstract function write($output); + + public function __construct($spec=null, $vals=null) { + if (is_array($spec) && is_array($vals)) { + foreach ($spec as $fid => $fspec) { + $var = $fspec['var']; + if (isset($vals[$var])) { + $this->$var = $vals[$var]; + } + } + } + } + + private function _readMap(&$var, $spec, $input) { + $xfer = 0; + $ktype = $spec['ktype']; + $vtype = $spec['vtype']; + $kread = $vread = null; + if (isset(TBase::$tmethod[$ktype])) { + $kread = 'read'.TBase::$tmethod[$ktype]; + } else { + $kspec = $spec['key']; + } + if (isset(TBase::$tmethod[$vtype])) { + $vread = 'read'.TBase::$tmethod[$vtype]; + } else { + $vspec = $spec['val']; + } + $var = array(); + $_ktype = $_vtype = $size = 0; + $xfer += $input->readMapBegin($_ktype, $_vtype, $size); + for ($i = 0; $i < $size; ++$i) { + $key = $val = null; + if ($kread !== null) { + $xfer += $input->$kread($key); + } else { + switch ($ktype) { + case TType::STRUCT: + $class = $kspec['class']; + $key = new $class(); + $xfer += $key->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($key, $kspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($key, $kspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($key, $kspec, $input, true); + break; + } + } + if ($vread !== null) { + $xfer += $input->$vread($val); + } else { + switch ($vtype) { + case TType::STRUCT: + $class = $vspec['class']; + $val = new $class(); + $xfer += $val->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($val, $vspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($val, $vspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($val, $vspec, $input, true); + break; + } + } + $var[$key] = $val; + } + $xfer += $input->readMapEnd(); + return $xfer; + } + + private function _readList(&$var, $spec, $input, $set=false) { + $xfer = 0; + $etype = $spec['etype']; + $eread = $vread = null; + if (isset(TBase::$tmethod[$etype])) { + $eread = 'read'.TBase::$tmethod[$etype]; + } else { + $espec = $spec['elem']; + } + $var = array(); + $_etype = $size = 0; + if ($set) { + $xfer += $input->readSetBegin($_etype, $size); + } else { + $xfer += $input->readListBegin($_etype, $size); + } + for ($i = 0; $i < $size; ++$i) { + $elem = null; + if ($eread !== null) { + $xfer += $input->$eread($elem); + } else { + $espec = $spec['elem']; + switch ($etype) { + case TType::STRUCT: + $class = $espec['class']; + $elem = new $class(); + $xfer += $elem->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($elem, $espec, $input); + break; + case TType::LST: + $xfer += $this->_readList($elem, $espec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($elem, $espec, $input, true); + break; + } + } + if ($set) { + $var[$elem] = true; + } else { + $var []= $elem; + } + } + if ($set) { + $xfer += $input->readSetEnd(); + } else { + $xfer += $input->readListEnd(); + } + return $xfer; + } + + protected function _read($class, $spec, $input) { + $xfer = 0; + $fname = null; + $ftype = 0; + $fid = 0; + $xfer += $input->readStructBegin($fname); + while (true) { + $xfer += $input->readFieldBegin($fname, $ftype, $fid); + if ($ftype == TType::STOP) { + break; + } + if (isset($spec[$fid])) { + $fspec = $spec[$fid]; + $var = $fspec['var']; + if ($ftype == $fspec['type']) { + $xfer = 0; + if (isset(TBase::$tmethod[$ftype])) { + $func = 'read'.TBase::$tmethod[$ftype]; + $xfer += $input->$func($this->$var); + } else { + switch ($ftype) { + case TType::STRUCT: + $class = $fspec['class']; + $this->$var = new $class(); + $xfer += $this->$var->read($input); + break; + case TType::MAP: + $xfer += $this->_readMap($this->$var, $fspec, $input); + break; + case TType::LST: + $xfer += $this->_readList($this->$var, $fspec, $input, false); + break; + case TType::SET: + $xfer += $this->_readList($this->$var, $fspec, $input, true); + break; + } + } + } else { + $xfer += $input->skip($ftype); + } + } else { + $xfer += $input->skip($ftype); + } + $xfer += $input->readFieldEnd(); + } + $xfer += $input->readStructEnd(); + return $xfer; + } + + private function _writeMap($var, $spec, $output) { + $xfer = 0; + $ktype = $spec['ktype']; + $vtype = $spec['vtype']; + $kwrite = $vwrite = null; + if (isset(TBase::$tmethod[$ktype])) { + $kwrite = 'write'.TBase::$tmethod[$ktype]; + } else { + $kspec = $spec['key']; + } + if (isset(TBase::$tmethod[$vtype])) { + $vwrite = 'write'.TBase::$tmethod[$vtype]; + } else { + $vspec = $spec['val']; + } + $xfer += $output->writeMapBegin($ktype, $vtype, count($var)); + foreach ($var as $key => $val) { + if (isset($kwrite)) { + $xfer += $output->$kwrite($key); + } else { + switch ($ktype) { + case TType::STRUCT: + $xfer += $key->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($key, $kspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($key, $kspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($key, $kspec, $output, true); + break; + } + } + if (isset($vwrite)) { + $xfer += $output->$vwrite($val); + } else { + switch ($vtype) { + case TType::STRUCT: + $xfer += $val->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($val, $vspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($val, $vspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($val, $vspec, $output, true); + break; + } + } + } + $xfer += $output->writeMapEnd(); + return $xfer; + } + + private function _writeList($var, $spec, $output, $set=false) { + $xfer = 0; + $etype = $spec['etype']; + $ewrite = null; + if (isset(TBase::$tmethod[$etype])) { + $ewrite = 'write'.TBase::$tmethod[$etype]; + } else { + $espec = $spec['elem']; + } + if ($set) { + $xfer += $output->writeSetBegin($etype, count($var)); + } else { + $xfer += $output->writeListBegin($etype, count($var)); + } + foreach ($var as $key => $val) { + $elem = $set ? $key : $val; + if (isset($ewrite)) { + $xfer += $output->$ewrite($elem); + } else { + switch ($etype) { + case TType::STRUCT: + $xfer += $elem->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($elem, $espec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($elem, $espec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($elem, $espec, $output, true); + break; + } + } + } + if ($set) { + $xfer += $output->writeSetEnd(); + } else { + $xfer += $output->writeListEnd(); + } + return $xfer; + } + + protected function _write($class, $spec, $output) { + $xfer = 0; + $xfer += $output->writeStructBegin($class); + foreach ($spec as $fid => $fspec) { + $var = $fspec['var']; + if ($this->$var !== null) { + $ftype = $fspec['type']; + $xfer += $output->writeFieldBegin($var, $ftype, $fid); + if (isset(TBase::$tmethod[$ftype])) { + $func = 'write'.TBase::$tmethod[$ftype]; + $xfer += $output->$func($this->$var); + } else { + switch ($ftype) { + case TType::STRUCT: + $xfer += $this->$var->write($output); + break; + case TType::MAP: + $xfer += $this->_writeMap($this->$var, $fspec, $output); + break; + case TType::LST: + $xfer += $this->_writeList($this->$var, $fspec, $output, false); + break; + case TType::SET: + $xfer += $this->_writeList($this->$var, $fspec, $output, true); + break; + } + } + $xfer += $output->writeFieldEnd(); + } + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} + +class TApplicationException extends TException { + static $_TSPEC = + array(1 => array('var' => 'message', + 'type' => TType::STRING), + 2 => array('var' => 'code', + 'type' => TType::I32)); + + const UNKNOWN = 0; + const UNKNOWN_METHOD = 1; + const INVALID_MESSAGE_TYPE = 2; + const WRONG_METHOD_NAME = 3; + const BAD_SEQUENCE_ID = 4; + const MISSING_RESULT = 5; + const INTERNAL_ERROR = 6; + const PROTOCOL_ERROR = 7; + + function __construct($message=null, $code=0) { + parent::__construct($message, $code); + } + + public function read($output) { + return $this->_read('TApplicationException', self::$_TSPEC, $output); + } + + public function write($output) { + $xfer = 0; + $xfer += $output->writeStructBegin('TApplicationException'); + if ($message = $this->getMessage()) { + $xfer += $output->writeFieldBegin('message', TType::STRING, 1); + $xfer += $output->writeString($message); + $xfer += $output->writeFieldEnd(); + } + if ($code = $this->getCode()) { + $xfer += $output->writeFieldBegin('type', TType::I32, 2); + $xfer += $output->writeI32($code); + $xfer += $output->writeFieldEnd(); + } + $xfer += $output->writeFieldStop(); + $xfer += $output->writeStructEnd(); + return $xfer; + } +} + +/** + * Set global THRIFT ROOT automatically via inclusion here + */ +if (!isset($GLOBALS['THRIFT_ROOT'])) { + $GLOBALS['THRIFT_ROOT'] = dirname(__FILE__); +} +include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TProtocol.php'; +include_once $GLOBALS['THRIFT_ROOT'].'/transport/TTransport.php'; +include_once $GLOBALS['THRIFT_ROOT'].'/TStringUtils.php'; + http://git-wip-us.apache.org/repos/asf/airavata/blob/1441a831/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/autoload.php ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/autoload.php b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/autoload.php new file mode 100644 index 0000000..3a35545 --- /dev/null +++ b/airavata-api/airavata-client-sdks/airavata-php-sdk/lib/Thrift/autoload.php @@ -0,0 +1,51 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + * @package thrift + */ + + +/** + * Include this file if you wish to use autoload with your PHP generated Thrift + * code. The generated code will *not* include any defined Thrift classes by + * default, except for the service interfaces. The generated code will populate + * values into $GLOBALS['THRIFT_AUTOLOAD'] which can be used by the autoload + * method below. If you have your own autoload system already in place, rename your + * __autoload function to something else and then do: + * $GLOBALS['AUTOLOAD_HOOKS'][] = 'my_autoload_func'; + * + * Generate this code using the --gen php:autoload Thrift generator flag. + */ + +$GLOBALS['THRIFT_AUTOLOAD'] = array(); +$GLOBALS['AUTOLOAD_HOOKS'] = array(); + +if (!function_exists('__autoload')) { + function __autoload($class) { + global $THRIFT_AUTOLOAD; + $classl = strtolower($class); + if (isset($THRIFT_AUTOLOAD[$classl])) { + include_once $GLOBALS['THRIFT_ROOT'].'/packages/'.$THRIFT_AUTOLOAD[$classl]; + } else if (!empty($GLOBALS['AUTOLOAD_HOOKS'])) { + foreach ($GLOBALS['AUTOLOAD_HOOKS'] as $hook) { + $hook($class); + } + } + } +}
