use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData in project open-kilda by telstra.
the class RerouteQueueServiceTest method shouldSendThrottledRequestOnFlushWindowEvent.
@Test
public void shouldSendThrottledRequestOnFlushWindowEvent() {
FlowThrottlingData throttling = getFlowThrottlingData(flow, CORRELATION_ID).build();
RerouteQueue rerouteQueue = RerouteQueue.builder().throttling(throttling).build();
rerouteQueueService.getReroutes().put(FLOW_ID, rerouteQueue);
rerouteQueueService.flushThrottling();
assertEquals(throttling, rerouteQueue.getInProgress());
assertNull(rerouteQueue.getPending());
assertNull(rerouteQueue.getThrottling());
FlowRerouteRequest expectedRequest = getFlowRerouteRequest(FLOW_ID, throttling);
verify(carrier).sendRerouteRequest(any(String.class), eq(expectedRequest));
}
use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData in project open-kilda by telstra.
the class RerouteQueueServiceTest method shouldNotInjectRetryWhenRetryCountIsExceeded.
@Test
public void shouldNotInjectRetryWhenRetryCountIsExceeded() {
FlowThrottlingData inProgress = getFlowThrottlingData(flow, CORRELATION_ID).build();
inProgress.setRetryCounter(4);
RerouteQueue rerouteQueue = RerouteQueue.builder().inProgress(inProgress).build();
rerouteQueueService.getReroutes().put(FLOW_ID, rerouteQueue);
rerouteQueueService.handleTimeout(CORRELATION_ID);
assertNull(rerouteQueue.getInProgress());
assertNull(rerouteQueue.getPending());
assertNull(rerouteQueue.getThrottling());
}
use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData in project open-kilda by telstra.
the class RerouteQueueService method flushThrottling.
/**
* Move reroute requests form throttling to pending/in-progress.
*/
public void flushThrottling() {
Map<String, FlowThrottlingData> requestsToSend = new HashMap<>();
reroutes.forEach((flowId, rerouteQueue) -> rerouteQueue.flushThrottling().ifPresent(flowThrottlingData -> requestsToSend.put(flowId, flowThrottlingData)));
log.info("Send reroute requests for flows {}", requestsToSend.keySet());
Comparator<FlowThrottlingData> comparator = ((Comparator<FlowThrottlingData>) this::comparePriority).thenComparing(this::compareAvailableBandwidth).thenComparing(this::compareTimeCreate);
requestsToSend.entrySet().stream().sorted(Map.Entry.comparingByValue(comparator)).forEach(es -> {
String flowId = es.getKey();
FlowThrottlingData flowThrottlingData = es.getValue();
sendRerouteRequest(flowId, flowThrottlingData);
});
}
use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData in project open-kilda by telstra.
the class RerouteQueueService method injectRetry.
private void injectRetry(String flowId, RerouteQueue rerouteQueue, boolean ignoreBandwidth) {
log.info("Injecting retry for flow {} wuth ignore b/w flag {}", flowId, ignoreBandwidth);
FlowThrottlingData retryRequest = rerouteQueue.getInProgress();
if (retryRequest == null) {
throw new IllegalStateException(format("Can not retry 'null' reroute request for flow %s.", flowId));
}
retryRequest.setIgnoreBandwidth(computeIgnoreBandwidth(retryRequest, ignoreBandwidth));
if (retryRequest.getRetryCounter() < maxRetry) {
retryRequest.increaseRetryCounter();
String retryCorrelationId = new CommandContext(retryRequest.getCorrelationId()).fork(format("retry #%d ignore_bw %b", retryRequest.getRetryCounter(), retryRequest.isIgnoreBandwidth())).getCorrelationId();
retryRequest.setCorrelationId(retryCorrelationId);
FlowThrottlingData toSend = rerouteQueue.processRetryRequest(retryRequest, carrier);
sendRerouteRequest(flowId, toSend);
} else {
log.error("No more retries available for reroute request {}.", retryRequest);
FlowThrottlingData toSend = rerouteQueue.processPending();
if (toSend != null) {
toSend.setIgnoreBandwidth(computeIgnoreBandwidth(toSend, ignoreBandwidth));
}
sendRerouteRequest(flowId, toSend);
}
}
use of org.openkilda.wfm.topology.reroute.model.FlowThrottlingData in project open-kilda by telstra.
the class RerouteQueueService method processRerouteResult.
/**
* Process reroute result. Check fail reason, decide if retry is needed and schedule it if yes.
*
* @param rerouteResultInfoData reroute result
* @param correlationId correlation id
*/
public void processRerouteResult(RerouteResultInfoData rerouteResultInfoData, String correlationId) {
String flowId = rerouteResultInfoData.getFlowId();
RerouteQueue rerouteQueue = getRerouteQueue(flowId);
FlowThrottlingData inProgress = rerouteQueue.getInProgress();
if (inProgress == null || !Objects.equals(inProgress.getCorrelationId(), correlationId)) {
log.error("Skipped unexpected reroute result for flow {} with correlation id {}.", flowId, correlationId);
return;
}
carrier.cancelTimeout(correlationId);
if (rerouteResultInfoData.isSuccess()) {
FlowThrottlingData toSend = rerouteQueue.processPending();
sendRerouteRequest(flowId, toSend);
} else {
RerouteError rerouteError = rerouteResultInfoData.getRerouteError();
if (isRetryRequired(flowId, rerouteError, rerouteResultInfoData.isYFlow())) {
injectRetry(flowId, rerouteQueue, rerouteError instanceof NoPathFoundError);
} else {
FlowThrottlingData toSend = rerouteQueue.processPending();
sendRerouteRequest(flowId, toSend);
}
}
}
Aggregations