1 package org.openkilda.atdd.utils.controller;
3 import static org.awaitility.Awaitility.await;
8 import com.fasterxml.jackson.core.JsonProcessingException;
9 import com.fasterxml.jackson.core.type.TypeReference;
10 import com.spotify.docker.client.exceptions.DockerCertificateException;
11 import com.spotify.docker.client.exceptions.DockerException;
12 import org.glassfish.jersey.client.ClientConfig;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 import java.io.IOException;
17 import java.util.List;
19 import java.util.concurrent.TimeUnit;
20 import javax.ws.rs.ProcessingException;
21 import javax.ws.rs.client.Client;
22 import javax.ws.rs.client.ClientBuilder;
23 import javax.ws.rs.client.Entity;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
28 private static final Logger LOGGER = LoggerFactory.getLogger(
ControllerUtils.class);
29 private final Client restClient;
31 public ControllerUtils() throws DockerCertificateException, DockerException, InterruptedException {
32 restClient = ClientBuilder.newClient(
new ClientConfig());
35 public void restart() throws DockerException, InterruptedException {
36 await().atMost(10, TimeUnit.SECONDS)
37 .until(this::isAlive);
42 String json =
Utils.
MAPPER.writeValueAsString(flow);
45 .path(
"/wm/staticentrypusher/json")
47 .accept(MediaType.APPLICATION_JSON)
48 .post(Entity.json(json));
49 }
catch (ProcessingException e) {
53 if (response.getStatus() != 200) {
62 .path(String.format(
"/wm/staticentrypusher/list/%s/json", dpId))
64 .accept(MediaType.APPLICATION_JSON)
66 }
catch (ProcessingException e) {
70 if (response.getStatus() != 200) {
74 String json = response.readEntity(String.class);
77 }
catch (IOException e) {
90 .path(String.format(
"/wm/core/switch/%s/flow/json", dpId))
92 .accept(MediaType.APPLICATION_JSON)
94 }
catch (ProcessingException e) {
98 if (response.getStatus() != 200) {
102 final String flowsKey =
"flows";
103 String json = response.readEntity(String.class);
104 LOGGER.debug(
"FloodLight switch \"{}\" list flows response: {}", dpId, json);
106 Map<String, Object> keyChecker =
Utils.
MAPPER.readValue(json,
new TypeReference<Map<String, Object>>() {
108 if (!keyChecker.containsKey(flowsKey)) {
112 Map<String, List<CoreFlowEntry>> wrapper =
Utils.
MAPPER.readValue(
113 json,
new TypeReference<Map<String, List<CoreFlowEntry>>>() {
115 return wrapper.get(flowsKey);
116 }
catch (IOException e) {
125 .path(
"/wm/core/controller/summary/json")
128 }
catch (ProcessingException e) {
129 LOGGER.info(
"floodlight is unavailable");
133 boolean alive = response != null;
135 LOGGER.info(
"floodlight available");
147 .path(String.format(
"wm/core/switch/%s/port-desc/json", switchId))
149 .accept(MediaType.APPLICATION_JSON)
151 }
catch (ProcessingException e) {
155 if (response.getStatus() != 200) {
159 String json = response.readEntity(String.class);
162 }
catch (IOException e) {
static final ObjectMapper MAPPER
SwitchEntry getSwitchPorts(String switchId)
List< CoreFlowEntry > listCoreFlows(String dpId)
DpIdEntriesList listStaticEntries()
DpIdEntriesList listStaticEntries(String dpId)
static final String FLOODLIGHT_ENDPOINT
void addStaticFlow(StaticFlowEntry flow)