@Test public void shouldUpdateMaxLatencyPriorityAndPinnedFlowFields() throws FlowNotFoundException { String testFlowId = "flow_id"; Long maxLatency = 555L; Integer priority = 777; PathComputationStrategy pathComputationStrategy = PathComputationStrategy.LATENCY; String description = "new_description"; Flow flow = new TestFlowBuilder() .flowId(testFlowId) .srcSwitch(createSwitch(SWITCH_ID_1)) .srcPort(1) .srcVlan(10) .destSwitch(createSwitch(SWITCH_ID_2)) .destPort(2) .destVlan(11) .encapsulationType(FlowEncapsulationType.TRANSIT_VLAN) .pathComputationStrategy(PathComputationStrategy.COST) .description("description") .status(FlowStatus.UP) .build(); flowRepository.add(flow); FlowPatch receivedFlow = FlowPatch.builder() .flowId(testFlowId) .maxLatency(maxLatency) .priority(priority) .pinned(true) .targetPathComputationStrategy(pathComputationStrategy) .description("new_description") .build(); Flow updatedFlow = flowOperationsService.updateFlow(new FlowCarrierImpl(), receivedFlow); assertEquals(maxLatency, updatedFlow.getMaxLatency()); assertEquals(priority, updatedFlow.getPriority()); assertEquals(pathComputationStrategy, updatedFlow.getTargetPathComputationStrategy()); assertEquals(description, updatedFlow.getDescription()); assertTrue(updatedFlow.isPinned()); receivedFlow = FlowPatch.builder() .flowId(testFlowId) .build(); updatedFlow = flowOperationsService.updateFlow(new FlowCarrierImpl(), receivedFlow); assertEquals(maxLatency, updatedFlow.getMaxLatency()); assertEquals(priority, updatedFlow.getPriority()); assertEquals(pathComputationStrategy, updatedFlow.getTargetPathComputationStrategy()); assertEquals(description, updatedFlow.getDescription()); assertTrue(updatedFlow.isPinned()); }
public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException { UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> { Optional<Flow> foundFlow = flowRepository.findById(flowPatch.getFlowId()); if (!foundFlow.isPresent()) { return Optional.<UpdateFlowResult>empty(); } Flow currentFlow = foundFlow.get(); final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow); Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency); 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.getPeriodicPings()).ifPresent(periodicPings -> { boolean oldPeriodicPings = currentFlow.isPeriodicPings(); currentFlow.setPeriodicPings(periodicPings); if (oldPeriodicPings != currentFlow.isPeriodicPings()) { carrier.emitPeriodicPingUpdate(flowPatch.getFlowId(), flowPatch.getPeriodicPings()); } }); flowDashboardLogger.onFlowPatchUpdate(currentFlow); return Optional.of(result.updatedFlow(currentFlow).build()); }).orElseThrow(() -> new FlowNotFoundException(flowPatch.getFlowId())); Flow updatedFlow = updateFlowResult.getUpdatedFlow(); if (updateFlowResult.isNeedUpdateFlow()) { FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow); carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch)); } else { carrier.sendNorthboundResponse(new FlowResponse(FlowMapper.INSTANCE.map(updatedFlow))); } return updateFlowResult.getUpdatedFlow(); }
FlowOperationsService { public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException { UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> { Optional<Flow> foundFlow = flowRepository.findById(flowPatch.getFlowId()); if (!foundFlow.isPresent()) { return Optional.<UpdateFlowResult>empty(); } Flow currentFlow = foundFlow.get(); final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow); Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency); 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.getPeriodicPings()).ifPresent(periodicPings -> { boolean oldPeriodicPings = currentFlow.isPeriodicPings(); currentFlow.setPeriodicPings(periodicPings); if (oldPeriodicPings != currentFlow.isPeriodicPings()) { carrier.emitPeriodicPingUpdate(flowPatch.getFlowId(), flowPatch.getPeriodicPings()); } }); flowDashboardLogger.onFlowPatchUpdate(currentFlow); return Optional.of(result.updatedFlow(currentFlow).build()); }).orElseThrow(() -> new FlowNotFoundException(flowPatch.getFlowId())); Flow updatedFlow = updateFlowResult.getUpdatedFlow(); if (updateFlowResult.isNeedUpdateFlow()) { FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow); carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch)); } else { carrier.sendNorthboundResponse(new FlowResponse(FlowMapper.INSTANCE.map(updatedFlow))); } return updateFlowResult.getUpdatedFlow(); } }
FlowOperationsService { public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException { UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> { Optional<Flow> foundFlow = flowRepository.findById(flowPatch.getFlowId()); if (!foundFlow.isPresent()) { return Optional.<UpdateFlowResult>empty(); } Flow currentFlow = foundFlow.get(); final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow); Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency); 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.getPeriodicPings()).ifPresent(periodicPings -> { boolean oldPeriodicPings = currentFlow.isPeriodicPings(); currentFlow.setPeriodicPings(periodicPings); if (oldPeriodicPings != currentFlow.isPeriodicPings()) { carrier.emitPeriodicPingUpdate(flowPatch.getFlowId(), flowPatch.getPeriodicPings()); } }); flowDashboardLogger.onFlowPatchUpdate(currentFlow); return Optional.of(result.updatedFlow(currentFlow).build()); }).orElseThrow(() -> new FlowNotFoundException(flowPatch.getFlowId())); Flow updatedFlow = updateFlowResult.getUpdatedFlow(); if (updateFlowResult.isNeedUpdateFlow()) { FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow); carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch)); } else { carrier.sendNorthboundResponse(new FlowResponse(FlowMapper.INSTANCE.map(updatedFlow))); } return updateFlowResult.getUpdatedFlow(); } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); }
FlowOperationsService { public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException { UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> { Optional<Flow> foundFlow = flowRepository.findById(flowPatch.getFlowId()); if (!foundFlow.isPresent()) { return Optional.<UpdateFlowResult>empty(); } Flow currentFlow = foundFlow.get(); final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow); Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency); 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.getPeriodicPings()).ifPresent(periodicPings -> { boolean oldPeriodicPings = currentFlow.isPeriodicPings(); currentFlow.setPeriodicPings(periodicPings); if (oldPeriodicPings != currentFlow.isPeriodicPings()) { carrier.emitPeriodicPingUpdate(flowPatch.getFlowId(), flowPatch.getPeriodicPings()); } }); flowDashboardLogger.onFlowPatchUpdate(currentFlow); return Optional.of(result.updatedFlow(currentFlow).build()); }).orElseThrow(() -> new FlowNotFoundException(flowPatch.getFlowId())); Flow updatedFlow = updateFlowResult.getUpdatedFlow(); if (updateFlowResult.isNeedUpdateFlow()) { FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow); carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch)); } else { carrier.sendNorthboundResponse(new FlowResponse(FlowMapper.INSTANCE.map(updatedFlow))); } return updateFlowResult.getUpdatedFlow(); } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort,
                                                    SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests(
            Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason); }
