Search in sources :

Example 6 with AgentLifeCycleBo

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());
}
Also used : ResultsExtractor(com.navercorp.pinpoint.common.hbase.ResultsExtractor) TableName(org.apache.hadoop.hbase.TableName) AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) Scan(org.apache.hadoop.hbase.client.Scan) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState) Test(org.junit.Test)

Example 7 with AgentLifeCycleBo

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());
}
Also used : AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)

Example 8 with AgentLifeCycleBo

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));
}
Also used : AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)

Example 9 with 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);
        }
    }
}
Also used : AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)

Example 10 with AgentLifeCycleBo

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);
}
Also used : AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) Scan(org.apache.hadoop.hbase.client.Scan) AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)

Aggregations

AgentLifeCycleBo (com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)11 Scan (org.apache.hadoop.hbase.client.Scan)8 AgentLifeCycleState (com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)7 AgentStatus (com.navercorp.pinpoint.web.vo.AgentStatus)7 ResultsExtractor (com.navercorp.pinpoint.common.hbase.ResultsExtractor)5 TableName (org.apache.hadoop.hbase.TableName)5 Test (org.junit.Test)5 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)4 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)1 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)1 ArrayList (java.util.ArrayList)1