Open Kilda Java Documentation
FlowService.java
Go to the documentation of this file.
1 package org.openkilda.service;
2 
3 import java.util.Collection;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7 
8 import org.apache.log4j.Logger;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service;
23 
29 @Service
30 public class FlowService {
31 
32  private static final Logger LOGGER = Logger.getLogger(FlowService.class);
33 
34  @Autowired
35  private FlowsIntegrationService flowsIntegrationService;
36 
37  @Autowired
38  private SwitchIntegrationService switchIntegrationService;
39 
40  @Autowired
41  private UserService userService;
42 
48  public List<FlowInfo> getAllFlows() {
49  return flowsIntegrationService.getFlows();
50  }
51 
52 
59  public Collection<FlowCount> getFlowsCount(final List<Flow> flows) {
60  LOGGER.info("Inside ServiceFlowImpl method getFlowsCount");
61  Map<FlowCount, FlowCount> infoByFlowInfo = new HashMap<>();
62  Map<String, String> csNames = switchIntegrationService.getCustomSwitchNameFromFile();
63 
64  if (!CollectionUtil.isEmpty(flows)) {
65  flows.forEach((flow) -> {
66  FlowCount flowInfo = new FlowCount();
67  if (flow.getSource() != null) {
68  flowInfo.setSrcSwitch(flow.getSource().getSwitchId());
69  String srcSwitchName = switchIntegrationService.customSwitchName(csNames,
70  flow.getSource().getSwitchId());
71  flowInfo.setSrcSwitchName(srcSwitchName);
72  }
73  if (flow.getDestination() != null) {
74  flowInfo.setDstSwitch(flow.getDestination().getSwitchId());
75  String dstSwitchName = switchIntegrationService.customSwitchName(csNames,
76  flow.getDestination().getSwitchId());
77  flowInfo.setDstSwitchName(dstSwitchName);
78  }
79  flowInfo.setFlowCount(1);
80 
81  if (infoByFlowInfo.containsKey(flowInfo)) {
82  infoByFlowInfo.get(flowInfo).incrementFlowCount();
83  } else {
84  infoByFlowInfo.put(flowInfo, flowInfo);
85  }
86  });
87  }
88  LOGGER.info("exit ServiceSwitchImpl method getFlowsCount");
89  return infoByFlowInfo.values();
90  }
91 
98  public FlowPayload getFlowPath(final String flowId) throws IntegrationException {
99  return flowsIntegrationService.getFlowPath(flowId);
100  }
101 
107  public List<Flow> getAllFlowList() {
108  return flowsIntegrationService.getAllFlowList();
109  }
110 
117  public FlowPath rerouteFlow(String flowId) {
118  return flowsIntegrationService.rerouteFlow(flowId);
119  }
120 
127  public String validateFlow(String flowId) {
128  return flowsIntegrationService.validateFlow(flowId);
129  }
130 
137  public Flow getFlowById(String flowId) {
138  return flowsIntegrationService.getFlowById(flowId);
139  }
140 
141 
148  public FlowStatus getFlowStatusById(String flowId) {
149  return flowsIntegrationService.getFlowStatusById(flowId);
150  }
151 
152 
159  public Flow createFlow(Flow flow) {
160  return flowsIntegrationService.createFlow(flow);
161  }
162 
170  public Flow updateFlow(String flowId, Flow flow) {
171  return flowsIntegrationService.updateFlow(flowId, flow);
172  }
173 
181  public Flow deleteFlow(String flowId, UserInfo userInfo) {
182  if (userService.validateOTP(userInfo.getUserId(), userInfo.getCode())) {
183  return flowsIntegrationService.deleteFlow(flowId);
184  } else {
185  return null;
186  }
187  }
188 }
Collection< FlowCount > getFlowsCount(final List< Flow > flows)
Flow deleteFlow(String flowId, UserInfo userInfo)
static boolean isEmpty(final Collection<?> collection)
void setFlowCount(final Integer flowCount)
Definition: FlowCount.java:97
String validateFlow(String flowId)
void setDstSwitch(final String dstSwitch)
Definition: FlowCount.java:63
void setSrcSwitchName(String srcSwitchName)
Definition: FlowCount.java:71
FlowStatus getFlowStatusById(String flowId)
Flow updateFlow(String flowId, Flow flow)
FlowPath rerouteFlow(String flowId)
FlowPayload getFlowPath(final String flowId)
void setSrcSwitch(final String srcSwitch)
Definition: FlowCount.java:45
void setDstSwitchName(String dstSwitchName)
Definition: FlowCount.java:79