airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject git commit: fixing AIRAVATA-1264
Date Thu, 22 May 2014 19:02:49 GMT
Repository: airavata
Updated Branches:
  refs/heads/master fe507e4b6 -> ce10da776


fixing AIRAVATA-1264


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

Branch: refs/heads/master
Commit: ce10da77634c48ec5b046348837e96a28eb20eea
Parents: fe507e4
Author: Chathuri Wimalasena <kamalasini@gmail.com>
Authored: Thu May 22 15:02:29 2014 -0400
Committer: Chathuri Wimalasena <kamalasini@gmail.com>
Committed: Thu May 22 15:02:29 2014 -0400

----------------------------------------------------------------------
 .../client/samples/CreateLaunchExperiment.java  |  4 +--
 .../persistance/registry/jpa/ResourceUtils.java |  6 ++--
 .../registry/jpa/impl/ExperimentRegistry.java   |  8 +++--
 .../registry/jpa/impl/RegistryImpl.java         | 34 +++++++++++++++-----
 .../registry/jpa/resources/GatewayResource.java | 19 +++++++++--
 .../registry/jpa/resources/WorkerResource.java  |  1 -
 .../registry/jpa/GatewayResourceTest.java       |  4 +--
 7 files changed, 57 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
index 7f7e095..e39430a 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
@@ -65,9 +65,9 @@ public class CreateLaunchExperiment {
 
 //            final String expId = createExperimentForSSHHost(airavata);
 //            final String expId = createExperimentForSSHHost(airavata);
-            final String expId = createExperimentForTrestles(airavata);
+//            final String expId = createExperimentForTrestles(airavata);
 //            final String expId = createExperimentForStampede(airavata);
-//            final String expId = createExperimentForLocalHost(airavata);
+            final String expId = createExperimentForLocalHost(airavata);
             System.out.println("Experiment ID : " + expId);
 //            updateExperiment(airavata, expId);
             launchExperiment(airavata, expId);

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
index c7410f2..3ee9324 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
@@ -198,7 +198,7 @@ public class ResourceUtils {
      * @param gatewayResource
      * @param userResource
      */
-    public static void addGatewayWorker(GatewayResource gatewayResource, UserResource userResource)
{
+    public static WorkerResource addGatewayWorker(GatewayResource gatewayResource, UserResource
userResource) {
         try {
             EntityManager em = getEntityManager();
             em.getTransaction().begin();
@@ -216,10 +216,12 @@ public class ResourceUtils {
             em.persist(gatewayWorker);
             em.getTransaction().commit();
             em.close();
+            WorkerResource resource = (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER,
gatewayWorker);
+            return resource;
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
         }
-
+        return null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
index 89c2e45..ff476be 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
@@ -44,8 +44,12 @@ public class ExperimentRegistry {
 
     public ExperimentRegistry(GatewayResource gateway, UserResource user) {
         gatewayResource = gateway;
-        workerResource = new WorkerResource(user.getUserName(), gatewayResource);
-        workerResource.save();
+        if (!gatewayResource.isExists(ResourceType.GATEWAY_WORKER, user.getUserName())){
+            workerResource = ResourceUtils.addGatewayWorker(gateway, user);
+        }else {
+            workerResource = (WorkerResource)ResourceUtils.getWorker(gateway.getGatewayName(),
user.getUserName());
+        }
+
     }
 
     public String addExperiment(Experiment experiment) throws Exception {

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
index a766ddb..8e89fc8 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
@@ -45,10 +45,19 @@ public class RegistryImpl implements Registry {
 
     public RegistryImpl() {
         try {
-            gatewayResource = (GatewayResource) ResourceUtils.createGateway(ServerSettings.getSystemUserGateway());
-            gatewayResource.save();
-            user = ResourceUtils.createUser(ServerSettings.getSystemUser(), ServerSettings.getSystemUserPassword());
-            user.save();
+            if (!ResourceUtils.isGatewayExist(ServerSettings.getSystemUserGateway())){
+                gatewayResource = (GatewayResource) ResourceUtils.createGateway(ServerSettings.getSystemUserGateway());
+                gatewayResource.save();
+            }else {
+                gatewayResource = (GatewayResource)ResourceUtils.getGateway(ServerSettings.getSystemUserGateway());
+            }
+
+            if (!ResourceUtils.isUserExist(ServerSettings.getSystemUser())){
+                user = ResourceUtils.createUser(ServerSettings.getSystemUser(), ServerSettings.getSystemUserPassword());
+                user.save();
+            }else {
+                user = (UserResource)ResourceUtils.getUser(ServerSettings.getSystemUser());
+            }
             experimentRegistry = new ExperimentRegistry(gatewayResource, user);
             projectRegistry = new ProjectRegistry(gatewayResource, user);
         } catch (ApplicationSettingsException e) {
@@ -57,10 +66,19 @@ public class RegistryImpl implements Registry {
     }
 
     public RegistryImpl(String gateway, String username, String password) {
-        gatewayResource = (GatewayResource) ResourceUtils.createGateway(gateway);
-        gatewayResource.save();
-        user = ResourceUtils.createUser(username, password);
-        user.save();
+        if (!ResourceUtils.isGatewayExist(gateway)){
+            gatewayResource = (GatewayResource) ResourceUtils.createGateway(gateway);
+            gatewayResource.save();
+        }else {
+            gatewayResource = (GatewayResource)ResourceUtils.getGateway(gateway);
+        }
+
+        if (!ResourceUtils.isUserExist(username)){
+            user = ResourceUtils.createUser(username, password);
+            user.save();
+        }else {
+            user = (UserResource)ResourceUtils.getUser(username);
+        }
         experimentRegistry = new ExperimentRegistry(gatewayResource, user);
         projectRegistry = new ProjectRegistry(gatewayResource, user);
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
index 80e79f2..aac889c 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
@@ -206,7 +206,7 @@ public class GatewayResource extends AbstractResource {
         QueryGenerator generator;
         Query q;
         switch (type) {
-            case USER:
+            case GATEWAY_WORKER:
                 generator = new QueryGenerator(GATEWAY_WORKER);
                 generator.setParameter(GatewayWorkerConstants.USERNAME, name);
                 generator.setParameter(GatewayWorkerConstants.GATEWAY_NAME, gatewayName);
@@ -217,6 +217,16 @@ public class GatewayResource extends AbstractResource {
                 em.getTransaction().commit();
                 em.close();
                 return workerResource;
+            case USER:
+                generator = new QueryGenerator(USERS);
+                generator.setParameter(UserConstants.USERNAME, name);
+                q = generator.selectQuery(em);
+                Users user = (Users) q.getSingleResult();
+                UserResource userResource =
+                        (UserResource)Utils.getResource(ResourceType.USER, user);
+                em.getTransaction().commit();
+                em.close();
+                return userResource;
             case PUBLISHED_WORKFLOW:
                 generator = new QueryGenerator(PUBLISHED_WORKFLOW);
                 generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME,
name);
@@ -449,11 +459,16 @@ public class GatewayResource extends AbstractResource {
         Query q;
         Number count;
         switch (type){
-            case USER:
+            case GATEWAY_WORKER:
                 em = ResourceUtils.getEntityManager();
                 Gateway_Worker existingWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayName,
name.toString()));
                 em.close();
                 return existingWorker!= null;
+            case USER:
+                em = ResourceUtils.getEntityManager();
+                Users existingUser = em.find(Users.class, name);
+                em.close();
+                return existingUser!= null;
             case PUBLISHED_WORKFLOW:
                 em = ResourceUtils.getEntityManager();
                 Published_Workflow existingWf = em.find(Published_Workflow.class, new Published_Workflow_PK(gatewayName,
name.toString()));

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
index 622531c..c5e5c45 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
@@ -488,7 +488,6 @@ public class WorkerResource extends AbstractResource {
            }
         }
         query = query.substring(0, query.length() - 5);
-        System.out.println(query);
         EntityManager em = ResourceUtils.getEntityManager();
         em.getTransaction().begin();
         Query q = em.createQuery(query);

http://git-wip-us.apache.org/repos/asf/airavata/blob/ce10da77/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
index cc1f015..80d29f9 100644
--- a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/GatewayResourceTest.java
@@ -132,7 +132,7 @@ public class GatewayResourceTest extends AbstractResourceTest {
     
     @Test
     public void testIsExists() throws Exception {
-        assertTrue(gatewayResource.isExists(ResourceType.USER, "admin"));
+        assertTrue(gatewayResource.isExists(ResourceType.GATEWAY_WORKER, "admin"));
         assertTrue(gatewayResource.isExists(ResourceType.PUBLISHED_WORKFLOW, "pubworkflow1"));
         assertTrue(gatewayResource.isExists(ResourceType.HOST_DESCRIPTOR, "testHostDesc"));
         assertTrue(gatewayResource.isExists(ResourceType.SERVICE_DESCRIPTOR, "testServiceDesc"));
@@ -142,7 +142,7 @@ public class GatewayResourceTest extends AbstractResourceTest {
 
     @Test
     public void testGet() throws Exception {
-        assertNotNull(gatewayResource.get(ResourceType.USER, "admin"));
+        assertNotNull(gatewayResource.get(ResourceType.GATEWAY_WORKER, "admin"));
         assertNotNull(gatewayResource.get(ResourceType.PUBLISHED_WORKFLOW, "pubworkflow1"));
         assertNotNull(gatewayResource.get(ResourceType.HOST_DESCRIPTOR, "testHostDesc"));
         assertNotNull(gatewayResource.get(ResourceType.SERVICE_DESCRIPTOR, "testServiceDesc"));


Mime
View raw message