Remove obsolete TLS netconf configuration. Prefix all ServiceAdaptor configurations with common namespace.
Change-Id: Ief5fc0a9b62bd9857f77e934d8097543c2fc7a65
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
*.iws
.idea
xtend-gen
+classes
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}
*/
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);
+ }
}
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;
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();
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 {
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
<!-- 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"/>
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(), //
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() {
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.*") //
);
* 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.
*/
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) {
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());
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) {
}
}
- 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);
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;
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
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;
*/
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
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;
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() {
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;
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;
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);
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(
static int props = 0;
@Override
- public void setProperties(BundleContext configProvider) {
+ public void setProperties(PropertiesProvider propertiesProvider) {
props++;
}
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;
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;
@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();
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
@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)) {
}
}
}
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();
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) {