airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata] branch group-based-auth updated: AIRAVATA-2781 Give Admins WRITE on every Project, Experiment
Date Wed, 06 Jun 2018 13:38:56 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch group-based-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/group-based-auth by this push:
     new 8dacd90  AIRAVATA-2781 Give Admins WRITE on every Project, Experiment
8dacd90 is described below

commit 8dacd905dd5e4f3827bc9012442dde150bc7fd01
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Wed Jun 6 09:38:12 2018 -0400

    AIRAVATA-2781 Give Admins WRITE on every Project, Experiment
---
 .../migrator/airavata/AiravataDataMigrator.java    | 107 ++++++++++++---------
 1 file changed, 63 insertions(+), 44 deletions(-)

diff --git a/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
b/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
index 584581d..cf4747b 100644
--- a/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
+++ b/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
@@ -157,10 +157,36 @@ public class AiravataDataMigrator {
 
         }
 
+        //Map to reuse the domain ID and owner for creating application-deployment entities
+        Map<String, String> domainOwnerMap = new HashMap<>();
+        Map<String, GatewayGroups> gatewayGroupsMap = new HashMap<>();
+
+        //Creating the gateway groups
+        List<Domain> domainList = sharingRegistryServerHandler.getDomains(0, -1);
+        final RegistryService.Client registryServiceClient = getRegistryServiceClient();
+        for (Domain domain : domainList) {
+            String ownerId = getAdminOwnerUser(domain, sharingRegistryServerHandler, credentialStoreServiceClient,
registryServiceClient);
+            if (ownerId != null) {
+                domainOwnerMap.put(domain.domainId, ownerId);
+            } else {
+                continue;
+            }
+
+            if (registryServiceClient.isGatewayGroupsExists(domain.domainId)) {
+                GatewayGroups gatewayGroups = registryServiceClient.getGatewayGroups(domain.domainId);
+                gatewayGroupsMap.put(domain.domainId, gatewayGroups);
+            } else {
+
+                GatewayGroups gatewayGroups = migrateRolesToGatewayGroups(domain, ownerId,
sharingRegistryServerHandler, registryServiceClient);
+                gatewayGroupsMap.put(domain.domainId, gatewayGroups);
+            }
+        }
+
         //Creating project entries
         query = "SELECT * FROM PROJECT";
         statement = expCatConnection.createStatement();
         rs = statement.executeQuery(query);
+        List<Entity> projectEntities = new ArrayList<>();
         while(rs.next()){
             try{
                 Entity entity = new Entity();
@@ -174,21 +200,26 @@ public class AiravataDataMigrator {
                     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());
+//                Map<String, String> metadata = new HashMap<>();
+//                metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
+                projectEntities.add(entity);
 
-                if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
-                    sharingRegistryServerHandler.createEntity(entity);
             }catch (Exception ex) {
                 ex.printStackTrace();
             }
+        }
 
+        for (Entity entity : projectEntities) {
+            if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
+                sharingRegistryServerHandler.createEntity(entity);
+            shareEntityWithAdminGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroupsMap.get(entity.domainId),
false);
         }
 
         //Creating experiment entries
         query = "SELECT * FROM EXPERIMENT";
         statement = expCatConnection.createStatement();
         rs = statement.executeQuery(query);
