Martin Peřina has uploaded a new change for review.

Change subject: tools: Match transport names with EventNotificationMethod
......................................................................

tools: Match transport names with EventNotificationMethod

Fixes different names in Smtp/Snmp.getName() and
EventNotificationMethod values which represents transport names in db.
If those names differ (current state), no events are sent through
notifier.

Change-Id: Ie93d2d371a6f29a33e32a776e74ada5f221cbb4e
Bug-Url: https://bugzilla.redhat.com/1071536
Signed-off-by: Martin Perina <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/EventNotificationMethod.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/EventDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EventDAOTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/smtp/Smtp.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/users/UserEventNotifierListModel.java
A packaging/dbscripts/upgrade/03_04_0650_fix_event_notfication_method.sql
10 files changed, 54 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/13/25313/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
index 1e6b6c5..bf7b424 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EventSubscriptionCommandBase.java
@@ -52,7 +52,7 @@
         EventNotificationMethod notificationMethod = eventNotificationMethod;
 
         switch (notificationMethod) {
-        case EMAIL:
+        case SMTP:
             String mailAdress = 
(StringUtils.isEmpty(event_subscriber.getmethod_address())) ? user.getEmail()
                     : event_subscriber.getmethod_address();
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/EventNotificationMethod.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/EventNotificationMethod.java
index 70254cd..9e6b170 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/EventNotificationMethod.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/EventNotificationMethod.java
@@ -1,6 +1,32 @@
 package org.ovirt.engine.core.common;
 
 public enum EventNotificationMethod {
-    EMAIL,
-    SNMP_TRAP
+    SMTP("smtp"),
+    SNMP("snmp");
+
+    /**
+     * External string representation (database, text configuration)
+     */
+    private String value;
+
+    /**
+     * Sets external string representation as lowercase name
+     */
+    private EventNotificationMethod(String value) {
+        this.value = value;
+    }
+
+    /**
+     * Return string representation (database, configuration
+     */
+    public String getAsString() {
+        return value;
+    }
+
+    /**
+     * Returns enum value based on external string representation
+     */
+    public static EventNotificationMethod valueOfString(String value) {
+        return valueOf(value != null ? value.toUpperCase() : value);
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/EventDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/EventDAODbFacadeImpl.java
index 141da5f..e6c3805 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/EventDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/EventDAODbFacadeImpl.java
@@ -25,7 +25,7 @@
                 throws SQLException {
             event_subscriber entity = new event_subscriber();
             entity.setevent_up_name(rs.getString("event_up_name"));
-            
entity.setevent_notification_method(EventNotificationMethod.valueOf(rs.getString("notification_method")));
+            
entity.setevent_notification_method(EventNotificationMethod.valueOfString(rs.getString("notification_method")));
             entity.setmethod_address(rs.getString("method_address"));
             entity.setsubscriber_id(getGuidDefaultEmpty(rs, "subscriber_id"));
             entity.settag_name(rs.getString("tag_name"));
@@ -59,7 +59,7 @@
     public void subscribe(event_subscriber subscriber) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("event_up_name", subscriber.getevent_up_name())
-                .addValue("notification_method", 
subscriber.getevent_notification_method().name())
+                .addValue("notification_method", 
subscriber.getevent_notification_method().getAsString())
                 .addValue("method_address", subscriber.getmethod_address())
                 .addValue("subscriber_id", subscriber.getsubscriber_id())
                 .addValue("tag_name", subscriber.gettag_name());
@@ -71,7 +71,7 @@
     public void unsubscribe(event_subscriber subscriber) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("event_up_name", subscriber.getevent_up_name())
-                .addValue("notification_method", 
subscriber.getevent_notification_method().name())
+                .addValue("notification_method", 
subscriber.getevent_notification_method().getAsString())
                 .addValue("subscriber_id", subscriber.getsubscriber_id())
                 .addValue("tag_name", subscriber.gettag_name());
 
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EventDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EventDAOTest.java
index 252124d..ca721f1 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EventDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/EventDAOTest.java
@@ -32,7 +32,7 @@
         newSubscriber = new Guid("9bf7c640-b620-456f-a550-0348f366544b");
         newSubscription = new event_subscriber();
         newSubscription.setsubscriber_id(newSubscriber);
-        
newSubscription.setevent_notification_method(EventNotificationMethod.EMAIL);
+        
newSubscription.setevent_notification_method(EventNotificationMethod.SMTP);
         newSubscription.setevent_up_name("TestRun");
         newSubscription.settag_name("farkle");
 
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 48afb4e..6886a84 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -4063,7 +4063,7 @@
         <row>
             <value>9bf7c640-b620-456f-a550-0348f366544a</value>
             <value>TestRun</value>
-            <value>EMAIL</value>
+            <value>smtp</value>
             <null />
             <value>testrun</value>
         </row>
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java
index d5f582d..8ff7d54 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/NotificationService.java
@@ -118,7 +118,7 @@
                         new FirstMatchSimpleFilter.FilterEntry(
                                 EventsManager.DATABASE_UNREACHABLE,
                                 false,
-                                EventNotificationMethod.EMAIL.name(),
+                                EventNotificationMethod.SMTP.getAsString(),
                                 subscriber);
                     }
                 }
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/smtp/Smtp.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/smtp/Smtp.java
index ff1ea39..8d5e1d2 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/smtp/Smtp.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/smtp/Smtp.java
@@ -172,14 +172,14 @@
                                 message.getMessageBody()));
                     }
                     sendMail(attempt.address, message.getMessageSubject(), 
message.getMessageBody());
-                    notifyObservers(DispatchResult.success(attempt.event, 
attempt.address, EventNotificationMethod.EMAIL));
+                    notifyObservers(DispatchResult.success(attempt.event, 
attempt.address, EventNotificationMethod.SMTP));
                     iterator.remove();
                 } catch (Exception ex) {
                     attempt.retries++;
                     if (attempt.retries >= retries) {
                         notifyObservers(DispatchResult.failure(attempt.event,
                                 attempt.address,
-                                EventNotificationMethod.EMAIL,
+                                EventNotificationMethod.SMTP,
                                 ex.getMessage()));
                         iterator.remove();
                     }
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java
index 990cb75..f9d493e 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java
@@ -131,10 +131,10 @@
                     )
                 );
                 snmp.send(v2pdu, target);
