ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-19356 Change type of fields for Ambari SNMP alert trap (dsen)
Date Fri, 06 Jan 2017 16:23:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 b0adfbfdf -> f08628e7c


AMBARI-19356 Change type of fields for Ambari SNMP alert trap (dsen)


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

Branch: refs/heads/branch-2.5
Commit: f08628e7cfcc8e0fed8cf76bd834344f55503ade
Parents: b0adfbf
Author: Dmytro Sen <dsen@apache.org>
Authored: Fri Jan 6 18:22:43 2017 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Fri Jan 6 18:22:43 2017 +0200

----------------------------------------------------------------------
 .../dispatchers/AmbariSNMPDispatcher.java       | 37 ++++++++++++++------
 .../dispatchers/AmbariSNMPDispatcherTest.java   | 12 +++++++
 2 files changed, 39 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f08628e7/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcher.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcher.java
b/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcher.java
index dcc8aac..1eb9977 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcher.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcher.java
@@ -28,12 +28,14 @@ import org.slf4j.LoggerFactory;
 import org.snmp4j.PDU;
 import org.snmp4j.Snmp;
 import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.smi.Integer32;
 import org.snmp4j.smi.OID;
 import org.snmp4j.smi.OctetString;
 import org.snmp4j.smi.VariableBinding;
 import org.snmp4j.util.DefaultPDUFactory;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -112,15 +114,15 @@ public class AmbariSNMPDispatcher extends SNMPDispatcher {
         pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(AMBARI_ALERT_TRAP_OID)));
         // Set notification body and subject for PDU objects with identifiers specified in
dispatch properties.
         AlertNoticeDispatchService.AlertInfo alertInfo = alertNotification.getAlertInfo();
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_ID_OID, alertInfo.getAlertDefinitionId());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_NAME_OID, alertInfo.getAlertDefinition().getDefinitionName());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_HASH_OID, alertInfo.getAlertDefinitionHash());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_NAME_OID, alertInfo.getAlertName());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_TEXT_OID, alertInfo.getAlertText());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_STATE_OID, alertInfo.getAlertState().getIntValue());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_HOST_NAME_OID, alertInfo.getHostName());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_SERVICE_NAME_OID, alertInfo.getServiceName());
-        addVariableBindingCheckForNull(pdu, AMBARI_ALERT_COMPONENT_NAME_OID, alertInfo.getComponentName());
+        addIntVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_ID_OID, new BigDecimal(alertInfo.getAlertDefinitionId()).intValueExact());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_NAME_OID, alertInfo.getAlertDefinition().getDefinitionName());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_DEFINITION_HASH_OID, alertInfo.getAlertDefinitionHash());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_NAME_OID, alertInfo.getAlertName());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_TEXT_OID, alertInfo.getAlertText());
+        addIntVariableBindingCheckForNull(pdu, AMBARI_ALERT_STATE_OID, alertInfo.getAlertState().getIntValue());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_HOST_NAME_OID, alertInfo.getHostName());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_SERVICE_NAME_OID, alertInfo.getServiceName());
+        addStringVariableBindingCheckForNull(pdu, AMBARI_ALERT_COMPONENT_NAME_OID, alertInfo.getComponentName());
 
         return pdu;
     }
@@ -140,7 +142,7 @@ public class AmbariSNMPDispatcher extends SNMPDispatcher {
      * @param oid
      * @param val
      */
-    private void addVariableBindingCheckForNull(PDU pdu, String oid, Object val) {
+    private void addStringVariableBindingCheckForNull(PDU pdu, String oid, Object val) {
         if (val == null)  {
             pdu.add(new VariableBinding(new OID(oid), new OctetString("null")));
         } else {
@@ -148,4 +150,19 @@ public class AmbariSNMPDispatcher extends SNMPDispatcher {
                     new OctetString(String.valueOf(val))));
         }
     }
+    /**
+     * Adds new {@link VariableBinding} using provided {@link OID} and value to {@link PDU}
+     * if val is null than adds {@link OctetString} with "null" value;
+     * @param pdu
+     * @param oid
+     * @param val
+     */
+    private void addIntVariableBindingCheckForNull(PDU pdu, String oid, Integer val) {
+        if (val == null)  {
+            pdu.add(new VariableBinding(new OID(oid), new OctetString("null")));
+        } else {
+            pdu.add(new VariableBinding(new OID(oid),
+                    new Integer32(val)));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f08628e7/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcherTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcherTest.java
index 1f18c82..b1fee2b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AmbariSNMPDispatcherTest.java
@@ -34,6 +34,9 @@ import org.snmp4j.PDU;
 import org.snmp4j.Snmp;
 import org.snmp4j.Target;
 import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
 import org.snmp4j.smi.VariableBinding;
 
 import java.io.IOException;
@@ -245,14 +248,23 @@ public class AmbariSNMPDispatcherTest {
         }
         assertEquals(10, variableBindings.size());
         assertEquals(AmbariSNMPDispatcher.AMBARI_ALERT_TRAP_OID, variableBindings.get(SnmpConstants.snmpTrapOID.toString()).toValueString());
+        assertTrue(variableBindings.get(SnmpConstants.snmpTrapOID.toString()).getVariable()
instanceof OID);
         assertEquals(String.valueOf(DEFINITION_ID), variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_DEFINITION_ID_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_DEFINITION_ID_OID).getVariable()
instanceof Integer32);
         assertEquals(DEFINITION_NAME, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_DEFINITION_NAME_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_DEFINITION_NAME_OID).getVariable()
instanceof OctetString);
         assertEquals(ALERT_LABEL, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_NAME_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_NAME_OID).getVariable()
instanceof OctetString);
         assertEquals(ALERT_TEXT, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_TEXT_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_TEXT_OID).getVariable()
instanceof OctetString);
         assertEquals(String.valueOf(ALERT_STATE.getIntValue()), variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_STATE_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_STATE_OID).getVariable()
instanceof Integer32);
         assertEquals(ALERT_HOSTNAME, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_HOST_NAME_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_HOST_NAME_OID).getVariable()
instanceof OctetString);
         assertEquals(ALERT_SERVICE_NAME, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_SERVICE_NAME_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_SERVICE_NAME_OID).getVariable()
instanceof OctetString);
         assertEquals(ALERT_COMPONENT_NAME, variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_COMPONENT_NAME_OID).toValueString());
+        assertTrue(variableBindings.get(AmbariSNMPDispatcher.AMBARI_ALERT_COMPONENT_NAME_OID).getVariable()
instanceof OctetString);
     }
 
     @Test


Mime
View raw message