+        List<Entity> experimentEntities = new ArrayList<>();
         while(rs.next()){
             try {
                 Entity entity = new Entity();
@@ -203,46 +234,26 @@ public class AiravataDataMigrator {
                     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"));
+//                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"));
+                experimentEntities.add(entity);
 
-                if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
-                    sharingRegistryServerHandler.createEntity(entity);
             }catch (Exception ex){
                 ex.printStackTrace();
             }
         }
 
-        //Map to reuse the domain ID and owner for creating application-deployment entities
-        Map<String, String> domainOwnerMap = new HashMap<>();
-        Map<String, GatewayGroups> gatewayGroupsMap = new HashMap<>();
-
-        //Creating the gateway groups
-        List<Domain> domainList = sharingRegistryServerHandler.getDomains(0, -1);
-        final RegistryService.Client registryServiceClient = getRegistryServiceClient();
-        for (Domain domain : domainList) {
-            String ownerId = getAdminOwnerUser(domain, sharingRegistryServerHandler, credentialStoreServiceClient,
registryServiceClient);
-            if (ownerId != null) {
-                domainOwnerMap.put(domain.domainId, ownerId);
-            } else {
-                continue;
-            }
-
-            if (registryServiceClient.isGatewayGroupsExists(domain.domainId)) {
-                GatewayGroups gatewayGroups = registryServiceClient.getGatewayGroups(domain.domainId);
-                gatewayGroupsMap.put(domain.domainId, gatewayGroups);
-            } else {
-
-                GatewayGroups gatewayGroups = migrateRolesToGatewayGroups(domain, ownerId,
sharingRegistryServerHandler, registryServiceClient);
-                gatewayGroupsMap.put(domain.domainId, gatewayGroups);
-            }
+        for (Entity entity : experimentEntities) {
+            if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
+                sharingRegistryServerHandler.createEntity(entity);
+            shareEntityWithAdminGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroupsMap.get(entity.domainId),
false);
         }
 
         //Creating application deployment entries
@@ -264,7 +275,7 @@ public class AiravataDataMigrator {
 
                 if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
                     sharingRegistryServerHandler.createEntity(entity);
-                shareEntityWithGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroups);
+                shareEntityWithGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroups,
false);
             }
         }
 
@@ -285,7 +296,7 @@ public class AiravataDataMigrator {
                 entity.setDescription(groupResourceProfile.getGroupResourceProfileName()
+ " Group Resource Profile");
                 if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
                     sharingRegistryServerHandler.createEntity(entity);
-                shareEntityWithGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroups);
+                shareEntityWithGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroups,
false);
 
             }
         }
@@ -295,15 +306,23 @@ public class AiravataDataMigrator {
 
     }
 
-    private static void shareEntityWithGatewayGroups(SharingRegistryServerHandler sharingRegistryServerHandler,
Entity entity, GatewayGroups gatewayGroups) throws TException {
+    private static void shareEntityWithGatewayGroups(SharingRegistryServerHandler sharingRegistryServerHandler,
Entity entity, GatewayGroups gatewayGroups, boolean cascadePermission) throws TException {
+        // Give default Gateway Users group and Read Only Admins group READ access
+        sharingRegistryServerHandler.shareEntityWithGroups(entity.domainId, entity.entityId,
+                Arrays.asList(gatewayGroups.getDefaultGatewayUsersGroupId()),
+                entity.domainId + ":" + ResourcePermissionType.READ, cascadePermission);
+        shareEntityWithAdminGatewayGroups(sharingRegistryServerHandler, entity, gatewayGroups,
cascadePermission);
+    }
+
+    private static void shareEntityWithAdminGatewayGroups(SharingRegistryServerHandler sharingRegistryServerHandler,
Entity entity, GatewayGroups gatewayGroups, boolean cascadePermission) throws TException {
         // Give default Gateway Users group and Read Only Admins group READ access
         sharingRegistryServerHandler.shareEntityWithGroups(entity.domainId, entity.entityId,
-                Arrays.asList(gatewayGroups.getDefaultGatewayUsersGroupId(), gatewayGroups.getReadOnlyAdminsGroupId()),
-                entity.domainId + ":" + ResourcePermissionType.READ, true);
+                Arrays.asList(gatewayGroups.getReadOnlyAdminsGroupId()),
+                entity.domainId + ":" + ResourcePermissionType.READ, cascadePermission);
         // Give Admins group WRITE access
         sharingRegistryServerHandler.shareEntityWithGroups(entity.domainId, entity.entityId,
                 Arrays.asList(gatewayGroups.getAdminsGroupId()),
-                entity.domainId + ":" + ResourcePermissionType.WRITE, true);
+                entity.domainId + ":" + ResourcePermissionType.WRITE, cascadePermission);
     }
 
     private static GatewayGroups migrateRolesToGatewayGroups(Domain domain, String ownerId,
SharingRegistryServerHandler sharingRegistryServerHandler, RegistryService.Client registryServiceClient)
throws TException, ApplicationSettingsException {

-- 
To stop receiving notification emails like this one, please contact
machristie@apache.org.

Mime
View raw message