BUG-7027 : wired data-change-counter with Blueprint 09/56009/11
authorDana Kutenicsova <dana.kutenics@gmail.com>
Tue, 25 Apr 2017 15:16:06 +0000 (17:16 +0200)
committerRobert Varga <nite@hq.sk>
Sat, 10 Jun 2017 22:57:11 +0000 (22:57 +0000)
Deprecate existing config modules,
add BP xml with custom config yang file.
No default configuration is set, to avoid
conflict modification when using on 3 node clustering.

Change-Id: I2b0408310605c9b96388585582d2e7a9f63007cb
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
data-change-counter/src/main/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModule.java
data-change-counter/src/main/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModuleFactory.java
data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounter.java
data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounterDeployer.java [new file with mode: 0644]
data-change-counter/src/main/resources/org/opendaylight/blueprint/topology-data-change-counter.xml [new file with mode: 0644]
data-change-counter/src/main/yang/odl-data-change-counter-config.yang [new file with mode: 0644]
data-change-counter/src/test/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModuleTest.java [deleted file]
data-change-counter/src/test/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounterTest.java

index e8e8edc0971b38f4d190de5a3edca0548879e586..7578ae0f0abaff9bf8edaa0d516362b2e64274cd 100755 (executable)
@@ -9,18 +9,18 @@
 package org.opendaylight.controller.config.yang.bgpcep.data.change.counter;
 
 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.protocol.data.change.counter.TopologyDataChangeCounter;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.protocol.data.change.counter.TopologyDataChangeCounterDeployer;
+import org.osgi.framework.BundleContext;
 
+/**
+ * @deprecated Replaced by blueprint wiring but remains for backwards compatibility until downstream users
+ *             of the provided config system service are converted to blueprint.
+ */
 public class DataChangeCounterImplModule extends org.opendaylight.controller.config.yang.bgpcep.data.change.counter.AbstractDataChangeCounterImplModule {
 
+    private BundleContext bundleContext;
+
     public DataChangeCounterImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
@@ -41,30 +41,19 @@ public class DataChangeCounterImplModule extends org.opendaylight.controller.con
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataProviderDependency(), getCounterId());
-        final InstanceIdentifier<Topology> topoIId = InstanceIdentifier.builder(NetworkTopology.class)
-                .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).build();
-        final ListenerRegistration<TopologyDataChangeCounter> registration = getDataProviderDependency().registerDataTreeChangeListener(
-            new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, topoIId), counter);
-        return new DataChangeCounterCloseable(counter, registration);
+        final WaitingServiceTracker<TopologyDataChangeCounterDeployer> deployerTracker =
+            WaitingServiceTracker.create(TopologyDataChangeCounterDeployer.class, this.bundleContext);
+        final TopologyDataChangeCounterDeployer deployer = deployerTracker
+            .waitForService(WaitingServiceTracker.FIVE_MINUTES);
+        final String counterId = getCounterId();
+        deployer.chandleCounterChange(counterId, getTopologyName());
+        return ()->{
+            deployer.deleteCounterChange(counterId);
+            deployerTracker.close();
+        };
     }
 
-    private static final class DataChangeCounterCloseable implements AutoCloseable {
-
-        private final TopologyDataChangeCounter inner;
-        private final ListenerRegistration<TopologyDataChangeCounter> registration;
-
-        public DataChangeCounterCloseable(final TopologyDataChangeCounter inner,
-                final ListenerRegistration<TopologyDataChangeCounter> registration) {
-            this.inner = inner;
-            this.registration = registration;
-        }
-
-        @Override
-        public void close() {
-            this.registration.close();
-            this.inner.close();
-        }
+    public void setBundleContext(final BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
     }
-
 }
index 1cbb891c4b067c4f7f3bb957605c7a6803ce80f2..03262a7ddcbc789fa38412c963a8eb27d310e3b7 100755 (executable)
 *
 * Do not modify this file unless it is present under src/main directory
 */
