use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.
the class SpeakerWorkerService method handleTimeout.
/**
* Handles operation timeout.
* @param key operation identifier.
*/
public void handleTimeout(@NonNull String key) throws PipelineException {
SpeakerRequest failedRequest = keyToRequest.remove(key);
if (failedRequest instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
carrier.sendResponse(key, response);
} else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
if (command instanceof FlowCommand) {
return ((FlowCommand) command).getData();
}
if (command instanceof MeterCommand) {
return ((MeterCommand) command).getData();
}
return ((GroupCommand) command).getData();
}).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
carrier.sendResponse(key, response);
}
}
use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method produceAsyncResponse.
private void produceAsyncResponse(FlowPathSwapService service, String fsmKey, SpeakerRequest speakerRequest) {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
commandResponse = buildSpeakerResponse((FlowSegmentRequest) speakerRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
service.handleAsyncResponse(fsmKey, commandResponse);
}
use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method shouldFailSwapOnUnsuccessfulYFlowRulesInstallation.
@Test
public void shouldFailSwapOnUnsuccessfulYFlowRulesInstallation() {
// given
Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
createTestYFlowForSubFlow(origin);
// when
FlowPathSwapService service = makeService();
FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
service.handleRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
int failCounter = 1;
SpeakerRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
commandResponse = buildSpeakerResponse((FlowSegmentRequest) speakerRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
if (failCounter > 0) {
commandResponse = buildErrorYFlowSpeakerResponse(speakerCommandsRequest);
failCounter--;
} else {
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
}
service.handleAsyncResponse(dummyRequestKey, commandResponse);
}
// then
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathNotSwapped(origin, result);
verifyNorthboundSuccessResponse(carrier);
}
use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method shouldFailSwapOnTimeoutDuringYFlowRulesInstallation.
@Test
public void shouldFailSwapOnTimeoutDuringYFlowRulesInstallation() {
// given
Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
createTestYFlowForSubFlow(origin);
// when
FlowPathSwapService service = makeService();
FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
service.handleRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
int failCounter = 1;
SpeakerRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest instanceof FlowSegmentRequest) {
service.handleAsyncResponse(dummyRequestKey, buildSpeakerResponse((FlowSegmentRequest) speakerRequest));
} else {
if (failCounter > 0) {
service.handleTimeout(dummyRequestKey);
failCounter--;
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
service.handleAsyncResponse(dummyRequestKey, buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest));
}
}
}
// then
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathNotSwapped(origin, result);
verifyNorthboundSuccessResponse(carrier);
}
use of org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest in project open-kilda by telstra.
the class YFlowDeleteServiceTest method handleSpeakerCommandsAndTimeoutRemove.
private void handleSpeakerCommandsAndTimeoutRemove(YFlowDeleteService yFlowDeleteService, String yFlowFsmKey) {
handleSpeakerRequests(request -> {
SpeakerResponse commandResponse;
if (request instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) request;
commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) request;
if (speakerCommandsRequest instanceof DeleteSpeakerCommandsRequest) {
try {
yFlowDeleteService.handleTimeout(yFlowFsmKey);
} catch (UnknownKeyException ex) {
// skip
}
} else {
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
handleAsyncResponse(yFlowDeleteService, yFlowFsmKey, commandResponse);
}
}
});
}
Aggregations