use of com.navercorp.pinpoint.common.server.bo.SimpleAgentKey in project pinpoint by naver.
the class HbaseAgentLifeCycleDao method getAgentStatus.
/**
* @param agentStatusQuery agentId and agentStartTime
*/
@Override
public List<Optional<AgentStatus>> getAgentStatus(AgentStatusQuery agentStatusQuery) {
Objects.requireNonNull(agentStatusQuery, "agentStatusQuery");
if (agentStatusQuery.getAgentKeys().isEmpty()) {
return Collections.emptyList();
}
List<SimpleAgentKey> agentKeyList = agentStatusQuery.getAgentKeys();
List<Scan> scans = new ArrayList<>(agentKeyList.size());
for (SimpleAgentKey agentInfo : agentKeyList) {
if (agentInfo != null) {
final String agentId = agentInfo.getAgentId();
// startTimestamp is stored in reverse order
final long toTimestamp = agentInfo.getAgentStartTime();
final long fromTimestamp = toTimestamp - 1;
scans.add(createScan(agentId, fromTimestamp, toTimestamp));
}
}
ResultsExtractor<AgentLifeCycleBo> action = new MostRecentAgentLifeCycleResultsExtractor(this.agentLifeCycleMapper, agentStatusQuery.getQueryTimestamp());
TableName agentLifeCycleTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
List<AgentLifeCycleBo> agentLifeCycles = this.hbaseOperations2.findParallel(agentLifeCycleTableName, scans, action);
int idx = 0;
List<Optional<AgentStatus>> agentStatusResult = new ArrayList<>(agentKeyList.size());
for (SimpleAgentKey agentInfo : agentKeyList) {
if (agentInfo != null) {
AgentStatus agentStatus = createAgentStatus(agentInfo.getAgentId(), agentLifeCycles.get(idx++));
agentStatusResult.add(Optional.of(agentStatus));
} else {
agentStatusResult.add(Optional.empty());
}
}
return agentStatusResult;
}
use of com.navercorp.pinpoint.common.server.bo.SimpleAgentKey in project pinpoint by naver.
the class AgentStatusQuery method buildQuery.
public static <T> AgentStatusQuery buildQuery(Collection<T> agentInfos, Function<T, SimpleAgentKey> transform, long timestamp) {
AgentStatusQuery.Builder builder = AgentStatusQuery.newBuilder();
for (T agentInfo : agentInfos) {
SimpleAgentKey apply = transform.apply(agentInfo);
builder.addAgentKey(apply);
}
return builder.build(timestamp);
}
use of com.navercorp.pinpoint.common.server.bo.SimpleAgentKey in project pinpoint by naver.
the class ApplicationMapBuilderTest method setUp.
@Before
public void setUp() {
MapResponseDao mapResponseDao = mock(MapResponseDao.class);
mapResponseNodeHistogramDataSource = new MapResponseNodeHistogramDataSource(mapResponseDao);
ResponseHistograms responseHistograms = mock(ResponseHistograms.class);
responseHistogramBuilderNodeHistogramDataSource = new ResponseHistogramsNodeHistogramDataSource(responseHistograms);
AgentInfoService agentInfoService = mock(AgentInfoService.class);
agentInfoServerInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService);
Answer<List<ResponseTime>> responseTimeAnswer = new Answer<List<ResponseTime>>() {
final long timestamp = System.currentTimeMillis();
@Override
public List<ResponseTime> answer(InvocationOnMock invocation) {
Application application = invocation.getArgument(0);
String applicationName = application.getName();
ServiceType applicationServiceType = application.getServiceType();
int depth = ApplicationMapBuilderTestHelper.getDepthFromApplicationName(applicationName);
ResponseTime responseTime = new ResponseTime(application.getName(), application.getServiceType(), timestamp);
responseTime.addResponseTime(ApplicationMapBuilderTestHelper.createAgentIdFromDepth(depth), applicationServiceType.getHistogramSchema().getNormalSlot().getSlotTime(), 1);
return Collections.singletonList(responseTime);
}
};
when(mapResponseDao.selectResponseTime(any(Application.class), any(Range.class))).thenAnswer(responseTimeAnswer);
when(responseHistograms.getResponseTimeList(any(Application.class))).thenAnswer(responseTimeAnswer);
when(agentInfoService.getAgentsByApplicationName(anyString(), anyLong())).thenAnswer(new Answer<Set<AgentInfo>>() {
@Override
public Set<AgentInfo> answer(InvocationOnMock invocation) throws Throwable {
String applicationName = invocation.getArgument(0);
AgentInfo agentInfo = ApplicationMapBuilderTestHelper.createAgentInfoFromApplicationName(applicationName);
AgentStatus agentStatus = new AgentStatus(agentInfo.getAgentId(), AgentLifeCycleState.RUNNING, 0);
agentInfo.setStatus(agentStatus);
Set<AgentInfo> agentInfos = new HashSet<>();
agentInfos.add(agentInfo);
return agentInfos;
}
});
when(agentInfoService.getAgentsByApplicationNameWithoutStatus(anyString(), anyLong())).thenAnswer(new Answer<Set<AgentInfo>>() {
@Override
public Set<AgentInfo> answer(InvocationOnMock invocation) throws Throwable {
String applicationName = invocation.getArgument(0);
AgentInfo agentInfo = ApplicationMapBuilderTestHelper.createAgentInfoFromApplicationName(applicationName);
Set<AgentInfo> agentInfos = new HashSet<>();
agentInfos.add(agentInfo);
return agentInfos;
}
});
when(agentInfoService.getAgentStatus(anyString(), anyLong())).thenAnswer(new Answer<AgentStatus>() {
@Override
public AgentStatus answer(InvocationOnMock invocation) throws Throwable {
String agentId = invocation.getArgument(0);
AgentStatus agentStatus = new AgentStatus(agentId, AgentLifeCycleState.RUNNING, System.currentTimeMillis());
return agentStatus;
}
});
doAnswer(new Answer<List<Optional<AgentStatus>>>() {
@Override
public List<Optional<AgentStatus>> answer(InvocationOnMock invocation) throws Throwable {
List<Optional<AgentStatus>> result = new ArrayList<>();
AgentStatusQuery query = invocation.getArgument(0);
for (SimpleAgentKey agentInfo : query.getAgentKeys()) {
AgentStatus agentStatus = new AgentStatus(agentInfo.getAgentId(), AgentLifeCycleState.RUNNING, System.currentTimeMillis());
result.add(Optional.of(agentStatus));
}
return result;
}
}).when(agentInfoService).getAgentStatus(any());
}
Aggregations