use of org.openkilda.wfm.topology.nbworker.bolts.FlowOperationsCarrier 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