-                notifyObservers(DispatchResult.success(event, address, 
EventNotificationMethod.SNMP_TRAP));
+                notifyObservers(DispatchResult.success(event, address, 
EventNotificationMethod.SNMP));
             } catch (Exception e) {
                 log.error(e.getMessage());
-                notifyObservers(DispatchResult.failure(event, address, 
EventNotificationMethod.SNMP_TRAP, e.getMessage()));
+                notifyObservers(DispatchResult.failure(event, address, 
EventNotificationMethod.SNMP, e.getMessage()));
             }
         }
     }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/users/UserEventNotifierListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/users/UserEventNotifierListModel.java
index 568102c..4e4b974 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/users/UserEventNotifierListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/users/UserEventNotifierListModel.java
@@ -257,14 +257,14 @@
             for (event_subscriber a : existing)
             {
                 toRemoveList.add(new EventSubscriptionParametesBase(new 
event_subscriber(a.getevent_up_name(),
-                        EventNotificationMethod.EMAIL,
+                        EventNotificationMethod.SMTP,
                         a.getmethod_address(),
                         a.getsubscriber_id(), ""), "")); //$NON-NLS-1$ 
//$NON-NLS-2$
             }
             for (SelectionTreeNodeModel a : selected)
             {
                 toAddList.add(new EventSubscriptionParametesBase(new 
event_subscriber(a.getTitle(),
-                        EventNotificationMethod.EMAIL,
+                        EventNotificationMethod.SMTP,
                         (String) model.getEmail().getEntity(),
                         getEntity().getId(), ""), "")); //$NON-NLS-1$ 
//$NON-NLS-2$
             }
@@ -274,7 +274,7 @@
             for (SelectionTreeNodeModel a : added)
             {
                 toAddList.add(new EventSubscriptionParametesBase(new 
event_subscriber(a.getTitle(),
-                        EventNotificationMethod.EMAIL,
+                        EventNotificationMethod.SMTP,
                         (String) model.getEmail().getEntity(),
                         getEntity().getId(), ""), "")); //$NON-NLS-1$ 
//$NON-NLS-2$
             }
@@ -282,7 +282,7 @@
             for (event_subscriber a : removed)
             {
                 toRemoveList.add(new EventSubscriptionParametesBase(new 
event_subscriber(a.getevent_up_name(),
-                        EventNotificationMethod.EMAIL,
+                        EventNotificationMethod.SMTP,
                         a.getmethod_address(),
                         a.getsubscriber_id(), ""), "")); //$NON-NLS-1$ 
//$NON-NLS-2$
             }
diff --git 
a/packaging/dbscripts/upgrade/03_04_0650_fix_event_notfication_method.sql 
b/packaging/dbscripts/upgrade/03_04_0650_fix_event_notfication_method.sql
new file mode 100644
index 0000000..555a106
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_04_0650_fix_event_notfication_method.sql
@@ -0,0 +1,11 @@
+ALTER TABLE event_subscriber RENAME COLUMN notification_method TO nmx;
+ALTER TABLE event_subscriber ADD COLUMN notification_method CHARACTER 
VARYING(32);
+
+UPDATE event_subscriber SET notification_method = 'smtp' WHERE nmx = 'EMAIL';
+UPDATE event_subscriber SET notification_method = 'snmp' WHERE nmx = 
'SNMP_TRAP';
+
+ALTER TABLE event_subscriber DROP COLUMN nmx;
+
+-- Name check constraint so it could be easily dropped in future if needed
+ALTER TABLE event_subscriber ADD CONSTRAINT event_subscriber_method_check 
CHECK (notification_method IN ('smtp', 'snmp'));
+


-- 
To view, visit http://gerrit.ovirt.org/25313
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie93d2d371a6f29a33e32a776e74ada5f221cbb4e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4.0
Gerrit-Owner: Martin Peřina <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to