+/**
+ * @deprecated Replaced by blueprint wiring but remains for backwards compatibility until downstream users
+ *             of the provided config system service are converted to blueprint.
+ */
 package org.opendaylight.controller.config.yang.bgpcep.data.change.counter;
 
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
+import org.opendaylight.controller.config.spi.Module;
+import org.osgi.framework.BundleContext;
+
 public class DataChangeCounterImplModuleFactory extends org.opendaylight.controller.config.yang.bgpcep.data.change.counter.AbstractDataChangeCounterImplModuleFactory {
+    @Override
+    public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
+        final DataChangeCounterImplModule module = (DataChangeCounterImplModule) super.createModule(instanceName, dependencyResolver, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
 
+    @Override
+    public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
+                               final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception {
+        final DataChangeCounterImplModule module = (DataChangeCounterImplModule)  super.createModule(instanceName, dependencyResolver, old, bundleContext);
+        module.setBundleContext(bundleContext);
+        return module;
+    }
 }
index 8be19cd44fa870b2bb00677f62e6a341d995c345..a36376318fbe83389e70a6d9a3de6171a04cc6ce 100644 (file)
@@ -10,9 +10,11 @@ package org.opendaylight.protocol.data.change.counter;
 
 import java.util.Collection;
 import java.util.concurrent.atomic.AtomicLong;
+
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 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.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
@@ -24,12 +26,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.CounterBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.CounterKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TopologyDataChangeCounter implements ClusteredDataTreeChangeListener<Topology>, TransactionChainListener {
+final class TopologyDataChangeCounter implements ClusteredDataTreeChangeListener<Topology>, TransactionChainListener, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(TopologyDataChangeCounter.class);
 
@@ -38,15 +44,22 @@ public class TopologyDataChangeCounter implements ClusteredDataTreeChangeListene
     private final InstanceIdentifier<Counter> counterInstanceId;
     private final BindingTransactionChain chain;
     private final AtomicLong count;
+    private final ListenerRegistration<TopologyDataChangeCounter> registration;
+    private final String topologyName;
 
-    public TopologyDataChangeCounter(final DataBroker dataBroker, final String counterId) {
+    public TopologyDataChangeCounter(final DataBroker dataBroker, final String counterId, final String topologyName) {
         this.dataBroker = dataBroker;
+        this.topologyName = topologyName;
         this.chain = this.dataBroker.createTransactionChain(this);
         this.counterId = counterId;
         this.counterInstanceId = InstanceIdentifier.builder(DataChangeCounter.class)
-                .child(Counter.class, new CounterKey(this.counterId)).build();
+            .child(Counter.class, new CounterKey(this.counterId)).build();
         this.count = new AtomicLong(0);
         putCount(this.count.get());
+        final InstanceIdentifier<Topology> topoIId = InstanceIdentifier.builder(NetworkTopology.class)
+            .child(Topology.class, new TopologyKey(new TopologyId(topologyName))).build();
+        this.registration = this.dataBroker.registerDataTreeChangeListener(
+            new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, topoIId), this);
         LOG.debug("Data change counter {} initiated", this.counterId);
     }
 
@@ -56,12 +69,14 @@ public class TopologyDataChangeCounter implements ClusteredDataTreeChangeListene
         LOG.debug("Data change #{} for counter {}", this.count.get(), this.counterId);
     }
 
+    @Override
     public void close() {
+        this.registration.close();
         final WriteTransaction wTx = this.dataBroker.newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId);
         try {
             wTx.submit().checkedGet();
-        } catch (TransactionCommitFailedException except) {
+        } catch (final TransactionCommitFailedException except) {
             LOG.warn("Error on remove data change counter {}", this.counterId, except);
         }
         this.chain.close();
@@ -70,13 +85,14 @@ public class TopologyDataChangeCounter implements ClusteredDataTreeChangeListene
 
     private void putCount(final long count) {
         final WriteTransaction wTx = this.chain.newWriteOnlyTransaction();
-        Counter counter = new CounterBuilder().setId(this.counterId).setCount(count).build();
+        final Counter counter = new CounterBuilder().setId(this.counterId).setCount(count).build();
         wTx.put(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId, counter);
         wTx.submit();
     }
 
     @Override
-    public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+    public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction,
+        final Throwable cause) {
         chain.close();
         LOG.warn("Transaction chain failure. Transaction: {}", transaction, cause);
     }
@@ -86,4 +102,7 @@ public class TopologyDataChangeCounter implements ClusteredDataTreeChangeListene
         LOG.debug("Transaction chain successful. {}", chain);
     }
 
+    public String getTopologyName() {
+        return this.topologyName;
+    }
 }
