use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.
the class RequestedFlowMapper method toFlowRequest.
/**
* Convert {@link Flow} to {@link FlowRequest}.
*/
public FlowRequest toFlowRequest(@NonNull Flow flow) {
FlowRequest request = generatedMap(flow);
request.setSource(new FlowSourceAdapter(flow).getEndpoint());
request.setDestination(new FlowDestAdapter(flow).getEndpoint());
if (flow.getPathComputationStrategy() != null) {
request.setPathComputationStrategy(flow.getPathComputationStrategy().toString().toLowerCase());
}
return request;
}
use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.
the class FlowCreateServiceTest method shouldCreateFlowWithProtectedPath.
@Test
public void shouldCreateFlowWithProtectedPath() throws Exception {
FlowRequest request = makeRequest().flowId("test_successful_flow_id").allocateProtectedPath(true).build();
when(pathComputer.getPath(makeFlowArgumentMatch(request.getFlowId()))).thenReturn(make2SwitchesPathPair()).thenReturn(make3SwitchesPathPair());
Flow result = testHappyPath(request, "successful_flow_create");
Assert.assertTrue(result.isAllocateProtectedPath());
verifyFlowPathStatus(result.getProtectedForwardPath(), FlowPathStatus.ACTIVE, "protected-forward");
verifyFlowPathStatus(result.getProtectedReversePath(), FlowPathStatus.ACTIVE, "protected-reverse");
}
use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.
the class FlowCreateServiceTest method shouldRollbackIfEgressRuleNotInstalled.
@Test
public void shouldRollbackIfEgressRuleNotInstalled() throws Exception {
when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
String key = "failed_flow_create";
FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
FlowCreateService service = makeService();
service.handleRequest(key, new CommandContext(), flowRequest);
Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest request;
int installCommands = 0;
int deleteCommands = 0;
while ((request = requests.poll()) != null) {
try {
if (request.isVerifyRequest()) {
service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
} else if (request.isInstallRequest()) {
installCommands++;
if (requests.size() > 1) {
handleResponse(service, key, request);
} else {
handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
}
} else if (request.isRemoveRequest()) {
deleteCommands++;
handleResponse(service, key, request);
}
} catch (UnknownKeyException ex) {
// skip
}
}
assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
// TODO(surabujin): do we really want to create flow without paths?
Assert.assertNull(result.getForwardPath());
Assert.assertNull(result.getReversePath());
}
use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.
the class FlowCreateServiceTest method testSpeakerCommandRetry.
private void testSpeakerCommandRetry(Class<?> failRequest, ErrorCode error, boolean mustRetry) throws Exception {
String key = "retries_non_ingress_installation";
FlowRequest flowRequest = makeRequest().flowId("dummy_flow_id").build();
int retriesLimit = 10;
FlowCreateService service = makeService(retriesLimit);
preparePathComputation(flowRequest.getFlowId(), make2SwitchesPathPair());
service.handleRequest(key, new CommandContext(), flowRequest);
Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
verifyNorthboundSuccessResponse(carrier);
Set<UUID> producedErrors = new HashSet<>();
Map<UUID, Integer> remainingRetries = new HashMap<>();
Map<UUID, Integer> seenCounter = new HashMap<>();
FlowSegmentRequest request;
while ((request = requests.poll()) != null) {
UUID commandId = request.getCommandId();
seenCounter.put(commandId, seenCounter.getOrDefault(commandId, 0) + 1);
Integer remaining = remainingRetries.getOrDefault(commandId, retriesLimit);
try {
if (failRequest.isInstance(request) && remaining > 0) {
producedErrors.add(commandId);
remainingRetries.put(commandId, remaining - 1);
handleErrorResponse(service, key, request, error);
} else if (request.isVerifyRequest()) {
service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
} else {
handleResponse(service, key, request);
}
} catch (UnknownKeyException ex) {
// skip
}
}
Assert.assertFalse(producedErrors.isEmpty());
for (Map.Entry<UUID, Integer> entry : seenCounter.entrySet()) {
if (!producedErrors.contains(entry.getKey())) {
continue;
}
Integer counter = entry.getValue();
if (mustRetry) {
Assert.assertEquals(retriesLimit + 1, (int) counter);
} else {
Assert.assertEquals(1, (int) counter);
}
}
if (mustRetry) {
Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.UP);
verifyFlowPathStatus(result.getForwardPath(), FlowPathStatus.ACTIVE, "forward");
verifyFlowPathStatus(result.getReversePath(), FlowPathStatus.ACTIVE, "reverse");
} else {
verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
}
}
use of org.openkilda.messaging.command.flow.FlowRequest in project open-kilda by telstra.
the class FlowCreateServiceTest method shouldCreatePinnedFlow.
@Test
public void shouldCreatePinnedFlow() throws Exception {
FlowRequest request = makeRequest().flowId("test_successful_flow_id").pinned(true).build();
preparePathComputation(request.getFlowId(), make3SwitchesPathPair());
Flow result = testHappyPath(request, "successful_flow_create");
Assert.assertTrue(result.isPinned());
}
Aggregations