use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class RecordHandler method doInstallFlowForSwitchManager.
/**
* Install of flow on the switch from SwitchManager topology.
*
* @param message with list of flows.
*/
private void doInstallFlowForSwitchManager(final CommandMessage message) {
InstallFlowForSwitchManagerRequest request = (InstallFlowForSwitchManagerRequest) message.getData();
String replyToTopic = context.getKafkaSwitchManagerTopic();
FlowSegmentResponseFactory responseFactory = new FlowSegmentSyncResponseFactory(message.getCorrelationId(), replyToTopic);
MessageContext messageContext = new MessageContext(message);
Optional<FlowSegmentWrapperCommand> syncCommand = makeSyncCommand(request.getFlowCommand(), messageContext, responseFactory);
if (syncCommand.isPresent()) {
handleSpeakerCommand(syncCommand.get());
return;
}
try {
installFlow(request.getFlowCommand());
} catch (SwitchOperationException e) {
logger.error("Error during flow installation", e);
ErrorData errorData = new ErrorData(ErrorType.INTERNAL_ERROR, "Error during flow installation", "Switch operation error");
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
} catch (FlowCommandException e) {
String errorMessage = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
logger.error("Failed to handle message {}: {}", message, errorMessage);
ErrorData errorData = new FlowCommandErrorData(e.getFlowId(), e.getCookie(), e.getTransactionId(), e.getErrorType(), errorMessage, e.getMessage());
ErrorMessage error = new ErrorMessage(errorData, System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), error);
}
InfoMessage response = new InfoMessage(new FlowInstallResponse(), System.currentTimeMillis(), message.getCorrelationId());
getKafkaProducer().sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class UpdateYFlowRulesAction method buildYFlowInstallRequest.
protected InstallSpeakerCommandsRequest buildYFlowInstallRequest(SwitchId switchId, PathId pathId, CommandContext context) {
List<OfCommand> ofCommands = buildYFlowOfCommands(switchId, pathId);
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
return new InstallSpeakerCommandsRequest(messageContext, switchId, commandId, ofCommands);
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class UpdateYFlowRulesAction method buildYFlowDeleteRequest.
protected DeleteSpeakerCommandsRequest buildYFlowDeleteRequest(SwitchId switchId, PathId pathId, CommandContext context) {
List<OfCommand> ofCommands = buildYFlowOfCommands(switchId, pathId);
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
return new DeleteSpeakerCommandsRequest(messageContext, switchId, commandId, ofCommands);
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class GroupInstallCommand method handleOfError.
@Override
public CompletableFuture<Optional<OFMessage>> handleOfError(OFErrorMsg response) {
CompletableFuture<Optional<OFMessage>> future = new CompletableFuture<>();
if (!isInstallConflict(response)) {
future.completeExceptionally(new SwitchErrorResponseException(getSw().getId(), String.format("Can't install group %s - %s", mirrorConfig.getGroupId(), response)));
return future;
}
log.info("Group conflict detected sw:{} group:{}", getSw().getId(), mirrorConfig.getGroupId());
GroupVerifyCommand verifyCommand = new GroupVerifyCommand(messageContext, switchId, mirrorConfig, flowTransitData);
propagateFutureResponse(future, commandProcessor.chain(verifyCommand).thenAccept(this::handleGroupVerify).thenApply(ignore -> Optional.empty()));
return future;
}
use of org.openkilda.messaging.MessageContext in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilder method makeEgressSegmentRequests.
private List<FlowSegmentRequestFactory> makeEgressSegmentRequests(CommandContext context, FlowPath path, FlowTransitEncapsulation encapsulation, PathSegment segment, FlowSideAdapter flowSide, FlowSideAdapter ingressFlowSide, MirrorContext mirrorContext) {
Flow flow = flowSide.getFlow();
PathSegmentSide segmentSide = makePathSegmentDestSide(segment);
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
FlowSegmentMetadata metadata = makeMetadata(path, ensureEqualMultiTableFlag(segmentSide.isMultiTable(), path.isDestWithMultiTable(), String.format("Last flow(id:%s, path:%s) segment and flow path level multi-table flags value " + "are incompatible to each other - segment(%s) != flow path(%s)", flow.getFlowId(), path.getPathId(), segmentSide.isMultiTable(), path.isDestWithMultiTable())));
List<FlowSegmentRequestFactory> egressFactories = new ArrayList<>();
if (!mirrorContext.isBuildMirrorFactoryOnly()) {
egressFactories.add(EgressFlowSegmentRequestFactory.builder().messageContext(messageContext).metadata(metadata).endpoint(flowSide.getEndpoint()).ingressEndpoint(ingressFlowSide.getEndpoint()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).build());
}
Optional<MirrorConfig> mirrorConfig = makeMirrorConfig(path, flowSide.getEndpoint(), mirrorContext);
if (mirrorConfig.isPresent() || mirrorContext.isRemoveFlowOperation()) {
FlowSegmentCookie mirrorCookie = path.getCookie().toBuilder().mirror(true).build();
egressFactories.add(EgressMirrorFlowSegmentRequestFactory.builder().messageContext(new MessageContext(commandIdGenerator.generate().toString(), context.getCorrelationId())).metadata(makeMetadata(metadata.getFlowId(), mirrorCookie, metadata.isMultiTable())).endpoint(flowSide.getEndpoint()).ingressEndpoint(ingressFlowSide.getEndpoint()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).mirrorConfig(mirrorConfig.orElse(null)).build());
}
return egressFactories;
}
Aggregations