diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/Application.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/Application.java index eb123ee5f..2e8878942 100644 --- a/src/main/java/com/nhn/pinpoint/web/applicationmap/Application.java +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/Application.java @@ -1,11 +1,14 @@ package com.nhn.pinpoint.web.applicationmap; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import com.nhn.pinpoint.common.ServiceType; import com.nhn.pinpoint.common.bo.AgentInfoBo; @@ -21,9 +24,12 @@ public class Application implements Comparable { protected final String applicationName; protected final ServiceType serviceType; protected final Map hostList; - protected final Set agentSet; - public Application(String id, String applicationName, ServiceType serviceType, Map hostList, Set agentSet) { + protected final Map> serverInstanceList = new TreeMap>(); + + protected final Map> agentList = new TreeMap>(); + + public Application(String id, String applicationName, ServiceType serviceType, Map serverList, Set agentSet) { this.id = id; if (serviceType == ServiceType.CLIENT) { this.applicationName = "CLIENT"; @@ -31,9 +37,75 @@ public class Application implements Comparable { this.applicationName = applicationName; } - this.hostList = (hostList == null) ? new HashMap() : hostList; - this.agentSet = agentSet; + this.hostList = (serverList == null) ? new HashMap() : serverList; this.serviceType = serviceType; + + fillAgentList(agentSet); + fillServerInstanceList(agentSet, hostList); + +// System.out.println(""); +// System.out.println("----------------------------------"); +// System.out.println("applicationName=" + applicationName); +// System.out.println("SERVERLIST=" + serverList); +// System.out.println("AGENTSET=" + agentSet); +// System.out.println("HOSTLIST=" + hostList); +// System.out.println("serverInstanceList=" + serverInstanceList); +// System.out.println(""); + } + + public Map> getServerInstanceList() { + return serverInstanceList; + } + + private void fillAgentList(final Set agentSet) { + if (agentSet == null) { + return; + } + for (AgentInfoBo agent : agentSet) { + String key = agent.getHostname(); + List list = agentList.get(key); + + if (list == null) { + List value = new ArrayList(); + value.add(agent); + agentList.put(key, value); + } else { + agentList.get(key).add(agent); + } + } + } + + private void fillServerInstanceList(final Set agentSet, final Map agentHistogram) { + if (agentSet == null) { + return; + } + for (AgentInfoBo agent : agentSet) { + String key = agent.getHostname(); + SortedMap serverInstanceMap = serverInstanceList.get(key); + + ResponseHistogram histogram = null; + if (agentHistogram != null) { + Host host = agentHistogram.get(agent.getAgentId()); + if (host != null) { + histogram = host.getHistogram(); + } + } + + ServerInstance serverInstance = new ServerInstance(agent, histogram); + + if (serverInstanceMap == null) { + SortedMap value = new TreeMap(); + value.put(serverInstance.getId(), serverInstance); + serverInstanceList.put(key, value); + } else { + SortedMap map = serverInstanceList.get(key); + if (map.containsKey(serverInstance.getId())) { + map.get(serverInstance.getId()).mergeWith(serverInstance); + } else { + map.put(key, serverInstance); + } + } + } } public String getId() { @@ -60,7 +132,12 @@ public class Application implements Comparable { return hostList; } + public Map> getAgentList() { + return agentList; + } + public void mergeWith(Application application) { + // merge host list for (Entry entry : application.getHostList().entrySet()) { Host host = hostList.get(entry.getKey()); if (host != null) { @@ -69,15 +146,29 @@ public class Application implements Comparable { hostList.put(entry.getKey(), entry.getValue()); } } + + // merge server instance list + for (Entry> entry : application.getServerInstanceList().entrySet()) { + SortedMap exists = serverInstanceList.get(entry.getKey()); + + if (exists == null) { + serverInstanceList.put(entry.getKey(), entry.getValue()); + } else { + SortedMap srcValueMap = entry.getValue(); + for (Entry valueEntry : srcValueMap.entrySet()) { + if (exists.containsKey(valueEntry.getKey())) { + exists.get(entry.getKey()).mergeWith(valueEntry.getValue()); + } else { + exists.put(valueEntry.getKey(), valueEntry.getValue()); + } + } + } + } } public ServiceType getServiceType() { return serviceType; } - - public Set getAgentSet() { - return agentSet; - } public String getJson() { StringBuilder sb = new StringBuilder(); @@ -86,18 +177,30 @@ public class Application implements Comparable { sb.append("\"sequence\" : ").append(sequence).append(","); sb.append("\"applicationName\" : \"").append(applicationName).append("\","); sb.append("\"serviceType\" : \"").append(serviceType).append("\","); - sb.append("\"serviceTypeCode\" : \"").append(serviceType.getCode()).append("\","); - sb.append("\"agents\" : [ "); - if (agentSet != null) { - Iterator iterator = agentSet.iterator(); - while (iterator.hasNext()) { - sb.append(iterator.next().getJson()); - if (iterator.hasNext()) { - sb.append(","); - } - } - } - sb.append(" ]"); + sb.append("\"serviceTypeCode\" : \"").append(serviceType.getCode()).append("\""); + // sb.append("\"agents\" : [ "); + // if (agentList != null) { + // Iterator>> iterator = + // agentList.entrySet().iterator(); + // while (iterator.hasNext()) { + // Entry> entry = iterator.next(); + // sb.append("{ \"host\":\"").append(entry.getKey()).append("\", \"agentList\":["); + // + // Iterator agentIterator = entry.getValue().iterator(); + // while(agentIterator.hasNext()) { + // sb.append(agentIterator.next().getJson()); + // if (agentIterator.hasNext()) { + // sb.append(","); + // } + // } + // + // sb.append("]}"); + // if (iterator.hasNext()) { + // sb.append(","); + // } + // } + // } + // sb.append(" ]"); sb.append(" }"); return sb.toString(); diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/ApplicationMap.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/ApplicationMap.java index 0580f9b65..f2a8db27c 100644 --- a/src/main/java/com/nhn/pinpoint/web/applicationmap/ApplicationMap.java +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/ApplicationMap.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/Host.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/Host.java index 489c5526c..b2be54b30 100644 --- a/src/main/java/com/nhn/pinpoint/web/applicationmap/Host.java +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/Host.java @@ -1,10 +1,8 @@ package com.nhn.pinpoint.web.applicationmap; import com.nhn.pinpoint.common.ServiceType; -import com.nhn.pinpoint.common.bo.AgentInfoBo; /** - * application의 host정보. * * @author netspider * @@ -14,45 +12,45 @@ public class Host { * UI에서 호스트를 구분하기 위한 목적으로 hostname, agentid, endpoint등 구분할 수 있는 아무거나 넣으면 됨. */ private final String host; - private final AgentInfoBo agentInfo; private final ResponseHistogram histogram; - public Host(String host, ServiceType serviceType, AgentInfoBo agentInfo) { + public Host(String host, ServiceType serviceType) { this.host = host; this.histogram = new ResponseHistogram(serviceType); - this.agentInfo = agentInfo; } public String getHost() { return host; } - public AgentInfoBo getAgentInfo() { - return agentInfo; - } - public ResponseHistogram getHistogram() { return histogram; } public void mergeWith(Host host) { - this.histogram.mergeWith(host.getHistogram()); + this.histogram.mergeWith(host.histogram); } public String getJson() { StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("\"name\":\"").append(host).append("\","); - if (agentInfo != null) { - sb.append("\"agentInfo\":").append(agentInfo.getJson()).append(","); - } else { - sb.append("\"agentInfo\":").append("null").append(","); - } - // sb.append("\"callCount\":").append(histogram.getTotalCount()).append(","); - // sb.append("\"error\":").append(histogram.getErrorCount()).append(","); - // sb.append("\"slow\":").append(histogram.getSlowCount()).append(","); - sb.append("\"histogram\":").append(histogram); + sb.append("\"histogram\":").append(histogram); // .append(","); + // sb.append("\"agentList\":["); + // Iterator iterator = agentList.iterator(); + // while (iterator.hasNext()) { + // AgentInfoBo agent = iterator.next(); + // sb.append(agent.getJson()); + // if (iterator.hasNext()) { + // sb.append(","); + // } + // } sb.append("}"); return sb.toString(); } + + @Override + public String toString() { + return "Host [host=" + host + ", histogram=" + histogram + "]"; + } } diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/ResponseHistogram.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/ResponseHistogram.java index 562599261..f5df3895d 100644 --- a/src/main/java/com/nhn/pinpoint/web/applicationmap/ResponseHistogram.java +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/ResponseHistogram.java @@ -110,6 +110,7 @@ public class ResponseHistogram { return true; } + // FIXME 나중에 getJson()으로 바꾸기. @Override public String toString() { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/ServerInstance.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/ServerInstance.java new file mode 100644 index 000000000..47511ca3d --- /dev/null +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/ServerInstance.java @@ -0,0 +1,86 @@ +package com.nhn.pinpoint.web.applicationmap; + +import com.nhn.pinpoint.common.bo.AgentInfoBo; + +/** + * + * @author netspider + * + */ +public class ServerInstance implements Comparable { + + private final String id; + private final AgentInfoBo agentInfo; + private final ResponseHistogram histogram; + + public ServerInstance(AgentInfoBo agentInfo, ResponseHistogram histogram) { + this.id = agentInfo.getAgentId(); + this.agentInfo = agentInfo; + this.histogram = histogram; + } + + public String getId() { + return this.id; + } + + public AgentInfoBo getAgentInfo() { + return agentInfo; + } + + public ResponseHistogram getHistogram() { + return histogram; + } + + public String getJson() { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + sb.append("\"agentId\":\"").append(id).append("\","); + sb.append("\"agentInfo\":").append(agentInfo.getJson()).append(","); + sb.append("\"histogram\":").append(histogram); + sb.append("}"); + return sb.toString(); + } + + public ServerInstance mergeWith(ServerInstance serverInstance) { + if (this.id.equals(serverInstance.getId())) { + throw new IllegalArgumentException("Server instance id is not equal."); + } + this.histogram.mergeWith(serverInstance.getHistogram()); + return this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServerInstance other = (ServerInstance) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public String toString() { + return "ServerInstance [id=" + id + ", agentInfo=" + agentInfo + ", histogram=" + histogram + "]"; + } + + @Override + public int compareTo(ServerInstance serverInstance) { + return this.id.compareTo(serverInstance.id); + } +} diff --git a/src/main/java/com/nhn/pinpoint/web/applicationmap/TransactionFlowStatistics.java b/src/main/java/com/nhn/pinpoint/web/applicationmap/TransactionFlowStatistics.java index 99a456cf8..9e964eb3b 100644 --- a/src/main/java/com/nhn/pinpoint/web/applicationmap/TransactionFlowStatistics.java +++ b/src/main/java/com/nhn/pinpoint/web/applicationmap/TransactionFlowStatistics.java @@ -44,7 +44,7 @@ public class TransactionFlowStatistics { if (toHostList.containsKey(hostname)) { toHostList.get(hostname).getHistogram().addSample(slot, value); } else { - Host host = new Host(hostname, ServiceType.findServiceType(serviceTypeCode), null); + Host host = new Host(hostname, ServiceType.findServiceType(serviceTypeCode)); host.getHistogram().addSample(slot, value); toHostList.put(hostname, host); } diff --git a/src/main/webapp/WEB-INF/views/applicationmap.jsp b/src/main/webapp/WEB-INF/views/applicationmap.jsp index 16127d634..af3217e8d 100644 --- a/src/main/webapp/WEB-INF/views/applicationmap.jsp +++ b/src/main/webapp/WEB-INF/views/applicationmap.jsp @@ -15,8 +15,7 @@ "fig" : "RoundedRectangle" "fig" : "Rectangle" , - - "hosts" : [ + "histogram" : [ ${host.value.json} , @@ -24,13 +23,20 @@ ], "serviceTypeCode" : "${node.serviceType.code}", "terminal" : "${node.serviceType.terminal}", - "agents" : [ - - ${agent.json} - , - - ], - "histogram" : {} + "serverlist" : [ + + { + "name":"${serverInstance.key}", + "agentList":[ + + ${instance.value.json} + , + + ] + } + , + + ] } , ], diff --git a/src/main/webapp/WEB-INF/views/applicationmap.old.jsp b/src/main/webapp/WEB-INF/views/applicationmap.old.jsp new file mode 100644 index 000000000..e420686c0 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/applicationmap.old.jsp @@ -0,0 +1,83 @@ +<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +{ + "applicationMapData" : { + "nodeDataArray": [ + + { + "id" : ${status.count}, + "key" : ${status.count}, + "text" : "${node.applicationName}", + "category" : "${node.serviceType.desc}", + + "fig" : "Ellipse" + "fig" : "RoundedRectangle" + "fig" : "Rectangle" + , + "hosts" : [ + + ${host.value.json} + , + + ], + "serviceTypeCode" : "${node.serviceType.code}", + "terminal" : "${node.serviceType.terminal}", + "agents" : [ + + { + "hostname" : "${agentMap.key}", + "agentList" : [ + + ${agent.json} + , + + ] + } + , + + ], + "serverlist" : [ + + { + "name":"${serverInstance.key}", + "agentList":[ + + ${instance.json} + , + + ] + } + , + + ] + } , + + ], + "linkDataArray": [ + + { + "id" : "${link.from.sequence + 1}-${link.to.sequence + 1}", + "from" : ${link.from.sequence + 1}, + "to" : ${link.to.sequence + 1}, + "sourceinfo" : ${link.from.json}, + "targetinfo" : ${link.to.json}, + "text" : ${link.histogram.totalCount}, + "error" : ${link.histogram.errorCount}, + "slow" : ${link.histogram.slowCount}, + "histogram" : ${link.histogram}, + "targetHosts" : [ + + ${host.value.json} + , + + ], + + "category" : "bad" + "category" : "default" + + } , + + ] + } +} \ No newline at end of file