Search in sources :

Example 1 with FlowOperationsCarrier

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();
}
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

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Builder (lombok.Builder)1 Data (lombok.Data)1 Slf4j (lombok.extern.slf4j.Slf4j)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1