Search in sources :

Example 1 with TCommandEcho

use of com.navercorp.pinpoint.thrift.dto.command.TCommandEcho 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)

Example 2 with TCommandEcho

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

the class EchoService method requestCommandService.

@Override
public TBase<?, ?> requestCommandService(TBase tbase) {
    logger.info("{} execute {}.", this, tbase);
    TCommandEcho param = (TCommandEcho) tbase;
    return param;
}
Also used : TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)

Example 3 with TCommandEcho

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

the class ProfilerCommandServiceLocatorTest method basicFunctionTest1.

@Test
public void basicFunctionTest1() throws Exception {
    ProfilerCommandLocatorBuilder builder = new ProfilerCommandLocatorBuilder();
    builder.addService(new EchoService());
    builder.addService(new EchoService());
    ProfilerCommandServiceLocator commandServiceLocator = builder.build();
    TCommandEcho commandEcho = new TCommandEcho();
    Assert.assertEquals(1, commandServiceLocator.getCommandServiceClasses().size());
    Assert.assertEquals(1, commandServiceLocator.getCommandServiceCodes().size());
    Assert.assertTrue(commandServiceLocator.getCommandServiceCodes().contains(TCommandType.getType(commandEcho.getClass()).getCode()));
    Assert.assertNotNull(commandServiceLocator.getService(commandEcho));
    Assert.assertNotNull(commandServiceLocator.getRequestService(commandEcho));
    Assert.assertNull(commandServiceLocator.getSimpleService(commandEcho));
    Assert.assertNull(commandServiceLocator.getStreamService(commandEcho));
}
Also used : EchoService(com.navercorp.pinpoint.profiler.receiver.service.EchoService) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) Test(org.junit.Test)

Example 4 with TCommandEcho

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

the class CommandController method echo.

@RequestMapping(value = "/echo", method = RequestMethod.GET)
public ModelAndView echo(@RequestParam("applicationName") String applicationName, @RequestParam("agentId") String agentId, @RequestParam("startTimeStamp") long startTimeStamp, @RequestParam("message") String message) throws TException {
    AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId, startTimeStamp);
    if (agentInfo == null) {
        return createResponse(false, String.format("Can't find suitable PinpointServer(%s/%s/%d).", applicationName, agentId, startTimeStamp));
    }
    TCommandEcho echo = new TCommandEcho();
    echo.setMessage(message);
    try {
        PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, echo);
        if (pinpointRouteResponse != null && pinpointRouteResponse.getRouteResult() == TRouteResult.OK) {
            TBase<?, ?> result = pinpointRouteResponse.getResponse();
            if (result == null) {
                return createResponse(false, "result null.");
            } else if (result instanceof TCommandEcho) {
                return createResponse(true, ((TCommandEcho) result).getMessage());
            } else if (result instanceof TResult) {
                return createResponse(false, ((TResult) result).getMessage());
            } else {
                return createResponse(false, result.toString());
            }
        } else {
            return createResponse(false, "unknown");
        }
    } catch (TException e) {
        return createResponse(false, e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) PinpointRouteResponse(com.navercorp.pinpoint.web.cluster.PinpointRouteResponse) TResult(com.navercorp.pinpoint.thrift.dto.TResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)4 Test (org.junit.Test)2 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)1 AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)1 EchoService (com.navercorp.pinpoint.profiler.receiver.service.EchoService)1 TResult (com.navercorp.pinpoint.thrift.dto.TResult)1 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)1 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)1 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)1 PinpointRouteResponse (com.navercorp.pinpoint.web.cluster.PinpointRouteResponse)1 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)1 TException (org.apache.thrift.TException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1