use of org.openkilda.messaging.info.flow.FlowValidationResponse in project open-kilda by telstra.
the class FlowValidationService method validateFlow.
/**
* Validate flow.
*/
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
int rulesCount = 0;
int metersCount = 0;
for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (!foundFlow.isPresent()) {
throw new FlowNotFoundException(flowId);
}
Flow flow = foundFlow.get();
if (flow.getForwardPath() == null) {
throw new InvalidPathException(flowId, "Forward path was not returned.");
}
if (flow.getReversePath() == null) {
throw new InvalidPathException(flowId, "Reverse path was not returned.");
}
List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
if (flow.getProtectedForwardPath() != null) {
List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
}
if (flow.getProtectedReversePath() != null) {
List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
}
return flowValidationResponse;
}
use of org.openkilda.messaging.info.flow.FlowValidationResponse in project open-kilda by telstra.
the class CompleteYFlowValidationAction method performWithResponse.
@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) throws FlowNotFoundException, SwitchNotFoundException {
YFlowDiscrepancyDto resourcesValidationResult = validationService.validateYFlowResources(stateMachine.getYFlowId(), stateMachine.getReceivedRules(), stateMachine.getReceivedMeters());
YFlowValidationResponse result = new YFlowValidationResponse();
result.setYFlowValidationResult(resourcesValidationResult);
result.setSubFlowValidationResults(stateMachine.getSubFlowValidationResults());
boolean notAsExpected = !resourcesValidationResult.isAsExpected() || stateMachine.getSubFlowValidationResults().stream().map(FlowValidationResponse::getAsExpected).anyMatch(n -> !n);
result.setAsExpected(!notAsExpected);
CommandContext commandContext = stateMachine.getCommandContext();
InfoMessage message = new InfoMessage(result, commandContext.getCreateTime(), commandContext.getCorrelationId());
return Optional.of(message);
}
Aggregations