airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: implementing experiment catalog to sharing catalog data migrator
Date Wed, 05 Oct 2016 07:48:14 GMT
Repository: airavata
Updated Branches:
  refs/heads/airavata-gov-registry 496ddbaad -> a47c6383b


implementing experiment catalog to sharing catalog data migrator


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

Branch: refs/heads/airavata-gov-registry
Commit: a47c6383b9fba7c4c643f501fbcbea8156461334
Parents: 496ddba
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Wed Oct 5 03:48:10 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Wed Oct 5 03:48:10 2016 -0400

----------------------------------------------------------------------
 .../airavata-sharing-data-migrator/pom.xml      |  10 --
 .../sharing/registry/ConnectionFactory.java     |  59 ++++++++
 .../airavata/sharing/registry/DataMigrator.java | 137 +++++++++++++++++++
 .../sharing/registry/db/utils/JPAUtils.java     |   2 +-
 .../registry/server/GovRegistryServer.java      |   2 +-
 5 files changed, 198 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/a47c6383/modules/airavata-sharing-registry/airavata-sharing-data-migrator/pom.xml
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-data-migrator/pom.xml b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/pom.xml
index a664200..472b0a2 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-data-migrator/pom.xml
+++ b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/pom.xml
@@ -17,15 +17,5 @@
             <artifactId>airavata-sharing-registry-core</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.airavata</groupId>
