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());
}
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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations