From 6c429fdffb84843093c208b57ba66b2a0638d931 Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 15 Jul 2022 12:12:30 +0900 Subject: [PATCH 1/3] [#9023] Refactor HyperLink --- ...AgentInfoServerInstanceListDataSource.java | 7 +- .../applicationmap/nodes/ServerBuilder.java | 41 ++++- .../applicationmap/nodes/ServerInstance.java | 16 +- .../web/hyperlink/DefaultLinkSource.java | 23 +++ .../DefaultMatcherGroup.java | 66 ++++---- .../link => hyperlink}/EmptyLinkMatcher.java | 72 ++++----- .../HyperLink.java} | 146 ++++++++--------- .../web/hyperlink/HyperLinkFactory.java | 34 ++++ .../pinpoint/web/hyperlink/LinkSource.java | 6 + .../pinpoint/web/hyperlink/LinkSources.java | 21 +++ .../link => hyperlink}/MatcherGroup.java | 152 +++++++++--------- .../PostfixServerMatcher.java | 122 +++++++------- .../link => hyperlink}/ServerMatcher.java | 50 +++--- .../web/mapper/AgentInfoResultsExtractor.java | 10 +- .../web/service/AgentInfoServiceImpl.java | 15 +- .../web/service/FilteredMapServiceImpl.java | 21 +-- .../pinpoint/web/service/MapServiceImpl.java | 16 +- .../ResponseTimeHistogramServiceImpl.java | 23 +-- .../ServerInstanceDatasourceService.java | 23 +++ .../web/view/AgentInfoSerializer.java | 23 +-- .../view/ApplicationAgentsListSerializer.java | 10 +- .../view/ServerInstanceListSerializer.java | 28 ++-- .../web/view/ServiceTypeDescView.java | 16 ++ .../navercorp/pinpoint/web/vo/AgentInfo.java | 52 +++--- .../pinpoint/web/vo/AgentInfoAndLink.java | 36 +++++ .../pinpoint/web/vo/AgentInfoFactory.java | 37 +++++ .../pinpoint/web/vo/ApplicationAgentList.java | 17 +- .../web/vo/ApplicationAgentsList.java | 29 +++- .../main/resources/applicationContext-web.xml | 1 + .../ApplicationMapBuilderTest.java | 6 +- .../ServerInstanceListTest.java | 5 +- .../PostfixServerMatcherTest.java | 86 +++++----- .../service/FilteredMapServiceImplTest.java | 53 +++--- .../web/vo/ApplicationAgentsListTest.java | 15 +- 34 files changed, 763 insertions(+), 515 deletions(-) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/DefaultMatcherGroup.java (70%) rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/EmptyLinkMatcher.java (75%) rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link/LinkInfo.java => hyperlink/HyperLink.java} (87%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLinkFactory.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSource.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSources.java rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/MatcherGroup.java (83%) rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/PostfixServerMatcher.java (83%) rename web/src/main/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/ServerMatcher.java (85%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/ServerInstanceDatasourceService.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/view/ServiceTypeDescView.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFactory.java rename web/src/test/java/com/navercorp/pinpoint/web/{applicationmap/link => hyperlink}/PostfixServerMatcherTest.java (89%) 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 8e0911c547ce..3e84693f3e5a 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 @@ -22,6 +22,7 @@ import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram; 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.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; @@ -49,9 +50,11 @@ public class AgentInfoServerInstanceListDataSource implements ServerInstanceList private final Logger logger = LogManager.getLogger(this.getClass()); private final AgentInfoService agentInfoService; + private final HyperLinkFactory hyperLinkFactory; - public AgentInfoServerInstanceListDataSource(AgentInfoService agentInfoService) { + public AgentInfoServerInstanceListDataSource(AgentInfoService agentInfoService, HyperLinkFactory hyperLinkFactory) { this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); + this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); } public ServerInstanceList createServerInstanceList(Node node, Instant timestamp) { @@ -72,7 +75,7 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp) agentInfos = filterAgentInfos(agentInfos, timestamp, node); logger.debug("add agentInfos {} : {}", application, agentInfos); - ServerBuilder builder = new ServerBuilder(); + ServerBuilder builder = new ServerBuilder(hyperLinkFactory); builder.addAgentInfo(agentInfos); 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 4dd9f5f027cc..1739b9fe7478 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 @@ -19,12 +19,16 @@ import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogram; import com.navercorp.pinpoint.web.applicationmap.rawdata.AgentHistogramList; +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.AgentInfo; - -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; @@ -37,12 +41,16 @@ public class ServerBuilder { private final Logger logger = LogManager.getLogger(this.getClass()); - private final AgentHistogramList agentHistogramList; - private final Set agentSet; + private final AgentHistogramList agentHistogramList = new AgentHistogramList(); + private final Set agentSet = new HashSet<>(); + private final HyperLinkFactory hyperLinkFactory; public ServerBuilder() { - this.agentHistogramList = new AgentHistogramList(); - this.agentSet = new HashSet<>(); + this.hyperLinkFactory = null; + } + + public ServerBuilder(HyperLinkFactory hyperLinkFactory) { + this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); } public void addCallHistogramList(AgentHistogramList agentHistogramList) { @@ -87,7 +95,8 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog final String hostName = getHostName(agentHistogram.getId()); final ServiceType serviceType = agentHistogram.getServiceType(); - final ServerInstance serverInstance = new ServerInstance(hostName, instanceName, serviceType); + final ServerInstance serverInstance = new ServerInstance(hostName, instanceName, serviceType, buildHyperLink(hostName)); + serverInstanceList.addServerInstance(serverInstance); } return serverInstanceList; @@ -96,13 +105,29 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog public ServerInstanceList buildPhysicalServer(final Set agentSet) { final ServerInstanceList serverInstanceList = new ServerInstanceList(); for (AgentInfo agent : agentSet) { - final ServerInstance serverInstance = new ServerInstance(agent); + final ServerInstance serverInstance = new ServerInstance(agent, buildHyperLink(agent)); serverInstanceList.addServerInstance(serverInstance); } return serverInstanceList; } + private List buildHyperLink(AgentInfo agentInfo) { + if (hyperLinkFactory != null) { + return hyperLinkFactory.build(LinkSources.from(agentInfo)); + } else { + return Collections.emptyList(); + } + } + + private List buildHyperLink(String hostName) { + if (hyperLinkFactory != null) { + return hyperLinkFactory.build(LinkSources.from(hostName)); + } else { + return Collections.emptyList(); + } + } + public ServerInstanceList build() { if (!agentSet.isEmpty()) { // if agent name exists (physical server exists) 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 2554d694f942..7735da1cec91 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 @@ -16,13 +16,16 @@ package com.navercorp.pinpoint.web.applicationmap.nodes; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.hyperlink.HyperLink; import com.navercorp.pinpoint.web.view.ServerInstanceSerializer; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; +import java.util.List; import java.util.Objects; /** @@ -45,7 +48,9 @@ public class ServerInstance { private final AgentLifeCycleState status; - public ServerInstance(AgentInfo agentInfo) { + private final List linkList; + + public ServerInstance(AgentInfo agentInfo, List linkList) { Objects.requireNonNull(agentInfo, "agentInfo"); this.hostName = agentInfo.getHostName(); @@ -60,9 +65,10 @@ public ServerInstance(AgentInfo agentInfo) { this.status = AgentLifeCycleState.UNKNOWN; } this.serverType = ServerType.Physical; + this.linkList = Objects.requireNonNull(linkList, "linkList"); } - public ServerInstance(String hostName, String physicalName, ServiceType serviceType) { + public ServerInstance(String hostName, String physicalName, ServiceType serviceType, List linkList) { this.hostName = Objects.requireNonNull(hostName, "hostName"); this.ip = null; this.agentName = null; @@ -70,6 +76,7 @@ public ServerInstance(String hostName, String physicalName, ServiceType serviceT this.serviceType = Objects.requireNonNull(serviceType, "serviceType"); this.status = AgentLifeCycleState.UNKNOWN; this.serverType = ServerType.Logical; + this.linkList = Objects.requireNonNull(linkList, "linkList"); } public String getHostName() { @@ -88,6 +95,7 @@ public short getServiceTypeCode() { return serviceType.getCode(); } + @JsonIgnore public ServiceType getServiceType() { return serviceType; } @@ -104,6 +112,10 @@ public String getIp() { return ip; } + public List getLinkList() { + return linkList; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java new file mode 100644 index 000000000000..e3413512e034 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java @@ -0,0 +1,23 @@ +package com.navercorp.pinpoint.web.hyperlink; + + +public class DefaultLinkSource implements LinkSource { + private final String hostName; + private final String ip; + + + public DefaultLinkSource(String hostName, String ip) { + this.hostName = hostName; + this.ip = ip; + } + + @Override + public String getHostName() { + return hostName; + } + + @Override + public String getIp() { + return ip; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/DefaultMatcherGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultMatcherGroup.java similarity index 70% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/DefaultMatcherGroup.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultMatcherGroup.java index 6d6aedb299d5..4a4942cae93d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/DefaultMatcherGroup.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultMatcherGroup.java @@ -1,36 +1,32 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -/** - * @author minwoo.jung - */ -public class DefaultMatcherGroup extends MatcherGroup { - - public boolean ismatchingType(Object value) { - if (value instanceof String) { - return true; - } - - return false; - } - - @Override - protected String getMatchingSource(Object data) { - return (String)data; - } +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +/** + * @author minwoo.jung + */ +public class DefaultMatcherGroup extends MatcherGroup { + + public boolean isMatchingType(LinkSource linkSource) { + return false; + } + + @Override + protected String getMatchingSource(LinkSource linkSource) { + return null; + } } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/EmptyLinkMatcher.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/EmptyLinkMatcher.java similarity index 75% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/EmptyLinkMatcher.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/EmptyLinkMatcher.java index ff229815c13a..12a36ce7d0d9 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/EmptyLinkMatcher.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/EmptyLinkMatcher.java @@ -1,37 +1,37 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -import com.navercorp.pinpoint.web.applicationmap.link.LinkInfo.LinkType; - -/** - * @author minwoo.jung - * - */ -public class EmptyLinkMatcher implements ServerMatcher { - - @Override - public boolean isMatched(String value) { - return true; - } - - @Override - public LinkInfo getLinkInfo(String value) { - return new LinkInfo("", "", LinkType.ATAG); - } - +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +import com.navercorp.pinpoint.web.hyperlink.HyperLink.LinkType; + +/** + * @author minwoo.jung + * + */ +public class EmptyLinkMatcher implements ServerMatcher { + + @Override + public boolean isMatched(String value) { + return true; + } + + @Override + public HyperLink getLinkInfo(String value) { + return new HyperLink("", "", LinkType.ATAG); + } + } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkInfo.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLink.java similarity index 87% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkInfo.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLink.java index 61da6873948e..a4035efb3dbd 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/LinkInfo.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLink.java @@ -1,74 +1,74 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.navercorp.pinpoint.web.applicationmap.link; - -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * @author minwoo.jung - * - */ -public class LinkInfo { - private final String linkName; - private final String linkUrl; - private final LinkType linkType; - - public LinkInfo(String linkName, String linkUrl, LinkType linkType) { - this.linkName = linkName; - this.linkUrl = linkUrl; - this.linkType = linkType; - } - - @JsonProperty("linkName") - public String getLinkName() { - return linkName; - } - - @JsonProperty("linkURL") - public String getLinkUrl() { - return linkUrl; - } - - - @JsonProperty("linkType") - public String getLinkType() { - return linkType.getName(); - } - - @Override - public String toString() { - return "LinkInfo{" + - "linkName='" + linkName + '\'' + - ", linkUrl='" + linkUrl + '\'' + - ", linkType=" + linkType + - '}'; - } - - public enum LinkType { - ATAG("aTag"), - BUTTON("button"); - - private final String name; - - LinkType(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.navercorp.pinpoint.web.hyperlink; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author minwoo.jung + * + */ +public class HyperLink { + private final String linkName; + private final String linkUrl; + private final LinkType linkType; + + public HyperLink(String linkName, String linkUrl, LinkType linkType) { + this.linkName = linkName; + this.linkUrl = linkUrl; + this.linkType = linkType; + } + + @JsonProperty("linkName") + public String getLinkName() { + return linkName; + } + + @JsonProperty("linkURL") + public String getLinkUrl() { + return linkUrl; + } + + + @JsonProperty("linkType") + public String getLinkType() { + return linkType.getName(); + } + + @Override + public String toString() { + return "HyperLink{" + + "linkName='" + linkName + '\'' + + ", linkUrl='" + linkUrl + '\'' + + ", linkType=" + linkType + + '}'; + } + + public enum LinkType { + ATAG("aTag"), + BUTTON("button"); + + private final String name; + + LinkType(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLinkFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLinkFactory.java new file mode 100644 index 000000000000..eccde4494c94 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/HyperLinkFactory.java @@ -0,0 +1,34 @@ +package com.navercorp.pinpoint.web.hyperlink; + +import com.navercorp.pinpoint.common.util.ArrayUtils; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class HyperLinkFactory { + private final MatcherGroup[] matcherGroups; + + public HyperLinkFactory(@Nullable List matcherGroups) { + if (matcherGroups == null) { + this.matcherGroups = new MatcherGroup[0]; + } else { + this.matcherGroups = matcherGroups.toArray(new MatcherGroup[0]); + } + } + + public List build(LinkSource source) { + if (ArrayUtils.isEmpty(matcherGroups)) { + return Collections.emptyList(); + } + List list = new ArrayList<>(); + for (MatcherGroup matcherGroup : matcherGroups) { + if (matcherGroup.isMatchingType(source)) { + HyperLink linkInfo = matcherGroup.makeLinkInfo(source); + list.add(linkInfo); + } + } + return list; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSource.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSource.java new file mode 100644 index 000000000000..2d0be8eb5c88 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSource.java @@ -0,0 +1,6 @@ +package com.navercorp.pinpoint.web.hyperlink; + +public interface LinkSource { + String getHostName(); + String getIp(); +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSources.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSources.java new file mode 100644 index 000000000000..37a3024d6312 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/LinkSources.java @@ -0,0 +1,21 @@ +package com.navercorp.pinpoint.web.hyperlink; + +import com.navercorp.pinpoint.web.vo.AgentInfo; + +import java.util.Objects; + +public final class LinkSources { + private LinkSources() { + } + + public static LinkSource from(String hostName) { + Objects.requireNonNull(hostName, "hostName"); + return new DefaultLinkSource(hostName, null); + } + + public static LinkSource from(AgentInfo agentInfo) { + Objects.requireNonNull(agentInfo, "agentInfo"); + return new DefaultLinkSource(agentInfo.getHostName(), agentInfo.getIp()); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/MatcherGroup.java similarity index 83% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/MatcherGroup.java index ea34f2ad7a8d..312628506abc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/MatcherGroup.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/MatcherGroup.java @@ -1,77 +1,77 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * @author emeroad - * @author minwoo.jung - */ -public abstract class MatcherGroup { - - final List serverMatcherList = new ArrayList<>(); - ServerMatcher defaultMatcher = new EmptyLinkMatcher(); - - public MatcherGroup() { - } - - public void setDefaultMatcher(ServerMatcher defaultMatcher) { - this.defaultMatcher = Objects.requireNonNull(defaultMatcher, "defaultMatcher"); - } - - public ServerMatcher getDefaultMatcher() { - return this.defaultMatcher; - } - - public void addServerMatcher(ServerMatcher serverMatcher) { - Objects.requireNonNull(serverMatcher, "serverMatcher"); - - serverMatcherList.add(serverMatcher); - } - - public void addMatcherGroup(MatcherGroup MatcherGroup) { - serverMatcherList.addAll(MatcherGroup.getServerMatcherList()); - defaultMatcher = MatcherGroup.getDefaultMatcher(); - } - - public List getServerMatcherList() { - return serverMatcherList; - } - - public LinkInfo makeLinkInfo(Object data) { - ServerMatcher serverMatcher = defaultMatcher; - String value = getMatchingSource(data); - - Objects.requireNonNull(value, "value"); - - - for (ServerMatcher matcher : serverMatcherList) { - if(matcher.isMatched(value)) { - serverMatcher = matcher; - } - } - - return serverMatcher.getLinkInfo(value); - } - - abstract protected String getMatchingSource(Object data); - - abstract public boolean ismatchingType(Object data); +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * @author emeroad + * @author minwoo.jung + */ +public abstract class MatcherGroup { + + final List serverMatcherList = new ArrayList<>(); + ServerMatcher defaultMatcher = new EmptyLinkMatcher(); + + public MatcherGroup() { + } + + public void setDefaultMatcher(ServerMatcher defaultMatcher) { + this.defaultMatcher = Objects.requireNonNull(defaultMatcher, "defaultMatcher"); + } + + public ServerMatcher getDefaultMatcher() { + return this.defaultMatcher; + } + + public void addServerMatcher(ServerMatcher serverMatcher) { + Objects.requireNonNull(serverMatcher, "serverMatcher"); + + serverMatcherList.add(serverMatcher); + } + + public void addMatcherGroup(MatcherGroup MatcherGroup) { + serverMatcherList.addAll(MatcherGroup.getServerMatcherList()); + defaultMatcher = MatcherGroup.getDefaultMatcher(); + } + + public List getServerMatcherList() { + return serverMatcherList; + } + + public HyperLink makeLinkInfo(LinkSource linkSource) { + ServerMatcher serverMatcher = defaultMatcher; + String value = getMatchingSource(linkSource); + + Objects.requireNonNull(value, "value"); + + + for (ServerMatcher matcher : serverMatcherList) { + if (matcher.isMatched(value)) { + serverMatcher = matcher; + } + } + + return serverMatcher.getLinkInfo(value); + } + + abstract protected String getMatchingSource(LinkSource linkSource); + + abstract public boolean isMatchingType(LinkSource linkSource); } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcher.java similarity index 83% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcher.java index 22121f9e0573..8303a28074c0 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcher.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcher.java @@ -1,62 +1,62 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -import com.navercorp.pinpoint.web.applicationmap.link.LinkInfo.LinkType; - -/** - * @author minwoo.jung - */ -public class PostfixServerMatcher implements ServerMatcher { - - private final String postfix; - private final String url; - private final String linkName; - private final LinkType linkType; - - public PostfixServerMatcher(String postfix, String url, String linkName, LinkType linkType) { - this.postfix = postfix; - this.url = url; - this.linkName = linkName; - this.linkType = linkType; - } - - @Override - public boolean isMatched(String value) { - if (value == null) { - return false; - } - return value.endsWith(postfix); - } - - private String getLink(String value) { - final int index = value.lastIndexOf(postfix); - - if (index == -1) { - throw new IllegalArgumentException("invalid serverName:" + value); - } - - String hostName = value.substring(0, index); - return url + hostName; - } - - - @Override - public LinkInfo getLinkInfo(String value) { - return new LinkInfo(linkName, getLink(value), linkType); - } +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +import com.navercorp.pinpoint.web.hyperlink.HyperLink.LinkType; + +/** + * @author minwoo.jung + */ +public class PostfixServerMatcher implements ServerMatcher { + + private final String postfix; + private final String url; + private final String linkName; + private final LinkType linkType; + + public PostfixServerMatcher(String postfix, String url, String linkName, LinkType linkType) { + this.postfix = postfix; + this.url = url; + this.linkName = linkName; + this.linkType = linkType; + } + + @Override + public boolean isMatched(String value) { + if (value == null) { + return false; + } + return value.endsWith(postfix); + } + + private String getLink(String value) { + final int index = value.lastIndexOf(postfix); + + if (index == -1) { + throw new IllegalArgumentException("invalid serverName:" + value); + } + + String hostName = value.substring(0, index); + return url + hostName; + } + + + @Override + public HyperLink getLinkInfo(String value) { + return new HyperLink(linkName, getLink(value), linkType); + } } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/ServerMatcher.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/ServerMatcher.java similarity index 85% rename from web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/ServerMatcher.java rename to web/src/main/java/com/navercorp/pinpoint/web/hyperlink/ServerMatcher.java index d1fc80403da1..89dbea489cfa 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/link/ServerMatcher.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/ServerMatcher.java @@ -1,26 +1,26 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -/** - * @author emeroad - */ -public interface ServerMatcher { - boolean isMatched(String value); - - LinkInfo getLinkInfo(String value); +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +/** + * @author emeroad + */ +public interface ServerMatcher { + boolean isMatched(String value); + + HyperLink getLinkInfo(String value); } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoResultsExtractor.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoResultsExtractor.java index c2ec73f59616..8b5ba6e17a4b 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoResultsExtractor.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoResultsExtractor.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentInfoFactory; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.springframework.stereotype.Component; @@ -32,13 +33,14 @@ */ @Component public class AgentInfoResultsExtractor implements ResultsExtractor { - private final AgentInfo.Binder binder; + private final AgentInfoFactory factory; private final RowMapper agentInfoMapper; - public AgentInfoResultsExtractor(ServiceTypeRegistryService registryService, RowMapper agentInfoMapper) { + public AgentInfoResultsExtractor(ServiceTypeRegistryService registryService, + RowMapper agentInfoMapper) { Objects.requireNonNull(registryService, "registryService"); - binder = new AgentInfo.Binder(registryService); + this.factory = new AgentInfoFactory(registryService); this.agentInfoMapper = Objects.requireNonNull(agentInfoMapper, "agentInfoMapper"); } @@ -47,7 +49,7 @@ public AgentInfo extractData(ResultScanner results) throws Exception { int found = 0; for (Result result : results) { AgentInfoBo agentInfoBo = agentInfoMapper.mapRow(result, found++); - return binder.bind(agentInfoBo); + return factory.build(agentInfoBo); } return null; } 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 94c7e83413f0..a7f17d89b33d 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 @@ -26,6 +26,7 @@ import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; import com.navercorp.pinpoint.web.dao.stat.AgentStatDao; import com.navercorp.pinpoint.web.filter.agent.AgentEventFilter; +import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.service.stat.AgentWarningStatService; import com.navercorp.pinpoint.web.vo.AgentEvent; import com.navercorp.pinpoint.web.vo.AgentInfo; @@ -78,18 +79,22 @@ public class AgentInfoServiceImpl implements AgentInfoService { private final AgentLifeCycleDao agentLifeCycleDao; private final AgentStatDao jvmGcDao; - + private final HyperLinkFactory hyperLinkFactory; public AgentInfoServiceImpl(AgentEventService agentEventService, AgentWarningStatService agentWarningStatService, ApplicationIndexDao applicationIndexDao, - AgentInfoDao agentInfoDao, AgentLifeCycleDao agentLifeCycleDao, - AgentStatDao jvmGcDao) { + AgentInfoDao agentInfoDao, + AgentLifeCycleDao agentLifeCycleDao, + AgentStatDao jvmGcDao, + HyperLinkFactory hyperLinkFactory) { this.agentEventService = Objects.requireNonNull(agentEventService, "agentEventService"); this.agentWarningStatService = Objects.requireNonNull(agentWarningStatService, "agentWarningStatService"); this.applicationIndexDao = Objects.requireNonNull(applicationIndexDao, "applicationIndexDao"); this.agentInfoDao = Objects.requireNonNull(agentInfoDao, "agentInfoDao"); this.agentLifeCycleDao = Objects.requireNonNull(agentLifeCycleDao, "agentLifeCycleDao"); this.jvmGcDao = Objects.requireNonNull(jvmGcDao, "jvmGcDao"); + this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); + } @Override @@ -97,7 +102,7 @@ public ApplicationAgentsList getAllApplicationAgentsList(AgentInfoFilter filter, Objects.requireNonNull(filter, "filter"); ApplicationAgentsList.GroupBy groupBy = ApplicationAgentsList.GroupBy.APPLICATION_NAME; - ApplicationAgentsList applicationAgentList = new ApplicationAgentsList(groupBy, filter); + ApplicationAgentsList applicationAgentList = new ApplicationAgentsList(groupBy, filter, hyperLinkFactory); List applications = applicationIndexDao.selectAllApplicationNames(); for (Application application : applications) { applicationAgentList.merge(getApplicationAgentsList(groupBy, filter, application.getName(), timestamp)); @@ -111,7 +116,7 @@ public ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.Grou Objects.requireNonNull(filter, "filter"); Objects.requireNonNull(applicationName, "applicationName"); - ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(groupBy, filter); + ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(groupBy, filter, hyperLinkFactory); Set agentInfos = getAgentsByApplicationName(applicationName, timestamp); if (agentInfos.isEmpty()) { logger.warn("agent list is empty for application:{}", applicationName); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImpl.java index 96deb1ee9894..fb472f01f1b6 100755 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImpl.java @@ -29,7 +29,6 @@ import com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.WasNodeHistogramDataSource; import com.navercorp.pinpoint.web.applicationmap.appender.server.DefaultServerInstanceListFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.StatisticsServerInstanceListFactory; -import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.ServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.link.LinkType; import com.navercorp.pinpoint.web.dao.ApplicationTraceIndexDao; @@ -67,8 +66,6 @@ public class FilteredMapServiceImpl implements FilteredMapService { private final Logger logger = LogManager.getLogger(this.getClass()); - private final AgentInfoService agentInfoService; - private final TraceDao traceDao; private final ApplicationTraceIndexDao applicationTraceIndexDao; @@ -77,6 +74,8 @@ public class FilteredMapServiceImpl implements FilteredMapService { private final ApplicationFactory applicationFactory; + private final ServerInstanceDatasourceService serverInstanceDatasourceService; + private final ServerMapDataFilter serverMapDataFilter; private final ApplicationMapBuilderFactory applicationMapBuilderFactory; @@ -86,16 +85,18 @@ public class FilteredMapServiceImpl implements FilteredMapService { @Value("${web.servermap.build.timeout:600000}") private long buildTimeoutMillis; - public FilteredMapServiceImpl(AgentInfoService agentInfoService, - TraceDao traceDao, + public FilteredMapServiceImpl(TraceDao traceDao, ApplicationTraceIndexDao applicationTraceIndexDao, - ServiceTypeRegistryService registry, ApplicationFactory applicationFactory, - Optional serverMapDataFilter, ApplicationMapBuilderFactory applicationMapBuilderFactory) { - this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); + ServiceTypeRegistryService registry, + ApplicationFactory applicationFactory, + ServerInstanceDatasourceService serverInstanceDatasourceService, + Optional serverMapDataFilter, + ApplicationMapBuilderFactory applicationMapBuilderFactory) { this.traceDao = Objects.requireNonNull(traceDao, "traceDao"); this.applicationTraceIndexDao = Objects.requireNonNull(applicationTraceIndexDao, "applicationTraceIndexDao"); this.registry = Objects.requireNonNull(registry, "registry"); this.applicationFactory = Objects.requireNonNull(applicationFactory, "applicationFactory"); + this.serverInstanceDatasourceService = Objects.requireNonNull(serverInstanceDatasourceService, "serverInstanceDatasourceService"); this.serverMapDataFilter = Objects.requireNonNull(serverMapDataFilter, "serverMapDataFilter").orElse(null); this.applicationMapBuilderFactory = Objects.requireNonNull(applicationMapBuilderFactory, "applicationMapBuilderFactory"); } @@ -175,8 +176,8 @@ private ApplicationMap createMap(FilteredMapServiceOption option, FilteredMap fi applicationMapBuilder.linkType(LinkType.DETAILED); final WasNodeHistogramDataSource wasNodeHistogramDataSource = new ResponseHistogramsNodeHistogramDataSource(filteredMap.getResponseHistograms()); applicationMapBuilder.includeNodeHistogram(new DefaultNodeHistogramFactory(wasNodeHistogramDataSource)); - ServerInstanceListDataSource serverInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService); - if(option.isUseStatisticsAgentState()) { + ServerInstanceListDataSource serverInstanceListDataSource = serverInstanceDatasourceService.getServerInstanceListDataSource();; + if (option.isUseStatisticsAgentState()) { applicationMapBuilder.includeServerInfo(new StatisticsServerInstanceListFactory(serverInstanceListDataSource)); } else { applicationMapBuilder.includeServerInfo(new DefaultServerInstanceListFactory(serverInstanceListDataSource)); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/MapServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/MapServiceImpl.java index 960c5ce76e82..357649b39110 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/MapServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/MapServiceImpl.java @@ -25,7 +25,6 @@ import com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.WasNodeHistogramDataSource; import com.navercorp.pinpoint.web.applicationmap.appender.server.DefaultServerInstanceListFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.StatisticsServerInstanceListFactory; -import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.ServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap; import com.navercorp.pinpoint.web.dao.MapResponseDao; @@ -58,8 +57,6 @@ public class MapServiceImpl implements MapService { private final LinkSelectorFactory linkSelectorFactory; - private final AgentInfoService agentInfoService; - private final MapResponseDao mapResponseDao; private final ServerMapDataFilter serverMapDataFilter; @@ -68,18 +65,23 @@ public class MapServiceImpl implements MapService { private final LinkDataLimiter linkDataLimiter; + private final ServerInstanceDatasourceService serverInstanceDatasourceService; + @Value("${web.servermap.build.timeout:600000}") private long buildTimeoutMillis; - public MapServiceImpl(LinkSelectorFactory linkSelectorFactory, AgentInfoService agentInfoService, + public MapServiceImpl(LinkSelectorFactory linkSelectorFactory, MapResponseDao mapResponseDao, - Optional serverMapDataFilter, ApplicationMapBuilderFactory applicationMapBuilderFactory, LinkDataLimiter linkDataLimiter) { + Optional serverMapDataFilter, + ApplicationMapBuilderFactory applicationMapBuilderFactory, + LinkDataLimiter linkDataLimiter, + ServerInstanceDatasourceService serverInstanceDatasourceService) { this.linkSelectorFactory = Objects.requireNonNull(linkSelectorFactory, "linkSelectorFactory"); - this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); this.mapResponseDao = Objects.requireNonNull(mapResponseDao, "mapResponseDao"); this.serverMapDataFilter = Objects.requireNonNull(serverMapDataFilter, "serverMapDataFilter").orElse(null); this.applicationMapBuilderFactory = Objects.requireNonNull(applicationMapBuilderFactory, "applicationMapBuilderFactory"); this.linkDataLimiter = linkDataLimiter; + this.serverInstanceDatasourceService = Objects.requireNonNull(serverInstanceDatasourceService, "serverInstanceDatasourceService"); } /** @@ -136,7 +138,7 @@ private ApplicationMapBuilder createApplicationMapBuilder(MapServiceOption optio NodeHistogramFactory nodeHistogramFactory = new DefaultNodeHistogramFactory(wasNodeHistogramDataSource); builder.includeNodeHistogram(nodeHistogramFactory); - ServerInstanceListDataSource serverInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService); + ServerInstanceListDataSource serverInstanceListDataSource = serverInstanceDatasourceService.getServerInstanceListDataSource(); if (option.isUseStatisticsAgentState()) { builder.includeServerInfo(new StatisticsServerInstanceListFactory(serverInstanceListDataSource)); } else { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ResponseTimeHistogramServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ResponseTimeHistogramServiceImpl.java index 405f902f2fca..9898b2723125 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/ResponseTimeHistogramServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ResponseTimeHistogramServiceImpl.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.common.trace.ServiceType; import com.navercorp.pinpoint.web.applicationmap.appender.histogram.DefaultNodeHistogramFactory; import com.navercorp.pinpoint.web.applicationmap.appender.histogram.NodeHistogramFactory; @@ -24,7 +25,6 @@ import com.navercorp.pinpoint.web.applicationmap.appender.server.DefaultServerInstanceListFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.ServerInstanceListFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.StatisticsServerInstanceListFactory; -import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.ServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram; import com.navercorp.pinpoint.web.applicationmap.link.CreateType; @@ -34,6 +34,7 @@ import com.navercorp.pinpoint.web.applicationmap.link.LinkListFactory; import com.navercorp.pinpoint.web.applicationmap.link.LinkType; import com.navercorp.pinpoint.web.applicationmap.nodes.Node; +import com.navercorp.pinpoint.web.applicationmap.nodes.NodeHistogramSummary; import com.navercorp.pinpoint.web.applicationmap.nodes.NodeList; import com.navercorp.pinpoint.web.applicationmap.nodes.NodeListFactory; import com.navercorp.pinpoint.web.applicationmap.nodes.NodeType; @@ -43,21 +44,19 @@ import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap; import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap; import com.navercorp.pinpoint.web.dao.MapResponseDao; -import com.navercorp.pinpoint.web.service.map.processor.ApplicationFilter; -import com.navercorp.pinpoint.web.service.map.processor.DestinationApplicationFilter; -import com.navercorp.pinpoint.web.service.map.processor.LinkDataMapProcessor; import com.navercorp.pinpoint.web.service.map.LinkSelector; import com.navercorp.pinpoint.web.service.map.LinkSelectorFactory; import com.navercorp.pinpoint.web.service.map.LinkSelectorType; +import com.navercorp.pinpoint.web.service.map.processor.ApplicationFilter; +import com.navercorp.pinpoint.web.service.map.processor.DestinationApplicationFilter; +import com.navercorp.pinpoint.web.service.map.processor.LinkDataMapProcessor; import com.navercorp.pinpoint.web.service.map.processor.SourceApplicationFilter; import com.navercorp.pinpoint.web.view.ApplicationTimeHistogramViewModel; -import com.navercorp.pinpoint.web.applicationmap.nodes.NodeHistogramSummary; import com.navercorp.pinpoint.web.vo.Application; import com.navercorp.pinpoint.web.vo.LinkKey; -import com.navercorp.pinpoint.common.server.util.time.Range; import com.navercorp.pinpoint.web.vo.ResponseTime; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.stereotype.Service; import java.util.Collections; @@ -75,19 +74,21 @@ public class ResponseTimeHistogramServiceImpl implements ResponseTimeHistogramSe private final LinkSelectorFactory linkSelectorFactory; - private final AgentInfoService agentInfoService; + private final ServerInstanceDatasourceService serverInstanceDatasourceService; private final MapResponseDao mapResponseDao; - public ResponseTimeHistogramServiceImpl(LinkSelectorFactory linkSelectorFactory, AgentInfoService agentInfoService, MapResponseDao mapResponseDao) { + public ResponseTimeHistogramServiceImpl(LinkSelectorFactory linkSelectorFactory, + ServerInstanceDatasourceService serverInstanceDatasourceService, + MapResponseDao mapResponseDao) { this.linkSelectorFactory = Objects.requireNonNull(linkSelectorFactory, "linkSelectorFactory"); - this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); + this.serverInstanceDatasourceService = Objects.requireNonNull(serverInstanceDatasourceService, "serverInstanceDatasourceService"); this.mapResponseDao = Objects.requireNonNull(mapResponseDao, "mapResponseDao"); } private ServerInstanceListFactory createServerInstanceListFactory(ResponseTimeHistogramServiceOption option) { - ServerInstanceListDataSource serverInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService); + ServerInstanceListDataSource serverInstanceListDataSource = serverInstanceDatasourceService.getServerInstanceListDataSource(); if (option.isUseStatisticsAgentState()) { return new StatisticsServerInstanceListFactory(serverInstanceListDataSource); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/ServerInstanceDatasourceService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/ServerInstanceDatasourceService.java new file mode 100644 index 000000000000..f1630ba6ca0e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/ServerInstanceDatasourceService.java @@ -0,0 +1,23 @@ +package com.navercorp.pinpoint.web.service; + +import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; +import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.ServerInstanceListDataSource; +import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +public class ServerInstanceDatasourceService { + private final AgentInfoService agentInfoService; + private final HyperLinkFactory hyperLinkFactory; + + public ServerInstanceDatasourceService(AgentInfoService agentInfoService, HyperLinkFactory hyperLinkFactory) { + this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); + this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); + } + + public ServerInstanceListDataSource getServerInstanceListDataSource() { + return new AgentInfoServerInstanceListDataSource(agentInfoService, hyperLinkFactory); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java index d3fe81889cb9..02bd92985ad1 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java @@ -19,23 +19,18 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.web.applicationmap.link.LinkInfo; -import com.navercorp.pinpoint.web.applicationmap.link.MatcherGroup; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; -import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; -import java.util.List; /** * @author HyunGil Jeong */ public class AgentInfoSerializer extends JsonSerializer { - @Autowired(required = false) - private List matcherGroupList; - + public AgentInfoSerializer() { + } @Override public void serialize(AgentInfo agentInfo, JsonGenerator jgen, SerializerProvider provider) throws IOException { @@ -63,20 +58,6 @@ public void serialize(AgentInfo agentInfo, JsonGenerator jgen, SerializerProvide jgen.writeNumberField("initialStartTimestamp", agentInfo.getInitialStartTimestamp()); - if (matcherGroupList != null) { - jgen.writeFieldName("linkList"); - jgen.writeStartArray(); - - for (MatcherGroup matcherGroup : matcherGroupList) { - if (matcherGroup.ismatchingType(agentInfo)) { - LinkInfo linkInfo = matcherGroup.makeLinkInfo(agentInfo); - jgen.writeObject(linkInfo); - } - } - - jgen.writeEndArray(); - } - jgen.writeEndObject(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationAgentsListSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationAgentsListSerializer.java index ff347053bf61..1b515f934d8d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationAgentsListSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/ApplicationAgentsListSerializer.java @@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.ApplicationAgentList; import com.navercorp.pinpoint.web.vo.ApplicationAgentsList; @@ -39,16 +38,9 @@ public void serialize(ApplicationAgentsList applicationAgentsList, JsonGenerator List applicationAgentLists = applicationAgentsList.getApplicationAgentLists(); for (ApplicationAgentList applicationAgentList : applicationAgentLists) { jgen.writeFieldName(applicationAgentList.getGroupName()); - writeAgentList(jgen, applicationAgentList.getAgentInfos()); + jgen.writeObject(applicationAgentList.getAgentInfoAndLinks()); } jgen.writeEndObject(); } - private void writeAgentList(JsonGenerator jgen, List agentList) throws IOException { - jgen.writeStartArray(); - for (AgentInfo agentInfo : agentList) { - jgen.writeObject(agentInfo); - } - jgen.writeEndArray(); - } } \ No newline at end of file diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializer.java index c2ae913986af..9b3e4e12cc56 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializer.java @@ -16,14 +16,13 @@ package com.navercorp.pinpoint.web.view; +import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstance; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.web.applicationmap.link.LinkInfo; -import com.navercorp.pinpoint.web.applicationmap.link.MatcherGroup; -import org.springframework.beans.factory.annotation.Autowired; +import com.navercorp.pinpoint.web.hyperlink.HyperLink; import org.springframework.stereotype.Component; import java.io.IOException; @@ -37,9 +36,6 @@ @Component public class ServerInstanceListSerializer extends JsonSerializer { - @Autowired(required=false) - private List matcherGroupList; - @Override public void serialize(ServerInstanceList serverInstanceList, JsonGenerator jgen, SerializerProvider provider) throws IOException { @@ -53,22 +49,16 @@ public void serialize(ServerInstanceList serverInstanceList, JsonGenerator jgen, jgen.writeStringField("name", entry.getKey()); jgen.writeStringField("status", null); - if (matcherGroupList != null) { - jgen.writeFieldName("linkList"); - jgen.writeStartArray(); - - for (MatcherGroup matcherGroup : matcherGroupList) { - if (matcherGroup.ismatchingType(entry.getValue().get(0))) { - LinkInfo linkInfo = matcherGroup.makeLinkInfo(entry.getValue().get(0)); - jgen.writeObject(linkInfo); - } - } - - jgen.writeEndArray(); + List serverInstances = entry.getValue(); + + ServerInstance serverInstance = org.springframework.util.CollectionUtils.firstElement(serverInstances); + List linkList = serverInstance.getLinkList(); + if (CollectionUtils.hasLength(linkList)) { + jgen.writeObjectField("linkList", linkList); } jgen.writeFieldName("instanceList"); - writeInstanceList(jgen, entry.getValue()); + writeInstanceList(jgen, serverInstances); jgen.writeEndObject(); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/ServiceTypeDescView.java b/web/src/main/java/com/navercorp/pinpoint/web/view/ServiceTypeDescView.java new file mode 100644 index 000000000000..6349b489536f --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/ServiceTypeDescView.java @@ -0,0 +1,16 @@ +package com.navercorp.pinpoint.web.view; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.navercorp.pinpoint.common.trace.ServiceType; + +import java.io.IOException; + +public class ServiceTypeDescView extends JsonSerializer { + + @Override + public void serialize(ServiceType serviceType, JsonGenerator jgen, SerializerProvider provider) throws IOException { + jgen.writeObject(serviceType.getDesc()); + } +} 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 1d3236f14710..00e8d884fd02 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 @@ -20,18 +20,15 @@ import java.util.Objects; import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; import com.navercorp.pinpoint.common.server.bo.JvmInfoBo; import com.navercorp.pinpoint.common.server.bo.ServerMetaDataBo; import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; -import com.navercorp.pinpoint.web.view.AgentInfoSerializer; +import com.navercorp.pinpoint.web.view.ServiceTypeDescView; import org.apache.commons.lang3.StringUtils; /** * @author HyunGil Jeong */ -@JsonSerialize(using = AgentInfoSerializer.class) public class AgentInfo { public static final Comparator AGENT_NAME_ASC_COMPARATOR @@ -109,11 +106,15 @@ public String getPorts() { return ports; } + public void setPorts(String ports) { + this.ports = ports; + } public short getServiceTypeCode() { return serviceType.getCode(); } + @JsonSerialize(using = ServiceTypeDescView.class) public ServiceType getServiceType() { return serviceType; } @@ -126,25 +127,41 @@ public int getPid() { return pid; } + public void setPid(int pid) { + this.pid = pid; + } public String getVmVersion() { return vmVersion; } + public void setVmVersion(String vmVersion) { + this.vmVersion = vmVersion; + } + public String getAgentVersion() { return agentVersion; } + public void setAgentVersion(String agentVersion) { + this.agentVersion = agentVersion; + } public ServerMetaDataBo getServerMetaData() { return serverMetaData; } + public void setServerMetaData(ServerMetaDataBo serverMetaData) { + this.serverMetaData = serverMetaData; + } public JvmInfoBo getJvmInfo() { return jvmInfo; } + public void setJvmInfo(JvmInfoBo jvmInfo) { + this.jvmInfo = jvmInfo; + } public long getInitialStartTimestamp() { return initialStartTimestamp; @@ -167,32 +184,7 @@ public void setStatus(AgentStatus status) { this.status = Objects.requireNonNull(status, "status"); } - public static class Binder { - private final ServiceTypeRegistryService registryService; - - public Binder(ServiceTypeRegistryService registryService) { - this.registryService = Objects.requireNonNull(registryService, "registryService"); - } - - public AgentInfo bind(AgentInfoBo agentInfoBo) { - AgentInfo agentInfo = new AgentInfo(); - agentInfo.applicationName = agentInfoBo.getApplicationName(); - agentInfo.agentId = agentInfoBo.getAgentId(); - agentInfo.agentName = agentInfoBo.getAgentName(); - agentInfo.startTimestamp = agentInfoBo.getStartTime(); - agentInfo.hostName = agentInfoBo.getHostName(); - agentInfo.ip = agentInfoBo.getIp(); - agentInfo.ports = agentInfoBo.getPorts(); - agentInfo.serviceType = registryService.findServiceType(agentInfoBo.getServiceTypeCode()); - agentInfo.pid = agentInfoBo.getPid(); - agentInfo.vmVersion = agentInfoBo.getVmVersion(); - agentInfo.agentVersion = agentInfoBo.getAgentVersion(); - agentInfo.serverMetaData = agentInfoBo.getServerMetaData(); - agentInfo.jvmInfo = agentInfoBo.getJvmInfo(); - agentInfo.container = agentInfoBo.isContainer(); - return agentInfo; - } - } + @Override public boolean equals(Object o) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java new file mode 100644 index 000000000000..bdbfe342182d --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndLink.java @@ -0,0 +1,36 @@ +package com.navercorp.pinpoint.web.vo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.navercorp.pinpoint.web.hyperlink.HyperLink; + +import java.util.List; +import java.util.Objects; + +public class AgentInfoAndLink { + private final AgentInfo agentInfo; + private final List hyperLinkList; + + public AgentInfoAndLink(AgentInfo agentInfo, List hyperLinkList) { + this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); + this.hyperLinkList = Objects.requireNonNull(hyperLinkList, "hyperLinkList"); + } + + @JsonUnwrapped + public AgentInfo getAgentInfo() { + return agentInfo; + } + + @JsonProperty("linkList") + public List getHyperLinkList() { + return hyperLinkList; + } + + @Override + public String toString() { + return "AgentInfoAndLink{" + + "agentInfo=" + agentInfo + + ", hyperLinkList=" + hyperLinkList + + '}'; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFactory.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFactory.java new file mode 100644 index 000000000000..3139cd53c286 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoFactory.java @@ -0,0 +1,37 @@ +package com.navercorp.pinpoint.web.vo; + +import com.navercorp.pinpoint.common.server.bo.AgentInfoBo; +import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService; +import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; +import com.navercorp.pinpoint.web.hyperlink.LinkSources; + +import java.util.Objects; + +public class AgentInfoFactory { + private final ServiceTypeRegistryService registryService; + + public AgentInfoFactory(ServiceTypeRegistryService registryService) { + this.registryService = Objects.requireNonNull(registryService, "registryService"); + } + + public AgentInfo build(AgentInfoBo agentInfoBo) { + Objects.requireNonNull(agentInfoBo, "agentInfoBo"); + + AgentInfo agentInfo = new AgentInfo(); + agentInfo.setApplicationName(agentInfoBo.getApplicationName()); + agentInfo.setAgentId(agentInfoBo.getAgentId()); + agentInfo.setAgentName(agentInfoBo.getAgentName()); + agentInfo.setStartTimestamp(agentInfoBo.getStartTime()); + agentInfo.setHostName(agentInfoBo.getHostName()); + agentInfo.setIp(agentInfoBo.getIp()); + agentInfo.setPorts(agentInfoBo.getPorts()); + agentInfo.setServiceType(registryService.findServiceType(agentInfoBo.getServiceTypeCode())); + agentInfo.setPid(agentInfoBo.getPid()); + agentInfo.setVmVersion(agentInfoBo.getVmVersion()); + agentInfo.setAgentVersion(agentInfoBo.getAgentVersion()); + agentInfo.setServerMetaData(agentInfoBo.getServerMetaData()); + agentInfo.setJvmInfo(agentInfoBo.getJvmInfo()); + agentInfo.setContainer(agentInfoBo.isContainer()); + return agentInfo; + } +} 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 dc3a4eeab61a..69d7667bcccf 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 @@ -18,6 +18,7 @@ import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @author HyunGil Jeong @@ -25,11 +26,11 @@ public class ApplicationAgentList { private final String groupName; - private final List agentInfos; + private final List agentInfoAndLinkList; - public ApplicationAgentList(String groupName, List agentInfos) { + public ApplicationAgentList(String groupName, List agentInfoAndLinkList) { this.groupName = Objects.requireNonNull(groupName, "groupName"); - this.agentInfos = Objects.requireNonNull(agentInfos, "agentInfos"); + this.agentInfoAndLinkList = Objects.requireNonNull(agentInfoAndLinkList, "agentInfoAndLinkList"); } public String getGroupName() { @@ -37,14 +38,20 @@ public String getGroupName() { } public List getAgentInfos() { - return agentInfos; + return agentInfoAndLinkList.stream() + .map(AgentInfoAndLink::getAgentInfo) + .collect(Collectors.toList()); + } + + public List getAgentInfoAndLinks() { + return agentInfoAndLinkList; } @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); sb.append('\'').append(groupName).append('\''); - sb.append(":").append(agentInfos); + sb.append(":").append(agentInfoAndLinkList); sb.append('}'); return sb.toString(); } 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 2aace14e903d..9eea59b26821 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 @@ -18,6 +18,9 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.navercorp.pinpoint.common.annotations.VisibleForTesting; +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.view.ApplicationAgentsListSerializer; import java.util.ArrayList; @@ -27,6 +30,7 @@ import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.stream.Collectors; /** * @author minwoo.jung @@ -90,11 +94,14 @@ private interface GroupingKey> extends Comparable { private final GroupBy groupBy; private final AgentInfoFilter filter; + private final HyperLinkFactory hyperLinkFactory; + private final Map> agentsMap = new TreeMap<>(); - public ApplicationAgentsList(GroupBy groupBy, AgentInfoFilter filter) { + public ApplicationAgentsList(GroupBy groupBy, AgentInfoFilter filter, HyperLinkFactory hyperLinkFactory) { this.groupBy = Objects.requireNonNull(groupBy, "groupBy"); this.filter = Objects.requireNonNull(filter, "filter"); + this.hyperLinkFactory = Objects.requireNonNull(hyperLinkFactory, "hyperLinkFactory"); } public void add(AgentInfo agentInfo) { @@ -123,15 +130,27 @@ public List getApplicationAgentLists() { return Collections.emptyList(); } List applicationAgentLists = new ArrayList<>(agentsMap.size()); - for (Map.Entry> e : agentsMap.entrySet()) { - GroupingKey groupingKey = e.getKey(); - List applicationAgents = new ArrayList<>(e.getValue()); + for (Map.Entry> entry : agentsMap.entrySet()) { + final GroupingKey groupingKey = entry.getKey(); + final List agentInfoList = entry.getValue(); + + List applicationAgents = new ArrayList<>(agentInfoList); applicationAgents.sort(groupBy.getComparator()); - applicationAgentLists.add(new ApplicationAgentList(groupingKey.value(), applicationAgents)); + + List agentInfoAndLinks = applicationAgents.stream() + .map(this::newAgentInfoAndLink) + .collect(Collectors.toList()); + + applicationAgentLists.add(new ApplicationAgentList(groupingKey.value(), agentInfoAndLinks)); } return applicationAgentLists; } + private AgentInfoAndLink newAgentInfoAndLink(AgentInfo agentInfo) { + List hyperLinks = hyperLinkFactory.build(LinkSources.from(agentInfo)); + return new AgentInfoAndLink(agentInfo, hyperLinks); + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("ApplicationAgentsList{"); diff --git a/web/src/main/resources/applicationContext-web.xml b/web/src/main/resources/applicationContext-web.xml index 62b606c67d3b..a955d1ab9af1 100644 --- a/web/src/main/resources/applicationContext-web.xml +++ b/web/src/main/resources/applicationContext-web.xml @@ -30,6 +30,7 @@ + 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 ad9c83fd4027..fd6705c21deb 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 @@ -28,6 +28,7 @@ import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap; import com.navercorp.pinpoint.web.dao.MapResponseDao; +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.AgentStatus; @@ -86,9 +87,10 @@ public void setUp() { responseHistogramBuilderNodeHistogramDataSource = new ResponseHistogramsNodeHistogramDataSource(responseHistograms); AgentInfoService agentInfoService = mock(AgentInfoService.class); - agentInfoServerInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService); + HyperLinkFactory hyperLinkFactory = mock(HyperLinkFactory.class); + agentInfoServerInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService, hyperLinkFactory); - Answer> responseTimeAnswer = new Answer>() { + Answer> responseTimeAnswer = new Answer<>() { final long timestamp = System.currentTimeMillis(); @Override public List answer(InvocationOnMock invocation) { 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 96b7f8283b68..37a3805d3a66 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 @@ -22,6 +22,7 @@ import com.navercorp.pinpoint.web.applicationmap.nodes.ServerBuilder; import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.vo.AgentInfoFactory; import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; @@ -70,9 +71,9 @@ public static AgentInfo createAgentInfo(String agentId, String hostName) { ServiceTypeRegistryService registry = mock(ServiceTypeRegistryService.class); when(registry.findServiceType(serviceType.getCode())).thenReturn(serviceType); - AgentInfo.Binder binder = new AgentInfo.Binder(registry); + AgentInfoFactory factory = new AgentInfoFactory(registry); - return binder.bind(agentInfoBuilder.build()); + return factory.build(agentInfoBuilder.build()); } } \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java b/web/src/test/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcherTest.java similarity index 89% rename from web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java rename to web/src/test/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcherTest.java index d172a7e35b90..83575e4ad6ec 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/link/PostfixServerMatcherTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/hyperlink/PostfixServerMatcherTest.java @@ -1,44 +1,44 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.applicationmap.link; - -import com.navercorp.pinpoint.web.applicationmap.link.LinkInfo.LinkType; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * @author minwoo.jung - */ -public class PostfixServerMatcherTest { - - @Test - public void test() { - String url = "http://naver.com/"; - String postfix = ".seoul.idc"; - PostfixServerMatcher matcher = new PostfixServerMatcher(postfix, url, "NAVER", LinkType.ATAG); - - String serverName = "naverServer01"; - assertTrue(matcher.isMatched(serverName + postfix)); - assertFalse(matcher.isMatched("naverserver" + "busan.idc")); - - assertEquals(url + serverName, matcher.getLinkInfo(serverName + postfix).getLinkUrl()); - } - +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.hyperlink; + +import com.navercorp.pinpoint.web.hyperlink.HyperLink.LinkType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author minwoo.jung + */ +public class PostfixServerMatcherTest { + + @Test + public void test() { + String url = "http://naver.com/"; + String postfix = ".seoul.idc"; + PostfixServerMatcher matcher = new PostfixServerMatcher(postfix, url, "NAVER", LinkType.ATAG); + + String serverName = "naverServer01"; + assertTrue(matcher.isMatched(serverName + postfix)); + assertFalse(matcher.isMatched("naverserver" + "busan.idc")); + + assertEquals(url + serverName, matcher.getLinkInfo(serverName + postfix).getLinkUrl()); + } + } \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImplTest.java b/web/src/test/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImplTest.java index bcddc846a24d..bbccc6029ae1 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImplTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/service/FilteredMapServiceImplTest.java @@ -29,6 +29,7 @@ import com.navercorp.pinpoint.web.applicationmap.appender.histogram.NodeHistogramAppenderFactory; import com.navercorp.pinpoint.web.applicationmap.appender.metric.DefaultMetricInfoAppenderFactory; import com.navercorp.pinpoint.web.applicationmap.appender.server.ServerInfoAppenderFactory; +import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource; import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram; import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram; import com.navercorp.pinpoint.web.applicationmap.histogram.TimeHistogramFormat; @@ -37,6 +38,7 @@ import com.navercorp.pinpoint.web.dao.ApplicationTraceIndexDao; import com.navercorp.pinpoint.web.dao.TraceDao; import com.navercorp.pinpoint.web.filter.Filter; +import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import com.navercorp.pinpoint.web.util.TimeWindow; import com.navercorp.pinpoint.web.util.TimeWindowDownSampler; import com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel; @@ -73,6 +75,7 @@ import static org.mockito.ArgumentMatchers.anyShort; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** @@ -86,8 +89,6 @@ public class FilteredMapServiceImplTest { private final ExecutorService executor = Executors.newFixedThreadPool(8); - @Mock - private AgentInfoService agentInfoService; @Mock private TraceDao traceDao; @@ -98,6 +99,9 @@ public class FilteredMapServiceImplTest { @Mock private ApplicationFactory applicationFactory; + @Mock + private ServerInstanceDatasourceService serverInstanceDatasourceService; + // Mocked private final ServiceTypeRegistryService registry = TestTraceUtils.mockServiceTypeRegistryService(); @@ -112,22 +116,35 @@ public class FilteredMapServiceImplTest { @BeforeEach public void init() { - when(applicationFactory.createApplication(anyString(), anyShort())).thenAnswer(invocation -> { - String applicationName = invocation.getArgument(0); - ServiceType serviceType = registry.findServiceType(invocation.getArgument(1)); - return new Application(applicationName, serviceType); - }); - when(applicationFactory.createApplication(anyString(), any(ServiceType.class))).thenAnswer(invocation -> { - String applicationName = invocation.getArgument(0); - ServiceType serviceType = invocation.getArgument(1); - return new Application(applicationName, serviceType); - }); - when(applicationFactory.createApplicationByTypeName(anyString(), anyString())).thenAnswer(invocation -> { - String applicationName = invocation.getArgument(0); - ServiceType serviceType = registry.findServiceTypeByName(invocation.getArgument(1)); - return new Application(applicationName, serviceType); - }); - filteredMapService = new FilteredMapServiceImpl(agentInfoService, traceDao, applicationTraceIndexDao, registry, applicationFactory, Optional.empty(), applicationMapBuilderFactory); + when(applicationFactory.createApplication(anyString(), anyShort())) + .thenAnswer(invocation -> { + String applicationName = invocation.getArgument(0); + ServiceType serviceType = registry.findServiceType(invocation.getArgument(1)); + return new Application(applicationName, serviceType); + }); + when(applicationFactory.createApplication(anyString(), any(ServiceType.class))) + .thenAnswer(invocation -> { + String applicationName = invocation.getArgument(0); + ServiceType serviceType = invocation.getArgument(1); + return new Application(applicationName, serviceType); + }); + when(applicationFactory.createApplicationByTypeName(anyString(), anyString())) + .thenAnswer(invocation -> { + String applicationName = invocation.getArgument(0); + ServiceType serviceType = registry.findServiceTypeByName(invocation.getArgument(1)); + return new Application(applicationName, serviceType); + }); + + when(serverInstanceDatasourceService.getServerInstanceListDataSource()) + .thenAnswer(invocation -> { + AgentInfoService agentInfoService = mock(AgentInfoService.class); + HyperLinkFactory hyperLinkFactory = new HyperLinkFactory(Collections.emptyList()); + return new AgentInfoServerInstanceListDataSource(agentInfoService, hyperLinkFactory); + }); + + filteredMapService = new FilteredMapServiceImpl(traceDao, applicationTraceIndexDao, + registry, applicationFactory, serverInstanceDatasourceService, Optional.empty(), applicationMapBuilderFactory); + } @AfterEach 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 6a767dd47843..fb9a8c8b2c0b 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 @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.vo; +import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -28,9 +29,11 @@ */ public class ApplicationAgentsListTest { + private HyperLinkFactory hyperLinkFactory = new HyperLinkFactory(null); + @Test public void groupByApplicationName() { - ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.APPLICATION_NAME, AgentInfoFilter::accept); + 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); @@ -58,7 +61,7 @@ public void groupByApplicationName() { @Test public void groupByHostNameShouldHaveContainersFirstAndGroupedSeparatelyByAgentStartTimestampDescendingOrder() { - ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept); + 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); @@ -97,9 +100,9 @@ public void mergeLists() { AgentInfo 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); + ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); applicationAgentsList.addAll(agentInfos.subList(0, agentInfos.size() / 2)); - ApplicationAgentsList applicationAgentsListToMerge = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept); + ApplicationAgentsList applicationAgentsListToMerge = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); applicationAgentsListToMerge.addAll(agentInfos.subList(agentInfos.size() / 2, agentInfos.size())); applicationAgentsList.merge(applicationAgentsListToMerge); @@ -132,9 +135,9 @@ 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); - ApplicationAgentsList groupedByHostnameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept); + ApplicationAgentsList groupedByHostnameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, AgentInfoFilter::accept, hyperLinkFactory); groupedByHostnameList.add(agent1); - ApplicationAgentsList groupedByApplicationNameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.APPLICATION_NAME, AgentInfoFilter::accept); + ApplicationAgentsList groupedByApplicationNameList = new ApplicationAgentsList(ApplicationAgentsList.GroupBy.APPLICATION_NAME, AgentInfoFilter::accept, hyperLinkFactory); groupedByApplicationNameList.add(agent2); groupedByApplicationNameList.add(agent3); From 54809c3d4a10ab9022b7972f20658b56bd23c606 Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 15 Jul 2022 20:22:28 +0900 Subject: [PATCH 2/3] [#9023] Refactor ClusterKey --- .../pinpoint/collector/cluster/AgentInfo.java | 107 -------------- .../collector/cluster/ClusterPoint.java | 3 +- .../cluster/ClusterPointRepository.java | 26 ++-- .../cluster/GrpcAgentConnection.java | 7 +- .../cluster/ThriftAgentConnection.java | 35 +++-- .../cluster/route/AbstractRouteHandler.java | 7 +- .../zookeeper/ZookeeperJobWorker2.java | 42 +++--- .../ZookeeperProfilerClusterManager.java | 12 +- .../controller/ClusterPointController.java | 21 ++- .../collector/manage/ClusterManager.java | 6 +- .../receiver/grpc/PinpointGrpcServer.java | 24 ++-- .../service/command/GrpcCommandService.java | 74 +++++----- .../receiver/grpc/PinpointGrpcServerTest.java | 8 +- .../{AgentInfoKey.java => ClusterKey.java} | 22 +-- .../dao/hbase/mapper/AgentInfoBoMapper.java | 8 +- .../thrift/io/TCommandTypeVersion.java | 7 +- .../nodes/ServerInstanceList.java | 43 +++--- .../controller/AgentCommandController.java | 14 +- .../web/cluster/ClusterDataManager.java | 6 +- .../web/cluster/ClusterKeyAndStatus.java | 24 ++++ .../pinpoint/web/cluster/ClusterKeyUtils.java | 21 +++ .../pinpoint/web/cluster/ClusterManager.java | 20 ++- .../CollectorClusterInfoRepository.java | 12 +- .../ZookeeperClusterDataManager.java | 24 ++-- .../web/controller/CommandController.java | 8 +- .../pinpoint/web/dao/AgentInfoDao.java | 4 - .../web/dao/hbase/HbaseAgentInfoDao.java | 39 ----- .../web/hyperlink/DefaultLinkSource.java | 4 +- .../web/service/AgentInfoAndStatus.java | 24 ++++ .../web/service/AgentInfoService.java | 5 +- .../web/service/AgentInfoServiceImpl.java | 21 +-- .../pinpoint/web/service/AgentService.java | 43 +++--- .../web/service/AgentServiceImpl.java | 136 +++++++++--------- .../pinpoint/web/service/SpanServiceImpl.java | 2 +- .../web/view/AgentInfoSerializer.java | 64 --------- .../pinpoint/web/view/NodeSerializer.java | 2 +- .../navercorp/pinpoint/web/vo/AgentInfo.java | 6 - .../pinpoint/web/vo/AgentInfoAndStatus.java | 24 ++++ .../ActiveThreadCountResponseAggregator.java | 60 ++++---- .../websocket/ActiveThreadCountWorker.java | 25 ++-- .../PinpointWebSocketHandlerWorker.java | 6 +- .../PinpointWebSocketResponseAggregator.java | 4 +- .../web/websocket/WorkerActiveManager.java | 36 ++--- .../CollectorClusterInfoRepositoryTest.java | 12 +- .../zookeeper/ZookeeperClusterTest.java | 37 ++--- 45 files changed, 506 insertions(+), 629 deletions(-) delete mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/cluster/AgentInfo.java rename commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/{AgentInfoKey.java => ClusterKey.java} (77%) create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyAndStatus.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java create mode 100644 web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/AgentInfo.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/AgentInfo.java deleted file mode 100644 index 106d0331266c..000000000000 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/AgentInfo.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2019 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.collector.cluster; - -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; - -import java.util.Objects; - -/** - * @author Taejin Koo - */ -public class AgentInfo { - - private final String applicationName; - private final String agentId; - private final long startTimestamp; - private final String version; - - private AgentInfoKey agentKey; - - public AgentInfo(String applicationName, String agentId, long startTimestamp) { - this(applicationName, agentId, startTimestamp, ""); - } - - public AgentInfo(String applicationName, String agentId, long startTimestamp, String version) { - this.applicationName = applicationName; - this.agentId = agentId; - this.startTimestamp = startTimestamp; - this.version = version; - } - - public String getApplicationName() { - return applicationName; - } - - public String getAgentId() { - return agentId; - } - - public long getStartTimestamp() { - return startTimestamp; - } - - public String getVersion() { - return version; - } - - public AgentInfoKey getAgentKey() { - if (agentKey == null) { - agentKey = new AgentInfoKey(applicationName, agentId, startTimestamp); - } - return agentKey; - } - - - public boolean equals(String applicationName, String agentId, long startTimestamp) { - if (!this.applicationName.equals(applicationName)) { - return false; - } - if (!this.agentId.equals(agentId)) { - return false; - } - if (this.startTimestamp != startTimestamp) { - return false; - } - return true; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - AgentInfo agentInfo = (AgentInfo) o; - return startTimestamp == agentInfo.startTimestamp && - Objects.equals(applicationName, agentInfo.applicationName) && - Objects.equals(agentId, agentInfo.agentId); - } - - @Override - public int hashCode() { - return Objects.hash(applicationName, agentId, startTimestamp); - } - - @Override - public String toString() { - return "AgentInfo{" + - "applicationName='" + applicationName + '\'' + - ", agentId='" + agentId + '\'' + - ", startTimestamp=" + startTimestamp + - ", version='" + version + '\'' + - '}'; - } -} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java index 6d3f237c0fe7..898935aa9215 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPoint.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.cluster; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.Future; import com.navercorp.pinpoint.rpc.ResponseMessage; @@ -28,7 +29,7 @@ public interface ClusterPoint { Future request(M request); - AgentInfo getDestAgentInfo(); + ClusterKey getDestClusterKey(); boolean isSupportCommand(TBase command); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java index 27c5eedf0097..e089522943e5 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ClusterPointRepository.java @@ -17,7 +17,7 @@ package com.navercorp.pinpoint.collector.cluster; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.common.SocketStateCode; import com.navercorp.pinpoint.rpc.server.PinpointServer; @@ -35,13 +35,12 @@ public class ClusterPointRepository> implements Cluste private final Logger logger = LogManager.getLogger(this.getClass()); - private final Map> clusterPointRepository = new HashMap<>(); + private final Map> clusterPointRepository = new HashMap<>(); public boolean addAndIsKeyCreated(T clusterPoint) { - AgentInfo destAgentInfo = clusterPoint.getDestAgentInfo(); - AgentInfoKey key = destAgentInfo.getAgentKey(); + ClusterKey destClusterKey = clusterPoint.getDestClusterKey(); synchronized (this) { - final Set clusterPointSet = clusterPointRepository.get(key); + final Set clusterPointSet = clusterPointRepository.get(destClusterKey); if (clusterPointSet != null) { clusterPointSet.add(clusterPoint); @@ -50,22 +49,21 @@ public boolean addAndIsKeyCreated(T clusterPoint) { Set newSet = new HashSet<>(); newSet.add(clusterPoint); - clusterPointRepository.put(key, newSet); + clusterPointRepository.put(destClusterKey, newSet); return true; } } } public boolean removeAndGetIsKeyRemoved(T clusterPoint) { - AgentInfo destAgentInfo = clusterPoint.getDestAgentInfo(); - AgentInfoKey key = destAgentInfo.getAgentKey(); + ClusterKey destClusterKey = clusterPoint.getDestClusterKey(); synchronized (this) { - final Set clusterPointSet = clusterPointRepository.get(key); + final Set clusterPointSet = clusterPointRepository.get(destClusterKey); if (clusterPointSet != null) { clusterPointSet.remove(clusterPoint); if (clusterPointSet.isEmpty()) { - clusterPointRepository.remove(key); + clusterPointRepository.remove(destClusterKey); return true; } } @@ -85,12 +83,12 @@ public List getClusterPointList() { } } - public Set getAvailableAgentKeyList() { + public Set getAvailableAgentKeyList() { synchronized (this) { - Set availableAgentKeySet = new HashSet<>(clusterPointRepository.size()); + Set availableAgentKeySet = new HashSet<>(clusterPointRepository.size()); - for (Map.Entry> entry : clusterPointRepository.entrySet()) { - final AgentInfoKey key = entry.getKey(); + for (Map.Entry> entry : clusterPointRepository.entrySet()) { + final ClusterKey key = entry.getKey(); final Set clusterPointSet = entry.getValue(); for (T clusterPoint : clusterPointSet) { if (clusterPoint instanceof ThriftAgentConnection) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java index 2bacaaf9680d..166e17158bae 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/GrpcAgentConnection.java @@ -18,6 +18,7 @@ import com.google.protobuf.GeneratedMessageV3; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.profiler.context.grpc.CommandThriftToGrpcMessageConverter; import com.navercorp.pinpoint.rpc.DefaultFuture; import com.navercorp.pinpoint.rpc.Future; @@ -72,8 +73,8 @@ public ClientStreamChannel openStream(TBase request, ClientStreamChannelEv } @Override - public AgentInfo getDestAgentInfo() { - return pinpointGrpcServer.getAgentInfo(); + public ClusterKey getDestClusterKey() { + return pinpointGrpcServer.getClusterKey(); } @Override @@ -92,7 +93,7 @@ public PinpointGrpcServer getPinpointGrpcServer() { @Override public int hashCode() { - return pinpointGrpcServer.getAgentInfo().hashCode(); + return pinpointGrpcServer.getClusterKey().hashCode(); } @Override diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java index 17f4fe7ba2b5..be9623d795e3 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/ThriftAgentConnection.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.collector.cluster; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.Future; import com.navercorp.pinpoint.rpc.ResponseMessage; import com.navercorp.pinpoint.rpc.server.ChannelProperties; @@ -34,32 +35,29 @@ public class ThriftAgentConnection implements ClusterPoint { private final PinpointServer pinpointServer; - private final AgentInfo agentInfo; - + private final ClusterKey clusterKey; + private final TCommandTypeVersion commandTypeVersion; private final List supportCommandList; public static ClusterPoint newClusterPoint(PinpointServer pinpointServer, ChannelProperties channelProperties) { - AgentInfo agentInfo = newAgentInfo(channelProperties); + ClusterKey agentInfo = newClusterKey(channelProperties); + TCommandTypeVersion commandTypeVersion = TCommandTypeVersion.getVersion(channelProperties.getAgentVersion()); List supportCommandList = SupportedCommandUtils.newSupportCommandList(channelProperties.getSupportCommand()); - return new ThriftAgentConnection(pinpointServer, agentInfo, supportCommandList); + return new ThriftAgentConnection(pinpointServer, agentInfo, commandTypeVersion, supportCommandList); } - public ThriftAgentConnection(PinpointServer pinpointServer, AgentInfo agentInfo, List supportCommandList) { + public ThriftAgentConnection(PinpointServer pinpointServer, ClusterKey clusterKey, TCommandTypeVersion commandTypeVersion, List supportCommandList) { this.pinpointServer = Objects.requireNonNull(pinpointServer, "pinpointServer"); - this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); + this.clusterKey = Objects.requireNonNull(clusterKey, "clusterKey"); + this.commandTypeVersion = Objects.requireNonNull(commandTypeVersion, "commandTypeVersion"); this.supportCommandList = Objects.requireNonNull(supportCommandList, "supportCommandList"); } - private static AgentInfo newAgentInfo(ChannelProperties channelProperties) { + private static ClusterKey newClusterKey(ChannelProperties channelProperties) { String applicationName = channelProperties.getApplicationName(); - String agentId = channelProperties.getAgentId(); - long startTimeStamp = channelProperties.getStartTime(); - - String version = channelProperties.getAgentVersion(); - - return new AgentInfo(applicationName, agentId, startTimeStamp, version); + return new ClusterKey(applicationName, agentId, startTimeStamp); } @Override @@ -68,8 +66,8 @@ public Future request(byte[] payload) { } @Override - public AgentInfo getDestAgentInfo() { - return agentInfo; + public ClusterKey getDestClusterKey() { + return clusterKey; } @Override @@ -80,8 +78,7 @@ public boolean isSupportCommand(TBase command) { } } - TCommandTypeVersion commandVersion = TCommandTypeVersion.getVersion(agentInfo.getVersion()); - if (commandVersion.isSupportCommand(command)) { + if (commandTypeVersion.isSupportCommand(command)) { return true; } @@ -97,7 +94,7 @@ public String toString() { StringBuilder log = new StringBuilder(32); log.append(this.getClass().getSimpleName()); log.append("("); - log.append(agentInfo); + log.append(clusterKey); log.append(", supportCommandList:"); log.append(supportCommandList); log.append(", pinpointServer:"); @@ -109,7 +106,7 @@ public String toString() { @Override public int hashCode() { - return agentInfo.hashCode(); + return clusterKey.hashCode(); } @Override diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/AbstractRouteHandler.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/AbstractRouteHandler.java index 3facc8496719..56dd62d60bd3 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/AbstractRouteHandler.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/route/AbstractRouteHandler.java @@ -16,9 +16,9 @@ package com.navercorp.pinpoint.collector.cluster.route; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.ClusterPoint; import com.navercorp.pinpoint.collector.cluster.ClusterPointLocator; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse; import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; @@ -46,12 +46,13 @@ protected ClusterPoint findClusterPoint(TCommandTransfer deliveryCommand) { String applicationName = deliveryCommand.getApplicationName(); String agentId = deliveryCommand.getAgentId(); long startTimeStamp = deliveryCommand.getStartTime(); + final ClusterKey sourceKey = new ClusterKey(applicationName, agentId, startTimeStamp); List> result = new ArrayList<>(); for (ClusterPoint targetClusterPoint : targetClusterPointLocator.getClusterPointList()) { - AgentInfo destAgentInfo = targetClusterPoint.getDestAgentInfo(); - if (destAgentInfo.equals(applicationName, agentId, startTimeStamp)) { + ClusterKey destAgentInfo = targetClusterPoint.getDestClusterKey(); + if (destAgentInfo.equals(sourceKey)) { result.add(targetClusterPoint); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperJobWorker2.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperJobWorker2.java index f9ec068eade8..b1056e2e9e04 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperJobWorker2.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperJobWorker2.java @@ -18,7 +18,7 @@ import com.navercorp.pinpoint.collector.cluster.zookeeper.job.ZookeeperJob; import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage; import com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperClient; import com.navercorp.pinpoint.common.server.cluster.zookeeper.util.CommonStateContext; @@ -41,7 +41,7 @@ /** * @author Taejin Koo */ -public class ZookeeperJobWorker2 implements Runnable, ClusterJobWorker { +public class ZookeeperJobWorker2 implements Runnable, ClusterJobWorker { private static final String PROFILER_SEPARATOR = "\r\n"; public static final String APPLICATION_NAME_SEPARATOR = "$$"; @@ -54,7 +54,7 @@ public class ZookeeperJobWorker2 implements Runnable, ClusterJobWorker> jobDeque = new LinkedBlockingDeque<>(); + private final LinkedBlockingDeque> jobDeque = new LinkedBlockingDeque<>(); private Thread workerThread; public ZookeeperJobWorker2(ZookeeperClient zookeeperClient, String connectedAgentZNodePath) { @@ -120,12 +120,12 @@ public void stop() { } @Override - public void addPinpointServer(AgentInfoKey key) { + public void addPinpointServer(ClusterKey key) { if (logger.isDebugEnabled()) { logger.debug("addPinpointServer key:{}", key); } - ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.ADD, key); + ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.ADD, key); synchronized (lock) { putZookeeperJob(job); } @@ -158,12 +158,12 @@ private String getClusterData(String path) { } @Override - public void removePinpointServer(AgentInfoKey key) { + public void removePinpointServer(ClusterKey key) { if (logger.isDebugEnabled()) { logger.debug("removePinpointServer key:{}", key); } - ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.REMOVE, key); + ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.REMOVE, key); synchronized (lock) { putZookeeperJob(job); } @@ -171,14 +171,14 @@ public void removePinpointServer(AgentInfoKey key) { @Override public void clear() { - ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.CLEAR); + ZookeeperJob job = new ZookeeperJob<>(ZookeeperJob.Type.CLEAR); synchronized (lock) { jobDeque.clear(); putZookeeperJob(job); } } - private boolean putZookeeperJob(ZookeeperJob zookeeperJob) { + private boolean putZookeeperJob(ZookeeperJob zookeeperJob) { synchronized (lock) { return jobDeque.add(zookeeperJob); } @@ -193,7 +193,7 @@ public void run() { // may lead to PinpointServer leak when events are left unresolved while (workerState.isStarted()) { try { - ZookeeperJob job = poll(); + ZookeeperJob job = poll(); boolean completed = handle(job); if (!completed) { @@ -207,9 +207,9 @@ public void run() { logger.info("run() completed."); } - private ZookeeperJob poll() throws InterruptedException { + private ZookeeperJob poll() throws InterruptedException { while (true) { - ZookeeperJob job = jobDeque.poll(3000, TimeUnit.MILLISECONDS); + ZookeeperJob job = jobDeque.poll(3000, TimeUnit.MILLISECONDS); if (job == null) { continue; } @@ -217,7 +217,7 @@ private ZookeeperJob poll() throws InterruptedException { } } - private boolean handle(ZookeeperJob job) { + private boolean handle(ZookeeperJob job) { ZookeeperJob.Type type = job.getType(); switch (type) { @@ -232,12 +232,12 @@ private boolean handle(ZookeeperJob job) { return false; } - private boolean handleUpdate(ZookeeperJob job) { + private boolean handleUpdate(ZookeeperJob job) { if (logger.isDebugEnabled()) { logger.debug("handleUpdate zookeeperJobList:{}", job); } - final AgentInfoKey key = job.getKey(); + final ClusterKey key = job.getKey(); try { String path = getPath(key); @@ -255,19 +255,19 @@ private boolean handleUpdate(ZookeeperJob job) { return false; } - private String getPath(AgentInfoKey key) { + private String getPath(ClusterKey key) { StringJoiner buffer = new StringJoiner(APPLICATION_NAME_SEPARATOR); buffer.add(collectorUniqPath); buffer.add(key.getApplicationName()); return buffer.toString(); } - private boolean handleDelete(ZookeeperJob job) { + private boolean handleDelete(ZookeeperJob job) { if (logger.isDebugEnabled()) { logger.debug("handleDelete zookeeperJobList:{}", job); } - final AgentInfoKey key = job.getKey(); + final ClusterKey key = job.getKey(); try { String path = getPath(key); @@ -286,7 +286,7 @@ private boolean handleDelete(ZookeeperJob job) { } - private boolean handleClear(ZookeeperJob job) { + private boolean handleClear(ZookeeperJob job) { if (logger.isDebugEnabled()) { logger.debug("handleClear zookeeperJobList:{}", job); } @@ -301,7 +301,7 @@ private boolean handleClear(ZookeeperJob job) { return false; } - private String addIfAbsentContents(String clusterDataString, AgentInfoKey addContentCandidate) { + private String addIfAbsentContents(String clusterDataString, ClusterKey addContentCandidate) { final List clusterDataList = tokenize(clusterDataString); List addContentCandidateList = Collections.singletonList(addContentCandidate.toString()); @@ -333,7 +333,7 @@ private boolean isExist(List contentList, String value) { return false; } - private String removeIfExistContents(String clusterDataString, AgentInfoKey removeClusterData) { + private String removeIfExistContents(String clusterDataString, ClusterKey removeClusterData) { final List clusterDataList = tokenize(clusterDataString); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperProfilerClusterManager.java b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperProfilerClusterManager.java index 198b68dee4e3..514178f49199 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperProfilerClusterManager.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/cluster/zookeeper/ZookeeperProfilerClusterManager.java @@ -19,7 +19,7 @@ import com.navercorp.pinpoint.collector.cluster.ClusterPoint; import com.navercorp.pinpoint.collector.cluster.ClusterPointRepository; import com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperClient; import com.navercorp.pinpoint.common.server.cluster.zookeeper.util.CommonStateContext; @@ -37,7 +37,7 @@ public class ZookeeperProfilerClusterManager implements ProfilerClusterManager { private final Logger logger = LogManager.getLogger(this.getClass()); - private final ClusterJobWorker worker; + private final ClusterJobWorker worker; private final CommonStateContext workerState = new CommonStateContext(); @@ -106,7 +106,7 @@ public boolean isRunning() { public void register(ClusterPoint targetClusterPoint) { if (workerState.isStarted()) { synchronized (lock) { - AgentInfoKey key = targetClusterPoint.getDestAgentInfo().getAgentKey(); + ClusterKey key = targetClusterPoint.getDestClusterKey(); boolean added = profileCluster.addAndIsKeyCreated(targetClusterPoint); if (key != null && added) { @@ -122,7 +122,7 @@ public void register(ClusterPoint targetClusterPoint) { public void unregister(ClusterPoint targetClusterPoint) { if (workerState.isStarted()) { synchronized (lock) { - AgentInfoKey key = targetClusterPoint.getDestAgentInfo().getAgentKey(); + ClusterKey key = targetClusterPoint.getDestClusterKey(); boolean removed = profileCluster.removeAndGetIsKeyRemoved(targetClusterPoint); if (key != null && removed) { @@ -139,8 +139,8 @@ public void refresh() { worker.clear(); synchronized (lock) { - Set availableAgentKeyList = profileCluster.getAvailableAgentKeyList(); - for (AgentInfoKey availableAgentKey : availableAgentKeyList) { + Set availableAgentKeyList = profileCluster.getAvailableAgentKeyList(); + for (ClusterKey availableAgentKey : availableAgentKeyList) { worker.addPinpointServer(availableAgentKey); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java b/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java index 278b3cf415f2..ff412f2eb60a 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/controller/ClusterPointController.java @@ -18,12 +18,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.ClusterPoint; import com.navercorp.pinpoint.collector.cluster.ClusterPointLocator; import com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.util.Assert; import com.navercorp.pinpoint.common.util.StringUtils; import com.navercorp.pinpoint.io.request.Message; @@ -136,17 +135,17 @@ private List getGrpcAgentConnectionList(final String applic if (!(clusterPoint instanceof GrpcAgentConnection)) { continue; } - AgentInfo destAgentInfo = clusterPoint.getDestAgentInfo(); + ClusterKey destClusterInfo = clusterPoint.getDestClusterKey(); - if (!destAgentInfo.getApplicationName().equals(applicationName)) { + if (!destClusterInfo.getApplicationName().equals(applicationName)) { continue; } - if (StringUtils.hasText(agentId) && !destAgentInfo.getAgentId().equals(agentId)) { + if (StringUtils.hasText(agentId) && !destClusterInfo.getAgentId().equals(agentId)) { continue; } - if (startTimestamp > 0 && destAgentInfo.getStartTimestamp() != startTimestamp) { + if (startTimestamp > 0 && destClusterInfo.getStartTimestamp() != startTimestamp) { continue; } @@ -157,7 +156,7 @@ private List getGrpcAgentConnectionList(final String applic } private CheckConnectionStatusResult request(GrpcAgentConnection grpcAgentConnection, int checkCount) { - logger.info("Ping message will be sent. collector => {}.", grpcAgentConnection.getDestAgentInfo().getAgentKey()); + logger.info("Ping message will be sent. collector => {}.", grpcAgentConnection.getDestClusterKey()); Future response = null; try { @@ -231,7 +230,7 @@ private static class GrpcAgentConnectionStats { private final InetSocketAddress remoteAddress; - private final AgentInfoKey agentKey; + private final ClusterKey clusterKey; private final String socketStateCode; @@ -242,7 +241,7 @@ private static class GrpcAgentConnectionStats { public GrpcAgentConnectionStats(GrpcAgentConnection grpcAgentConnection, CheckConnectionStatusResult checkConnectionStatusResult) { PinpointGrpcServer pinpointGrpcServer = grpcAgentConnection.getPinpointGrpcServer(); this.socketStateCode = pinpointGrpcServer.getState().name(); - this.agentKey = pinpointGrpcServer.getAgentInfo().getAgentKey(); + this.clusterKey = pinpointGrpcServer.getClusterKey(); this.remoteAddress = pinpointGrpcServer.getRemoteAddress(); this.availableCheckConnectionState = grpcAgentConnection.isSupportCommand(CONNECTION_CHECK_COMMAND); @@ -253,8 +252,8 @@ public InetSocketAddress getRemoteAddress() { return remoteAddress; } - public AgentInfoKey getAgentKey() { - return agentKey; + public ClusterKey getClusterKey() { + return clusterKey; } public String getSocketStateCode() { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/ClusterManager.java b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/ClusterManager.java index a1679e2aed65..11a3cd9d8822 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/manage/ClusterManager.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/manage/ClusterManager.java @@ -17,10 +17,10 @@ package com.navercorp.pinpoint.collector.manage; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.ClusterPoint; import com.navercorp.pinpoint.collector.cluster.ClusterPointLocator; import com.navercorp.pinpoint.collector.config.CollectorClusterConfig; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import java.util.ArrayList; import java.util.List; @@ -51,8 +51,8 @@ public List getConnectedAgentList() { List> clusterPointList = clusterPointLocator.getClusterPointList(); for (ClusterPoint clusterPoint : clusterPointList) { - AgentInfo destAgentInfo = clusterPoint.getDestAgentInfo(); - result.add(destAgentInfo.getAgentKey().toString()); + ClusterKey destClusterKey = clusterPoint.getDestClusterKey(); + result.add(destClusterKey.format()); } return result; diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java index c627606c885a..902d7a7564b8 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServer.java @@ -16,9 +16,9 @@ package com.navercorp.pinpoint.collector.receiver.grpc; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection; import com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.grpc.MessageFormatUtils; import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadCount; import com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump; @@ -80,16 +80,16 @@ public class PinpointGrpcServer { private final StreamChannelRepository streamChannelRepository = new StreamChannelRepository(); private final InetSocketAddress remoteAddress; - private final AgentInfo agentInfo; + private final ClusterKey clusterKey; private final RequestManager requestManager; private final ProfilerClusterManager profilerClusterManager; private final StreamObserver requestObserver; private Runnable onCloseHandler; - public PinpointGrpcServer(InetSocketAddress remoteAddress, AgentInfo agentInfo, RequestManager requestManager, ProfilerClusterManager profilerClusterManager, StreamObserver requestObserver) { + public PinpointGrpcServer(InetSocketAddress remoteAddress, ClusterKey clusterKey, RequestManager requestManager, ProfilerClusterManager profilerClusterManager, StreamObserver requestObserver) { this.remoteAddress = Objects.requireNonNull(remoteAddress, "remoteAddress"); - this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo"); + this.clusterKey = Objects.requireNonNull(clusterKey, "clusterKey"); this.requestManager = Objects.requireNonNull(requestManager, "requestManager"); this.profilerClusterManager = Objects.requireNonNull(profilerClusterManager, "profilerClusterManager"); this.requestObserver = Objects.requireNonNull(requestObserver, "requestObserver"); @@ -105,7 +105,7 @@ public void connected() { public boolean handleHandshake(List supportCommandServiceList) { if (isInfo) { - logger.info("{} handleHandshake() started. data:{}", agentInfo, supportCommandServiceList); + logger.info("{} handleHandshake() started. data:{}", clusterKey, supportCommandServiceList); } boolean isFirst = this.supportCommandServiceList.compareAndSet(null, supportCommandServiceList); @@ -128,7 +128,7 @@ private SocketStateChangeResult toState(SocketStateCode socketStateCode) { profilerClusterManager.unregister(grpcAgentConnection); } } else { - logger.warn("Failed to change state. agent:{}, result:{}", agentInfo, result); + logger.warn("Failed to change state. agent:{}, result:{}", clusterKey, result); } if (logger.isDebugEnabled()) { @@ -209,14 +209,14 @@ public void handleMessage(int responseId, GeneratedMessageV3 message) { } if (isInfo) { - logger.info("{} handleMessage:{}", agentInfo, MessageFormatUtils.debugLog(message)); + logger.info("{} handleMessage:{}", clusterKey, MessageFormatUtils.debugLog(message)); } TBase tMessage = messageConverter.toMessage(message); try { byte[] serialize = SerializationUtils.serialize(tMessage, commandHeaderTBaseSerializerFactory); ResponsePacket responsePacket = new ResponsePacket(responseId, serialize); - requestManager.messageReceived(responsePacket, agentInfo.toString()); + requestManager.messageReceived(responsePacket, clusterKey.format()); } catch (TException e) { setFailMessageToFuture(responseId, e.getMessage()); } @@ -303,7 +303,7 @@ public void close() { } public void close(SocketStateCode toState) { - logger.info("close() will be started. ( remoteAddress:{}, agentInfo:{}, closeState:{}", remoteAddress, agentInfo.getAgentKey(), toState); + logger.info("close() will be started. ( remoteAddress:{}, clusterKey:{}, closeState:{}", remoteAddress, clusterKey, toState); if (onCloseHandler != null) { onCloseHandler.run(); @@ -340,7 +340,7 @@ public void close(SocketStateCode toState) { logger.warn("stop(). Socket has unexpected state({})", currentStateCode); } } finally { - logger.info("{} <=> local all streamChannels will be close.", agentInfo.getAgentKey()); + logger.info("{} <=> local all streamChannels will be close.", clusterKey); streamChannelRepository.close(StreamCode.STATE_CLOSED); } } @@ -362,8 +362,8 @@ public SocketStateCode getState() { return state.getCurrentState(); } - public AgentInfo getAgentInfo() { - return agentInfo; + public ClusterKey getClusterKey() { + return clusterKey; } public Future createFailedFuture(Exception failException) { diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/command/GrpcCommandService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/command/GrpcCommandService.java index 5f0371110e61..ae0a160799bf 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/command/GrpcCommandService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/receiver/grpc/service/command/GrpcCommandService.java @@ -16,11 +16,11 @@ package com.navercorp.pinpoint.collector.receiver.grpc.service.command; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.ClusterService; import com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer; import com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServerRepository; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.grpc.Header; import com.navercorp.pinpoint.grpc.StatusError; import com.navercorp.pinpoint.grpc.StatusErrors; @@ -79,9 +79,9 @@ public GrpcCommandService(ClusterService clusterService) { @Override public StreamObserver handleCommand(StreamObserver requestObserver) { final Long transportId = getTransportId(); - final AgentInfo agentInfo = getAgentInfo(); + final ClusterKey clusterKey = getClusterKey(); - logger.info("{} => local. handleCommand(). transportId:{}.", agentInfo, transportId); + logger.info("{} => local. handleCommand(). transportId:{}.", clusterKey, transportId); final List supportCommandCodeList = getSupportCommandCodeList(); if (supportCommandCodeList != Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) { @@ -91,16 +91,16 @@ public StreamObserver handleCommand(StreamObserver req return DisabledStreamObserver.instance(); } - final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId); + final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, clusterKey, transportId); if (pinpointGrpcServer == null) { - return handleServerRegistrationFailed(requestObserver, agentInfo, transportId); + return handleServerRegistrationFailed(requestObserver, clusterKey, transportId); } final ServerCallStreamObserver serverCallStreamObserver = (ServerCallStreamObserver) requestObserver; serverCallStreamObserver.setOnReadyHandler(new Runnable() { public void run() { if (serverCallStreamObserver.isReady()) { - logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId); + logger.info("{} => local. ready() transportId:{}", clusterKey, transportId); pinpointGrpcServer.connected(); } @@ -128,12 +128,12 @@ public void onNext(PCmdMessage value) { @Override public void onError(Throwable t) { - handleOnError(t, pinpointGrpcServer, agentInfo); + handleOnError(t, pinpointGrpcServer, clusterKey); } @Override public void onCompleted() { - handleOnCompleted(pinpointGrpcServer, agentInfo); + handleOnCompleted(pinpointGrpcServer, clusterKey); } }; return responseObserver; @@ -142,26 +142,26 @@ public void onCompleted() { @Override public StreamObserver handleCommandV2(StreamObserver requestObserver) { final Long transportId = getTransportId(); - final AgentInfo agentInfo = getAgentInfo(); + final ClusterKey clusterKey = getClusterKey(); final List supportCommandCodeList = getSupportCommandCodeList(); - logger.info("{} => local. handleCommandV2(). transportId:{}, supportCommandCodeList{}", agentInfo, transportId, supportCommandCodeList); + logger.info("{} => local. handleCommandV2(). transportId:{}, supportCommandCodeList{}", clusterKey, transportId, supportCommandCodeList); if (supportCommandCodeList == Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) { logger.warn("handleCommandV2() not allow empty Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name()); requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT)); return DisabledStreamObserver.instance(); } - final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId); + final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, clusterKey, transportId); if (pinpointGrpcServer == null) { - return handleServerRegistrationFailed(requestObserver, agentInfo, transportId); + return handleServerRegistrationFailed(requestObserver, clusterKey, transportId); } final ServerCallStreamObserver serverCallStreamObserver = (ServerCallStreamObserver) requestObserver; serverCallStreamObserver.setOnReadyHandler(new Runnable() { public void run() { if (serverCallStreamObserver.isReady()) { - logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId); + logger.info("{} => local. ready() transportId:{}", clusterKey, transportId); pinpointGrpcServer.connected(); registerAgentCommandList(pinpointGrpcServer, supportCommandCodeList); } @@ -175,7 +175,7 @@ public void run() { } }); - final StreamObserver responseObserver = new StreamObserver() { + final StreamObserver responseObserver = new StreamObserver<>() { @Override public void onNext(PCmdMessage value) { if (value.hasFailMessage()) { @@ -186,20 +186,20 @@ public void onNext(PCmdMessage value) { @Override public void onError(Throwable t) { - handleOnError(t, pinpointGrpcServer, agentInfo); + handleOnError(t, pinpointGrpcServer, clusterKey); } @Override public void onCompleted() { - handleOnCompleted(pinpointGrpcServer, agentInfo); + handleOnCompleted(pinpointGrpcServer, clusterKey); } }; return responseObserver; } - private PinpointGrpcServer registerNewPinpointGrpcServer(StreamObserver requestObserver, AgentInfo agentInfo, Long transportId) { - PinpointGrpcServer pinpointGrpcServer = createPinpointGrpcServer(requestObserver, agentInfo); + private PinpointGrpcServer registerNewPinpointGrpcServer(StreamObserver requestObserver, ClusterKey clusterKey, Long transportId) { + PinpointGrpcServer pinpointGrpcServer = createPinpointGrpcServer(requestObserver, clusterKey); final boolean registered = grpcServerRepository.registerIfAbsent(transportId, pinpointGrpcServer); if (registered) { return pinpointGrpcServer; @@ -212,41 +212,41 @@ private void unregisterPinpointGrpcServer(Long transportId) { grpcServerRepository.unregister(transportId); } - private PinpointGrpcServer createPinpointGrpcServer(StreamObserver requestObserver, AgentInfo agentInfo) { + private PinpointGrpcServer createPinpointGrpcServer(StreamObserver requestObserver, ClusterKey clusterKey) { final RequestManager requestManager = new RequestManager(timer, 3000); - return new PinpointGrpcServer(getRemoteAddress(), agentInfo, requestManager, profilerClusterManager, requestObserver); + return new PinpointGrpcServer(getRemoteAddress(), clusterKey, requestManager, profilerClusterManager, requestObserver); } - private StreamObserver handleServerRegistrationFailed(StreamObserver requestObserver, AgentInfo agentInfo, Long transportId) { - logger.warn("Duplicate PCmdRequestStream found. Terminate stream. {} transportId:{}", agentInfo, transportId); + private StreamObserver handleServerRegistrationFailed(StreamObserver requestObserver, ClusterKey clusterKey, Long transportId) { + logger.warn("Duplicate PCmdRequestStream found. Terminate stream. {} transportId:{}", clusterKey, transportId); requestObserver.onError(new StatusException(Status.ALREADY_EXISTS)); return DisabledStreamObserver.instance(); } private boolean registerAgentCommandList(PinpointGrpcServer pinpointGrpcServer, List supportCommandServiceCodeList) { - logger.info("{} => local. execute supportCommandServiceCodeList:{}", getAgentInfo().getAgentKey(), supportCommandServiceCodeList); + logger.info("{} => local. execute supportCommandServiceCodeList:{}", getClusterKey(), supportCommandServiceCodeList); boolean handshakeSucceed = pinpointGrpcServer.handleHandshake(supportCommandServiceCodeList); return handshakeSucceed; } - private void handleOnError(Throwable t, PinpointGrpcServer pinpointGrpcServer, AgentInfo agentInfo) { + private void handleOnError(Throwable t, PinpointGrpcServer pinpointGrpcServer, ClusterKey clusterKey) { Objects.requireNonNull(pinpointGrpcServer, "pinpointGrpcServer"); - Objects.requireNonNull(agentInfo, "agentInfo"); + Objects.requireNonNull(clusterKey, "clusterKey"); final StatusError statusError = StatusErrors.throwable(t); if (statusError.isSimpleError()) { - logger.info("Failed to command stream, {} => local, cause={}", agentInfo.getAgentKey(), statusError.getMessage()); + logger.info("Failed to command stream, {} => local, cause={}", clusterKey, statusError.getMessage()); } else { - logger.warn("Failed to command stream, {} => local, cause={}", agentInfo.getAgentKey(), statusError.getMessage(), statusError.getThrowable()); + logger.warn("Failed to command stream, {} => local, cause={}", clusterKey, statusError.getMessage(), statusError.getThrowable()); } pinpointGrpcServer.disconnected(); } - private void handleOnCompleted(PinpointGrpcServer pinpointGrpcServer, AgentInfo agentInfo) { + private void handleOnCompleted(PinpointGrpcServer pinpointGrpcServer, ClusterKey clusterKey) { Objects.requireNonNull(pinpointGrpcServer, "pinpointGrpcServer"); - Objects.requireNonNull(agentInfo, "agentInfo"); + Objects.requireNonNull(clusterKey, "clusterKey"); - logger.info("{} => local. onCompleted", getAgentInfo().getAgentKey()); + logger.info("{} => local. onCompleted", getClusterKey()); pinpointGrpcServer.disconnected(); } @@ -260,7 +260,7 @@ public void commandEcho(PCmdEchoResponse echoResponse, StreamObserver res responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); } else { - logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId); + logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getClusterKey(), transportId); responseObserver.onError(new StatusException(Status.NOT_FOUND)); } } @@ -274,7 +274,7 @@ public void commandActiveThreadDump(PCmdActiveThreadDumpRes activeThreadDumpRes, responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); } else { - logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId); + logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getClusterKey(), transportId); responseObserver.onError(new StatusException(Status.NOT_FOUND)); } } @@ -288,7 +288,7 @@ public void commandActiveThreadLightDump(PCmdActiveThreadLightDumpRes activeThre responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); } else { - logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId); + logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getClusterKey(), transportId); responseObserver.onError(new StatusException(Status.NOT_FOUND)); } } @@ -298,7 +298,7 @@ public StreamObserver commandStreamActiveThreadCount(S final Long transportId = getTransportId(); PinpointGrpcServer pinpointGrpcServer = grpcServerRepository.get(transportId); if (pinpointGrpcServer == null) { - logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId); + logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getClusterKey(), transportId); streamConnectionManagerObserver.onError(new StatusException(Status.NOT_FOUND)); return DisabledStreamObserver.instance(); } @@ -306,7 +306,7 @@ public StreamObserver commandStreamActiveThreadCount(S try { return activeThreadCountService.handle(pinpointGrpcServer, streamConnectionManagerObserver); } catch (IllegalArgumentException e) { - logger.warn("Failed to handle activeThreadCountService. agentKey={}, transportId={}", getAgentInfo().getAgentKey(), transportId, e); + logger.warn("Failed to handle activeThreadCountService. agentKey={}, transportId={}", getClusterKey(), transportId, e); streamConnectionManagerObserver.onError(Status.INTERNAL.withDescription("Internal Server Error").asException()); return DisabledStreamObserver.instance(); } @@ -317,9 +317,9 @@ private InetSocketAddress getRemoteAddress() { return transportMetadata.getRemoteAddress(); } - private AgentInfo getAgentInfo() { + private ClusterKey getClusterKey() { Header header = ServerContext.getAgentInfo(); - return new AgentInfo(header.getApplicationName(), header.getAgentId(), header.getAgentStartTime()); + return new ClusterKey(header.getApplicationName(), header.getAgentId(), header.getAgentStartTime()); } private List getSupportCommandCodeList() { diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java index b663c768f023..4dfb11e5504b 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/grpc/PinpointGrpcServerTest.java @@ -17,8 +17,8 @@ package com.navercorp.pinpoint.collector.receiver.grpc; import com.google.protobuf.StringValue; -import com.navercorp.pinpoint.collector.cluster.AgentInfo; import com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.grpc.trace.PCmdEcho; import com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse; import com.navercorp.pinpoint.grpc.trace.PCmdRequest; @@ -48,7 +48,7 @@ public class PinpointGrpcServerTest { public static Timer testTimer = null; - private final AgentInfo agentInfo = new AgentInfo("applicationName", "agentid", System.currentTimeMillis()); + private final ClusterKey clusterKey = new ClusterKey("applicationName", "agentid", System.currentTimeMillis()); private final PCmdEcho request = PCmdEcho.newBuilder().setMessage("hello").build(); @@ -68,7 +68,7 @@ public static void tearDown() throws Exception { public void stateTest() { RecordedStreamObserver recordedStreamObserver = new RecordedStreamObserver(); - PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), agentInfo, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver); + PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), clusterKey, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver); assertCurrentState(SocketStateCode.NONE, pinpointGrpcServer); Future future = pinpointGrpcServer.request(request); requestOnInvalidState(future, recordedStreamObserver); @@ -98,7 +98,7 @@ private void requestOnInvalidState(Future future, RecordedStrea public void requestTest() { RecordedStreamObserver recordedStreamObserver = new RecordedStreamObserver(); - PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), agentInfo, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver); + PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), clusterKey, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver); pinpointGrpcServer.connected(); List supportCommandList = Collections.singletonList(Short.toUnsignedInt(TCommandType.ECHO.getCode())); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/AgentInfoKey.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java similarity index 77% rename from commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/AgentInfoKey.java rename to commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java index 4e26dcab9218..798a778baa11 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/AgentInfoKey.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/cluster/ClusterKey.java @@ -4,22 +4,22 @@ import java.util.Objects; -public class AgentInfoKey { +public class ClusterKey { public static final String DELIMITER = ":"; private final String applicationName; private final String agentId; private final long startTimestamp; - public static AgentInfoKey parse(String agentKeyStr) { - Objects.requireNonNull(agentKeyStr, "agentKeyStr"); + public static ClusterKey parse(String clusterKeyFormat) { + Objects.requireNonNull(clusterKeyFormat, "clusterKeyFormat"); - String[] tokens = agentKeyStr.split(DELIMITER); + String[] tokens = clusterKeyFormat.split(DELIMITER); Assert.isTrue(tokens.length == 3, "invalid token.length == 3"); - return new AgentInfoKey(tokens[0], tokens[1], Long.parseLong(tokens[2])); + return new ClusterKey(tokens[0], tokens[1], Long.parseLong(tokens[2])); } - public AgentInfoKey(String applicationName, String agentId, long startTimestamp) { + public ClusterKey(String applicationName, String agentId, long startTimestamp) { this.applicationName = Objects.requireNonNull(applicationName, "applicationName"); this.agentId = Objects.requireNonNull(agentId, "agentId"); this.startTimestamp = startTimestamp; @@ -42,7 +42,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - AgentInfoKey that = (AgentInfoKey) o; + ClusterKey that = (ClusterKey) o; if (startTimestamp != that.startTimestamp) return false; if (!applicationName.equals(that.applicationName)) return false; @@ -57,8 +57,7 @@ public int hashCode() { return result; } - @Override - public String toString() { + public String format() { StringBuilder builder = new StringBuilder(64); builder.append(applicationName); builder.append(DELIMITER); @@ -67,4 +66,9 @@ public String toString() { builder.append(startTimestamp); return builder.toString(); } + + @Override + public String toString() { + return format(); + } } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java index 692824742df1..7489ca8695d2 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java @@ -45,17 +45,17 @@ public AgentInfoBo mapRow(Result result, int rowNum) throws Exception { long reverseStartTime = BytesUtils.bytesToLong(rowKey, HbaseTableConstants.AGENT_ID_MAX_LEN); long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime); - byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER); - byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA); - byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM); - + final byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER); final AgentInfoBo.Builder agentInfoBoBuilder = createBuilderFromValue(serializedAgentInfo); agentInfoBoBuilder.setAgentId(agentId); agentInfoBoBuilder.setStartTime(startTime); + final byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA); if (serializedServerMetaData != null) { agentInfoBoBuilder.setServerMetaData(new ServerMetaDataBo.Builder(serializedServerMetaData).build()); } + + final byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM); if (serializedJvmInfo != null) { agentInfoBoBuilder.setJvmInfo(new JvmInfoBo(serializedJvmInfo)); } diff --git a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandTypeVersion.java b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandTypeVersion.java index 333a933ebf99..65549b5f2725 100644 --- a/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandTypeVersion.java +++ b/thrift/src/main/java/com/navercorp/pinpoint/thrift/io/TCommandTypeVersion.java @@ -19,6 +19,7 @@ import org.apache.thrift.TBase; import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.Objects; @@ -80,7 +81,9 @@ public enum TCommandTypeVersion { UNKNOWN("UNKNOWN"); private final String versionName; - private final List supportCommandList = new ArrayList(); + private final List supportCommandList = new ArrayList<>(); + + private static final EnumSet ALL = EnumSet.allOf(TCommandTypeVersion.class); TCommandTypeVersion(String versionName, TCommandTypeVersion version, TCommandType... supportCommandArray) { this.versionName = versionName; @@ -131,7 +134,7 @@ public String getVersionName() { public static TCommandTypeVersion getVersion(String version) { Objects.requireNonNull(version, "version"); - for (TCommandTypeVersion versionType : TCommandTypeVersion.values()) { + for (TCommandTypeVersion versionType : ALL) { if (versionType.getVersionName().equals(version)) { return versionType; } 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 23ecba4ba272..f5ff02cc33ee 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 @@ -16,7 +16,12 @@ package com.navercorp.pinpoint.web.applicationmap.nodes; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.navercorp.pinpoint.web.view.ServerInstanceListSerializer; @@ -41,35 +46,25 @@ public Map> getServerInstanceList() { } public List getAgentIdList() { - final Collection> serverInstanceValueList = this.serverInstanceList.values(); - - final List agentList = new ArrayList<>(); - for (List serverInstanceList : serverInstanceValueList) { - for (ServerInstance serverInstance : serverInstanceList) { - agentList.add(serverInstance.getName()); - } - } - return agentList; + Collection> serverList = this.serverInstanceList.values(); + return serverList.stream() + .flatMap(List::stream) + .map(ServerInstance::getName) + .collect(Collectors.toList()); } public Map getAgentIdNameMap() { - final Collection> serverInstanceValueList = this.serverInstanceList.values(); - - final Map map = new HashMap<>(); - for (List serverInstanceList : serverInstanceValueList) { - for (ServerInstance serverInstance : serverInstanceList) { - map.put(serverInstance.getName(), serverInstance.getAgentName()); - } - } - return map; + Collection> serverList = this.serverInstanceList.values(); + return serverList.stream() + .flatMap(List::stream) + .collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName)); } public int getInstanceCount() { - int count = 0; - for (List entry : serverInstanceList.values()) { - count += entry.size(); - } - return count; + Collection> serverList = this.serverInstanceList.values(); + return serverList.stream() + .mapToInt(List::size) + .sum(); } private void addServerInstance(List nodeList, ServerInstance serverInstance) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java index 1afe176640ba..daff92414f65 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentCommandController.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.authorization.controller; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.thrift.dto.TResult; import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump; import com.navercorp.pinpoint.thrift.dto.command.TActiveThreadLightDump; @@ -31,6 +32,7 @@ import com.navercorp.pinpoint.web.vo.AgentActiveThreadDumpList; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.response.CodeResult; +import com.navercorp.pinpoint.web.cluster.ClusterKeyUtils; import org.apache.thrift.TBase; import org.apache.thrift.TException; import org.springframework.http.HttpStatus; @@ -68,8 +70,8 @@ public CodeResult getActiveThreadDump(@RequestParam(value = "applicationName") S } - AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId); - if (agentInfo == null) { + final ClusterKey clusterKey = agentService.getClusterKey(applicationName, agentId); + if (clusterKey == null) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Can't find suitable Agent(%s/%s)", applicationName, agentId)); } @@ -86,7 +88,7 @@ public CodeResult getActiveThreadDump(@RequestParam(value = "applicationName") S } try { - PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, threadDump); + PinpointRouteResponse pinpointRouteResponse = agentService.invoke(clusterKey, threadDump); if (isSuccessResponse(pinpointRouteResponse)) { TBase result = pinpointRouteResponse.getResponse(); if (result instanceof TCmdActiveThreadDumpRes) { @@ -163,8 +165,8 @@ public CodeResult getActiveThreadLightDump(@RequestParam(value = "applicationNam throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Disable activeThreadDump option. 'config.enable.activeThreadDump=false'"); } - AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId); - if (agentInfo == null) { + final ClusterKey clusterKey = agentService.getClusterKey(applicationName, agentId); + if (clusterKey == null) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Can't find suitable Agent(%s/%s)", applicationName, agentId)); } @@ -180,7 +182,7 @@ public CodeResult getActiveThreadLightDump(@RequestParam(value = "applicationNam } try { - PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, threadDump); + PinpointRouteResponse pinpointRouteResponse = agentService.invoke(clusterKey, threadDump); if (isSuccessResponse(pinpointRouteResponse)) { TBase result = pinpointRouteResponse.getResponse(); if (result instanceof TCmdActiveThreadLightDumpRes) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterDataManager.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterDataManager.java index fa380ea11c74..1a7b236a3c12 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterDataManager.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterDataManager.java @@ -1,6 +1,6 @@ package com.navercorp.pinpoint.web.cluster; -import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import java.util.List; @@ -15,8 +15,6 @@ public interface ClusterDataManager { boolean registerWebCluster(String zNodeName, byte[] contents); - List getRegisteredAgentList(AgentInfo agentInfo); - - List getRegisteredAgentList(String applicationName, String agentId, long startTimeStamp); + List getRegisteredAgentList(ClusterKey key); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyAndStatus.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyAndStatus.java new file mode 100644 index 000000000000..a70d32ced15e --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyAndStatus.java @@ -0,0 +1,24 @@ +package com.navercorp.pinpoint.web.cluster; + +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; +import com.navercorp.pinpoint.web.vo.AgentStatus; + +import java.util.Objects; + +public class ClusterKeyAndStatus { + private final ClusterKey clusterKey; + private final AgentStatus status; + + public ClusterKeyAndStatus(ClusterKey clusterKey, AgentStatus status) { + this.clusterKey = Objects.requireNonNull(clusterKey, "clusterKey"); + this.status = Objects.requireNonNull(status, "status"); + } + + public ClusterKey getClusterKey() { + return clusterKey; + } + + public AgentStatus getStatus() { + return status; + } +} 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 new file mode 100644 index 000000000000..89050c891fd7 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterKeyUtils.java @@ -0,0 +1,21 @@ +package com.navercorp.pinpoint.web.cluster; + +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; +import com.navercorp.pinpoint.web.vo.AgentInfo; + +import java.util.Objects; + +public final class ClusterKeyUtils { + + public static ClusterKey from(AgentInfo agentInfo) { + Objects.requireNonNull(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()); + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterManager.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterManager.java index c22af7c41be0..b31253f5e211 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterManager.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/ClusterManager.java @@ -16,12 +16,12 @@ package com.navercorp.pinpoint.web.cluster; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.util.NetUtils; import com.navercorp.pinpoint.rpc.PinpointSocket; import com.navercorp.pinpoint.web.cluster.connection.ClusterAcceptor; import com.navercorp.pinpoint.web.cluster.connection.ClusterConnectionManager; import com.navercorp.pinpoint.web.config.WebClusterConfig; -import com.navercorp.pinpoint.web.vo.AgentInfo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -129,31 +129,29 @@ public boolean isEnabled() { return config.isClusterEnable(); } - public boolean isConnected(AgentInfo agentInfo) { + public boolean isConnected(ClusterKey clusterKey) { if (!isEnabled()) { return false; } - - List clusterIdList = clusterDataManager.getRegisteredAgentList(agentInfo); + List clusterIdList = clusterDataManager.getRegisteredAgentList(clusterKey); return clusterIdList.size() == 1; } - public List getSocket(AgentInfo agentInfo) { - return getSocket(agentInfo.getApplicationName(), agentInfo.getAgentId(), agentInfo.getStartTimestamp()); - } - public List getSocket(String applicationName, String agentId, long startTimeStamp) { + public List getSocket(ClusterKey clusterKey) { + Objects.requireNonNull(clusterKey, "clusterKey"); + if (!isEnabled()) { return Collections.emptyList(); } - List clusterIdList = clusterDataManager.getRegisteredAgentList(applicationName, agentId, startTimeStamp); + List clusterIdList = clusterDataManager.getRegisteredAgentList(clusterKey); if (clusterIdList.isEmpty()) { - logger.warn("{}/{}/{} couldn't find agent.", applicationName, agentId, startTimeStamp); + logger.warn("{} couldn't find agent.", clusterKey); return Collections.emptyList(); } else if (clusterIdList.size() > 1) { - logger.warn("{}/{}/{} found duplicate agent {}.", applicationName, agentId, startTimeStamp, clusterIdList); + logger.warn("{} found duplicate agent {}.", clusterKey, clusterIdList); } List pinpointSocketList = new ArrayList<>(clusterIdList.size()); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepository.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepository.java index 052dcd8c6d5a..ce40f5276009 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepository.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepository.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.web.cluster; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import java.util.ArrayList; import java.util.HashMap; @@ -31,11 +31,11 @@ */ public class CollectorClusterInfoRepository { - private final Map> repository = new HashMap<>(); + private final Map> repository = new HashMap<>(); private final Object lock = new Object(); - public void put(ClusterId clusterId, Set profilerInfoSet) { + public void put(ClusterId clusterId, Set profilerInfoSet) { Objects.requireNonNull(clusterId, "clusterId"); Objects.requireNonNull(profilerInfoSet, "profilerInfoSet"); @@ -52,13 +52,13 @@ public void remove(ClusterId clusterId) { } } - public List get(AgentInfoKey agentKey) { + public List get(ClusterKey agentKey) { Objects.requireNonNull(agentKey, "agentKey"); final List result = new ArrayList<>(); synchronized (lock) { - for (Map.Entry> entry : repository.entrySet()) { - final Set valueSet = entry.getValue(); + for (Map.Entry> entry : repository.entrySet()) { + final Set valueSet = entry.getValue(); final boolean exist = valueSet.contains(agentKey); if (exist) { final ClusterId clusterId = entry.getKey(); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterDataManager.java b/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterDataManager.java index f2dd132547e7..e0f8446171a3 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterDataManager.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterDataManager.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.web.cluster.zookeeper; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage; import com.navercorp.pinpoint.common.server.cluster.zookeeper.CuratorZookeeperClient; import com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperClient; @@ -37,7 +37,6 @@ import com.navercorp.pinpoint.web.cluster.ClusterId; import com.navercorp.pinpoint.web.cluster.CollectorClusterInfoRepository; import com.navercorp.pinpoint.web.config.WebClusterConfig; -import com.navercorp.pinpoint.web.vo.AgentInfo; import org.apache.curator.utils.ZKPaths; import org.apache.zookeeper.WatchedEvent; @@ -255,13 +254,8 @@ private boolean handleNodeDataChanged(String path) { } @Override - public List getRegisteredAgentList(AgentInfo agentInfo) { - return getRegisteredAgentList(agentInfo.getApplicationName(), agentInfo.getAgentId(), agentInfo.getStartTimestamp()); - } - - @Override - public List getRegisteredAgentList(String applicationName, String agentId, long startTimeStamp) { - final AgentInfoKey key = new AgentInfoKey(applicationName, agentId, startTimeStamp); + public List getRegisteredAgentList(ClusterKey key) { + Objects.requireNonNull(key, "key"); return collectorClusterInfo.get(key); } @@ -285,7 +279,7 @@ private boolean syncPullCollectorCluster() { logger.info("Get collector({}) info.", map.keySet()); for (Map.Entry entry : map.entrySet()) { - Set profilerInfo = newProfilerInfo(entry.getValue()); + Set profilerInfo = newProfilerInfo(entry.getValue()); collectorClusterInfo.put(entry.getKey(), profilerInfo); } @@ -300,7 +294,7 @@ private boolean pushCollectorClusterData(ClusterId id) { synchronized (this) { try { byte[] data = client.getData(path, true); - Set profilerInfo = newProfilerInfo(data); + Set profilerInfo = newProfilerInfo(data); collectorClusterInfo.put(id, profilerInfo); logger.info("pushCollectorClusterData() completed. {}", path); return true; @@ -314,17 +308,17 @@ private boolean pushCollectorClusterData(ClusterId id) { return false; } } - private Set newProfilerInfo(byte[] bytes) { + private Set newProfilerInfo(byte[] bytes) { if (bytes == null) { return Collections.emptySet(); } final String strData = new String(bytes, StandardCharsets.UTF_8); final String[] profilerInfoList = StringUtils.tokenizeToStringArray(strData, PROFILER_SEPARATOR); - Set agentInfoKeys = Arrays.stream(profilerInfoList) - .map(AgentInfoKey::parse) + Set clusterKeys = Arrays.stream(profilerInfoList) + .map(ClusterKey::parse) .collect(Collectors.toSet()); - return agentInfoKeys; + return clusterKeys; } class PushWebClusterJob implements PushZnodeJob { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java index 78b18b50db38..cfb619187590 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/CommandController.java @@ -16,12 +16,12 @@ package com.navercorp.pinpoint.web.controller; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.thrift.dto.TResult; import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; import com.navercorp.pinpoint.thrift.dto.command.TRouteResult; import com.navercorp.pinpoint.web.cluster.PinpointRouteResponse; import com.navercorp.pinpoint.web.service.AgentService; -import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.response.CodeResult; import org.apache.thrift.TBase; import org.apache.thrift.TException; @@ -55,8 +55,8 @@ public CommandController(AgentService agentService) { public CodeResult echo(@RequestParam("applicationName") String applicationName, @RequestParam("agentId") String agentId, @RequestParam("startTimeStamp") long startTimeStamp, @RequestParam("message") String message) throws TException { - AgentInfo agentInfo = agentService.getAgentInfo(applicationName, agentId, startTimeStamp); - if (agentInfo == null) { + final ClusterKey clusterKey = agentService.getClusterKey(applicationName, agentId, startTimeStamp); + if (clusterKey == null) { throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Can't find suitable PinpointServer(%s/%s/%d).", applicationName, agentId, startTimeStamp)); } @@ -64,7 +64,7 @@ public CodeResult echo(@RequestParam("applicationName") String applicationName, echo.setMessage(message); try { - PinpointRouteResponse pinpointRouteResponse = agentService.invoke(agentInfo, echo); + PinpointRouteResponse pinpointRouteResponse = agentService.invoke(clusterKey, echo); if (pinpointRouteResponse != null && pinpointRouteResponse.getRouteResult() == TRouteResult.OK) { TBase result = pinpointRouteResponse.getResponse(); if (result == null) { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentInfoDao.java index ee130534720f..97addef89684 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentInfoDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/AgentInfoDao.java @@ -26,10 +26,6 @@ */ public interface AgentInfoDao { - AgentInfo getInitialAgentInfo(String agentId); - - List getInitialAgentInfos(List agentIds); - AgentInfo getAgentInfo(String agentId, long timestamp); AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTimeInMilliSeconds); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java index e60a58fb9712..b65450fe7f9d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java @@ -62,45 +62,6 @@ public HbaseAgentInfoDao(HbaseOperations2 hbaseOperations2, this.agentInfoResultsExtractor = Objects.requireNonNull(agentInfoResultsExtractor, "agentInfoResultsExtractor"); } - /** - * Returns the very first information of the agent - * - * @param agentId - */ - @Override - public AgentInfo getInitialAgentInfo(final String agentId) { - Objects.requireNonNull(agentId, "agentId"); - - Scan scan = createScanForInitialAgentInfo(agentId); - - TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable()); - return this.hbaseOperations2.find(agentInfoTableName, scan, agentInfoResultsExtractor); - } - - @Override - public List getInitialAgentInfos(List agentIds) { - if (CollectionUtils.isEmpty(agentIds)) { - return Collections.emptyList(); - } - List scans = new ArrayList<>(agentIds.size()); - for (String agentId : agentIds) { - scans.add(createScanForInitialAgentInfo(agentId)); - } - - TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable()); - return this.hbaseOperations2.find(agentInfoTableName, scans, agentInfoResultsExtractor); - } - - private Scan createScanForInitialAgentInfo(String agentId) { - Scan scan = new Scan(); - - byte[] reverseStartKey = RowKeyUtils.agentIdAndTimestamp(agentId, Long.MAX_VALUE); - scan.withStartRow(reverseStartKey); - scan.setReversed(true); - scan.setMaxVersions(1); - scan.setCaching(SCANNER_CACHING); - return scan; - } /** * Returns the information of the agent with its start time closest to the given timestamp diff --git a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java index e3413512e034..f969306e64cb 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java @@ -1,12 +1,14 @@ package com.navercorp.pinpoint.web.hyperlink; +import javax.annotation.Nullable; + public class DefaultLinkSource implements LinkSource { private final String hostName; private final String ip; - public DefaultLinkSource(String hostName, String ip) { + public DefaultLinkSource(String hostName, @Nullable String ip) { this.hostName = hostName; this.ip = ip; } 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 new file mode 100644 index 000000000000..04d70f8ba612 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java @@ -0,0 +1,24 @@ +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 d7ff793e0031..6149aafff686 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 @@ -16,7 +16,6 @@ package com.navercorp.pinpoint.web.service; -import com.navercorp.pinpoint.web.vo.AgentDownloadInfo; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentInfoFilter; import com.navercorp.pinpoint.web.vo.AgentStatus; @@ -52,7 +51,9 @@ public interface AgentInfoService { AgentInfo getAgentInfo(String agentId, long timestamp); - AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds); + AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp); + + AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds); AgentStatus getAgentStatus(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 a7f17d89b33d..dc0635ca8e3d 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 @@ -278,12 +278,7 @@ public Set getRecentAgentsByApplicationName(String applicationName, l @Override public AgentInfo getAgentInfo(String agentId, long timestamp) { - Objects.requireNonNull(agentId, "agentId"); - - if (timestamp < 0) { - throw new IllegalArgumentException("timestamp must not be less than 0"); - } - AgentInfo agentInfo = this.agentInfoDao.getAgentInfo(agentId, timestamp); + AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp); if (agentInfo != null) { Optional agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp); agentInfo.setStatus(agentStatus.orElse(null)); @@ -292,7 +287,17 @@ public AgentInfo getAgentInfo(String agentId, long timestamp) { } @Override - public AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) { + public AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp) { + Objects.requireNonNull(agentId, "agentId"); + + if (timestamp < 0) { + throw new IllegalArgumentException("timestamp must not be less than 0"); + } + return this.agentInfoDao.getAgentInfo(agentId, timestamp); + } + + @Override + public AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) { return this.agentInfoDao.getAgentInfo(agentId, agentStartTime, deltaTimeInMilliSeconds); } @@ -348,7 +353,7 @@ public InspectorTimeline getAgentStatusTimeline(String agentId, Range range, int @Override public boolean isExistAgentId(String agentId) { - AgentInfo agentInfo = getAgentInfo(agentId, System.currentTimeMillis()); + AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, System.currentTimeMillis()); return agentInfo != null; } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentService.java index 75b2966ded7e..f309a282c6be 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentService.java @@ -16,13 +16,14 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannel; import com.navercorp.pinpoint.rpc.stream.ClientStreamChannelEventHandler; import com.navercorp.pinpoint.rpc.stream.StreamException; +import com.navercorp.pinpoint.web.cluster.ClusterKeyAndStatus; import com.navercorp.pinpoint.web.cluster.PinpointRouteResponse; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList; -import com.navercorp.pinpoint.web.vo.AgentInfo; import org.apache.thrift.TBase; import org.apache.thrift.TException; @@ -35,33 +36,33 @@ */ public interface AgentService { - AgentInfo getAgentInfo(String applicationName, String agentId); - AgentInfo getAgentInfo(String applicationName, String agentId, long startTimeStamp); - AgentInfo getAgentInfo(String applicationName, String agentId, long startTimeStamp, boolean checkDB); + ClusterKey getClusterKey(String applicationName, String agentId); + ClusterKey getClusterKey(String applicationName, String agentId, long startTimeStamp); + ClusterKey getClusterKey(String applicationName, String agentId, long startTimeStamp, boolean checkDB); - List getRecentAgentInfoList(String applicationName); - List getRecentAgentInfoList(String applicationName, long timeDiff); + List getRecentAgentInfoList(String applicationName); + List getRecentAgentInfoList(String applicationName, long timeDiff); - boolean isConnected(AgentInfo agentInfo); + boolean isConnected(ClusterKey clusterKey); - PinpointRouteResponse invoke(AgentInfo agentInfo, TBase tBase) throws TException; - PinpointRouteResponse invoke(AgentInfo agentInfo, TBase tBase, long timeout) throws TException; - PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload) throws TException; - PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long timeout) throws TException; + PinpointRouteResponse invoke(ClusterKey clusterKey, TBase tBase) throws TException; + PinpointRouteResponse invoke(ClusterKey clusterKey, TBase tBase, long timeout) throws TException; + PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload) throws TException; + PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload, long timeout) throws TException; - Map invoke(List agentInfoList, TBase tBase) throws TException; - Map invoke(List agentInfoList, TBase tBase, long timeout) throws TException; - Map invoke(List agentInfoList, byte[] payload) throws TException; - Map invoke(List agentInfoList, byte[] payload, long timeout) throws TException; + Map invoke(List agentInfoList, TBase tBase) throws TException; + Map invoke(List agentInfoList, TBase tBase, long timeout) throws TException; + Map invoke(List agentInfoList, byte[] payload) throws TException; + Map invoke(List agentInfoList, byte[] payload, long timeout) throws TException; - ClientStreamChannel openStream(AgentInfo agentInfo, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException; - ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException; + ClientStreamChannel openStream(ClusterKey clusterKey, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException; + ClientStreamChannel openStream(ClusterKey clusterKey, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException; - ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException; - ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException; + ClientStreamChannel openStreamAndAwait(ClusterKey clusterKey, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException; + ClientStreamChannel openStreamAndAwait(ClusterKey clusterKey, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException; - AgentActiveThreadCountList getActiveThreadCount(List agentInfoList) throws TException; - AgentActiveThreadCountList getActiveThreadCount(List agentInfoList, byte[] payload) throws TException; + AgentActiveThreadCountList getActiveThreadCount(List agentInfoList) throws TException; + AgentActiveThreadCountList getActiveThreadCount(List agentInfoList, byte[] payload) throws TException; byte[] serializeRequest(TBase tBase) throws TException; byte[] serializeRequest(TBase tBase, byte[] defaultValue); 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 beb8918fa0ef..6e16df7f2940 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 @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.service; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.util.CollectionUtils; import com.navercorp.pinpoint.io.request.Message; import com.navercorp.pinpoint.rpc.Future; @@ -34,6 +35,7 @@ import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer; import com.navercorp.pinpoint.thrift.io.SerializerFactory; import com.navercorp.pinpoint.thrift.util.SerializationUtils; +import com.navercorp.pinpoint.web.cluster.ClusterKeyAndStatus; import com.navercorp.pinpoint.web.cluster.ClusterManager; import com.navercorp.pinpoint.web.cluster.DefaultPinpointRouteResponse; import com.navercorp.pinpoint.web.cluster.FailedPinpointRouteResponse; @@ -43,19 +45,20 @@ import com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList; import com.navercorp.pinpoint.web.vo.AgentInfo; +import com.navercorp.pinpoint.web.cluster.ClusterKeyUtils; import org.apache.thrift.TBase; import org.apache.thrift.TException; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * @author HyunGil Jeong @@ -91,10 +94,10 @@ private void setTimeDiffMs(int durationDays) { } @Override - public AgentInfo getAgentInfo(String applicationName, String agentId) { + public ClusterKey getClusterKey(String applicationName, String agentId) { long currentTime = System.currentTimeMillis(); - Set agentInfos = agentInfoService.getAgentsByApplicationName(applicationName, currentTime); + Set agentInfos = agentInfoService.getAgentsByApplicationNameWithoutStatus(applicationName, currentTime); for (AgentInfo agentInfo : agentInfos) { if (agentInfo == null) { continue; @@ -106,23 +109,23 @@ public AgentInfo getAgentInfo(String applicationName, String agentId) { continue; } - return agentInfo; + return ClusterKeyUtils.from(agentInfo); } return null; } @Override - public AgentInfo getAgentInfo(String applicationName, String agentId, long startTimeStamp) { - return getAgentInfo(applicationName, agentId, startTimeStamp, false); + public ClusterKey getClusterKey(String applicationName, String agentId, long startTimeStamp) { + return getClusterKey(applicationName, agentId, startTimeStamp, false); } @Override - public AgentInfo getAgentInfo(String applicationName, String agentId, long startTimeStamp, boolean checkDB) { + public ClusterKey getClusterKey(String applicationName, String agentId, long startTimeStamp, boolean checkDB) { if (checkDB) { long currentTime = System.currentTimeMillis(); - Set agentInfos = agentInfoService.getAgentsByApplicationName(applicationName, currentTime); + Set agentInfos = agentInfoService.getAgentsByApplicationNameWithoutStatus(applicationName, currentTime); for (AgentInfo agentInfo : agentInfos) { if (agentInfo == null) { continue; @@ -137,62 +140,57 @@ public AgentInfo getAgentInfo(String applicationName, String agentId, long start continue; } - return agentInfo; + return ClusterKeyUtils.from(agentInfo); } return null; } else { - AgentInfo agentInfo = new AgentInfo(); - agentInfo.setApplicationName(applicationName); - agentInfo.setAgentId(agentId); - agentInfo.setStartTimestamp(startTimeStamp); - return agentInfo; + return new ClusterKey(applicationName, agentId, startTimeStamp); } } @Override - public List getRecentAgentInfoList(String applicationName) { + public List getRecentAgentInfoList(String applicationName) { return this.getRecentAgentInfoList(applicationName, this.timeDiffMs); } @Override - public List getRecentAgentInfoList(String applicationName, long timeDiff) { - List agentInfoList = new ArrayList<>(); + public List getRecentAgentInfoList(String applicationName, long timeDiff) { long currentTime = System.currentTimeMillis(); Set agentInfos = agentInfoService.getRecentAgentsByApplicationName(applicationName, currentTime, timeDiff); - for (AgentInfo agentInfo : agentInfos) { - org.apache.commons.collections4.CollectionUtils.addIgnoreNull(agentInfoList, agentInfo); - } - return agentInfoList; + return agentInfos.stream() + .filter(Objects::nonNull) + .map(ClusterKeyUtils::withStatusFrom) + .collect(Collectors.toList()); } @Override - public boolean isConnected(AgentInfo agentInfo) { - return clusterManager.isConnected(agentInfo); + public boolean isConnected(ClusterKey clusterKey) { + return clusterManager.isConnected(clusterKey); } @Override - public PinpointRouteResponse invoke(AgentInfo agentInfo, TBase tBase) throws TException { + public PinpointRouteResponse invoke(ClusterKey clusterKey, TBase tBase) throws TException { byte[] payload = serializeRequest(tBase); - return invoke(agentInfo, payload); + return invoke(clusterKey, payload); } @Override - public PinpointRouteResponse invoke(AgentInfo agentInfo, TBase tBase, long timeout) throws TException { + public PinpointRouteResponse invoke(ClusterKey clusterKey, TBase tBase, long timeout) throws TException { byte[] payload = serializeRequest(tBase); - return invoke(agentInfo, payload, timeout); + return invoke(clusterKey, payload, timeout); } @Override - public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload) throws TException { - return invoke(agentInfo, payload, DEFAULT_FUTURE_TIMEOUT); + public PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload) throws TException { + return invoke(clusterKey, payload, DEFAULT_FUTURE_TIMEOUT); } @Override - public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long timeout) throws TException { - TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload); - List socketList = clusterManager.getSocket(agentInfo); + public PinpointRouteResponse invoke(ClusterKey clusterKey, byte[] payload, long timeout) throws TException { + TCommandTransfer transferObject = createCommandTransferObject(clusterKey, payload); + List socketList = clusterManager.getSocket(clusterKey); Future future = null; if (CollectionUtils.nullSafeSize(socketList) == 1) { @@ -200,72 +198,71 @@ public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long ti future = socket.request(serializeRequest(transferObject)); } - PinpointRouteResponse response = getResponse(future, timeout); - return response; + return getResponse(future, timeout); } @Override - public Map invoke(List agentInfoList, TBase tBase) + public Map invoke(List agentInfoList, TBase tBase) throws TException { byte[] payload = serializeRequest(tBase); return invoke(agentInfoList, payload); } @Override - public Map invoke(List agentInfoList, TBase tBase, long timeout) + public Map invoke(List agentInfoList, TBase tBase, long timeout) throws TException { byte[] payload = serializeRequest(tBase); return invoke(agentInfoList, payload, timeout); } @Override - public Map invoke(List agentInfoList, byte[] payload) + public Map invoke(List agentInfoList, byte[] payload) throws TException { return invoke(agentInfoList, payload, DEFAULT_FUTURE_TIMEOUT); } @Override - public Map invoke(List agentInfoList, byte[] payload, long timeout) + public Map invoke(List agentInfoList, byte[] payload, long timeout) throws TException { - Map> futureMap = new HashMap<>(); - for (AgentInfo agentInfo : agentInfoList) { - TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload); - List socketList = clusterManager.getSocket(agentInfo); + Map> futureMap = new HashMap<>(); + for (ClusterKey clusterKey : agentInfoList) { + TCommandTransfer transferObject = createCommandTransferObject(clusterKey, payload); + List socketList = clusterManager.getSocket(clusterKey); if (CollectionUtils.nullSafeSize(socketList) == 1) { PinpointSocket socket = socketList.get(0); Future future = socket.request(serializeRequest(transferObject)); - futureMap.put(agentInfo, future); + futureMap.put(clusterKey, future); } else { - futureMap.put(agentInfo, null); + futureMap.put(clusterKey, null); } } long startTime = System.currentTimeMillis(); - Map result = new HashMap<>(); - for (Map.Entry> futureEntry : futureMap.entrySet()) { - AgentInfo agentInfo = futureEntry.getKey(); + Map result = new HashMap<>(); + for (Map.Entry> futureEntry : futureMap.entrySet()) { + ClusterKey clusterKey = futureEntry.getKey(); Future future = futureEntry.getValue(); PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout)); - result.put(agentInfo, response); + result.put(clusterKey, response); } return result; } @Override - public ClientStreamChannel openStream(AgentInfo agentInfo, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException { + public ClientStreamChannel openStream(ClusterKey clusterKey, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException { byte[] payload = serializeRequest(tBase); - return openStream(agentInfo, payload, streamChannelEventHandler); + return openStream(clusterKey, payload, streamChannelEventHandler); } @Override - public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException { + public ClientStreamChannel openStream(ClusterKey clusterKey, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException { assertClusterEnabled(); - TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload); - List socketList = clusterManager.getSocket(agentInfo); + TCommandTransfer transferObject = createCommandTransferObject(clusterKey, payload); + List socketList = clusterManager.getSocket(clusterKey); if (CollectionUtils.nullSafeSize(socketList) == 1) { PinpointSocket socket = socketList.get(0); return socket.openStream(serializeRequest(transferObject), streamChannelEventHandler); @@ -277,17 +274,17 @@ public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, Clien } @Override - public ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException { + public ClientStreamChannel openStreamAndAwait(ClusterKey clusterKey, TBase tBase, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException { byte[] payload = serializeRequest(tBase); - return openStreamAndAwait(agentInfo, payload, streamChannelEventHandler, timeout); + return openStreamAndAwait(clusterKey, payload, streamChannelEventHandler, timeout); } @Override - public ClientStreamChannel openStreamAndAwait(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException { + public ClientStreamChannel openStreamAndAwait(ClusterKey clusterKey, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler, long timeout) throws TException, StreamException { assertClusterEnabled(); - TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload); - List socketList = clusterManager.getSocket(agentInfo); + TCommandTransfer transferObject = createCommandTransferObject(clusterKey, payload); + List socketList = clusterManager.getSocket(clusterKey); if (CollectionUtils.nullSafeSize(socketList) == 1) { PinpointSocket socket = socketList.get(0); return socket.openStreamAndAwait(serializeRequest(transferObject), streamChannelEventHandler, timeout); @@ -305,22 +302,21 @@ private void assertClusterEnabled() throws StreamException { } @Override - public AgentActiveThreadCountList getActiveThreadCount(List agentInfoList) throws TException { + public AgentActiveThreadCountList getActiveThreadCount(List agentInfoList) throws TException { byte[] activeThread = serializeRequest(new TCmdActiveThreadCount()); return getActiveThreadCount(agentInfoList, activeThread); } @Override - public AgentActiveThreadCountList getActiveThreadCount(List agentInfoList, byte[] payload) - throws TException { + public AgentActiveThreadCountList getActiveThreadCount(List agentInfoList, byte[] payload) throws TException { AgentActiveThreadCountList activeThreadCountList = new AgentActiveThreadCountList(agentInfoList.size()); - Map responseList = invoke(agentInfoList, payload); - for (Map.Entry entry : responseList.entrySet()) { - AgentInfo agentInfo = entry.getKey(); + Map responseList = invoke(agentInfoList, payload); + for (Map.Entry entry : responseList.entrySet()) { + ClusterKey clusterKey = entry.getKey(); PinpointRouteResponse response = entry.getValue(); - AgentActiveThreadCount activeThreadCount = createActiveThreadCount(agentInfo.getAgentId(), response); + AgentActiveThreadCount activeThreadCount = createActiveThreadCount(clusterKey.getAgentId(), response); activeThreadCountList.add(activeThreadCount); } @@ -340,11 +336,13 @@ private AgentActiveThreadCount createActiveThreadCount(String agentId, PinpointR } } - private TCommandTransfer createCommandTransferObject(AgentInfo agentInfo, byte[] payload) { + private TCommandTransfer createCommandTransferObject(ClusterKey clusterKey, byte[] payload) { + Objects.requireNonNull(clusterKey, "agentInfoKey"); + TCommandTransfer transferObject = new TCommandTransfer(); - transferObject.setApplicationName(agentInfo.getApplicationName()); - transferObject.setAgentId(agentInfo.getAgentId()); - transferObject.setStartTime(agentInfo.getStartTimestamp()); + transferObject.setApplicationName(clusterKey.getApplicationName()); + transferObject.setAgentId(clusterKey.getAgentId()); + transferObject.setStartTime(clusterKey.getStartTimestamp()); transferObject.setPayload(payload); return transferObject; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/SpanServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/SpanServiceImpl.java index 8d6e174b8dd5..c801c000a69b 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/SpanServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/SpanServiceImpl.java @@ -506,7 +506,7 @@ private SpanResult order(List spans, Predicate filter, boolean i private Optional getAgentName(String agentId, long agentStartTime) { final int deltaTimeInMilli = 1000; - final AgentInfo agentInfo = this.agentInfoService.getAgentInfoNoStatus(agentId, agentStartTime, deltaTimeInMilli); + final AgentInfo agentInfo = this.agentInfoService.getAgentInfoWithoutStatus(agentId, agentStartTime, deltaTimeInMilli); return agentInfo == null ? Optional.empty() : Optional.ofNullable(agentInfo.getAgentName()); } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java deleted file mode 100644 index 02bd92985ad1..000000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.view; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.navercorp.pinpoint.web.vo.AgentInfo; -import com.navercorp.pinpoint.web.vo.AgentStatus; - -import java.io.IOException; - -/** - * @author HyunGil Jeong - */ -public class AgentInfoSerializer extends JsonSerializer { - - public AgentInfoSerializer() { - } - - @Override - public void serialize(AgentInfo agentInfo, JsonGenerator jgen, SerializerProvider provider) throws IOException { - jgen.writeStartObject(); - - jgen.writeStringField("applicationName", agentInfo.getApplicationName()); - jgen.writeStringField("agentId", agentInfo.getAgentId()); - jgen.writeStringField("agentName", agentInfo.getAgentName()); - jgen.writeNumberField("startTimestamp", agentInfo.getStartTimestamp()); - jgen.writeStringField("hostName", agentInfo.getHostName()); - jgen.writeStringField("ip", agentInfo.getIp()); - jgen.writeStringField("ports", agentInfo.getPorts()); - - jgen.writeStringField("serviceType", agentInfo.getServiceType().getDesc()); - jgen.writeNumberField("pid", agentInfo.getPid()); - jgen.writeStringField("vmVersion", agentInfo.getVmVersion()); - jgen.writeStringField("agentVersion", agentInfo.getAgentVersion()); - jgen.writeObjectField("serverMetaData", agentInfo.getServerMetaData()); - jgen.writeObjectField("jvmInfo", agentInfo.getJvmInfo()); - - AgentStatus status = agentInfo.getStatus(); - if (status != null) { - jgen.writeObjectField("status", status); - } - - jgen.writeNumberField("initialStartTimestamp", agentInfo.getInitialStartTimestamp()); - - jgen.writeEndObject(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/view/NodeSerializer.java b/web/src/main/java/com/navercorp/pinpoint/web/view/NodeSerializer.java index 30f6c47d4eba..5d899a29ee5c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/view/NodeSerializer.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/view/NodeSerializer.java @@ -42,7 +42,7 @@ public class NodeSerializer extends JsonSerializer { @Override - public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { + public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); // jgen.writeStringField("id", node.getNodeName());serverInstanceList jgen.writeStringField("key", node.getNodeName()); // necessary for go.js 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 00e8d884fd02..a2f59cebb97b 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 @@ -47,7 +47,6 @@ public class AgentInfo { private String agentVersion; private ServerMetaDataBo serverMetaData; private JvmInfoBo jvmInfo; - private long initialStartTimestamp; private boolean container; private AgentStatus status; @@ -163,10 +162,6 @@ public void setJvmInfo(JvmInfoBo jvmInfo) { this.jvmInfo = jvmInfo; } - public long getInitialStartTimestamp() { - return initialStartTimestamp; - } - public boolean isContainer() { return container; @@ -221,7 +216,6 @@ public String toString() { sb.append(", agentVersion='").append(agentVersion).append('\''); sb.append(", serverMetaData='").append(serverMetaData).append('\''); sb.append(", jvmInfo=").append(jvmInfo); - sb.append(", initialStartTimestamp=").append(initialStartTimestamp); sb.append(", container=").append(container); sb.append(", status=").append(status); sb.append('}'); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java new file mode 100644 index 000000000000..0c00946b2fb3 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfoAndStatus.java @@ -0,0 +1,24 @@ +package com.navercorp.pinpoint.web.vo; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; + +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"); + } + + @JsonUnwrapped + public AgentInfo getAgentInfo() { + return agentInfo; + } + + public AgentStatus getStatus() { + return status; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountResponseAggregator.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountResponseAggregator.java index 2595b01e14ea..eac69d57d9f8 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountResponseAggregator.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountResponseAggregator.java @@ -16,14 +16,17 @@ package com.navercorp.pinpoint.web.websocket; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; import com.navercorp.pinpoint.rpc.stream.StreamChannel; +import com.navercorp.pinpoint.web.cluster.ClusterKeyAndStatus; import com.navercorp.pinpoint.web.service.AgentService; import com.navercorp.pinpoint.web.task.TimerTaskDecorator; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCount; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCountList; import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; +import com.navercorp.pinpoint.web.cluster.ClusterKeyUtils; import com.navercorp.pinpoint.web.websocket.message.PinpointWebSocketMessageConverter; import com.fasterxml.jackson.core.JsonProcessingException; @@ -122,33 +125,34 @@ public void addWebSocketSession(WebSocketSession webSocketSession) { logger.info("addWebSocketSession. applicationName:{}, webSocketSession:{}", applicationName, webSocketSession); - List agentInfoList = agentService.getRecentAgentInfoList(applicationName, DEFAULT_AGENT_LOOKUP_TIME); + List clusterKeys = agentService.getRecentAgentInfoList(applicationName, DEFAULT_AGENT_LOOKUP_TIME); synchronized (workerManagingLock) { if (isStopped) { return; } - Map streamChannelMap = new HashMap<>(agentInfoList.size()); - for (AgentInfo agentInfo : agentInfoList) { - AgentStatus agentStatus = agentInfo.getStatus(); + Map streamChannelMap = new HashMap<>(clusterKeys.size()); + for (ClusterKeyAndStatus key : clusterKeys) { + ClusterKey clusterKey = key.getClusterKey(); + AgentStatus agentStatus = key.getStatus(); if (agentStatus != null && agentStatus.getState() != AgentLifeCycleState.UNKNOWN) { - StreamChannel streamChannel = registerWorkerAndConnectStream(agentInfo); - streamChannelMap.put(agentInfo, streamChannel); - } else if (agentService.isConnected(agentInfo)) { - StreamChannel streamChannel = registerWorkerAndConnectStream(agentInfo); - streamChannelMap.put(agentInfo, streamChannel); + StreamChannel streamChannel = registerWorkerAndConnectStream(key.getClusterKey()); + streamChannelMap.put(clusterKey, streamChannel); + } else if (agentService.isConnected(clusterKey)) { + StreamChannel streamChannel = registerWorkerAndConnectStream(clusterKey); + streamChannelMap.put(clusterKey, streamChannel); } } long maxAwaitTimeout = 3000; long currentTimeMillis = System.currentTimeMillis(); - for (Map.Entry agentInfoStreamChannelEntry : streamChannelMap.entrySet()) { - AgentInfo agentInfo = agentInfoStreamChannelEntry.getKey(); + for (Map.Entry agentInfoStreamChannelEntry : streamChannelMap.entrySet()) { + ClusterKey clusterKey = agentInfoStreamChannelEntry.getKey(); StreamChannel streamChannel = agentInfoStreamChannelEntry.getValue(); long diff = System.currentTimeMillis() - currentTimeMillis; long awaitTimeout = Math.max(maxAwaitTimeout - diff, 500); - activeWorker(agentInfo, streamChannel, awaitTimeout); + activeWorker(clusterKey, streamChannel, awaitTimeout); } final boolean added = webSocketSessions.add(webSocketSession); @@ -188,10 +192,10 @@ public boolean removeWebSocketSessionAndGetIsCleared(WebSocketSession webSocketS } @Override - public void addActiveWorker(AgentInfo agentInfo) { - logger.info("activeWorker applicationName:{}, agentId:{}", applicationName, agentInfo.getAgentId()); + public void addActiveWorker(ClusterKey clusterKey) { + logger.info("activeWorker applicationName:{}, agentId:{}", applicationName, clusterKey.getAgentId()); - if (!applicationName.equals(agentInfo.getApplicationName())) { + if (!applicationName.equals(clusterKey.getApplicationName())) { return; } @@ -199,18 +203,18 @@ public void addActiveWorker(AgentInfo agentInfo) { if (isStopped) { return; } - activeWorker(agentInfo); + activeWorker(clusterKey); } } - private StreamChannel registerWorkerAndConnectStream(AgentInfo agentInfo) { - String agentId = agentInfo.getAgentId(); + private StreamChannel registerWorkerAndConnectStream(ClusterKey clusterKey) { + String agentId = clusterKey.getAgentId(); synchronized (workerManagingLock) { ActiveThreadCountWorker worker = activeThreadCountWorkerRepository.get(agentId); if (worker == null) { - worker = new ActiveThreadCountWorker(agentService, agentInfo, this, workerActiveManager); - StreamChannel streamChannel = worker.connect(agentInfo); + worker = new ActiveThreadCountWorker(agentService, clusterKey.getApplicationName(), clusterKey.getAgentId(), this, workerActiveManager); + StreamChannel streamChannel = worker.connect(clusterKey); activeThreadCountWorkerRepository.put(agentId, worker); return streamChannel; } else { @@ -219,8 +223,8 @@ private StreamChannel registerWorkerAndConnectStream(AgentInfo agentInfo) { } } - private void activeWorker(AgentInfo agentInfo, StreamChannel streamChannel, long waitTimeout) { - String agentId = agentInfo.getAgentId(); + private void activeWorker(ClusterKey clusterKey, StreamChannel streamChannel, long waitTimeout) { + String agentId = clusterKey.getAgentId(); synchronized (workerManagingLock) { ActiveThreadCountWorker worker = activeThreadCountWorkerRepository.get(agentId); @@ -231,19 +235,21 @@ private void activeWorker(AgentInfo agentInfo, StreamChannel streamChannel, long } } - private void activeWorker(AgentInfo agentInfo) { - String agentId = agentInfo.getAgentId(); + private void activeWorker(ClusterKey clusterKey) { + String agentId = clusterKey.getAgentId(); synchronized (workerManagingLock) { ActiveThreadCountWorker worker = activeThreadCountWorkerRepository.get(agentId); if (worker == null) { - worker = new ActiveThreadCountWorker(agentService, agentInfo, this, workerActiveManager); - StreamChannel streamChannel = worker.connect(agentInfo); + worker = new ActiveThreadCountWorker(agentService, + clusterKey.getApplicationName(), clusterKey.getAgentId(), + this, workerActiveManager); + StreamChannel streamChannel = worker.connect(clusterKey); worker.active(streamChannel, 3000); activeThreadCountWorkerRepository.put(agentId, worker); } else { - worker.reactive(agentInfo); + worker.reactive(clusterKey); } } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java index df8ce8602499..da3d1e98414d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/ActiveThreadCountWorker.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.websocket; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.packet.stream.StreamClosePacket; import com.navercorp.pinpoint.rpc.packet.stream.StreamCode; import com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket; @@ -30,7 +31,6 @@ import com.navercorp.pinpoint.web.service.AgentService; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCount; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCountFactory; -import com.navercorp.pinpoint.web.vo.AgentInfo; import org.apache.thrift.TBase; import org.apache.thrift.TException; @@ -69,9 +69,6 @@ public class ActiveThreadCountWorker implements PinpointWebSocketHandlerWorker { private StreamChannel streamChannel; - public ActiveThreadCountWorker(AgentService agentService, AgentInfo agentInfo, PinpointWebSocketResponseAggregator webSocketResponseAggregator, WorkerActiveManager workerActiveManager) { - this(agentService, agentInfo.getApplicationName(), agentInfo.getAgentId(), webSocketResponseAggregator, workerActiveManager); - } public ActiveThreadCountWorker(AgentService agentService, String applicationName, String agentId, PinpointWebSocketResponseAggregator webSocketResponseAggregator, WorkerActiveManager workerActiveManager) { this.agentService = Objects.requireNonNull(agentService, "agentService"); @@ -90,12 +87,12 @@ public ActiveThreadCountWorker(AgentService agentService, String applicationName } @Override - public StreamChannel connect(AgentInfo agentInfo) { - if (!applicationName.equals(agentInfo.getApplicationName())) { + public StreamChannel connect(ClusterKey clusterKey) { + if (!applicationName.equals(clusterKey.getApplicationName())) { return null; } - if (!agentId.equals(agentInfo.getAgentId())) { + if (!agentId.equals(clusterKey.getAgentId())) { return null; } @@ -107,14 +104,14 @@ public StreamChannel connect(AgentInfo agentInfo) { StreamChannel streamChannel = null; try { - streamChannel = connect0(agentInfo); + streamChannel = connect0(clusterKey); return streamChannel; } catch (StreamException streamException) { closeStreamChannel(streamChannel, streamException.getStreamCode()); StreamCode streamCode = streamException.getStreamCode(); if (streamCode == StreamCode.CONNECTION_NOT_FOUND) { - workerActiveManager.addReactiveWorker(agentInfo); + workerActiveManager.addReactiveWorker(clusterKey); } setDefaultErrorMessage(streamCode.name()); } catch (TException exception) { @@ -140,7 +137,7 @@ public void active(StreamChannel streamChannel, long waitTimeout) { } @Override - public boolean reactive(AgentInfo agentInfo) { + public boolean reactive(ClusterKey clusterKey) { synchronized (lock) { if (isTurnOn()) { if (active) { @@ -148,7 +145,7 @@ public boolean reactive(AgentInfo agentInfo) { } logger.info("ActiveThreadCountWorker reactive. applicationName:{}, agentId:{}", applicationName, agentId); - active = active0(agentInfo); + active = active0(clusterKey); return active; } } @@ -172,7 +169,7 @@ public void stop() { } } - private boolean active0(AgentInfo agentInfo) { + private boolean active0(ClusterKey agentInfo) { synchronized (lock) { StreamChannel streamChannel = null; try { @@ -213,8 +210,8 @@ private boolean active0(StreamChannel streamChannel, long timeout) { } } - private StreamChannel connect0(AgentInfo agentInfo) throws TException, StreamException { - return agentService.openStream(agentInfo, COMMAND_INSTANCE, eventHandler); + private StreamChannel connect0(ClusterKey clusterKey) throws TException, StreamException { + return agentService.openStream(clusterKey, COMMAND_INSTANCE, eventHandler); } private boolean isTurnOn() { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketHandlerWorker.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketHandlerWorker.java index 7bac08086dfc..de66b731b66f 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketHandlerWorker.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketHandlerWorker.java @@ -16,19 +16,19 @@ package com.navercorp.pinpoint.web.websocket; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.rpc.stream.StreamChannel; -import com.navercorp.pinpoint.web.vo.AgentInfo; /** * @author Taejin Koo */ public interface PinpointWebSocketHandlerWorker { - StreamChannel connect(AgentInfo agentInfo); + StreamChannel connect(ClusterKey clusterKey); void active(StreamChannel streamChannel, long waitTimeout); - boolean reactive(AgentInfo agentInfo); + boolean reactive(ClusterKey clusterKey); void stop(); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketResponseAggregator.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketResponseAggregator.java index e45da6cd6f78..cc166e93cedc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketResponseAggregator.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/PinpointWebSocketResponseAggregator.java @@ -16,8 +16,8 @@ package com.navercorp.pinpoint.web.websocket; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.web.vo.AgentActiveThreadCount; -import com.navercorp.pinpoint.web.vo.AgentInfo; import org.springframework.web.socket.WebSocketSession; import java.util.concurrent.Executor; @@ -42,7 +42,7 @@ public interface PinpointWebSocketResponseAggregator { // return when aggregator cleared. boolean removeWebSocketSessionAndGetIsCleared(WebSocketSession webSocketSession); - void addActiveWorker(AgentInfo agentInfo); + void addActiveWorker(ClusterKey clusterKey); String getApplicationName(); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/websocket/WorkerActiveManager.java b/web/src/main/java/com/navercorp/pinpoint/web/websocket/WorkerActiveManager.java index 8bead561d51b..1c5e71b6a407 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/websocket/WorkerActiveManager.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/websocket/WorkerActiveManager.java @@ -16,10 +16,11 @@ package com.navercorp.pinpoint.web.websocket; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState; +import com.navercorp.pinpoint.web.cluster.ClusterKeyAndStatus; import com.navercorp.pinpoint.web.service.AgentService; import com.navercorp.pinpoint.web.task.TimerTaskDecorator; -import com.navercorp.pinpoint.web.vo.AgentInfo; import com.navercorp.pinpoint.web.vo.AgentStatus; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -88,9 +89,9 @@ public void close() { } } - public void addReactiveWorker(AgentInfo agentInfo) { - if (this.applicationName.equals(agentInfo.getApplicationName())) { - addReactiveWorker(agentInfo.getAgentId()); + public void addReactiveWorker(ClusterKey clusterKey) { + if (this.applicationName.equals(clusterKey.getApplicationName())) { + addReactiveWorker(clusterKey.getAgentId()); } } @@ -144,9 +145,9 @@ public void run() { for (String agentId : reactiveWorkerCandidates) { try { - AgentInfo newAgentInfo = agentService.getAgentInfo(applicationName, agentId); - if (newAgentInfo != null) { - responseAggregator.addActiveWorker(newAgentInfo); + final ClusterKey clusterKey = agentService.getClusterKey(applicationName, agentId); + if (clusterKey != null) { + responseAggregator.addActiveWorker(clusterKey); } } catch (Exception e) { logger.warn("failed while to get AgentInfo(applicationName:{}, agentId:{}). error:{}.", applicationName, agentId, e.getMessage(), e); @@ -164,7 +165,7 @@ public void run() { logger.debug("AgentCheckTimerTask started."); } - List agentInfoList = Collections.emptyList(); + List agentInfoList = Collections.emptyList(); try { agentInfoList = agentService.getRecentAgentInfoList(applicationName, DEFAULT_AGENT_LOOKUP_TIME); } catch (Exception e) { @@ -172,17 +173,18 @@ public void run() { } try { - for (AgentInfo agentInfo : agentInfoList) { - String agentId = agentInfo.getAgentId(); + for (ClusterKeyAndStatus clusterKeyStatus : agentInfoList) { + final ClusterKey clusterKey = clusterKeyStatus.getClusterKey(); + final String agentId = clusterKey.getAgentId(); if (defaultAgentIdList.contains(agentId)) { continue; } - AgentStatus agentStatus = agentInfo.getStatus(); + final AgentStatus agentStatus = clusterKeyStatus.getStatus(); if (agentStatus != null && agentStatus.getState() != AgentLifeCycleState.UNKNOWN) { - addActiveWorker(agentInfo); - } else if (agentService.isConnected(agentInfo)) { - addActiveWorker(agentInfo); + addActiveWorker(clusterKey); + } else if (agentService.isConnected(clusterKey)) { + addActiveWorker(clusterKey); } } } finally { @@ -194,10 +196,10 @@ public void run() { } } - private void addActiveWorker(AgentInfo agentInfo) { + private void addActiveWorker(ClusterKey clusterKey) { try { - responseAggregator.addActiveWorker(agentInfo); - defaultAgentIdList.add(agentInfo.getAgentId()); + responseAggregator.addActiveWorker(clusterKey); + defaultAgentIdList.add(clusterKey.getAgentId()); } catch (Exception e) { logger.warn("failed while adding active worker. error:{}", e.getMessage(), e); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepositoryTest.java b/web/src/test/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepositoryTest.java index c2153e936c19..f2eaadff7283 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepositoryTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepositoryTest.java @@ -16,7 +16,7 @@ package com.navercorp.pinpoint.web.cluster; -import com.navercorp.pinpoint.common.server.cluster.AgentInfoKey; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -38,19 +38,19 @@ public void test() throws Exception { CollectorClusterInfoRepository info = new CollectorClusterInfoRepository(); - final AgentInfoKey agent1 = new AgentInfoKey("app", "agent1", 0); - final AgentInfoKey agent2 = new AgentInfoKey("app", "agent2", 1); - final Set profilerInfos = Set.of(agent1, agent2); + final ClusterKey clusterKey1 = new ClusterKey("app", "agent1", 0); + final ClusterKey clusterKey2 = new ClusterKey("app", "agent2", 1); + final Set profilerInfos = Set.of(clusterKey1, clusterKey2); ClusterId clusterId = new ClusterId("/path", "/collectorA", "appName"); info.put(clusterId, profilerInfos); - List collectorList = info.get(agent1); + List collectorList = info.get(clusterKey1); logger.debug("{}", collectorList); Assertions.assertEquals(clusterId, collectorList.get(0)); info.remove(clusterId); - Assertions.assertTrue(info.get(agent1).isEmpty(), "Not found"); + Assertions.assertTrue(info.get(clusterKey1).isEmpty(), "Not found"); } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterTest.java b/web/src/test/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterTest.java index 0d6b1878889a..63b1b4b0e093 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/cluster/zookeeper/ZookeeperClusterTest.java @@ -16,6 +16,7 @@ package com.navercorp.pinpoint.web.cluster.zookeeper; +import com.navercorp.pinpoint.common.server.cluster.ClusterKey; import com.navercorp.pinpoint.common.server.cluster.zookeeper.ZookeeperConstants; import com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException; import com.navercorp.pinpoint.common.util.NetUtils; @@ -133,15 +134,15 @@ public void process(WatchedEvent event) { manager.start(); awaitClusterManagerConnected(manager); - awaitCheckAgentRegistered(manager, "a", "b", 1L); - List agentList = manager.getRegisteredAgentList("a", "b", 1L); + awaitCheckAgentRegistered(manager, new ClusterKey("a", "b", 1L)); + List agentList = manager.getRegisteredAgentList(new ClusterKey("a", "b", 1L)); Assertions.assertEquals(1, agentList.size()); Assertions.assertEquals("test", agentList.get(0).getCollectorId()); - agentList = manager.getRegisteredAgentList("b", "c", 1L); + agentList = manager.getRegisteredAgentList(new ClusterKey("b", "c", 1L)); Assertions.assertEquals(0, agentList.size()); zookeeper.setData(COLLECTOR_TEST_NODE_PATH, "".getBytes(), -1); - awaitCheckAgentUnRegistered(manager, "a", "b", 1L); + awaitCheckAgentUnRegistered(manager, new ClusterKey("a", "b", 1L)); } finally { closeZk(zookeeper); @@ -179,31 +180,31 @@ public void process(WatchedEvent watchedEvent) { manager.start(); awaitClusterManagerConnected(manager); - awaitCheckAgentRegistered(manager, "a", "b", 1L); - List agentList = manager.getRegisteredAgentList("a", "b", 1L); + awaitCheckAgentRegistered(manager, new ClusterKey("a", "b", 1L)); + List agentList = manager.getRegisteredAgentList(new ClusterKey("a", "b", 1L)); Assertions.assertEquals(1, agentList.size()); Assertions.assertEquals("test", agentList.get(0).getCollectorId()); zookeeper.setData(COLLECTOR_TEST_NODE_PATH, "a:b:1\r\nc:d:2".getBytes(), -1); - awaitCheckAgentRegistered(manager, "c", "d", 2L); + awaitCheckAgentRegistered(manager, new ClusterKey("c", "d", 2L)); - agentList = manager.getRegisteredAgentList("a", "b", 1L); + agentList = manager.getRegisteredAgentList(new ClusterKey("a", "b", 1L)); Assertions.assertEquals(1, agentList.size()); Assertions.assertEquals("test", agentList.get(0).getCollectorId()); - agentList = manager.getRegisteredAgentList("c", "d", 2L); + agentList = manager.getRegisteredAgentList(new ClusterKey("c", "d", 2L)); Assertions.assertEquals(1, agentList.size()); Assertions.assertEquals("test", agentList.get(0).getCollectorId()); zookeeper.delete(COLLECTOR_TEST_NODE_PATH, -1); Thread.sleep(10000); - awaitCheckAgentUnRegistered(manager, "a", "b", 1L); + awaitCheckAgentUnRegistered(manager, new ClusterKey("a", "b", 1L)); - agentList = manager.getRegisteredAgentList("a", "b", 1L); + agentList = manager.getRegisteredAgentList(new ClusterKey("a", "b", 1L)); Assertions.assertEquals(0, agentList.size()); - agentList = manager.getRegisteredAgentList("c", "d", 2L); + agentList = manager.getRegisteredAgentList(new ClusterKey("c", "d", 2L)); Assertions.assertEquals(0, agentList.size()); } finally { closeZk(zookeeper); @@ -216,18 +217,18 @@ private void awaitClusterManagerConnected(final ZookeeperClusterDataManager mana .until(manager::isConnected); } - private void awaitCheckAgentRegistered(final ZookeeperClusterDataManager manager, final String applicationName, final String agentId, final long startTimeStamp) { + private void awaitCheckAgentRegistered(final ZookeeperClusterDataManager manager, ClusterKey clusterKey) { awaitility() - .until(getRegisteredAgentList(manager, applicationName, agentId, startTimeStamp), not(IsEmptyCollection.empty())); + .until(getRegisteredAgentList(manager, clusterKey), not(IsEmptyCollection.empty())); } - private void awaitCheckAgentUnRegistered(final ZookeeperClusterDataManager manager, final String applicationName, final String agentId, final long startTimeStamp) { + private void awaitCheckAgentUnRegistered(final ZookeeperClusterDataManager manager, ClusterKey clusterKey) { awaitility() - .until(getRegisteredAgentList(manager, applicationName, agentId, startTimeStamp), IsEmptyCollection.empty()); + .until(getRegisteredAgentList(manager, clusterKey), IsEmptyCollection.empty()); } - private Callable> getRegisteredAgentList(ZookeeperClusterDataManager manager, String applicationName, String agentId, long startTimeStamp) { - return () -> manager.getRegisteredAgentList(applicationName, agentId, startTimeStamp); + private Callable> getRegisteredAgentList(ZookeeperClusterDataManager manager, ClusterKey clusterKey) { + return () -> manager.getRegisteredAgentList(clusterKey); } private static TestingServer createZookeeperServer(int port) throws Exception { From 827be6d60c0034ded8451d4b85b68307aa476438 Mon Sep 17 00:00:00 2001 From: emeroad Date: Tue, 19 Jul 2022 16:08:52 +0900 Subject: [PATCH 3/3] [#9023] AgentAndStatus --- .../batch/job/AgentCountProcessor.java | 8 +-- .../StatisticsServerInstanceListFactory.java | 6 +- ...AgentInfoServerInstanceListDataSource.java | 8 ++- .../applicationmap/nodes/ServerBuilder.java | 11 +-- .../applicationmap/nodes/ServerInstance.java | 16 +++-- .../nodes/ServerInstanceList.java | 14 ++-- .../controller/AgentInfoController.java | 3 +- .../pinpoint/web/cluster/ClusterKeyUtils.java | 9 +-- .../web/controller/MapController.java | 25 ++++--- .../web/service/AgentInfoAndStatus.java | 24 ------- .../web/service/AgentInfoService.java | 7 +- .../web/service/AgentInfoServiceImpl.java | 43 +++++------ .../web/service/AgentServiceImpl.java | 5 +- ...gentInfoAndLink.java => AgentAndLink.java} | 4 +- ...InfoAndStatus.java => AgentAndStatus.java} | 11 ++- .../navercorp/pinpoint/web/vo/AgentInfo.java | 9 --- .../pinpoint/web/vo/AgentInfoFilter.java | 10 +-- .../pinpoint/web/vo/AgentInfoFilterChain.java | 4 +- .../pinpoint/web/vo/ApplicationAgentList.java | 8 +-- .../web/vo/ApplicationAgentsList.java | 60 +++++++++------- .../web/vo/DefaultAgentInfoFilter.java | 4 +- .../ApplicationMapBuilderTest.java | 16 ++--- .../ServerInstanceListTest.java | 11 +-- .../dao/hbase/HbaseAgentLifeCycleDaoTest.java | 15 ++-- .../ServerInstanceListSerializerTest.java | 10 +-- .../web/vo/AgentInfoFilterChainTest.java | 17 ++--- .../web/vo/ApplicationAgentsListTest.java | 72 +++++++++---------- 27 files changed, 211 insertions(+), 219 deletions(-) delete mode 100644 web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoAndStatus.java rename web/src/main/java/com/navercorp/pinpoint/web/vo/{AgentInfoAndLink.java => AgentAndLink.java} (88%) rename web/src/main/java/com/navercorp/pinpoint/web/vo/{AgentInfoAndStatus.java => AgentAndStatus.java} (62%) 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); } }