airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramin...@apache.org
Subject airavata git commit: To get gatewayid based on security token. AIRAVATA-1554
Date Fri, 23 Jan 2015 17:10:20 GMT
Repository: airavata
Updated Branches:
  refs/heads/master b81daafbe -> 0b70b6936


To get gatewayid based on security token. AIRAVATA-1554

Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/0b70b693
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/0b70b693
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/0b70b693

Branch: refs/heads/master
Commit: 0b70b6936886a2353b14ef7acd69ffcae0a24fd0
Parents: b81daaf
Author: raminder <ramifnu@indiana.edu>
Authored: Fri Jan 23 12:09:44 2015 -0500
Committer: raminder <ramifnu@indiana.edu>
Committed: Fri Jan 23 12:09:44 2015 -0500

----------------------------------------------------------------------
 .../store/store/CredentialReader.java           | 11 +++++++
 .../store/store/impl/CredentialReaderImpl.java  | 10 ++++++
 .../store/store/impl/db/CredentialsDAO.java     | 34 ++++++++++++++++++++
 .../store/store/impl/db/CredentialsDAOTest.java |  5 ++-
 .../server/OrchestratorServerHandler.java       | 18 +++++++++--
 .../core/impl/GFACEmbeddedJobSubmitter.java     | 27 +++++++++-------
 .../core/impl/GFACServiceJobSubmitter.java      | 16 +++++++--
 .../orchestrator/core/job/JobSubmitter.java     | 10 ------
 8 files changed, 104 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java
