You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/04/03 20:11:41 UTC

[airavata] branch develop updated: AIRAVATA-3002 Update profile service to use same db event publishing utils

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8cf2b82  AIRAVATA-3002 Update profile service to use same db event publishing utils
8cf2b82 is described below

commit 8cf2b821ed1ee46215ee4137e642d9ba2056bd72
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Wed Apr 3 16:11:23 2019 -0400

    AIRAVATA-3002 Update profile service to use same db event publishing utils
---
 .../handlers/TenantProfileServiceHandler.java      | 28 +++------
 .../handlers/UserProfileServiceHandler.java        | 24 ++------
 .../service/profile/utils/ProfileServiceUtils.java | 70 ----------------------
 .../common/utils/DBEventManagerConstants.java      | 15 -----
 4 files changed, 14 insertions(+), 123 deletions(-)

diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
index 3f4a109..b181ce6 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
@@ -22,12 +22,12 @@ package org.apache.airavata.service.profile.handlers;
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.Constants;
-import org.apache.airavata.common.utils.DBEventManagerConstants;
 import org.apache.airavata.common.utils.DBEventService;
 import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.credential.store.client.CredentialStoreClientFactory;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
 import org.apache.airavata.credential.store.exception.CredentialStoreException;
+import org.apache.airavata.messaging.core.util.DBEventPublisherUtils;
 import org.apache.airavata.model.credential.store.PasswordCredential;
 import org.apache.airavata.model.dbevent.CrudType;
 import org.apache.airavata.model.dbevent.EntityType;
@@ -40,7 +40,6 @@ import org.apache.airavata.service.profile.tenant.core.repositories.TenantProfil
 import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService;
 import org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException;
 import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants;
-import org.apache.airavata.service.profile.utils.ProfileServiceUtils;
 import org.apache.airavata.service.security.interceptor.SecurityCheck;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
@@ -57,6 +56,7 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface {
     private final static Logger logger = LoggerFactory.getLogger(TenantProfileServiceHandler.class);
 
     private TenantProfileRepository tenantProfileRepository;
+    private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT);
 
     public TenantProfileServiceHandler() {
         logger.debug("Initializing TenantProfileServiceHandler");
@@ -85,10 +85,7 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface {
                     // replicate tenant at end-places only if status is APPROVED
                     if (gateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED)) {
                         logger.info("Gateway with ID: {}, is now APPROVED, replicating to subscribers.", gateway.getGatewayId());
-                        ProfileServiceUtils.getDbEventPublisher().publish(
-                                ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.CREATE, gateway),
-                                DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                        );
+                        dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.CREATE, gateway);
                     }
                     // return internal id
                     return gateway.getAiravataInternalGatewayId();
