Fixed testool performance bottleneck due to testtool using NetconfMonitoring from... 87/16187/4
authorTomas Cere <tcere@cisco.com>
Mon, 9 Mar 2015 09:23:56 +0000 (10:23 +0100)
committerTomas Cere <tcere@cisco.com>
Tue, 10 Mar 2015 08:27:37 +0000 (09:27 +0100)
Added a dummy NetconfMonitoring implementation for testtool.

Change-Id: I4d2eaf955ccac78de135749bd8c2bda3e3d6f35b
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DummyMonitoringService.java [new file with mode: 0644]
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/FakeModuleBuilderCapability.java
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/ModuleBuilderCapability.java
opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java

diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DummyMonitoringService.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DummyMonitoringService.java
new file mode 100644 (file)
index 0000000..e96be6c
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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.controller.netconf.test.tool;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.opendaylight.controller.netconf.api.Capability;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
+import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Sessions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SessionsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema.Location;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema.Location.Enumeration;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
+
+public class DummyMonitoringService implements NetconfMonitoringService {
+
+    private static final Sessions EMPTY_SESSIONS = new SessionsBuilder().setSession(Collections.<Session>emptyList()).build();
+    private static final Function<Capability, Uri> CAPABILITY_URI_FUNCTION = new Function<Capability, Uri>() {
+        @Nullable
+        @Override
+        public Uri apply(Capability capability) {
+            return new Uri(capability.getCapabilityUri());
+        }
+    };
+
+    private static final Function<Capability, Schema> CAPABILITY_SCHEMA_FUNCTION = new Function<Capability, Schema>() {
+        @Nullable
+        @Override
+        public Schema apply(@Nullable Capability capability) {
+            return new SchemaBuilder()
+                    .setIdentifier(capability.getModuleName().get())
+                    .setNamespace(new Uri(capability.getModuleNamespace().get()))
+                    .setFormat(Yang.class)
+                    .setVersion(capability.getRevision().get())
+                    .setLocation(Collections.singletonList(new Location(Enumeration.NETCONF)))
+                    .setKey(new SchemaKey(Yang.class, capability.getModuleName().get(), capability.getRevision().get())).build();
+        }
+    };
+
+    private final Capabilities capabilities;
+    private final ArrayListMultimap<String, Capability> capabilityMultiMap;
+    private final Schemas schemas;
+
+    public DummyMonitoringService(Set<Capability> capabilities) {
+
+        this.capabilities = new CapabilitiesBuilder().setCapability(
+                Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_URI_FUNCTION))).build();
+
+        this.capabilityMultiMap = ArrayListMultimap.create();
+        for (Capability cap : capabilities) {
+            capabilityMultiMap.put(cap.getModuleName().get(), cap);
+        }
+
+        this.schemas = new SchemasBuilder().setSchema(Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_SCHEMA_FUNCTION))).build();
+    }
+
+    @Override
+    public Sessions getSessions() {
+        return EMPTY_SESSIONS;
+    }
+
+    @Override
+    public Schemas getSchemas() {
+        return schemas;
+    }
+
+    @Override
+    public String getSchemaForCapability(String moduleName, Optional<String> revision) {
+
+        for (Capability capability : capabilityMultiMap.get(moduleName)) {
+            if (capability.getRevision().get().equals(revision.get())) {
+                return capability.getCapabilitySchema().get();
+            }
+        }
+        throw new IllegalArgumentException("Module with name: " + moduleName + " and revision: " + revision + " does not exist");
+    }
+
+    @Override
+    public Capabilities getCapabilities() {
+        return capabilities;
+    }
+
+    @Override
+    public AutoCloseable registerListener(MonitoringListener listener) {
+        return null;
+    }
+
+    @Override
+    public void onCapabilitiesAdded(Set<Capability> addedCaps) {
+
+    }
+
+    @Override
+    public void onCapabilitiesRemoved(Set<Capability> removedCaps) {
+
+    }
+
+    @Override
+    public void onSessionUp(NetconfManagementSession session) {
+
+    }
+
+    @Override
+    public void onSessionDown(NetconfManagementSession session) {
+
+    }
+}
index 3aba6f8..5f8107c 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
  */
 public class FakeModuleBuilderCapability implements Capability{
     private static final Date NO_REVISION = new Date(0);
+    private static final List<String> NETCONF = Collections.singletonList("NETCONF");
     private final ModuleBuilder input;
     private final Optional<String> content;
 
@@ -68,6 +69,7 @@ public class FakeModuleBuilderCapability implements Capability{
 
     @Override
     public List<String> getLocation() {
-        return Collections.emptyList();
+        return NETCONF;
     }
+
 }
index 11af568..eb9d906 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
 
 final class ModuleBuilderCapability implements Capability {
     private static final Date NO_REVISION = new Date(0);
+    private static final List<String> NETCONF = Collections.singletonList("NETCONF");
     private final ModuleBuilder input;
     private final Optional<String> content;
 
@@ -60,6 +61,6 @@ final class ModuleBuilderCapability implements Capability {
 
     @Override
     public List<String> getLocation() {
-        return Collections.emptyList();
+        return NETCONF;
     }
 }
index 72a9da6..817b45f 100644 (file)
@@ -64,7 +64,6 @@ import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
@@ -142,13 +141,14 @@ public class NetconfDeviceSimulator implements Closeable {
 
         final SessionIdProvider idProvider = new SessionIdProvider();
 
-
         final AggregatedNetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = new AggregatedNetconfOperationServiceFactory();
         final SimulatedOperationProvider simulatedOperationProvider = new SimulatedOperationProvider(idProvider, capabilities, notificationsFile);
 
-        final NetconfMonitoringService monitoringService1 = new NetconfMonitoringServiceImpl(aggregatedNetconfOperationServiceFactory);
+        final NetconfMonitoringService monitoringService1 = new DummyMonitoringService(capabilities);
+
         final NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory monitoringService =
-                new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(new NetconfMonitoringOperationService(monitoringService1));
+                new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
+                        new NetconfMonitoringOperationService(monitoringService1));
         aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(simulatedOperationProvider);
         aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(monitoringService);
 

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.