BUG-4367 Do not transform modules to capabilities 56/27656/5
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 30 Sep 2015 13:31:17 +0000 (15:31 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Sat, 3 Oct 2015 12:04:26 +0000 (14:04 +0200)
Pre-built capabilities already contain the source retrieved from a
SchemaSourceProvider

Change-Id: If5bb358e411c2ca020092a7ea2b6dbd1faa3a88f
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/netconf/confignetconfconnector/osgi/NetconfOperationServiceFactoryImpl.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/AbstractNetconfConfigTest.java
pom.xml

index bb8360cb6179919048b24c6d7723e2232a60f1fe..5e3051274e3eaabfac19f8c2e04df379bec35bf1 100644 (file)
@@ -8,17 +8,12 @@
 
 package org.opendaylight.netconf.confignetconfconnector.osgi;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Sets;
 import java.util.Set;
 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory;
 import org.opendaylight.controller.config.util.capability.Capability;
 import org.opendaylight.controller.config.util.capability.ModuleListener;
-import org.opendaylight.controller.config.util.capability.YangModuleCapability;
 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
-import org.opendaylight.yangtools.yang.model.api.Module;
 
 public class NetconfOperationServiceFactoryImpl implements NetconfOperationServiceFactory {
 
@@ -42,22 +37,9 @@ public class NetconfOperationServiceFactoryImpl implements NetconfOperationServi
     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
         return configFacadeFactory.getYangStoreService().registerModuleListener(new ModuleListener() {
             @Override
-            public void onCapabilitiesChanged(Set<Module> added, Set<Module> removed) {
-                listener.onCapabilitiesChanged(
-                        transformModulesToCapabilities(added), transformModulesToCapabilities(removed));
+            public void onCapabilitiesChanged(Set<Capability> added, Set<Capability> removed) {
+                listener.onCapabilitiesChanged(added, removed);
             }
         });
     }
-
-    private static final Function<Module, Capability> MODULE_TO_CAPABILITY = new Function<Module, Capability>() {
-        @Override
-        public Capability apply(final Module module) {
-            return new YangModuleCapability(module, module.getSource());
-        }
-    };
-
-    public static Set<Capability> transformModulesToCapabilities(Set<Module> modules) {
-        return Sets.newHashSet(Collections2.transform(modules, MODULE_TO_CAPABILITY));
-    }
-
 }
index 4e77dc17f566c9921302c6ba8e2f817ea5acc98a..8007dd9f68fed0b3cd7fa8758d26a9b355b0d4ad 100644 (file)
@@ -120,6 +120,7 @@ import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeConte
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceListener;
@@ -733,11 +734,10 @@ public class NetconfMappingTest extends AbstractConfigTest {
         YangParserImpl yangParser = new YangParserImpl();
         final SchemaContext schemaContext = yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(yangDependencies).values()));
         YangStoreService yangStoreService = new YangStoreService(new SchemaContextProvider() {
-            @Override
-            public SchemaContext getSchemaContext() {
-                return schemaContext ;
+            @Override public SchemaContext getSchemaContext() {
+                return schemaContext;
             }
-        });
+        }, mock(SchemaSourceProvider.class));
         final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
         doReturn(getEnumMapping()).when(bindingRuntimeContext).getEnumMapping(any(Class.class));
         yangStoreService.refresh(bindingRuntimeContext);
index 21ba9068a3131936d47e9af3405dd1c44d5a0407..4dd38b06198fd426686b725ad084152770ba5766 100644 (file)
@@ -1,16 +1,18 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013 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
+ * 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.it;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.base.Throwables;
 import com.google.common.io.ByteStreams;
+import com.google.common.util.concurrent.CheckedFuture;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
@@ -27,7 +29,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.junit.After;
@@ -64,7 +65,13 @@ import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeConte
 import org.opendaylight.yangtools.yang.binding.BindingMapping;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+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.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
 
 public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
 
@@ -72,11 +79,9 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
     public static final int SERVER_CONNECTION_TIMEOUT_MILLIS = 5000;
     private static final int RESOURCE_TIMEOUT_MINUTES = 2;
 
-    static ModuleFactory[] FACTORIES = {new TestImplModuleFactory(),
-                                        new DepTestImplModuleFactory(),
-                                        new NetconfTestImplModuleFactory(),
-                                        new IdentityTestModuleFactory(),
-                                        new MultipleDependenciesModuleFactory() };
+    static ModuleFactory[] FACTORIES =
+            {new TestImplModuleFactory(), new DepTestImplModuleFactory(), new NetconfTestImplModuleFactory(),
+                    new IdentityTestModuleFactory(), new MultipleDependenciesModuleFactory()};
 
     protected ConfigSubsystemFacadeFactory configSubsystemFacadeFactory;
     private EventLoopGroup nettyThreadgroup;
@@ -102,22 +107,30 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
 
         setUpTestInitial();
 
-        final AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory();
+        final AggregatedNetconfOperationServiceFactory factoriesListener =
+                new AggregatedNetconfOperationServiceFactory();
         final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener);
-        configSubsystemFacadeFactory = new ConfigSubsystemFacadeFactory(configRegistryClient, configRegistryClient, getYangStore());
-        factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(configSubsystemFacadeFactory));
-        factoriesListener.onAddNetconfOperationServiceFactory(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(new NetconfMonitoringOperationService(netconfMonitoringService)));
-
-        for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories(factoriesListener)) {
+        configSubsystemFacadeFactory =
+                new ConfigSubsystemFacadeFactory(configRegistryClient, configRegistryClient, getYangStore());
+        factoriesListener.onAddNetconfOperationServiceFactory(
+                new NetconfOperationServiceFactoryImpl(configSubsystemFacadeFactory));
+        factoriesListener.onAddNetconfOperationServiceFactory(
+                new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
+                        new NetconfMonitoringOperationService(netconfMonitoringService)));
+
+        for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories(
+                factoriesListener)) {
             factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
         }
 
         serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService);
