16 package org.openkilda.wfm.topology.cache.service;
30 import org.apache.commons.lang.StringUtils;
31 import org.apache.commons.lang3.tuple.MutablePair;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Objects;
38 import java.util.stream.Collectors;
43 private final List<MutablePair<Flow, CachedFlowState>> predefinedFlows =
new ArrayList<>();
48 this.networkCache = networkCache;
58 List<IslInfoData> links = getActiveLinks(switchId);
61 .flatMap(List::stream)
63 .collect(Collectors.toList());
71 private List<IslInfoData> getActiveLinks(
SwitchId switchId) {
72 return networkCache.getIslsBySwitch(switchId).stream()
73 .filter(isl -> isLinkAvailable(isl.getPath(), switchId))
74 .collect(Collectors.toList());
83 private boolean isLinkAvailable(List<PathNode>
nodes,
SwitchId currentSwitchId) {
85 .allMatch(
node -> networkCache.getSwitch(
node.getSwitchId()).getState().isActive()
86 || StringUtils.equals(currentSwitchId.
toString(),
node.getSwitchId().toString()));
96 List<CommandData>
result =
new ArrayList<>();
97 predefinedFlows.stream()
98 .filter(flow -> switchId.
equals(flow.getLeft().getSourceSwitch()))
101 if (Objects.nonNull(
command)) {
114 LOGGER.info(
"Created flow create request for flowId {}", flow.getFlowId());
115 predefinedFlows.stream()
116 .filter(item -> item.getLeft().equals(flow))
118 .ifPresent(pair -> pair.setRight(CachedFlowState.CREATED));
124 private boolean isFlowSwitchesUp(Flow flow) {
125 return Objects.nonNull(flow) && flow.getFlowPath().getPath()
128 networkCache.getSwitch(
node.getSwitchId()).getState().isActive());
136 if (Objects.nonNull(flows.
getLeft())) {
137 predefinedFlows.add(
new MutablePair<>(flows.
getLeft(), CachedFlowState.CACHED));
139 if (Objects.nonNull(flows.
getRight())) {
140 predefinedFlows.add(
new MutablePair<>(flows.
getRight(), CachedFlowState.CACHED));
144 private enum CachedFlowState {
List< CommandData > getFlowCommands(SwitchId switchId)
List< PortInfoData > getPortsForDiscovering(SwitchId switchId)
CacheWarmingService(NetworkCache networkCache)
def command(payload, fields)
void addPredefinedFlow(ImmutablePair< Flow, Flow > flows)
List< PathNode > getPath()