Netvirt: Qos Alert patch6 20/56120/10
authorArun Sharma <arun.e.sharma@ericsson.com>
Wed, 26 Apr 2017 19:09:07 +0000 (00:39 +0530)
committerSam Hague <shague@redhat.com>
Mon, 1 May 2017 18:02:15 +0000 (18:02 +0000)
*** patch #6 - Added log4j configuraton support ***

1. Added a new log4j appender with default logging properties in qosalert.cfg
2. Added listener method update in QosAlertGenerator class to handle any chage in qosalert.cfg

Spec Review Link:
https://git.opendaylight.org/gerrit/50689

Change-Id: I2008a0a2dd22661e0f45251f0aac1088270d3d96
Signed-off-by: Arun Sharma <arun.e.sharma@ericsson.com>
docs/specs/qos-alert.rst
vpnservice/features/odl-netvirt-impl/pom.xml
vpnservice/features/odl-netvirt-impl/src/main/feature/feature.xml
vpnservice/features/vpnservice-features/pom.xml
vpnservice/features/vpnservice-features/src/main/features/features.xml
vpnservice/qosservice/impl/pom.xml
vpnservice/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosAlertGenerator.java
vpnservice/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosConstants.java
vpnservice/qosservice/impl/src/main/resources/initial/netvirt-qosservice-config.xml [moved from vpnservice/qosservice/impl/src/main/resources/initial/netvirt-qosalert-config.xml with 100% similarity]
vpnservice/qosservice/impl/src/main/resources/initial/qosservice.cfg [new file with mode: 0644]
vpnservice/qosservice/impl/src/main/resources/org/opendaylight/blueprint/qosservice.xml

index fccc07e561b754f8ed83ba0c2c6b8f23d400af88..15413ceea0664a2be69660ff8c0dfc14dae5f447 100644 (file)
@@ -109,7 +109,7 @@ A new yang file shall be created for qos-alert configuration as specified below:
 Configuration impact
 ---------------------
 Following new parameters shall be made available as configuration. Initial or default configuration
-is specified in ``netvirt-qosalert-config.xml``
+is specified in ``netvirt-qosservice-config.xml``
 
 ======== =============================  ====================================================
   Sl No.  configuration                 Description
index e27790dbdfd752d226eadef09022960b28f5bcea..66035642e34ae4a61171923b67ca96ebd3b7515f 100644 (file)
             <classifier>config</classifier>
         </dependency>
         <dependency>
-            <!-- finalname="etc/opendaylight/datastore/initial/config/netvirt-qosalert-config.xml" -->
+            <!-- finalname="etc/opendaylight/datastore/initial/config/netvirt-qosservice-config.xml" -->
             <groupId>${project.groupId}</groupId>
             <artifactId>qosservice-impl</artifactId>
             <version>${project.version}</version>
             <type>xml</type>
             <classifier>config</classifier>
         </dependency>
+        <dependency>
+            <!-- finalname="etc/org.opendaylight.netvirt.qosservice.cfg" -->
+            <groupId>${project.groupId}</groupId>
+            <artifactId>qosservice-impl</artifactId>
+            <version>${project.version}</version>
+            <type>cfg</type>
+            <classifier>config</classifier>
+        </dependency>
         <dependency>
             <!-- finalname="etc/opendaylight/datastore/initial/config/netvirt-statistics-config.xml" -->
             <groupId>${project.groupId}</groupId>
             <classifier>config</classifier>
         </dependency>
     </dependencies>
-</project>
\ No newline at end of file
+</project>
index 69a4da4e178dfb1cb18631b3ca3183b501e9deee..b93b8b169239c593189dcb6932093ea132647755 100644 (file)
         <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-neutronvpn-config.xml">
             mvn:org.opendaylight.netvirt/neutronvpn-impl/${project.version}/xml/config
         </configfile>
-        <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-qosalert-config.xml">
+        <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-qosservice-config.xml">
             mvn:org.opendaylight.netvirt/qosservice-impl/${project.version}/xml/config
         </configfile>
+        <configfile finalname="etc/org.opendaylight.netvirt.qosservice.cfg">
+            mvn:org.opendaylight.netvirt/qosservice-impl/${project.version}/cfg/config
+        </configfile>
         <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-statistics-config.xml">
             mvn:org.opendaylight.netvirt/statistics-impl/${project.version}/xml/config
         </configfile>
index bfc2070df1512a0759be7b49d4fa21fbe92adf00..86c4ea9f432c7a05802e3d0db60d024c62d1f755 100644 (file)
       <type>xml</type>
       <classifier>config</classifier>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>qosservice-impl</artifactId>
