Modified Sharing Registry tests and Data Migrator
MODIFY
modules/sharing-registry/sharing-data-migrator/pom.xml
modules/sharing-registry/sharing-data-migrator/pom.xml
<artifactId>airavata-data-models</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>registry-api-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>airavata-credential-store-stubs</artifactId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
+ <dependency>
+ <groupId>org.mariadb.jdbc</groupId>
+ <artifactId>mariadb-java-client</artifactId>
+ <version>2.0.2</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file

MODIFY
modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
package org.apache.airavata.sharing.registry.migrator.airavata;
import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription;
import org.apache.airavata.model.group.ResourcePermissionType;
import org.apache.airavata.model.group.ResourceType;
-import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory;
import org.apache.airavata.sharing.registry.models.*;
import org.apache.airavata.sharing.registry.server.SharingRegistryServerHandler;
import org.apache.thrift.TException;
-import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
import org.apache.airavata.credential.store.cpi.CredentialStoreService;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.credential.store.client.CredentialStoreClientFactory;
@@ -49,7 +48,6 @@ public class AiravataDataMigrator {
Connection expCatConnection = ConnectionFactory.getInstance().getExpCatConnection();
SharingRegistryServerHandler sharingRegistryServerHandler = new SharingRegistryServerHandler();
- SharingRegistryService.Client sharingClient = SharingRegistryServiceClientFactory.createSharingRegistryClient("149.165.169.138", 7878);
CredentialStoreService.Client credentialStoreServiceClient = getCredentialStoreServiceClient();
String query = "SELECT * FROM GATEWAY";
@@ -219,16 +217,41 @@ public class AiravataDataMigrator {
}
}
+ //Map to reuse the domain ID and owner for creating application-deployment entities
+ Map<String, String> domainOwnerMap = new HashMap<>();
+
//Creating the everyone group
- List<Domain> domainList = sharingClient.getDomains(-1, 0);
+ List<Domain> domainList = sharingRegistryServerHandler.getDomains(0, -1);
for (Domain domain : domainList) {
- GatewayResourceProfile gatewayResourceProfile = getRegistryServiceClient().getGatewayResourceProfile(domain.domainId);
+ GatewayResourceProfile gatewayResourceProfile = null;
+ try {
+ gatewayResourceProfile = getRegistryServiceClient().getGatewayResourceProfile(domain.domainId);
+ } catch (Exception e) {
+ System.out.println("Skipping creating everyone group for " + domain.domainId + " because it doesn't have a GatewayResourceProfile");
+ continue;
+ }
+ if (gatewayResourceProfile.getIdentityServerPwdCredToken() == null) {
+ System.out.println("Skipping creating everyone group for " + domain.domainId + " because it doesn't have an identity server pwd credential token");
+ continue;
+ }
+ String groupOwner = null;
+ try {
PasswordCredential credential = credentialStoreServiceClient.getPasswordCredential(
gatewayResourceProfile.getIdentityServerPwdCredToken(), gatewayResourceProfile.getGatewayID());
- String groupOwner = credential.getLoginUserName();
+ groupOwner = credential.getLoginUserName();
+ } catch (Exception e) {
+ System.out.println("Skipping creating everyone group for " + domain.domainId + " because the identity server pwd credential could not be retrieved.");
+ continue;
+ }
+ domainOwnerMap.put(domain.domainId, groupOwner);
String groupId = "everyone@" + domain.domainId;
- if (!sharingClient.isGroupExists(domain.domainId, groupId)) {
+ String ownerId = groupOwner + "@" + domain.domainId;
+ if (!sharingRegistryServerHandler.isUserExists(domain.domainId, ownerId)) {
+ System.out.println("Skipping creating everyone group for " + domain.domainId + " because admin user doesn't exist in sharing registry.");
+ continue;
+ }
+ if (!sharingRegistryServerHandler.isGroupExists(domain.domainId, groupId)) {
UserGroup userGroup = new UserGroup();
userGroup.setGroupId(groupId);
userGroup.setDomainId(domain.domainId);
@@ -237,55 +260,45 @@ public class AiravataDataMigrator {
userGroup.setUpdatedTime(System.currentTimeMillis());
userGroup.setName("everyone");
userGroup.setDescription("Default Group");
- userGroup.setOwnerId(groupOwner + "@" + domain.domainId);
+ userGroup.setOwnerId(ownerId);
userGroup.setGroupType(GroupType.DOMAIN_LEVEL_GROUP);
- sharingClient.createGroup(userGroup);
+ sharingRegistryServerHandler.createGroup(userGroup);
- List<User> userList = sharingClient.getUsers(domain.domainId, -1, 0);
+ List<User> userList = sharingRegistryServerHandler.getUsers(domain.domainId, 0, -1);
List<String> users = new ArrayList<>();
for (User user : userList) {
users.add(user.getUserId());
}
- sharingClient.addUsersToGroup(domain.domainId, users, groupId);
+ sharingRegistryServerHandler.addUsersToGroup(domain.domainId, users, groupId);
}
}
//Creating application deployment entries
- query = "SELECT * FROM APPLICATION_DEPLOYMENT";
- statement = expCatConnection.createStatement();
- rs = statement.executeQuery(query);
- while(rs.next()){
- try {
- GatewayResourceProfile gatewayResourceProfile = getRegistryServiceClient().
- getGatewayResourceProfile(rs.getString("GATEWAY_ID"));
- PasswordCredential credential = credentialStoreServiceClient.getPasswordCredential(
- gatewayResourceProfile.getIdentityServerPwdCredToken(), gatewayResourceProfile.getGatewayID());
- String applicationDeploymentOwner = credential.getLoginUserName();
-
+ for (String domainID : domainOwnerMap.keySet()) {
+ List<ApplicationDeploymentDescription> applicationDeploymentDescriptionList = getRegistryServiceClient().getAllApplicationDeployments(domainID);
+ for (ApplicationDeploymentDescription description : applicationDeploymentDescriptionList) {
Entity entity = new Entity();
- entity.setEntityId(rs.getString("DEPLOYMENT_ID"));
- entity.setDomainId(rs.getString("GATEWAY_ID"));
- entity.setEntityTypeId(rs.getString("GATEWAY_ID") + ":" + ResourceType.APPLICATION_DEPLOYMENT.name());
- entity.setOwnerId(applicationDeploymentOwner + "@" + rs.getString("GATEWAY_ID"));
- entity.setName(rs.getString("DEPLOYMENT_ID"));
- entity.setDescription(rs.getString("APPLICATION_DESC"));
+ entity.setEntityId(description.getAppDeploymentId());
+ entity.setDomainId(domainID);
+ entity.setEntityTypeId(entity.domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name());
+ entity.setOwnerId(domainOwnerMap.get(domainID) + "@" + entity.domainId);
+ entity.setName(description.getAppDeploymentId());
+ entity.setDescription(description.getAppDeploymentDescription());
if (entity.getDescription() == null)
- entity.setFullText(entity.getName());
+ entity.setDescription(entity.getName());
else
entity.setFullText(entity.getName() + " " + entity.getDescription());
- Map<String, String> metadata = new HashMap<>();
- metadata.put("CREATION_TIME", rs.getDate("CREATION_TIME").toString());
if (!sharingRegistryServerHandler.isEntityExists(entity.domainId, entity.entityId))
sharingRegistryServerHandler.createEntity(entity);
- String groupId = "everyone@" + entity.domainId;
- sharingClient.shareEntityWithGroups(entity.domainId, entity.entityId, Arrays.asList(groupId), entity.domainId+":"+ ResourcePermissionType.EXEC, true);
- } catch (Exception ex){
- ex.printStackTrace();
+ String groupID = "everyone@" + entity.domainId;
+ sharingRegistryServerHandler.shareEntityWithGroups(entity.domainId, entity.entityId, Arrays.asList(groupID),
+ entity.domainId + ":" + ResourcePermissionType.EXEC, true);
}
}
expCatConnection.close();
+ System.out.println("Completed!");
}

MODIFY
modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
@@ -157,7 +157,12 @@ public abstract class AbstractRepository<T, E, Id> {
entityManager.getTransaction().commit();
return r;
} finally {
+ if (entityManager.isOpen()) {
+ if (entityManager.getTransaction().isActive()) {
+ entityManager.getTransaction().rollback();
+ }
entityManager.close();
}
}
}
+}
\ No newline at end of file

MODIFY
modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
@@ -166,7 +166,23 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
// Add user to the domain's "everyone" group
String groupId = "everyone@" + user.domainId;
+ if (isGroupExists(user.domainId, groupId)) {
addUsersToGroup(user.domainId, Arrays.asList(user.userId), groupId);
+ }
+ else {
+ //Create an "everyone" group for the domain
+ UserGroup everyone = new UserGroup();
+ everyone.setGroupId(groupId);
+ everyone.setDomainId(user.domainId);
+ everyone.setGroupCardinality(GroupCardinality.MULTI_USER);
+ everyone.setCreatedTime(System.currentTimeMillis());
+ everyone.setUpdatedTime(System.currentTimeMillis());
+ everyone.setOwnerId(user.userId);
+ everyone.setName("everyone");
+ everyone.setDescription("Default Group");
+ everyone.setGroupType(GroupType.DOMAIN_LEVEL_GROUP);
+ createGroup(everyone);
+ }
return user.userId;
}catch (Throwable ex) {

MODIFY
modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServerHandlerTest.java
modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServerHandlerTest.java
@@ -59,7 +59,6 @@ public class SharingRegistryServerHandlerTest {
Assert.assertNotNull(sharingRegistryServerHandler.createDomain(domain));
Assert.assertTrue(sharingRegistryServerHandler.getDomains(0, 10).size() > 0);
-
//Creating users
User user1 = new User();
String userName1 = "test-user-1." + System.currentTimeMillis();
@@ -111,7 +110,7 @@ public class SharingRegistryServerHandlerTest {
userGroup1.setUpdatedTime(System.currentTimeMillis());
Assert.assertNotNull(sharingRegistryServerHandler.createGroup(userGroup1));
- Assert.assertTrue(sharingRegistryServerHandler.getAllMemberGroupsForUser(domainId, userId1).size() == 1);
+ Assert.assertTrue(sharingRegistryServerHandler.getAllMemberGroupsForUser(domainId, userId1).size() == 2);
UserGroup userGroup2 = new UserGroup();
String groupName2 = "test-group-2." + System.currentTimeMillis();
@@ -131,7 +130,7 @@ public class SharingRegistryServerHandlerTest {
sharingRegistryServerHandler.addUsersToGroup(domainId, Arrays.asList(userId1), groupId1);
sharingRegistryServerHandler.addUsersToGroup(domainId, Arrays.asList(userId2, userId3), groupId2);
- Assert.assertTrue(sharingRegistryServerHandler.getAllMemberGroupsForUser(domainId, userId3).size() == 1);
+ Assert.assertTrue(sharingRegistryServerHandler.getAllMemberGroupsForUser(domainId, userId3).size() == 2);
sharingRegistryServerHandler.addChildGroupsToParentGroup(domainId, Arrays.asList(groupId2), groupId1);
@@ -179,6 +178,17 @@ public class SharingRegistryServerHandlerTest {
String permissionTypeId2 = sharingRegistryServerHandler.createPermissionType(permissionType2);
Assert.assertNotNull(permissionTypeId2);
+ PermissionType permissionType3 = new PermissionType();
+ String permissionName3 = "EXEC";
+ permissionType3.setPermissionTypeId(domainId+":"+permissionName3);
+ permissionType3.setDomainId(domainId);
+ permissionType3.setName(permissionName3);
+ permissionType3.setDescription("EXEC description");
+ permissionType3.setCreatedTime(System.currentTimeMillis());
+ permissionType3.setUpdatedTime(System.currentTimeMillis());
+ String permissionTypeId3 = sharingRegistryServerHandler.createPermissionType(permissionType3);
+ Assert.assertNotNull(permissionTypeId3);
+
//Creating entity types
EntityType entityType1 = new EntityType();
String entityType1Name = "Project";
@@ -213,6 +223,17 @@ public class SharingRegistryServerHandlerTest {
String entityTypeId3 = sharingRegistryServerHandler.createEntityType(entityType3);
Assert.assertNotNull(entityTypeId3);
+ EntityType entityType4 = new EntityType();
+ String entityType4Name = "Application-Deployment";
+ entityType4.setEntityTypeId(domainId+":"+entityType4Name);
+ entityType4.setDomainId(domainId);
+ entityType4.setName(entityType4Name);
+ entityType4.setDescription("test entity type");
+ entityType4.setCreatedTime(System.currentTimeMillis());
+ entityType4.setUpdatedTime(System.currentTimeMillis());
+ String entityTypeId4 = sharingRegistryServerHandler.createEntityType(entityType4);
+ Assert.assertNotNull(entityTypeId4);
+
//Creating Entities
Entity entity1 = new Entity();
entity1.setEntityId(domainId+":Entity1");
@@ -281,6 +302,27 @@ public class SharingRegistryServerHandlerTest {
Assert.assertTrue(sharingRegistryServerHandler.userHasAccess(domainId, userId1, entityId4, permissionTypeId1));
Assert.assertFalse(sharingRegistryServerHandler.userHasAccess(domainId, userId3, entityId1, permissionTypeId1));
+ Entity entity5 = new Entity();
+ entity5.setEntityId(domainId+":Entity5");
+ entity5.setDomainId(domainId);
+ entity5.setEntityTypeId(entityTypeId4);
+ entity5.setOwnerId(userId1);
+ entity5.setName("App deployment name");
+ entity5.setDescription("App deployment description");
+ entity5.setFullText("App Deployment name app deployment description");
+ entity5.setCreatedTime(System.currentTimeMillis());
+ entity5.setUpdatedTime(System.currentTimeMillis());
+
+ String entityId5 = sharingRegistryServerHandler.createEntity(entity5);
+ Assert.assertNotNull(entityId5);
+
+ sharingRegistryServerHandler.shareEntityWithUsers(domainId, entityId5, Arrays.asList(userId2), permissionTypeId1, true);
+ sharingRegistryServerHandler.shareEntityWithGroups(domainId, entityId5, Arrays.asList(groupId2), permissionTypeId3, true);
+
+ Assert.assertTrue(sharingRegistryServerHandler.userHasAccess(domainId, userId3, entityId5, permissionTypeId3));
+ Assert.assertTrue(sharingRegistryServerHandler.userHasAccess(domainId, userId2, entityId5, permissionTypeId1));
+ Assert.assertFalse(sharingRegistryServerHandler.userHasAccess(domainId, userId3, entityId5, permissionTypeId2));
+
ArrayList<SearchCriteria> filters = new ArrayList<>();
SearchCriteria searchCriteria = new SearchCriteria();
searchCriteria.setSearchCondition(SearchCondition.LIKE);
@@ -301,7 +343,5 @@ public class SharingRegistryServerHandlerTest {
Assert.assertTrue(sharingRegistryServerHandler.getListOfSharedUsers(domainId, entityId1, domainId + ":OWNER").size()==1);
-// sharingRegistryServerHandler.revokeEntitySharingFromUsers(entityId1, Arrays.asList(userId2), permissionTypeId1);
-// sharingRegistryServerHandler.revokeEntitySharingFromGroups(entityId3, Arrays.asList(groupId2), permissionTypeId1);
}
}
\ No newline at end of file

MODIFY
modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
@@ -313,7 +313,7 @@ public class SharingRegistryServiceTest {
searchCriteria.setValue("1");
searchCriteria.setSearchCondition(SearchCondition.GTE);
filters.add(searchCriteria);
- Assert.assertTrue(sharingServiceClient.searchEntities(domainId, "test-user-2", filters, 0, -1).size() == 1);
+ Assert.assertEquals(1, sharingServiceClient.searchEntities(domainId, "test-user-2", filters, 0, -1).size());
sharingServiceClient.revokeEntitySharingFromUsers(domainId, "test-project-1", Arrays.asList("test-user-2"), "WRITE");

Modified Sharing Registry tests and Data Migrator