Merge "Revert "Fix bug 171. EchoReply payload must be the same as the correspoding...
authorGiovanni Meo <gmeo@cisco.com>
Fri, 29 Nov 2013 10:01:49 +0000 (10:01 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 29 Nov 2013 10:01:49 +0000 (10:01 +0000)
17 files changed:
.gitignore
opendaylight/commons/opendaylight/pom.xml
opendaylight/config/config-persister-api/src/main/java/org/opendaylight/controller/config/persist/api/storage/StorageAdapter.java
opendaylight/config/config-persister-file-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/FileStorageAdapter.java
opendaylight/distribution/opendaylight/src/main/resources/configuration/config.ini
opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml
opendaylight/md-sal/model/pom.xml
opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/NoOpStorageAdapter.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/PersisterImpl.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/PersisterImplTest.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/osgi/NetconfSSHActivator.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java

index bb3e26faf5ee24f0f3080cbd311a87c55f7430b2..18817e7c359dbfbe526b0f37e379d859f0dfc97b 100644 (file)
@@ -19,3 +19,4 @@ opendaylight/northbound/integrationtest/logs/*
 *.iws
 .idea
 xtend-gen
+classes
index 794986a7bb7b62fd0a755da2470f53297b3f521b..a652845770eb64009bf8fc79fc63356ce99a3e95 100644 (file)
                     </goals>
                   </pluginExecutionFilter>
                   <action>
-                    <ignore />
+                     <execute>
+                      <runOnIncremental>false</runOnIncremental>
+                     </execute>
                   </action>
                 </pluginExecution>
                 <pluginExecution>
index 9daf4a132502cb1c917b35065a2361fdcbeea552..50503c15cc02e6b384a5affd5dcab0e50d3e43c4 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.controller.config.persist.api.storage;
 
 import org.opendaylight.controller.config.persist.api.Persister;
-import org.osgi.framework.BundleContext;
 
 /**
  * Plugins for {@link org.opendaylight.controller.config.persist.api.Persister}
@@ -17,6 +16,20 @@ import org.osgi.framework.BundleContext;
  */
 public interface StorageAdapter extends Persister {
 
-    void setProperties(BundleContext bundleContext);
+    void setProperties(PropertiesProvider propertiesProvider);
+
+
+    public interface PropertiesProvider {
+        /**
+         * Get property value for given key. Implementation of this interface is allowed to prefix
+         * the key with a namespace.
+         */
+        String getProperty(String key);
+
+        /**
+         * @return prefix + key as used in getProperty method.
+         */
+        String getFullKeyForReporting(String key);
+    }
 
 }
index 775fb1f88192cb697b38e712716851c3a246e974..5098c6f352b515e43f0adba943aeef65575802be 100644 (file)
@@ -16,7 +16,6 @@ import com.google.common.collect.Sets;
 import com.google.common.io.Files;
 import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.controller.config.persist.api.storage.StorageAdapter;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -55,8 +54,8 @@ public class FileStorageAdapter implements StorageAdapter {
     private File storage;
 
     @Override
-    public void setProperties(BundleContext bundleContext) {
-        File storage = extractStorageFileFromProperties(bundleContext);
+    public void setProperties(PropertiesProvider propertiesProvider) {
+        File storage = extractStorageFileFromProperties(propertiesProvider);
         logger.debug("Using file {}", storage.getAbsolutePath());
         // Create file if it does not exist
         File parentFile = storage.getAbsoluteFile().getParentFile();
@@ -92,12 +91,11 @@ public class FileStorageAdapter implements StorageAdapter {
         numberOfStoredBackups = numberOfBackups;
     }
 
-    private static File extractStorageFileFromProperties(BundleContext bundleContext) {
-        String fileStorageProperty = bundleContext.getProperty(FILE_STORAGE_PROP);
-        Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + FILE_STORAGE_PROP
-                + " in received context :" + bundleContext);
+    private static File extractStorageFileFromProperties(PropertiesProvider propertiesProvider) {
+        String fileStorageProperty = propertiesProvider.getProperty(FILE_STORAGE_PROP);
+        Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + propertiesProvider.getFullKeyForReporting(FILE_STORAGE_PROP));
         File result = new File(fileStorageProperty);
-        String numberOfBAckupsAsString = bundleContext.getProperty(NUMBER_OF_BACKUPS);
+        String numberOfBAckupsAsString = propertiesProvider.getProperty(NUMBER_OF_BACKUPS);
         if (numberOfBAckupsAsString != null) {
             numberOfStoredBackups = Integer.valueOf(numberOfBAckupsAsString);
         } else {
index 00c46d9529ff0daaa4788b01d9607fcd4611cdd3..d9ff11ade7e074ba09af9f8c26b3edfb64e784d5 100644 (file)
@@ -20,10 +20,10 @@ netconf.tcp.port=8383
 
 netconf.ssh.address=0.0.0.0
 netconf.ssh.port=1830
-
 netconf.config.persister.storageAdapterClass=org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter
-fileStorage=configuration/controller.config
-numberOfBackups=1
+netconf.config.persister.fileStorage=configuration/controller.config
+netconf.config.persister.numberOfBackups=1
+
 yangstore.blacklist=.*controller.model.*
 
 # Set Default start level for framework
index 3ad0c61d4f66ffb8763354e65bc2d196d88929df..2815422274fad3c61cfa95ba724969eadf30d001 100644 (file)
@@ -36,7 +36,6 @@
   <!--  Base log level  -->
   <logger name="org.opendaylight" level="INFO"/>
 
-  <logger name="org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort" level="ERROR"/>
 
   <!-- Controller log level -->
   <logger name="org.opendaylight.controller" level="INFO"/>
index 34ad23844f363da800bc33a12b9dfee7eae045cb..2f3b7a036c6113b23d8020dd207c30ce490e6ab6 100644 (file)
@@ -40,6 +40,7 @@
                 <configuration>
                     <instructions>
                         <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+                        <Import-Package>*,org.opendaylight.yangtools.yang.binding.annotations</Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
index 0eace4daaca15973e76e056cb1b923627dfd51b6..608be10602283b0dd6126d6e58b2091ea0bfefc8 100644 (file)
@@ -41,7 +41,7 @@ public class TestHelper {
                 mavenBundle("org.opendaylight.bgpcep", "framework").versionAsInProject(), //
                 mavenBundle("org.opendaylight.bgpcep", "util").versionAsInProject(), //
                 mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
-                
+
                 mavenBundle(CONTROLLER, "config-api").versionAsInProject(), // //
                 mavenBundle(CONTROLLER, "config-manager").versionAsInProject(), // //
                 mavenBundle("commons-io", "commons-io").versionAsInProject(), //
@@ -54,30 +54,30 @@ public class TestHelper {
                 mavenBundle(CONTROLLER, "logback-config").versionAsInProject(), //
                 mavenBundle(CONTROLLER, "config-persister-api").versionAsInProject(), //
                 mavenBundle(CONTROLLER, "netconf-api").versionAsInProject(), //
-               
+
                 mavenBundle(CONTROLLER, "netconf-client").versionAsInProject(), //
                 mavenBundle(CONTROLLER, "netconf-util").versionAsInProject(), //
                 mavenBundle(CONTROLLER + ".thirdparty", "ganymed", "1.0-SNAPSHOT"), //
                 mavenBundle(CONTROLLER, "netconf-mapping-api").versionAsInProject(), //
 
                 mavenBundle(CONTROLLER, "config-persister-impl").versionAsInProject(), //
-                
+
                 mavenBundle("io.netty", "netty-handler").versionAsInProject(), //
                 mavenBundle("io.netty", "netty-codec").versionAsInProject(), //
                 mavenBundle("io.netty", "netty-buffer").versionAsInProject(), //
                 mavenBundle("io.netty", "netty-transport").versionAsInProject(), //
                 mavenBundle("io.netty", "netty-common").versionAsInProject(), //
-                
+
                 mavenBundle("org.opendaylight.controller.thirdparty", "exificient", "0.9.2-SNAPSHOT"), //
-                
+
                 mavenBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xerces", "2.11.0_1"),
                 mavenBundle("org.eclipse.birt.runtime.3_7_1", "org.apache.xml.resolver", "1.2.0"),
-                
+
                 mavenBundle(CONTROLLER, "config-netconf-connector").versionAsInProject(), //
                 mavenBundle(CONTROLLER, "netconf-impl").versionAsInProject(), //
-                
+
                 mavenBundle(CONTROLLER, "config-persister-file-adapter").versionAsInProject().noStart());
-            
+
     }
 
     public static Option bindingAwareSalBundles() {
@@ -114,8 +114,8 @@ public class TestHelper {
                 systemProperty("netconf.tcp.port").value("18383"), //
                 systemProperty("netconf.config.persister.storageAdapterClass").value(
                         "org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter"), //
-                systemProperty("fileStorage").value(PathUtils.getBaseDir() + "/src/test/resources/controller.config"), //
-                systemProperty("numberOfBackups").value("1") //
+                systemProperty("netconf.config.persister.fileStorage").value(PathUtils.getBaseDir() + "/src/test/resources/controller.config"), //
+                systemProperty("netconf.config.persister.numberOfBackups").value("1") //
                 //systemProperty("yangstore.blacklist").value(".*controller.model.*") //
 
         );
@@ -170,7 +170,7 @@ public class TestHelper {
                  * org/mockito/cglib/proxy/Factory have different Class objects
                  * for the type org/mockito/cglib/ proxy/Callback used in the
                  * signature
-                 * 
+                 *
                  * So we disable the bootdelegation. this property has no effect
                  * on the other OSGi implementation.
                  */
index 25d2ad6abd09943278d28262a7184649a0688f4f..747965c0645faeb3cb02914fa260867252da20e5 100644 (file)
@@ -93,6 +93,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
             registerToNetconf(maybeConfig.get().getCapabilities());
 
             final String configSnapshot = maybeConfig.get().getConfigSnapshot();
+            logger.trace("Pushing following xml to netconf {}", configSnapshot);
             try {
                 pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
             } catch (SAXException | IOException e) {
@@ -247,11 +248,14 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         return maybeConfigElement;
     }
 
-    private synchronized void pushLastConfig(Element persistedConfig) {
+    private synchronized void pushLastConfig(Element xmlToBePersisted) {
+        logger.info("Pushing last configuration to netconf");
         StringBuilder response = new StringBuilder("editConfig response = {");
 
-        Element configElement = persistedConfig;
-        NetconfMessage message = createEditConfigMessage(configElement, "/netconfOp/editConfig.xml");
+
+        NetconfMessage message = createEditConfigMessage(xmlToBePersisted, "/netconfOp/editConfig.xml");
+
+        // sending message to netconf
         NetconfMessage responseMessage = netconfClient.sendMessage(message);
 
         XmlElement element = XmlElement.fromDomDocument(responseMessage.getDocument());
@@ -271,7 +275,8 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         response.append("commit response = {");
         response.append(XmlUtil.toString(responseMessage.getDocument()));
         response.append("}");
-        logger.debug("Last configuration loaded successfully");
+        logger.info("Last configuration loaded successfully");
+        logger.trace("Detailed message {}", response);
     }
 
     private void checkIsOk(XmlElement element, NetconfMessage responseMessage) {
@@ -289,8 +294,8 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         }
     }
 
-    private NetconfMessage createEditConfigMessage(Element dataElement, String editConfigResourcename) {
-        try (InputStream stream = getClass().getResourceAsStream(editConfigResourcename)) {
+    private static NetconfMessage createEditConfigMessage(Element dataElement, String editConfigResourcename) {
+        try (InputStream stream = ConfigPersisterNotificationHandler.class.getResourceAsStream(editConfigResourcename)) {
             Preconditions.checkNotNull(stream, "Unable to load resource " + editConfigResourcename);
 
             Document doc = XmlUtil.readXmlToDocument(stream);
index cd604312f4d0318fa2f55ed637e00c01b392e206..305908ae8a79580733a99b71870bcc5f9c707cc4 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.netconf.persist.impl;
 
 import com.google.common.base.Optional;
 import org.opendaylight.controller.config.persist.api.storage.StorageAdapter;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -20,8 +19,8 @@ public class NoOpStorageAdapter implements StorageAdapter {
     private static final Logger logger = LoggerFactory.getLogger(NoOpStorageAdapter.class);
 
     @Override
-    public void setProperties(BundleContext bundleContext) {
-        logger.debug("setProperties called with {}", bundleContext);
+    public void setProperties(PropertiesProvider propertiesProvider) {
+        logger.debug("setProperties called with {}", propertiesProvider);
     }
 
     @Override
index e06968e86844f1e65148e1a9e06bc08092ff8d68..499e8b98796fd795a248da1ca7e925a418e49339 100644 (file)
@@ -12,7 +12,8 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import org.opendaylight.controller.config.persist.api.Persister;
 import org.opendaylight.controller.config.persist.api.storage.StorageAdapter;
-import org.osgi.framework.BundleContext;
+import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider;
+import org.opendaylight.controller.netconf.persist.impl.osgi.ConfigPersisterActivator;
 
 import java.io.IOException;
 
@@ -29,44 +30,38 @@ import java.io.IOException;
  */
 public final class PersisterImpl implements Persister {
 
-    public static final String STORAGE_ADAPTER_CLASS_PROP = "netconf.config.persister.storageAdapterClass";
+
     private final StorageAdapter storage;
 
     public PersisterImpl(StorageAdapter storage) {
         this.storage = storage;
     }
 
-    public static Optional<PersisterImpl> createFromProperties(BundleContext bundleContext) {
-        String storageAdapterClass = bundleContext.getProperty(STORAGE_ADAPTER_CLASS_PROP);
+    public static PersisterImpl createFromProperties(PropertiesProvider propertiesProvider) {
+        String storageAdapterClass = propertiesProvider.getProperty(ConfigPersisterActivator.STORAGE_ADAPTER_CLASS_PROP_SUFFIX);
         StorageAdapter storage;
         if (storageAdapterClass == null || storageAdapterClass.equals("")) {
-            return Optional.absent();
+            throw new IllegalStateException("No persister is defined in " +
+                    propertiesProvider.getFullKeyForReporting(ConfigPersisterActivator.STORAGE_ADAPTER_CLASS_PROP_SUFFIX)
+                    + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName()
+                    + " . Persister is not operational");
         }
 
         try {
-            storage = StorageAdapter.class.cast(resolveClass(storageAdapterClass, StorageAdapter.class).newInstance());
-            storage.setProperties(bundleContext);
+            Class<?> clazz = Class.forName(storageAdapterClass);
+            boolean implementsCorrectIfc = StorageAdapter.class.isAssignableFrom(clazz);
+            if (implementsCorrectIfc == false) {
+                throw new IllegalArgumentException("Storage adapter " + clazz + " does not implement " + StorageAdapter.class);
+            }
+            storage = StorageAdapter.class.cast(clazz.newInstance());
+
+            storage.setProperties(propertiesProvider);
 
         } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
             throw new IllegalArgumentException("Unable to instantiate storage adapter from " + storageAdapterClass, e);
         }
-        return Optional.of(new PersisterImpl(storage));
-    }
-
-    private static Class<?> resolveClass(String storageAdapterClass, Class<?> baseType) throws ClassNotFoundException {
-        Class<?> clazz = Class.forName(storageAdapterClass);
 
-        if (!isImplemented(baseType, clazz))
-            throw new IllegalArgumentException("Storage adapter " + clazz + " has to implement " + baseType);
-        return clazz;
-    }
-
-    private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) {
-        for (Class<?> iface : byClazz.getInterfaces()) {
-            if (iface.equals(expectedIface))
-                return true;
-        }
-        return false;
+        return new PersisterImpl(storage);
     }
 
     @Override
index ae6c95312c9143d29f384571ffe9182b227aa862..241830ddc33ebb74a4d95168887f48c225d77bc8 100644 (file)
@@ -8,12 +8,10 @@
 
 package org.opendaylight.controller.netconf.persist.impl.osgi;
 
-import com.google.common.base.Optional;
+import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider;
 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
-import org.opendaylight.controller.netconf.persist.impl.NoOpStorageAdapter;
 import org.opendaylight.controller.netconf.persist.impl.PersisterImpl;
 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -33,32 +31,33 @@ public class ConfigPersisterActivator implements BundleActivator {
 
     private Thread initializationThread;
 
+    private static final String NETCONF_CONFIG_PERSISTER_PREFIX = "netconf.config.persister.";
+    public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX =  "storageAdapterClass";
+
     @Override
-    public void start(BundleContext context) throws Exception {
-        logger.debug("ConfigPersister activator started");
-
-        Optional<PersisterImpl> maybePersister = PersisterImpl.createFromProperties(context);
-        if (maybePersister.isPresent() == false) {
-            throw new IllegalStateException("No persister is defined in " + PersisterImpl.STORAGE_ADAPTER_CLASS_PROP
-                    + " property. For noop persister use " + NoOpStorageAdapter.class.getCanonicalName()
-                    + " . Persister is not operational");
-        }
-
-        Optional<TLSConfiguration> maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(context);
-        Optional<InetSocketAddress> maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(context);
-
-        InetSocketAddress address;
-        if (maybeTLSConfiguration.isPresent()) {
-            throw new UnsupportedOperationException("TLS is currently not supported for persister");
-        } else if (maybeTCPAddress.isPresent()) {
-            address = maybeTCPAddress.get();
-        } else {
-            throw new IllegalStateException("Netconf is not configured, persister is not operational");
-        }
-
-        PersisterImpl persister = maybePersister.get();
+    public void start(final BundleContext context) throws Exception {
+        logger.debug("ConfigPersister starting");
+
+        PropertiesProvider propertiesProvider = new PropertiesProvider() {
+            @Override
+            public String getProperty(String key) {
+                return context.getProperty(getFullKeyForReporting(key));
+            }
+
+            @Override
+            public String getFullKeyForReporting(String key) {
+                return NETCONF_CONFIG_PERSISTER_PREFIX + key;
+            }
+        };
+
+        PersisterImpl persister = PersisterImpl.createFromProperties(propertiesProvider);
+
+        InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context,
+                "Netconf is not configured, persister is not operational");
         configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(persister, address,
                 platformMBeanServer);
+
+        // offload initialization to another thread in order to stop blocking activator
         Runnable initializationRunnable = new Runnable() {
             @Override
             public void run() {
index 44b3b610434038aba7cfb68a20c763e97f2f7cff..d88d9e5559d32bd1a74d0a73a69d370daf329ecd 100644 (file)
@@ -15,8 +15,9 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.config.persist.api.Persister;
 import org.opendaylight.controller.config.persist.api.storage.StorageAdapter;
+import org.opendaylight.controller.config.persist.api.storage.StorageAdapter.PropertiesProvider;
 import org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter;
-import org.osgi.framework.BundleContext;
+import org.opendaylight.controller.netconf.persist.impl.osgi.ConfigPersisterActivator;
 
 import java.io.File;
 import java.io.IOException;
@@ -27,6 +28,8 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.matchers.JUnitMatchers.containsString;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -34,19 +37,32 @@ import static org.mockito.Mockito.verify;
 
 public class PersisterImplTest {
     @Mock
-    BundleContext mockedContext;
+    TestingPropertiesProvider propertiesProvider;
+
+    class TestingPropertiesProvider implements PropertiesProvider {
+        @Override
+        public String getFullKeyForReporting(String key) {
+            return "prefix" + key;
+        }
+
+        @Override
+        public String getProperty(String key) {
+            throw new UnsupportedOperationException("should be mocked");
+        }
+    }
 
     @Before
     public void setUpMocks() {
         MockitoAnnotations.initMocks(this);
+        doCallRealMethod().when(propertiesProvider).getFullKeyForReporting(anyString());
     }
 
     @Test
     public void testFromProperties() throws Exception {
-        doReturn(MockAdapter.class.getName()).when(mockedContext).getProperty(
-                PersisterImpl.STORAGE_ADAPTER_CLASS_PROP);
+        doReturn(MockAdapter.class.getName()).when(propertiesProvider).getProperty(
+                ConfigPersisterActivator.STORAGE_ADAPTER_CLASS_PROP_SUFFIX);
 
-        PersisterImpl persisterImpl = PersisterImpl.createFromProperties(mockedContext).get();
+        PersisterImpl persisterImpl = PersisterImpl.createFromProperties(propertiesProvider);
         persisterImpl.persistConfig(null);
         persisterImpl.loadLastConfig();
         persisterImpl.persistConfig(null);
@@ -57,31 +73,33 @@ public class PersisterImplTest {
         assertEquals(1, MockAdapter.props);
     }
 
+
     @Test
     public void testFromProperties2() throws Exception {
-        mockedContext = mock(BundleContext.class);
-        doReturn(FileStorageAdapter.class.getName()).when(mockedContext).getProperty(
-                PersisterImpl.STORAGE_ADAPTER_CLASS_PROP);
+
+        doReturn(FileStorageAdapter.class.getName()).when(propertiesProvider).getProperty(
+                ConfigPersisterActivator.STORAGE_ADAPTER_CLASS_PROP_SUFFIX);
+
         doReturn("target" + File.separator + "generated-test-sources" + File.separator + "testFile").when(
-                mockedContext).getProperty(FileStorageAdapter.FILE_STORAGE_PROP);
-        doReturn("mockedContext").when(mockedContext).toString();
-        doReturn(null).when(mockedContext).getProperty("numberOfBackups");
+                propertiesProvider).getProperty(FileStorageAdapter.FILE_STORAGE_PROP);
+        doReturn("propertiesProvider").when(propertiesProvider).toString();
+        doReturn(null).when(propertiesProvider).getProperty("numberOfBackups");
 
-        PersisterImpl persisterImpl = PersisterImpl.createFromProperties(mockedContext).get();
+        PersisterImpl persisterImpl = PersisterImpl.createFromProperties(propertiesProvider);
         assertTrue(persisterImpl.getStorage() instanceof FileStorageAdapter);
     }
 
     @Test
     public void testFromProperties3() throws Exception {
-        mockedContext = mock(BundleContext.class);
-        doReturn(FileStorageAdapter.class.getName()).when(mockedContext).getProperty(
-                PersisterImpl.STORAGE_ADAPTER_CLASS_PROP);
+
+        doReturn(FileStorageAdapter.class.getName()).when(propertiesProvider).getProperty(
+                ConfigPersisterActivator.STORAGE_ADAPTER_CLASS_PROP_SUFFIX);
         doReturn("target" + File.separator + "generated-test-sources" + File.separator + "testFile").when(
-                mockedContext).getProperty(FileStorageAdapter.FILE_STORAGE_PROP);
-        doReturn("mockedContext").when(mockedContext).toString();
-        doReturn("0").when(mockedContext).getProperty("numberOfBackups");
+                propertiesProvider).getProperty(FileStorageAdapter.FILE_STORAGE_PROP);
+        doReturn("propertiesProvider").when(propertiesProvider).toString();
+        doReturn("0").when(propertiesProvider).getProperty("numberOfBackups");
         try {
-            PersisterImpl.createFromProperties(mockedContext).get();
+            PersisterImpl.createFromProperties(propertiesProvider);
             fail();
         } catch (RuntimeException e) {
             assertThat(
@@ -123,7 +141,7 @@ public class PersisterImplTest {
         static int props = 0;
 
         @Override
-        public void setProperties(BundleContext configProvider) {
+        public void setProperties(PropertiesProvider propertiesProvider) {
             props++;
         }
 
index 890bbe728804e469f0d2989253e6815ec1b85d06..b334c354fbd8749026e7a01447a775aee2d74c05 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFact
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.TLSConfiguration;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -30,9 +29,6 @@ public class NetconfImplActivator implements BundleActivator {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
 
-    private Optional<InetSocketAddress> maybeTCPAddress;
-    private Optional<TLSConfiguration> maybeTLSConfiguration;
-
     private NetconfOperationServiceFactoryTracker factoriesTracker;
     private DefaultCommitNotificationProducer commitNot;
     private NetconfServerDispatcher dispatch;
@@ -41,11 +37,8 @@ public class NetconfImplActivator implements BundleActivator {
 
     @Override
     public void start(final BundleContext context) throws Exception {
-        maybeTCPAddress = NetconfConfigUtil.extractTCPNetconfAddress(context);
-        maybeTLSConfiguration = NetconfConfigUtil.extractTLSConfiguration(context);
-        if (maybeTCPAddress.isPresent() == false && maybeTLSConfiguration.isPresent() == false) {
-            throw new IllegalStateException("TCP nor TLS is configured, netconf not available.");
-        }
+        InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, "TCP is not configured, netconf not available.");
+
         NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
         factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
         factoriesTracker.open();
@@ -62,26 +55,13 @@ public class NetconfImplActivator implements BundleActivator {
 
         eventLoopGroup = new NioEventLoopGroup();
 
-        if (maybeTCPAddress.isPresent()) {
-            Optional<SSLContext> maybeSSLContext = Optional.absent();
-            InetSocketAddress address = maybeTCPAddress.get();
-            NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                    maybeSSLContext, serverNegotiatorFactory, listenerFactory);
-            dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
-
-            logger.info("Starting TCP netconf server at {}", address);
-            dispatch.createServer(address);
-        }
-        if (maybeTLSConfiguration.isPresent()) {
-            Optional<SSLContext> maybeSSLContext = Optional.of(maybeTLSConfiguration.get().getSslContext());
-            InetSocketAddress address = maybeTLSConfiguration.get().getAddress();
-            NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
-                    maybeSSLContext, serverNegotiatorFactory, listenerFactory);
-            dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
-
-            logger.info("Starting TLS netconf server at {}", address);
-            dispatch.createServer(address);
-        }
+        NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
+                Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
+        dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
+
+        logger.info("Starting TCP netconf server at {}", address);
+        dispatch.createServer(address);
+
     }
 
     @Override
index e5b9fa3ffcd63404d6ec25264da45fcef7da581a..d08bb957e1cbd60aec752b1e9507870e3a28db03 100644 (file)
@@ -204,8 +204,8 @@ public class NetconfITTest extends AbstractConfigTest {
 
     @Test
     public void testTwoSessions() throws Exception {
-        try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 4000, clientDispatcher))  {
-            try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 4000, clientDispatcher))  {
+        try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 10000, clientDispatcher))  {
+            try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 10000, clientDispatcher))  {
             }
         }
     }
index 6626f47b0375e4a7a0e503f78cd862ab647f2f62..d2f6c8c81ce749a234d7ae2d433dad953e2e20c6 100644 (file)
@@ -37,10 +37,11 @@ public class NetconfSSHActivator implements BundleActivator{
         logger.trace("Starting netconf SSH  bridge.");
 
         Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context);
-        Optional<InetSocketAddress> tcpSocketAddressOptional = NetconfConfigUtil.extractTCPNetconfAddress(context);
+        InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,
+                "TCP is not configured, netconf ssh bridge is not available.");
 
-        if (sshSocketAddressOptional.isPresent() && tcpSocketAddressOptional.isPresent()){
-            server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddressOptional.get());
+        if (sshSocketAddressOptional.isPresent()){
+            server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress);
             Thread serverThread = new  Thread(server,"netconf SSH server thread");
             serverThread.setDaemon(true);
             serverThread.start();
index 8a0a9cd80e861510980c0fa6f77336c685e0911c..35e17a2a3e4564ffceac32158d00e5f7e6faba39 100644 (file)
@@ -35,8 +35,13 @@ public class NetconfConfigUtil {
     private static final String NETCONF_TLS_KEYSTORE_PROP = PREFIX_PROP + InfixProp.tls + ".keystore";
     private static final String NETCONF_TLS_KEYSTORE_PASSWORD_PROP = NETCONF_TLS_KEYSTORE_PROP + ".password";
 
-    public static Optional<InetSocketAddress> extractTCPNetconfAddress(BundleContext context) {
-        return extractSomeNetconfAddress(context, InfixProp.tcp);
+    public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound) {
+
+        Optional<InetSocketAddress> inetSocketAddressOptional = extractSomeNetconfAddress(context, InfixProp.tcp);
+        if (inetSocketAddressOptional.isPresent() == false) {
+            throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound);
+        }
+        return inetSocketAddressOptional.get();
     }
 
     public static Optional<InetSocketAddress> extractSSHNetconfAddress(BundleContext context) {