Search in sources :

Example 1 with AgentProperty

use of com.navercorp.pinpoint.collector.service.async.AgentProperty in project pinpoint by naver.

the class AgentLifeCycleAsyncTaskServiceTest method runAndVerifyAgentLifeCycle.

private void runAndVerifyAgentLifeCycle(ManagedAgentLifeCycle managedAgentLifeCycle) {
    // given
    final AgentLifeCycleState expectedLifeCycleState = managedAgentLifeCycle.getMappedState();
    final int expectedEventCounter = managedAgentLifeCycle.getEventCounter();
    final long expectedEventIdentifier = createEventIdentifier(TEST_SOCKET_ID, expectedEventCounter);
    ArgumentCaptor<AgentLifeCycleBo> argCaptor = ArgumentCaptor.forClass(AgentLifeCycleBo.class);
    // when
    ChannelPropertiesFactory channelPropertiesFactory = new ChannelPropertiesFactory();
    ChannelProperties channelProperties = channelPropertiesFactory.newChannelProperties(TEST_CHANNEL_PROPERTIES);
    AgentProperty agentProperty = new AgentPropertyChannelAdaptor(channelProperties);
    long eventIdentifier = AgentLifeCycleAsyncTaskService.createEventIdentifier(TEST_SOCKET_ID, expectedEventCounter);
    this.agentLifeCycleAsyncTaskService.handleLifeCycleEvent(agentProperty, TEST_EVENT_TIMESTAMP, expectedLifeCycleState, eventIdentifier);
    verify(this.agentLifeCycleService, times(1)).insert(argCaptor.capture());
    // then
    AgentLifeCycleBo actualAgentLifeCycleBo = argCaptor.getValue();
    assertEquals(AgentLifeCycleBo.CURRENT_VERSION, actualAgentLifeCycleBo.getVersion());
    assertEquals(TEST_AGENT_ID, actualAgentLifeCycleBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentLifeCycleBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentLifeCycleBo.getEventTimestamp());
    assertEquals(expectedLifeCycleState, actualAgentLifeCycleBo.getAgentLifeCycleState());
    assertEquals(expectedEventIdentifier, actualAgentLifeCycleBo.getEventIdentifier());
}
Also used : ChannelProperties(com.navercorp.pinpoint.rpc.server.ChannelProperties) AgentPropertyChannelAdaptor(com.navercorp.pinpoint.collector.service.async.AgentPropertyChannelAdaptor) ChannelPropertiesFactory(com.navercorp.pinpoint.rpc.server.ChannelPropertiesFactory) AgentProperty(com.navercorp.pinpoint.collector.service.async.AgentProperty) AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)

Example 2 with AgentProperty

use of com.navercorp.pinpoint.collector.service.async.AgentProperty in project pinpoint by naver.

the class AgentLifeCycleChangeEventHandler method stateUpdated.

@Override
public void stateUpdated(PinpointServer pinpointServer, SocketStateCode updatedStateCode) {
    ManagedAgentLifeCycle managedAgentLifeCycle = ManagedAgentLifeCycle.getManagedAgentLifeCycleByStateCode(updatedStateCode);
    if (managedAgentLifeCycle == STATE_NOT_MANAGED) {
        return;
    } else {
        logger.info("stateUpdated(). pinpointServer:{}, updatedStateCode:{}", pinpointServer, updatedStateCode);
        final long eventTimestamp = System.currentTimeMillis();
        final Map<Object, Object> channelPropertiesMap = pinpointServer.getChannelProperties();
        // nullable
        final ChannelProperties channelProperties = channelPropertiesFactory.newChannelProperties(channelPropertiesMap);
        if (channelProperties == null) {
            logger.debug("channelProperties is null {}", pinpointServer);
            return;
        }
        final AgentProperty agentProperty = new AgentPropertyChannelAdaptor(channelProperties);
        final AgentLifeCycleState agentLifeCycleState = managedAgentLifeCycle.getMappedState();
        final long eventIdentifier = AgentLifeCycleAsyncTaskService.createEventIdentifier(channelProperties.getSocketId(), managedAgentLifeCycle.getEventCounter());
        this.agentLifeCycleAsyncTaskService.handleLifeCycleEvent(agentProperty, eventTimestamp, agentLifeCycleState, eventIdentifier);
        AgentEventType agentEventType = managedAgentLifeCycle.getMappedEvent();
        this.agentEventAsyncTaskService.handleEvent(agentProperty, eventTimestamp, agentEventType);
    }
}
Also used : ChannelProperties(com.navercorp.pinpoint.rpc.server.ChannelProperties) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentPropertyChannelAdaptor(com.navercorp.pinpoint.collector.service.async.AgentPropertyChannelAdaptor) ManagedAgentLifeCycle(com.navercorp.pinpoint.collector.util.ManagedAgentLifeCycle) AgentProperty(com.navercorp.pinpoint.collector.service.async.AgentProperty) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)

