Skip to content

Commit 827be6d

Browse files
committed
[#9023] AgentAndStatus
1 parent 54809c3 commit 827be6d

27 files changed

+211
-219
lines changed

batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ public AgentCountStatistics process(ApplicationAgentsList item) throws Exception
4141
}
4242

4343
private int getAgentCount(List<ApplicationAgentList> applicationAgentLists) {
44-
int agentCount = 0;
45-
for (ApplicationAgentList applicationAgentList : applicationAgentLists) {
46-
agentCount += applicationAgentList.getAgentInfos().size();
47-
}
48-
return agentCount;
44+
return applicationAgentLists.stream()
45+
.mapToInt(applicationAgentList -> applicationAgentList.getAgentInfos().size())
46+
.sum();
4947
}
5048

5149
}

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/StatisticsServerInstanceListFactory.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
2424
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkData;
2525
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;
26+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
2627
import com.navercorp.pinpoint.web.vo.AgentInfo;
2728
import com.navercorp.pinpoint.web.vo.Application;
2829

@@ -58,16 +59,17 @@ ServerInstanceList createWasNodeInstanceListFromHistogram(Node wasNode, Instant
5859
}
5960

6061
final ServerBuilder builder = new ServerBuilder();
61-
final Set<AgentInfo> agentInfoSet = new HashSet<>();
62+
final Set<AgentAndStatus> agentInfoSet = new HashSet<>();
6263
final NodeHistogram nodeHistogram = wasNode.getNodeHistogram();
6364
if (nodeHistogram != null && nodeHistogram.getAgentHistogramMap() != null) {
6465
for (String agentId : nodeHistogram.getAgentHistogramMap().keySet()) {
6566
AgentInfo agentInfo = new AgentInfo();
6667
agentInfo.setAgentId(agentId);
6768
agentInfo.setHostName(agentId);
6869
agentInfo.setIp("");
70+
agentInfo.setAgentName("");
6971
agentInfo.setServiceType(wasNode.getServiceType());
70-
agentInfoSet.add(agentInfo);
72+
agentInfoSet.add(new AgentAndStatus(agentInfo));
7173
}
7274
}
7375
builder.addAgentInfo(agentInfoSet);

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/datasource/AgentInfoServerInstanceListDataSource.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
2525
import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory;
2626
import com.navercorp.pinpoint.web.service.AgentInfoService;
27+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
2728
import com.navercorp.pinpoint.web.vo.AgentInfo;
2829
import com.navercorp.pinpoint.web.vo.AgentStatus;
2930
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
@@ -41,6 +42,7 @@
4142
import java.util.Objects;
4243
import java.util.Optional;
4344
import java.util.Set;
45+
import java.util.stream.Collectors;
4446

