fix tracing ping-pong DataBroker wiring bug in trace blueprint XML 56/72656/5
authorMichael Vorburger <vorburger@redhat.com>
Mon, 4 Jun 2018 13:13:48 +0000 (15:13 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 6 Jun 2018 01:16:26 +0000 (01:16 +0000)
JIRA: CONTROLLER-1834
Change-Id: I4fda43c578ee55218acc40be1fbf4427c81c73c3
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/mdsal-trace/binding-impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
opendaylight/md-sal/mdsal-trace/cli/src/main/java/org/opendaylight/controller/md/sal/trace/cli/PrintOpenTransactionsCommand.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/java/org/opendaylight/controller/md/sal/trace/dom/impl/TracingBroker.java
opendaylight/md-sal/mdsal-trace/dom-impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
opendaylight/md-sal/mdsal-trace/dom-impl/src/test/java/org/opendaylight/controller/md/sal/trace/tests/TracingBrokerTest.java

index c44d55b..447ea6a 100644 (file)
@@ -29,11 +29,12 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
             interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
             odl:type="default" ranking="10"/>
 
-  <reference id="domPingPongDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
-                                                                                            odl:type="pingpong"/>
+  <reference id="tracingPingPongDOMDataBroker"
+      interface="org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker"
+      odl:type="pingpong"/>
 
   <bean id="bindingTracingPingPongDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
-    <argument ref="domPingPongDataBroker"/>
+    <argument ref="tracingPingPongDOMDataBroker"/>
     <argument ref="mappingCodec"/>
   </bean>
 
index 7f26f0d..7694ceb 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.md.sal.trace.cli;
 
+import java.util.List;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
@@ -25,7 +26,7 @@ import org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker;
 public class PrintOpenTransactionsCommand implements Action {
 
     @Reference
-    private TracingDOMDataBroker tracingDOMDataBroker;
+    private List<TracingDOMDataBroker> tracingDOMDataBrokers;
 
     // NB: Do NOT have a non-default constructor for injection of @Reference
     // Karaf needs a default constructor to create the command - and it works as is.
@@ -33,8 +34,8 @@ public class PrintOpenTransactionsCommand implements Action {
     @Override
     @SuppressWarnings("checkstyle:RegexpSingleLineJava")
     public Object execute() throws Exception {
-        if (!tracingDOMDataBroker.printOpenTransactions(System.out)) {
-            System.out.println("No open transactions, great!");
+        for (TracingDOMDataBroker tracingDOMDataBroker : tracingDOMDataBrokers) {
+            tracingDOMDataBroker.printOpenTransactions(System.out);
         }
         return null;
     }
index 8160b46..f66aa25 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.controller.md.sal.trace.dom.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -104,6 +105,7 @@ public class TracingBroker implements TracingDOMDataBroker {
 
     private static final int STACK_TRACE_FIRST_RELEVANT_FRAME = 2;
 
+    private final String type; // "default" VS "pingpong"
     private final BindingNormalizedNodeSerializer codec;
     private final DOMDataBroker delegate;
     private final List<Watch> registrationWatches = new ArrayList<>();
@@ -165,9 +167,10 @@ public class TracingBroker implements TracingDOMDataBroker {
         }
     }
 
-    public TracingBroker(DOMDataBroker delegate, Config config, BindingNormalizedNodeSerializer codec) {
-        this.delegate = Objects.requireNonNull(delegate);
-        this.codec = Objects.requireNonNull(codec);
+    public TracingBroker(String type, DOMDataBroker delegate, Config config, BindingNormalizedNodeSerializer codec) {
+        this.type = requireNonNull(type, "type");
+        this.delegate = requireNonNull(delegate, "delegate");
+        this.codec = requireNonNull(codec, "codec");
         configure(config);
 
         if (config.isTransactionDebugContextEnabled() != null) {
@@ -351,10 +354,12 @@ public class TracingBroker implements TracingDOMDataBroker {
             && writeTransactionsRegistry.getAllUnique().isEmpty()
             && readWriteTransactionsRegistry.getAllUnique().isEmpty()) {
 
+            ps.println(type + ": No open transactions, great!");
             return false;
         }
 
-        ps.println(getClass().getSimpleName() + " found some not yet (or never..) closed transaction[chain]s!");
+        ps.println(type + ": " + getClass().getSimpleName()
+                 + " found some not yet (or never..) closed transaction[chain]s!");
         ps.println("[NB: If no stack traces are shown below, then "
                  + "enable transaction-debug-context-enabled in mdsaltrace_config.xml]");
         ps.println();
index 7535f95..95f4e1f 100644 (file)
@@ -19,11 +19,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer"
         odl:type="default" />
 
+  <!-- Tracing Binding DataBroker -->
+
   <reference id="realDefaultDOMBroker"
       interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
       odl:type="default" />
 
   <bean id="tracingDefaultDOMBroker" class="org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker">
+      <argument value="default" />
       <argument ref="realDefaultDOMBroker" />
       <argument ref="mdsalConfig" />
       <argument ref="codec" />
@@ -36,12 +39,23 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     </interfaces>
   </service>
 
+  <!-- Tracing Binding PingPong DataBroker -->
+
+  <reference id="realPingPongDOMDataBroker"
+      interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
+      odl:type="pingpong"/>
 
-  <bean id="tracingPingPongDOMBroker" class="org.opendaylight.controller.md.sal.dom.broker.impl.PingPongDataBroker">
-    <argument ref="tracingDefaultDOMBroker" />
+  <bean id="tracingPingPongDOMBroker" class="org.opendaylight.controller.md.sal.trace.dom.impl.TracingBroker">
+      <argument value="pingpong" />
+      <argument ref="realPingPongDOMDataBroker" />
+      <argument ref="mdsalConfig" />
+      <argument ref="codec" />
   </bean>
 
-  <service id="tracingPingPongDOMBrokerSvc" ref="tracingPingPongDOMBroker"
-             interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
-             ranking="10" odl:type="pingpong" />
+  <service id="tracingPingPongDOMBrokerSvc" ref="tracingPingPongDOMBroker" ranking="10" odl:type="pingpong">
+    <interfaces>
+      <value>org.opendaylight.controller.md.sal.dom.api.DOMDataBroker</value>
+      <value>org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker</value>
+    </interfaces>
+  </service>
 </blueprint>
index d0731da..bcd2d7c 100644 (file)
@@ -36,7 +36,7 @@ public class TracingBrokerTest {
         DOMDataBroker domDataBroker = mock(DOMDataBroker.class, RETURNS_DEEP_STUBS);
         Config config = new ConfigBuilder().setTransactionDebugContextEnabled(true).build();
         BindingNormalizedNodeSerializer codec = mock(BindingNormalizedNodeSerializer.class);
-        TracingBroker tracingBroker = new TracingBroker(domDataBroker, config, codec);
+        TracingBroker tracingBroker = new TracingBroker("mock", domDataBroker, config, codec);
 
         for (int i = 0; i < 3; i++) {
             DOMDataReadWriteTransaction tx = tracingBroker.newReadWriteTransaction();

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.