diff --git a/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounterDeployer.java b/data-change-counter/src/main/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounterDeployer.java
new file mode 100644 (file)
index 0000000..e844912
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.protocol.data.change.counter;
+
+import com.google.common.base.Preconditions;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
+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.DataTreeChangeListener;
+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.params.xml.ns.yang.bgpcep.data.change.counter.config.rev170424.DataChangeCounterConfig;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TopologyDataChangeCounterDeployer implements DataTreeChangeListener<DataChangeCounterConfig>,
+    AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(TopologyDataChangeCounterDeployer.class);
+    private final static InstanceIdentifier<DataChangeCounterConfig> DATA_CHANGE_COUNTER_IID =
+        InstanceIdentifier.builder(DataChangeCounterConfig.class).build();
+    private final DataBroker dataBroker;
+    @GuardedBy("this")
+    private final Map<String, TopologyDataChangeCounter> counters = new HashMap<>();
+    private ListenerRegistration<TopologyDataChangeCounterDeployer> registration;
+
+    public TopologyDataChangeCounterDeployer(final DataBroker dataBroker) {
+        this.dataBroker = Preconditions.checkNotNull(dataBroker);
+    }
+
+    public synchronized void register() {
+        this.registration = this.dataBroker.registerDataTreeChangeListener(
+            new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, DATA_CHANGE_COUNTER_IID), this);
+        LOG.info("Data change counter Deployer initiated");
+    }
+
+
+    @Override
+    public synchronized void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<DataChangeCounterConfig>> changes) {
+        for (final DataTreeModification<DataChangeCounterConfig> dataTreeModification : changes) {
+            final DataObjectModification<DataChangeCounterConfig> rootNode = dataTreeModification.getRootNode();
+            switch (dataTreeModification.getRootNode().getModificationType()) {
+                case DELETE:
+                    deleteCounterChange(rootNode.getDataBefore().getCounterId());
+                    break;
+                case SUBTREE_MODIFIED:
+                case WRITE:
+                    final DataChangeCounterConfig change = rootNode.getDataAfter();
+                    chandleCounterChange(change.getCounterId(), change.getTopologyName());
+                    break;
+            }
+        }
+    }
+
+    public synchronized void deleteCounterChange(final String counterId) {
+        final TopologyDataChangeCounter oldCounter = this.counters.remove(counterId);
+        if (oldCounter != null) {
+            LOG.info("Data change counter Deployer deleted: {}", counterId);
+            oldCounter.close();
+        }
+    }
+
+    public synchronized void chandleCounterChange(final String counterId, final String topologyName) {
+        deleteCounterChange(counterId);
+        LOG.info("Data change counter Deployer created: {} / {}", counterId, topologyName);
+
+        final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(this.dataBroker, counterId, topologyName);
+        this.counters.put(counterId, counter);
+    }
+
+    @Override
+    public synchronized void close() throws Exception {
+        LOG.info("Closing Data change counter Deployer");
+
+        if (this.registration != null) {
+            this.registration.close();
+            this.registration = null;
+        }
+    }
+}
diff --git a/data-change-counter/src/main/resources/org/opendaylight/blueprint/topology-data-change-counter.xml b/data-change-counter/src/main/resources/org/opendaylight/blueprint/topology-data-change-counter.xml
new file mode 100644 (file)
index 0000000..ab581b9
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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
+  -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
+    <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" odl:type="pingpong"/>
+    <bean id="data-change-counter-deployer" class="org.opendaylight.protocol.data.change.counter.TopologyDataChangeCounterDeployer"
+          init-method="register"
+          destroy-method="close">
+        <argument ref="dataBroker"/>
+    </bean>
+    <service ref="data-change-counter-deployer" interface="org.opendaylight.protocol.data.change.counter.TopologyDataChangeCounterDeployer"/>
+</blueprint>
\ No newline at end of file
diff --git a/data-change-counter/src/main/yang/odl-data-change-counter-config.yang b/data-change-counter/src/main/yang/odl-data-change-counter-config.yang
new file mode 100644 (file)
index 0000000..833e203
--- /dev/null
@@ -0,0 +1,32 @@
+// vi: set smarttab et sw=4 tabstop=4:
+module odl-data-change-counter-config {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:bgpcep:data-change-counter-config";
+    prefix "dcc-cfg";
+
+    description
+        "This module contains the base YANG definitions for
+         topology data-change counter configuration.
+
+        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";
+
+    revision "2017-04-24" {
+        description
+            "Initial revision";
+    }
+
+    list data-change-counter-config {
+        key "counter-id";
+        leaf counter-id {
+            type string;
+            mandatory true;
+        }
+        leaf topology-name {
+            type string;
+            mandatory true;
+        }
+    }
+}
\ No newline at end of file
diff --git a/data-change-counter/src/test/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModuleTest.java b/data-change-counter/src/test/java/org/opendaylight/controller/config/yang/bgpcep/data/change/counter/DataChangeCounterImplModuleTest.java
deleted file mode 100644 (file)
index 7b408e0..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.config.yang.bgpcep.data.change.counter;
-
-import java.util.Collections;
-import java.util.Set;
-import javax.management.ObjectName;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.DependencyResolverFactory;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
-import org.opendaylight.controller.config.api.jmx.CommitStatus;
-import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
-import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
-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.DataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.DataChangeCounter;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.osgi.framework.BundleContext;
-
-public class DataChangeCounterImplModuleTest extends AbstractConfigTest {
-
-    private static final String FACTORY_NAME = DataChangeCounterImplModuleFactory.NAME;
-    private static final String INSTANCE_NAME = "data-change-counter";
-    private static final String DATA_BROKER_INSTANCE_NAME = "data-broker-instance";
-
-    private static final String COUNTER_ID = "counter";
-    private static final String NEW_COUNTER_ID = "new-counter";
-    private static final String TOPOLOGY_NAME = "test";
-    private static final String NEW_TOPOLOGY_NAME = "new-test";
-
-    @Mock
-    private CloseableDataBroker dataBroker;
-    @Mock
-    private BindingTransactionChain chain;
-    @Mock
-    private WriteTransaction wTx;
-    @Mock
-    private ListenerRegistration<DataTreeChangeListener<?>> registration;
-
-    @Before
-    public void setUp() throws Exception {
-        Mockito.doNothing().when(this.registration).close();
-        Mockito.doReturn(null).when(this.wTx).submit();
-        Mockito.doNothing().when(this.wTx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(), Mockito.any(DataChangeCounter.class));
-        Mockito.doReturn(this.registration).when(this.dataBroker).registerDataTreeChangeListener(Mockito.any(DataTreeIdentifier.class), Mockito.any(ClusteredDataTreeChangeListener.class));
-        Mockito.doNothing().when(this.wTx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any());
-        Mockito.doReturn(this.chain).when(this.dataBroker).createTransactionChain(Mockito.any(TransactionChainListener.class));
-        Mockito.doReturn(this.wTx).when(this.chain).newWriteOnlyTransaction();
-        Mockito.doReturn(this.wTx).when(this.dataBroker).newWriteOnlyTransaction();
-        Mockito.doNothing().when(this.chain).close();
-        Mockito.doNothing().when(this.dataBroker).close();
-        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new DataChangeCounterImplModuleFactory(), new MockDataBrokerModuleFct()));
-    }
-
-    @Test
-    public void testCreateBean() throws Exception {
-        final CommitStatus status = createInstance(COUNTER_ID, TOPOLOGY_NAME);
-        assertBeanCount(1, FACTORY_NAME);
-        assertStatus(status, 2, 0, 0);
-    }
-
-    @Test
-    public void testReusingOldInstance() throws Exception {
-        createInstance(COUNTER_ID, TOPOLOGY_NAME);
-        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        assertBeanCount(1, FACTORY_NAME);
-        final CommitStatus status = transaction.commit();
-        assertBeanCount(1, FACTORY_NAME);
-        assertStatus(status, 0, 0, 2);
-    }
-
-    @Test
-    public void testReconfigureBean() throws Exception {
-        createInstance(COUNTER_ID, TOPOLOGY_NAME);
-        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        final DataChangeCounterImplModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
-                DataChangeCounterImplModuleMXBean.class);
-        mxBean.setCounterId(NEW_COUNTER_ID);
-        mxBean.setTopologyName(NEW_TOPOLOGY_NAME);
-        final CommitStatus status = transaction.commit();
-        assertBeanCount(1, FACTORY_NAME);
-        assertStatus(status, 0, 1, 1);
-
-        final ConfigTransactionJMXClient transaction2 = this.configRegistryClient.createTransaction();
-        final DataChangeCounterImplModuleMXBean mxBean2 = transaction2.newMXBeanProxy(transaction2.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
-                DataChangeCounterImplModuleMXBean.class);
-        Assert.assertEquals(NEW_COUNTER_ID, mxBean2.getCounterId());
-        Assert.assertEquals(NEW_TOPOLOGY_NAME, mxBean2.getTopologyName());
-    }
-
-    private CommitStatus createInstance(final String counterId, final String topologyName) throws Exception {
-        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
-        final ObjectName on = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
-        final ObjectName dbOn = transaction.createModule(MockDataBrokerModuleFct.INSTANCE_NAME, DATA_BROKER_INSTANCE_NAME);
-        final DataChangeCounterImplModuleMXBean mxBean = transaction.newMXBeanProxy(on, DataChangeCounterImplModuleMXBean.class);
-        mxBean.setCounterId(counterId);
-        mxBean.setTopologyName(topologyName);
-        mxBean.setDataProvider(dbOn);
-        return transaction.commit();
-    }
-
-    private final class MockDataBrokerModuleFct implements org.opendaylight.controller.config.spi.ModuleFactory {
-
-        private static final String INSTANCE_NAME = "data-broker-fct";
-
-        @Override
-        public String getImplementationName() {
-            return INSTANCE_NAME;
-        }
-
-        @Override
-        public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
-                final BundleContext bundleContext) {
-            return new MockDataBrokerModule();
-        }
-
-        @Override
-        public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
-                final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception {
-            return new MockDataBrokerModule();
-        }
-
-        @Override
-        public boolean isModuleImplementingServiceInterface(final Class<? extends AbstractServiceInterface> serviceInterface) {
-            return true;
-        }
-
-        @Override
-        public Set<Class<? extends AbstractServiceInterface>> getImplementedServiceIntefaces() {
-            final java.util.Set<Class<? extends org.opendaylight.controller.config.api.annotations.AbstractServiceInterface>> serviceIfcs2 = new java.util.HashSet<>();
-            return java.util.Collections.unmodifiableSet(serviceIfcs2);
-        }
-
-        @Override
-        public Set<? extends Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory,
-                final BundleContext bundleContext) {
-            return Collections.emptySet();
-        }
-
-    }
-
-    private final class MockDataBrokerModule implements org.opendaylight.controller.config.spi.Module,org.opendaylight.controller.config.yang.md.sal.binding.impl.BindingAsyncDataBrokerImplModuleMXBean,org.opendaylight.controller.config.yang.md.sal.binding.DataBrokerServiceInterface {
-
-        @Override
-        public ModuleIdentifier getIdentifier() {
-            return new ModuleIdentifier(MockDataBrokerModuleFct.INSTANCE_NAME, DATA_BROKER_INSTANCE_NAME);
-        }
-
-        @Override
-        public ObjectName getBindingMappingService() {
-            return null;
-        }
-
-        @Override
-        public void setBindingMappingService(final ObjectName bindingMappingService) {
-            return;
-        }
-
-        @Override
-        public ObjectName getDomAsyncBroker() {
-            return null;
-        }
-
-        @Override
-        public void setDomAsyncBroker(final ObjectName domAsyncBroker) {
-            return;
-        }
-
-        @Override
-        public void validate() {
-            return;
-        }
-
-        @Override
-        public AutoCloseable getInstance() {
-            return DataChangeCounterImplModuleTest.this.dataBroker;
-        }
-
-        @Override
-        public ObjectName getSchemaService() {
-            return null;
-        }
-
-        @Override
-        public void setSchemaService(final ObjectName schemaService) {
-            return;
-        }
-
-        @Override
-        public boolean canReuse(final Module arg0) {
-            return true;
-        }
-
-    }
-
-    private interface CloseableDataBroker extends DataBroker, AutoCloseable {
-    }
-
-}
index 3f7cf86d978f1c07cc0c84edc77f9e9912cc17ea..9ac27e9b6a52b7ec17b11ca31084828bb4e3bba2 100755 (executable)
@@ -24,6 +24,7 @@ public class TopologyDataChangeCounterTest extends AbstractConcurrentDataBrokerT
 
     private static final String COUNTER_ID1 = "counter1";
     private static final String COUNTER_ID2 = "counter2";
