You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2017/12/16 12:50:35 UTC

[airavata-sandbox] 04/12: API class that contains the function to execute Airavata experiment

This is an automated email from the ASF dual-hosted git repository.

smarru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-sandbox.git

commit 1be5f9a9debba07a0c44b5e4d8fd4d8090108dec
Author: Saurabh Agrawal <sa...@gmail.com>
AuthorDate: Sat Dec 16 00:55:51 2017 -0500

    API class that contains the function to execute Airavata experiment
---
 cwl-workflows/api.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/cwl-workflows/api.py b/cwl-workflows/api.py
new file mode 100644
index 0000000..887e2c6
--- /dev/null
+++ b/cwl-workflows/api.py
@@ -0,0 +1,89 @@
+# API for Jupyter Notebook client
+
+from apache.airavata.model.workspace.ttypes import *
+from apache.airavata.model.experiment.ttypes import *
+
+from thrift.protocol import TBinaryProtocol
+from thrift.transport import TSSLSocket
+from thrift.transport import TTransport
+
+from apache.airavata.api import Airavata
+from apache.airavata.model.security.ttypes import AuthzToken
+
+
+def get_transport(hostname, port):
+    """Create a socket to the Airavata Server
+
+    :param hostname: Hostname of Airavata server
+    :param port:     Port of Airavata server
+    :return: Transport object
+    """
+    # TODO: validate server certificate
+    transport = TSSLSocket.TSSLSocket(hostname, port, validate=False)
+    # Use Buffered Protocol to speedup over raw sockets
+    transport = TTransport.TBufferedTransport(transport)
+    return transport
+
+
+def get_airavata_client(transport):
+    """Creates and returns airavata client object
+
+    :param transport: Transport object
+    :return: AiravataClient object
+    """
+    # Airavata currently uses Binary Protocol
+    protocol = TBinaryProtocol.TBinaryProtocol(transport)
+
+    # Create a Airavata client to use the protocol encoder
+    airavataClient = Airavata.Client(protocol)
+    return airavataClient
+
+
+def get_authz_token(token, gateway_id, user_name):
+    """Creates and returns a authorization token
+
+    :param token:     Token string
+    :param gateway_id: Gateway ID
+    :param user_name:  User name of the user
+    :return: AuthzToken object
+    """
+    return AuthzToken(accessToken=token, claimsMap={'gatewayID': gateway_id, 'userName': user_name})
+
+
+def launch_experiment(hostname, port, user_name, token_string, experiment_id, gateway_id):
+    """Launches an experiment identified by an experiment id
+
+    :param hostname:      Hostname of the host where experiment is to be executed
+    :param port:          Port of the host where experiment is to be executed
+    :param user_name:     Airavata user
+    :param token_string:  Access token passed as a string
+    :param experiment_id: ID of the experiment that needs to be executed
+    :param gateway_id:    ID of the gateway where the experiment needs to be executed
+    """
+    transport = get_transport(hostname, port)
+    transport.open()
+    airavata_client = get_airavata_client(transport)
+    auth_token = get_authz_token(token_string, gateway_id, user_name)
+    airavata_client.launchExperiment(auth_token, experiment_id, gateway_id)
+    transport.close()
+
+
+def create_experiment(hostname, port, token_string, gateway_id, project_id, user_name, experiment_name):
+    """Creates an experiment in Airavata
+
+    :param hostname:         Host name of the Airavata server
+    :param port:             Port number of the Airavata server
+    :param token_string:     Token string
+    :param gateway_id:       Gateway ID
+    :param project_id:       Project ID
+    :param user_name:        Name of the user
+    :param experiment_name:  Name of the experiment
+    :return: Experiment ID
+    """
+    transport = get_transport(hostname, port)
+    transport.open()
+    airavata_client = get_airavata_client(transport)
+    auth_token = get_authz_token(token_string, gateway_id, user_name)
+    experiment_model = ExperimentModel(projectId=project_id, gatewayId=gateway_id,
+                                       userName=user_name, experimentName=experiment_name)
+    return airavata_client.createExperiment(auth_token, gateway_id, experiment_model)

-- 
To stop receiving notification emails like this one, please contact
"commits@airavata.apache.org" <co...@airavata.apache.org>.