+      <version>${project.version}</version>
+      <type>cfg</type>
+      <classifier>config</classifier>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>aclservice-api</artifactId>
index e1ae9c6cec4e1f5748a54f22657cc37312911cc0..82f551fa7434c11bd78d7cfe88d570c538fec270 100644 (file)
@@ -89,7 +89,8 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-elanmanager-config.xml">mvn:org.opendaylight.netvirt/elanmanager-impl/{{VERSION}}/xml/config</configfile>
     <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml">mvn:org.opendaylight.netvirt/natservice-impl/{{VERSION}}/xml/config</configfile>
     <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-neutronvpn-config.xml">mvn:org.opendaylight.netvirt/neutronvpn-impl/{{VERSION}}/xml/config</configfile>
-    <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-qosalert-config.xml">mvn:org.opendaylight.netvirt/qosservice-impl/{{VERSION}}/xml/config</configfile>
+    <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-qosservice-config.xml">mvn:org.opendaylight.netvirt/qosservice-impl/{{VERSION}}/xml/config</configfile>
+    <configfile finalname="etc/org.opendaylight.netvirt.qosservice.cfg">mvn:org.opendaylight.netvirt/qosservice-impl/{{VERSION}}/cfg/config</configfile>
     <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-statistics-config.xml">mvn:org.opendaylight.netvirt/statistics-impl/{{VERSION}}/xml/config</configfile>
     <configfile finalname="etc/opendaylight/datastore/initial/config/netvirt-vpnmanager-config.xml">mvn:org.opendaylight.netvirt/vpnmanager-impl/{{VERSION}}/xml/config</configfile>
   </feature>
index 42400bef698591dd2d76049e2cd7b3d1d9656ed7..1ba6ca969ea6a1ad331370e1a2e8d96ae36f889d 100644 (file)
@@ -60,7 +60,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             <artifactId>org.apache.karaf.shell.console</artifactId>
             <scope>provided</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.configadmin</artifactId>
+            <version>1.8.14</version>
+        </dependency>
     </dependencies>
 
 
@@ -79,10 +83,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
               <configuration>
                 <artifacts>
                   <artifact>
-                    <file>${project.build.directory}/classes/initial/netvirt-qosalert-config.xml</file>
+                    <file>${project.build.directory}/classes/initial/netvirt-qosservice-config.xml</file>
                     <type>xml</type>
                     <classifier>config</classifier>
                   </artifact>
+                  <artifact>
+                    <file>${project.build.directory}/classes/initial/qosservice.cfg</file>
+                    <type>cfg</type>
+                    <classifier>config</classifier>
+                  </artifact>
                 </artifacts>
               </configuration>
             </execution>
index efd7de6e258783162f9216f10db022b19419cd5a..a66a485b487999242e12af6a9c233b1ef7d25b14 100644 (file)
@@ -8,16 +8,35 @@
 
 package org.opendaylight.netvirt.qosservice;
 
