use of org.openkilda.floodlight.api.request.SpeakerRequest 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.SpeakerRequest in project open-kilda by telstra.
the class SpeakerWorkerService method handleResponse.
/**
* Processes received response and forwards it to the hub component.
* @param key operation's key.
* @param response response payload.
*/
public void handleResponse(@NonNull String key, @NonNull SpeakerResponse response) throws PipelineException {
log.debug("Got a response from speaker {}", response);
SpeakerRequest pendingRequest = keyToRequest.remove(key);
if (pendingRequest != null) {
if (pendingRequest.getCommandId().equals(response.getCommandId())) {
carrier.sendResponse(key, response);
} else {
log.warn("Pending request's command id and received response's command id mismatch");
}
}
}
use of org.openkilda.floodlight.api.request.SpeakerRequest 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.SpeakerRequest 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.SpeakerRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method shouldFailSwapOnUnsuccessfulInstallation.
@Test
public void shouldFailSwapOnUnsuccessfulInstallation() {
// given
Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
// when
FlowPathSwapService service = makeService();
FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), true);
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) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
if (flowSegmentRequest.isInstallRequest() && failCounter > 0) {
service.handleAsyncResponse(dummyRequestKey, FlowErrorResponse.errorBuilder().messageContext(flowSegmentRequest.getMessageContext()).errorCode(ErrorCode.UNKNOWN).description(injectedErrorMessage).commandId(flowSegmentRequest.getCommandId()).metadata(flowSegmentRequest.getMetadata()).switchId(flowSegmentRequest.getSwitchId()).build());
failCounter--;
} else {
service.handleAsyncResponse(dummyRequestKey, buildSpeakerResponse(flowSegmentRequest));
}
} else {
fail();
}
}
// then
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathNotSwapped(origin, result);
verifyNorthboundSuccessResponse(carrier);
}
Aggregations