MD-SAL Statistics Provider 22/2722/1
authorAnil Vishnoi <avishnoi@in.ibm.com>
Wed, 13 Nov 2013 21:42:19 +0000 (03:12 +0530)
committerAnil Vishnoi <avishnoi@in.ibm.com>
Wed, 13 Nov 2013 21:44:07 +0000 (03:14 +0530)
Change-Id: I9ae1235b88546f25795c51780057dfe52d19967f
Signed-off-by: Anil Vishnoi <avishnoi@in.ibm.com>
opendaylight/md-sal/pom.xml
opendaylight/md-sal/statistics-manager/pom.xml [new file with mode: 0644]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsManagerActivator.java [new file with mode: 0644]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java [new file with mode: 0644]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java [new file with mode: 0644]

index 99ce493..3198109 100644 (file)
@@ -45,6 +45,7 @@
         <module>clustered-data-store/implementation</module>
 
         <module>inventory-manager</module>
+        <module>statistics-manager</module>
         <!-- Compability Packages -->
         <module>compatibility</module>
 
diff --git a/opendaylight/md-sal/statistics-manager/pom.xml b/opendaylight/md-sal/statistics-manager/pom.xml
new file mode 100644 (file)
index 0000000..3a355d2
--- /dev/null
@@ -0,0 +1,65 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-parent</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <groupId>org.opendaylight.controller.md</groupId>
+    <artifactId>statistics-manager</artifactId>
+    <packaging>bundle</packaging>
+    <scm>
+        <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+        <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+        <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal-binding-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller.model</groupId>
+            <artifactId>model-flow-statistics</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller.model</groupId>
+            <artifactId>model-flow-base</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.xtend</groupId>
+            <artifactId>org.eclipse.xtend.lib</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>org.opendaylight.controller.md.statistics.manager.StatisticsManagerActivator</Bundle-Activator>
+                        <Private-Package>org.opendaylight.controller.md.statistics.manager</Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.eclipse.xtend</groupId>
+                <artifactId>xtend-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <artifactId>maven-clean-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsManagerActivator.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsManagerActivator.java
new file mode 100644 (file)
index 0000000..3c5c579
--- /dev/null
@@ -0,0 +1,35 @@
+package org.opendaylight.controller.md.statistics.manager;
+
+import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.osgi.framework.BundleContext;
+
+public class StatisticsManagerActivator extends AbstractBindingAwareProvider {
+
+    private static ProviderContext pSession;
+    
+    private static StatisticsProvider statsProvider = new StatisticsProvider();
+   
+    @Override
+    public void onSessionInitiated(ProviderContext session) {
+        
+        DataProviderService dps = session.<DataProviderService>getSALService(DataProviderService.class);
+        StatisticsManagerActivator.statsProvider.setDataService(dps);
+        NotificationProviderService nps = session.<NotificationProviderService>getSALService(NotificationProviderService.class);
+        StatisticsManagerActivator.statsProvider.setNotificationService(nps);
+        StatisticsManagerActivator.statsProvider.start();
+
+    }
+    
+    @Override
+    protected void stopImpl(BundleContext context) {
+        StatisticsManagerActivator.statsProvider.close();
+    }
+    
+    public static ProviderContext getProviderContext(){
+        return pSession;
+    }
+
+}
diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java
new file mode 100644 (file)
index 0000000..073d43e
--- /dev/null
@@ -0,0 +1,82 @@
+package org.opendaylight.controller.md.statistics.manager;
+
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StatisticsProvider implements AutoCloseable {
+
+    public final static Logger spLogger = LoggerFactory.getLogger(StatisticsProvider.class);
+    
+    private DataProviderService dps;
+
+    private NotificationProviderService nps;
+    
+    private OpendaylightGroupStatisticsService groupStatsService;
+    
+    private OpendaylightMeterStatisticsService meterStatsService;
+    
+    public DataProviderService getDataService() {
+      return this.dps;
+    }
+    
+    public void setDataService(final DataProviderService dataService) {
+      this.dps = dataService;
+    }
+    
+    public NotificationProviderService getNotificationService() {
+      return this.nps;
+    }
+    
+    public void setNotificationService(final NotificationProviderService notificationService) {
+      this.nps = notificationService;
+    }
+
+    private final StatisticsUpdateCommiter updateCommiter = new StatisticsUpdateCommiter(StatisticsProvider.this);
+    
+    private Registration<NotificationListener> listenerRegistration;
+    
+    public void start() {
+        
+        NotificationProviderService nps = this.getNotificationService();
+        Registration<NotificationListener> registerNotificationListener = nps.registerNotificationListener(this.updateCommiter);
+        this.listenerRegistration = registerNotificationListener;
+        
+        // Get Group/Meter statistics service instance
+        groupStatsService = StatisticsManagerActivator.getProviderContext().getRpcService(OpendaylightGroupStatisticsService.class);
+        
+        meterStatsService = StatisticsManagerActivator.getProviderContext().getRpcService(OpendaylightMeterStatisticsService.class);
+
+        spLogger.info("Statistics Provider started.");
+    }
+    
+    protected DataModificationTransaction startChange() {
+        
+        DataProviderService dps = this.getDataService();
+        return dps.beginTransaction();
+    }
+    
+    @Override
+    public void close(){
+        
+        try {
+            spLogger.info("Statistics Provider stopped.");
+            if (this.listenerRegistration != null) {
+              
+                this.listenerRegistration.close();
+            
+            }
+          } catch (Throwable e) {
+            throw Exceptions.sneakyThrow(e);
+          }
+
+    }
+
+}
diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsUpdateCommiter.java
new file mode 100644 (file)
index 0000000..f952124
--- /dev/null
@@ -0,0 +1,57 @@
+package org.opendaylight.controller.md.statistics.manager;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsListener;
+
+public class StatisticsUpdateCommiter implements OpendaylightGroupStatisticsListener,
+        OpendaylightMeterStatisticsListener {
+    
+    private final StatisticsProvider statisticsManager;
+
+    public StatisticsUpdateCommiter(final StatisticsProvider manager){
+
+        this.statisticsManager = manager;
+    }
+    public StatisticsProvider getStatisticsManager(){
+        return statisticsManager;
+    }
+    @Override
+    public void onMeterConfigStatsUpdated(MeterConfigStatsUpdated notification) {
+        // TODO Auto-generated method stub
+    }
+
+    @Override
+    public void onMeterStatisticsUpdated(MeterStatisticsUpdated notification) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onGroupDescStatsUpdated(GroupDescStatsUpdated notification) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void onGroupStatisticsUpdated(GroupStatisticsUpdated notification) {
+        // TODO Auto-generated method stub
+
+    }
+    @Override
+    public void onMeterFeaturesUpdated(MeterFeaturesUpdated notification) {
+        // TODO Auto-generated method stub
+        
+    }
+    @Override
+    public void onGroupFeaturesUpdated(GroupFeaturesUpdated notification) {
+        // TODO Auto-generated method stub
+        
+    }
+
+}