Merge "Bug 4719 Shiro integration into restconf"
authorTony Tkacik <ttkacik@cisco.com>
Fri, 11 Dec 2015 13:18:31 +0000 (13:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 11 Dec 2015 13:18:31 +0000 (13:18 +0000)
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacade.java
opendaylight/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/KeepaliveSalFacadeTest.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/http/perf/Parameters.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/http/perf/PerfClientCallable.java

index e62089601b0ffc15026c3d17facb3a8ebafbb1f2..7512f2616b4eac6c44a905d2ea9b10c3a9703071 100644 (file)
@@ -72,7 +72,7 @@ public class NetconfImplActivator implements BundleActivator {
                     new ServiceTracker<>(context, NetconfNotificationCollector.class, new ServiceTrackerCustomizer<NetconfNotificationCollector, NetconfNotificationCollector>() {
                         @Override
                         public NetconfNotificationCollector addingService(ServiceReference<NetconfNotificationCollector> reference) {
-                            Preconditions.checkState(listenerReg != null, "Notification collector service was already added");
+                            Preconditions.checkState(listenerReg == null, "Notification collector service was already added");
                             listenerReg = context.getService(reference).registerBaseNotificationPublisher();
                             monitoringService.setNotificationPublisher(listenerReg);
                             return null;
index cadfc35050a765b20188d1af8e40869bd974af62..862b860eef38ab7e4e001428b220382595dc44b6 100644 (file)
@@ -185,8 +185,13 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
 
         @Override
         public void onSuccess(final DOMRpcResult result) {
-            LOG.debug("{}: Keepalive RPC successful with response: {}", id, result.getResult());
-            scheduleKeepalive();
+            if (result != null && result.getResult() != null) {
+                LOG.debug("{}: Keepalive RPC successful with response: {}", id, result.getResult());
+                scheduleKeepalive();
+            } else {
+                LOG.warn("{} Keepalive RPC returned null with response: {}. Reconnecting netconf session", id, result);
+                reconnect();
+            }
         }
 
         @Override
index b6ea4ddbe141cfd166d4371db79f9e3b4de5d6b0..5dda13a956ca5e9c4fe7a9ed02b988c3dce92e93 100644 (file)
@@ -98,10 +98,13 @@ public class KeepaliveSalFacadeTest {
         final DOMRpcResult result = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(
                 new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
 
-        final DOMRpcResult resultFail = new DefaultDOMRpcResult(mock(RpcError.class));
+        RpcError error = mock(RpcError.class);
+        doReturn("Failure").when(error).toString();
+
+        final DOMRpcResult resultFailWithResultAndError = new DefaultDOMRpcResult(mock(NormalizedNode.class), error);
 
         doReturn(Futures.immediateCheckedFuture(result))
-                .doReturn(Futures.immediateCheckedFuture(resultFail))
+                .doReturn(Futures.immediateCheckedFuture(resultFailWithResultAndError))
                 .doReturn(Futures.immediateFailedCheckedFuture(new IllegalStateException("illegal-state")))
                 .when(deviceRpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
 
@@ -121,7 +124,7 @@ public class KeepaliveSalFacadeTest {
 
         // Reconnect with same keepalive responses
         doReturn(Futures.immediateCheckedFuture(result))
-                .doReturn(Futures.immediateCheckedFuture(resultFail))
+                .doReturn(Futures.immediateCheckedFuture(resultFailWithResultAndError))
                 .doReturn(Futures.immediateFailedCheckedFuture(new IllegalStateException("illegal-state")))
                 .when(deviceRpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
 
@@ -131,6 +134,16 @@ public class KeepaliveSalFacadeTest {
         verify(listener, timeout(15000).times(2)).disconnect();
         // 6 attempts now total
         verify(deviceRpc, times(3 * 2)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+
+        final DOMRpcResult resultFailwithError = new DefaultDOMRpcResult(error);
+
+        doReturn(Futures.immediateCheckedFuture(resultFailwithError))
+                .when(deviceRpc).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+
+        keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
+
+        // 1 failed that results in disconnect, 3 total with previous fail
+        verify(listener, timeout(15000).times(3)).disconnect();
     }
 
     @Test
index 32bb6a36b983fdb43830c0017cbf6d4a74355d85..8ef49f3511a555073f421304ffb40c0dc2d9d51f 100644 (file)
@@ -13,6 +13,7 @@ import java.io.File;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import net.sourceforge.argparse4j.ArgumentParsers;
 import net.sourceforge.argparse4j.annotation.Arg;
 import net.sourceforge.argparse4j.inf.ArgumentParser;
@@ -49,6 +50,9 @@ public class Parameters {
     @Arg(dest = "throttle")
     public int throttle;
 
+    @Arg(dest = "auth")
+    public ArrayList<String> auth;
+
     static ArgumentParser getParser() {
         final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
 
@@ -113,6 +117,11 @@ public class Parameters {
                         "with mutltiple threads this gets divided among all threads")
                 .dest("throttle");
 
+        parser.addArgument("--auth")
+                .nargs(2)
+                .help("Username and password for HTTP basic authentication in order username password.")
+                .dest("auth");
+
         return parser;
     }
 
index e073fbcb2624d9e1cf9edbb413afd8fd319874c8..fed504abb0d212c0cce3cb911518270e0f503d6a 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.test.tool.client.http.perf;
 
 import com.ning.http.client.AsyncHttpClient;
 import com.ning.http.client.AsyncHttpClientConfig;
+import com.ning.http.client.Realm;
 import com.ning.http.client.Request;
 import java.util.ArrayList;
 import java.util.concurrent.Callable;
@@ -36,12 +37,22 @@ public class PerfClientCallable implements Callable<Void>{
                 .build());
         this.payloads = new ArrayList<>();
         for (DestToPayload payload : payloads) {
-            this.payloads.add(asyncHttpClient.preparePost(payload.getDestination())
+            AsyncHttpClient.BoundRequestBuilder requestBuilder = asyncHttpClient.preparePost(payload.getDestination())
                     .addHeader("content-type", "application/json")
                     .addHeader("Accept", "application/xml")
                     .setBody(payload.getPayload())
-                    .setRequestTimeout(Integer.MAX_VALUE)
-                    .build());
+                    .setRequestTimeout(Integer.MAX_VALUE);
+
+            if(params.auth != null) {
+                requestBuilder.setRealm(new Realm.RealmBuilder()
+                        .setScheme(Realm.AuthScheme.BASIC)
+                        .setPrincipal(params.auth.get(0))
+                        .setPassword(params.auth.get(1))
+                        .setUsePreemptiveAuth(true)
+                        .build());
+            }
+
+            this.payloads.add(requestBuilder.build());
         }
         executionStrategy = getExecutionStrategy();
     }