Search in sources :

Example 6 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class Gate method listen.

@KafkaHandler
void listen(ClearFlows data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
    Builder builder = CommandPacket.newBuilder();
    builder.setType(Type.CLEAR_FLOWS);
    SwitchId switchId = new SwitchId(switchIdKey);
    FlowRttControl.ClearFlowsFilter clearFlowsFilter = FlowRttControl.ClearFlowsFilter.newBuilder().setDstMac(switchId.toMacAddress()).build();
    builder.addCommand(Any.pack(clearFlowsFilter));
    try {
        zeroMqClient.send(builder.build());
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data);
    }
}
Also used : Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SwitchId(org.openkilda.model.SwitchId) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 7 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class Gate method listen.

@KafkaHandler
void listen(@Payload AddIsl data) {
    Builder builder = CommandPacket.newBuilder();
    builder.setType(Type.ADD_ISL);
    SwitchId switchId = data.getSwitchId();
    String switchIdKey = switchId.toString();
    IslEndpoint endpoint = IslEndpoint.newBuilder().setSwitchId(switchIdKey).setPort(data.getPort()).build();
    IslRttControl.AddIsl addIsl = IslRttControl.AddIsl.newBuilder().setIsl(endpoint).setSwitchMac(switchId.toMacAddress()).setUdpSrcPort(islRttUdpSrcPortOffset + data.getPort()).setTransitEncapsulationType(IslRttControl.AddIsl.EncapsulationType.VLAN).setTransitTunnelId(switchToVlanMap.get(switchIdKey)).setHashCode(data.hashCode()).build();
    builder.addCommand(Any.pack(addIsl));
    try {
        zeroMqClient.send(builder.build());
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data, e);
    }
}
Also used : IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SwitchId(org.openkilda.model.SwitchId) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 8 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class Gate method listen.

@KafkaHandler
void listen(PushSettings data) {
    Builder builder = CommandPacket.newBuilder();
    Control.PushSettings pushSettings = Control.PushSettings.newBuilder().setPacketGenerationIntervalInMs(data.getPacketGenerationIntervalInMs()).build();
    builder.setType(Type.PUSH_SETTINGS);
    builder.addCommand(Any.pack(pushSettings));
    CommandPacket packet = builder.build();
    try {
        zeroMqClient.send(packet);
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data);
    }
}
Also used : Control(org.openkilda.server42.control.messaging.Control) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 9 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class Gate method listen.

@KafkaHandler
void listen(@Payload ClearIsls data) {
    Builder builder = CommandPacket.newBuilder();
    builder.setType(Type.CLEAR_ISLS);
    IslRttControl.ClearIslsFilter clearIslsFilter = IslRttControl.ClearIslsFilter.newBuilder().setSwitchId(data.getSwitchId().toString()).build();
    builder.addCommand(Any.pack(clearIslsFilter));
    try {
        zeroMqClient.send(builder.build());
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data, e);
    }
}
Also used : Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 10 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class KafkaMessageListener method onMessage.

/**
 * Handles all messages from kafka and sends to corresponding component for further processing.
 *
 * @param message received  message.
 */
@KafkaHandler
public void onMessage(@Header(name = KafkaHeaders.RECEIVED_MESSAGE_KEY, required = false) String key, Message message) {
    try (MDCCloseable closable = MDC.putCloseable(Utils.CORRELATION_ID, message.getCorrelationId())) {
        log.debug("Message received: {} - {}", Thread.currentThread().getId(), message);
        messageProcessor.processRequest(message, key);
    }
}
Also used : MDCCloseable(org.slf4j.MDC.MDCCloseable) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Aggregations

KafkaHandler (org.springframework.kafka.annotation.KafkaHandler)11 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 Builder (org.openkilda.server42.control.messaging.Control.CommandPacket.Builder)7 IslRttControl (org.openkilda.server42.control.messaging.islrtt.IslRttControl)5 Any (com.google.protobuf.Any)4 CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)4 CommandPacketResponse (org.openkilda.server42.control.messaging.Control.CommandPacketResponse)4 SwitchId (org.openkilda.model.SwitchId)3 FlowRttControl (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)3 HashSet (java.util.HashSet)2 AddFlow (org.openkilda.server42.control.messaging.flowrtt.AddFlow)2 Flow (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow)2 RemoveFlow (org.openkilda.server42.control.messaging.flowrtt.RemoveFlow)2 IslEndpoint (org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint)2 MDCCloseable (org.slf4j.MDC.MDCCloseable)2 Control (org.openkilda.server42.control.messaging.Control)1 ListFlowsResponse (org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse)1 ListIslsResponse (org.openkilda.server42.control.messaging.islrtt.ListIslsResponse)1