Skip to content

Commit

Permalink
[#9023] Refactor HyperLink
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jul 20, 2022
1 parent ca19baa commit 5db7c89
Show file tree
Hide file tree
Showing 34 changed files with 763 additions and 515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,12 +41,16 @@ public class ServerBuilder {

private final Logger logger = LogManager.getLogger(this.getClass());

private final AgentHistogramList agentHistogramList;
private final Set<AgentInfo> agentSet;
private final AgentHistogramList agentHistogramList = new AgentHistogramList();
private final Set<AgentInfo> 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) {
Expand Down Expand Up @@ -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;
Expand All @@ -96,13 +105,29 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog
public ServerInstanceList buildPhysicalServer(final Set<AgentInfo> 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<HyperLink> buildHyperLink(AgentInfo agentInfo) {
if (hyperLinkFactory != null) {
return hyperLinkFactory.build(LinkSources.from(agentInfo));
} else {
return Collections.emptyList();
}
}

private List<HyperLink> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -45,7 +48,9 @@ public class ServerInstance {

private final AgentLifeCycleState status;

public ServerInstance(AgentInfo agentInfo) {
private final List<HyperLink> linkList;

public ServerInstance(AgentInfo agentInfo, List<HyperLink> linkList) {
Objects.requireNonNull(agentInfo, "agentInfo");

this.hostName = agentInfo.getHostName();
Expand All @@ -60,16 +65,18 @@ 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<HyperLink> linkList) {
this.hostName = Objects.requireNonNull(hostName, "hostName");
this.ip = null;
this.agentName = null;
this.name = Objects.requireNonNull(physicalName, "physicalName");
this.serviceType = Objects.requireNonNull(serviceType, "serviceType");
this.status = AgentLifeCycleState.UNKNOWN;
this.serverType = ServerType.Logical;
this.linkList = Objects.requireNonNull(linkList, "linkList");
}

public String getHostName() {
Expand All @@ -88,6 +95,7 @@ public short getServiceTypeCode() {
return serviceType.getCode();
}

@JsonIgnore
public ServiceType getServiceType() {
return serviceType;
}
Expand All @@ -104,6 +112,10 @@ public String getIp() {
return ip;
}

public List<HyperLink> getLinkList() {
return linkList;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<[email protected]>
*
*/
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<[email protected]>
*
*/
public class EmptyLinkMatcher implements ServerMatcher {

@Override
public boolean isMatched(String value) {
return true;
}

@Override
public HyperLink getLinkInfo(String value) {
return new HyperLink("", "", LinkType.ATAG);
}

}
Loading

0 comments on commit 5db7c89

Please sign in to comment.