From 2c6f70e0e363b856b5303e20418312be69135316 Mon Sep 17 00:00:00 2001 From: "matus.kubica" Date: Tue, 19 Apr 2016 16:07:31 +0200 Subject: [PATCH] Remove inventory related code from netconf connector also removed tests from MountInstanceTests due to deleted deprecated methods from NetconfDeviceSalProvider Change-Id: I2f78db4b37447fa9c4808122107759523cb9dd40 Signed-off-by: matus.kubica --- .../sal/NetconfDeviceDatastoreAdapter.java | 179 ------------------ .../netconf/sal/NetconfDeviceSalFacade.java | 7 - .../netconf/sal/NetconfDeviceSalProvider.java | 52 +---- .../netconf/sal/MountInstanceTest.java | 21 -- 4 files changed, 1 insertion(+), 258 deletions(-) delete mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceDatastoreAdapter.java diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceDatastoreAdapter.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceDatastoreAdapter.java deleted file mode 100644 index 54dda9ddb8..0000000000 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceDatastoreAdapter.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2015 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.netconf.sal.connect.netconf.sal; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.FluentIterable; -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; - -import java.util.Set; -import java.util.concurrent.ExecutionException; - -import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; -import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; -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.TransactionCommitFailedException; -import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.inventory.rev140108.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.inventory.rev140108.NetconfNodeBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Asynchronous (Binding-aware) adapter over datastore subtree for netconf device. - * - * All data changes are submitted to an ExecutorService to avoid Thread blocking while sal is waiting for schema. - * - * @deprecated Data is pushed into Topology instead if Inventory model - */ -@Deprecated -final class NetconfDeviceDatastoreAdapter implements AutoCloseable { - - private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceDatastoreAdapter.class); - - private final RemoteDeviceId id; - private BindingTransactionChain txChain; - - NetconfDeviceDatastoreAdapter(final RemoteDeviceId deviceId, final BindingTransactionChain txChain) { - this.id = Preconditions.checkNotNull(deviceId); - this.txChain = Preconditions.checkNotNull(txChain); - - initDeviceData(); - } - - public void updateDeviceState(final boolean up, final Set capabilities) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node data = buildDataForDeviceState( - up, capabilities, id); - - final ReadWriteTransaction transaction = txChain.newReadWriteTransaction(); - logger.trace("{}: Update device state transaction {} merging operational data started.", id, transaction.getIdentifier()); - transaction.put(LogicalDatastoreType.OPERATIONAL, id.getBindingPath(), data); - logger.trace("{}: Update device state transaction {} merging operational data ended.", id, transaction.getIdentifier()); - - commitTransaction(transaction, "update"); - } - - private void removeDeviceConfigAndState() { - final WriteTransaction transaction = txChain.newWriteOnlyTransaction(); - logger.trace("{}: Close device state transaction {} removing all data started.", id, transaction.getIdentifier()); - transaction.delete(LogicalDatastoreType.CONFIGURATION, id.getBindingPath()); - transaction.delete(LogicalDatastoreType.OPERATIONAL, id.getBindingPath()); - logger.trace("{}: Close device state transaction {} removing all data ended.", id, transaction.getIdentifier()); - - try { - transaction.submit().get(); - } catch (InterruptedException | ExecutionException e) { - logger.error("{}: Transaction(close) {} FAILED!", id, transaction.getIdentifier(), e); - throw new IllegalStateException(id + " Transaction(close) not committed correctly", e); - } - } - - private void initDeviceData() { - final WriteTransaction transaction = txChain.newWriteOnlyTransaction(); - - createNodesListIfNotPresent(transaction); - - final InstanceIdentifier path = id.getBindingPath(); - final Node nodeWithId = getNodeWithId(id); - - logger.trace("{}: Init device state transaction {} putting if absent operational data started.", id, transaction.getIdentifier()); - transaction.put(LogicalDatastoreType.OPERATIONAL, path, nodeWithId); - logger.trace("{}: Init device state transaction {} putting operational data ended.", id, transaction.getIdentifier()); - - logger.trace("{}: Init device state transaction {} putting if absent config data started.", id, transaction.getIdentifier()); - transaction.put(LogicalDatastoreType.CONFIGURATION, path, nodeWithId); - logger.trace("{}: Init device state transaction {} putting config data ended.", id, transaction.getIdentifier()); - - commitTransaction(transaction, "init"); - } - - private void createNodesListIfNotPresent(final WriteTransaction writeTx) { - final Nodes nodes = new NodesBuilder().build(); - final InstanceIdentifier path = InstanceIdentifier.builder(Nodes.class).build(); - logger.trace("{}: Merging {} container to ensure its presence", id, Nodes.QNAME, writeTx.getIdentifier()); - writeTx.merge(LogicalDatastoreType.CONFIGURATION, path, nodes); - writeTx.merge(LogicalDatastoreType.OPERATIONAL, path, nodes); - } - - private void commitTransaction(final WriteTransaction transaction, final String txType) { - logger.trace("{}: Committing Transaction {}:{}", id, txType, transaction.getIdentifier()); - final CheckedFuture result = transaction.submit(); - - Futures.addCallback(result, new FutureCallback() { - @Override - public void onSuccess(final Void result) { - logger.trace("{}: Transaction({}) {} SUCCESSFUL", id, txType, transaction.getIdentifier()); - } - - @Override - public void onFailure(final Throwable t) { - logger.error("{}: Transaction({}) {} FAILED!", id, txType, transaction.getIdentifier(), t); - throw new IllegalStateException(id + " Transaction(" + txType + ") not committed correctly", t); - } - }); - - } - - @Override - public void close() throws Exception { - removeDeviceConfigAndState(); - } - - public static org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node buildDataForDeviceState( - final boolean up, final Set capabilities, final RemoteDeviceId id) { - - final NodeBuilder nodeBuilder = getNodeWithIdBuilder(id); - final NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder(); - netconfNodeBuilder.setConnected(up); - netconfNodeBuilder.setInitialCapability(FluentIterable.from(capabilities) - .transform(new Function() { - @Override - public String apply(final QName input) { - return input.toString(); - } - }).toList()); - nodeBuilder.addAugmentation(NetconfNode.class, netconfNodeBuilder.build()); - - return nodeBuilder.build(); - } - - private static ListenableFuture> readNodeData( - final LogicalDatastoreType store, - final ReadWriteTransaction transaction, - final InstanceIdentifier path) { - return transaction.read(store, path); - } - - private static Node getNodeWithId(final RemoteDeviceId id) { - final NodeBuilder nodeBuilder = getNodeWithIdBuilder(id); - return nodeBuilder.build(); - } - - private static NodeBuilder getNodeWithIdBuilder(final RemoteDeviceId id) { - final NodeBuilder nodeBuilder = new NodeBuilder(); - nodeBuilder.setKey(id.getBindingKey()); - nodeBuilder.setId(id.getBindingKey().getId()); - return nodeBuilder; - } - - public void setTxChain(BindingTransactionChain txChain) { - this.txChain = Preconditions.checkNotNull(txChain); - } -} diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java index 2a817db7ec..829487a409 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java @@ -8,7 +8,6 @@ package org.opendaylight.netconf.sal.connect.netconf.sal; import com.google.common.collect.Lists; -import java.util.Collections; import java.util.List; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMNotification; @@ -19,7 +18,6 @@ import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,24 +55,19 @@ public final class NetconfDeviceSalFacade implements AutoCloseable, RemoteDevice final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService(); - salProvider.getMountInstance().onDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService); - salProvider.getDatastoreAdapter().updateDeviceState(true, netconfSessionPreferences.getModuleBasedCaps()); salProvider.getMountInstance().onTopologyDeviceConnected(schemaContext, domBroker, deviceRpc, notificationService); salProvider.getTopologyDatastoreAdapter().updateDeviceData(true, netconfSessionPreferences.getNetconfDeviceCapabilities()); } @Override public synchronized void onDeviceDisconnected() { - salProvider.getDatastoreAdapter().updateDeviceState(false, Collections.emptySet()); salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, new NetconfDeviceCapabilities()); - salProvider.getMountInstance().onDeviceDisconnected(); salProvider.getMountInstance().onTopologyDeviceDisconnected(); } @Override public synchronized void onDeviceFailed(final Throwable throwable) { salProvider.getTopologyDatastoreAdapter().setDeviceAsFailed(throwable); - salProvider.getMountInstance().onDeviceDisconnected(); salProvider.getMountInstance().onTopologyDeviceDisconnected(); } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java index a01b74e941..278771a5ba 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java @@ -38,7 +38,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceSalProvider.class); private final RemoteDeviceId id; - private volatile NetconfDeviceDatastoreAdapter datastoreAdapter; private MountInstance mountInstance; private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter; @@ -71,12 +70,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin return mountInstance; } - public NetconfDeviceDatastoreAdapter getDatastoreAdapter() { - Preconditions.checkState(datastoreAdapter != null, - "%s: Sal provider %s was not initialized by sal. Cannot get datastore adapter", id); - return datastoreAdapter; - } - public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() { Preconditions.checkState(topologyDatastoreAdapter != null, "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id); @@ -105,14 +98,12 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin this.dataBroker = session.getSALService(DataBroker.class); txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener); - datastoreAdapter = new NetconfDeviceDatastoreAdapter(id, txChain); topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, txChain); } private void resetTransactionChainForAdapaters() { txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener); - datastoreAdapter.setTxChain(txChain); topologyDatastoreAdapter.setTxChain(txChain); logger.trace("{}: Resetting TransactionChain {}", id, txChain); @@ -121,8 +112,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin public void close() throws Exception { mountInstance.close(); - datastoreAdapter.close(); - datastoreAdapter = null; topologyDatastoreAdapter.close(); topologyDatastoreAdapter = null; txChain.close(); @@ -132,7 +121,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin private DOMMountPointService mountService; private final RemoteDeviceId id; - private ObjectRegistration registration; private NetconfDeviceNotificationService notificationService; private ObjectRegistration topologyRegistration; @@ -142,44 +130,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin this.id = Preconditions.checkNotNull(id); } - @Deprecated - synchronized void onDeviceConnected(final SchemaContext initialCtx, - final DOMDataBroker broker, final DOMRpcService rpc, - final NetconfDeviceNotificationService notificationService) { - - Preconditions.checkNotNull(mountService, "Closed"); - Preconditions.checkState(registration == null, "Already initialized"); - - final DOMMountPointService.DOMMountPointBuilder mountBuilder = mountService.createMountPoint(id.getPath()); - mountBuilder.addInitialSchemaContext(initialCtx); - - mountBuilder.addService(DOMDataBroker.class, broker); - mountBuilder.addService(DOMRpcService.class, rpc); - mountBuilder.addService(DOMNotificationService.class, notificationService); - this.notificationService = notificationService; - - registration = mountBuilder.register(); - logger.debug("{}: Mountpoint exposed into MD-SAL {}", id, registration); - } - - @Deprecated - synchronized void onDeviceDisconnected() { - if(registration == null) { - logger.trace("{}: Not removing mountpoint from MD-SAL, mountpoint was not registered yet", id); - return; - } - - try { - registration.close(); - } catch (final Exception e) { - // Only log and ignore - logger.warn("Unable to unregister mount instance for {}. Ignoring exception", id.getPath(), e); - } finally { - logger.debug("{}: Mountpoint removed from MD-SAL {}", id, registration); - registration = null; - } - } - public synchronized void onTopologyDeviceConnected(final SchemaContext initialCtx, final DOMDataBroker broker, final DOMRpcService rpc, final NetconfDeviceNotificationService notificationService) { @@ -193,6 +143,7 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin mountBuilder.addService(DOMDataBroker.class, broker); mountBuilder.addService(DOMRpcService.class, rpc); mountBuilder.addService(DOMNotificationService.class, notificationService); + this.notificationService = notificationService; topologyRegistration = mountBuilder.register(); logger.debug("{}: TOPOLOGY Mountpoint exposed into MD-SAL {}", id, topologyRegistration); @@ -218,7 +169,6 @@ public class NetconfDeviceSalProvider implements AutoCloseable, Provider, Bindin @Override public synchronized void close() throws Exception { - onDeviceDisconnected(); onTopologyDeviceDisconnected(); mountService = null; } diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java index 6386a88348..7e62990bc7 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.java @@ -67,27 +67,6 @@ public class MountInstanceTest { mountInstance = new NetconfDeviceSalProvider.MountInstance(service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830))); } - @Test - public void testOnDeviceConnected() throws Exception { - mountInstance.onDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - verify(mountPointBuilder).addInitialSchemaContext(SCHEMA_CONTEXT); - verify(mountPointBuilder).addService(DOMDataBroker.class, broker); - verify(mountPointBuilder).addService(DOMRpcService.class, rpcService); - verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService); - } - - @Test - public void testOnDeviceDisconnected() throws Exception { - mountInstance.onDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - mountInstance.onDeviceDisconnected(); - verify(registration).close(); - try { - mountInstance.onDeviceConnected(SCHEMA_CONTEXT, broker, rpcService, notificationService); - } catch (IllegalStateException e) { - e.printStackTrace(); - Assert.fail("Registration still present after disconnect "); - } - } @Test public void testOnTopologyDeviceConnected() throws Exception { -- 2.36.6