use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class PostFlowMirrorPathDeallocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
boolean mirrorPointsWereDeallocated = transactionManager.doInTransaction(() -> {
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
flowMirrorPointsRepository.remove(flowMirrorPoints);
resourcesManager.deallocateMirrorGroup(flowPathId, mirrorSwitchId);
return true;
}
return false;
});
if (mirrorPointsWereDeallocated) {
stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorSwitchId));
}
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class FlowValidationFsm method receiveData.
protected void receiveData(State from, State to, Event event, Object context) {
Flow flow;
try {
flow = service.checkFlowStatusAndGetFlow(flowId);
} catch (FlowNotFoundException e) {
log.error("Flow {} not found when sending commands to SpeakerWorkerBolt", flowId, e);
sendException(e.getMessage(), "Receiving rules operation in FlowValidationFsm", ErrorType.NOT_FOUND);
return;
} catch (IllegalFlowStateException e) {
log.error("Could not validate flow: Flow {} is in DOWN state", flowId, e);
sendException("Could not validate flow", format("Could not validate flow: Flow %s is in DOWN state", flowId), ErrorType.UNPROCESSABLE_REQUEST);
return;
}
List<SwitchId> switchIds = service.getSwitchIdListByFlowId(flowId);
awaitingRules = switchIds.size();
log.debug("Send commands to get rules on the switches");
switchIds.forEach(switchId -> getCarrier().sendSpeakerRequest(flowId, new DumpRulesForFlowHsRequest(switchId)));
log.debug("Send commands to get meters on the termination switches");
awaitingMeters = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getDestSwitchId()));
log.debug("Send commands to get groups on the termination switches");
awaitingGroups = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getDestSwitchId()));
}
use of org.openkilda.model.SwitchId 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.model.SwitchId in project open-kilda by telstra.
the class RevertYFlowRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
String yFlowId = flow.getYFlowId();
if (yFlowId == null) {
stateMachine.saveActionToHistory("No need to revert y-flow rules - it's not a sub-flow");
stateMachine.fire(Event.SKIP_YFLOW_RULES_REVERT);
return;
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found in persistent storage", yFlowId)));
stateMachine.clearPendingAndRetriedAndFailedCommands();
SwitchId sharedEndpoint = yFlow.getSharedEndpoint().getSwitchId();
InstallSpeakerCommandsRequest installRequest = buildYFlowInstallRequest(sharedEndpoint, stateMachine.getOldPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addInstallSpeakerCommand(installRequest.getCommandId(), installRequest);
DeleteSpeakerCommandsRequest deleteRequest = buildYFlowDeleteRequest(sharedEndpoint, stateMachine.getNewPrimaryForwardPath(), stateMachine.getCommandContext());
stateMachine.addDeleteSpeakerCommand(deleteRequest.getCommandId(), deleteRequest);
// emitting
Stream.of(installRequest, deleteRequest).forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for reverting y-flow rules have been sent");
}
use of org.openkilda.model.SwitchId in project open-kilda by telstra.
the class SetValidateRuleErrorAction method execute.
@Override
public void execute(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
Set<SwitchId> switches = Stream.concat(stateMachine.getPendingCommands().values().stream(), stateMachine.getFailedValidationResponses().values().stream().map(SpeakerResponse::getSwitchId)).collect(Collectors.toSet());
stateMachine.setRerouteError(new SpeakerRequestError("Failed to validate rules", switches));
log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
stateMachine.clearPendingCommands();
}
Aggregations