-            <artifactId>airavata-commons</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-java</artifactId>
-            <version>5.1.34</version>
-        </dependency>
     </dependencies>
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/a47c6383/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/ConnectionFactory.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/ConnectionFactory.java
b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/ConnectionFactory.java
new file mode 100644
index 0000000..d501b96
--- /dev/null
+++ b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/ConnectionFactory.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+package org.apache.airavata.sharing.registry;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class ConnectionFactory {
+    private final static Logger logger = LoggerFactory.getLogger(ConnectionFactory.class);
+
+    //static reference to itself
+    private static ConnectionFactory instance;
+
+    public static final String EXPCAT_URL = "jdbc:mysql://localhost/airavata_exp_catalog";
+    public static final String EXPCAT_USER = "root";
+    public static final String EXPCAT_PASSWORD = "";
+    public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
+
+    private static Connection expCatConnection, sharingCatConnection;
+
+    //private constructor
+    private ConnectionFactory() throws ClassNotFoundException, SQLException {
+        Class.forName(DRIVER_CLASS);
+        expCatConnection = DriverManager.getConnection(EXPCAT_URL, EXPCAT_USER, EXPCAT_PASSWORD);
+    }
+
+    public static ConnectionFactory getInstance() throws SQLException, ClassNotFoundException
{
+        if(instance == null)
+            instance = new ConnectionFactory();
+        return instance;
+    }
+
+    public Connection getExpCatConnection() throws SQLException {
+        return expCatConnection;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/a47c6383/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/DataMigrator.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/DataMigrator.java
b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/DataMigrator.java
index 53573ff..ccc0c41 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/DataMigrator.java
+++ b/modules/airavata-sharing-registry/airavata-sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/DataMigrator.java
@@ -20,9 +20,146 @@
 */
 package org.apache.airavata.sharing.registry;
 
+import org.apache.airavata.sharing.registry.models.*;
+import org.apache.airavata.sharing.registry.server.GovRegistryServerHandler;
+import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.Map;
+
 public class DataMigrator {
     private final static Logger logger = LoggerFactory.getLogger(DataMigrator.class);
+
+    public static void main(String[] args) throws SQLException, ClassNotFoundException, TException
{
+        Connection expCatConnection = ConnectionFactory.getInstance().getExpCatConnection();
+
+        GovRegistryServerHandler govRegistryServerHandler = new GovRegistryServerHandler();
+
+        String query = "SELECT * FROM GATEWAY";
+        Statement statement = expCatConnection.createStatement();
+        ResultSet rs = statement.executeQuery(query);
+
+        while (rs.next()) {
+            //Creating domain entries
+            Domain domain = new Domain();
+            domain.setDomainId(rs.getString("GATEWAY_ID"));
+            if(rs.getString("GATEWAY_NAME") != null)
+                domain.setName(rs.getString("GATEWAY_NAME"));
+            else
+                domain.setName(rs.getString("GATEWAY_ID"));
+            domain.setDescription("Domain entry for " + domain.name);
+
+            govRegistryServerHandler.createDomain(domain);
+
+            //Creating Entity Types for each domain
+            EntityType entityType = new EntityType();
+            entityType.setEntityTypeId(domain.domainId+":PROJECT");
+            entityType.setDomainId(domain.domainId);
+            entityType.setName("PROJECT");
+            entityType.setDescription("Project entity type");
+            govRegistryServerHandler.createEntityType(entityType);
+
+            entityType = new EntityType();
+            entityType.setEntityTypeId(domain.domainId+":EXPERIMENT");
+            entityType.setDomainId(domain.domainId);
+            entityType.setName("EXPERIMENT");
+            entityType.setDescription("Experiment entity type");
+            govRegistryServerHandler.createEntityType(entityType);
+
+            entityType = new EntityType();
+            entityType.setEntityTypeId(domain.domainId+":FILE");
+            entityType.setDomainId(domain.domainId);
+            entityType.setName("FILE");
+            entityType.setDescription("File entity type");
+            govRegistryServerHandler.createEntityType(entityType);
+
+            //Creating Permission Types for each domain
+            PermissionType permissionType = new PermissionType();
+            permissionType.setPermissionTypeId(domain.domainId+":READ");
+            permissionType.setDomainId(domain.domainId);
+            permissionType.setName("READ");
+            permissionType.setDescription("Read permission type");
+            govRegistryServerHandler.createPermissionType(permissionType);
+
+            permissionType = new PermissionType();
+            permissionType.setPermissionTypeId(domain.domainId+":WRITE");
+            permissionType.setDomainId(domain.domainId);
+            permissionType.setName("WRITE");
+            permissionType.setDescription("Write permission type");
+            govRegistryServerHandler.createPermissionType(permissionType);
+        }
+
+        //Creating user entries
+        query = "SELECT * FROM USERS";
+        statement = expCatConnection.createStatement();
+        rs = statement.executeQuery(query);
+        while(rs.next()){
+            User user = new User();
+            user.setUserId(rs.getString("AIRAVATA_INTERNAL_USER_ID"));
+            user.setDomainId(rs.getString("GATEWAY_ID"));
+            user.setUserName(rs.getString("USER_NAME"));
+
+            govRegistryServerHandler.createUser(user);
+        }
+
+        //Creating project entries
+        query = "SELECT * FROM PROJECT";
+        statement = expCatConnection.createStatement();
+        rs = statement.executeQuery(query);
+        while(rs.next()){
+            Entity entity = new Entity();
+            entity.setEntityId(rs.getString("PROJECT_ID"));
+            entity.setDomainId(rs.getString("GATEWAY_ID"));
+            entity.setEntityTypeId(rs.getString("GATEWAY_ID") + ":PROJECT");
+            entity.setOwnerId(rs.getString("USER_NAME") + "@" + rs.getString("GATEWAY_ID"));
+            entity.setName(rs.getString("PROJECT_NAME"));
+            entity.setDescription(rs.getString("DESCRIPTION"));
+            if(entity.getDescription() == null)
+                entity.setFullText(entity.getName());
+            else
+                entity.setFullText(entity.getName() + " " + entity.getDescription());
+            Map<String, String> metadata = new HashMap<>();
+            metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
+
+            govRegistryServerHandler.createEntity(entity);
+        }
+
+        //Creating experiment entries
+        query = "SELECT * FROM EXPERIMENT";
+        statement = expCatConnection.createStatement();
+        rs = statement.executeQuery(query);
+        while(rs.next()){
+            Entity entity = new Entity();
+            entity.setEntityId(rs.getString("EXPERIMENT_ID"));
+            entity.setDomainId(rs.getString("GATEWAY_ID"));
+            entity.setEntityTypeId(rs.getString("GATEWAY_ID") + ":EXPERIMENT");
+            entity.setOwnerId(rs.getString("USER_NAME") + "@" + rs.getString("GATEWAY_ID"));
+            entity.setParentEntityId(rs.getString("PROJECT_ID"));
+            entity.setName(rs.getString("EXPERIMENT_NAME"));
+            entity.setDescription(rs.getString("DESCRIPTION"));
+            if(entity.getDescription() == null)
+                entity.setFullText(entity.getName());
+            else
+                entity.setFullText(entity.getName() + " " + entity.getDescription());
+            Map<String, String> metadata = new HashMap<>();
+            metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
+            metadata.put("EXPERIMENT_TYPE", rs.getString("EXPERIMENT_TYPE"));
+            metadata.put("EXECUTION_ID", rs.getString("EXECUTION_ID"));
+            metadata.put("GATEWAY_EXECUTION_ID", rs.getString("GATEWAY_EXECUTION_ID"));
+            metadata.put("ENABLE_EMAIL_NOTIFICATION", rs.getString("ENABLE_EMAIL_NOTIFICATION"));
+            metadata.put("EMAIL_ADDRESSES", rs.getString("EMAIL_ADDRESSES"));
+            metadata.put("GATEWAY_INSTANCE_ID", rs.getString("GATEWAY_INSTANCE_ID"));
+            metadata.put("ARCHIVE", rs.getString("ARCHIVE"));
+
+            govRegistryServerHandler.createEntity(entity);
+        }
+
+        expCatConnection.close();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/a47c6383/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
index e1eba62..7f31d7f 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
+++ b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java
@@ -57,7 +57,7 @@ public class JPAUtils {
 //
 
             String connectionProperties = "DriverClassName=com.mysql.jdbc.Driver," +
-                    "Url=jdbc:mysql://localhost:3306/airavata_gov_registry?autoReconnect=true,"
+
+                    "Url=jdbc:mysql://localhost:3306/airavata_sharing_catalog?autoReconnect=true,"
+
                     "Username=root," +
                     "Password=," +
                     ",validationQuery=SELECT 1 FROM CONFIGURATION";

http://git-wip-us.apache.org/repos/asf/airavata/blob/a47c6383/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServer.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServer.java
b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServer.java
index 276c99e..764bda0 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServer.java
+++ b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServer.java
@@ -18,7 +18,7 @@
  * under the License.
  *
 */
-package org.apache.airavata.gov.registry.server;
+package org.apache.airavata.sharing.registry.server;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;


Mime
View raw message