+import java.io.IOException;
 import java.math.BigInteger;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class QosAlertGenerator {
 
-    private static final  Logger LOG = LoggerFactory.getLogger(QosAlertGenerator.class);
+    private static ConfigurationAdmin configurationAdmin;
+    private static final Logger LOG = LoggerFactory.getLogger(QosAlertGenerator.class);
+
+    public QosAlertGenerator() {
+        BundleContext bundleContext = FrameworkUtil.getBundle(QosAlertGenerator.class).getBundleContext();
+        configurationAdmin = (ConfigurationAdmin) bundleContext.getService(bundleContext
+                .getServiceReference(ConfigurationAdmin.class.getName()));
+        updateQoSAlertLog4jProperties(getPropertyMap(QosConstants.QOS_ALERT_PROPERTIES_PID));
+    }
 
-    private QosAlertGenerator() {
-       // Hide implicit constructor
+    public void update(Map<String, Object> qosAlertProperties) {
+        updateQoSAlertLog4jProperties(qosAlertProperties);
     }
 
     public static void raiseAlert(final String qosPolicyName, final String qosPolicyUuid, final String portUuid,
@@ -25,7 +44,50 @@ public class QosAlertGenerator {
                                   final BigInteger rxDroppedPackets) {
         // Log the alert message in a text file using log4j appender qosalertmsg
         LOG.debug(QosConstants.alertMsgFormat, qosPolicyName, qosPolicyUuid, portUuid, networkUuid,
-                                                                                   rxPackets, rxDroppedPackets);
+                                                                                        rxPackets, rxDroppedPackets);
     }
 
+    private static Configuration getConfig(String pid) {
+        Configuration config = null;
+        try {
+            config = configurationAdmin.getConfiguration(pid);
+        } catch (java.io.IOException ioe) {
+            LOG.error("Exception in configuration {}", ioe);
+        }
+        return (config);
+    }
+
+    private static Map<String, Object> getPropertyMap(String pid) {
+        Map<String, Object> propertyMap = null;
+        Configuration configurationInit = getConfig(pid);
+        Dictionary<String, Object> config = configurationInit.getProperties();
+        propertyMap = new HashMap<>(config.size());
+        Enumeration<String> keys = config.keys();
+        while (keys.hasMoreElements()) {
+            String key = keys.nextElement();
+            propertyMap.put(key, config.get(key));
+        }
+        return (propertyMap);
+    }
+
+    private static Map<String, Object> removeNonLog4jProperties(Map<String, Object> qosAlertLog4jProperties) {
+        qosAlertLog4jProperties.remove(QosConstants.FELIX_FILEINSTALL_FILENAME);
+        qosAlertLog4jProperties.remove(QosConstants.SERVICE_PID);
+        return (qosAlertLog4jProperties);
+    }
+
+    private static void updateQoSAlertLog4jProperties(Map<String, Object> qosAlertLog4jProperties) {
+        Map<String, Object> log4jProperties = getPropertyMap(QosConstants.ORG_OPS4J_PAX_LOGGING);
+        Hashtable<String, Object> updateLog4jProperties = new Hashtable<>();
+        updateLog4jProperties.putAll(log4jProperties);
+        updateLog4jProperties.putAll(removeNonLog4jProperties(qosAlertLog4jProperties));
+
+        Configuration log4jConfig = getConfig(QosConstants.ORG_OPS4J_PAX_LOGGING);
+        try {
+            log4jConfig.update(updateLog4jProperties);
+            log4jConfig.update();
+        } catch (IOException ioe) {
+            LOG.error("Exception in configuration {}", ioe);
+        }
+    }
 }
index b28889260170091b8a6c7ef0f8d6899294ad300c..609e8b1ca9e7a8d1d8c93c5e4c0b388a94955d79 100644 (file)
@@ -12,4 +12,8 @@ public class QosConstants {
     public static final int QOS_DEFAULT_FLOW_PRIORITY = 10;
     public static String alertMsgFormat = "Packet drop threshold hit for qos policy {} with qos-id {} for port port-{}"
         + " on network network-{} rx_received {} rx_dropped {}";
+    public static final String QOS_ALERT_PROPERTIES_PID = "org.opendaylight.netvirt.qosservice";
+    public static final String ORG_OPS4J_PAX_LOGGING = "org.ops4j.pax.logging";
+    public static final String FELIX_FILEINSTALL_FILENAME = "felix.fileinstall.filename";
+    public static final String SERVICE_PID = "service.pid";
 }
diff --git a/vpnservice/qosservice/impl/src/main/resources/initial/qosservice.cfg b/vpnservice/qosservice/impl/src/main/resources/initial/qosservice.cfg
new file mode 100644 (file)
index 0000000..5c351d2
--- /dev/null
@@ -0,0 +1,9 @@
+log4j.logger.org.opendaylight.netvirt.qosservice.QosAlertGenerator=TRACE, qosalertmsg
+log4j.additivity.org.opendaylight.netvirt.qosservice.QosAlertGenerator=false
+log4j.appender.qosalertmsg=org.apache.log4j.RollingFileAppender
+log4j.appender.qosalertmsg.layout=org.apache.log4j.PatternLayout
+log4j.appender.qosalertmsg.layout.ConversionPattern=%d{ISO8601} %m%n
+log4j.appender.qosalertmsg.file=${karaf.home}/qosalert/qosalert.log
+log4j.appender.qosalertmsg.append=true
+log4j.appender.qosalertmsg.maxFileSize=1MB
+log4j.appender.qosalertmsg.maxBackupIndex=10
index 29be4dc65322aeadea2bac38a696617879b6f7f7..770ec7c74741529cf921c91d1ed2d82d1bceea31 100644 (file)
@@ -23,7 +23,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     <odl:clustered-app-config id="qosalertConfig"
                               binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.qosalert.config.rev170301.QosalertConfig"
-                              default-config-file-name="netvirt-qosalert-config.xml"
+                              default-config-file-name="netvirt-qosservice-config.xml"
                               update-strategy="none">
     </odl:clustered-app-config>
 
@@ -51,4 +51,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
     </command-bundle>
 
+    <bean id="qosAlertGenerator" class="org.opendaylight.netvirt.qosservice.QosAlertGenerator">
+      <cm:managed-properties persistent-id="org.opendaylight.netvirt.qosservice"
+                           update-strategy="component-managed" update-method="update"/>
+    </bean>
+
 </blueprint>