Merge "Bug 9256: Add websocket server config knob for ip"
authorTomas Cere <tcere@cisco.com>
Thu, 12 Oct 2017 10:18:08 +0000 (10:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Oct 2017 10:18:08 +0000 (10:18 +0000)
45 files changed:
features/netconf-connector/odl-netconf-connector/pom.xml
netconf/callhome-protocol/pom.xml
netconf/mdsal-netconf-monitoring/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/monitoring/MonitoringToMdsalWriter.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/controller/config/yang/netconf/mdsal/notification/NotificationToMdsalWriter.java
netconf/mdsal-netconf-yang-library/src/main/java/org/opendaylight/netconf/mdsal/yang/library/SchemaServiceToMdsalWriter.java
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java
netconf/netconf-ssh/pom.xml
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/NetconfTopologyManager.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/NetconfNodeActor.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadAdapter.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/actors/WriteAdapter.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/tx/ProxyWriteAdapter.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/messages/transactions/SubmitFailedReply.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/actors/ReadWriteTransactionActorTest.java
netconf/netconf-topology-singleton/src/test/java/org/opendaylight/netconf/topology/singleton/impl/actors/WriteTransactionActorTest.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfConnectorFactoryImpl.java
netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfTopologyImpl.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/AbstractWriteTx.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/WriteCandidateTx.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java
netconf/tools/netconf-testtool/README.adoc [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Main.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/ScaleUtil.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TestToolUtils.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolParameters.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/Configuration.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/ConfigurationBuilder.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/operations/OperationsProvider.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandler.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandlerDefault.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableOperationRpcProvider.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/ModelData.java [new file with mode: 0644]
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/SchemaSourceCache.java [new file with mode: 0644]
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibProvider.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BatchedExistenceCheck.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/BrokerFacade.java

index c332d3667947423565b9254679c5532e61827f10..66988da7824551f58cb4dd8feeabeddec05c8c2f 100644 (file)
             <type>xml</type>
             <classifier>features</classifier>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>odl-mdsal-model-inventory</artifactId>
+            <version>1.7.0-SNAPSHOT</version>
+            <type>xml</type>
+            <classifier>features</classifier>
+        </dependency>
         <dependency>
             <groupId>com.google.code.gson</groupId>
             <artifactId>gson</artifactId>
             <groupId>org.opendaylight.netconf</groupId>
             <artifactId>sal-netconf-connector</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller.model</groupId>
-            <artifactId>model-inventory</artifactId>
-            <version>1.7.0-SNAPSHOT</version>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.netconf</groupId>
             <artifactId>netconf-topology</artifactId>
index e8cf5dc72306d31726f608e13f611832324ebbbf..0900e7660783e5c6d8fc4027bb4f96a639b9486c 100644 (file)
       <groupId>org.opendaylight.netconf</groupId>
       <artifactId>netconf-client</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcpkix-jdk15on</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcprov-jdk15on</artifactId>
-    </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
index 30e2655924086de8b934c3e1833a77effffbbbed..0bd79fde0ce6a734ca8540e0738dcf64a87347ee 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.config.yang.netconf.mdsal.monitoring;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collection;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
@@ -112,7 +113,7 @@ public final class MonitoringToMdsalWriter implements AutoCloseable, NetconfMoni
             public void onFailure(Throwable throwable) {
                 LOG.warn("Unable to update netconf state", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private static void updateSessions(WriteTransaction tx, Collection<Session> sessions) {
index 1535b987f983eb718aee58984bc0511d78f1d755..d5ba353fe64ab4ed812c330c859d0104ddfe826a 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.config.yang.netconf.mdsal.notification;
 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.MoreExecutors;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -61,7 +62,7 @@ public final class NotificationToMdsalWriter implements AutoCloseable, NetconfNo
             public void onFailure(Throwable throwable) {
                 LOG.warn("Unable to clear streams", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         notificationRegistration.close();
     }
index 9690ad3e243354ec7294d2c494b417845857186f..d0d383a2bb0dbfe28f2d59ef3cf94f4dc2aa163b 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.netconf.mdsal.yang.library;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -91,7 +92,7 @@ public class SchemaServiceToMdsalWriter implements SchemaContextListener, AutoCl
             public void onFailure(final Throwable throwable) {
                 LOG.warn("Failed to update modules state", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private ModulesState createModuleStateFromModules(final Set<Module> modules) {
index 47417bc7372597cb9825bd5d6f723d72b13bbcfb..9a9fa6e1ee09c7bf665027827c2f1144cc2c428a 100644 (file)
@@ -12,7 +12,9 @@ import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder;
@@ -97,9 +100,14 @@ public class NetconfCommandsImpl implements NetconfCommands {
                             ImmutableList.of(netconfNode.getPort().getValue().toString()));
                     attributes.put(NetconfConsoleConstants.STATUS,
                             ImmutableList.of(netconfNode.getConnectionStatus().name()));
-                    attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES,
-                            netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
-                                    .map(AvailableCapability::getCapability).collect(Collectors.toList()));
+                    if (netconfNode.getConnectionStatus().equals(
+                            NetconfNodeConnectionStatus.ConnectionStatus.Connected)) {
+                        attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES,
+                                netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
+                                        .map(AvailableCapability::getCapability).collect(Collectors.toList()));
+                    } else {
+                        attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Collections.singletonList(""));
+                    }
                     device.put(node.getNodeId().getValue(), attributes);
                 }
             }
@@ -122,9 +130,13 @@ public class NetconfCommandsImpl implements NetconfCommands {
                         ImmutableList.of(netconfNode.getPort().getValue().toString()));
                 attributes.put(NetconfConsoleConstants.STATUS,
                         ImmutableList.of(netconfNode.getConnectionStatus().name()));
-                attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES,
-                        netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
-                                .map(AvailableCapability::getCapability).collect(Collectors.toList()));
+                if (netconfNode.getConnectionStatus().equals(NetconfNodeConnectionStatus.ConnectionStatus.Connected)) {
+                    attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES,
+                            netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
+                                    .map(AvailableCapability::getCapability).collect(Collectors.toList()));
+                } else {
+                    attributes.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Collections.singletonList(""));
+                }
                 device.put(node.getNodeId().getValue(), attributes);
             }
         }
@@ -160,7 +172,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
                 LOG.error("Failed to created NetconfNode={}", netconfNode);
                 throw new RuntimeException(throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     @Override
@@ -242,7 +254,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
                     LOG.error("Failed to updated NetconfNode={}", netconfNode);
                     throw new RuntimeException(throwable);
                 }
-            });
+            }, MoreExecutors.directExecutor());
 
             return "NETCONF node: " + netconfNodeId + " updated successfully.";
         } else {
index f1806b43cef396659dea16e04f50aa9d6c19d8ed..df9ece7dd92983cfd72285b789a1055f7d843f83 100644 (file)
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -120,7 +121,7 @@ public class AsyncSshHandlerTest {
             public void onSuccess(final SshFutureListener<AuthFuture> result) {
                 sshAuthListener = result;
             }
-        });
+        }, MoreExecutors.directExecutor());
         doReturn(authFuture).when(authHandler).authenticate(any(ClientSession.class));
     }
 
@@ -169,7 +170,7 @@ public class AsyncSshHandlerTest {
             public void onSuccess(final SshFutureListener<ConnectFuture> result) {
                 sshConnectListener = result;
             }
-        });
+        }, MoreExecutors.directExecutor());
         doReturn(connectFuture).when(sshClient).connect("usr", remoteAddress);
     }
 
