use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.
the class ValidateFlowAction method performWithResponse.
@TimedExecution("fsm.validate_flow")
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Set<IslEndpoint> affectedIsl = new HashSet<>(Optional.ofNullable(context.getAffectedIsl()).orElse(emptySet()));
dashboardLogger.onFlowPathReroute(flowId, affectedIsl, context.isForceReroute());
String rerouteReason = context.getRerouteReason();
stateMachine.saveNewEventToHistory("Started flow validation", FlowEventData.Event.REROUTE, rerouteReason == null ? FlowEventData.Initiator.NB : FlowEventData.Initiator.AUTO, rerouteReason == null ? null : "Reason: " + rerouteReason);
stateMachine.setRerouteReason(rerouteReason);
Flow flow = transactionManager.doInTransaction(() -> {
Flow foundFlow = getFlow(flowId);
if (foundFlow.getStatus() == FlowStatus.IN_PROGRESS) {
String message = format("Flow %s is in progress now", flowId);
stateMachine.setRerouteError(new RerouteError(message));
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, message);
}
if (!foundFlow.getSrcSwitch().isActive()) {
String message = format("Flow's %s src switch is not active", flowId);
stateMachine.setRerouteError(new RerouteError(message));
throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, message);
}
if (!foundFlow.getDestSwitch().isActive()) {
String message = format("Flow's %s dest switch is not active", flowId);
stateMachine.setRerouteError(new RerouteError(message));
throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, message);
}
stateMachine.setOriginalFlowStatus(foundFlow.getStatus());
stateMachine.setOriginalFlowStatusInfo(foundFlow.getStatusInfo());
stateMachine.setOriginalEncapsulationType(foundFlow.getEncapsulationType());
stateMachine.setOriginalPathComputationStrategy(foundFlow.getPathComputationStrategy());
stateMachine.setRecreateIfSamePath(!foundFlow.isActive() || context.isForceReroute());
stateMachine.setOriginalFlow(RequestedFlowMapper.INSTANCE.toRequestedFlow(foundFlow));
stateMachine.setPeriodicPingsEnabled(foundFlow.isPeriodicPings());
if (foundFlow.getTargetPathComputationStrategy() != null) {
foundFlow.setPathComputationStrategy(foundFlow.getTargetPathComputationStrategy());
foundFlow.setTargetPathComputationStrategy(null);
}
foundFlow.setStatus(FlowStatus.IN_PROGRESS);
return foundFlow;
});
if (featureTogglesRepository.getOrDefault().getFlowsRerouteUsingDefaultEncapType()) {
stateMachine.setNewEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
}
boolean reroutePrimary;
boolean rerouteProtected;
if (affectedIsl.isEmpty()) {
// no know affected ISLs
reroutePrimary = true;
rerouteProtected = true;
} else {
reroutePrimary = checkIsPathAffected(flow.getForwardPath(), affectedIsl) || checkIsPathAffected(flow.getReversePath(), affectedIsl);
rerouteProtected = checkIsPathAffected(flow.getProtectedForwardPath(), affectedIsl) || checkIsPathAffected(flow.getProtectedReversePath(), affectedIsl);
}
// check protected path presence
rerouteProtected &= flow.isAllocateProtectedPath();
if (!reroutePrimary && !rerouteProtected) {
throw new FlowProcessingException(ErrorType.NOT_FOUND, format("No paths of the flow %s are affected by failure on %s", flowId, affectedIsl.stream().map(IslEndpoint::toString).collect(Collectors.joining(","))));
}
if (reroutePrimary) {
log.info("Reroute for the flow {} will affect primary paths: {} / {}", flowId, flow.getForwardPathId(), flow.getReversePathId());
}
if (rerouteProtected) {
log.info("Reroute for the flow {} will affect protected paths: {} / {}", flowId, flow.getProtectedForwardPathId(), flow.getProtectedReversePathId());
}
stateMachine.setReroutePrimary(reroutePrimary);
stateMachine.setRerouteProtected(rerouteProtected);
stateMachine.setEffectivelyDown(context.isEffectivelyDown());
if (stateMachine.isRerouteProtected() && flow.isPinned()) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Flow %s is pinned, fail to reroute its protected paths", flowId));
}
stateMachine.setAffectedIsls(context.getAffectedIsl());
stateMachine.setForceReroute(context.isForceReroute());
stateMachine.setIgnoreBandwidth(context.isIgnoreBandwidth());
stateMachine.saveActionToHistory("Flow was validated successfully");
return Optional.empty();
}
use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.
the class FlowOperationsBolt method processGetFlowsForSwitchRequest.
@TimedExecution("get_flows_for_switch")
private List<FlowResponse> processGetFlowsForSwitchRequest(GetFlowsForSwitchRequest request) {
SwitchId srcSwitch = request.getSwitchId();
Integer srcPort = request.getPort();
try {
return flowOperationsService.getFlowsForEndpoint(srcSwitch, srcPort).stream().distinct().map(flowOperationsService::buildFlowResponse).collect(Collectors.toList());
} catch (SwitchNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
}
}
use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.
the class FlowOperationsBolt method processFlowReadRequest.
@TimedExecution("flow_read")
private List<FlowResponse> processFlowReadRequest(FlowReadRequest readRequest) {
try {
String flowId = readRequest.getFlowId();
Flow flow = flowOperationsService.getFlow(flowId);
FlowStats flowStats = flowOperationsService.getFlowStats(flowId);
FlowResponse response = flowOperationsService.buildFlowResponse(flow, flowStats);
return Collections.singletonList(response);
} catch (FlowNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, "Can not get flow: " + e.getMessage(), "Flow not found");
} catch (Exception e) {
log.error("Can not get flow", e);
throw new MessageException(ErrorType.INTERNAL_ERROR, "Can not get flow", "Internal Error");
}
}
use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.
the class FlowOperationsBolt method processRerouteFlowsForLinkRequest.
@TimedExecution("reroute_flows_for_link")
private List<FlowsResponse> processRerouteFlowsForLinkRequest(RerouteFlowsForIslRequest message) {
SwitchId srcSwitch = message.getSource().getDatapath();
Integer srcPort = message.getSource().getPortNumber();
SwitchId dstSwitch = message.getDestination().getDatapath();
Integer dstPort = message.getDestination().getPortNumber();
Collection<FlowPath> paths;
try {
paths = flowOperationsService.getFlowPathsForLink(srcSwitch, srcPort, dstSwitch, dstPort);
} catch (IslNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "ISL was not found.");
}
Set<IslEndpoint> affectedIslEndpoints = new HashSet<>();
affectedIslEndpoints.add(new IslEndpoint(srcSwitch, srcPort));
affectedIslEndpoints.add(new IslEndpoint(dstSwitch, dstPort));
sendRerouteRequest(paths, affectedIslEndpoints, format("initiated via Northbound, reroute all flows that go over the link %s_%d - %s_%d", srcSwitch, srcPort, dstSwitch, dstPort));
List<String> flowIds = paths.stream().map(FlowPath::getFlow).map(Flow::getFlowId).distinct().collect(Collectors.toList());
return Collections.singletonList(new FlowsResponse(flowIds));
}
use of org.openkilda.wfm.share.metrics.TimedExecution in project open-kilda by telstra.
the class AllocateProtectedResourcesAction method allocate.
@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
String flowId = stateMachine.getFlowId();
Flow tmpFlowCopy = getFlow(flowId);
// Detach the entity to avoid propagation to the database.
flowRepository.detach(tmpFlowCopy);
if (stateMachine.getNewEncapsulationType() != null) {
// This is for PCE to use proper (updated) encapsulation type.
tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
}
FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
PathId newForwardPathId = resourcesManager.generatePathId(flowId);
PathId newReversePathId = resourcesManager.generatePathId(flowId);
List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
pathsToReuse.addAll(stateMachine.getRejectedPaths());
log.debug("Finding a new protected path for flow {}", flowId);
GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
if (allocatedPaths != null) {
stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
if (!testNonOverlappingPath.test(allocatedPaths)) {
stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
} else {
log.debug("New protected paths have been allocated: {}", allocatedPaths);
stateMachine.setNewProtectedForwardPath(newForwardPathId);
stateMachine.setNewProtectedReversePath(newReversePathId);
log.debug("Allocating resources for a new protected path of flow {}", flowId);
FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
stateMachine.setNewProtectedResources(flowResources);
FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
log.debug("New protected paths have been created: {}", createdPaths);
saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
}
} else {
stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
}
}
Aggregations