airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dimuthu...@apache.org
Subject [airavata] branch master updated: Validating thrift clients before emitting from the pool
Date Thu, 02 May 2019 17:55:57 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 26d3f1a  Validating thrift clients before emitting from the pool
26d3f1a is described below

commit 26d3f1a668adf9d069a46f434d461cea4eb23490
Author: Dimuthu Wannipurage <dimuthu.upeksha2@gmail.com>
AuthorDate: Thu May 2 13:55:48 2019 -0400

    Validating thrift clients before emitting from the pool
---
 modules/commons/pom.xml                            |  5 +++++
 .../airavata/common/utils/ThriftClientPool.java    | 26 +++++++++++++++-------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index 1cae29c..c8997ef 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -138,6 +138,11 @@
             <artifactId>logback-classic</artifactId>
             <version>${logback.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.airavata</groupId>
+            <artifactId>airavata-base-api</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftClientPool.java
b/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftClientPool.java
index b04ef82..43dd926 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftClientPool.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/ThriftClientPool.java
@@ -19,9 +19,9 @@
  */
 package org.apache.airavata.common.utils;
 
+import org.apache.airavata.base.api.BaseAPI;
 import org.apache.commons.pool.BasePoolableObjectFactory;
 import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.thrift.TServiceClient;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.TSocket;
@@ -30,11 +30,9 @@ import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ThriftClientPool<T extends TServiceClient> implements
-        AutoCloseable {
+public class ThriftClientPool<T extends BaseAPI.Client> implements AutoCloseable {
 
-    private static final Logger LOGGER = LoggerFactory
-            .getLogger(ThriftClientPool.class);
+    private static final Logger logger = LoggerFactory.getLogger(ThriftClientPool.class);
 
     private final GenericObjectPool internalPool;
 
@@ -67,7 +65,7 @@ public class ThriftClientPool<T extends TServiceClient> implements
                 TProtocol protocol = protocolFactory.make();
                 return clientFactory.make(protocol);
             } catch (Exception e) {
-                LOGGER.warn(e.getMessage(), e);
+                logger.warn(e.getMessage(), e);
                 throw new ThriftClientException(
                         "Can not make a new object for pool", e);
             }
@@ -109,7 +107,7 @@ public class ThriftClientPool<T extends TServiceClient> implements
             try {
                 transport.open();
             } catch (TTransportException e) {
-                LOGGER.warn(e.getMessage(), e);
+                logger.warn(e.getMessage(), e);
                 throw new ThriftClientException("Can not make protocol", e);
             }
             return new TBinaryProtocol(transport);
@@ -129,7 +127,19 @@ public class ThriftClientPool<T extends TServiceClient> implements
 
     public T getResource() {
         try {
-            return (T) internalPool.borrowObject();
+            for( int i = 0; i < 10 ; i++) {
+                // This tries to fetch a client from the pool and validate it before returning.
+                final T client = (T) internalPool.borrowObject();
+                try {
+                    String apiVersion = client.getAPIVersion();
+                    logger.debug("Validated client and fetched api version " + apiVersion);
+                    return client;
+                } catch (Exception e) {
+                    logger.warn("Failed to validate the client. Retrying " + i, e);
+                    returnBrokenResource(client);
+                }
+            }
+            throw new Exception("Failed to fetch a client form the pool after validation");
         } catch (Exception e) {
             throw new ThriftClientException(
                     "Could not get a resource from the pool", e);


Mime
View raw message