use of com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo in project pinpoint by naver.
the class HbaseAgentLifeCycleDaoTest method agentInfo_should_be_populated_as_unknown_if_status_cannot_be_found.
@Test
public void agentInfo_should_be_populated_as_unknown_if_status_cannot_be_found() {
// Given
final String expectedAgentId = "test-agent";
final long expectedTimestamp = 0L;
final AgentLifeCycleState expectedAgentLifeCycleState = AgentLifeCycleState.UNKNOWN;
final AgentLifeCycleBo scannedLifeCycleBo = null;
when(this.hbaseOperations2.find(any(TableName.class), any(Scan.class), any(ResultsExtractor.class))).thenReturn(scannedLifeCycleBo);
AgentInfo givenAgentInfo = new AgentInfo();
givenAgentInfo.setAgentId(expectedAgentId);
givenAgentInfo.setStartTimestamp(expectedTimestamp);
// When
this.agentLifeCycleDao.populateAgentStatus(givenAgentInfo, expectedTimestamp);
// Then
AgentStatus actualAgentStatus = givenAgentInfo.getStatus();
Assert.assertEquals(expectedAgentId, actualAgentStatus.getAgentId());
Assert.assertEquals(expectedTimestamp, actualAgentStatus.getEventTimestamp());
Assert.assertEquals(expectedAgentLifeCycleState, actualAgentStatus.getState());
}
use of com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo in project pinpoint by naver.
the class AgentLifeCycleHandlerTest method runAndVerifyAgentLifeCycle.
private void runAndVerifyAgentLifeCycle(ManagedAgentLifeCycle managedAgentLifeCycle) {
// given
final AgentLifeCycleState expectedLifeCycleState = managedAgentLifeCycle.getMappedState();
final int expectedEventCounter = managedAgentLifeCycle.getEventCounter();
final long expectedEventIdentifier = this.agentLifeCycleHandler.createEventIdentifier(TEST_SOCKET_ID, expectedEventCounter);
ArgumentCaptor<AgentLifeCycleBo> argCaptor = ArgumentCaptor.forClass(AgentLifeCycleBo.class);
// when
this.agentLifeCycleHandler.handleLifeCycleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedLifeCycleState, expectedEventCounter);
verify(this.agentLifeCycleDao, 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.common.server.bo.AgentLifeCycleBo in project pinpoint by naver.
the class AgentLifeCycleHandler method handleLifeCycleEvent.
public void handleLifeCycleEvent(PinpointServer pinpointServer, long eventTimestamp, AgentLifeCycleState agentLifeCycleState, int eventCounter) {
if (pinpointServer == null) {
throw new NullPointerException("pinpointServer may not be null");
}
if (agentLifeCycleState == null) {
throw new NullPointerException("agentLifeCycleState may not be null");
}
if (eventCounter < 0) {
throw new IllegalArgumentException("eventCounter may not be negative");
}
logger.info("handle lifecycle event - pinpointServer:{}, state:{}", pinpointServer, agentLifeCycleState);
Map<Object, Object> channelProperties = pinpointServer.getChannelProperties();
final Integer socketId = MapUtils.getInteger(channelProperties, SOCKET_ID_KEY);
if (socketId == null) {
logger.debug("socketId not found, agent does not support life cycle management - pinpointServer:{}", pinpointServer);
return;
}
final String agentId = MapUtils.getString(channelProperties, HandshakePropertyType.AGENT_ID.getName());
final long startTimestamp = MapUtils.getLong(channelProperties, HandshakePropertyType.START_TIMESTAMP.getName());
final long eventIdentifier = createEventIdentifier(socketId, eventCounter);
final AgentLifeCycleBo agentLifeCycleBo = new AgentLifeCycleBo(agentId, startTimestamp, eventTimestamp, eventIdentifier, agentLifeCycleState);
this.executor.execute(new AgentLifeCycleHandlerDispatch(agentLifeCycleBo));
}
use of com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo in project pinpoint by naver.
the class HbaseAgentLifeCycleDao method populateAgentStatuses.
@Override
public void populateAgentStatuses(Collection<AgentInfo> agentInfos, long timestamp) {
if (CollectionUtils.isEmpty(agentInfos)) {
return;
}
List<Scan> scans = new ArrayList<>(agentInfos.size());
for (AgentInfo agentInfo : agentInfos) {
if (agentInfo != null) {
final String agentId = agentInfo.getAgentId();
// startTimestamp is stored in reverse order
final long toTimestamp = agentInfo.getStartTimestamp();
final long fromTimestamp = toTimestamp - 1;
scans.add(createScan(agentId, fromTimestamp, toTimestamp));
}
}
List<AgentLifeCycleBo> agentLifeCycles = this.hbaseOperations2.findParallel(HBaseTables.AGENT_LIFECYCLE, scans, new MostRecentAgentLifeCycleResultsExtractor(this.agentLifeCycleMapper, timestamp));
int idx = 0;
for (AgentInfo agentInfo : agentInfos) {
if (agentInfo != null) {
AgentStatus agentStatus = createAgentStatus(agentInfo.getAgentId(), agentLifeCycles.get(idx++));
agentInfo.setStatus(agentStatus);
}
}
}
use of com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo in project pinpoint by naver.
the class HbaseAgentLifeCycleDao method populateAgentStatus.
@Override
public void populateAgentStatus(AgentInfo agentInfo, long timestamp) {
if (agentInfo == null) {
return;
}
Assert.isTrue(timestamp >= 0, "timestamp must not be less than 0");
final String agentId = agentInfo.getAgentId();
// startTimestamp is stored in reverse order
final long toTimestamp = agentInfo.getStartTimestamp();
final long fromTimestamp = toTimestamp - 1;
Scan scan = createScan(agentId, fromTimestamp, toTimestamp);
AgentLifeCycleBo agentLifeCycleBo = this.hbaseOperations2.find(HBaseTables.AGENT_LIFECYCLE, scan, new MostRecentAgentLifeCycleResultsExtractor(this.agentLifeCycleMapper, timestamp));
AgentStatus agentStatus = createAgentStatus(agentId, agentLifeCycleBo);
agentInfo.setStatus(agentStatus);
}
Aggregations