b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java
index eea85f0..fe54b8e 100644
--- a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java
+++ b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/CredentialReader.java
@@ -97,5 +97,16 @@ public interface CredentialReader {
      *             If an error occurred while retrieving data.
      */
     void removeCredentials(String gatewayName, String tokenId) throws CredentialStoreException;
+    
+    /**
+     * Retrieves gatewayID from the credential store.
+     * 
+     * @param tokenId
+     *            The token id associated with the credential
+     * @return The Credential object associated with the token.
+     * @throws CredentialStoreException
+     *             If an error occurred while retrieving a credential.
+     */
+    String getGatewayID(String tokenId) throws CredentialStoreException;
 
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java
b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java
index 79d362b..dc2fd60 100644
--- a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java
+++ b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/CredentialReaderImpl.java
@@ -149,4 +149,14 @@ public class CredentialReaderImpl implements CredentialReader, Serializable
{
 
     }
 
+	@Override
+	public String getGatewayID(String tokenId) throws CredentialStoreException {
+		 Connection connection = getConnection();
+	        try {
+	            return this.credentialsDAO.getGatewayID(tokenId, connection);
+	        } finally {
+	            DBUtil.cleanup(connection);
+	        }
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
index 6699e7e..b9dc2ef 100644
--- a/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
+++ b/modules/credential-store-service/credential-store/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
@@ -244,7 +244,41 @@ public class CredentialsDAO extends ParentDAO {
 
         return null;
     }
+    /**
+     * 
+     */
+    public String getGatewayID(String tokenId, Connection connection)
+            throws CredentialStoreException {
+
+        String sql = "SELECT GATEWAY_ID FROM CREDENTIALS WHERE TOKEN_ID=?";
+
+        PreparedStatement preparedStatement = null;
+        ResultSet resultSet = null;
+
+        try {
+            preparedStatement = connection.prepareStatement(sql);
+
+            preparedStatement.setString(1, tokenId);
+         
+            resultSet = preparedStatement.executeQuery();
+
+            if (resultSet.next()) {
+            	return resultSet.getString("GATEWAY_ID");
+              }
 
+        } catch (SQLException e) {
+            StringBuilder stringBuilder = new StringBuilder("Error retrieving credentials
for user.");
+            stringBuilder.append("token id - ").append(tokenId);
+
+            log.debug(stringBuilder.toString(), e);
+
+            throw new CredentialStoreException(stringBuilder.toString(), e);
+        } finally {
+            DBUtil.cleanup(preparedStatement, resultSet);
+        }
+
+        return null;
+    }
     /**
      * String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + "        GATEWAY_ID VARCHAR(256)
NOT NULL,\n" +
      * "        TOKEN_ID VARCHAR(256) NOT NULL,\n" + // Actual token used to identify the
credential

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/credential-store-service/credential-store/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java
----------------------------------------------------------------------
diff --git a/modules/credential-store-service/credential-store/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java
b/modules/credential-store-service/credential-store/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java
index 53565d2..c175454 100644
--- a/modules/credential-store-service/credential-store/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java
+++ b/modules/credential-store-service/credential-store/src/test/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAOTest.java
@@ -314,15 +314,18 @@ public class CredentialsDAOTest extends DatabaseTestCases {
         try {
             CertificateCredential certificateCredential = (CertificateCredential) credentialsDAO.getCredential("gw1",
                     "tom", connection);
+            //Test get gateway name
+            String gateway = credentialsDAO.getGatewayID("tom", connection);
             Assert.assertNotNull(certificateCredential);
             Assert.assertEquals("jerry", certificateCredential.getPortalUserName());
+            Assert.assertEquals("gw1", gateway);
             checkEquality(x509Certificates, certificateCredential.getCertificates());
             Assert.assertEquals(privateKey.getFormat(), certificateCredential.getPrivateKey().getFormat());
         } finally {
             connection.close();
         }
     }
-
+    
     @Test
     public void testDeleteCredentials() throws Exception {
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
index e0548f4..e88945d 100644
--- a/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
+++ b/modules/orchestrator/airavata-orchestrator-service/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java
@@ -34,6 +34,8 @@ import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential;
+import org.apache.airavata.credential.store.store.CredentialReader;
 import org.apache.airavata.gfac.core.scheduler.HostScheduler;
 import org.apache.airavata.gfac.core.utils.GFacUtils;
 import org.apache.airavata.messaging.core.MessageContext;
@@ -109,7 +111,8 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface,
 					+ ":"
 					+ ServerSettings
 							.getSetting(Constants.ORCHESTRATOR_SERVER_PORT);
-            setGatewayName(ServerSettings.getDefaultUserGateway());
+			
+//            setGatewayName(ServerSettings.getDefaultUserGateway());
             setAiravataUserName(ServerSettings.getDefaultUser());
 			try {
 				zk = new ZooKeeper(zkhostPort, 6000, this); // no watcher is
@@ -676,7 +679,18 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface,
                         experiment.setExperimentStatus(status);
                         registry.update(RegistryModelType.EXPERIMENT_STATUS, status, experimentId);
                         if (ServerSettings.isRabbitMqPublishEnabled()) {
-                            String gatewayId = ServerSettings.getDefaultUserGateway();
+                        	 String gatewayId = null;
+                        	 CredentialReader credentialReader = GFacUtils.getCredentialReader();
+                             if (credentialReader != null) {
+                                 try {
+                                	 gatewayId = credentialReader.getGatewayID(airavataCredStoreToken);
+                                 } catch (Exception e) {
+                                     log.error(e.getLocalizedMessage());
+                                 }
+                             }
+                            if(gatewayId == null || gatewayId.isEmpty()){
+                             gatewayId = ServerSettings.getDefaultUserGateway();
+                            }
                             ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.LAUNCHED,
                                     experimentId,
                                     gatewayId);

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACEmbeddedJobSubmitter.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACEmbeddedJobSubmitter.java
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACEmbeddedJobSubmitter.java
index 5341623..bafb45e 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACEmbeddedJobSubmitter.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACEmbeddedJobSubmitter.java
@@ -23,9 +23,11 @@ package org.apache.airavata.orchestrator.core.impl;
 
 import org.apache.airavata.common.utils.MonitorPublisher;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.credential.store.store.CredentialReader;
 import org.apache.airavata.gfac.client.GFACInstance;
 import org.apache.airavata.gfac.core.cpi.BetterGfacImpl;
 import org.apache.airavata.gfac.core.cpi.GFac;
+import org.apache.airavata.gfac.core.utils.GFacUtils;
 import org.apache.airavata.orchestrator.core.context.OrchestratorContext;
 import org.apache.airavata.orchestrator.core.exception.OrchestratorException;
 import org.apache.airavata.orchestrator.core.job.JobSubmitter;
@@ -57,20 +59,21 @@ public class GFACEmbeddedJobSubmitter implements JobSubmitter {
     }
 
 
-    public boolean submit(String experimentID, String taskID) throws OrchestratorException
{
-        try {
-            return gfac.submitJob(experimentID, taskID, ServerSettings.getDefaultUserGateway());
-        } catch (Exception e) {
-            String error = "Error launching the job : " + experimentID;
-            logger.error(error);
-            throw new OrchestratorException(error);
-        }
-    }
-
-
     public boolean submit(String experimentID, String taskID,String tokenId) throws OrchestratorException
{
         try {
-            return submit(experimentID,taskID);
+        	 String gatewayId = null;
+        	 CredentialReader credentialReader = GFacUtils.getCredentialReader();
+             if (credentialReader != null) {
+                 try {
+                	 gatewayId = credentialReader.getGatewayID(tokenId);
+                 } catch (Exception e) {
+                     logger.error(e.getLocalizedMessage());
+                 }
+             }
+            if(gatewayId == null || gatewayId.isEmpty()){
+             gatewayId = ServerSettings.getDefaultUserGateway();
+            }
+          return gfac.submitJob(experimentID, taskID, gatewayId);
         } catch (Exception e) {
             String error = "Error launching the job : " + experimentID;
             logger.error(error);

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
index fccbb44..3bbc588 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/impl/GFACServiceJobSubmitter.java
@@ -29,6 +29,7 @@ import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataZKUtils;
 import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.credential.store.store.CredentialReader;
 import org.apache.airavata.gfac.client.GFACInstance;
 import org.apache.airavata.gfac.client.GFacClientFactory;
 import org.apache.airavata.gfac.core.utils.GFacUtils;
@@ -99,8 +100,19 @@ public class GFACServiceJobSubmitter implements JobSubmitter, Watcher
{
 				if (zk.exists(gfacServer + File.separator + pickedChild, false) != null) {
 					// before submitting the job we check again the state of the node
 					if (GFacUtils.createExperimentEntry(experimentID, taskID, zk, experimentNode, pickedChild,
tokenId)) {
-						// FIXME:: The GatewayID is temporarily read from properties file. It should instead
be inferred from the token.
-						return gfacClient.submitJob(experimentID, taskID, ServerSettings.getDefaultUserGateway());
+						 String gatewayId = null;
+                    	 CredentialReader credentialReader = GFacUtils.getCredentialReader();
+                         if (credentialReader != null) {
+                             try {
+                            	 gatewayId = credentialReader.getGatewayID(tokenId);
+                             } catch (Exception e) {
+                                 logger.error(e.getLocalizedMessage());
+                             }
+                         }
+                        if(gatewayId == null || gatewayId.isEmpty()){
+                         gatewayId = ServerSettings.getDefaultUserGateway();
+                        }
+						return gfacClient.submitJob(experimentID, taskID, gatewayId);
 					}
 				}
 			}

http://git-wip-us.apache.org/repos/asf/airavata/blob/0b70b693/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/job/JobSubmitter.java
----------------------------------------------------------------------
diff --git a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/job/JobSubmitter.java
b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/job/JobSubmitter.java
index 254c6c9..be0c76c 100644
--- a/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/job/JobSubmitter.java
+++ b/modules/orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/job/JobSubmitter.java
@@ -44,16 +44,6 @@ public interface JobSubmitter {
 
 
     /**
-     * This can be used when user doesn't want to run in a threaded pull mode
-     * just get the request data and do the submission
-     * @param experimentID experimentID cannot be null
-     * @param taskID taskID cannot be null
-     * @return boolean return the submit status
-     */
-    boolean submit(String experimentID, String taskID) throws OrchestratorException;
-
-
-    /**
      * This is similar to submit with expId and taskId but this has extra param called token
      * @param experimentID
      * @param taskID


Mime
View raw message