Skip to content

Commit dfb7f85

Browse files
committed
[pinpoint-apm#9037] Refactor ClusterKey
1 parent 0a80254 commit dfb7f85

File tree

12 files changed

+49
-158
lines changed

12 files changed

+49
-158
lines changed

commons-server/src/main/java/com/navercorp/pinpoint/common/server/dao/hbase/mapper/AgentInfoBoMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ public AgentInfoBo mapRow(Result result, int rowNum) throws Exception {
4545
long reverseStartTime = BytesUtils.bytesToLong(rowKey, HbaseTableConstants.AGENT_ID_MAX_LEN);
4646
long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime);
4747

48-
byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER);
49-
byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA);
50-
byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM);
51-
48+
final byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER);
5249
final AgentInfoBo.Builder agentInfoBoBuilder = createBuilderFromValue(serializedAgentInfo);
5350
agentInfoBoBuilder.setAgentId(agentId);
5451
agentInfoBoBuilder.setStartTime(startTime);
5552

53+
final byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA);
5654
if (serializedServerMetaData != null) {
5755
agentInfoBoBuilder.setServerMetaData(new ServerMetaDataBo.Builder(serializedServerMetaData).build());
5856
}
57+
58+
final byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM);
5959
if (serializedJvmInfo != null) {
6060
agentInfoBoBuilder.setJvmInfo(new JvmInfoBo(serializedJvmInfo));
6161
}

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616

1717
package com.navercorp.pinpoint.web.applicationmap.nodes;
1818

19-
import java.util.*;
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.TreeMap;
24+
import java.util.stream.Collectors;
2025

2126
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2227
import com.navercorp.pinpoint.web.view.ServerInstanceListSerializer;
@@ -41,35 +46,25 @@ public Map<String, List<ServerInstance>> getServerInstanceList() {
4146
}
4247

4348
public List<String> getAgentIdList() {
44-
final Collection<List<ServerInstance>> serverInstanceValueList = this.serverInstanceList.values();
45-
46-
final List<String> agentList = new ArrayList<>();
47-
for (List<ServerInstance> serverInstanceList : serverInstanceValueList) {
48-
for (ServerInstance serverInstance : serverInstanceList) {
49-
agentList.add(serverInstance.getName());
50-
}
51-
}
52-
return agentList;
49+
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
50+
return serverList.stream()
51+
.flatMap(List::stream)
52+
.map(ServerInstance::getName)
53+
.collect(Collectors.toList());
5354
}
5455

5556
public Map<String, String> getAgentIdNameMap() {
56-
final Collection<List<ServerInstance>> serverInstanceValueList = this.serverInstanceList.values();
57-
58-
final Map<String, String> map = new HashMap<>();
59-
for (List<ServerInstance> serverInstanceList : serverInstanceValueList) {
60-
for (ServerInstance serverInstance : serverInstanceList) {
61-
map.put(serverInstance.getName(), serverInstance.getAgentName());
62-
}
63-
}
64-
return map;
57+
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
58+
return serverList.stream()
59+
.flatMap(List::stream)
60+
.collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName));
6561
}
6662

6763
public int getInstanceCount() {
68-
int count = 0;
69-
for (List<ServerInstance> entry : serverInstanceList.values()) {
70-
count += entry.size();
71-
}
72-
return count;
64+
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
65+
return serverList.stream()
66+
.mapToInt(List::size)
67+
.sum();
7368
}
7469