@@ -227,7 +228,7 @@ public class AsyncSshHandlerTest {
                 doReturn(true).when(asyncOut).isClosed();
                 result.operationComplete(mockedReadFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         final IoOutputStream asyncIn = getMockedIoOutputStream();
         final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
@@ -256,7 +257,7 @@ public class AsyncSshHandlerTest {
                         .removeListener(Matchers.<SshFutureListener<IoReadFuture>>any());
                 result.operationComplete(mockedReadFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         final IoOutputStream asyncIn = getMockedIoOutputStream();
         final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
@@ -308,7 +309,7 @@ public class AsyncSshHandlerTest {
                 doReturn(true).when(asyncIn).isClosed();
                 result.operationComplete(ioWriteFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         final ChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
         final ClientSession sshSession = getMockedSshSession(subsystemChannel);
@@ -463,7 +464,7 @@ public class AsyncSshHandlerTest {
                 doReturn(true).when(closeFuture).isClosed();
                 result.operationComplete(closeFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
         doReturn(closeFuture).when(sshSession).close(false);
 
         doReturn(subsystemChannel).when(sshSession).createSubsystemChannel(anyString());
@@ -484,7 +485,7 @@ public class AsyncSshHandlerTest {
             public void onSuccess(final SshFutureListener<OpenFuture> result) {
                 sshChannelOpenListener = result;
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         doReturn(asyncOut).when(subsystemChannel).getAsyncOut();
 
@@ -504,7 +505,7 @@ public class AsyncSshHandlerTest {
             public void onSuccess(final SshFutureListener<IoWriteFuture> result) {
                 result.operationComplete(ioWriteFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         doReturn(ioWriteFuture).when(mock).write(any(Buffer.class));
         doReturn(false).when(mock).isClosed();
@@ -527,7 +528,7 @@ public class AsyncSshHandlerTest {
             public void onSuccess(final SshFutureListener<IoReadFuture> result) {
                 result.operationComplete(ioReadFuture);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         doReturn(ioReadFuture).when(mock).read(any(Buffer.class));
         doReturn(false).when(mock).isClosed();
index 444ba088aa85fc1a6e822d4a45760d49484e8339..a90a669d347cb2657bc78c2d4dbc2f091ffccfb8 100644 (file)
       <groupId>org.opendaylight.mdsal.model</groupId>
       <artifactId>ietf-inet-types-2013-07-15</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcpkix-jdk15on</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.bouncycastle</groupId>
-      <artifactId>bcprov-jdk15on</artifactId>
-    </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
index 1018be37cd88f70baa40415e04a7249769f7dcb5..48f063e92049400aa34995a201e3d27da2d67a51 100644 (file)
@@ -13,6 +13,7 @@ import akka.util.Timeout;
 import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
 import java.util.Collection;
 import java.util.HashMap;
@@ -255,7 +256,7 @@ public class NetconfTopologyManager
             public void onFailure(@Nonnull final Throwable throwable) {
                 LOG.error("Unable to initialize netconf-topology, {}", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         LOG.debug("Registering datastore listener");
         return dataBroker.registerDataTreeChangeListener(
index acf3854a83c7289b3b9bd91ae56b1b2217043d16..826342d23f2f4fe12881860238d385c74eb4dc60 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
 import java.math.BigDecimal;
 import java.net.InetSocketAddress;
@@ -124,7 +125,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
             public void onFailure(@Nullable final Throwable throwable) {
                 LOG.error("{}: Connector failed, {}", remoteDeviceId, throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
index 6d1e7717168bdf1780c42400909566ba1d04281e..2e46cd4a1bfbb033f2b5948116503124eb3bf567 100644 (file)
@@ -15,6 +15,7 @@ import akka.util.Timeout;
 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.MoreExecutors;
 import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -214,7 +215,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 sender.tell(throwable, getSelf());
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void invokeSlaveRpc(final SchemaPath schemaPath, final NormalizedNodeMessage normalizedNodeMessage,
@@ -242,7 +243,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 recipient.tell(throwable, getSelf());
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void registerSlaveMountPoint(final ActorRef masterReference) {
@@ -268,7 +269,7 @@ public class NetconfNodeActor extends UntypedActor {
             public void onFailure(@Nonnull final Throwable throwable) {
                 LOG.error("{}: Failed to register mount point: {}", id, throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private DOMRpcService getDOMRpcService(final ActorRef masterReference) {
index d36062459d35670fe61ed5bd56890b62103a4dae..3d881e65def18fd6ff0a15c21064922e8a2bee45 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Optional;
 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.MoreExecutors;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -67,7 +68,7 @@ class ReadAdapter {
             public void onFailure(@Nonnull final Throwable throwable) {
                 sender.tell(throwable, self);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private void exists(final YangInstanceIdentifier path, final LogicalDatastoreType store, final ActorRef sender,
@@ -87,6 +88,6 @@ class ReadAdapter {
             public void onFailure(@Nonnull final Throwable throwable) {
                 sender.tell(throwable, self);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 }
index 4cf51eead297a3fbaff603a23ab22df699227a68..a214dd4fc71a7a45383f7f78e63686a648ca9e0a 100644 (file)
@@ -13,6 +13,7 @@ import akka.actor.ActorRef;
 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.MoreExecutors;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
@@ -21,10 +22,16 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.CancelR
 import org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest;
+import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitFailedReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 class WriteAdapter {
+
+    private static final Logger LOG = LoggerFactory.getLogger(WriteAdapter.class);
+
     private final DOMDataWriteTransaction tx;
 
     WriteAdapter(final DOMDataWriteTransaction tx) {
@@ -48,27 +55,35 @@ class WriteAdapter {
 
             @Override
             public void onFailure(@Nonnull final Throwable throwable) {
-                requester.tell(throwable, self);
+                requester.tell(new SubmitFailedReply(throwable), self);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void handle(final Object message, final ActorRef sender, final ActorContext context, final ActorRef self) {
-        if (message instanceof MergeRequest) {
-            final MergeRequest mergeRequest = (MergeRequest) message;
-            final NormalizedNodeMessage data = mergeRequest.getNormalizedNodeMessage();
-            tx.merge(mergeRequest.getStore(), data.getIdentifier(), data.getNode());
-        } else if (message instanceof PutRequest) {
-            final PutRequest putRequest = (PutRequest) message;
-            final NormalizedNodeMessage data = putRequest.getNormalizedNodeMessage();
-            tx.put(putRequest.getStore(), data.getIdentifier(), data.getNode());
-        } else if (message instanceof DeleteRequest) {
-            final DeleteRequest deleteRequest = (DeleteRequest) message;
-            tx.delete(deleteRequest.getStore(), deleteRequest.getPath());
-        } else if (message instanceof CancelRequest) {
-            cancel(context, sender, self);
-        } else if (message instanceof SubmitRequest) {
-            submit(sender, self, context);
+        // we need to catch everything, since an unchecked exception can be thrown from the underlying parse.
+        // TODO Maybe we should store it and fail the submit immediately?.
+        try {
+            if (message instanceof MergeRequest) {
+                final MergeRequest mergeRequest = (MergeRequest) message;
+                final NormalizedNodeMessage data = mergeRequest.getNormalizedNodeMessage();
+                tx.merge(mergeRequest.getStore(), data.getIdentifier(), data.getNode());
+            } else if (message instanceof PutRequest) {
+                final PutRequest putRequest = (PutRequest) message;
+                final NormalizedNodeMessage data = putRequest.getNormalizedNodeMessage();
+                tx.put(putRequest.getStore(), data.getIdentifier(), data.getNode());
+            } else if (message instanceof DeleteRequest) {
+                final DeleteRequest deleteRequest = (DeleteRequest) message;
+                tx.delete(deleteRequest.getStore(), deleteRequest.getPath());
+            } else if (message instanceof CancelRequest) {
+                cancel(context, sender, self);
+            } else if (message instanceof SubmitRequest) {
+                submit(sender, self, context);
+            }
+
+        } catch (final RuntimeException exception) {
+            LOG.error("Write command has failed.", exception);
         }
     }
 }
index 223e443cd52161228be1a7755cc168bd6bcfd77a..a833e3bb422ef721030ea426beab4c45ee40c08f 100644 (file)
@@ -101,7 +101,10 @@ public class ProxyWriteAdapter {
                 } else {
                     if (success instanceof SubmitFailedReply) {
                         LOG.error("{}: Transaction was not submitted because already closed.", id);
+                        settableFuture.setException(((SubmitFailedReply) success).getThrowable());
+                        return;
                     }
+
                     settableFuture.set(null);
                 }
             }
index 18e1f47393c01493398e9304114e6e4e08ac4d5c..7dfc19c0c6e79a000e9cb9db43c83e5e4d360b3b 100644 (file)
@@ -11,8 +11,18 @@ package org.opendaylight.netconf.topology.singleton.messages.transactions;
 import java.io.Serializable;
 
 /**
- * Message sent from master back to the slave when submit is not performed, tx is closed.
+ * Message sent from master back to the slave when submit fails, with the offending exception attached.
  */
 public class SubmitFailedReply implements Serializable {
     private static final long serialVersionUID = 1L;
+
+    private final Throwable throwable;
+
+    public SubmitFailedReply(final Throwable throwable) {
+        this.throwable = throwable;
+    }
+
+    public Throwable getThrowable() {
+        return throwable;
+    }
 }
index e02f1f8dc72a6bce4fbfe9230988ae01221ce52f..e9eee1851a2aaf77d286679927df98f303c05869 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.ExistsR
 import org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest;
+import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitFailedReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -174,7 +175,8 @@ public class ReadWriteTransactionActorTest {
         when(deviceReadWriteTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(cause));
         final Future<Object> submitFuture = Patterns.ask(actorRef, new SubmitRequest(), TIMEOUT);
         final Object result = Await.result(submitFuture, TIMEOUT.duration());
-        Assert.assertEquals(cause, result);
+        Assert.assertTrue(result instanceof SubmitFailedReply);
+        Assert.assertEquals(cause, ((SubmitFailedReply)result).getThrowable());
         verify(deviceReadWriteTx).submit();
     }
 
index 4e7fc3537b5e006a837026aa11355106b17af587..cd2b9829142bc96d15a44bbb1066eb1a81d12262 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.netconf.topology.singleton.messages.transactions.CancelR
 import org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest;
+import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitFailedReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitReply;
 import org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -122,7 +123,8 @@ public class WriteTransactionActorTest {
         when(deviceWriteTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(cause));
         final Future<Object> submitFuture = Patterns.ask(actorRef, new SubmitRequest(), TIMEOUT);
         final Object result = Await.result(submitFuture, TIMEOUT.duration());
-        Assert.assertEquals(cause, result);
+        Assert.assertTrue(result instanceof SubmitFailedReply);
+        Assert.assertEquals(cause, ((SubmitFailedReply)result).getThrowable());
         verify(deviceWriteTx).submit();
     }
 
index 4362b92e645cf67aff50e4c7c666b0ebcd32b106..d430ce2f1c4cc2243cd12c0adfddbeaa513358ef 100644 (file)
@@ -15,6 +15,7 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
 import java.io.File;
 import java.math.BigDecimal;
@@ -244,7 +245,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology {
                 LOG.error("Connector for : " + nodeId.getValue() + " failed");
                 // remove this node from active connectors?
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         return future;
     }
index c925a8828f012ceaa3ca7d4e6315cdb37205ba55..c644286504d6248fb034bffd700df7b455c42126 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.topology.impl;
 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.MoreExecutors;
 import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -90,7 +91,7 @@ public class NetconfConnectorFactoryImpl implements NetconfConnectorFactory {
             public void onFailure(final Throwable throwable) {
                 LOG.error("Node {} creation failed: {}", instanceName, throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
         return node;
     }
 }
\ No newline at end of file
index 263e524bd7541a10a28ce10a6eff13223ae272e2..a17369f144accdd5b3e9f89ead6910a7d0162d8a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.topology.impl;
 
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
 import java.util.Collection;
 import javax.annotation.Nonnull;
@@ -96,7 +97,7 @@ public class NetconfTopologyImpl extends AbstractNetconfTopology
             public void onFailure(final Throwable throwable) {
                 LOG.error("Unable to initialize netconf-topology, {}", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         LOG.debug("Registering datastore listener");
         datastoreListenerRegistration =
index b78011460e4e81f4544c79863184e7f7089ea429..22fa4cb92ed49cbd25c38ed9fa119b3f814b0783 100644 (file)
@@ -165,7 +165,7 @@ public class NetconfDevice
             }
         };
 
-        Futures.addCallback(sourceResolverFuture, resolvedSourceCallback);
+        Futures.addCallback(sourceResolverFuture, resolvedSourceCallback, MoreExecutors.directExecutor());
     }
 
     private void registerToBaseNetconfStream(final NetconfDeviceRpc deviceRpc,
@@ -206,7 +206,7 @@ public class NetconfDevice
                 LOG.warn("Unable to subscribe to base notification stream. Schemas will not be reloaded on the fly",
                         throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     private boolean shouldListenOnSchemaChange(final NetconfSessionPreferences remoteSessionCapabilities) {
index b77e7269e553ae6dc11837c4ef45ab309e3dccc9..a92ad42c709044a031e9c65095358a4c16b665fd 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.base.Preconditions;
 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.MoreExecutors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -191,7 +192,8 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
                 if (previousKeepalive != null && !previousKeepalive.isDone()) {
                     onFailure(new IllegalStateException("Previous keepalive timed out"));
                 } else {
-                    Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this);
+                    Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this,
+                                        MoreExecutors.directExecutor());
                 }
             } catch (NullPointerException e) {
                 LOG.debug("{}: Skipping keepalive while reconnecting", id);
@@ -296,7 +298,8 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
                                                                       final NormalizedNode<?, ?> input) {
             final CheckedFuture<DOMRpcResult, DOMRpcException> domRpcResultDOMRpcExceptionCheckedFuture =
                     deviceRpc.invokeRpc(type, input);
-            Futures.addCallback(domRpcResultDOMRpcExceptionCheckedFuture, resetKeepaliveTask);
+            Futures.addCallback(domRpcResultDOMRpcExceptionCheckedFuture, resetKeepaliveTask,
+                                MoreExecutors.directExecutor());
 
             final RequestTimeoutTask timeoutTask = new RequestTimeoutTask(domRpcResultDOMRpcExceptionCheckedFuture);
             executor.schedule(timeoutTask, defaultRequestTimeoutMillis, TimeUnit.MILLISECONDS);
index 7667ba28bcb924a904175e9e32fd3e7dbebead17..41609b89c4fdd52950b336440adc643a52ee786b 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 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.MoreExecutors;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -242,8 +243,7 @@ public final class NetconfDeviceTopologyAdapter implements AutoCloseable {
                 throw new IllegalStateException(
                         id + "  Transaction(" + txType + ") not committed correctly", throwable);
             }
-        });
-
+        }, MoreExecutors.directExecutor());
     }
 
     private static Node getNodeWithId(final RemoteDeviceId id) {
index 14926d99f20d0e45b494c572970ecd04ab924b13..7d6dd3e9e862f3cc8e41caea0428f0e98563d3b1 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -169,7 +170,7 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
             public void onFailure(final Throwable throwable) {
                 listeners.forEach(listener -> listener.onTransactionFailed(AbstractWriteTx.this, throwable));
             }
-        });
+        }, MoreExecutors.directExecutor());
         return result;
     }
 
@@ -218,7 +219,7 @@ public abstract class AbstractWriteTx implements DOMDataWriteTransaction {
                                 DocumentedException.ErrorSeverity.ERROR);
                 transformed.setException(exception);
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         return transformed;
     }
index febbff6cec99aebe12942a64b0935ea64129a612..1d429022c1da73a611224a993030f2f2fa776987 100644 (file)
@@ -15,6 +15,7 @@ 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 com.google.common.util.concurrent.MoreExecutors;
 import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
@@ -131,7 +132,7 @@ public class WriteCandidateTx extends AbstractWriteTx {
                 // cleanup is trying to do unlock, but this will fail
                 cleanup();
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         return txResult;
     }
index debd460936ecfb524da81fd2385688a47138fd28..3dee33869ede81d72aa3f8572c8ef43d5f77be8c 100644 (file)
@@ -33,6 +33,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade.KeepaliveDOMRpcService;
@@ -79,14 +80,14 @@ public final class NetconfBaseOps {
 
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_LOCK_QNAME), getLockContent(datastore));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
     public ListenableFuture<DOMRpcResult> lockCandidate(final FutureCallback<DOMRpcResult> callback) {
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_LOCK_QNAME), getLockContent(NETCONF_CANDIDATE_QNAME));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -94,7 +95,7 @@ public final class NetconfBaseOps {
     public ListenableFuture<DOMRpcResult> lockRunning(final FutureCallback<DOMRpcResult> callback) {
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_LOCK_QNAME), getLockContent(NETCONF_RUNNING_QNAME));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -104,21 +105,21 @@ public final class NetconfBaseOps {
 
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_UNLOCK_QNAME), getUnLockContent(datastore));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
     public ListenableFuture<DOMRpcResult> unlockRunning(final FutureCallback<DOMRpcResult> callback) {
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_UNLOCK_QNAME), getUnLockContent(NETCONF_RUNNING_QNAME));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
     public ListenableFuture<DOMRpcResult> unlockCandidate(final FutureCallback<DOMRpcResult> callback) {
         final ListenableFuture<DOMRpcResult> future =
                 rpc.invokeRpc(toPath(NETCONF_UNLOCK_QNAME), getUnLockContent(NETCONF_CANDIDATE_QNAME));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -126,7 +127,7 @@ public final class NetconfBaseOps {
         Preconditions.checkNotNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -135,7 +136,7 @@ public final class NetconfBaseOps {
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(
             toPath(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME), NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -145,7 +146,7 @@ public final class NetconfBaseOps {
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(
                 toPath(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME), getValidateContent(datastore));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -166,7 +167,7 @@ public final class NetconfBaseOps {
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(
                 toPath(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME), getCopyConfigContent(source, target));
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -189,7 +190,7 @@ public final class NetconfBaseOps {
                             NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, getSourceNode(datastore)));
         }
 
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
@@ -281,7 +282,7 @@ public final class NetconfBaseOps {
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(toPath(NETCONF_EDIT_CONFIG_QNAME),
                 getEditConfigContent(datastore, editStructure, modifyAction, rollback));
 
-        Futures.addCallback(future, callback);
+        Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
 
index a26401efc599ed320e1c805428c6d7448da43d6a..4edbedf6c265830028c82a72af1527aadd75afe5 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Preconditions;
 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.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.concurrent.Future;
 import org.opendaylight.aaa.encrypt.AAAEncryptionService;
@@ -101,7 +102,7 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
                 LOG.error("add-netconf-node RPC: Unable to add netconf node.", exception);
                 futureResult.setException(exception);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
 }
diff --git a/netconf/tools/netconf-testtool/README.adoc b/netconf/tools/netconf-testtool/README.adoc
new file mode 100644 (file)
index 0000000..cfdefdf
--- /dev/null
@@ -0,0 +1,72 @@
+# NetConf TestTool
+
+This project is used to simulate NetConf devices in order to test NetConf
+south-bound plugin and applications using this plugin. *netconf-testtool*
+project is designed as versatile java library to be used for custom NetConf device
+test simulations.
+
+## How to use as standalone application
+* compile project
+* start org.opendaylight.netconf.test.tool.Main
+
+## How to use it in your code
+* Use maven dependency in your project
+----
+<dependency>
+    <groupId>org.opendaylight.netconf</groupId>
+    <artifactId>netconf-testtool-core</artifactId>
+    <version>0.1.0-SNAPSHOT</version>
+</dependency>
+----
+* Prepare configuration - models are loaded by classloader
+  from classpath.
+----
+Set<String> models = ImmutableSet.of(
+    "models/iana-afn-safi@2013-07-04.yang",
+    "models/ietf-inet-types@2013-07-15.yang",
+    "models/ietf-netconf@2011-06-01.yang",
+    "models/ietf-netconf-monitoring@2010-10-04.yang",
+    "models/ietf-netconf-monitoring-extension@2013-12-10.yang",
+    "models/ietf-yang-library@2016-06-21.yang",
+    "models/ietf-yang-types@2013-07-15.yang",
+    "models/nc-notifications@2008-07-14.yang",
+    "models/notifications@2008-07-14.yang",
+    ...
+);
+----
+* Prepare list of capabilities
+----
+Set<String> capabilities = ImmutableSet.of(
+    "urn:ietf:params:netconf:base:1.0",
+    "urn:ietf:params:netconf:base:1.1",
+    ...
+);
+----
+* Override RPC mapping provider org.opendaylight.netconf.test.tool.rpchandler.RpcHandler
+----
+public class RpcHandlerImpl implements RpcHandler {
+    @Override
+    public Optional<Document> getResponse(XmlElement rpcElement) {
+        ...
+        return response;
+    }
+}
+
+----
+* Start NetConf device simulator in your code
+----
+public class Main {
+
+    public static void main(String[] args) {
+        Configuration configuration = new ConfigurationBuilder()
+                .setModels(models)
+                .setCapabilities(capabilities)
+                .setRpcHandler(new RpcHandlerImpl())
+                .build();
+        NetConfDeviceSimulator netConfDeviceSimulator =
+                new NetConfDeviceSimulator(configuration);
+        netConfDeviceSimulator.start();
+    }
+
+}
+----
index 3a0b69a47ee4fa835b8f7599cb37d758581cd9f0..4e6c2a327a6192af8bbb10576279bd3cad87b998 100644 (file)
@@ -37,6 +37,8 @@ import org.apache.karaf.features.internal.model.ConfigFile;
 import org.apache.karaf.features.internal.model.Feature;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
+import org.opendaylight.netconf.test.tool.config.Configuration;
+import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,10 +54,11 @@ public final class Main {
             .getLogger(Logger.ROOT_LOGGER_NAME);
         root.setLevel(params.debug ? Level.DEBUG : Level.INFO);
 
-        final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(params.threadPoolSize);
+        final Configuration configuration = new ConfigurationBuilder().from(params).build();
+        final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(configuration);
         try {
             LOG.debug("Trying to start netconf test-tool with parameters {}", params);
-            final List<Integer> openDevices = netconfDeviceSimulator.start(params);
+            final List<Integer> openDevices = netconfDeviceSimulator.start();
             if (openDevices.size() == 0) {
                 LOG.error("Failed to start any simulated devices, exiting...");
                 System.exit(1);
index 53ca53ab70ab4eabfdeeb8011d80e6119c31c87b..dffd79e6c564625407af852e9362546175556131 100644 (file)
@@ -42,7 +42,6 @@ import org.opendaylight.controller.config.util.capability.BasicCapability;
 import org.opendaylight.controller.config.util.capability.Capability;
 import org.opendaylight.controller.config.util.capability.YangModuleCapability;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
-import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.netconf.impl.SessionIdProvider;
@@ -53,7 +52,11 @@ import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringOperationServic
 import org.opendaylight.netconf.ssh.SshProxyServer;
 import org.opendaylight.netconf.ssh.SshProxyServerConfiguration;
 import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
+import org.opendaylight.netconf.test.tool.config.Configuration;
 import org.opendaylight.netconf.test.tool.customrpc.SettableOperationProvider;
+import org.opendaylight.netconf.test.tool.operations.OperationsProvider;
+import org.opendaylight.netconf.test.tool.rpchandler.SettableOperationRpcProvider;
+import org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -83,27 +86,23 @@ public class NetconfDeviceSimulator implements Closeable {
     private final List<SshProxyServer> sshWrappers = Lists.newArrayList();
     private final ScheduledExecutorService minaTimerExecutor;
     private final ExecutorService nioExecutor;
+    private final Configuration configuration;
     private SchemaContext schemaContext;
 
     private boolean sendFakeSchema = false;
 
-    public NetconfDeviceSimulator(final int threadPoolSize) {
-        this(new NioEventLoopGroup(), new HashedWheelTimer(),
-                Executors.newScheduledThreadPool(threadPoolSize,
-                    new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build()),
-                ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", threadPoolSize));
-    }
-
-    private NetconfDeviceSimulator(final NioEventLoopGroup eventExecutors, final HashedWheelTimer hashedWheelTimer,
-            final ScheduledExecutorService minaTimerExecutor, final ExecutorService nioExecutor) {
-        this.nettyThreadgroup = eventExecutors;
-        this.hashedWheelTimer = hashedWheelTimer;
-        this.minaTimerExecutor = minaTimerExecutor;
-        this.nioExecutor = nioExecutor;
+    public NetconfDeviceSimulator(Configuration configuration) {
+        this.configuration = configuration;
+        this.nettyThreadgroup = new NioEventLoopGroup();
+        this.hashedWheelTimer = new HashedWheelTimer();
+        this.minaTimerExecutor = Executors.newScheduledThreadPool(configuration.getThreadPoolSize(),
+                new ThreadFactoryBuilder().setNameFormat("netconf-ssh-server-mina-timers-%d").build());
+        this.nioExecutor = ThreadUtils
+                .newFixedThreadPool("netconf-ssh-server-nio-group", configuration.getThreadPoolSize());
     }
 
     private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities,
-            final SchemaSourceProvider<YangTextSchemaSource> sourceProvider, final TesttoolParameters params) {
+            final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
 
         final Set<Capability> transformedCapabilities = Sets.newHashSet(Collections2.transform(capabilities, input -> {
             if (sendFakeSchema) {
@@ -118,15 +117,13 @@ public class NetconfDeviceSimulator implements Closeable {
         final SessionIdProvider idProvider = new SessionIdProvider();
 
         final NetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = createOperationServiceFactory(
-            sourceProvider, params, transformedCapabilities, monitoringService1, idProvider);
+            sourceProvider, transformedCapabilities, monitoringService1, idProvider);
 
-        final Set<String> serverCapabilities = params.exi
-                ? NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES
-                : Sets.newHashSet(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
-                    XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1);
+        final Set<String> serverCapabilities = configuration.getCapabilities();
 
         final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new TesttoolNegotiationFactory(
-                hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, params.generateConfigsTimeout,
+                hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider,
+                configuration.getGenerateConfigsTimeout(),
                 monitoringService1, serverCapabilities);
 
         final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer =
@@ -135,20 +132,25 @@ public class NetconfDeviceSimulator implements Closeable {
     }
 
     private NetconfOperationServiceFactory createOperationServiceFactory(
-            final SchemaSourceProvider<YangTextSchemaSource> sourceProvider, final TesttoolParameters params,
+            final SchemaSourceProvider<YangTextSchemaSource> sourceProvider,
             final Set<Capability> transformedCapabilities, final NetconfMonitoringService monitoringService1,
             final SessionIdProvider idProvider) {
         final AggregatedNetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory =
             new AggregatedNetconfOperationServiceFactory();
 
         final NetconfOperationServiceFactory operationProvider;
-        if (params.mdSal) {
+        if (configuration.isMdSal()) {
+            LOG.info("using MdsalOperationProvider.");
             operationProvider = new MdsalOperationProvider(
                 idProvider, transformedCapabilities, schemaContext, sourceProvider);
-        } else {
+        } else if (configuration.isXmlConfigurationProvided()) {
+            LOG.info("using SimulatedOperationProvider.");
             operationProvider = new SimulatedOperationProvider(idProvider, transformedCapabilities,
-                    Optional.fromNullable(params.notificationFile),
-                    Optional.fromNullable(params.initialConfigXMLFile));
+                    Optional.fromNullable(configuration.getNotificationFile()),
+                    Optional.fromNullable(configuration.getInitialConfigXMLFile()));
+        } else {
+            LOG.info("using OperationsProvider.");
+            operationProvider = new OperationsProvider(idProvider, transformedCapabilities);
         }
 
 
@@ -157,39 +159,44 @@ public class NetconfDeviceSimulator implements Closeable {
                         new NetconfMonitoringOperationService(monitoringService1));
         aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(operationProvider);
         aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(monitoringService);
-        if (params.rpcConfig != null) {
-            final SettableOperationProvider settableService = new SettableOperationProvider(params.rpcConfig);
+        if (configuration.getRpcConfigFile() != null) {
+            final SettableOperationProvider settableService =
+                    new SettableOperationProvider(configuration.getRpcConfigFile());
+            aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(settableService);
+        } else {
+            final SettableOperationRpcProvider settableService =
+                    new SettableOperationRpcProvider(configuration.getRpcHandler());
             aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(settableService);
         }
         return aggregatedNetconfOperationServiceFactory;
     }
 
-    public List<Integer> start(final TesttoolParameters params) {
+    public List<Integer> start() {
         LOG.info("Starting {}, {} simulated devices starting on port {}",
-            params.deviceCount, params.ssh ? "SSH" : "TCP", params.startingPort);
+                configuration.getDeviceCount(), configuration.isSsh() ? "SSH" : "TCP", configuration.getStartingPort());
 
         final SharedSchemaRepository schemaRepo = new SharedSchemaRepository("netconf-simulator");
-        final Set<Capability> capabilities = parseSchemasToModuleCapabilities(params, schemaRepo);
+        final Set<Capability> capabilities = parseSchemasToModuleCapabilities(schemaRepo);
 
         final NetconfServerDispatcherImpl dispatcher = createDispatcher(capabilities,
-            sourceIdentifier -> schemaRepo.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class), params);
+            sourceIdentifier -> schemaRepo.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class));
 
-        int currentPort = params.startingPort;
+        int currentPort = configuration.getStartingPort();
 
         final List<Integer> openDevices = Lists.newArrayList();
 
         // Generate key to temp folder
         final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider();
 
-        for (int i = 0; i < params.deviceCount; i++) {
+        for (int i = 0; i < configuration.getDeviceCount(); i++) {
             if (currentPort > 65535) {
                 LOG.warn("Port cannot be greater than 65535, stopping further attempts.");
                 break;
             }
-            final InetSocketAddress address = getAddress(params.ip, currentPort);
+            final InetSocketAddress address = getAddress(configuration.getIp(), currentPort);
 
             final ChannelFuture server;
-            if (params.ssh) {
+            if (configuration.isSsh()) {
                 final InetSocketAddress bindingAddress = InetSocketAddress.createUnresolved("0.0.0.0", currentPort);
                 final LocalAddress tcpLocalAddress = new LocalAddress(address.toString());
 
@@ -245,9 +252,9 @@ public class NetconfDeviceSimulator implements Closeable {
             openDevices.add(currentPort - 1);
         }
 
-        if (openDevices.size() == params.deviceCount) {
+        if (openDevices.size() == configuration.getDeviceCount()) {
             LOG.info("All simulated devices started successfully from port {} to {}",
-                params.startingPort, currentPort - 1);
+                    configuration.getStartingPort(), currentPort - 1);
         } else if (openDevices.size() == 0) {
             LOG.warn("No simulated devices started.");
         } else {
@@ -278,12 +285,9 @@ public class NetconfDeviceSimulator implements Closeable {
         }
     }
 
-    private Set<Capability> parseSchemasToModuleCapabilities(final TesttoolParameters params,
-                                                             final SharedSchemaRepository consumer) {
+    private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
         final Set<SourceIdentifier> loadedSources = Sets.newHashSet();
-
         consumer.registerSchemaSourceListener(TextToASTTransformer.create(consumer, consumer));
-
         consumer.registerSchemaSourceListener(new SchemaSourceListener() {
             @Override
             public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {}
@@ -299,10 +303,18 @@ public class NetconfDeviceSimulator implements Closeable {
             public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {}
         });
 
-        if (params.schemasDir != null) {
+        if (configuration.getSchemasDir() != null) {
+            LOG.info("Loading models from directory.");
             final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
-                consumer, YangTextSchemaSource.class, params.schemasDir);
+                consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
+            consumer.registerSchemaSourceListener(cache);
+        } else if (configuration.getModels() != null) {
+            LOG.info("Loading models from classpath.");
+            final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(
+                    consumer, YangTextSchemaSource.class, configuration.getModels());
             consumer.registerSchemaSourceListener(cache);
+        } else {
+            LOG.info("Custom module loading skipped.");
         }
 
         addDefaultSchemas(consumer);
@@ -399,6 +411,6 @@ public class NetconfDeviceSimulator implements Closeable {
         nettyThreadgroup.shutdownGracefully();
         minaTimerExecutor.shutdownNow();
         nioExecutor.shutdownNow();
-        // close Everything
     }
+
 }
index e28d936f6df34644ab5469c552e887314803a59a..36e336ad69435fc3b05d283f0d2369578ed59eef 100644 (file)
@@ -32,6 +32,8 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import net.sourceforge.argparse4j.inf.ArgumentParser;
 import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import org.opendaylight.netconf.test.tool.config.Configuration;
+import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -60,9 +62,10 @@ public class ScaleUtil {
         while (true) {
             root.warn("Starting scale test with {} devices", params.deviceCount);
             final ScheduledFuture timeoutGuardFuture = EXECUTOR.schedule(new TimeoutGuard(), TIMEOUT, TimeUnit.MINUTES);
-            final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(params.threadAmount);
+            final Configuration configuration = new ConfigurationBuilder().from(params).build();
+            final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(configuration);
             try {
-                final List<Integer> openDevices = netconfDeviceSimulator.start(params);
+                final List<Integer> openDevices = netconfDeviceSimulator.start();
                 if (openDevices.size() == 0) {
                     root.error("Failed to start any simulated devices, exiting...");
                     System.exit(1);
index b2c6ca0c319ba6f4973783cdb84e69ac8a231d11..15fd535de8c3d0eadf876935720884f2dbd6bf0b 100644 (file)
@@ -8,19 +8,23 @@
 
 package org.opendaylight.netconf.test.tool;
 
-public class TestToolUtils {
+import java.io.InputStream;
+
+public final class TestToolUtils {
 
     public static String getMac(long mac) {
         final StringBuilder builder = new StringBuilder(Long.toString(mac, 16));
-
         for (int i = builder.length(); i < 12; i++) {
             builder.insert(0, "0");
         }
-
         for (int j = builder.length() - 2; j >= 2; j -= 2) {
             builder.insert(j, ":");
         }
-
         return builder.toString();
     }
+
+    public static InputStream getDataAsStream(final String path) {
+        return TestToolUtils.class.getClassLoader().getResourceAsStream(path);
+    }
+
 }
index ecd9c1b5a61b6a78fa0f8b314605ef85f7448c5d..775aa7670b0a55ac6eb222102a346ea79655657f 100644 (file)
@@ -90,10 +90,8 @@ public class TesttoolParameters {
     @Arg(dest = "time-out")
     public long timeOut;
     private InputStream stream;
-
     @Arg(dest = "ip")
     public String ip;
-
     @Arg(dest = "thread-pool-size")
     public int threadPoolSize;
     @Arg(dest = "rpc-config")
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/Configuration.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/Configuration.java
new file mode 100644 (file)
index 0000000..c57f158
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * 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.netconf.test.tool.config;
+
+import com.google.common.collect.ImmutableSet;
+import java.io.File;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.test.tool.rpchandler.RpcHandler;
+import org.opendaylight.netconf.test.tool.rpchandler.RpcHandlerDefault;
+
+
+public class Configuration {
+
+    public static final Set<String> DEFAULT_BASE_CAPABILITIES_EXI = ImmutableSet.of(
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1,
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0
+    );
+
+    public static final Set<String> DEFAULT_BASE_CAPABILITIES = ImmutableSet.of(
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0,
+            XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1
+    );
+
+    private int generateConfigsTimeout = (int) TimeUnit.MINUTES.toMillis(30);
+    private int threadPoolSize = 8;
+    private int startingPort = 17830;
+    private int deviceCount = 1;
+    private boolean ssh = true;
+    private String ip = "0.0.0.0";
+
+    private Set<String> models;
+    private Set<String> capabilities = DEFAULT_BASE_CAPABILITIES_EXI;
+    private RpcHandler rpcHandler = new RpcHandlerDefault();
+
+    @Deprecated
+    private boolean mdSal = false;
+
+    @Deprecated
+    private File rpcConfigFile;
+
+    @Deprecated
+    private File notificationFile;
+
+    @Deprecated
+    private File initialConfigXMLFile;
+
+    @Deprecated
+    private File schemasDir;
+
+    public Configuration() {
+    }
+
+    public int getThreadPoolSize() {
+        return threadPoolSize;
+    }
+
+    public void setThreadPoolSize(int threadPoolSize) {
+        this.threadPoolSize = threadPoolSize;
+    }
+
+    public int getStartingPort() {
+        return startingPort;
+    }
+
+    public void setStartingPort(int startingPort) {
+        this.startingPort = startingPort;
+    }
+
+    public int getDeviceCount() {
+        return deviceCount;
+    }
+
+    public void setDeviceCount(int deviceCount) {
+        this.deviceCount = deviceCount;
+    }
+
+    public int getGenerateConfigsTimeout() {
+        return generateConfigsTimeout;
+    }
+
+    public void setGenerateConfigsTimeout(int generateConfigsTimeout) {
+        this.generateConfigsTimeout = generateConfigsTimeout;
+    }
+
+    public boolean isSsh() {
+        return ssh;
+    }
+
+    public void setSsh(boolean ssh) {
+        this.ssh = ssh;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public Set<String> getModels() {
+        return models;
+    }
+
+    public void setModels(Set<String> models) {
+        this.models = models;
+    }
+
+    public Set<String> getCapabilities() {
+        return capabilities;
+    }
+
+    public void setCapabilities(Set<String> capabilities) {
+        this.capabilities = capabilities;
+    }
+
+    public RpcHandler getRpcHandler() {
+        return rpcHandler;
+    }
+
+    public void setRpcHandler(RpcHandler rpcHandler) {
+        this.rpcHandler = rpcHandler;
+    }
+
+    @Deprecated
+    public boolean isMdSal() {
+        return mdSal;
+    }
+
+    @Deprecated
+    public void setMdSal(boolean mdSal) {
+        this.mdSal = mdSal;
+    }
+
+    @Deprecated
+    public File getRpcConfigFile() {
+        return rpcConfigFile;
+    }
+
+    @Deprecated
+    public void setRpcConfigFile(File rpcConfigFile) {
+        this.rpcConfigFile = rpcConfigFile;
+    }
+
+    @Deprecated
+    public File getNotificationFile() {
+        return notificationFile;
+    }
+
+    @Deprecated
+    public void setNotificationFile(File notificationFile) {
+        this.notificationFile = notificationFile;
+    }
+
+    @Deprecated
+    public File getInitialConfigXMLFile() {
+        return initialConfigXMLFile;
+    }
+
+    @Deprecated
+    public void setInitialConfigXMLFile(File initialConfigXMLFile) {
+        this.initialConfigXMLFile = initialConfigXMLFile;
+    }
+
+    @Deprecated
+    public boolean isXmlConfigurationProvided() {
+        return initialConfigXMLFile != null && notificationFile != null;
+    }
+
+    @Deprecated
+    public File getSchemasDir() {
+        return schemasDir;
+    }
+
+    @Deprecated
+    public void setSchemasDir(File schemasDir) {
+        this.schemasDir = schemasDir;
+    }
+
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/ConfigurationBuilder.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/config/ConfigurationBuilder.java
new file mode 100644 (file)
index 0000000..2ed4aa2
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * 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.netconf.test.tool.config;
+
+import java.io.File;
+import java.util.Set;
+import org.opendaylight.netconf.test.tool.TesttoolParameters;
+import org.opendaylight.netconf.test.tool.rpchandler.RpcHandler;
+
+public class ConfigurationBuilder {
+
+    private Configuration configuration;
+
+    public ConfigurationBuilder() {
+        this.configuration = new Configuration();
+    }
+
+    public ConfigurationBuilder setThreadPoolSize(int threadPoolSize) {
+        this.configuration.setThreadPoolSize(threadPoolSize);
+        return this;
+    }
+
+    public ConfigurationBuilder setGenerateConfigsTimeout(int generateConfigsTimeout) {
+        this.configuration.setGenerateConfigsTimeout(generateConfigsTimeout);
+        return this;
+    }
+
+    public ConfigurationBuilder setModels(Set<String> models) {
+        this.configuration.setModels(models);
+        return this;
+    }
+
+    public ConfigurationBuilder setCapabilities(Set<String> capabilities) {
+        this.configuration.setCapabilities(capabilities);
+        return this;
+    }
+
+    public ConfigurationBuilder setStartingPort(int startingPort) {
+        this.configuration.setStartingPort(startingPort);
+        return this;
+    }
+
+    public ConfigurationBuilder setDeviceCount(int deviceCount) {
+        this.configuration.setDeviceCount(deviceCount);
+        return this;
+    }
+
+    public ConfigurationBuilder setSsh(boolean ssh) {
+        this.configuration.setSsh(ssh);
+        return this;
+    }
+
+    public ConfigurationBuilder setIp(String ip) {
+        this.configuration.setIp(ip);
+        return this;
+    }
+
+    public ConfigurationBuilder setRpcMapping(RpcHandler rpcHandler) {
+        this.configuration.setRpcHandler(rpcHandler);
+        return this;
+    }
+
+    @Deprecated
+    public ConfigurationBuilder setMdSal(boolean mdSal) {
+        this.configuration.setMdSal(mdSal);
+        return this;
+    }
+
+    @Deprecated
+    public ConfigurationBuilder setRpcConfigFile(File rpcConfigFile) {
+        this.configuration.setRpcConfigFile(rpcConfigFile);
+        return this;
+    }
+
+    @Deprecated
+    public ConfigurationBuilder setInitialConfigXMLFile(File initialConfigXMLFile) {
+        this.configuration.setInitialConfigXMLFile(initialConfigXMLFile);
+        return this;
+    }
+
+    @Deprecated
+    public ConfigurationBuilder setNotificationFile(File notificationFile) {
+        this.configuration.setNotificationFile(notificationFile);
+        return this;
+    }
+
+    public ConfigurationBuilder from(Configuration configuration) {
+        this.configuration.setThreadPoolSize(configuration.getThreadPoolSize());
+        this.configuration.setGenerateConfigsTimeout(configuration.getGenerateConfigsTimeout());
+        this.configuration.setModels(configuration.getModels());
+        this.configuration.setCapabilities(configuration.getCapabilities());
+        this.configuration.setStartingPort(configuration.getStartingPort());
+        this.configuration.setDeviceCount(configuration.getDeviceCount());
+        this.configuration.setSsh(configuration.isSsh());
+        this.configuration.setIp(configuration.getIp());
+        this.configuration.setRpcHandler(configuration.getRpcHandler());
+        this.configuration.setMdSal(configuration.isMdSal());
+        this.configuration.setRpcConfigFile(configuration.getRpcConfigFile());
+        this.configuration.setInitialConfigXMLFile(configuration.getInitialConfigXMLFile());
+        this.configuration.setNotificationFile(configuration.getNotificationFile());
+        this.configuration.setSchemasDir(configuration.getSchemasDir());
+        return this;
+    }
+
+    public ConfigurationBuilder from(TesttoolParameters testtoolParameters) {
+        this.configuration.setGenerateConfigsTimeout(testtoolParameters.generateConfigsTimeout);
+        this.configuration.setStartingPort(testtoolParameters.startingPort);
+        this.configuration.setDeviceCount(testtoolParameters.deviceCount);
+        this.configuration.setSsh(testtoolParameters.ssh);
+        this.configuration.setIp(testtoolParameters.ip);
+        this.configuration.setMdSal(testtoolParameters.mdSal);
+        this.configuration.setRpcConfigFile(testtoolParameters.rpcConfig);
+        this.configuration.setInitialConfigXMLFile(testtoolParameters.initialConfigXMLFile);
+        this.configuration.setNotificationFile(testtoolParameters.notificationFile);
+        this.configuration.setSchemasDir(testtoolParameters.schemasDir);
+        return this;
+    }
+
+    public Configuration build() {
+        return configuration;
+    }
+
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/operations/OperationsProvider.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/operations/OperationsProvider.java
new file mode 100644 (file)
index 0000000..de05df7
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * 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.netconf.test.tool.operations;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+import java.util.Collections;
+import java.util.Set;
+import org.opendaylight.controller.config.util.capability.Capability;
+import org.opendaylight.netconf.api.monitoring.CapabilityListener;
+import org.opendaylight.netconf.impl.SessionIdProvider;
+import org.opendaylight.netconf.mapping.api.NetconfOperation;
+import org.opendaylight.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
+import org.opendaylight.netconf.test.tool.rpc.DataList;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedCommit;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedCreateSubscription;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedDiscardChanges;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedEditConfig;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedGet;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedGetConfig;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedLock;
+import org.opendaylight.netconf.test.tool.rpc.SimulatedUnLock;
+
+
+public class OperationsProvider implements NetconfOperationServiceFactory {
+    private final Set<Capability> caps;
+    private final SimulatedOperationService simulatedOperationService;
+
+    public OperationsProvider(final SessionIdProvider idProvider,
+                       final Set<Capability> caps) {
+        this.caps = caps;
+        simulatedOperationService = new SimulatedOperationService(
+            idProvider.getCurrentSessionId());
+    }
+
+    @Override
+    public Set<Capability> getCapabilities() {
+        return caps;
+    }
+
+    @Override
+    public AutoCloseable registerCapabilityListener(
+            final CapabilityListener listener) {
+        listener.onCapabilitiesChanged(caps, Collections.<Capability>emptySet());
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+            }
+        };
+    }
+
+    @Override
+    public NetconfOperationService createService(
+            final String netconfSessionIdForReporting) {
+        return simulatedOperationService;
+    }
+
+    static class SimulatedOperationService implements NetconfOperationService {
+        private final long currentSessionId;
+
+        SimulatedOperationService(final long currentSessionId) {
+            this.currentSessionId = currentSessionId;
+        }
+
+        @Override
+        public Set<NetconfOperation> getNetconfOperations() {
+            final DataList storage = new DataList();
+            final SimulatedGet sGet = new SimulatedGet(String.valueOf(currentSessionId), storage);
+            final SimulatedEditConfig sEditConfig = new SimulatedEditConfig(String.valueOf(currentSessionId), storage);
+            final SimulatedGetConfig sGetConfig = new SimulatedGetConfig(
+                String.valueOf(currentSessionId), storage, Optional.absent());
+            final SimulatedCommit sCommit = new SimulatedCommit(String.valueOf(currentSessionId));
+            final SimulatedLock sLock = new SimulatedLock(String.valueOf(currentSessionId));
+            final SimulatedUnLock sUnlock = new SimulatedUnLock(String.valueOf(currentSessionId));
+            final SimulatedCreateSubscription sCreateSubs = new SimulatedCreateSubscription(
+                    String.valueOf(currentSessionId), Optional.absent());
+            final SimulatedDiscardChanges sDiscardChanges = new SimulatedDiscardChanges(
+                String.valueOf(currentSessionId));
+            return Sets.newHashSet(
+                sGet, sGetConfig, sEditConfig, sCommit, sLock, sUnlock, sCreateSubs, sDiscardChanges);
+        }
+
+        @Override
+        public void close() {
+        }
+
+    }
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandler.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandler.java
new file mode 100644 (file)
index 0000000..ec0105b
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.test.tool.rpchandler;
+
+import java.util.Optional;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.w3c.dom.Document;
+
+public interface RpcHandler {
+
+    Optional<Document> getResponse(XmlElement rpcElement);
+
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandlerDefault.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/RpcHandlerDefault.java
new file mode 100644 (file)
index 0000000..5a84ea6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.test.tool.rpchandler;
+
+import java.util.Optional;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+public class RpcHandlerDefault implements RpcHandler {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RpcHandlerDefault.class);
+
+    @Override
+    public Optional<Document> getResponse(XmlElement rpcElement) {
+        LOG.info("getResponse: {}", rpcElement.toString());
+        return null;
+    }
+
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableOperationRpcProvider.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableOperationRpcProvider.java
new file mode 100644 (file)
index 0000000..66199d9
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 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.test.tool.rpchandler;
+
+import java.util.Collections;
+import java.util.Set;
+import org.opendaylight.controller.config.util.capability.Capability;
+import org.opendaylight.netconf.api.monitoring.CapabilityListener;
+import org.opendaylight.netconf.mapping.api.NetconfOperation;
+import org.opendaylight.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
+
+public class SettableOperationRpcProvider implements NetconfOperationServiceFactory {
+
+    private final RpcHandler rpcHandler;
+
+    public SettableOperationRpcProvider(RpcHandler rpcHandler) {
+        this.rpcHandler = rpcHandler;
+    }
+
+    @Override
+    public Set<Capability> getCapabilities() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
+        return () -> {
+            //no op
+        };
+    }
+
+    @Override
+    public NetconfOperationService createService(final String netconfSessionIdForReporting) {
+        return new SettableOperationService(rpcHandler);
+    }
+
+    private static class SettableOperationService implements NetconfOperationService {
+
+        private final SettableRpc rpc;
+
+        private SettableOperationService(RpcHandler rpcHandler) {
+            this.rpc = new SettableRpc(rpcHandler);
+        }
+
+        @Override
+        public Set<NetconfOperation> getNetconfOperations() {
+            return Collections.singleton(rpc);
+        }
+
+        @Override
+        public void close() {
+            // no op
+        }
+    }
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/rpchandler/SettableRpc.java
new file mode 100644 (file)
index 0000000..1f2b97d
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016 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.test.tool.rpchandler;
+
+import java.util.Optional;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.mapping.api.HandlingPriority;
+import org.opendaylight.netconf.mapping.api.NetconfOperation;
+import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
+import org.w3c.dom.Document;
+
+/**
+ * {@link NetconfOperation} implementation. It can be configured to intercept rpcs with defined input
+ * and reply with defined output. If input isn't defined, rpc handling is delegated to the subsequent
+ * {@link NetconfOperation} which is able to handle it.
+ */
+class SettableRpc implements NetconfOperation {
+
+    private final RpcHandler rpcHandler;
+
+    SettableRpc(RpcHandler rpcHandler) {
+        this.rpcHandler = rpcHandler;
+    }
+
+    @Override
+    public HandlingPriority canHandle(final Document message) throws DocumentedException {
+        return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY.increasePriority(1000);
+    }
+
+    @Override
+    public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation)
+            throws DocumentedException {
+        final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
+        final XmlElement rpcElement = requestElement.getOnlyChildElement();
+        final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
+        final Optional<Document> response = rpcHandler.getResponse(rpcElement);
+        if (response.isPresent()) {
+            final Document document = response.get();
+            checkForError(document);
+            document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
+            return document;
+        } else if (subsequentOperation.isExecutionTermination()) {
+            throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage),
+                    DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED,
+                    DocumentedException.ErrorSeverity.ERROR);
+        } else {
+            return subsequentOperation.execute(requestMessage);
+        }
+    }
+
+    private void checkForError(final Document document) throws DocumentedException {
+        final XmlElement rpcReply = XmlElement.fromDomDocument(document);
+        if (rpcReply.getOnlyChildElementOptionally("rpc-error").isPresent()) {
+            throw DocumentedException.fromXMLDocument(document);
+        }
+    }
+
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/ModelData.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/ModelData.java
new file mode 100644 (file)
index 0000000..ae431dc
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.netconf.test.tool.schemacache;
+
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+
+public class ModelData {
+
+    private SourceIdentifier id;
+    private String path;
+
+    public ModelData(SourceIdentifier id, String path) {
+        this.id = id;
+        this.path = path;
+    }
+
+    public SourceIdentifier getId() {
+        return id;
+    }
+
+    public String getPath() {
+        return path;
+    }
+}
diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/SchemaSourceCache.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/schemacache/SchemaSourceCache.java
new file mode 100644 (file)
index 0000000..9ece5a9
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * 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.netconf.test.tool.schemacache;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.opendaylight.netconf.test.tool.TestToolUtils;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
+import org.opendaylight.yangtools.yang.model.repo.util.AbstractSchemaSourceCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Cache implementation that stores schemas in form of files under provided folder.
+ */
+public final class SchemaSourceCache<T extends SchemaSourceRepresentation>
+        extends AbstractSchemaSourceCache<T> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(SchemaSourceCache.class);
+
+    public static final Pattern CACHED_FILE_PATTERN =
+            Pattern.compile(
+                    ".*/(?<moduleName>[^@]+)" + "(@(?<revision>" + SourceIdentifier.REVISION_PATTERN + "))?.yang");
+
+    private final Class<T> representation;
+    private final Set<String> modelList;
+    private Map<String, ModelData> cachedSchemas;
+
+    public SchemaSourceCache(
+            final SchemaSourceRegistry consumer, final Class<T> representation, final Set<String> modelList) {
+        super(consumer, representation, Costs.LOCAL_IO);
+        this.representation = representation;
+        this.modelList = Preconditions.checkNotNull(modelList);
+        init();
+    }
+
+    /**
+     * Restore cache state.
+     */
+    private void init() {
+        cachedSchemas = new HashMap<>();
+        for (String modelPath: modelList) {
+            Optional<SourceIdentifier> sourceIdentifierOptional = getSourceIdentifier(modelPath);
+            if (sourceIdentifierOptional.isPresent()) {
+                SourceIdentifier sourceIdentifier = sourceIdentifierOptional.get();
+                cachedSchemas.put(sourceIdentifier.toYangFilename(), new ModelData(sourceIdentifier, modelPath));
+            } else {
+                LOG.debug("Skipping caching model {}, cannot restore source identifier from model path,"
+                        + " does not match {}", modelPath, CACHED_FILE_PATTERN);
+            }
+        }
+        for (final ModelData cachedSchema : cachedSchemas.values()) {
+            register(cachedSchema.getId());
+        }
+    }
+
+    @Override
+    public synchronized CheckedFuture<? extends T, SchemaSourceException> getSource(
+            final SourceIdentifier sourceIdentifier) {
+        ModelData modelData = cachedSchemas.get(sourceIdentifier.toYangFilename());
+        if (modelData != null) {
+            final SchemaSourceRepresentation restored = restoreAsType(modelData.getId(), modelData.getPath());
+            return Futures.immediateCheckedFuture(representation.cast(restored));
+        } else {
+            LOG.debug("Source {} not found in cache as {}", sourceIdentifier);
+            return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found",
+                    sourceIdentifier));
+        }
+    }
+
+    @Override
+    protected synchronized void offer(final T source) {
+        LOG.trace("Source {} offered to cache", source.getIdentifier());
+    }
+
+    private YangTextSchemaSource restoreAsType(final SourceIdentifier sourceIdentifier, final String cachedSource) {
+        return new YangTextSchemaSource(sourceIdentifier) {
+
+            @Override
+            protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+                return toStringHelper;
+            }
+
+            @Override
+            public InputStream openStream() throws IOException {
+                return TestToolUtils.getDataAsStream(cachedSource);
+            }
+        };
+    }
+
+    private static Optional<SourceIdentifier> getSourceIdentifier(final String fileName) {
+        final Matcher matcher = CACHED_FILE_PATTERN.matcher(fileName);
+        if (matcher.matches()) {
+            final String moduleName = matcher.group("moduleName");
+            final String revision = matcher.group("revision");
+            return Optional.of(RevisionSourceIdentifier.create(moduleName, Optional.fromNullable(revision)));
+        }
+        return Optional.absent();
+    }
+
+}
index f5a648a91f86d0b7d464511d5f14a719210ce52e..df88860c1f7e757ce548c2f0bb171b84a4c661e2 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
@@ -145,7 +146,7 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener {
             public void onFailure(final Throwable throwable) {
                 LOG.warn("Unable to update modules state", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
     @Override
@@ -174,7 +175,7 @@ public class YangLibProvider implements AutoCloseable, SchemaSourceListener {
             public void onFailure(final Throwable throwable) {
                 LOG.warn("Unable to update modules state", throwable);
             }
-        });
+        }, MoreExecutors.directExecutor());
     }
 
 
index a1765e56d822ba0f13ec02add02ff21586e16bb0..f36caa0d2dc46a965b1644b16f0359dc3f40627f 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.sal.restconf.impl;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.Collection;
@@ -59,7 +60,7 @@ final class BatchedExistenceCheck {
 
                     ret.complete(path, ReadFailedException.MAPPER.apply(e));
                 }
-            });
+            }, MoreExecutors.directExecutor());
         }
 
         return ret;
index d2fd19307991a4c3acc1c9ec6561fc9a32011396..e1178633136e8e90babd43e8d1ccb68946f6525e 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableList;
 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.MoreExecutors;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -462,7 +463,7 @@ public class BrokerFacade {
                         new RestconfError(ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, throwable.getMessage()))));
                 waiter.countDown();
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         waiter.await();
         return status.getStatus();