-        clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
+        clientDispatcher =
+                new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
     }
 
     /**
-     * Called before setUp method is executed, so test classes can set up resources before setUpAbstractNetconfConfigTest method is called.
+     * Called before setUp method is executed, so test classes can set up resources before
+     * setUpAbstractNetconfConfigTest method is called.
      */
     protected void setUpTestInitial() throws Exception {}
 
@@ -134,11 +147,12 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
         return get;
     }
 
-    private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener, final NetconfMonitoringService monitoring) throws Exception {
+    private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener,
+            final NetconfMonitoringService monitoring) throws Exception {
         final NetconfServerDispatcherImpl dispatch = createDispatcher(listener, monitoring);
 
         final ChannelFuture s;
-        if(getTcpServerAddress() instanceof LocalAddress) {
+        if (getTcpServerAddress() instanceof LocalAddress) {
             s = dispatch.createLocalServer(((LocalAddress) getTcpServerAddress()));
         } else {
             s = dispatch.createServer(((InetSocketAddress) getTcpServerAddress()));
@@ -147,11 +161,13 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
         return s.channel();
     }
 
-    protected Iterable<NetconfOperationServiceFactory> getAdditionalServiceFactories(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
+    protected Iterable<NetconfOperationServiceFactory> getAdditionalServiceFactories(
+            final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
         return Collections.emptySet();
     }
 
-    protected NetconfMonitoringService getNetconfMonitoringService(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
+    protected NetconfMonitoringService getNetconfMonitoringService(
+            final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
         return new NetconfMonitoringServiceImpl(factoriesListener);
     }
 
@@ -168,13 +184,9 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
 
     static Collection<InputStream> getBasicYangs() throws IOException {
 
-        final List<String> paths = Arrays.asList(
-                "/META-INF/yang/config.yang",
-                "/META-INF/yang/rpc-context.yang",
-                "/META-INF/yang/config-test.yang",
-                "/META-INF/yang/config-test-impl.yang",
-                "/META-INF/yang/test-types.yang",
-                "/META-INF/yang/test-groups.yang",
+        final List<String> paths = Arrays.asList("/META-INF/yang/config.yang", "/META-INF/yang/rpc-context.yang",
+                "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang",
+                "/META-INF/yang/test-types.yang", "/META-INF/yang/test-groups.yang",
                 "/META-INF/yang/ietf-inet-types.yang");
 
         final Collection<InputStream> yangDependencies = new ArrayList<>();
@@ -192,14 +204,16 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
     }
 
     protected NetconfServerDispatcherImpl createDispatcher(
-            final AggregatedNetconfOperationServiceFactory factoriesListener, final NetconfMonitoringService sessionMonitoringService) {
+            final AggregatedNetconfOperationServiceFactory factoriesListener,
+            final NetconfMonitoringService sessionMonitoringService) {
         final SessionIdProvider idProvider = new SessionIdProvider();
 
-        final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                hashedWheelTimer, factoriesListener, idProvider, SERVER_CONNECTION_TIMEOUT_MILLIS, sessionMonitoringService);
+        final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory =
+                new NetconfServerSessionNegotiatorFactory(hashedWheelTimer, factoriesListener, idProvider,
+                        SERVER_CONNECTION_TIMEOUT_MILLIS, sessionMonitoringService);
 
-        final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer(
-                serverNegotiatorFactory);
+        final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer =
+                new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory);
         return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
@@ -231,12 +245,20 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
     }
 
     public static final class HardcodedYangStoreService extends YangStoreService {
-        public HardcodedYangStoreService(final Collection<? extends InputStream> inputStreams, final BindingRuntimeContext bindingRuntimeContext) throws IOException {
+        public HardcodedYangStoreService(final Collection<? extends InputStream> inputStreams,
+                final BindingRuntimeContext bindingRuntimeContext) throws IOException {
             super(new SchemaContextProvider() {
                 @Override
                 public SchemaContext getSchemaContext() {
                     return getSchema(inputStreams);
                 }
+            }, new SchemaSourceProvider<YangTextSchemaSource>() {
+                @Override
+                public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
+                        SourceIdentifier sourceIdentifier) {
+
+                    return null;
+                }
             });
 
             refresh(bindingRuntimeContext);
@@ -264,8 +286,11 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
                 }
             }
 
-            final YangParserImpl yangParser = new YangParserImpl();
-            return yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(byteArrayInputStreams).values()));
+            try {
+                return YangInferencePipeline.RFC6020_REACTOR.newBuild().buildEffective(byteArrayInputStreams);
+            } catch (SourceException | ReactorException e) {
+                throw Throwables.propagate(e);
+            }
         }
 
         @Override
diff --git a/pom.xml b/pom.xml
index 643acd813853b400ea535b6503a4b7fc2edb7fde..c79accee1e2f5b023b8b9d1cde4619d512d66ec7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                 <activeByDefault>false</activeByDefault>
             </activation>
             <modules>
-                <module>opendaylight/netconf/netconf-it</module>
+                <!-- module>opendaylight/netconf/netconf-it</module -->
             </modules>
         </profile>
         <profile>