diff --git a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java index d6a88a557c45..16d7247faf17 100644 --- a/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java +++ b/batch/src/main/java/com/navercorp/pinpoint/batch/job/AgentCountProcessor.java @@ -41,11 +41,9 @@ public AgentCountStatistics process(ApplicationAgentsList item) throws Exception } private int getAgentCount(List applicationAgentLists) { - int agentCount = 0; - for (ApplicationAgentList applicationAgentList : applicationAgentLists) { - agentCount += applicationAgentList.getAgentInfos().size(); - } - return agentCount; + return applicationAgentLists.stream() + .mapToInt(applicationAgentList -> applicationAgentList.getAgentInfos().size()) + .sum(); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/StatisticsServerInstanceListFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/StatisticsServerInstanceListFactory.java index b64324809b3b..d13b5b8731cc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/StatisticsServerInstanceListFactory.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/StatisticsServerInstanceListFactory.java @@ -23,6 +23,7 @@ import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkData; import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.Application; @@ -58,7 +59,7 @@ ServerInstanceList createWasNodeInstanceListFromHistogram(Node wasNode, Instant } final ServerBuilder builder = new ServerBuilder(); - final Set agentInfoSet = new HashSet<>(); + final Set agentInfoSet = new HashSet<>(); final NodeHistogram nodeHistogram = wasNode.getNodeHistogram(); if (nodeHistogram != null && nodeHistogram.getAgentHistogramMap() != null) { for (String agentId : nodeHistogram.getAgentHistogramMap().keySet()) { @@ -66,8 +67,9 @@ ServerInstanceList createWasNodeInstanceListFromHistogram(Node wasNode, Instant agentInfo.setAgentId(agentId); agentInfo.setHostName(agentId); agentInfo.setIp(""); + agentInfo.setAgentName(""); agentInfo.setServiceType(wasNode.getServiceType()); - agentInfoSet.add(agentInfo); + agentInfoSet.add(new AgentAndStatus(agentInfo)); } } builder.addAgentInfo(agentInfoSet); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/datasource/AgentInfoServerInstanceListDataSource.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/datasource/AgentInfoServerInstanceListDataSource.java index 3e84693f3e5a..8533fbfec1bc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/datasource/AgentInfoServerInstanceListDataSource.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/appender/server/datasource/AgentInfoServerInstanceListDataSource.java @@ -24,6 +24,7 @@ import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram; import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.service.AgentInfoService; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; import com.navercorp.pinpoint.web.vo.AgentStatusQuery; @@ -41,6 +42,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** * @author HyunGil Jeong @@ -75,8 +77,12 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp) agentInfos = filterAgentInfos(agentInfos, timestamp, node); logger.debug("add agentInfos {} : {}", application, agentInfos); + Set agentAndStatusSet = agentInfos.stream() + .map(AgentAndStatus::new) + .collect(Collectors.toSet()); + ServerBuilder builder = new ServerBuilder(hyperLinkFactory); - builder.addAgentInfo(agentInfos); + builder.addAgentInfo(agentAndStatusSet); return builder.build(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerBuilder.java index 1739b9fe7478..34d7aefad4c5 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerBuilder.java @@ -22,6 +22,7 @@ import com.navercorp.pinpoint.web.hyperlink.HyperLink; import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.hyperlink.LinkSources; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,7 +43,7 @@ public class ServerBuilder { private final Logger logger = LogManager.getLogger(this.getClass()); private final AgentHistogramList agentHistogramList = new AgentHistogramList(); - private final Set agentSet = new HashSet<>(); + private final Set agentSet = new HashSet<>(); private final HyperLinkFactory hyperLinkFactory; public ServerBuilder() { @@ -60,7 +61,7 @@ public void addCallHistogramList(AgentHistogramList agentHistogramList) { this.agentHistogramList.addAgentHistogram(agentHistogramList); } - public void addAgentInfo(Set agentInfo) { + public void addAgentInfo(Set agentInfo) { if (agentInfo == null) { return; } @@ -102,10 +103,10 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog return serverInstanceList; } - public ServerInstanceList buildPhysicalServer(final Set agentSet) { + public ServerInstanceList buildPhysicalServer(final Set agentSet) { final ServerInstanceList serverInstanceList = new ServerInstanceList(); - for (AgentInfo agent : agentSet) { - final ServerInstance serverInstance = new ServerInstance(agent, buildHyperLink(agent)); + for (AgentAndStatus agentAndStatus : agentSet) { + final ServerInstance serverInstance = new ServerInstance(agentAndStatus.getAgentInfo(), agentAndStatus.getStatus(), buildHyperLink(agentAndStatus.getAgentInfo())); serverInstanceList.addServerInstance(serverInstance); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java index 7735da1cec91..a23f913a8a2a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstance.java @@ -50,22 +50,24 @@ public class ServerInstance { private final List linkList; - public ServerInstance(AgentInfo agentInfo, List linkList) { + public ServerInstance(AgentInfo agentInfo, AgentStatus agentStatus, List linkList) { Objects.requireNonNull(agentInfo, "agentInfo"); - this.hostName = agentInfo.getHostName(); this.ip = agentInfo.getIp(); this.name = agentInfo.getAgentId(); this.agentName = agentInfo.getAgentName(); this.serviceType = agentInfo.getServiceType(); - AgentStatus agentStatus = agentInfo.getStatus(); + this.status = getAgentLifeCycleState(agentStatus); + this.serverType = ServerType.Physical; + this.linkList = Objects.requireNonNull(linkList, "linkList"); + } + + private AgentLifeCycleState getAgentLifeCycleState(AgentStatus agentStatus) { if (agentStatus != null) { - this.status = agentStatus.getState(); + return agentStatus.getState(); } else { - this.status = AgentLifeCycleState.UNKNOWN; + return AgentLifeCycleState.UNKNOWN; } - this.serverType = ServerType.Physical; - this.linkList = Objects.requireNonNull(linkList, "linkList"); } public ServerInstance(String hostName, String physicalName, ServiceType serviceType, List linkList) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstanceList.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstanceList.java index f5ff02cc33ee..35191b852573 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstanceList.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/nodes/ServerInstanceList.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -54,10 +55,15 @@ public List getAgentIdList() { } public Map getAgentIdNameMap() { - Collection> serverList = this.serverInstanceList.values(); - return serverList.stream() - .flatMap(List::stream) - .collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName)); + // Stream is not recommended + final Map map = new HashMap<>(); + for (List serverInstanceList : this.serverInstanceList.values()) { + for (ServerInstance serverInstance : serverInstanceList) { + // NPE + map.put(serverInstance.getName(), serverInstance.getAgentName()); + } + } + return map; } public int getInstanceCount() { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java index 60251ec21c39..ab82ba0dc579 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentInfoController.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.common.util.IdValidateUtils; import com.navercorp.pinpoint.web.service.AgentEventService; import com.navercorp.pinpoint.web.service.AgentInfoService; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentEvent; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentInfoFilter; @@ -107,7 +108,7 @@ public ApplicationAgentsList getAgentList( } @GetMapping(value = "/getAgentInfo") - public AgentInfo getAgentInfo( + public AgentAndStatus getAgentInfo( @RequestParam("agentId") String agentId, @RequestParam("timestamp") long timestamp) { return this.agentInfoService.getAgentInfo(agentId, timestamp); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java index 89050c891fd7..5c6e707e4ff3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java @@ -2,6 +2,7 @@ import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import java.util.Objects; @@ -13,9 +14,9 @@ public static ClusterKey from(AgentInfo agentInfo) { return new ClusterKey(agentInfo.getApplicationName(), agentInfo.getAgentId(), agentInfo.getStartTimestamp()); } - public static ClusterKeyAndStatus withStatusFrom(AgentInfo agentInfo) { - Objects.requireNonNull(agentInfo, "agentInfo"); - ClusterKey clusterKey = from(agentInfo); - return new ClusterKeyAndStatus(clusterKey, agentInfo.getStatus()); + public static ClusterKeyAndStatus withStatusFrom(AgentAndStatus agentInfoAndStatus) { + Objects.requireNonNull(agentInfoAndStatus, "agentInfoAndStatus"); + ClusterKey clusterKey = from(agentInfoAndStatus.getAgentInfo()); + return new ClusterKeyAndStatus(clusterKey, agentInfoAndStatus.getStatus()); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/MapController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/MapController.java index cc6f58e5d574..419527b61cd0 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/MapController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/MapController.java @@ -296,17 +296,11 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2( Application application = applicationFactory.createApplication(applicationName, serviceTypeCode); - List fromApplications = new ArrayList<>(fromApplicationNames.size()); - for (int i = 0; i < fromApplicationNames.size(); i++) { - Application fromApplication = applicationFactory.createApplication(fromApplicationNames.get(i), fromServiceTypeCodes.get(i)); - fromApplications.add(fromApplication); - } - List toApplications = new ArrayList<>(toApplicationNames.size()); - for (int i = 0; i < toApplicationNames.size(); i++) { - Application toApplication = applicationFactory.createApplication(toApplicationNames.get(i), toServiceTypeCodes.get(i)); - toApplications.add(toApplication); - } - final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications).setUseStatisticsAgentState(useStatisticsAgentState).build(); + List fromApplications = toApplications(fromApplicationNames, fromServiceTypeCodes); + List toApplications = toApplications(toApplicationNames, toServiceTypeCodes); + final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications) + .setUseStatisticsAgentState(useStatisticsAgentState) + .build(); final NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option); if (useLoadHistogramFormat) { @@ -315,6 +309,15 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2( return nodeHistogramSummary; } + private List toApplications(List applicationNames, List serviceTypeCodes) { + List result = new ArrayList<>(applicationNames.size()); + for (int i = 0; i < applicationNames.size(); i++) { + Application application = applicationFactory.createApplication(applicationNames.get(i), serviceTypeCodes.get(i)); + result.add(application); + } + return result; + } + private List mapApplicationPairsToApplications(List applicationPairs) { if (CollectionUtils.isEmpty(applicationPairs)) { return Collections.emptyList(); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java deleted file mode 100644 index 04d70f8ba612..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.navercorp.pinpoint.web.service; - -import com.navercorp.pinpoint.web.vo.AgentInfo; -import com.navercorp.pinpoint.web.vo.AgentStatus; - -import java.util.Objects; - -public class AgentInfoAndStatus { - private final AgentInfo agentInfo; - private final AgentStatus status; - - public AgentInfoAndStatus(AgentInfo agentInfo, AgentStatus status) { - this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); - this.status = Objects.requireNonNull(status, "status"); - } - - public AgentInfo getAgentInfo() { - return agentInfo; - } - - public AgentStatus getStatus() { - return status; - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java index 6149aafff686..4e55e7d76b4f 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.web.service; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfoFilter; import com.navercorp.pinpoint.web.vo.AgentStatus; import com.navercorp.pinpoint.web.vo.AgentStatusQuery; @@ -43,13 +44,13 @@ public interface AgentInfoService { ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays); - Set getAgentsByApplicationName(String applicationName, long timestamp); + Set getAgentsByApplicationName(String applicationName, long timestamp); Set getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp); - Set getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff); + Set getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff); - AgentInfo getAgentInfo(String agentId, long timestamp); + AgentAndStatus getAgentInfo(String agentId, long timestamp); AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java index dc0635ca8e3d..b4e93a083cc4 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java @@ -30,6 +30,7 @@ import com.navercorp.pinpoint.web.service.stat.AgentWarningStatService; import com.navercorp.pinpoint.web.vo.AgentEvent; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfoFilter; import com.navercorp.pinpoint.web.vo.AgentStatus; import com.navercorp.pinpoint.web.vo.AgentStatusQuery; @@ -117,12 +118,12 @@ public ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.Grou Objects.requireNonNull(applicationName, "applicationName"); ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(groupBy, filter, hyperLinkFactory); - Set agentInfos = getAgentsByApplicationName(applicationName, timestamp); - if (agentInfos.isEmpty()) { + Set agentInfoAnsStatuss = getAgentsByApplicationName(applicationName, timestamp); + if (agentInfoAnsStatuss.isEmpty()) { logger.warn("agent list is empty for application:{}", applicationName); return applicationAgentsList; } - applicationAgentsList.addAll(agentInfos); + applicationAgentsList.addAll(agentInfoAnsStatuss); if (logger.isDebugEnabled()) { logger.debug("getApplicationAgentsList={}", applicationAgentsList); } @@ -218,20 +219,20 @@ private List getApplicationNameList(List applications) { } @Override - public Set getAgentsByApplicationName(String applicationName, long timestamp) { + public Set getAgentsByApplicationName(String applicationName, long timestamp) { List agentInfos = this.getAgentsByApplicationNameWithoutStatus0(applicationName, timestamp); + List result = new ArrayList<>(agentInfos.size()); AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, Instant.ofEpochMilli(timestamp)); List> agentStatus = this.agentLifeCycleDao.getAgentStatus(query); for (int i = 0; i < agentStatus.size(); i++) { Optional status = agentStatus.get(i); - if (status.isPresent()) { - AgentInfo agentInfo = agentInfos.get(i); - agentInfo.setStatus(status.get()); - } + AgentInfo agentInfo = agentInfos.get(i); + result.add(new AgentAndStatus(agentInfo, status.orElse(null))); } - return new HashSet<>(agentInfos); + + return new HashSet<>(result); } @@ -257,33 +258,35 @@ public List getAgentsByApplicationNameWithoutStatus0(String applicati } @Override - public Set getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) { + public Set getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) { if (timeDiff > timestamp) { throw new IllegalArgumentException("timeDiff must not be greater than timestamp"); } - Set unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp); + Set unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp); final long eventTimestampFloor = timestamp - timeDiff; - Set filteredAgentInfos = new HashSet<>(); - for (AgentInfo agentInfo : unfilteredAgentInfos) { - AgentStatus agentStatus = agentInfo.getStatus(); + Set filteredAgentInfos = new HashSet<>(); + for (AgentAndStatus agentInfoAndStatus : unfilteredAgentInfos) { + AgentStatus agentStatus = agentInfoAndStatus.getStatus(); if (AgentLifeCycleState.UNKNOWN == agentStatus.getState() || eventTimestampFloor <= agentStatus.getEventTimestamp()) { - filteredAgentInfos.add(agentInfo); + filteredAgentInfos.add(agentInfoAndStatus); } } return filteredAgentInfos; } @Override - public AgentInfo getAgentInfo(String agentId, long timestamp) { + public AgentAndStatus getAgentInfo(String agentId, long timestamp) { + AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp); - if (agentInfo != null) { - Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp); - agentInfo.setStatus(agentStatus.orElse(null)); + if (agentInfo == null) { + return null; } - return agentInfo; + + Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp); + return new AgentAndStatus(agentInfo, agentStatus.orElse(null)); } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java index 6e16df7f2940..d2e68e8ab592 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentServiceImpl.java @@ -46,6 +46,7 @@ import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.cluster.ClusterKeyUtils; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import org.apache.thrift.TBase; import org.apache.thrift.TException; import org.springframework.beans.factory.annotation.Qualifier; @@ -158,8 +159,8 @@ public List getRecentAgentInfoList(String applicationName, long currentTime = System.currentTimeMillis(); - Set agentInfos = agentInfoService.getRecentAgentsByApplicationName(applicationName, currentTime, timeDiff); - return agentInfos.stream() + Set agentInfoAndStatusSet = agentInfoService.getRecentAgentsByApplicationName(applicationName, currentTime, timeDiff); + return agentInfoAndStatusSet.stream() .filter(Objects::nonNull) .map(ClusterKeyUtils::withStatusFrom) .collect(Collectors.toList()); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndLink.java similarity index 88% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndLink.java index bdbfe342182d..e8bfff800e79 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndLink.java @@ -7,11 +7,11 @@ import java.util.List; import java.util.Objects; -public class AgentInfoAndLink { +public class AgentAndLink { private final AgentInfo agentInfo; private final List hyperLinkList; - public AgentInfoAndLink(AgentInfo agentInfo, List hyperLinkList) { + public AgentAndLink(AgentInfo agentInfo, List hyperLinkList) { this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); this.hyperLinkList = Objects.requireNonNull(hyperLinkList, "hyperLinkList"); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndStatus.java similarity index 62% rename from web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java rename to web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndStatus.java index 0c00946b2fb3..53a9a0d738ef 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentAndStatus.java @@ -2,15 +2,20 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped; +import javax.annotation.Nullable; import java.util.Objects; -public class AgentInfoAndStatus { +public class AgentAndStatus { private final AgentInfo agentInfo; private final AgentStatus status; - public AgentInfoAndStatus(AgentInfo agentInfo, AgentStatus status) { + public AgentAndStatus(AgentInfo agentInfo, @Nullable AgentStatus status) { this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); - this.status = Objects.requireNonNull(status, "status"); + this.status = status; + } + + public AgentAndStatus(AgentInfo agentInfo) { + this(agentInfo, null); } @JsonUnwrapped diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java index a2f59cebb97b..ce4abe6b8648 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java @@ -171,15 +171,6 @@ public void setContainer(boolean container) { this.container = container; } - public AgentStatus getStatus() { - return status; - } - - public void setStatus(AgentStatus status) { - this.status = Objects.requireNonNull(status, "status"); - } - - @Override public boolean equals(Object o) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilter.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilter.java index a5fe5c520227..b6797555b7e3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilter.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilter.java @@ -6,18 +6,18 @@ public interface AgentInfoFilter { boolean ACCEPT = true; boolean REJECT = false; - boolean filter(AgentInfo agentInfo); + boolean filter(AgentAndStatus agentInfo); - static boolean accept(AgentInfo agentInfo) { + static boolean accept(AgentAndStatus agentAndStatus) { return ACCEPT; } - static boolean reject(AgentInfo agentInfo) { + static boolean reject(AgentAndStatus agentAndStatus) { return REJECT; } - static boolean filterRunning(AgentInfo agentInfo) { - final AgentStatus agentStatus = agentInfo.getStatus(); + static boolean filterRunning(AgentAndStatus agentAndStatus) { + final AgentStatus agentStatus = agentAndStatus.getStatus(); if (agentStatus == null) { return REJECT; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChain.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChain.java index 5fa7f09c7e1b..3e2799005b18 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChain.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChain.java @@ -10,9 +10,9 @@ public AgentInfoFilterChain(AgentInfoFilter... agentInfoFilters) { } @Override - public boolean filter(AgentInfo agentInfo) { + public boolean filter(AgentAndStatus agentAndStatus) { for (AgentInfoFilter agentFilter : this.agentInfoFilters) { - if (agentFilter.filter(agentInfo) == ACCEPT) { + if (agentFilter.filter(agentAndStatus) == ACCEPT) { return ACCEPT; } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentList.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentList.java index 69d7667bcccf..bead24160661 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentList.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentList.java @@ -26,9 +26,9 @@ public class ApplicationAgentList { private final String groupName; - private final List agentInfoAndLinkList; + private final List agentInfoAndLinkList; - public ApplicationAgentList(String groupName, List agentInfoAndLinkList) { + public ApplicationAgentList(String groupName, List agentInfoAndLinkList) { this.groupName = Objects.requireNonNull(groupName, "groupName"); this.agentInfoAndLinkList = Objects.requireNonNull(agentInfoAndLinkList, "agentInfoAndLinkList"); } @@ -39,11 +39,11 @@ public String getGroupName() { public List getAgentInfos() { return agentInfoAndLinkList.stream() - .map(AgentInfoAndLink::getAgentInfo) + .map(AgentAndLink::getAgentInfo) .collect(Collectors.toList()); } - public List getAgentInfoAndLinks() { + public List getAgentInfoAndLinks() { return agentInfoAndLinkList; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsList.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsList.java index 9eea59b26821..0d89d5561da3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsList.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsList.java @@ -38,28 +38,35 @@ */ @JsonSerialize(using = ApplicationAgentsListSerializer.class) public class ApplicationAgentsList { - public enum GroupBy { APPLICATION_NAME { @Override - protected GroupingKey extractKey(AgentInfo agentInfo) { - return new StringGroupingKey(agentInfo.getApplicationName()); + protected GroupingKey extractKey(AgentAndStatus agentInfoAndStatus) { + return new StringGroupingKey(agentInfoAndStatus.getAgentInfo().getApplicationName()); } @Override - protected Comparator getComparator() { - return AgentInfo.AGENT_NAME_ASC_COMPARATOR; + protected Comparator getComparator() { + return new Comparator() { + @Override + public int compare(AgentAndStatus o1, AgentAndStatus o2) { + return AgentInfo.AGENT_NAME_ASC_COMPARATOR.compare(o1.getAgentInfo(), o2.getAgentInfo()); + } + }; } }, HOST_NAME { @Override - protected GroupingKey extractKey(AgentInfo agentInfo) { + protected GroupingKey extractKey(AgentAndStatus agentInfoAndStatus) { + AgentInfo agentInfo = agentInfoAndStatus.getAgentInfo(); return new HostNameContainerGroupingKey(agentInfo.getHostName(), agentInfo.isContainer()); } @Override - protected Comparator getComparator() { - return (agentInfo1, agentInfo2) -> { + protected Comparator getComparator() { + return (agentInfoAndStatus1, agentInfoAndStatus2) -> { + final AgentInfo agentInfo1 = agentInfoAndStatus1.getAgentInfo(); + final AgentInfo agentInfo2 = agentInfoAndStatus2.getAgentInfo(); if (agentInfo1.isContainer() && agentInfo2.isContainer()) { // reverse start time order if both are containers return Long.compare(agentInfo2.getStartTimestamp(), agentInfo1.getStartTimestamp()); @@ -76,12 +83,12 @@ protected Comparator getComparator() { } }; - protected abstract GroupingKey extractKey(AgentInfo agentInfo); + protected abstract GroupingKey extractKey(AgentAndStatus agentInfoAndStatus); /** * Do not use this for sorted set and maps. */ - protected abstract Comparator getComparator(); + protected abstract Comparator getComparator(); } /** @@ -96,7 +103,7 @@ private interface GroupingKey> extends Comparable { private final AgentInfoFilter filter; private final HyperLinkFactory hyperLinkFactory; - private final Map> agentsMap = new TreeMap<>(); + private final Map> agentsMap = new TreeMap<>(); public ApplicationAgentsList(GroupBy groupBy, AgentInfoFilter filter, HyperLinkFactory hyperLinkFactory) { this.groupBy = Objects.requireNonNull(groupBy, "groupBy"); @@ -104,23 +111,23 @@ public ApplicationAgentsList(GroupBy groupBy, AgentInfoFilter filter, HyperLinkF this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); } - public void add(AgentInfo agentInfo) { - if (filter.filter(agentInfo) == AgentInfoFilter.REJECT) { + public void add(AgentAndStatus agentInfoAndStatus) { + if (filter.filter(agentInfoAndStatus) == AgentInfoFilter.REJECT) { return; } - GroupingKey key = groupBy.extractKey(agentInfo); - List agentInfos = agentsMap.computeIfAbsent(key, k -> new ArrayList<>()); - agentInfos.add(agentInfo); + GroupingKey key = groupBy.extractKey(agentInfoAndStatus); + List agentInfos = agentsMap.computeIfAbsent(key, k -> new ArrayList<>()); + agentInfos.add(agentInfoAndStatus); } - public void addAll(Iterable agentInfos) { - for (AgentInfo agentInfo : agentInfos) { - add(agentInfo); + public void addAll(Iterable agentInfoAndStatusList) { + for (AgentAndStatus agent : agentInfoAndStatusList) { + add(agent); } } public void merge(ApplicationAgentsList applicationAgentList) { - for (List agentInfos : applicationAgentList.agentsMap.values()) { + for (List agentInfos : applicationAgentList.agentsMap.values()) { addAll(agentInfos); } } @@ -130,14 +137,15 @@ public List getApplicationAgentLists() { return Collections.emptyList(); } List applicationAgentLists = new ArrayList<>(agentsMap.size()); - for (Map.Entry> entry : agentsMap.entrySet()) { + for (Map.Entry> entry : agentsMap.entrySet()) { final GroupingKey groupingKey = entry.getKey(); - final List agentInfoList = entry.getValue(); + final List agentInfoList = entry.getValue(); - List applicationAgents = new ArrayList<>(agentInfoList); + List applicationAgents = new ArrayList<>(agentInfoList); applicationAgents.sort(groupBy.getComparator()); - List agentInfoAndLinks = applicationAgents.stream() + List agentInfoAndLinks = applicationAgents.stream() + .map(AgentAndStatus::getAgentInfo) .map(this::newAgentInfoAndLink) .collect(Collectors.toList()); @@ -146,9 +154,9 @@ public List getApplicationAgentLists() { return applicationAgentLists; } - private AgentInfoAndLink newAgentInfoAndLink(AgentInfo agentInfo) { + private AgentAndLink newAgentInfoAndLink(AgentInfo agentInfo) { List hyperLinks = hyperLinkFactory.build(LinkSources.from(agentInfo)); - return new AgentInfoAndLink(agentInfo, hyperLinks); + return new AgentAndLink(agentInfo, hyperLinks); } @Override diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/DefaultAgentInfoFilter.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/DefaultAgentInfoFilter.java index 4dcb560fd4cc..ea5ea553b2a0 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/vo/DefaultAgentInfoFilter.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/DefaultAgentInfoFilter.java @@ -10,8 +10,8 @@ public DefaultAgentInfoFilter(long from) { } @Override - public boolean filter(AgentInfo agentInfo) { - final AgentStatus agentStatus = agentInfo.getStatus(); + public boolean filter(AgentAndStatus agentAndStatus) { + final AgentStatus agentStatus = agentAndStatus.getStatus(); if (agentStatus == null) { return REJECT; } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java index fd6705c21deb..a88b09c3197a 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ApplicationMapBuilderTest.java @@ -31,6 +31,7 @@ import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.service.AgentInfoService; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentStatus; import com.navercorp.pinpoint.web.vo.AgentStatusQuery; import com.navercorp.pinpoint.web.vo.Application; @@ -46,7 +47,6 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -106,16 +106,14 @@ public List answer(InvocationOnMock invocation) { 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>() { + when(agentInfoService.getAgentsByApplicationName(anyString(), anyLong())).thenAnswer(new Answer>() { @Override - public Set answer(InvocationOnMock invocation) throws Throwable { + public Set 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 agentInfos = new HashSet<>(); - agentInfos.add(agentInfo); - return agentInfos; + + return Set.of(new AgentAndStatus(agentInfo, agentStatus)); } }); when(agentInfoService.getAgentsByApplicationNameWithoutStatus(anyString(), anyLong())).thenAnswer(new Answer>() { @@ -123,9 +121,7 @@ public Set answer(InvocationOnMock invocation) throws Throwable { public Set answer(InvocationOnMock invocation) throws Throwable { String applicationName = invocation.getArgument(0); AgentInfo agentInfo = ApplicationMapBuilderTestHelper.createAgentInfoFromApplicationName(applicationName); - Set agentInfos = new HashSet<>(); - agentInfos.add(agentInfo); - return agentInfos; + return Set.of(agentInfo); } }); when(agentInfoService.getAgentStatus(anyString(), anyLong())).thenAnswer(new Answer() { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java index 37a3805d3a66..804f7464c6b2 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerBuilder; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentInfoFactory; import org.hamcrest.MatcherAssert; @@ -44,10 +45,10 @@ public class ServerInstanceListTest { @Test public void testGetAgentIdList() { - AgentInfo agentInfo1 = createAgentInfo("agentId1", "testHost"); - AgentInfo agentInfo2 = createAgentInfo("agentId2", "testHost"); + AgentAndStatus agentInfo1 = createAgentInfo("agentId1", "testHost"); + AgentAndStatus agentInfo2 = createAgentInfo("agentId2", "testHost"); - Set agentInfoSet = new HashSet<>(); + Set agentInfoSet = new HashSet<>(); agentInfoSet.add(agentInfo1); agentInfoSet.add(agentInfo2); @@ -61,7 +62,7 @@ public void testGetAgentIdList() { MatcherAssert.assertThat(agentIdList, hasItem("agentId2")); } - public static AgentInfo createAgentInfo(String agentId, String hostName) { + public static AgentAndStatus createAgentInfo(String agentId, String hostName) { AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder(); agentInfoBuilder.setAgentId(agentId); @@ -73,7 +74,7 @@ public static AgentInfo createAgentInfo(String agentId, String hostName) { when(registry.findServiceType(serviceType.getCode())).thenReturn(serviceType); AgentInfoFactory factory = new AgentInfoFactory(registry); - return factory.build(agentInfoBuilder.build()); + return new AgentAndStatus(factory.build(agentInfoBuilder.build())); } } \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java index b805a2477486..cf4ac3acae81 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentLifeCycleDaoTest.java @@ -131,12 +131,12 @@ public void agentInfo_should_be_populated_appropriately_if_status_is_known() { givenAgentInfo.setAgentId(expectedAgentId); givenAgentInfo.setStartTimestamp(expectedTimestamp); Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(givenAgentInfo.getAgentId(), givenAgentInfo.getStartTimestamp(), expectedTimestamp); - givenAgentInfo.setStatus(agentStatus.get()); + AgentStatus givenStatus = agentStatus.get(); + // Then - AgentStatus actualAgentStatus = givenAgentInfo.getStatus(); - Assertions.assertEquals(expectedAgentId, actualAgentStatus.getAgentId()); - Assertions.assertEquals(expectedTimestamp, actualAgentStatus.getEventTimestamp()); - Assertions.assertEquals(expectedAgentLifeCycleState, actualAgentStatus.getState()); + Assertions.assertEquals(expectedAgentId, givenStatus.getAgentId()); + Assertions.assertEquals(expectedTimestamp, givenStatus.getEventTimestamp()); + Assertions.assertEquals(expectedAgentLifeCycleState, givenStatus.getState()); } @Test @@ -154,10 +154,9 @@ public void agentInfo_should_be_populated_as_unknown_if_status_cannot_be_found() givenAgentInfo.setStartTimestamp(expectedTimestamp); // When Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(givenAgentInfo.getAgentId(), givenAgentInfo.getStartTimestamp(), expectedTimestamp); - givenAgentInfo.setStatus(agentStatus.get()); + AgentStatus actualAgentStatus = agentStatus.get(); // Then - AgentStatus actualAgentStatus = givenAgentInfo.getStatus(); Assertions.assertEquals(expectedAgentId, actualAgentStatus.getAgentId()); Assertions.assertEquals(expectedTimestamp, actualAgentStatus.getEventTimestamp()); Assertions.assertEquals(expectedAgentLifeCycleState, actualAgentStatus.getState()); @@ -187,7 +186,7 @@ public void agentInfos_should_be_populated_accordingly_even_with_nulls() { Assertions.assertEquals(nullAgentInfo, givenAgentInfos.get(1)); Assertions.assertEquals(nonNullAgentInfo, givenAgentInfos.get(2)); Assertions.assertEquals(nullAgentInfo, givenAgentInfos.get(3)); - AgentStatus nonNullAgentInfoStatus = agentStatus.get(0).get(); + AgentStatus nonNullAgentInfoStatus = agentStatus.get(0).orElse(null); Assertions.assertEquals(expectedAgentId, nonNullAgentInfoStatus.getAgentId()); Assertions.assertEquals(expectedTimestamp, Instant.ofEpochMilli(nonNullAgentInfoStatus.getEventTimestamp())); Assertions.assertEquals(expectedAgentLifeCycleState, nonNullAgentInfoStatus.getState()); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java index 975c848e739a..50449097bcf1 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java @@ -28,12 +28,10 @@ import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.web.applicationmap.ServerInstanceListTest; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerBuilder; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; -import com.navercorp.pinpoint.web.util.ServiceTypeRegistryMockFactory; -import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentAndStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Test; @@ -53,10 +51,8 @@ public void testSerialize() throws Exception { ObjectMapper mapper = createMapper(); - AgentInfo agentInfo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost"); - - Set agentInfoSet = new HashSet<>(); - agentInfoSet.add(agentInfo); + AgentAndStatus agentInfo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost"); + Set agentInfoSet = Set.of(agentInfo); ServerBuilder builder = new ServerBuilder(); builder.addAgentInfo(agentInfoSet); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChainTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChainTest.java index a6d58131037f..d9b08d314fe0 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChainTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/AgentInfoFilterChainTest.java @@ -16,10 +16,9 @@ public void filter_running() { ); AgentStatus status = new AgentStatus("testAgent", AgentLifeCycleState.RUNNING, current); - AgentInfo info = new AgentInfo(); - info.setStatus(status); + AgentAndStatus agentAndStatus = new AgentAndStatus(new AgentInfo(), status); - Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(info)); + Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(agentAndStatus)); } @Test @@ -31,10 +30,8 @@ public void filter_from_accept() { ); AgentStatus status = new AgentStatus("testAgent", AgentLifeCycleState.RUNNING, current); - AgentInfo info = new AgentInfo(); - info.setStatus(status); - - Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(info)); + AgentAndStatus agentAndStatus = new AgentAndStatus(new AgentInfo(), status); + Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(agentAndStatus)); } @Test @@ -46,9 +43,7 @@ public void filter_from_reject() { ); AgentStatus status = new AgentStatus("testAgent", AgentLifeCycleState.RUNNING, current); - AgentInfo info = new AgentInfo(); - info.setStatus(status); - - Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(info)); + AgentAndStatus agentAndStatus = new AgentAndStatus(new AgentInfo(), status); + Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(agentAndStatus)); } } \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsListTest.java index fb9a8c8b2c0b..95e8e109cf75 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsListTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/vo/ApplicationAgentsListTest.java @@ -34,10 +34,10 @@ public class ApplicationAgentsListTest { @Test public void groupByApplicationName() { ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.APPLICATION_NAME, AgentInfoFilter::accept, hyperLinkFactory); - AgentInfo app1Agent1 = createAgentInfo("APP_1", "app1-agent1", "Host11", true); - AgentInfo app1Agent2 = createAgentInfo("APP_1", "app1-agent2", "Host12", false); - AgentInfo app2Agent1 = createAgentInfo("APP_2", "app2-agent1", "Host21", false); - AgentInfo app2Agent2 = createAgentInfo("APP_2", "app2-agent2", "Host22", true); + AgentAndStatus app1Agent1 = createAgentInfo("APP_1", "app1-agent1", "Host11", true); + AgentAndStatus app1Agent2 = createAgentInfo("APP_1", "app1-agent2", "Host12", false); + AgentAndStatus app2Agent1 = createAgentInfo("APP_2", "app2-agent1", "Host21", false); + AgentAndStatus app2Agent2 = createAgentInfo("APP_2", "app2-agent2", "Host22", true); applicationAgentsList.addAll(shuffleAgentInfos(app1Agent1, app1Agent2, app2Agent1, app2Agent2)); List applicationAgentLists = applicationAgentsList.getApplicationAgentLists(); @@ -48,24 +48,24 @@ public void groupByApplicationName() { Assertions.assertEquals("APP_1", app1AgentList.getGroupName()); List app1AgentInfos = app1AgentList.getAgentInfos(); Assertions.assertEquals(2, app1AgentInfos.size()); - Assertions.assertEquals(app1Agent1, app1AgentInfos.get(0)); - Assertions.assertEquals(app1Agent2, app1AgentInfos.get(1)); + Assertions.assertEquals(app1Agent1.getAgentInfo(), app1AgentInfos.get(0)); + Assertions.assertEquals(app1Agent2.getAgentInfo(), app1AgentInfos.get(1)); ApplicationAgentList app2AgentList = applicationAgentLists.get(1); Assertions.assertEquals("APP_2", app2AgentList.getGroupName()); List app2AgentInfos = app2AgentList.getAgentInfos(); Assertions.assertEquals(2, app2AgentInfos.size()); - Assertions.assertEquals(app2Agent1, app2AgentInfos.get(0)); - Assertions.assertEquals(app2Agent2, app2AgentInfos.get(1)); + Assertions.assertEquals(app2Agent1.getAgentInfo(), app2AgentInfos.get(0)); + Assertions.assertEquals(app2Agent2.getAgentInfo(), app2AgentInfos.get(1)); } @Test public void groupByHostNameShouldHaveContainersFirstAndGroupedSeparatelyByAgentStartTimestampDescendingOrder() { ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); - AgentInfo host1Agent1 = createAgentInfo("APP_1", "host1-agent1", "Host1", false); - AgentInfo host2Agent1 = createAgentInfo("APP_1", "host2-agent1", "Host2", false); - AgentInfo containerAgent1 = createAgentInfo("APP_1", "container-agent1", "Host3", true, 1); - AgentInfo containerAgent2 = createAgentInfo("APP_1", "container-agent2", "Host4", true, 2); + AgentAndStatus host1Agent1 = createAgentInfo("APP_1", "host1-agent1", "Host1", false); + AgentAndStatus host2Agent1 = createAgentInfo("APP_1", "host2-agent1", "Host2", false); + AgentAndStatus containerAgent1 = createAgentInfo("APP_1", "container-agent1", "Host3", true, 1); + AgentAndStatus containerAgent2 = createAgentInfo("APP_1", "container-agent2", "Host4", true, 2); applicationAgentsList.addAll(shuffleAgentInfos(containerAgent1, host1Agent1, host2Agent1, containerAgent2)); List applicationAgentLists = applicationAgentsList.getApplicationAgentLists(); @@ -76,29 +76,29 @@ public void groupByHostNameShouldHaveContainersFirstAndGroupedSeparatelyByAgentS Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName()); List containerAgents = containerAgentList.getAgentInfos(); Assertions.assertEquals(2, containerAgents.size()); - Assertions.assertEquals(containerAgent2, containerAgents.get(0)); - Assertions.assertEquals(containerAgent1, containerAgents.get(1)); + Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0)); + Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1)); ApplicationAgentList host1AgentList = applicationAgentLists.get(1); Assertions.assertEquals("Host1", host1AgentList.getGroupName()); List host1Agents = host1AgentList.getAgentInfos(); Assertions.assertEquals(1, host1Agents.size()); - Assertions.assertEquals(host1Agent1, host1Agents.get(0)); + Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0)); ApplicationAgentList host2AgentList = applicationAgentLists.get(2); Assertions.assertEquals("Host2", host2AgentList.getGroupName()); List host2Agents = host2AgentList.getAgentInfos(); Assertions.assertEquals(1, host2Agents.size()); - Assertions.assertEquals(host2Agent1, host2Agents.get(0)); + Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0)); } @Test public void mergeLists() { - AgentInfo host1Agent1 = createAgentInfo("APP_1", "host1-agent1", "Host1", false); - AgentInfo host2Agent1 = createAgentInfo("APP_1", "host2-agent1", "Host2", false); - AgentInfo containerAgent1 = createAgentInfo("APP_1", "container-agent1", "Host3", true, 1); - AgentInfo containerAgent2 = createAgentInfo("APP_1", "container-agent2", "Host4", true, 2); - List agentInfos = shuffleAgentInfos(containerAgent1, host1Agent1, host2Agent1, containerAgent2); + AgentAndStatus host1Agent1 = createAgentInfo("APP_1", "host1-agent1", "Host1", false); + AgentAndStatus host2Agent1 = createAgentInfo("APP_1", "host2-agent1", "Host2", false); + AgentAndStatus containerAgent1 = createAgentInfo("APP_1", "container-agent1", "Host3", true, 1); + AgentAndStatus containerAgent2 = createAgentInfo("APP_1", "container-agent2", "Host4", true, 2); + List agentInfos = shuffleAgentInfos(containerAgent1, host1Agent1, host2Agent1, containerAgent2); ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); applicationAgentsList.addAll(agentInfos.subList(0, agentInfos.size() / 2)); @@ -114,27 +114,27 @@ public void mergeLists() { Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName()); List containerAgents = containerAgentList.getAgentInfos(); Assertions.assertEquals(2, containerAgents.size()); - Assertions.assertEquals(containerAgent2, containerAgents.get(0)); - Assertions.assertEquals(containerAgent1, containerAgents.get(1)); + Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0)); + Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1)); ApplicationAgentList host1AgentList = applicationAgentLists.get(1); Assertions.assertEquals("Host1", host1AgentList.getGroupName()); List host1Agents = host1AgentList.getAgentInfos(); Assertions.assertEquals(1, host1Agents.size()); - Assertions.assertEquals(host1Agent1, host1Agents.get(0)); + Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0)); ApplicationAgentList host2AgentList = applicationAgentLists.get(2); Assertions.assertEquals("Host2", host2AgentList.getGroupName()); List host2Agents = host2AgentList.getAgentInfos(); Assertions.assertEquals(1, host2Agents.size()); - Assertions.assertEquals(host2Agent1, host2Agents.get(0)); + Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0)); } @Test public void mergeListsGroupedDifferently() { - AgentInfo agent1 = createAgentInfo("APP_1", "app1-agent1", "Host1", false); - AgentInfo agent2 = createAgentInfo("APP_2", "app2-agent1", "Host2", false); - AgentInfo agent3 = createAgentInfo("APP_2", "app2-agent2", "Host2", true); + AgentAndStatus agent1 = createAgentInfo("APP_1", "app1-agent1", "Host1", false); + AgentAndStatus agent2 = createAgentInfo("APP_2", "app2-agent1", "Host2", false); + AgentAndStatus agent3 = createAgentInfo("APP_2", "app2-agent2", "Host2", true); ApplicationAgentsList groupedByHostnameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); groupedByHostnameList.add(agent1); ApplicationAgentsList groupedByApplicationNameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.APPLICATION_NAME, AgentInfoFilter::accept, hyperLinkFactory); @@ -150,38 +150,38 @@ public void mergeListsGroupedDifferently() { Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName()); List containerAgents = containerAgentList.getAgentInfos(); Assertions.assertEquals(1, containerAgents.size()); - Assertions.assertEquals(agent3, containerAgents.get(0)); + Assertions.assertEquals(agent3.getAgentInfo(), containerAgents.get(0)); ApplicationAgentList host1AgentList = applicationAgentLists.get(1); Assertions.assertEquals("Host1", host1AgentList.getGroupName()); List host1Agents = host1AgentList.getAgentInfos(); Assertions.assertEquals(1, host1Agents.size()); - Assertions.assertEquals(agent1, host1Agents.get(0)); + Assertions.assertEquals(agent1.getAgentInfo(), host1Agents.get(0)); ApplicationAgentList host2AgentList = applicationAgentLists.get(2); Assertions.assertEquals("Host2", host2AgentList.getGroupName()); List host2Agents = host2AgentList.getAgentInfos(); Assertions.assertEquals(1, host2Agents.size()); - Assertions.assertEquals(agent2, host2Agents.get(0)); + Assertions.assertEquals(agent2.getAgentInfo(), host2Agents.get(0)); } - private static List shuffleAgentInfos(AgentInfo... agentInfos) { - List agentInfoList = Arrays.asList(agentInfos); + private static List shuffleAgentInfos(AgentAndStatus... agentInfos) { + List agentInfoList = Arrays.asList(agentInfos); Collections.shuffle(agentInfoList); return agentInfoList; } - private static AgentInfo createAgentInfo(String applicationName, String agentId, String hostname, boolean container) { + private static AgentAndStatus createAgentInfo(String applicationName, String agentId, String hostname, boolean container) { return createAgentInfo(applicationName, agentId, hostname, container, System.currentTimeMillis()); } - private static AgentInfo createAgentInfo(String applicationName, String agentId, String hostname, boolean container, long startTimestamp) { + private static AgentAndStatus createAgentInfo(String applicationName, String agentId, String hostname, boolean container, long startTimestamp) { AgentInfo agentInfo = new AgentInfo(); agentInfo.setApplicationName(applicationName); agentInfo.setAgentId(agentId); agentInfo.setHostName(hostname); agentInfo.setContainer(container); agentInfo.setStartTimestamp(startTimestamp); - return agentInfo; + return new AgentAndStatus(agentInfo); } }