Merge "Cleanup features a bit"
authorMaros Marsalek <mmarsale@cisco.com>
Sat, 9 Jan 2016 10:17:54 +0000 (10:17 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 9 Jan 2016 10:17:54 +0000 (10:17 +0000)
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.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/MdsalOperationProvider.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java
opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolNegotiationFactory.java [new file with mode: 0644]
opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java

index cd15779e1b7e5446ec23c02d7c109dc95c88f996..24ea8f655cb9e2428ef3a52854880ceded078a8b 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.Sets;
 import io.netty.channel.Channel;
 import io.netty.util.Timer;
 import io.netty.util.concurrent.Promise;
+import java.net.SocketAddress;
 import java.util.Set;
 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
@@ -107,18 +108,25 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
         }
 
         return new NetconfServerSessionNegotiator(proposal, promise, channel, timer,
-                getListener(Long.toString(sessionId)), connectionTimeoutMillis);
+                getListener(Long.toString(sessionId), channel.localAddress()), connectionTimeoutMillis);
     }
 
-    private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting) {
-        final NetconfOperationService service =
-                this.aggregatedOpService.createService(netconfSessionIdForReporting);
+    private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
+        final NetconfOperationService service = getOperationServiceForAddress(netconfSessionIdForReporting, socketAddress);
         final NetconfOperationRouter operationRouter =
                 new NetconfOperationRouterImpl(service, monitoringService, netconfSessionIdForReporting);
         return new NetconfServerSessionListener(operationRouter, monitoringService, service);
 
     }
 
