Search in sources :

Example 6 with TCommandTransfer

use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.

the class AgentServiceImpl method invoke.

@Override
public Map<AgentInfo, PinpointRouteResponse> invoke(List<AgentInfo> agentInfoList, byte[] payload, long timeout) throws TException {
    Map<AgentInfo, Future<ResponseMessage>> futureMap = new HashMap<>();
    for (AgentInfo agentInfo : agentInfoList) {
        TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
        PinpointSocket socket = clusterManager.getSocket(agentInfo);
        if (socket != null) {
            Future<ResponseMessage> future = socket.request(serializeRequest(transferObject));
            futureMap.put(agentInfo, future);
        } else {
            futureMap.put(agentInfo, null);
        }
    }
    long startTime = System.currentTimeMillis();
    Map<AgentInfo, PinpointRouteResponse> result = new HashMap<>();
    for (Map.Entry<AgentInfo, Future<ResponseMessage>> futureEntry : futureMap.entrySet()) {
        AgentInfo agentInfo = futureEntry.getKey();
        Future<ResponseMessage> future = futureEntry.getValue();
        PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout));
        result.put(agentInfo, response);
    }
    return result;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) HashMap(java.util.HashMap) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Future(com.navercorp.pinpoint.rpc.Future) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) FailedPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse) DefaultPinpointRouteResponse(com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with TCommandTransfer

use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.

the class ClusterPointRouter method handleRouteRequest.

private boolean handleRouteRequest(TCommandTransfer request, RequestPacket requestPacket, PinpointSocket pinpointSocket) {
    byte[] payload = ((TCommandTransfer) request).getPayload();
    TBase<?, ?> command = deserialize(payload);
    TCommandTransferResponse response = routeHandler.onRoute(new RequestEvent((TCommandTransfer) request, pinpointSocket.getRemoteAddress(), requestPacket.getRequestId(), command));
    pinpointSocket.response(requestPacket, serialize(response));
    return response.getRouteResult() == TRouteResult.OK;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) RequestEvent(com.navercorp.pinpoint.collector.cluster.route.RequestEvent)

Example 8 with TCommandTransfer

use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.

the class ClusterPointRouter method handleStreamRouteCreate.

private StreamCode handleStreamRouteCreate(TCommandTransfer request, StreamCreatePacket packet, ServerStreamChannelContext streamChannelContext) {
    byte[] payload = ((TCommandTransfer) request).getPayload();
    TBase<?, ?> command = deserialize(payload);
    if (command == null) {
        return StreamCode.TYPE_UNKNOWN;
    }
    TCommandTransferResponse response = streamRouteHandler.onRoute(new StreamEvent((TCommandTransfer) request, streamChannelContext, command));
    TRouteResult routeResult = response.getRouteResult();
    if (routeResult != TRouteResult.OK) {
        logger.warn("handleStreamRouteCreate failed. command:{}, routeResult:{}", command, routeResult);
        return convertToStreamCode(routeResult);
    }
    return StreamCode.OK;
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) StreamEvent(com.navercorp.pinpoint.collector.cluster.route.StreamEvent) TRouteResult(com.navercorp.pinpoint.thrift.dto.command.TRouteResult)

Example 9 with TCommandTransfer

use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_handle_serialization_of_request_events.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_handle_serialization_of_request_events() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.USER_THREAD_DUMP;
    final TCommandThreadDumpResponse expectedThreadDumpResponse = new TCommandThreadDumpResponse();
    final byte[] expectedThreadDumpResponseBody = new byte[0];
    final TCommandTransfer tCommandTransfer = new TCommandTransfer();
    tCommandTransfer.setAgentId(TEST_AGENT_ID);
    tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
    final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
    tCommandTransferResponse.setRouteResult(TRouteResult.OK);
    tCommandTransferResponse.setPayload(expectedThreadDumpResponseBody);
    final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
    when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
    when(deserializer.deserialize(expectedThreadDumpResponseBody)).thenReturn((TBase) expectedThreadDumpResponse);
    // when
    this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
    // then
    verify(this.agentEventDao, atLeast(1)).insert(argCaptor.capture());
    AgentEventBo actualAgentEventBo = argCaptor.getValue();
    assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
    assertEquals(expectedEventType, actualAgentEventBo.getEventType());
    assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody());
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Example 10 with TCommandTransfer

use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_ignore_request_events_with_unsupported_message_types.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_ignore_request_events_with_unsupported_message_types() throws Exception {
    // given
    final TCommandEcho mismatchingResponse = new TCommandEcho();
    final byte[] mismatchingResponseBody = new byte[0];
    final TCommandTransfer tCommandTransfer = new TCommandTransfer();
    tCommandTransfer.setAgentId(TEST_AGENT_ID);
    tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
    final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
    tCommandTransferResponse.setRouteResult(TRouteResult.OK);
    tCommandTransferResponse.setPayload(mismatchingResponseBody);
    final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
    when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
    when(deserializer.deserialize(mismatchingResponseBody)).thenReturn((TBase) mismatchingResponse);
    // when
    this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
    // then
    verify(this.agentEventDao, never()).insert(argCaptor.capture());
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Aggregations

TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)10 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)4 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)3 Test (org.junit.Test)3 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)2 AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)2 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)2 DefaultPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse)2 FailedPinpointRouteResponse (com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse)2 PinpointRouteResponse (com.navercorp.pinpoint.web.cluster.PinpointRouteResponse)2 RequestEvent (com.navercorp.pinpoint.collector.cluster.route.RequestEvent)1 StreamEvent (com.navercorp.pinpoint.collector.cluster.route.StreamEvent)1 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)1 Future (com.navercorp.pinpoint.rpc.Future)1 TResult (com.navercorp.pinpoint.thrift.dto.TResult)1 TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)1 TCommandThreadDumpResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse)1 TRouteResult (com.navercorp.pinpoint.thrift.dto.command.TRouteResult)1 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)1