@@ -123,10 +120,7 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface {
             if (tenantProfileRepository.update(updatedGateway) != null) {
                 logger.debug("Updated gateway-profile with ID: " + updatedGateway.getGatewayId());
                 // replicate tenant at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.UPDATE, updatedGateway),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.UPDATE, updatedGateway);
                 return true;
             } else {
                 return false;
@@ -164,16 +158,10 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface {
             boolean deleteSuccess = tenantProfileRepository.delete(airavataInternalGatewayId);
             if (deleteSuccess) {
                 // delete tenant at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.DELETE,
-                                 // pass along gateway datamodel, with correct gatewayId;
-                                 // approvalstatus is not used for delete, hence set dummy value
-                                new Gateway(gatewayId,
-                                        GatewayApprovalStatus.DEACTIVATED
-                                )
-                        ),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.DELETE,
+                        // pass along gateway datamodel, with correct gatewayId;
+                        // approvalstatus is not used for delete, hence set dummy value
+                        new Gateway(gatewayId, GatewayApprovalStatus.DEACTIVATED));
             }
             return deleteSuccess;
         } catch (Exception ex) {
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java
index 3a6f137..8fcd0e3 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java
@@ -23,9 +23,9 @@ package org.apache.airavata.service.profile.handlers;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.common.utils.Constants;
-import org.apache.airavata.common.utils.DBEventManagerConstants;
 import org.apache.airavata.common.utils.DBEventService;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.messaging.core.util.DBEventPublisherUtils;
 import org.apache.airavata.model.dbevent.CrudType;
 import org.apache.airavata.model.dbevent.EntityType;
 import org.apache.airavata.model.error.AuthorizationException;
@@ -40,7 +40,6 @@ import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamA
 import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository;
 import org.apache.airavata.service.profile.user.cpi.UserProfileService;
 import org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException;
-import org.apache.airavata.service.profile.utils.ProfileServiceUtils;
 import org.apache.airavata.service.security.AiravataSecurityManager;
 import org.apache.airavata.service.security.SecurityManagerFactory;
 import org.apache.airavata.service.security.UserInfo;
@@ -56,6 +55,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface {
     private final static Logger logger = LoggerFactory.getLogger(UserProfileServiceHandler.class);
 
     private UserProfileRepository userProfileRepository;
+    private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.USER_PROFILE);
 
     public UserProfileServiceHandler() {
 
@@ -94,10 +94,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface {
             if (null != userProfile) {
                 logger.info("Added UserProfile with userId: " + userProfile.getUserId());
                 // replicate userProfile at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.CREATE, userProfile),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile);
                 // return userId
                 return userProfile.getUserId();
             } else {
@@ -122,10 +119,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface {
             if (null != userProfile) {
                 logger.info("Added UserProfile with userId: " + userProfile.getUserId());
                 // replicate userProfile at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.CREATE, userProfile),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile);
                 // return userId
                 return userProfile.getUserId();
             } else {
@@ -150,10 +144,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface {
             if(userProfileRepository.updateUserProfile(userProfile, iamUserProfileUpdater) != null) {
                 logger.info("Updated UserProfile with userId: " + userProfile.getUserId());
                 // replicate userProfile at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.UPDATE, userProfile),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.UPDATE, userProfile);
                 return true;
             }
             return false;
@@ -209,10 +200,7 @@ public class UserProfileServiceHandler implements UserProfileService.Iface {
 
             if (deleteSuccess) {
                 // delete userProfile at end-places
-                ProfileServiceUtils.getDbEventPublisher().publish(
-                        ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.DELETE, userProfile),
-                        DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString())
-                );
+                dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.DELETE, userProfile);
             }
             return deleteSuccess;
         } catch (Exception e) {
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/utils/ProfileServiceUtils.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/utils/ProfileServiceUtils.java
deleted file mode 100644
index 0db4db5..0000000
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/utils/ProfileServiceUtils.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.apache.airavata.service.profile.utils;
-
-import org.apache.airavata.common.exception.AiravataException;
-import org.apache.airavata.common.utils.DBEventManagerConstants;
-import org.apache.airavata.common.utils.ThriftUtils;
-import org.apache.airavata.messaging.core.MessageContext;
-import org.apache.airavata.messaging.core.MessagingFactory;
-import org.apache.airavata.messaging.core.Publisher;
-import org.apache.airavata.model.dbevent.*;
-import org.apache.airavata.model.messaging.event.MessageType;
-import org.apache.thrift.TBase;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Created by goshenoy on 3/28/17.
- */
-public class ProfileServiceUtils {
-
-    private final static Logger logger = LoggerFactory.getLogger(ProfileServiceUtils.class);
-    private static Publisher dbEventPublisher = null;
-
-    /**
-     * Returns singleton instance of dbEventPublisher
-     * @return
-     * @throws AiravataException
-     */
-    public static Publisher getDbEventPublisher() throws AiravataException {
-        if (dbEventPublisher == null) {
-            dbEventPublisher = MessagingFactory.getDBEventPublisher();
-        }
-        return dbEventPublisher;
-    }
-
-    /**
-     * Constructs the dbEventMessageContext
-     * @param entityType
-     * @param crudType
-     * @param entityModel
-     * @return
-     * @throws AiravataException
-     */
-    public static MessageContext getDBEventMessageContext(EntityType entityType, CrudType crudType, TBase entityModel) throws AiravataException {
-        try {
-            // set the publisherContext
-            DBEventMessage dbEventMessage = new DBEventMessage();
-            DBEventPublisherContext publisherContext = new DBEventPublisherContext();
-            publisherContext.setCrudType(crudType);
-            publisherContext.setEntityDataModel(ThriftUtils.serializeThriftObject(entityModel));
-            publisherContext.setEntityType(entityType);
-
-            // create dbEventPublisher with publisherContext
-            DBEventPublisher dbEventPublisher = new DBEventPublisher();
-            dbEventPublisher.setPublisherContext(publisherContext);
-
-            // set messageContext to dbEventPublisher
-            DBEventMessageContext dbMessageContext = DBEventMessageContext.publisher(dbEventPublisher);
-
-            // set dbEventMessage with messageContext
-            dbEventMessage.setDbEventType(DBEventType.PUBLISHER);
-            dbEventMessage.setPublisherService(DBEventManagerConstants.getDbEventServiceName(entityType));
-            dbEventMessage.setMessageContext(dbMessageContext);
-
-            // construct and return messageContext
-            return new MessageContext(dbEventMessage, MessageType.DB_EVENT, "", "");
-        } catch (Exception ex) {
-            throw new AiravataException(ex.getMessage(), ex);
-        }
-    }
-}
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventManagerConstants.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventManagerConstants.java
index 60e8c25..51dedd6 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventManagerConstants.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventManagerConstants.java
@@ -65,21 +65,6 @@ public class DBEventManagerConstants {
     }
 
     /**
-     * Get serviceName from EntityType
-     * @param entityType
-     * @return
-     */
-    @Deprecated
-    public static String getDbEventServiceName(EntityType entityType) {
-        for (DBEventService service : DBEventService.values()) {
-            if (service.name().equals(entityType.name())) {
-                return service.toString();
-            }
-        }
-        return null;
-    }
-
-    /**
      * Get the service as enum, given the service-name as string
      * @param dbEventService
      * @return