Search in sources :

Example 46 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class SwitchesUtils method knockoutSwitch.

/**
 * Turns off switch.
 * @param switchName switch name.
 * @return true if result is success.
 */
public static boolean knockoutSwitch(String switchName) {
    System.out.println("\n==> Knockout switch");
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client.target(trafficEndpoint).path("/knockoutswitch").queryParam("switch", switchName).request().post(Entity.json(""));
    System.out.println(format("===> Response = %s", result.toString()));
    return result.getStatus() == 200;
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 47 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class FlowCrudBasicRunTest method checkTraffic.

private int checkTraffic(String sourceSwitch, String destSwitch, int sourceVlan, int destinationVlan, int expectedStatus) {
    if (isTrafficTestsEnabled()) {
        System.out.print("=====> Send traffic");
        long current = System.currentTimeMillis();
        Client client = ClientBuilder.newClient(new ClientConfig());
        // NOTE: current implementation requires two auxiliary switches in
        // topology, one for generating traffic, another for receiving it.
        // Originaly smallest meaningful topology was supposed to consist
        // of three switches, thus switches 1 and 5 were used as auxiliary.
        // Now some scenarios require even smaller topologies and at the same
        // time they reuse small linear topology. This leads to shutting off of
        // switches 1 and 5 from flows and to test failures. Since topology
        // reuse speeds testing up the code below determines which switch:port
        // pairs should be used as source and drains for traffic while keepig
        // small linear topology in use.
        int fromNum = Integer.parseInt(sourceSwitch.substring(sourceSwitch.length() - 1));
        int toNum = Integer.parseInt(destSwitch.substring(destSwitch.length() - 1));
        String from = "0000000" + (fromNum - 1);
        String to = "0000000" + (toNum + 1);
        int fromPort = from.equals("00000001") ? 1 : 2;
        int toPort = 1;
        System.out.println(String.format("from:%s:%d::%d via %s, To:%s:%d::%d via %s", from, fromPort, sourceVlan, sourceSwitch, to, toPort, destinationVlan, destSwitch));
        Response result = client.target(trafficEndpoint).path("/checkflowtraffic").queryParam("srcswitch", from).queryParam("dstswitch", to).queryParam("srcport", fromPort).queryParam("dstport", toPort).queryParam("srcvlan", sourceVlan).queryParam("dstvlan", destinationVlan).request().get();
        System.out.println(String.format("======> Response = %s", result.toString()));
        System.out.println(String.format("======> Send traffic Time: %,.3f", getTimeDuration(current)));
        return result.getStatus();
    } else {
        return expectedStatus;
    }
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) DefaultParameters.trafficEndpoint(org.openkilda.DefaultParameters.trafficEndpoint) DefaultParameters.mininetEndpoint(org.openkilda.DefaultParameters.mininetEndpoint)

Example 48 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class FlowFFRTest method trafficIsOk.

private boolean trafficIsOk(boolean expectedResult) throws Throwable {
    if (isTrafficTestsEnabled()) {
        System.out.println("=====> Send traffic");
        long current = System.currentTimeMillis();
        Client client = ClientBuilder.newClient(new ClientConfig());
        Response result = client.target(trafficEndpoint).path("/checkflowtraffic").queryParam("srcswitch", "s1").queryParam("dstswitch", "s8").queryParam("srcport", "1").queryParam("dstport", "1").queryParam("srcvlan", "1000").queryParam("dstvlan", "1000").request().get();
        System.out.println(String.format("======> Response = %s", result.toString()));
        System.out.println(String.format("======> Send traffic Time: %,.3f", getTimeDuration(current)));
        return result.getStatus() == 200;
    } else {
        return expectedResult;
    }
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 49 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class FlowFFRTest method portUp.

private boolean portUp(String switchName, String portNo) throws Throwable {
    System.out.println("\n==> Set Port Up");
    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client.target(trafficEndpoint).path("/port/up").queryParam("switch", switchName).queryParam("port", portNo).request().post(Entity.json(""));
    System.out.println(String.format("===> Response = %s", result.toString()));
    System.out.println(String.format("===> Set Port Up Time: %,.3f", getTimeDuration(current)));
    return result.getStatus() == 200;
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 50 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class StatisticsBasicTest method getNumberOfDatapoints.

private List<Metric> getNumberOfDatapoints() throws Throwable {
    System.out.println("\n==> OpenTSDB Metrics request");
    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response response = client.target(opentsdbEndpoint).path("/api/query").queryParam("start", "24h-ago").queryParam("m", "sum:pen.switch.tx-bytes").queryParam("timezone", "Australia/Melbourne").request().get();
    System.out.println(String.format("===> Response = %s", response));
    System.out.println(String.format("===> OpenTSDB Metrics Time: %,.3f", getTimeDuration(current)));
    List<Metric> metrics = new ObjectMapper().readValue(response.readEntity(String.class), new TypeReference<List<Metric>>() {
    });
    System.out.println(String.format("====> Metrics = %s", metrics));
    return metrics;
}
Also used : Response(javax.ws.rs.core.Response) Metric(org.openkilda.messaging.model.Metric) List(java.util.List) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)169 Client (javax.ws.rs.client.Client)129 Test (org.junit.Test)85 Response (javax.ws.rs.core.Response)66 JerseyTest (org.glassfish.jersey.test.JerseyTest)52 WebTarget (javax.ws.rs.client.WebTarget)48 ClientBuilder (javax.ws.rs.client.ClientBuilder)17 SSLContext (javax.net.ssl.SSLContext)12 Invocation (javax.ws.rs.client.Invocation)12 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)10 IOException (java.io.IOException)9 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)8 URI (java.net.URI)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5