src-java/flowhs-topology/flowhs-storm-topology/src/main/java/org/openkilda/wfm/topology/flowhs/validation/FlowValidator.java
/**
     * Ensure switches are exists.
     *
     * @param flow a flow to be validated.
     * @throws UnavailableFlowEndpointException if switch not found.
     */
Ensure switches are exists.
@param flow a flow to be validated.
@throws UnavailableFlowEndpointException if switch not found.
Ensure switches are exists . @param flow a flow to be validated . @throws UnavailableFlowEndpointException if switch not found .
@VisibleForTesting
    void checkSwitchesExistsAndActive(RequestedFlow flow) throws UnavailableFlowEndpointException {
        final SwitchId sourceId = flow.getSrcSwitch();
        final SwitchId destinationId = flow.getDestSwitch();
        boolean sourceSwitchAvailable;
        boolean destinationSwitchAvailable;
        if (Objects.equals(sourceId, destinationId)) {
            Optional<Switch> sw = switchRepository.findById(sourceId);
            sourceSwitchAvailable = destinationSwitchAvailable = sw.map(Switch::isActive)
                    .orElse(false);
        } else {
            sourceSwitchAvailable = switchRepository.findById(sourceId)
                    .map(Switch::isActive)
                    .orElse(false);
            destinationSwitchAvailable = switchRepository.findById(destinationId)
                    .map(Switch::isActive)
                    .orElse(false);
        }
        if (!sourceSwitchAvailable && !destinationSwitchAvailable) {
            throw new UnavailableFlowEndpointException(
                    String.format("Source switch %s and Destination switch %s are not connected to the controller",
                            sourceId, destinationId));
        } else if (!sourceSwitchAvailable) {
            throw new UnavailableFlowEndpointException(
                    String.format("Source switch %s is not connected to the controller", sourceId));
        } else if (!destinationSwitchAvailable) {
            throw new UnavailableFlowEndpointException(
                    String.format("Destination switch %s is not connected to the controller", destinationId));
        }
    }
@ VisibleForTesting void checkSwitchesExistsAndActive ( RequestedFlow flow ) throws UnavailableFlowEndpointException { final SwitchId sourceId = flow . getSrcSwitch ( ) ; final SwitchId destinationId = flow . getDestSwitch ( ) ; boolean sourceSwitchAvailable ; boolean destinationSwitchAvailable ; if ( Objects . equals ( sourceId , destinationId ) ) { Optional < Switch > sw = switchRepository . findById ( sourceId ) ; sourceSwitchAvailable = destinationSwitchAvailable = sw . map ( Switch :: isActive ) . orElse ( false ) ; } else { sourceSwitchAvailable = switchRepository . findById ( sourceId ) . map ( Switch :: isActive ) . orElse ( false ) ; destinationSwitchAvailable = switchRepository . findById ( destinationId ) . map ( Switch :: isActive ) . orElse ( false ) ; } if ( ! sourceSwitchAvailable && ! destinationSwitchAvailable ) { throw new UnavailableFlowEndpointException ( String . format ( "Source switch %s and Destination switch %s are not connected to the controller" , sourceId , destinationId ) ) ; } else if ( ! sourceSwitchAvailable ) { throw new UnavailableFlowEndpointException ( String . format ( "Source switch %s is not connected to the controller" , sourceId ) ) ; } else if ( ! destinationSwitchAvailable ) { throw new UnavailableFlowEndpointException ( String . format ( "Destination switch %s is not connected to the controller" , destinationId ) ) ; } }
Ensure switches are exists.
Ensure switches are exists .