use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testMainPath.
@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
assertEquals(4, message.size());
try {
assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
} catch (FlowNotFoundException | SwitchNotFoundException e) {
// tested in the FlowValidationServiceTest
}
}
@Override
public void sendNorthboundResponse(Message message) {
fail();
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
}
for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
}
for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
}
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowOperationsBolt method processFlowMirrorPointsDumpRequest.
private List<FlowMirrorPointsDumpResponse> processFlowMirrorPointsDumpRequest(FlowMirrorPointsDumpRequest readRequest) {
try {
String flowId = readRequest.getFlowId();
List<FlowMirrorPoint> points = flowOperationsService.getFlowMirrorPoints(flowId);
FlowMirrorPointsDumpResponse response = FlowMirrorPointsDumpResponse.builder().flowId(flowId).points(points).build();
return Collections.singletonList(response);
} catch (FlowNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow mirror points: " + e.getMessage(), "Flow not found");
} catch (Exception e) {
throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow mirror points: " + e.getMessage(), "Internal Error");
}
}
use of org.openkilda.wfm.error.FlowNotFoundException 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);
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class YFlowValidationService method validateYFlowResources.
/**
* Validate y-flow.
*/
public YFlowDiscrepancyDto validateYFlowResources(String yFlowId, List<SwitchFlowEntries> actualSwitchFlowEntries, List<SwitchMeterEntries> actualSwitchMeterEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> actualRules = new HashMap<>();
for (SwitchFlowEntries switchRulesEntries : actualSwitchFlowEntries) {
SwitchMeterEntries switchMeters = actualSwitchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, null);
actualRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
}
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId));
List<SimpleSwitchRule> expectedRules = new ArrayList<>();
for (YSubFlow subFlow : yFlow.getSubFlows()) {
Flow flow = subFlow.getFlow();
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getForwardPathId(), flow.getReversePathId(), yFlow.getYPoint(), yFlow.getMeterId()));
if (flow.isAllocateProtectedPath()) {
if (flow.getProtectedForwardPathId() != null && flow.getProtectedReversePathId() != null) {
expectedRules.addAll(buildSimpleSwitchRules(flow, yFlow.getSharedEndpoint().getSwitchId(), yFlow.getSharedEndpointMeterId(), flow.getProtectedForwardPathId(), flow.getProtectedReversePathId(), yFlow.getProtectedPathYPoint(), yFlow.getProtectedPathMeterId()));
} else {
log.warn("Sub-flow {} of y-flow {} has no expected protected paths", flow.getFlowId(), yFlowId);
}
}
}
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
for (SimpleSwitchRule simpleRule : expectedRules) {
discrepancies.addAll(simpleSwitchRuleComparator.findDiscrepancy(simpleRule, actualRules.get(simpleRule.getSwitchId())));
}
return YFlowDiscrepancyDto.builder().discrepancies(discrepancies).asExpected(discrepancies.isEmpty()).build();
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowOperationsService method updateFlow.
/**
* Partial update flow.
*/
public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException {
String flowId = flowPatch.getFlowId();
if (yFlowRepository.isSubFlow(flowId)) {
throw new MessageException(ErrorType.REQUEST_INVALID, "Could not modify flow", format("%s is a sub-flow of a y-flow. Operations on sub-flows are forbidden.", flowId));
}
UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> {
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (!foundFlow.isPresent()) {
return Optional.<UpdateFlowResult>empty();
}
Flow currentFlow = foundFlow.get();
validateFlow(flowPatch, currentFlow);
final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow);
Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency);
Optional.ofNullable(flowPatch.getMaxLatencyTier2()).ifPresent(currentFlow::setMaxLatencyTier2);
Optional.ofNullable(flowPatch.getPriority()).ifPresent(currentFlow::setPriority);
Optional.ofNullable(flowPatch.getPinned()).ifPresent(currentFlow::setPinned);
Optional.ofNullable(flowPatch.getDescription()).ifPresent(currentFlow::setDescription);
Optional.ofNullable(flowPatch.getTargetPathComputationStrategy()).ifPresent(currentFlow::setTargetPathComputationStrategy);
Optional.ofNullable(flowPatch.getStrictBandwidth()).ifPresent(currentFlow::setStrictBandwidth);
Optional.ofNullable(flowPatch.getPeriodicPings()).ifPresent(periodicPings -> {
boolean oldPeriodicPings = currentFlow.isPeriodicPings();
currentFlow.setPeriodicPings(periodicPings);
if (oldPeriodicPings != currentFlow.isPeriodicPings()) {
carrier.emitPeriodicPingUpdate(flowId, flowPatch.getPeriodicPings());
}
});
return Optional.of(result.updatedFlow(currentFlow).build());
}).orElseThrow(() -> new FlowNotFoundException(flowId));
Flow updatedFlow = updateFlowResult.getUpdatedFlow();
if (updateFlowResult.isNeedUpdateFlow()) {
FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow);
addChangedFields(flowRequest, flowPatch);
flowDashboardLogger.onFlowPatchUpdate(RequestedFlowMapper.INSTANCE.toFlow(flowRequest));
carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch));
} else {
flowDashboardLogger.onFlowPatchUpdate(updatedFlow);
carrier.sendNorthboundResponse(buildFlowResponse(updatedFlow));
}
return updateFlowResult.getUpdatedFlow();
}
Aggregations