import com.ning.http.client.AsyncHttpClientConfig.Builder;
import com.ning.http.client.Request;
import com.ning.http.client.Response;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.sourceforge.argparse4j.inf.ArgumentParser;
-import net.sourceforge.argparse4j.inf.ArgumentParserException;
import org.opendaylight.netconf.test.tool.config.Configuration;
import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ScaleUtil {
+@SuppressFBWarnings({"DM_EXIT", "DM_DEFAULT_ENCODING"})
+public final class ScaleUtil {
private static final ScheduledExecutorService EXECUTOR = new LoggingWrapperExecutor(4);
private static final Semaphore SEMAPHORE = new Semaphore(0);
private static final Stopwatch STOPWATCH = Stopwatch.createUnstarted();
private static ch.qos.logback.classic.Logger root;
private static Logger resultsLog;
+ private ScaleUtil() {
+ }
+
@SuppressWarnings("checkstyle:illegalCatch")
public static void main(final String[] args) {
final TesttoolParameters params = TesttoolParameters.parseArgs(args, TesttoolParameters.getParser());
root.error("Failed to start any simulated devices, exiting...");
System.exit(1);
}
- if (params.distroFolder != null) {
- final Main.ConfigGenerator configGenerator = new Main.ConfigGenerator(
- params.distroFolder, openDevices);
- final List<File> generated = configGenerator.generate(
- params.ssh, params.generateConfigBatchSize,
- params.generateConfigsTimeout, params.generateConfigsAddress,
- params.devicesPerPort);
- configGenerator.updateFeatureFile(generated);
- configGenerator.changeLoadOrder();
+
+ if (params.distroFolder == null) {
+ root.error("Distro folder is not set, exiting...");
+ System.exit(1);
}
+
+ final Main.ConfigGenerator configGenerator = new Main.ConfigGenerator(
+ params.distroFolder, openDevices);
+ final List<File> generated = configGenerator.generate(
+ params.ssh, params.generateConfigBatchSize,
+ params.generateConfigsTimeout, params.generateConfigsAddress,
+ params.devicesPerPort);
+ configGenerator.updateFeatureFile(generated);
+ configGenerator.changeLoadOrder();
} catch (final Exception e) {
root.error("Unhandled exception", e);
netconfDeviceSimulator.close();
if (f.isDirectory()) {
deleteFolder(f);
} else {
- f.delete();
+ if (!f.delete()) {
+ root.warn("Failed to delete {}", f);
+ }
}
}
}
- folder.delete();
- }
-
- private static TesttoolParameters parseArgs(final String[] args, final ArgumentParser parser) {
- final TesttoolParameters parameters = new TesttoolParameters();
- try {
- parser.parseArgs(args, parameters);
- return parameters;
- } catch (ArgumentParserException e) {
- parser.handleError(e);
+ if (!folder.delete()) {
+ root.warn("Failed to delete {}", folder);
}
-
- System.exit(1);
- return null;
}
- private static class ScaleVerifyCallable implements Callable {
+ private static class ScaleVerifyCallable implements Callable<Void> {
private static final Logger LOG = LoggerFactory.getLogger(ScaleVerifyCallable.class);
private static final String RESTCONF_URL
}
@Override
- public Object call() throws Exception {
+ public Void call() throws Exception {
try {
final Response response = asyncHttpClient.executeRequest(request).get();
}
}
- private static class TimeoutGuard implements Callable {
+ private static class TimeoutGuard implements Callable<Void> {
@Override
- public Object call() throws Exception {
+ public Void call() {
resultsLog.warn("Timeout for scale test reached after: {} ..aborting", STOPWATCH);
root.warn("Timeout for scale test reached after: {} ..aborting", STOPWATCH);
System.exit(0);
@Override
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
- return super.schedule(wrapCallable(callable), delay, unit);
- }
-
- private Callable wrapCallable(Callable callable) {
- return new LogOnExceptionCallable(callable);
+ return super.schedule(new LogOnExceptionCallable<>(callable), delay, unit);
}
- private class LogOnExceptionCallable implements Callable {
- private Callable theCallable;
+ private static class LogOnExceptionCallable<T> implements Callable<T> {
+ private final Callable<T> theCallable;
- LogOnExceptionCallable(Callable theCallable) {
- super();
+ LogOnExceptionCallable(Callable<T> theCallable) {
this.theCallable = theCallable;
}
@Override
- public Object call() throws Exception {
+ public T call() {
try {
- theCallable.call();
- return null;
+ return theCallable.call();
} catch (Exception e) {
// log
root.warn("error in executing: " + theCallable + ". It will no longer be run!", e);