FlowOperationsService { public Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch) throws FlowNotFoundException { UpdateFlowResult updateFlowResult = transactionManager.doInTransaction(() -> { Optional<Flow> foundFlow = flowRepository.findById(flowPatch.getFlowId()); if (!foundFlow.isPresent()) { return Optional.<UpdateFlowResult>empty(); } Flow currentFlow = foundFlow.get(); final UpdateFlowResult.UpdateFlowResultBuilder result = prepareFlowUpdateResult(flowPatch, currentFlow); Optional.ofNullable(flowPatch.getMaxLatency()).ifPresent(currentFlow::setMaxLatency); 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.getPeriodicPings()).ifPresent(periodicPings -> { boolean oldPeriodicPings = currentFlow.isPeriodicPings(); currentFlow.setPeriodicPings(periodicPings); if (oldPeriodicPings != currentFlow.isPeriodicPings()) { carrier.emitPeriodicPingUpdate(flowPatch.getFlowId(), flowPatch.getPeriodicPings()); } }); flowDashboardLogger.onFlowPatchUpdate(currentFlow); return Optional.of(result.updatedFlow(currentFlow).build()); }).orElseThrow(() -> new FlowNotFoundException(flowPatch.getFlowId())); Flow updatedFlow = updateFlowResult.getUpdatedFlow(); if (updateFlowResult.isNeedUpdateFlow()) { FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(updatedFlow); carrier.sendUpdateRequest(addChangedFields(flowRequest, flowPatch)); } else { carrier.sendNorthboundResponse(new FlowResponse(FlowMapper.INSTANCE.map(updatedFlow))); } return updateFlowResult.getUpdatedFlow(); } FlowOperationsService(RepositoryFactory repositoryFactory, TransactionManager transactionManager); Flow getFlow(String flowId); Set<String> getDiverseFlowsId(String flowId, String groupId); Collection<Flow> getAllFlows(FlowsDumpRequest request); Collection<FlowPath> getFlowPathsForLink(SwitchId srcSwitchId, Integer srcPort,
                                                    SwitchId dstSwitchId, Integer dstPort); Collection<Flow> getFlowsForEndpoint(SwitchId switchId, Integer port); Collection<FlowPath> getFlowPathsForSwitch(SwitchId switchId); List<FlowPathDto> getFlowPath(String flowId); Flow updateFlow(FlowOperationsCarrier carrier, FlowPatch flowPatch); Collection<SwitchConnectedDevice> getFlowConnectedDevice(String flowId); List<FlowRerouteRequest> makeRerouteRequests(
            Collection<FlowPath> targetPaths, Set<IslEndpoint> affectedIslEndpoints, String reason);  }