Search in sources :

Example 1 with GetPacketInOutStatsRequest

use of org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest in project open-kilda by telstra.

the class StatsRequesterBolt method emitGrpcStatsRequest.

private void emitGrpcStatsRequest(Tuple input, Switch sw) {
    Optional<String> address = Optional.ofNullable(sw.getSocketAddress()).map(IpSocketAddress::getAddress);
    if (!address.isPresent()) {
        return;
    }
    GetPacketInOutStatsRequest packetInOutStatsRequest = new GetPacketInOutStatsRequest(address.get(), sw.getSwitchId());
    String correlationId = getCommandContext().getCorrelationId().concat(" : ").concat(address.get());
    CommandMessage grpcRequest = new CommandMessage(packetInOutStatsRequest, System.currentTimeMillis(), correlationId);
    emit(GRPC_REQUEST_STREAM, input, new Values(grpcRequest));
}
Also used : Values(org.apache.storm.tuple.Values) GetPacketInOutStatsRequest(org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest) IpSocketAddress(org.openkilda.model.IpSocketAddress) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 2 with GetPacketInOutStatsRequest

use of org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest in project open-kilda by telstra.

the class SpeakerStatsRequesterBoltTest method requestGrpcStatsForNoviflowSwitchesTest.

@Test
public void requestGrpcStatsForNoviflowSwitchesTest() {
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setCollectGrpcStats(true);
    String address = "192.168.1.1";
    Switch sw = Switch.builder().switchId(new SwitchId(1)).socketAddress(new IpSocketAddress(address, 20)).build();
    sw.setOfDescriptionSoftware("NW500.1.1");
    when(switchRepository.findActive()).thenReturn(Collections.singleton(sw));
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    StatsRequesterBolt statsRequesterBolt = new StatsRequesterBolt(persistenceManager, ZooKeeperSpout.SPOUT_ID);
    statsRequesterBolt.prepare(Collections.emptyMap(), topologyContext, output);
    statsRequesterBolt.execute(startTuple);
    verify(output).emit(eq(ZkStreams.ZK.toString()), any(Tuple.class), anyList());
    statsRequesterBolt.execute(input);
    ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
    verify(output, times(1)).emit(eq(STATS_REQUEST_STREAM), any(Tuple.class), anyList());
    verify(output, times(1)).emit(eq(GRPC_REQUEST_STREAM), any(Tuple.class), values.capture());
    Values capturedValues = values.getValue();
    assertTrue(capturedValues.get(0) instanceof CommandMessage);
    CommandMessage commandMessage = (CommandMessage) capturedValues.get(0);
    assertTrue(commandMessage.getData() instanceof GetPacketInOutStatsRequest);
    GetPacketInOutStatsRequest request = (GetPacketInOutStatsRequest) commandMessage.getData();
    assertEquals(address, request.getAddress());
}
Also used : Switch(org.openkilda.model.Switch) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) GetPacketInOutStatsRequest(org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest) IpSocketAddress(org.openkilda.model.IpSocketAddress) Tuple(org.apache.storm.tuple.Tuple) CommandMessage(org.openkilda.messaging.command.CommandMessage) Test(org.junit.Test)

Example 3 with GetPacketInOutStatsRequest

use of org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest in project open-kilda by telstra.

the class MessageProcessor method handleCommandMessage.

private void handleCommandMessage(CommandMessage command, String key) {
    CommandData data = command.getData();
    String correlationId = command.getCorrelationId();
    CompletableFuture<Response> result;
    if (data instanceof CreateLogicalPortRequest) {
        result = handleCreateLogicalPortRequest((CreateLogicalPortRequest) data);
    } else if (data instanceof DumpLogicalPortsRequest) {
        result = handleDumpLogicalPortsRequest((DumpLogicalPortsRequest) data);
    } else if (data instanceof GetSwitchInfoRequest) {
        result = handleGetSwitchInfoRequest((GetSwitchInfoRequest) data);
    } else if (data instanceof GetPacketInOutStatsRequest) {
        result = handleGetPacketInOutStatsRequest((GetPacketInOutStatsRequest) data);
    } else if (data instanceof DeleteLogicalPortRequest) {
        result = handleDeleteLogicalPortRequest((DeleteLogicalPortRequest) data);
    } else {
        result = unhandledMessage(command);
    }
    result.thenAccept(response -> sendResponse(response, correlationId, key));
}
Also used : GetSwitchInfoResponse(org.openkilda.messaging.info.grpc.GetSwitchInfoResponse) CreateLogicalPortResponse(org.openkilda.messaging.info.grpc.CreateLogicalPortResponse) GetPacketInOutStatsResponse(org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse) DeleteLogicalPortResponse(org.openkilda.messaging.info.grpc.DeleteLogicalPortResponse) DumpLogicalPortsResponse(org.openkilda.messaging.info.grpc.DumpLogicalPortsResponse) DeleteLogicalPortRequest(org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest) GetSwitchInfoRequest(org.openkilda.messaging.command.grpc.GetSwitchInfoRequest) DumpLogicalPortsRequest(org.openkilda.messaging.command.grpc.DumpLogicalPortsRequest) GetPacketInOutStatsRequest(org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest) CommandData(org.openkilda.messaging.command.CommandData) CreateLogicalPortRequest(org.openkilda.messaging.command.grpc.CreateLogicalPortRequest)

Aggregations

GetPacketInOutStatsRequest (org.openkilda.messaging.command.grpc.GetPacketInOutStatsRequest)3 Values (org.apache.storm.tuple.Values)2 CommandMessage (org.openkilda.messaging.command.CommandMessage)2 IpSocketAddress (org.openkilda.model.IpSocketAddress)2 Tuple (org.apache.storm.tuple.Tuple)1 Test (org.junit.Test)1 CommandData (org.openkilda.messaging.command.CommandData)1 CreateLogicalPortRequest (org.openkilda.messaging.command.grpc.CreateLogicalPortRequest)1 DeleteLogicalPortRequest (org.openkilda.messaging.command.grpc.DeleteLogicalPortRequest)1 DumpLogicalPortsRequest (org.openkilda.messaging.command.grpc.DumpLogicalPortsRequest)1 GetSwitchInfoRequest (org.openkilda.messaging.command.grpc.GetSwitchInfoRequest)1 CreateLogicalPortResponse (org.openkilda.messaging.info.grpc.CreateLogicalPortResponse)1 DeleteLogicalPortResponse (org.openkilda.messaging.info.grpc.DeleteLogicalPortResponse)1 DumpLogicalPortsResponse (org.openkilda.messaging.info.grpc.DumpLogicalPortsResponse)1 GetPacketInOutStatsResponse (org.openkilda.messaging.info.grpc.GetPacketInOutStatsResponse)1 GetSwitchInfoResponse (org.openkilda.messaging.info.grpc.GetSwitchInfoResponse)1 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)1 Switch (org.openkilda.model.Switch)1 SwitchId (org.openkilda.model.SwitchId)1