Open Kilda Java Documentation
FlowController.java
Go to the documentation of this file.
1 package org.openkilda.controller;
2 
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.http.HttpStatus;
8 import org.springframework.stereotype.Controller;
9 import org.springframework.web.bind.annotation.PathVariable;
10 import org.springframework.web.bind.annotation.RequestBody;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestMethod;
13 import org.springframework.web.bind.annotation.ResponseBody;
14 import org.springframework.web.bind.annotation.ResponseStatus;
15 import org.springframework.web.servlet.ModelAndView;
17 
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21 
22 import javax.servlet.http.HttpServletRequest;
23 
36 
42 @Controller
43 @RequestMapping(value = "/flows")
44 public class FlowController extends BaseController {
45 
46  private static final Logger LOGGER = LoggerFactory.getLogger(FlowController.class);
47 
48  @Autowired
49  private FlowService flowService;
50 
51  @Autowired
52  private ActivityLogger activityLogger;
53 
54  @Autowired
55  private ServerContext serverContext;
56 
63  @RequestMapping
65  public ModelAndView flowList(final HttpServletRequest request) {
66  return validateAndRedirect(request, IConstants.View.FLOW_LIST);
67  }
68 
75  @RequestMapping(value = "/details")
76  public ModelAndView flowDetails(final HttpServletRequest request) {
77  return validateAndRedirect(request, IConstants.View.FLOW_DETAILS);
78  }
79 
80 
86  @RequestMapping(value = "/count", method = RequestMethod.GET)
87  @ResponseStatus(HttpStatus.OK)
88  public @ResponseBody Collection<FlowCount> getFlowCount() {
89  Collection<FlowCount> flowsInfo = new ArrayList<FlowCount>();
90  List<Flow> flows = flowService.getAllFlowList();
91  if (flows != null) {
92  flowsInfo = flowService.getFlowsCount(flows);
93  }
94  return flowsInfo;
95  }
96 
102  @RequestMapping(value = "/list", method = RequestMethod.GET)
103  @ResponseStatus(HttpStatus.OK)
104  public @ResponseBody List<FlowInfo> getFlows() {
105  return flowService.getAllFlows();
106  }
107 
114  @RequestMapping(value = "/path/{flowId}", method = RequestMethod.GET)
115  @ResponseStatus(HttpStatus.OK)
116  public @ResponseBody FlowPayload getFlowPath(@PathVariable final String flowId) {
117  LOGGER.info("[getFlowPath] - start. Flow id: " + flowId);
118  return flowService.getFlowPath(flowId);
119  }
120 
127  @RequestMapping(value = "/{flowId}/reroute", method = RequestMethod.GET)
128  @ResponseStatus(HttpStatus.OK)
129  public @ResponseBody FlowPath rerouteFlow(@PathVariable final String flowId) {
130  activityLogger.log(ActivityType.FLOW_REROUTE, flowId);
131  LOGGER.info("[rerouteFlow] - start. Flow id: " + flowId);
132  return flowService.rerouteFlow(flowId);
133  }
134 
141  @RequestMapping(value = "/{flowId}/validate", method = RequestMethod.GET)
142  @ResponseStatus(HttpStatus.OK)
143  public @ResponseBody String validateFlow(@PathVariable final String flowId) {
144  activityLogger.log(ActivityType.FLOW_VALIDATE, flowId);
145  LOGGER.info("[validateFlow] - start. Flow id: " + flowId);
146  return flowService.validateFlow(flowId);
147  }
148 
155  @RequestMapping(value = "/{flowId}", method = RequestMethod.GET)
156  @ResponseStatus(HttpStatus.OK)
157  public @ResponseBody Flow getFlowById(@PathVariable final String flowId) {
158  LOGGER.info("[getFlowById] - start. Flow id: " + flowId);
159  return flowService.getFlowById(flowId);
160  }
161 
168  @RequestMapping(value = "/{flowId}/status", method = RequestMethod.GET)
169  @ResponseStatus(HttpStatus.OK)
170  public @ResponseBody FlowStatus getFlowStatusById(@PathVariable final String flowId) {
171  LOGGER.info("[getFlowStatusById] - start. Flow id: " + flowId);
172  return flowService.getFlowStatusById(flowId);
173  }
174 
181  @RequestMapping(method = RequestMethod.PUT)
182  @ResponseStatus(HttpStatus.CREATED)
184  public @ResponseBody Flow createFlow(@RequestBody final Flow flow) {
185  LOGGER.info("[createFlow] - start. Flow id: " + flow.getId());
186  return flowService.createFlow(flow);
187  }
188 
196  @RequestMapping(value = "/{flowId}", method = RequestMethod.PUT)
197  @ResponseStatus(HttpStatus.CREATED)
199  public @ResponseBody Flow updateFlow(@PathVariable("flowId") final String flowId,@RequestBody final Flow flow) {
200  LOGGER.info("[updateFlow] - start. Flow id: " + flowId);
201  return flowService.updateFlow(flowId, flow);
202  }
203 
211  @RequestMapping(value = "/{flowId}", method = RequestMethod.DELETE)
212  @ResponseStatus(HttpStatus.OK)
214  public @ResponseBody Flow deleteFlow(@RequestBody final UserInfo userInfo,
215  @PathVariable("flowId") final String flowId) {
216  LOGGER.info("[deleteFlow] - start. Flow id: " + flowId);
217  if (serverContext.getRequestContext() != null) {
218  userInfo.setUserId(serverContext.getRequestContext().getUserId());
219  }
220  return flowService.deleteFlow(flowId, userInfo);
221  }
222 }
Flow deleteFlow(@RequestBody final UserInfo userInfo, @PathVariable("flowId") final String flowId)
Flow updateFlow(@PathVariable("flowId") final String flowId, @RequestBody final Flow flow)
value
Definition: nodes.py:62
Flow createFlow(@RequestBody final Flow flow)
ModelAndView flowList(final HttpServletRequest request)