4547
/**
4648
* @author HyunGil Jeong
@@ -75,8 +77,12 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp)
7577
agentInfos = filterAgentInfos(agentInfos, timestamp, node);
7678
logger.debug("add agentInfos {} : {}", application, agentInfos);
7779

80+
Set<AgentAndStatus> agentAndStatusSet = agentInfos.stream()
81+
.map(AgentAndStatus::new)
82+
.collect(Collectors.toSet());
83+
7884
ServerBuilder builder = new ServerBuilder(hyperLinkFactory);
79-
builder.addAgentInfo(agentInfos);
85+
builder.addAgentInfo(agentAndStatusSet);
8086
return builder.build();
8187
}
8288

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerBuilder.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.navercorp.pinpoint.web.hyperlink.HyperLink;
2323
import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory;
2424
import com.navercorp.pinpoint.web.hyperlink.LinkSources;
25+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
2526
import com.navercorp.pinpoint.web.vo.AgentInfo;
2627
import org.apache.logging.log4j.LogManager;
2728
import org.apache.logging.log4j.Logger;
@@ -42,7 +43,7 @@ public class ServerBuilder {
4243
private final Logger logger = LogManager.getLogger(this.getClass());
4344

4445
private final AgentHistogramList agentHistogramList = new AgentHistogramList();
45-
private final Set<AgentInfo> agentSet = new HashSet<>();
46+
private final Set<AgentAndStatus> agentSet = new HashSet<>();
4647
private final HyperLinkFactory hyperLinkFactory;
4748

4849
public ServerBuilder() {
@@ -60,7 +61,7 @@ public void addCallHistogramList(AgentHistogramList agentHistogramList) {
6061
this.agentHistogramList.addAgentHistogram(agentHistogramList);
6162
}
6263

63-
public void addAgentInfo(Set<AgentInfo> agentInfo) {
64+
public void addAgentInfo(Set<AgentAndStatus> agentInfo) {
6465
if (agentInfo == null) {
6566
return;
6667
}
@@ -102,10 +103,10 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog
102103
return serverInstanceList;
103104
}
104105

105-
public ServerInstanceList buildPhysicalServer(final Set<AgentInfo> agentSet) {
106+
public ServerInstanceList buildPhysicalServer(final Set<AgentAndStatus> agentSet) {
106107
final ServerInstanceList serverInstanceList = new ServerInstanceList();
107-
for (AgentInfo agent : agentSet) {
108-
final ServerInstance serverInstance = new ServerInstance(agent, buildHyperLink(agent));
108+
for (AgentAndStatus agentAndStatus : agentSet) {
109+
final ServerInstance serverInstance = new ServerInstance(agentAndStatus.getAgentInfo(), agentAndStatus.getStatus(), buildHyperLink(agentAndStatus.getAgentInfo()));
109110
serverInstanceList.addServerInstance(serverInstance);
110111

111112
}

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@ public class ServerInstance {
5050

5151
private final List<HyperLink> linkList;
5252

53-
public ServerInstance(AgentInfo agentInfo, List<HyperLink> linkList) {
53+
public ServerInstance(AgentInfo agentInfo, AgentStatus agentStatus, List<HyperLink> linkList) {
5454
Objects.requireNonNull(agentInfo, "agentInfo");
55-
5655
this.hostName = agentInfo.getHostName();
5756
this.ip = agentInfo.getIp();
5857
this.name = agentInfo.getAgentId();
5958
this.agentName = agentInfo.getAgentName();
6059
this.serviceType = agentInfo.getServiceType();
61-
AgentStatus agentStatus = agentInfo.getStatus();
60+
this.status = getAgentLifeCycleState(agentStatus);
61+
this.serverType = ServerType.Physical;
62+
this.linkList = Objects.requireNonNull(linkList, "linkList");
63+
}
64+
65+
private AgentLifeCycleState getAgentLifeCycleState(AgentStatus agentStatus) {
6266
if (agentStatus != null) {
63-
this.status = agentStatus.getState();
67+
return agentStatus.getState();
6468
} else {
65-
this.status = AgentLifeCycleState.UNKNOWN;
69+
return AgentLifeCycleState.UNKNOWN;
6670
}
67-
this.serverType = ServerType.Physical;
68-
this.linkList = Objects.requireNonNull(linkList, "linkList");
6971
}
7072

7173
public ServerInstance(String hostName, String physicalName, ServiceType serviceType, List<HyperLink> linkList) {

web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstanceList.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collection;
21+
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.TreeMap;
@@ -54,10 +55,15 @@ public List<String> getAgentIdList() {
5455
}
5556

5657
public Map<String, String> getAgentIdNameMap() {
57-
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
58-
return serverList.stream()
59-
.flatMap(List::stream)
60-
.collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName));
58+
// Stream is not recommended
59+
final Map<String, String> map = new HashMap<>();
60+
for (List<ServerInstance> serverInstanceList : this.serverInstanceList.values()) {
61+
for (ServerInstance serverInstance : serverInstanceList) {
62+
// NPE
63+
map.put(serverInstance.getName(), serverInstance.getAgentName());
64+
}
65+
}
66+
return map;
6167
}
6268

6369
public int getInstanceCount() {

web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.navercorp.pinpoint.common.util.IdValidateUtils;
2222
import com.navercorp.pinpoint.web.service.AgentEventService;
2323
import com.navercorp.pinpoint.web.service.AgentInfoService;
24+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
2425
import com.navercorp.pinpoint.web.vo.AgentEvent;
2526
import com.navercorp.pinpoint.web.vo.AgentInfo;
2627
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
@@ -107,7 +108,7 @@ public ApplicationAgentsList getAgentList(
107108
}
108109

109110
@GetMapping(value = "/getAgentInfo")
110-
public AgentInfo getAgentInfo(
111+
public AgentAndStatus getAgentInfo(
111112
@RequestParam("agentId") String agentId,
112113
@RequestParam("timestamp") long timestamp) {
113114
return this.agentInfoService.getAgentInfo(agentId, timestamp);

web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.navercorp.pinpoint.common.server.cluster.ClusterKey;
44
import com.navercorp.pinpoint.web.vo.AgentInfo;
5+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
56

67
import java.util.Objects;
78

@@ -13,9 +14,9 @@ public static ClusterKey from(AgentInfo agentInfo) {
1314
return new ClusterKey(agentInfo.getApplicationName(), agentInfo.getAgentId(), agentInfo.getStartTimestamp());
1415
}
1516

16-
public static ClusterKeyAndStatus withStatusFrom(AgentInfo agentInfo) {
17-
Objects.requireNonNull(agentInfo, "agentInfo");
18-
ClusterKey clusterKey = from(agentInfo);
19-
return new ClusterKeyAndStatus(clusterKey, agentInfo.getStatus());
17+
public static ClusterKeyAndStatus withStatusFrom(AgentAndStatus agentInfoAndStatus) {
18+
Objects.requireNonNull(agentInfoAndStatus, "agentInfoAndStatus");
19+
ClusterKey clusterKey = from(agentInfoAndStatus.getAgentInfo());
20+
return new ClusterKeyAndStatus(clusterKey, agentInfoAndStatus.getStatus());
2021
}
2122
}

web/src/main/java/com/navercorp/pinpoint/web/controller/MapController.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,11 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2(
296296

297297
Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);
298298

299-
List<Application> fromApplications = new ArrayList<>(fromApplicationNames.size());
300-
for (int i = 0; i < fromApplicationNames.size(); i++) {
301-
Application fromApplication = applicationFactory.createApplication(fromApplicationNames.get(i), fromServiceTypeCodes.get(i));
302-
fromApplications.add(fromApplication);
303-
}
304-
List<Application> toApplications = new ArrayList<>(toApplicationNames.size());
305-
for (int i = 0; i < toApplicationNames.size(); i++) {
306-
Application toApplication = applicationFactory.createApplication(toApplicationNames.get(i), toServiceTypeCodes.get(i));
307-
toApplications.add(toApplication);
308-
}
309-
final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications).setUseStatisticsAgentState(useStatisticsAgentState).build();
299+
List<Application> fromApplications = toApplications(fromApplicationNames, fromServiceTypeCodes);
300+
List<Application> toApplications = toApplications(toApplicationNames, toServiceTypeCodes);
301+
final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications)
302+
.setUseStatisticsAgentState(useStatisticsAgentState)
303+
.build();
310304

311305
final NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
312306
if (useLoadHistogramFormat) {
@@ -315,6 +309,15 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2(
315309
return nodeHistogramSummary;
316310
}
317311

312+
private List<Application> toApplications(List<String> applicationNames, List<Short> serviceTypeCodes) {
313+
List<Application> result = new ArrayList<>(applicationNames.size());
314+
for (int i = 0; i < applicationNames.size(); i++) {
315+
Application application = applicationFactory.createApplication(applicationNames.get(i), serviceTypeCodes.get(i));
316+
result.add(application);
317+
}
318+
return result;
319+
}
320+
318321
private List<Application> mapApplicationPairsToApplications(List<ApplicationPair> applicationPairs) {
319322
if (CollectionUtils.isEmpty(applicationPairs)) {
320323
return Collections.emptyList();

web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java

-24
This file was deleted.

web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.navercorp.pinpoint.web.service;
1818

1919
import com.navercorp.pinpoint.web.vo.AgentInfo;
20+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
2021
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
2122
import com.navercorp.pinpoint.web.vo.AgentStatus;
2223
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
@@ -43,13 +44,13 @@ public interface AgentInfoService {
4344

4445
ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays);
4546

46-
Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp);
47+
Set<AgentAndStatus> getAgentsByApplicationName(String applicationName, long timestamp);
4748

4849
Set<AgentInfo> getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp);
4950

50-
Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff);
51+
Set<AgentAndStatus> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff);
5152

52-
AgentInfo getAgentInfo(String agentId, long timestamp);
53+
AgentAndStatus getAgentInfo(String agentId, long timestamp);
5354

5455
AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp);
5556

web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.navercorp.pinpoint.web.service.stat.AgentWarningStatService;
3131
import com.navercorp.pinpoint.web.vo.AgentEvent;
3232
import com.navercorp.pinpoint.web.vo.AgentInfo;
33+
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
3334
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
3435
import com.navercorp.pinpoint.web.vo.AgentStatus;
3536
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
@@ -117,12 +118,12 @@ public ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.Grou
117118
Objects.requireNonNull(applicationName, "applicationName");
118119

119120
ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(groupBy, filter, hyperLinkFactory);
120-
Set<AgentInfo> agentInfos = getAgentsByApplicationName(applicationName, timestamp);
121-
if (agentInfos.isEmpty()) {
121+
Set<AgentAndStatus> agentInfoAnsStatuss = getAgentsByApplicationName(applicationName, timestamp);
122+
if (agentInfoAnsStatuss.isEmpty()) {
122123
logger.warn("agent list is empty for application:{}", applicationName);
123124
return applicationAgentsList;
124125
}
125-
applicationAgentsList.addAll(agentInfos);
126+
applicationAgentsList.addAll(agentInfoAnsStatuss);
126127
if (logger.isDebugEnabled()) {
127128
logger.debug("getApplicationAgentsList={}", applicationAgentsList);
128129
}
@@ -218,20 +219,20 @@ private List<String> getApplicationNameList(List<Application> applications) {
218219
}
219220

220221
@Override
221-
public Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp) {
222+
public Set<AgentAndStatus> getAgentsByApplicationName(String applicationName, long timestamp) {
222223
List<AgentInfo> agentInfos = this.getAgentsByApplicationNameWithoutStatus0(applicationName, timestamp);
223224

225+
List<AgentAndStatus> result = new ArrayList<>(agentInfos.size());
224226

225227
AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, Instant.ofEpochMilli(timestamp));
226228
List<Optional<AgentStatus>> agentStatus = this.agentLifeCycleDao.getAgentStatus(query);
227229
for (int i = 0; i < agentStatus.size(); i++) {
228230
Optional<AgentStatus> status = agentStatus.get(i);
229-
if (status.isPresent()) {
230-
AgentInfo agentInfo = agentInfos.get(i);
231-
agentInfo.setStatus(status.get());
232-
}
231+
AgentInfo agentInfo = agentInfos.get(i);
232+
result.add(new AgentAndStatus(agentInfo, status.orElse(null)));
233233
}
234-
return new HashSet<>(agentInfos);
234+
235+
return new HashSet<>(result);
235236
}
236237

237238

@@ -257,33 +258,35 @@ public List<AgentInfo> getAgentsByApplicationNameWithoutStatus0(String applicati
257258
}
258259

259260
@Override
260-
public Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) {
261+
public Set<AgentAndStatus> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) {
261262
if (timeDiff > timestamp) {
262263
throw new IllegalArgumentException("timeDiff must not be greater than timestamp");
263264
}
264265

265-
Set<AgentInfo> unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp);
266+
Set<AgentAndStatus> unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp);
266267

267268
final long eventTimestampFloor = timestamp - timeDiff;
268269

269-
Set<AgentInfo> filteredAgentInfos = new HashSet<>();
270-
for (AgentInfo agentInfo : unfilteredAgentInfos) {
271-
AgentStatus agentStatus = agentInfo.getStatus();
270+
Set<AgentAndStatus> filteredAgentInfos = new HashSet<>();
271+
for (AgentAndStatus agentInfoAndStatus : unfilteredAgentInfos) {
272+
AgentStatus agentStatus = agentInfoAndStatus.getStatus();
272273
if (AgentLifeCycleState.UNKNOWN == agentStatus.getState() || eventTimestampFloor <= agentStatus.getEventTimestamp()) {
273-
filteredAgentInfos.add(agentInfo);
274+
filteredAgentInfos.add(agentInfoAndStatus);
274275
}
275276
}
276277
return filteredAgentInfos;
277278
}
278279

279280
@Override
280-
public AgentInfo getAgentInfo(String agentId, long timestamp) {
281+
public AgentAndStatus getAgentInfo(String agentId, long timestamp) {
282+
281283
AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp);
282-
if (agentInfo != null) {
283-
Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
284-
agentInfo.setStatus(agentStatus.orElse(null));
284+
if (agentInfo == null) {
285+
return null;
285286
}
286-
return agentInfo;
287+
288+
Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
289+
return new AgentAndStatus(agentInfo, agentStatus.orElse(null));
287290
}
288291

289292
@Override

0 commit comments

Comments
 (0)