X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=netconf%2Ftools%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Ftest%2Ftool%2FExecution.java;h=8a0595fde6038f4828ddb313ed6570b5f2c9f3be;hb=71f65f66e59aedd94762954ea055531d8f2c9ea8;hp=e2799d86614888bb2668117e46026d8b5d2c717b;hpb=990f1c0d249e9f27e192cf6c1300e516ace81087;p=netconf.git diff --git a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java index e2799d8661..8a0595fde6 100644 --- a/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java +++ b/netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/Execution.java @@ -5,19 +5,22 @@ * 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.netconf.test.tool; -import com.ning.http.client.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import com.ning.http.client.AsyncCompletionHandler; +import com.ning.http.client.AsyncHttpClient; +import com.ning.http.client.AsyncHttpClientConfig; +import com.ning.http.client.HttpResponseStatus; +import com.ning.http.client.Realm; +import com.ning.http.client.Request; +import com.ning.http.client.Response; import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Semaphore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class Execution implements Callable { @@ -33,7 +36,7 @@ public class Execution implements Callable { private final String destination; private final String payload; - public DestToPayload(String destination, String payload) { + DestToPayload(final String destination, final String payload) { this.destination = destination; this.payload = payload; } @@ -47,7 +50,7 @@ public class Execution implements Callable { } } - public Execution(TesttoolParameters params, ArrayList payloads) { + public Execution(final TesttoolParameters params, final ArrayList payloads) { this.invokeAsync = params.async; this.throttle = params.throttle / params.threadAmount; @@ -90,23 +93,22 @@ public class Execution implements Callable { Response response = asyncHttpClient.executeRequest(request).get(); if (response.getStatusCode() != 200 && response.getStatusCode() != 204) { if (response.getStatusCode() == 409) { - LOG.warn("Request failed, status code: {} - one or more of the devices" + - " is already configured, skipping the whole batch", response.getStatusCode()); + LOG.warn("Request failed, status code: {} - one or more of the devices" + + " is already configured, skipping the whole batch", response.getStatusCode()); } else { LOG.warn("Status code: {}", response.getStatusCode()); LOG.warn("url: {}", request.getUrl()); - LOG.warn(response.getResponseBody()); + LOG.warn("body: {}", response.getResponseBody()); } } } catch (InterruptedException | ExecutionException | IOException e) { - LOG.warn(e.toString()); + LOG.warn("Failed to execute request", e); } } LOG.info("End sending sync requests"); } private void invokeAsync() { - final ArrayList> futures = new ArrayList<>(); LOG.info("Begin sending async requests"); for (final Request request : payloads) { @@ -115,16 +117,17 @@ public class Execution implements Callable { } catch (InterruptedException e) { LOG.warn("Semaphore acquire interrupted"); } - futures.add(asyncHttpClient.executeRequest(request, new AsyncCompletionHandler() { + asyncHttpClient.executeRequest(request, new AsyncCompletionHandler() { @Override - public STATE onStatusReceived(HttpResponseStatus status) throws Exception { + public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { super.onStatusReceived(status); if (status.getStatusCode() != 200 && status.getStatusCode() != 204) { if (status.getStatusCode() == 409) { - LOG.warn("Request failed, status code: {} - one or more of the devices" + - " is already configured, skipping the whole batch", status.getStatusCode()); + LOG.warn("Request failed, status code: {} - one or more of the devices" + + " is already configured, skipping the whole batch", status.getStatusCode()); } else { - LOG.warn("Request failed, status code: {}", status.getStatusCode() + status.getStatusText()); + LOG.warn("Request failed, status code: {}", + status.getStatusCode() + status.getStatusText()); LOG.warn("request: {}", request.toString()); } } @@ -132,11 +135,11 @@ public class Execution implements Callable { } @Override - public Response onCompleted(Response response) throws Exception { + public Response onCompleted(final Response response) { semaphore.release(); return response; } - })); + }); } LOG.info("Requests sent, waiting for responses"); @@ -150,7 +153,7 @@ public class Execution implements Callable { } @Override - public Void call() throws Exception { + public Void call() { if (invokeAsync) { this.invokeAsync(); } else {