+    protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
+        return this.aggregatedOpService.createService(netconfSessionIdForReporting);
+    }
+
+    protected final NetconfOperationServiceFactory getOperationServiceFactory() {
+        return aggregatedOpService;
+    }
+
     private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException {
         return NetconfHelloMessage.createServerHello(Sets.union(transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId);
     }
index 3677ba41e9f8033ffbf84755c1b964306e31c901..569f642130208795016994cd67f233b7b56f0c60 100644 (file)
@@ -128,7 +128,7 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
     private void scheduleKeepalive() {
         Preconditions.checkState(currentDeviceRpc != null);
         LOG.trace("{}: Scheduling next keepalive in {} {}", id, keepaliveDelaySeconds, TimeUnit.SECONDS);
-        currentKeepalive = executor.schedule(new Keepalive(), keepaliveDelaySeconds, TimeUnit.SECONDS);
+        currentKeepalive = executor.schedule(new Keepalive(currentKeepalive), keepaliveDelaySeconds, TimeUnit.SECONDS);
     }
 
     @Override
@@ -168,16 +168,21 @@ public final class KeepaliveSalFacade implements RemoteDeviceHandler<NetconfSess
      */
     private class Keepalive implements Runnable, FutureCallback<DOMRpcResult> {
 
+        private final ScheduledFuture<?> previousKeepalive;
+
+        public Keepalive(final ScheduledFuture<?> previousKeepalive) {
+            this.previousKeepalive = previousKeepalive;
+        }
+
         @Override
         public void run() {
             LOG.trace("{}: Invoking keepalive RPC", id);
 
             try {
-                if(!currentKeepalive.isDone()) {
+                if(previousKeepalive != null && !previousKeepalive.isDone()) {
                     onFailure(new IllegalStateException("Previous keepalive timed out"));
                 } else {
                     Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this);
-                    scheduleKeepalive();
                 }
             } catch (NullPointerException e) {
                 LOG.debug("{}: Skipping keepalive while reconnecting", id);
index 1bb2f7a732646d21e82a3663e1cf52344fdae444..2a6ba4301fe3e3827aac2ce4e0521959e0228469 100644 (file)
@@ -114,7 +114,7 @@ public class KeepaliveSalFacadeTest {
         verify(underlyingSalFacade).onDeviceConnected(
                 any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class));
 
-        verify(deviceRpc, timeout(15000).atLeast(5)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+        verify(deviceRpc, timeout(15000).times(5)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
     }
 
     @Test
index 3070e4919d15ba6700efc60584b11f05bd481a33..25ebc579d7182a49d97330aada5ba696cc338277 100644 (file)
@@ -66,14 +66,13 @@ class MdsalOperationProvider implements NetconfOperationServiceFactory {
             .getLogger(MdsalOperationProvider.class);
 
     private final Set<Capability> caps;
-    private final MdsalOperationService mdsalOperationService;
+    private final SchemaContext schemaContext;
 
     public MdsalOperationProvider(final SessionIdProvider idProvider,
                                   final Set<Capability> caps,
                                   final SchemaContext schemaContext) {
         this.caps = caps;
-        mdsalOperationService = new MdsalOperationService(
-                idProvider.getCurrentSessionId(), schemaContext, caps);
+        this.schemaContext = schemaContext;
     }
 
     @Override
@@ -94,13 +93,15 @@ class MdsalOperationProvider implements NetconfOperationServiceFactory {
 
     @Override
     public NetconfOperationService createService(String netconfSessionIdForReporting) {
-        return mdsalOperationService;
+        return new MdsalOperationService(Long.parseLong(netconfSessionIdForReporting), schemaContext, caps);
     }
 
     static class MdsalOperationService implements NetconfOperationService {
         private final long currentSessionId;
         private final SchemaContext schemaContext;
         private final Set<Capability> caps;
+        private final SchemaService schemaService;
+        private final DOMDataBroker dataBroker;
 
         public MdsalOperationService(final long currentSessionId,
                                      final SchemaContext schemaContext,
@@ -108,14 +109,15 @@ class MdsalOperationProvider implements NetconfOperationServiceFactory {
             this.currentSessionId = currentSessionId;
             this.schemaContext = schemaContext;
             this.caps = caps;
+            this.schemaService = createSchemaService();
+
+            this.dataBroker = createDataStore(schemaService);
+
         }
 
         @Override
         public Set<NetconfOperation> getNetconfOperations() {
-            final SchemaService schemaService = createSchemaService();
-
-            final DOMDataBroker db = createDataStore(schemaService);
-            TransactionProvider transactionProvider = new TransactionProvider(db, String.valueOf(currentSessionId));
+            TransactionProvider transactionProvider = new TransactionProvider(dataBroker, String.valueOf(currentSessionId));
             CurrentSchemaContext currentSchemaContext = new CurrentSchemaContext(schemaService);
 
             ContainerNode netconf = createNetconfState();
@@ -123,7 +125,7 @@ class MdsalOperationProvider implements NetconfOperationServiceFactory {
             YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().node(NetconfState.QNAME)
                     .build();
 
-            final DOMDataWriteTransaction tx = db.newWriteOnlyTransaction();
+            final DOMDataWriteTransaction tx = dataBroker.newWriteOnlyTransaction();
             tx.put(LogicalDatastoreType.OPERATIONAL, yangInstanceIdentifier, netconf);
 
             try {
index 97739e1614dd0cb8d27db203dc9e7b5f7fb07803..4572c09de76bd9e1cafd4cff46cdf8adcc04434d 100644 (file)
@@ -136,7 +136,7 @@ public class NetconfDeviceSimulator implements Closeable {
                 ? NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES
                 : Sets.newHashSet(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1);
 
-        final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
+        final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new TesttoolNegotiationFactory(
                 hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, generateConfigsTimeout, monitoringService1, serverCapabilities);
 
         final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer(
diff --git a/opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolNegotiationFactory.java b/opendaylight/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/TesttoolNegotiationFactory.java
new file mode 100644 (file)
index 0000000..d94c0ad
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import io.netty.util.Timer;
+import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
+import org.opendaylight.netconf.impl.SessionIdProvider;
+import org.opendaylight.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
+
+public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
+
+    private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
+
+    public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
+                                      final SessionIdProvider idProvider, final long connectionTimeoutMillis,
+                                      final NetconfMonitoringService monitoringService) {
+        super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService);
+    }
+
+    public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
+                                      final SessionIdProvider idProvider, final long connectionTimeoutMillis,
+                                      final NetconfMonitoringService monitoringService, final Set<String> baseCapabilities) {
+        super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, baseCapabilities);
+    }
+
+    @Override
+    protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
+        if (cachedOperationServices.containsKey(socketAddress)) {
+            return cachedOperationServices.get(socketAddress);
+        } else {
+            final NetconfOperationService service = getOperationServiceFactory().createService(netconfSessionIdForReporting);
+            cachedOperationServices.put(socketAddress, service);
+            return service;
+        }
+    }
+}
index 5356e75e460eef46fefc2aee69a7240e4a270a66..bc2d23cd70f052cde95e2a304b40f1786a626b70 100644 (file)
@@ -717,14 +717,11 @@ public class RestconfImpl implements RestconfService {
          * document the behavior).
          */
         int tries = 2;
-        Status status = Status.NOT_MODIFIED;
         while(true) {
             try {
                 if (mountPoint != null) {
-                    status = broker.readConfigurationData(mountPoint, normalizedII) != null ? Status.OK : Status.CREATED;
                     broker.commitConfigurationDataPut(mountPoint, normalizedII, payload.getData()).checkedGet();
                 } else {
-                    status = broker.readConfigurationData(normalizedII) != null ? Status.OK : Status.CREATED;
                     broker.commitConfigurationDataPut(controllerContext.getGlobalSchema(), normalizedII, payload.getData()).checkedGet();
                 }
 
@@ -748,7 +745,7 @@ public class RestconfImpl implements RestconfService {
             }
         }
 
-        return Response.status(status).build();
+        return Response.status(Status.OK).build();
     }
 
     private static void validateTopLevelNodeName(final NormalizedNodeContext node,