Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9023] Refactor ApplicationAgentList #9060

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public AgentCountStatistics process(ApplicationAgentsList item) throws Exception

private int getAgentCount(List<ApplicationAgentList> applicationAgentLists) {
return applicationAgentLists.stream()
.mapToInt(applicationAgentList -> applicationAgentList.getAgentInfos().size())
.mapToInt(applicationAgentList -> applicationAgentList.getAgentStatusAndLinks().size())
.sum();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void serialize(ApplicationAgentsList applicationAgentsList, JsonGenerator
List<ApplicationAgentList> applicationAgentLists = applicationAgentsList.getApplicationAgentLists();
for (ApplicationAgentList applicationAgentList : applicationAgentLists) {
jgen.writeFieldName(applicationAgentList.getGroupName());
jgen.writeObject(applicationAgentList.getAgentInfoAndLinks());
jgen.writeObject(applicationAgentList.getAgentStatusAndLinks());
}
jgen.writeEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.navercorp.pinpoint.web.hyperlink.HyperLink;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

public class AgentAndLink {
public class AgentStatusAndLink {
private final AgentInfo agentInfo;
private final AgentStatus agentStatus;
private final List<HyperLink> hyperLinkList;

public AgentAndLink(AgentInfo agentInfo, List<HyperLink> hyperLinkList) {
public AgentStatusAndLink(AgentInfo agentInfo, @Nullable AgentStatus agentStatus, List<HyperLink> hyperLinkList) {
this.agentInfo = Objects.requireNonNull(agentInfo, "agentInfo");
this.agentStatus = agentStatus;
this.hyperLinkList = Objects.requireNonNull(hyperLinkList, "hyperLinkList");
}

Expand All @@ -21,15 +24,20 @@ public AgentInfo getAgentInfo() {
return agentInfo;
}

public AgentStatus getStatus() {
return agentStatus;
}

@JsonProperty("linkList")
public List<HyperLink> getHyperLinkList() {
return hyperLinkList;
}

@Override
public String toString() {
return "AgentInfoAndLink{" +
return "AgentStatusAndLink{" +
"agentInfo=" + agentInfo +
", agentStatus=" + agentStatus +
", hyperLinkList=" + hyperLinkList +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* @author HyunGil Jeong
*/
public class ApplicationAgentList {

private final String groupName;
private final List<AgentAndLink> agentInfoAndLinkList;
private final List<AgentStatusAndLink> agentInfoAndLinkList;

public ApplicationAgentList(String groupName, List<AgentAndLink> agentInfoAndLinkList) {
public ApplicationAgentList(String groupName, List<AgentStatusAndLink> agentInfoAndLinkList) {
this.groupName = Objects.requireNonNull(groupName, "groupName");
this.agentInfoAndLinkList = Objects.requireNonNull(agentInfoAndLinkList, "agentInfoAndLinkList");
}
Expand All @@ -37,13 +36,7 @@ public String getGroupName() {
return groupName;
}

public List<AgentInfo> getAgentInfos() {
return agentInfoAndLinkList.stream()
.map(AgentAndLink::getAgentInfo)
.collect(Collectors.toList());
}

public List<AgentAndLink> getAgentInfoAndLinks() {
public List<AgentStatusAndLink> getAgentStatusAndLinks() {
return agentInfoAndLinkList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public List<ApplicationAgentList> getApplicationAgentLists() {
List<AgentAndStatus> applicationAgents = new ArrayList<>(agentInfoList);
applicationAgents.sort(groupBy.getComparator());

List<AgentAndLink> agentInfoAndLinks = applicationAgents.stream()
.map(AgentAndStatus::getAgentInfo)
List<AgentStatusAndLink> agentInfoAndLinks = applicationAgents.stream()
.map(this::newAgentInfoAndLink)
.collect(Collectors.toList());

Expand All @@ -154,9 +153,11 @@ public List<ApplicationAgentList> getApplicationAgentLists() {
return applicationAgentLists;
}

private AgentAndLink newAgentInfoAndLink(AgentInfo agentInfo) {
private AgentStatusAndLink newAgentInfoAndLink(AgentAndStatus agentAndStatus) {
AgentInfo agentInfo = agentAndStatus.getAgentInfo();
AgentStatus status = agentAndStatus.getStatus();
List<HyperLink> hyperLinks = hyperLinkFactory.build(LinkSources.from(agentInfo));
return new AgentAndLink(agentInfo, hyperLinks);
return new AgentStatusAndLink(agentInfo, status, hyperLinks);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public void groupByApplicationName() {

ApplicationAgentList app1AgentList = applicationAgentLists.get(0);
Assertions.assertEquals("APP_1", app1AgentList.getGroupName());
List<AgentInfo> app1AgentInfos = app1AgentList.getAgentInfos();
List<AgentStatusAndLink> app1AgentInfos = app1AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(2, app1AgentInfos.size());
Assertions.assertEquals(app1Agent1.getAgentInfo(), app1AgentInfos.get(0));
Assertions.assertEquals(app1Agent2.getAgentInfo(), app1AgentInfos.get(1));
Assertions.assertEquals(app1Agent1.getAgentInfo(), app1AgentInfos.get(0).getAgentInfo());
Assertions.assertEquals(app1Agent2.getAgentInfo(), app1AgentInfos.get(1).getAgentInfo());

ApplicationAgentList app2AgentList = applicationAgentLists.get(1);
Assertions.assertEquals("APP_2", app2AgentList.getGroupName());
List<AgentInfo> app2AgentInfos = app2AgentList.getAgentInfos();
List<AgentStatusAndLink> app2AgentInfos = app2AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(2, app2AgentInfos.size());
Assertions.assertEquals(app2Agent1.getAgentInfo(), app2AgentInfos.get(0));
Assertions.assertEquals(app2Agent2.getAgentInfo(), app2AgentInfos.get(1));
Assertions.assertEquals(app2Agent1.getAgentInfo(), app2AgentInfos.get(0).getAgentInfo());
Assertions.assertEquals(app2Agent2.getAgentInfo(), app2AgentInfos.get(1).getAgentInfo());
}

@Test
Expand All @@ -74,22 +74,22 @@ public void groupByHostNameShouldHaveContainersFirstAndGroupedSeparatelyByAgentS

ApplicationAgentList containerAgentList = applicationAgentLists.get(0);
Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName());
List<AgentInfo> containerAgents = containerAgentList.getAgentInfos();
List<AgentStatusAndLink> containerAgents = containerAgentList.getAgentStatusAndLinks();
Assertions.assertEquals(2, containerAgents.size());
Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0));
Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1));
Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0).getAgentInfo());
Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1).getAgentInfo());

ApplicationAgentList host1AgentList = applicationAgentLists.get(1);
Assertions.assertEquals("Host1", host1AgentList.getGroupName());
List<AgentInfo> host1Agents = host1AgentList.getAgentInfos();
List<AgentStatusAndLink> host1Agents = host1AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host1Agents.size());
Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0));
Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0).getAgentInfo());

