Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / client / http / perf / SyncExecutionStrategy.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.netconf.test.tool.client.http.perf;
10
11 import com.ning.http.client.AsyncHttpClient;
12 import com.ning.http.client.Request;
13 import com.ning.http.client.Response;
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.concurrent.ExecutionException;
17 import org.opendaylight.controller.netconf.test.tool.client.stress.ExecutionStrategy;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class SyncExecutionStrategy implements ExecutionStrategy{
22
23     private static final Logger LOG = LoggerFactory.getLogger(SyncExecutionStrategy.class);
24
25     private final Parameters params;
26     private final ArrayList<Request> payloads;
27     private final AsyncHttpClient asyncHttpClient;
28
29     SyncExecutionStrategy(final Parameters params, final AsyncHttpClient asyncHttpClient, final ArrayList<Request> payloads) {
30         this.params = params;
31         this.asyncHttpClient = asyncHttpClient;
32         this.payloads = payloads;
33     }
34
35     @Override
36     public void invoke() {
37
38         LOG.info("Begin sending sync requests");
39         for (Request request : payloads) {
40             try {
41                 Response response = asyncHttpClient.executeRequest(request).get();
42                 if (response.getStatusCode() != 200 && response.getStatusCode() != 204) {
43                     LOG.warn("Status code: {}", response.getStatusCode());
44                     LOG.warn("url: {}", request.getUrl());
45                     LOG.warn(response.getResponseBody());
46                 }
47             } catch (InterruptedException | ExecutionException | IOException e) {
48                 LOG.warn(e.toString());
49             }
50         }
51         LOG.info("End sending sync requests");
52
53     }
54 }