You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2018/07/21 20:12:58 UTC
[airavata-django-portal] 04/07: AIRAVATA-2859 Renamed Thrift client
utils
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit a95f7a652aa0f24cebf6284f979e814390a56bed
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Fri Jul 20 14:05:19 2018 -0400
AIRAVATA-2859 Renamed Thrift client utils
---
django_airavata/apps/workspace/signals.py | 9 ++--
django_airavata/middleware.py | 12 ++---
django_airavata/utils.py | 74 +++++++++++++++----------------
3 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/django_airavata/apps/workspace/signals.py b/django_airavata/apps/workspace/signals.py
index e99f03d..0ef462f 100644
--- a/django_airavata/apps/workspace/signals.py
+++ b/django_airavata/apps/workspace/signals.py
@@ -8,7 +8,7 @@ from django.dispatch import receiver
from airavata.model.workspace.ttypes import Project
from django_airavata.apps.auth.utils import get_authz_token
-from django_airavata.utils import airavata_client
+from django_airavata.utils import get_airavata_client
log = logging.getLogger(__name__)
@@ -18,9 +18,10 @@ def create_default_project_if_not_exists(sender, request, user, **kwargs):
# auth middleware hasn't run yet so authz_token attribute is not available
# on request, so need to create the authz_token manually
authz_token = get_authz_token(request)
- with airavata_client() as client:
+ with get_airavata_client() as airavata_client:
# Just retrieve the first project
- projects = client.getUserProjects(authz_token, settings.GATEWAY_ID, request.user.username, 1, 0)
+ projects = airavata_client.getUserProjects(
+ authz_token, settings.GATEWAY_ID, request.user.username, 1, 0)
if len(projects) == 0:
log.info("Creating default project for user {}".format(
user.username))
@@ -31,5 +32,5 @@ def create_default_project_if_not_exists(sender, request, user, **kwargs):
default_project.description = ("This is the default project for "
"user {owner}".format(
owner=default_project.owner))
- client.createProject(authz_token, settings.GATEWAY_ID,
+ airavata_client.createProject(authz_token, settings.GATEWAY_ID,
default_project)
diff --git a/django_airavata/middleware.py b/django_airavata/middleware.py
index 5e82e7f..a49ce87 100644
--- a/django_airavata/middleware.py
+++ b/django_airavata/middleware.py
@@ -14,7 +14,7 @@ def airavata_client(get_response):
# If user is logged in create an airavata api client for the request
if request.user.is_authenticated:
try:
- with utils.airavata_client() as airavata_client:
+ with utils.get_airavata_client() as airavata_client:
request.airavata_client = airavata_client
response = get_response(request)
except utils.ThriftConnectionException as e:
@@ -39,7 +39,7 @@ def sharing_client(get_response):
# If user is logged in create a sharing registry client for the request
if request.user.is_authenticated:
try:
- with utils.sharing_client() as sharing_client:
+ with utils.get_sharing_client() as sharing_client:
request.sharing_client = sharing_client
response = get_response(request)
except utils.ThriftConnectionException as e:
@@ -69,10 +69,10 @@ def profile_service_client(get_response):
# If user is logged in create an profile service client for the request
if request.user.is_authenticated:
try:
- with utils.group_manager_client() as group_manager_client, \
- utils.iam_admin_client() as iam_admin_client, \
- utils.tenant_profile_client() as tenant_profile_client, \
- utils.user_profile_client() as user_profile_client:
+ with utils.get_group_manager_client() as group_manager_client, \
+ utils.get_iam_admin_client() as iam_admin_client, \
+ utils.get_tenant_profile_client() as tenant_profile_client, \
+ utils.get_user_profile_client() as user_profile_client:
request.profile_service = {
'group_manager': group_manager_client,
'iam_admin': iam_admin_client,
diff --git a/django_airavata/utils.py b/django_airavata/utils.py
index 53388d4..0ff8382 100644
--- a/django_airavata/utils.py
+++ b/django_airavata/utils.py
@@ -55,7 +55,7 @@ def get_transport(hostname, port, secure=True):
return transport
-def get_airavata_client(transport):
+def create_airavata_client(transport):
# Airavata currently uses Binary Protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport)
@@ -65,7 +65,7 @@ def get_airavata_client(transport):
return client
-def get_sharing_client(transport):
+def create_sharing_client(transport):
protocol = TBinaryProtocol.TBinaryProtocol(transport)
@@ -76,81 +76,81 @@ def get_binary_protocol(transport):
return TBinaryProtocol.TBinaryProtocol(transport)
-def get_group_manager_client(transport):
+def create_group_manager_client(transport):
protocol = get_binary_protocol(transport)
multiplex_prot = TMultiplexedProtocol(protocol, GROUP_MANAGER_CPI_NAME)
return GroupManagerService.Client(multiplex_prot)
-def get_iamadmin_client(transport):
+def create_iamadmin_client(transport):
protocol = get_binary_protocol(transport)
multiplex_prot = TMultiplexedProtocol(protocol,
IAM_ADMIN_SERVICES_CPI_NAME)
return IamAdminServices.Client(multiplex_prot)
-def get_tenant_profile_client(transport):
+def create_tenant_profile_client(transport):
protocol = get_binary_protocol(transport)
multiplex_prot = TMultiplexedProtocol(protocol, TENANT_PROFILE_CPI_NAME)
return TenantProfileService.Client(multiplex_prot)
-def get_user_profile_client(transport):
+def create_user_profile_client(transport):
protocol = get_binary_protocol(transport)
multiplex_prot = TMultiplexedProtocol(protocol, USER_PROFILE_CPI_NAME)
return UserProfileService.Client(multiplex_prot)
-def airavata_client():
+def get_airavata_client():
"""Get Airavata API client as context manager (use in `with statement`)."""
- return thrift_client(settings.AIRAVATA_API_HOST,
- settings.AIRAVATA_API_PORT,
- settings.AIRAVATA_API_SECURE,
- get_airavata_client)
+ return get_thrift_client(settings.AIRAVATA_API_HOST,
+ settings.AIRAVATA_API_PORT,
+ settings.AIRAVATA_API_SECURE,
+ create_airavata_client)
-def sharing_client():
+def get_sharing_client():
"""Get Sharing API client as context manager (use in `with statement`)."""
- return thrift_client(settings.SHARING_API_HOST,
- settings.SHARING_API_PORT,
- settings.SHARING_API_SECURE,
- get_airavata_client)
+ return get_thrift_client(settings.SHARING_API_HOST,
+ settings.SHARING_API_PORT,
+ settings.SHARING_API_SECURE,
+ create_sharing_client)
-def group_manager_client():
+def get_group_manager_client():
"""Group Manager client as context manager (use in `with statement`)."""
- return thrift_client(settings.PROFILE_SERVICE_HOST,
- settings.PROFILE_SERVICE_PORT,
- settings.PROFILE_SERVICE_SECURE,
- get_group_manager_client)
+ return get_thrift_client(settings.PROFILE_SERVICE_HOST,
+ settings.PROFILE_SERVICE_PORT,
+ settings.PROFILE_SERVICE_SECURE,
+ create_group_manager_client)
-def iam_admin_client():
+def get_iam_admin_client():
"""IAM Admin client as context manager (use in `with statement`)."""
- return thrift_client(settings.PROFILE_SERVICE_HOST,
- settings.PROFILE_SERVICE_PORT,
- settings.PROFILE_SERVICE_SECURE,
- get_iamadmin_client)
+ return get_thrift_client(settings.PROFILE_SERVICE_HOST,
+ settings.PROFILE_SERVICE_PORT,
+ settings.PROFILE_SERVICE_SECURE,
+ create_iamadmin_client)
-def tenant_profile_client():
+def get_tenant_profile_client():
"""Tenant Profile client as context manager (use in `with statement`)."""
- return thrift_client(settings.PROFILE_SERVICE_HOST,
- settings.PROFILE_SERVICE_PORT,
- settings.PROFILE_SERVICE_SECURE,
- get_tenant_profile_client)
+ return get_thrift_client(settings.PROFILE_SERVICE_HOST,
+ settings.PROFILE_SERVICE_PORT,
+ settings.PROFILE_SERVICE_SECURE,
+ create_tenant_profile_client)
-def user_profile_client():
+def get_user_profile_client():
"""User Profile client as context manager (use in `with statement`)."""
- return thrift_client(settings.PROFILE_SERVICE_HOST,
- settings.PROFILE_SERVICE_PORT,
- settings.PROFILE_SERVICE_SECURE,
- get_user_profile_client)
+ return get_thrift_client(settings.PROFILE_SERVICE_HOST,
+ settings.PROFILE_SERVICE_PORT,
+ settings.PROFILE_SERVICE_SECURE,
+ create_user_profile_client)
@contextmanager
-def thrift_client(host, port, is_secure, client_generator):
+def get_thrift_client(host, port, is_secure, client_generator):
transport = get_transport(host, port, is_secure)
client = client_generator(transport)