+    private static final String TOPOLOGY_NAME = "example-linkstate-topology";
     private final InstanceIdentifier<Counter> counterInstanceId_1 = InstanceIdentifier.builder(DataChangeCounter.class)
         .child(Counter.class, new CounterKey(COUNTER_ID1)).build();
     private final InstanceIdentifier<Counter> counterInstanceId_2 = InstanceIdentifier.builder(DataChangeCounter.class)
@@ -31,7 +32,7 @@ public class TopologyDataChangeCounterTest extends AbstractConcurrentDataBrokerT
 
     @Test
     public void testDataChangeCounter() throws Exception {
-        final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
+        final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1, TOPOLOGY_NAME);
         readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
@@ -49,13 +50,13 @@ public class TopologyDataChangeCounterTest extends AbstractConcurrentDataBrokerT
 
     @Test
     public void testDataChangeCounterTwoInstances() throws Exception {
-        final TopologyDataChangeCounter counter1 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
+        final TopologyDataChangeCounter counter1 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1, TOPOLOGY_NAME);
         readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
         });
 
-        final TopologyDataChangeCounter counter2 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID2);
+        final TopologyDataChangeCounter counter2 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID2, TOPOLOGY_NAME);
         readDataOperational(getDataBroker(), this.counterInstanceId_2, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;