Search in sources :

Example 1 with ConfigurationBuilder

use of org.opendaylight.netconf.test.tool.config.ConfigurationBuilder in project netconf by opendaylight.

the class Main method main.

@SuppressWarnings("checkstyle:IllegalCatch")
@SuppressFBWarnings({ "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" })
public static void main(final String[] args) {
    final TesttoolParameters params = TesttoolParameters.parseArgs(args, TesttoolParameters.getParser());
    params.validate();
    final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(params.debug ? Level.DEBUG : Level.INFO);
    final Configuration configuration = new ConfigurationBuilder().from(params).build();
    final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(configuration);
    try {
        LOG.debug("Trying to start netconf test-tool with parameters {}", params);
        final List<Integer> openDevices = netconfDeviceSimulator.start();
        if (openDevices.size() == 0) {
            LOG.error("Failed to start any simulated devices, exiting...");
            System.exit(1);
        }
        // if ODL controller ip is not set NETCONF devices will be started, but not registered at the controller
        if (params.controllerIp != null) {
            final List<Execution> executionThreads = divideDevicesForThreads(openDevices, params);
            final ExecutorService executorService = Executors.newFixedThreadPool(params.threadAmount);
            final Stopwatch time = Stopwatch.createStarted();
            final List<Future<Void>> futures = executorService.invokeAll(executionThreads, params.timeOut, TimeUnit.SECONDS);
            int threadNum = 0;
            for (final Future<Void> future : futures) {
                threadNum++;
                if (future.isCancelled()) {
                    LOG.info("{}. thread timed out.", threadNum);
                } else {
                    try {
                        future.get();
                    } catch (final ExecutionException | InterruptedException e) {
                        LOG.info("{}. thread failed.", threadNum, e);
                    }
                }
            }
            time.stop();
            LOG.info("Time spent with configuration of devices: {}.", time);
        }
    } catch (final RuntimeException | InterruptedException e) {
        LOG.error("Unhandled exception", e);
        netconfDeviceSimulator.close();
        System.exit(1);
    }
    // Block main thread
    synchronized (netconfDeviceSimulator) {
        try {
            netconfDeviceSimulator.wait();
        } catch (final InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ConfigurationBuilder(org.opendaylight.netconf.test.tool.config.ConfigurationBuilder) Configuration(org.opendaylight.netconf.test.tool.config.Configuration) Stopwatch(com.google.common.base.Stopwatch) Logger(org.slf4j.Logger) ExecutionException(java.util.concurrent.ExecutionException) Stopwatch(com.google.common.base.Stopwatch) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with ConfigurationBuilder

use of org.opendaylight.netconf.test.tool.config.ConfigurationBuilder in project netconf by opendaylight.

the class ScaleUtil method main.

@SuppressWarnings("checkstyle:illegalCatch")
public static void main(final String[] args) {
    final TesttoolParameters params = TesttoolParameters.parseArgs(args, TesttoolParameters.getParser());
    setUpLoggers(params);
    // cleanup at the start in case controller was already running
    final Runtime runtime = Runtime.getRuntime();
    cleanup(runtime, params);
    while (true) {
        root.warn("Starting scale test with {} devices", params.deviceCount);
        final ScheduledFuture<?> timeoutGuardFuture = EXECUTOR.schedule(new TimeoutGuard(), TIMEOUT, TimeUnit.MINUTES);
        final Configuration configuration = new ConfigurationBuilder().from(params).build();
        final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(configuration);
        final List<Integer> openDevices = netconfDeviceSimulator.start();
        if (openDevices.size() == 0) {
            root.error("Failed to start any simulated devices, exiting...");
            System.exit(1);
        }
        if (params.distroFolder == null) {
            root.error("Distro folder is not set, exiting...");
            System.exit(1);
        }
        root.warn(params.distroFolder.getAbsolutePath());
        try {
            runtime.exec(params.distroFolder.getAbsolutePath() + "/bin/start");
            String status;
            do {
                final Process list = runtime.exec(params.distroFolder.getAbsolutePath() + "/bin/client feature:list");
                try {
                    Thread.sleep(2000L);
                } catch (InterruptedException e) {
                    root.warn("Failed to sleep", e);
                }
                status = CharStreams.toString(new BufferedReader(new InputStreamReader(list.getErrorStream())));
                root.warn(status);
            } while (status.startsWith("Failed to get the session"));
            root.warn("Doing feature install {}", params.distroFolder.getAbsolutePath() + "/bin/client feature:install odl-restconf-nb-rfc8040 odl-netconf-topology");
            final Process featureInstall = runtime.exec(params.distroFolder.getAbsolutePath() + "/bin/client feature:install odl-restconf-nb-rfc8040 odl-netconf-topology");
            root.warn(CharStreams.toString(new BufferedReader(new InputStreamReader(featureInstall.getInputStream()))));
            root.warn(CharStreams.toString(new BufferedReader(new InputStreamReader(featureInstall.getErrorStream()))));
        } catch (IOException e) {
            root.error("Failed to start karaf", e);
            System.exit(1);
        }
        waitNetconfTopologyReady(params);
        final Execution ex = new Execution(openDevices, params);
        ex.call();
        root.warn("Karaf started, starting stopwatch");
        STOPWATCH.start();
        try {
            EXECUTOR.schedule(new ScaleVerifyCallable(params), RETRY_DELAY, TimeUnit.SECONDS);
            root.warn("First callable scheduled");
            SEMAPHORE.acquire();
            root.warn("semaphore released");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        timeoutGuardFuture.cancel(false);
        params.deviceCount += DEVICE_STEP;
        netconfDeviceSimulator.close();
        STOPWATCH.reset();
        cleanup(runtime, params);
    }
}
Also used : ConfigurationBuilder(org.opendaylight.netconf.test.tool.config.ConfigurationBuilder) Configuration(org.opendaylight.netconf.test.tool.config.Configuration) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Aggregations

Configuration (org.opendaylight.netconf.test.tool.config.Configuration)2 ConfigurationBuilder (org.opendaylight.netconf.test.tool.config.ConfigurationBuilder)2 Stopwatch (com.google.common.base.Stopwatch)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Logger (org.slf4j.Logger)1