7570
private void addServerInstance(List<ServerInstance> nodeList, ServerInstance serverInstance) {

web/src/main/java/com/navercorp/pinpoint/web/dao/AgentInfoDao.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
*/
2727
public interface AgentInfoDao {
2828

29-
AgentInfo getInitialAgentInfo(String agentId);
30-
31-
List<AgentInfo> getInitialAgentInfos(List<String> agentIds);
32-
3329
AgentInfo getAgentInfo(String agentId, long timestamp);
3430

3531
AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTimeInMilliSeconds);

web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,45 +62,6 @@ public HbaseAgentInfoDao(HbaseOperations2 hbaseOperations2,
6262
this.agentInfoResultsExtractor = Objects.requireNonNull(agentInfoResultsExtractor, "agentInfoResultsExtractor");
6363
}
6464

65-
/**
66-
* Returns the very first information of the agent
67-
*
68-
* @param agentId
69-
*/
70-
@Override
71-
public AgentInfo getInitialAgentInfo(final String agentId) {
72-
Objects.requireNonNull(agentId, "agentId");
73-
74-
Scan scan = createScanForInitialAgentInfo(agentId);
75-
76-
TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
77-
return this.hbaseOperations2.find(agentInfoTableName, scan, agentInfoResultsExtractor);
78-
}
79-
80-
@Override
81-
public List<AgentInfo> getInitialAgentInfos(List<String> agentIds) {
82-
if (CollectionUtils.isEmpty(agentIds)) {
83-
return Collections.emptyList();
84-
}
85-
List<Scan> scans = new ArrayList<>(agentIds.size());
86-
for (String agentId : agentIds) {
87-
scans.add(createScanForInitialAgentInfo(agentId));
88-
}
89-
90-
TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
91-
return this.hbaseOperations2.find(agentInfoTableName, scans, agentInfoResultsExtractor);
92-
}
93-
94-
private Scan createScanForInitialAgentInfo(String agentId) {
95-
Scan scan = new Scan();
96-
97-
byte[] reverseStartKey = RowKeyUtils.agentIdAndTimestamp(agentId, Long.MAX_VALUE);
98-
scan.withStartRow(reverseStartKey);
99-
scan.setReversed(true);
100-
scan.setMaxVersions(1);
101-
scan.setCaching(SCANNER_CACHING);
102-
return scan;
103-
}
10465

10566
/**
10667
* Returns the information of the agent with its start time closest to the given timestamp

web/src/main/java/com/navercorp/pinpoint/web/hyperlink/DefaultLinkSource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.navercorp.pinpoint.web.hyperlink;
22

33

4+
import javax.annotation.Nullable;
5+
46
public class DefaultLinkSource implements LinkSource {
57
private final String hostName;
68
private final String ip;
79

810

9-
public DefaultLinkSource(String hostName, String ip) {
11+
public DefaultLinkSource(String hostName, @Nullable String ip) {
1012
this.hostName = hostName;
1113
this.ip = ip;
1214
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public interface AgentInfoService {
5151

5252
AgentInfo getAgentInfo(String agentId, long timestamp);
5353

54-
AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds);
54+
AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp);
55+
56+
AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds);
5557

5658
AgentStatus getAgentStatus(String agentId, long timestamp);
5759

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,7 @@ public Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, l
278278

279279
@Override
280280
public AgentInfo getAgentInfo(String agentId, long timestamp) {
281-
Objects.requireNonNull(agentId, "agentId");
282-
283-
if (timestamp < 0) {
284-
throw new IllegalArgumentException("timestamp must not be less than 0");
285-
}
286-
AgentInfo agentInfo = this.agentInfoDao.getAgentInfo(agentId, timestamp);
281+
AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp);
287282
if (agentInfo != null) {
288283
Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
289284
agentInfo.setStatus(agentStatus.orElse(null));
@@ -292,7 +287,17 @@ public AgentInfo getAgentInfo(String agentId, long timestamp) {
292287
}
293288

294289
@Override
295-
public AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) {
290+
public AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp) {
291+
Objects.requireNonNull(agentId, "agentId");
292+
293+
if (timestamp < 0) {
294+
throw new IllegalArgumentException("timestamp must not be less than 0");
295+
}
296+
return this.agentInfoDao.getAgentInfo(agentId, timestamp);
297+
}
298+
299+
@Override
300+
public AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) {
296301
return this.agentInfoDao.getAgentInfo(agentId, agentStartTime, deltaTimeInMilliSeconds);
297302
}
298303

@@ -348,7 +353,7 @@ public InspectorTimeline getAgentStatusTimeline(String agentId, Range range, int
348353

349354
@Override
350355
public boolean isExistAgentId(String agentId) {
351-
AgentInfo agentInfo = getAgentInfo(agentId, System.currentTimeMillis());
356+
AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, System.currentTimeMillis());
352357
return agentInfo != null;
353358
}
354359

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private SpanResult order(List<SpanBo> spans, Predicate<SpanBo> filter, boolean i
506506

507507
private Optional<String> getAgentName(String agentId, long agentStartTime) {
508508
final int deltaTimeInMilli = 1000;
509-
final AgentInfo agentInfo = this.agentInfoService.getAgentInfoNoStatus(agentId, agentStartTime, deltaTimeInMilli);
509+
final AgentInfo agentInfo = this.agentInfoService.getAgentInfoWithoutStatus(agentId, agentStartTime, deltaTimeInMilli);
510510
return agentInfo == null ? Optional.empty() : Optional.ofNullable(agentInfo.getAgentName());
511511
}
512512
}

web/src/main/java/com/navercorp/pinpoint/web/view/AgentInfoSerializer.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

web/src/main/java/com/navercorp/pinpoint/web/view/NodeSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
public class NodeSerializer extends JsonSerializer<Node> {
4343

4444
@Override
45-
public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
45+
public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException {
4646
jgen.writeStartObject();
4747
// jgen.writeStringField("id", node.getNodeName());serverInstanceList
4848
jgen.writeStringField("key", node.getNodeName()); // necessary for go.js

web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public class AgentInfo {
4747
private String agentVersion;
4848
private ServerMetaDataBo serverMetaData;
4949
private JvmInfoBo jvmInfo;
50-
private long initialStartTimestamp;
5150
private boolean container;
5251
private AgentStatus status;
5352

@@ -163,10 +162,6 @@ public void setJvmInfo(JvmInfoBo jvmInfo) {
163162
this.jvmInfo = jvmInfo;
164163
}
165164

166-
public long getInitialStartTimestamp() {
167-
return initialStartTimestamp;
168-
}
169-
170165

171166
public boolean isContainer() {
172167
return container;
@@ -221,7 +216,6 @@ public String toString() {
221216
sb.append(", agentVersion='").append(agentVersion).append('\'');
222217
sb.append(", serverMetaData='").append(serverMetaData).append('\'');
223218
sb.append(", jvmInfo=").append(jvmInfo);
224-
sb.append(", initialStartTimestamp=").append(initialStartTimestamp);
225219
sb.append(", container=").append(container);
226220
sb.append(", status=").append(status);
227221
sb.append('}');

web/src/test/java/com/navercorp/pinpoint/web/cluster/CollectorClusterInfoRepositoryTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ public void test() throws Exception {
3838

3939
CollectorClusterInfoRepository info = new CollectorClusterInfoRepository();
4040

41-
final ClusterKey agent1 = new ClusterKey("app", "agent1", 0);
42-
final ClusterKey agent2 = new ClusterKey("app", "agent2", 1);
43-
final Set<ClusterKey> profilerInfos = Set.of(agent1, agent2);
41+
final ClusterKey clusterKey1 = new ClusterKey("app", "agent1", 0);
42+
final ClusterKey clusterKey2 = new ClusterKey("app", "agent2", 1);
43+
final Set<ClusterKey> profilerInfos = Set.of(clusterKey1, clusterKey2);
4444

4545
ClusterId clusterId = new ClusterId("/path", "/collectorA", "appName");
4646
info.put(clusterId, profilerInfos);
4747

48-
List<ClusterId> collectorList = info.get(agent1);
48+
List<ClusterId> collectorList = info.get(clusterKey1);
4949
logger.debug("{}", collectorList);
5050
Assertions.assertEquals(clusterId, collectorList.get(0));
5151

5252
info.remove(clusterId);
53-
Assertions.assertTrue(info.get(agent1).isEmpty(), "Not found");
53+
Assertions.assertTrue(info.get(clusterKey1).isEmpty(), "Not found");
5454
}
5555

5656

0 commit comments

Comments
 (0)