Stop polluting log file with unnecessary 'Exception' messages by logging-bridge, print stack trace with exceptions using slf4j.
Increase connection timeout in sal-netconf-client from 5s to 20s.
Include label in NetconfClient exceptions.
Change-Id: If6819029fb79ea6ebead6b6745adf2c439d107da
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>commons.opendaylight</artifactId>
- <version>1.4.2-SNAPSHOT</version>
- <relativePath>../../commons/opendaylight</relativePath>
- </parent>
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
- <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
- <tag>HEAD</tag>
- </scm>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.2-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <scm>
+ <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+ <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+ <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+ <tag>HEAD</tag>
+ </scm>
- <artifactId>logging.bridge</artifactId>
- <version>0.4.2-SNAPSHOT</version>
- <packaging>bundle</packaging>
+ <artifactId>logging.bridge</artifactId>
+ <version>0.4.2-SNAPSHOT</version>
+ <packaging>bundle</packaging>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>equinoxSDK381</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${bundle.plugin.version}</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Import-Package>
- org.slf4j,
- org.osgi.framework,
- org.osgi.service.log
- </Import-Package>
- <Bundle-Activator>
- org.opendaylight.controller.logging.bridge.internal.Activator
- </Bundle-Activator>
- </instructions>
- <manifestLocation>${project.basedir}/META-INF</manifestLocation>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.slf4j,
+ org.osgi.framework,
+ org.osgi.service.log
+ </Import-Package>
+ <Bundle-Activator>
+ org.opendaylight.controller.logging.bridge.internal.Activator
+ </Bundle-Activator>
+ </instructions>
+ <manifestLocation>${project.basedir}/META-INF</manifestLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
if (this.logger != null) {
switch (entry.getLevel()) {
case LogService.LOG_DEBUG:
- this.logger.debug("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.debug("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_INFO:
- this.logger.info("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.info("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_WARNING:
- this.logger.warn("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.warn("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_ERROR:
- this.logger.error("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.error("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
}
--- /dev/null
+/*
+ * 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
+ */
+package org.opendaylight.controller.logging.bridge.internal;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class LogListenerImplTest {
+ private static final Logger logger = LoggerFactory.getLogger(LogListenerImplTest.class);
+
+ @Test
+ public void test() {
+ LogListenerImpl tested = new LogListenerImpl(logger);
+ tested.logged(getEntry("m1", null));
+ tested.logged(getEntry("m2", new RuntimeException()));
+ }
+
+ private LogEntry getEntry(final String message, final Exception e) {
+ return new LogEntry() {
+ @Override
+ public Bundle getBundle() {
+ Bundle mock = mock(Bundle.class);
+ doReturn(null).when(mock).getSymbolicName();
+ return mock;
+ }
+
+ @Override
+ public ServiceReference getServiceReference() {
+ return null;
+ }
+
+ @Override
+ public int getLevel() {
+ return LogService.LOG_INFO;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public Throwable getException() {
+ return e;
+ }
+
+ @Override
+ public long getTime() {
+ return 0;
+ }
+ };
+ }
+
+}
leaf connection-timeout-millis {
description "Specifies timeout in milliseconds after which connection must be established.";
type uint32;
- default 5000;
+ default 20000;
}
leaf max-connection-attempts {
try {
return clientFuture.get();
} catch (CancellationException e) {
- throw new RuntimeException("Netconf client interrupted", e);
+ throw new RuntimeException("Cancelling " + this, e);
} catch (ExecutionException e) {
- throw new IllegalStateException("Unable to create netconf client", e);
+ throw new IllegalStateException("Unable to create " + this, e);
}
}
- public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
- return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher);
+ public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
+ return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher);
}
- public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException {
- return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher,listener);
+ public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException {
+ return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher,listener);
}
public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher);
}
- public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat,
+ public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy,
NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException{
this.label = clientLabelForLogging;
dispatch = netconfClientDispatcher;
sessionListener = listener;
- Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strat);
+ Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strategy);
this.address = address;
clientSession = get(clientFuture);
this.sessionId = clientSession.getSessionId();
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.util.NetconfUtil;
import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
@Ignore
public class SSHNetconfClientLiveTest {
+ private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class);
NioEventLoopGroup nettyThreadgroup;
NetconfSshClientDispatcher netconfClientDispatcher;
+ InetSocketAddress address;
+ final int connectionAttempts = 10, attemptMsTimeout = 1000;
+ final int connectionTimeoutMillis = 20000;
@Before
public void setUp() {
nettyThreadgroup = new NioEventLoopGroup();
+
netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword(
System.getProperty("username"), System.getProperty("password")),
- nettyThreadgroup, nettyThreadgroup, 5000);
+ nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis);
+
+ address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port")));
}
+ @Ignore
@Test
public void test() throws Exception {
- InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), 830);
- int connectionAttempts = 10, attemptMsTimeout = 1000;
+ //runnable.run();
+ }
- NetconfClient netconfClient = new NetconfClient("client", address, connectionAttempts,
- attemptMsTimeout, netconfClientDispatcher);
+ @Test
+ public void testInExecutor() throws Exception {
+ int threads = 4;
+ ExecutorService executorService = Executors.newFixedThreadPool(threads);
+ try {
+ for (int i= 0;i< threads;i++) {
+ InetSocketAddress address = new InetSocketAddress(System.getProperty("host"),
+ Integer.parseInt(System.getProperty("port")));
+ NetconfRunnable runnable = new NetconfRunnable(address);
+ executorService.execute(runnable);
+ }
+ executorService.shutdown();
+ executorService.awaitTermination(1, TimeUnit.MINUTES);
- netconfClient.getCapabilities();
- NetconfMessage netconfMessage = NetconfUtil.createMessage(getClass().getResourceAsStream("/get_schema.xml"));
- NetconfMessage response = netconfClient.sendMessage(netconfMessage);
- NetconfUtil.checkIsMessageOk(response);
+ } finally {
+ executorService.shutdownNow();
+ }
}
+
+ class NetconfRunnable implements Runnable {
+ private final InetSocketAddress address;
+
+ NetconfRunnable(InetSocketAddress address) {
+ this.address = address;
+ }
+
+ @Override
+ public void run() {
+ try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts,
+ attemptMsTimeout, netconfClientDispatcher);) {
+ logger.info("OK {}", address);
+ } catch (InterruptedException | IOException e) {
+ logger.error("Failed {}", address, e);
+ }
+ }
+ };
}