Search in sources :

Example 6 with FlowNotFoundException

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);
    }
}
Also used : DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) Message(org.openkilda.messaging.Message) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) CommandContext(org.openkilda.wfm.CommandContext) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) FlowValidationRequest(org.openkilda.messaging.command.flow.FlowValidationRequest) InfoData(org.openkilda.messaging.info.InfoData) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) List(java.util.List) CommandData(org.openkilda.messaging.command.CommandData) Test(org.junit.Test)

Example 7 with FlowNotFoundException

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");
    }
}
Also used : FlowMirrorPoint(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse.FlowMirrorPoint) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) FlowMirrorPointsDumpResponse(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse) MessageException(org.openkilda.messaging.error.MessageException) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException)

Example 8 with FlowNotFoundException

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);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) CommandContext(org.openkilda.wfm.CommandContext) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) NbTrackableAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event) Optional(java.util.Optional) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Example 9 with FlowNotFoundException

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();
}
Also used : YFlow(org.openkilda.model.YFlow) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) HashMap(java.util.HashMap) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) PathDiscrepancyEntity(org.openkilda.messaging.info.flow.PathDiscrepancyEntity) SwitchId(org.openkilda.model.SwitchId) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with FlowNotFoundException

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();
}
Also used : MAX_LATENCY(org.openkilda.model.PathComputationStrategy.MAX_LATENCY) FlowStats(org.openkilda.model.FlowStats) IslNotFoundException(org.openkilda.wfm.error.IslNotFoundException) FlowPath(org.openkilda.model.FlowPath) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) FlowMirrorPoint(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse.FlowMirrorPoint) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) SwitchConnectedDeviceRepository(org.openkilda.persistence.repositories.SwitchConnectedDeviceRepository) IslEndpoint(org.openkilda.model.IslEndpoint) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) PathComputationStrategy(org.openkilda.model.PathComputationStrategy) YSubFlow(org.openkilda.model.YSubFlow) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) FlowPatch(org.openkilda.messaging.model.FlowPatch) Builder(lombok.Builder) FlowsDumpRequest(org.openkilda.messaging.nbtopology.request.FlowsDumpRequest) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) Optional(java.util.Optional) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ListUtils.union(org.apache.commons.collections4.ListUtils.union) TransactionManager(org.openkilda.persistence.tx.TransactionManager) FlowStatsRepository(org.openkilda.persistence.repositories.FlowStatsRepository) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) PathNodePayload(org.openkilda.messaging.payload.flow.PathNodePayload) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) PatchEndpoint(org.openkilda.messaging.model.PatchEndpoint) FlowPathDtoBuilder(org.openkilda.messaging.model.FlowPathDto.FlowPathDtoBuilder) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowPathDto(org.openkilda.messaging.model.FlowPathDto) YFlow(org.openkilda.model.YFlow) FlowProtectedPathDto(org.openkilda.messaging.model.FlowPathDto.FlowProtectedPathDto) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) RequestedFlowMapper(org.openkilda.wfm.share.mappers.RequestedFlowMapper) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) ErrorType(org.openkilda.messaging.error.ErrorType) LATENCY(org.openkilda.model.PathComputationStrategy.LATENCY) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowMapper(org.openkilda.wfm.share.mappers.FlowMapper) FlowFilter(org.openkilda.model.FlowFilter) SwitchId(org.openkilda.model.SwitchId) FlowOperationsCarrier(org.openkilda.wfm.topology.nbworker.bolts.FlowOperationsCarrier) Data(lombok.Data) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) Optional(java.util.Optional) MessageException(org.openkilda.messaging.error.MessageException) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Aggregations

FlowNotFoundException (org.openkilda.wfm.error.FlowNotFoundException)13 Flow (org.openkilda.model.Flow)9 List (java.util.List)6 SwitchId (org.openkilda.model.SwitchId)6 YFlow (org.openkilda.model.YFlow)6 YSubFlow (org.openkilda.model.YSubFlow)6 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)6 ArrayList (java.util.ArrayList)5 Slf4j (lombok.extern.slf4j.Slf4j)4 MessageException (org.openkilda.messaging.error.MessageException)4 Duration (java.time.Duration)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 RetryPolicy (net.jodah.failsafe.RetryPolicy)3 FlowResponse (org.openkilda.messaging.info.flow.FlowResponse)3