public function getAiravataClient() { $transport = new TSocket($this->airavataServerHost, $this->airavataServerPort); $protocol = new TBinaryProtocol($transport); $transport->open(); return new AiravataClient($protocol); }
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 getUserAPIClient() { $transport = new TSocket($this->userapiServerHost, $this->userapiServerPort); $transport->setRecvTimeout(5000); $transport->setSendTimeout(5000); $protocol = new TBinaryProtocol($transport); $transport->open(); return new UserAPIClient($protocol); }
public function open() { parent::setSendTimeout($this->_connectTimeoutMs); try { parent::open(); } finally { parent::setSendTimeout($this->_sendTimeoutMs); } }
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(); } }
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); // }
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); }
/** * 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); }
/** * 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; }