ApplicationAgentList host2AgentList = applicationAgentLists.get(2);
Assertions.assertEquals("Host2", host2AgentList.getGroupName());
List<AgentInfo> host2Agents = host2AgentList.getAgentInfos();
List<AgentStatusAndLink> host2Agents = host2AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host2Agents.size());
Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0));
Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0).getAgentInfo());
}

@Test
Expand All @@ -112,22 +112,22 @@ public void mergeLists() {

ApplicationAgentList containerAgentList = applicationAgentLists.get(0);
Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName());
List<AgentInfo> containerAgents = containerAgentList.getAgentInfos();
List<AgentStatusAndLink> containerAgents = containerAgentList.getAgentStatusAndLinks();
Assertions.assertEquals(2, containerAgents.size());
Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0));
Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1));
Assertions.assertEquals(containerAgent2.getAgentInfo(), containerAgents.get(0).getAgentInfo());
Assertions.assertEquals(containerAgent1.getAgentInfo(), containerAgents.get(1).getAgentInfo());

ApplicationAgentList host1AgentList = applicationAgentLists.get(1);
Assertions.assertEquals("Host1", host1AgentList.getGroupName());
List<AgentInfo> host1Agents = host1AgentList.getAgentInfos();
List<AgentStatusAndLink> host1Agents = host1AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host1Agents.size());
Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0));
Assertions.assertEquals(host1Agent1.getAgentInfo(), host1Agents.get(0).getAgentInfo());

ApplicationAgentList host2AgentList = applicationAgentLists.get(2);
Assertions.assertEquals("Host2", host2AgentList.getGroupName());
List<AgentInfo> host2Agents = host2AgentList.getAgentInfos();
List<AgentStatusAndLink> host2Agents = host2AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host2Agents.size());
Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0));
Assertions.assertEquals(host2Agent1.getAgentInfo(), host2Agents.get(0).getAgentInfo());
}

@Test
Expand All @@ -148,21 +148,21 @@ public void mergeListsGroupedDifferently() {

ApplicationAgentList containerAgentList = applicationAgentLists.get(0);
Assertions.assertEquals(ApplicationAgentsList.HostNameContainerGroupingKey.CONTAINER, containerAgentList.getGroupName());
List<AgentInfo> containerAgents = containerAgentList.getAgentInfos();
List<AgentStatusAndLink> containerAgents = containerAgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, containerAgents.size());
Assertions.assertEquals(agent3.getAgentInfo(), containerAgents.get(0));
Assertions.assertEquals(agent3.getAgentInfo(), containerAgents.get(0).getAgentInfo());

ApplicationAgentList host1AgentList = applicationAgentLists.get(1);
Assertions.assertEquals("Host1", host1AgentList.getGroupName());
List<AgentInfo> host1Agents = host1AgentList.getAgentInfos();
List<AgentStatusAndLink> host1Agents = host1AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host1Agents.size());
Assertions.assertEquals(agent1.getAgentInfo(), host1Agents.get(0));
Assertions.assertEquals(agent1.getAgentInfo(), host1Agents.get(0).getAgentInfo());

ApplicationAgentList host2AgentList = applicationAgentLists.get(2);
Assertions.assertEquals("Host2", host2AgentList.getGroupName());
List<AgentInfo> host2Agents = host2AgentList.getAgentInfos();
List<AgentStatusAndLink> host2Agents = host2AgentList.getAgentStatusAndLinks();
Assertions.assertEquals(1, host2Agents.size());
Assertions.assertEquals(agent2.getAgentInfo(), host2Agents.get(0));
Assertions.assertEquals(agent2.getAgentInfo(), host2Agents.get(0).getAgentInfo());
}

private static List<AgentAndStatus> shuffleAgentInfos(AgentAndStatus... agentInfos) {
Expand Down