Example 3 with AgentProperty

use of com.navercorp.pinpoint.collector.service.async.AgentProperty in project pinpoint by naver.

the class AgentEventAsyncTaskServiceTest method handler_should_handle_events_with_empty_message_body.

@Test
public void handler_should_handle_events_with_empty_message_body() {
    // given
    final AgentEventType expectedEventType = AgentEventType.AGENT_CONNECTED;
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    // when
    ChannelProperties channelProperties = channelPropertiesFactory.newChannelProperties(TEST_CHANNEL_PROPERTIES);
    AgentProperty agentProperty = new AgentPropertyChannelAdaptor(channelProperties);
    this.agentEventAsyncTaskService.handleEvent(agentProperty, TEST_EVENT_TIMESTAMP, expectedEventType);
    verify(this.agentEventService, times(1)).insert(argCaptor.capture());
    // then
    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());
    assertEquals(0, actualAgentEventBo.getEventBody().length);
}
Also used : ChannelProperties(com.navercorp.pinpoint.rpc.server.ChannelProperties) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.event.AgentEventBo) AgentPropertyChannelAdaptor(com.navercorp.pinpoint.collector.service.async.AgentPropertyChannelAdaptor) AgentProperty(com.navercorp.pinpoint.collector.service.async.AgentProperty) Test(org.junit.Test)

Example 4 with AgentProperty

use of com.navercorp.pinpoint.collector.service.async.AgentProperty in project pinpoint by naver.

the class KeepAliveService method updateState.

public void updateState(PingSession pingSession, boolean closeState, AgentLifeCycleState agentLifeCycleState, AgentEventType agentEventType) {
    final Header header = pingSession.getHeader();
    if (header == null) {
        // TODO dump client ip for debug
        logger.warn("Not found request header");
        return;
    }
    final long pingTimestamp = System.currentTimeMillis();
    final long socketId = header.getSocketId();
    if (socketId == -1) {
        // TODO dump client ip for debug
        logger.warn("SocketId not exist. header:{}", header);
        // skip
        return;
    }
    try {
        final AgentProperty agentProperty = newChannelProperties(header, pingSession.getServiceType());
        long eventIdentifier = AgentLifeCycleAsyncTaskService.createEventIdentifier((int) socketId, (int) pingSession.nextEventIdAllocator());
        this.agentLifeCycleAsyncTask.handleLifeCycleEvent(agentProperty, pingTimestamp, agentLifeCycleState, eventIdentifier);
        this.agentEventAsyncTask.handleEvent(agentProperty, pingTimestamp, agentEventType);
    } catch (Exception e) {
        logger.warn("Failed to update state. closeState:{} lifeCycle={} {}/{}", closeState, pingSession, agentLifeCycleState, agentEventType, e);
    }
}
Also used : Header(com.navercorp.pinpoint.grpc.Header) AgentProperty(com.navercorp.pinpoint.collector.service.async.AgentProperty) DefaultAgentProperty(com.navercorp.pinpoint.collector.service.async.DefaultAgentProperty)

Example 5 with AgentProperty

use of com.navercorp.pinpoint.collector.service.async.AgentProperty in project pinpoint by naver.

the class KeepAliveService method updateState.

public void updateState(PingSession pingSession) {
    final Header header = pingSession.getHeader();
    if (header == null) {
        // TODO dump client ip for debug
        logger.warn("Not found request header");
        return;
    }
    try {
        final AgentProperty agentProperty = newChannelProperties(header, pingSession.getServiceType());
        this.agentLifeCycleAsyncTask.handlePingEvent(agentProperty);
    } catch (Exception e) {
        logger.warn("Failed to update state. ping session={}", pingSession, e);
    }
}
Also used : Header(com.navercorp.pinpoint.grpc.Header) AgentProperty(com.navercorp.pinpoint.collector.service.async.AgentProperty) DefaultAgentProperty(com.navercorp.pinpoint.collector.service.async.DefaultAgentProperty)

Aggregations

AgentProperty (com.navercorp.pinpoint.collector.service.async.AgentProperty)5 AgentPropertyChannelAdaptor (com.navercorp.pinpoint.collector.service.async.AgentPropertyChannelAdaptor)3 ChannelProperties (com.navercorp.pinpoint.rpc.server.ChannelProperties)3 DefaultAgentProperty (com.navercorp.pinpoint.collector.service.async.DefaultAgentProperty)2 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)2 AgentLifeCycleState (com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)2 Header (com.navercorp.pinpoint.grpc.Header)2 ManagedAgentLifeCycle (com.navercorp.pinpoint.collector.util.ManagedAgentLifeCycle)1 AgentLifeCycleBo (com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)1 AgentEventBo (com.navercorp.pinpoint.common.server.bo.event.AgentEventBo)1 ChannelPropertiesFactory (com.navercorp.pinpoint.rpc.server.ChannelPropertiesFactory)1 Test (org.junit.Test)1