Remove inventory related code from netconf connector 18/37818/1
authormatus.kubica <Matus.Kubica@pantheon.tech>
Tue, 19 Apr 2016 14:07:31 +0000 (16:07 +0200)
committermatus.kubica <Matus.Kubica@pantheon.tech>
Tue, 19 Apr 2016 14:09:40 +0000 (16:09 +0200)
also removed tests from MountInstanceTests due to deleted deprecated methods from NetconfDeviceSalProvider

Change-Id: I2f78db4b37447fa9c4808122107759523cb9dd40
Signed-off-by: matus.kubica <Matus.Kubica@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceDatastoreAdapter.java [deleted file]
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/MountInstanceTest.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 (file)
index 54dda9d..0000000
+++ /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<QName> 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<Node> 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<Nodes> 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<Void, TransactionCommitFailedException> result = transaction.submit();
-
-        Futures.addCallback(result, new FutureCallback<Void>() {
-            @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<QName> 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<QName, String>() {
-                    @Override
-                    public String apply(final QName input) {
-                        return input.toString();
-                    }
-                }).toList());
-        nodeBuilder.addAugmentation(NetconfNode.class, netconfNodeBuilder.build());
-
-        return nodeBuilder.build();
-    }
-
-    private static ListenableFuture<Optional<Node>> readNodeData(
-            final LogicalDatastoreType store,
-            final ReadWriteTransaction transaction,
-            final InstanceIdentifier<Node> 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);
-    }
-}
index 2a817db7eca43ebfeef77ab7d57fd28f1c74ad7e..829487a409a232c7ab040fbe6eee013047b7c613 100644 (file)
@@ -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.<QName>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();
     }
 
index a01b74e94149bdd78c673bcae856900374154b28..278771a5ba880a97ec4e3c0eaaa2da7bdb841be4 100644 (file)
@@ -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<DOMMountPoint> registration;
         private NetconfDeviceNotificationService notificationService;
 
         private ObjectRegistration<DOMMountPoint> 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;
         }
index 6386a8834839c6a5be3943858b27e5a2a5a6decb..7e62990bc7288e619362040c2b04f78e31f11ac9 100644 (file)
@@ -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 {