1 package org.openkilda.integration.service;
5 import org.apache.http.HttpResponse;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.http.HttpMethod;
23 import org.springframework.stereotype.Service;
25 import com.fasterxml.jackson.core.JsonProcessingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
56 private ObjectMapper objectMapper;
68 if (flowList != null) {
69 return flowConverter.toFlowsInfo(flowList);
83 HttpResponse response =
84 restClientManager.invoke(applicationProperties.getFlowStatus() + flowId,
85 HttpMethod.GET,
"",
"", applicationService.getAuthHeader());
87 return restClientManager.getResponse(response,
FlowStatus.class);
101 HttpResponse response = restClientManager.invoke(
102 applicationProperties.getFlowPath().replace(
"{flow_id}", flowId),
103 HttpMethod.GET,
"",
"", applicationService.getAuthHeader());
106 restClientManager.getResponse(response,
FlowPayload.class);
107 return flowPathConverter.getFlowPath(flowId, flowPayload);
109 String content =
IoUtil.
toString(response.getEntity().getContent());
114 }
catch (Exception exception) {
115 LOGGER.error(
"Exception in getFlowPaths " + exception.getMessage());
128 HttpResponse response = restClientManager.invoke(applicationProperties.getFlows(),
129 HttpMethod.GET,
"",
"", applicationService.getAuthHeader());
131 return restClientManager.getResponseList(response,
Flow.class);
133 }
catch (Exception exception) {
134 LOGGER.error(
"Exception in getAllFlowList " + exception.getMessage());
148 HttpResponse response = restClientManager.invoke(
149 applicationProperties.getFlowReroute().replace(
"{flow_id}", flowId),
150 HttpMethod.PATCH,
"",
"", applicationService.getAuthHeader());
152 FlowPath flowPath = restClientManager.getResponse(response,
FlowPath.class);
155 String content =
IoUtil.
toString(response.getEntity().getContent());
159 }
catch (Exception exception) {
160 LOGGER.error(
"Exception in rerouteFlow " + exception.getMessage());
173 HttpResponse response = restClientManager.invoke(
174 applicationProperties.getFlowValidate().replace(
"{flow_id}", flowId),
175 HttpMethod.GET,
"",
"", applicationService.getAuthHeader());
177 }
catch (Exception exception) {
178 LOGGER.error(
"Exception in validateFlow " + exception.getMessage());
191 HttpResponse response =
192 restClientManager.invoke(applicationProperties.getFlows() +
"/" + flowId,
193 HttpMethod.GET,
"",
"", applicationService.getAuthHeader());
195 Flow flow = restClientManager.getResponse(response,
Flow.class);
196 return flowConverter.toFlowWithSwitchNames(flow);
198 }
catch (Exception exception) {
199 LOGGER.error(
"Exception in getFlowById " + exception.getMessage());
213 HttpResponse response = restClientManager.invoke(applicationProperties.getFlows(),
214 HttpMethod.PUT, objectMapper.writeValueAsString(flow),
"application/json",
215 applicationService.getAuthHeader());
217 return restClientManager.getResponse(response,
Flow.class);
219 }
catch (JsonProcessingException e) {
220 LOGGER.error(
"Inside createFlow Exception :", e);
235 HttpResponse response = restClientManager.invoke(applicationProperties.getUpdateFlow().replace(
"{flow_id}", flowId),
236 HttpMethod.PUT, objectMapper.writeValueAsString(flow),
"application/json",
237 applicationService.getAuthHeader());
239 return restClientManager.getResponse(response,
Flow.class);
241 }
catch (JsonProcessingException e) {
242 LOGGER.error(
"Inside updateFlow Exception :", e);
256 HttpResponse response = restClientManager.invoke(
257 applicationProperties.getUpdateFlow().replace(
"{flow_id}", flowId),
258 HttpMethod.DELETE,
"",
"application/json", applicationService.getAuthHeader());
260 return restClientManager.getResponse(response,
Flow.class);
Flow deleteFlow(String flowId)
static boolean isValidResponse(final HttpResponse response)
String validateFlow(String flowId)
Flow createFlow(Flow flow)
Flow getFlowById(String flowId)
List< Flow > getAllFlowList()
Flow updateFlow(String flowId, Flow flow)
static String toString(final InputStream inputStream)
FlowPayload getFlowPath(final String flowId)
FlowStatus getFlowStatusById(final String flowId)
List< FlowInfo > getFlows()
FlowPath rerouteFlow(String flowId)