This patch implements logger on neutron model change for debug.
Change-Id: Ifd079de8cded725d79ec2fe638415ab7be640318
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
<artifactId>transcriber</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>neutron-logger</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
<bundle>mvn:org.opendaylight.neutron/model/{{VERSION}}</bundle>
<bundle>mvn:org.osgi/org.osgi.core/{{VERSION}}</bundle>
</feature>
+ <feature name='odl-neutron-logger' version='${project.version}' description="OpenDaylight :: Neutron :: Logger">
+ <feature version='${controller.mdsal.version}'>odl-mdsal-broker</feature>
+ <bundle>mvn:org.opendaylight.neutron/model/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.neutron/neutron-logger/{{VERSION}}</bundle>
+ <bundle>mvn:org.osgi/org.osgi.core/{{VERSION}}</bundle>
+ </feature>
</features>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>dummyprovider</artifactId>
+ <artifactId>neutron-logger</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.neutron/features-neutron/{{VERSION}}/xml/features</repository>
- <feature name='odl-neutron-dummyprovider-test' version='${project.version}' description="OpenDaylight :: Neutron :: Dummy Provider Test">
+ <feature name='odl-neutron-neutron-logger-test' version='${project.version}' description="OpenDaylight :: Neutron :: Neutron Logger Test">
<feature version='${project.version}'>odl-neutron-service</feature>
- <bundle>mvn:org.opendaylight.neutron/dummyprovider/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.neutron/neutron-logger/{{VERSION}}</bundle>
</feature>
</features>
<classifier>features</classifier>
<type>xml</type>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>dummyprovider</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.opendaylight.neutron</groupId>
<artifactId>neutron-karaf</artifactId>
</goals>
<configuration>
<artifactItems>
+ <artifactItem>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>neutron-logger</artifactId>
+ <version>${project.version}</version>
+ </artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>neutron-spi</artifactId>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.neutron/features-neutron/{{VERSION}}/xml/features</repository>
- <feature name='odl-neutron-dummyprovider-test' version='${project.version}' description="OpenDaylight :: Neutron :: Dummy Provider Test">
+ <feature name='odl-neutron-neutron-logger-test' version='${project.version}' description="OpenDaylight :: Neutron :: Neutron Logger Test">
<feature version='${project.version}'>odl-neutron-service</feature>
- <bundle>mvn:org.opendaylight.neutron/dummyprovider/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.neutron/neutron-logger/{{VERSION}}</bundle>
</feature>
</features>
<maven>3.1.1</maven>
</prerequisites>
<properties>
- <karaf.localFeature>odl-neutron-dummyprovider-test</karaf.localFeature>
+ <karaf.localFeature>odl-neutron-neutron-logger-test</karaf.localFeature>
<checkstyle.location>${project.parent.basedir}/src/main/resources</checkstyle.location>
</properties>
<dependencies>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<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>config-parent</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.neutron</groupId>
+ <artifactId>neutron-logger</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <properties>
+ <checkstyle.location>${project.parent.basedir}/src/main/resources</checkstyle.location>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>mdsal-model-artifacts</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.neutron</groupId>
+ <artifactId>neutron-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.neutron</groupId>
+ <artifactId>model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>*</Import-Package>
+ </instructions>
+ <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <scm>
+ <connection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</connection>
+ <developerConnection>scm:git:ssh://git.opendaylight.org:29418/neutron.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://wiki.opendaylight.org/view/NeutronNorthBound:Main</url>
+ </scm>
+ <distributionManagement>
+ <!-- OpenDayLight Released artifact -->
+ <repository>
+ <id>opendaylight-release</id>
+ <url>${nexusproxy}/repositories/${nexus.repository.release}/</url>
+ </repository>
+ <!-- OpenDayLight Snapshot artifact -->
+ <snapshotRepository>
+ <id>opendaylight-snapshot</id>
+ <url>${nexusproxy}/repositories/${nexus.repository.snapshot}/</url>
+ </snapshotRepository>
+ <!-- Site deployment -->
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
+
+ <!--
+ Maven Site Configuration
+
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2016 Intel Corporation and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.neutron.logger;
+
+import com.google.common.base.Preconditions;
+
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronLogger implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NeutronLogger.class);
+
+ private DataBroker db;
+ private ClusteredDataTreeChangeListener configurationDataTreeChangeListener;
+ private ListenerRegistration<? extends ClusteredDataTreeChangeListener> configurationRegisteredListener;
+ private ClusteredDataTreeChangeListener operationalDataTreeChangeListener;
+ private ListenerRegistration<? extends ClusteredDataTreeChangeListener> operationalRegisteredListener;
+
+ public NeutronLogger(@Nonnull DataBroker db) {
+ LOG.info("Creating NeutronLogger {}", db);
+ this.db = Preconditions.checkNotNull(db, "null db");
+ }
+
+ private <T extends DataObject>
+ void formatModification(@Nonnull final StringBuilder messageBuilder,
+ @Nonnull final DataObjectModification<T> objectModification) {
+ final String typeName = objectModification.getDataType().getSimpleName();
+
+ switch (objectModification.getModificationType()) {
+ case SUBTREE_MODIFIED:
+ for (final DataObjectModification<? extends DataObject> child :
+ objectModification.getModifiedChildren()) {
+ formatModification(messageBuilder, child);
+ }
+ break;
+ case WRITE:
+ messageBuilder.append("\n");
+ messageBuilder.append("WRITE: type: ").append(typeName).append("\n");
+ final T dataAfter = objectModification.getDataAfter();
+ messageBuilder.append(dataAfter.toString());
+ break;
+ case DELETE:
+ messageBuilder.append("\n");
+ messageBuilder.append("DELETE: ").append(typeName);
+ break;
+ default:
+ LOG.warn("unknown modification type: {}", typeName);
+ break;
+ }
+ }
+
+ private <T extends DataObject>
+ void formatChanges(@Nonnull final StringBuilder messageBuilder,
+ @Nonnull final Collection<DataTreeModification<T>> changes) {
+ for (DataTreeModification modification : changes) {
+ final DataTreeIdentifier<T> identifier = modification.getRootPath();
+ final LogicalDatastoreType datastoreType = identifier.getDatastoreType();
+ if (datastoreType == LogicalDatastoreType.OPERATIONAL) {
+ messageBuilder.append("OPERATIONAL: ");
+ } else {
+ messageBuilder.append("CONFIGURATION: ");
+ }
+
+ final DataObjectModification<T> objectModification = modification.getRootNode();
+ formatModification(messageBuilder, objectModification);
+ }
+ }
+
+ private void logChanges(String prefix, @Nonnull Collection<DataTreeModification<Neutron>> changes) {
+ final StringBuilder messageBuilder = new StringBuilder();
+ messageBuilder.append(prefix);
+ formatChanges(messageBuilder, changes);
+ LOG.info(messageBuilder.toString());
+ }
+
+ private void configurationDataTreeChanged(@Nonnull Collection<DataTreeModification<Neutron>> changes) {
+ logChanges("Configuration DataTreeChanged ", changes);
+ }
+
+ private void operationalDataTreeChanged(@Nonnull Collection<DataTreeModification<Neutron>> changes) {
+ logChanges("Operational DataTreeChanged ", changes);
+ }
+
+ public void init() {
+ LOG.info("Register listener for Neutron model data changes");
+ InstanceIdentifier<Neutron> instanceId = Preconditions.checkNotNull(InstanceIdentifier.create(Neutron.class));
+
+ DataTreeIdentifier<Neutron> configurationDataTreeId =
+ new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceId);
+ configurationDataTreeChangeListener = new ClusteredDataTreeChangeListener<Neutron>() {
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<Neutron>> changes) {
+ configurationDataTreeChanged(changes);
+ }
+ };
+ configurationRegisteredListener = db.registerDataTreeChangeListener(configurationDataTreeId,
+ configurationDataTreeChangeListener);
+
+ DataTreeIdentifier<Neutron> operationalDataTreeId =
+ new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, instanceId);
+ operationalDataTreeChangeListener = new ClusteredDataTreeChangeListener<Neutron>() {
+ @Override
+ public void onDataTreeChanged(Collection<DataTreeModification<Neutron>> changes) {
+ operationalDataTreeChanged(changes);
+ }
+ };
+ operationalRegisteredListener = db.registerDataTreeChangeListener(operationalDataTreeId,
+ operationalDataTreeChangeListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ configurationRegisteredListener.close();
+ configurationRegisteredListener = null;
+ operationalRegisteredListener.close();
+ operationalRegisteredListener = null;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="dataBroker"
+ interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+ odl:type="default" />
+
+ <bean id="neutronLogger"
+ class="org.opendaylight.neutron.logger.NeutronLogger"
+ init-method="init"
+ destroy-method="close">
+ <argument ref="dataBroker"/>
+ </bean>
+
+</blueprint>
<module>northbound-api</module>
<module>transcriber</module>
<module>dummyprovider</module>
+ <module>neutron-logger</module>
<module>features/production</module>
<module>features/test</module>
<module>karaf</module>