From 39c4821f017d6da30bbebb989daa4e538c216f1a Mon Sep 17 00:00:00 2001 From: Chisu Yu Date: Fri, 1 Feb 2013 07:20:40 +0000 Subject: [PATCH] =?UTF-8?q?[=EC=9C=A0=EC=B9=98=EC=88=98]=20[NOBTS]=20serve?= =?UTF-8?q?rmap=EC=9D=B4=20=EC=83=81=EC=84=B8=EB=B3=B4=EA=B8=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=EB=8A=94=20server=20instance=EB=B3=84=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EC=9D=B4=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD.=20ma?= =?UTF-8?q?in=EC=97=90=EC=84=9C=EB=8A=94=20application=20name=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=ED=95=A9=EC=B3=90=EC=A7=90.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@1137 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../web/calltree/server/NodeIdGenerator.java | 34 +++++++++++++++++++ .../nhn/hippo/web/calltree/server/Server.java | 24 +++++++------ .../web/calltree/server/ServerCallTree.java | 30 +++++++++------- .../hippo/web/dao/TerminalStatisticsDao.java | 4 +-- .../dao/hbase/HbaseTerminalStatisticsDao.java | 6 ++-- ...per.java => TerminalStatisticsMapper.java} | 10 +++--- .../nhn/hippo/web/servermap/ServerMap.java | 16 ++++----- .../web/service/FlowChartServiceImpl.java | 22 ++++++------ ...alRequest.java => TerminalStatistics.java} | 8 ++--- src/main/resources/root-context.xml | 2 +- 10 files changed, 99 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/nhn/hippo/web/calltree/server/NodeIdGenerator.java rename src/main/java/com/nhn/hippo/web/mapper/{TerminalRequestCountMapper.java => TerminalStatisticsMapper.java} (69%) rename src/main/java/com/nhn/hippo/web/vo/{TerminalRequest.java => TerminalStatistics.java} (87%) diff --git a/src/main/java/com/nhn/hippo/web/calltree/server/NodeIdGenerator.java b/src/main/java/com/nhn/hippo/web/calltree/server/NodeIdGenerator.java new file mode 100644 index 000000000..42fdbccbf --- /dev/null +++ b/src/main/java/com/nhn/hippo/web/calltree/server/NodeIdGenerator.java @@ -0,0 +1,34 @@ +package com.nhn.hippo.web.calltree.server; + +import com.profiler.common.bo.SpanBo; +import com.profiler.common.bo.SubSpanBo; + +/** + * + * @author netspider + * + */ +public enum NodeIdGenerator { + + BY_SERVER_INSTANCE, BY_APPLICATION_NAME; + + public String makeServerId(SpanBo span) { + if (this == BY_SERVER_INSTANCE) { + return span.getEndPoint(); + } else if (this == BY_APPLICATION_NAME) { + return span.getServiceName(); + } else { + throw new IllegalArgumentException(); + } + } + + public String makeServerId(SubSpanBo span) { + if (this == BY_SERVER_INSTANCE) { + return span.getEndPoint(); + } else if (this == BY_APPLICATION_NAME) { + return span.getServiceName(); + } else { + throw new IllegalArgumentException(); + } + } +} diff --git a/src/main/java/com/nhn/hippo/web/calltree/server/Server.java b/src/main/java/com/nhn/hippo/web/calltree/server/Server.java index 99778ba1a..14c2ccc7e 100644 --- a/src/main/java/com/nhn/hippo/web/calltree/server/Server.java +++ b/src/main/java/com/nhn/hippo/web/calltree/server/Server.java @@ -11,16 +11,16 @@ import com.profiler.common.bo.SubSpanBo; * @author netspider */ public class Server implements Comparable { - private int sequence; - private final String id; - private final Set agentIds = new HashSet(); - private final String applicationName; - private final String endPoint; - private final ServiceType serviceType; + protected int sequence; + protected final String id; + protected final Set agentIds = new HashSet(); + protected final String applicationName; + protected final String endPoint; + protected final ServiceType serviceType; - private int recursiveCallCount; + protected int recursiveCallCount; - public Server(SubSpanBo span) { + public Server(SubSpanBo span, NodeIdGenerator idGenerator) { if (span.getServiceType().isTerminal()) { this.agentIds.add(span.getAgentId()); } else { @@ -33,7 +33,8 @@ public class Server implements Comparable { this.applicationName = span.getEndPoint(); this.serviceType = ServiceType.UNKNOWN_CLOUD; } else { - this.id = span.getServiceName(); + this.id = idGenerator.makeServerId(span); + // this.id = span.getServiceName(); this.applicationName = span.getServiceName(); this.serviceType = span.getServiceType(); } @@ -42,8 +43,9 @@ public class Server implements Comparable { this.recursiveCallCount = 0; } - public Server(SpanBo span) { - this.id = span.getServiceName(); + public Server(SpanBo span, NodeIdGenerator idGenerator) { + // this.id = span.getServiceName(); + this.id = idGenerator.makeServerId(span); if (span.getServiceType().isTerminal()) { this.agentIds.add(span.getAgentId()); diff --git a/src/main/java/com/nhn/hippo/web/calltree/server/ServerCallTree.java b/src/main/java/com/nhn/hippo/web/calltree/server/ServerCallTree.java index e2e9efc9d..fc5de926c 100644 --- a/src/main/java/com/nhn/hippo/web/calltree/server/ServerCallTree.java +++ b/src/main/java/com/nhn/hippo/web/calltree/server/ServerCallTree.java @@ -10,7 +10,7 @@ import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.nhn.hippo.web.vo.TerminalRequest; +import com.nhn.hippo.web.vo.TerminalStatistics; import com.profiler.common.ServiceType; import com.profiler.common.bo.SpanBo; import com.profiler.common.bo.SubSpanBo; @@ -28,18 +28,22 @@ public class ServerCallTree { private final Map servers = new HashMap(); private final Map serverRequests = new HashMap(); - + private final NodeIdGenerator idGenerator; private boolean isBuilt = false; // temporary variables private final List spans = new ArrayList(); private final List subspans = new ArrayList(); private final Map spanIdToServerId = new HashMap(); - private final Map terminalRequests = new HashMap(); + private final Map terminalRequests = new HashMap(); - public void addTerminal(TerminalRequest terminal) { + public ServerCallTree(NodeIdGenerator idGenerator) { + this.idGenerator = idGenerator; + } + + public void addTerminalStatistics(TerminalStatistics terminal) { if (terminalRequests.containsKey(terminal.getId())) { - TerminalRequest req = terminalRequests.get(terminal.getId()); + TerminalStatistics req = terminalRequests.get(terminal.getId()); req.mergeWith(terminal); } else { terminalRequests.put(terminal.getId(), terminal); @@ -56,7 +60,7 @@ public class ServerCallTree { } public void addSubSpan(SubSpanBo span) { - Server server = new Server(span); + Server server = new Server(span, idGenerator); if (server.getId() == null) { return; @@ -72,16 +76,16 @@ public class ServerCallTree { } public void addSpan(SpanBo span) { - Server server = new Server(span); + Server server = new Server(span, idGenerator); if (server.getId() == null) { return; } addServer(String.valueOf(span.getSpanId()), server); - + if (span.getParentSpanId() == -1) { -// businessTransactions.add(span); + // businessTransactions.add(span); } else { spans.add(span); } @@ -92,8 +96,8 @@ public class ServerCallTree { return this; // add terminal to the servers - for (Entry entry : terminalRequests.entrySet()) { - TerminalRequest terminal = entry.getValue(); + for (Entry entry : terminalRequests.entrySet()) { + TerminalStatistics terminal = entry.getValue(); Server server = new Server(terminal.getTo(), terminal.getTo(), "UNKNOWN", ServiceType.parse(terminal.getToServiceType())); servers.put(server.getId(), server); } @@ -105,8 +109,8 @@ public class ServerCallTree { } // add terminal requests - for (Entry entry : terminalRequests.entrySet()) { - TerminalRequest terminal = entry.getValue(); + for (Entry entry : terminalRequests.entrySet()) { + TerminalStatistics terminal = entry.getValue(); TerminalServerRequest request = new TerminalServerRequest(servers.get(terminal.getFrom()), servers.get(terminal.getTo()), (int) terminal.getRequestCount()); serverRequests.put(request.getId(), request); } diff --git a/src/main/java/com/nhn/hippo/web/dao/TerminalStatisticsDao.java b/src/main/java/com/nhn/hippo/web/dao/TerminalStatisticsDao.java index bdee06034..08890114e 100644 --- a/src/main/java/com/nhn/hippo/web/dao/TerminalStatisticsDao.java +++ b/src/main/java/com/nhn/hippo/web/dao/TerminalStatisticsDao.java @@ -2,7 +2,7 @@ package com.nhn.hippo.web.dao; import java.util.List; -import com.nhn.hippo.web.vo.TerminalRequest; +import com.nhn.hippo.web.vo.TerminalStatistics; /** * @@ -10,5 +10,5 @@ import com.nhn.hippo.web.vo.TerminalRequest; * */ public interface TerminalStatisticsDao { - public List> selectTerminal(String applicationName, long from, long to); + public List> selectTerminal(String applicationName, long from, long to); } diff --git a/src/main/java/com/nhn/hippo/web/dao/hbase/HbaseTerminalStatisticsDao.java b/src/main/java/com/nhn/hippo/web/dao/hbase/HbaseTerminalStatisticsDao.java index ec006f513..073ae0db8 100644 --- a/src/main/java/com/nhn/hippo/web/dao/hbase/HbaseTerminalStatisticsDao.java +++ b/src/main/java/com/nhn/hippo/web/dao/hbase/HbaseTerminalStatisticsDao.java @@ -9,7 +9,7 @@ import org.springframework.data.hadoop.hbase.RowMapper; import org.springframework.stereotype.Repository; import com.nhn.hippo.web.dao.TerminalStatisticsDao; -import com.nhn.hippo.web.vo.TerminalRequest; +import com.nhn.hippo.web.vo.TerminalStatistics; import com.profiler.common.hbase.HBaseTables; import com.profiler.common.hbase.HbaseOperations2; import com.profiler.common.util.TerminalSpanUtils; @@ -30,10 +30,10 @@ public class HbaseTerminalStatisticsDao implements TerminalStatisticsDao { @Autowired @Qualifier("terminalRequestCountMapper") - private RowMapper> terminalRequestCountMapper; + private RowMapper> terminalRequestCountMapper; @Override - public List> selectTerminal(String applicationName, long from, long to) { + public List> selectTerminal(String applicationName, long from, long to) { Scan scan = createScan(applicationName, from, to); return hbaseOperations2.find(HBaseTables.TERMINAL_STATISTICS, scan, terminalRequestCountMapper); } diff --git a/src/main/java/com/nhn/hippo/web/mapper/TerminalRequestCountMapper.java b/src/main/java/com/nhn/hippo/web/mapper/TerminalStatisticsMapper.java similarity index 69% rename from src/main/java/com/nhn/hippo/web/mapper/TerminalRequestCountMapper.java rename to src/main/java/com/nhn/hippo/web/mapper/TerminalStatisticsMapper.java index fbe8d8139..b31be1b20 100644 --- a/src/main/java/com/nhn/hippo/web/mapper/TerminalRequestCountMapper.java +++ b/src/main/java/com/nhn/hippo/web/mapper/TerminalStatisticsMapper.java @@ -9,7 +9,7 @@ import org.apache.hadoop.hbase.util.Bytes; import org.springframework.data.hadoop.hbase.RowMapper; import org.springframework.stereotype.Component; -import com.nhn.hippo.web.vo.TerminalRequest; +import com.nhn.hippo.web.vo.TerminalStatistics; import com.profiler.common.hbase.HBaseTables; import com.profiler.common.util.TerminalSpanUtils; @@ -17,13 +17,13 @@ import com.profiler.common.util.TerminalSpanUtils; * */ @Component -public class TerminalRequestCountMapper implements RowMapper> { +public class TerminalStatisticsMapper implements RowMapper> { @Override - public List mapRow(Result result, int rowNum) throws Exception { + public List mapRow(Result result, int rowNum) throws Exception { KeyValue[] keyList = result.raw(); - List requestList = new ArrayList(); + List requestList = new ArrayList(); for (KeyValue kv : keyList) { if (kv.getFamilyLength() == HBaseTables.TERMINAL_STATISTICS_CF_COUNTER.length) { String from = TerminalSpanUtils.getApplicationNameFromRowKey(kv.getRow()); @@ -31,7 +31,7 @@ public class TerminalRequestCountMapper implements RowMapper spans = new ArrayList(); private final List subspans = new ArrayList(); - private final Map terminalRequests = new HashMap(); + private final Map terminalRequests = new HashMap(); private boolean isBuilt = false; - public void addTerminalRequest(TerminalRequest terminal) { + public void addTerminalRequest(TerminalStatistics terminal) { if (terminalRequests.containsKey(terminal.getId())) { - TerminalRequest req = terminalRequests.get(terminal.getId()); + TerminalStatistics req = terminalRequests.get(terminal.getId()); req.mergeWith(terminal); } else { terminalRequests.put(terminal.getId(), terminal); @@ -79,8 +79,8 @@ public class ServerMap { return this; // add terminal to the nodes - for (Entry entry : terminalRequests.entrySet()) { - TerminalRequest terminal = entry.getValue(); + for (Entry entry : terminalRequests.entrySet()) { + TerminalStatistics terminal = entry.getValue(); Node node = new Node(terminal.getTo(), terminal.getTo(), "UNKNOWN", ServiceType.parse(terminal.getToServiceType())); nodes.addNode(node.getId(), node); } @@ -92,8 +92,8 @@ public class ServerMap { } // add terminal requests - for (Entry entry : terminalRequests.entrySet()) { - TerminalRequest terminal = entry.getValue(); + for (Entry entry : terminalRequests.entrySet()) { + TerminalStatistics terminal = entry.getValue(); Link link = new Link(nodes.get(terminal.getFrom()), nodes.get(terminal.getTo()), terminal.getRequestCount()); links.add(link); } diff --git a/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java b/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java index 91e041063..939272fa3 100755 --- a/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java +++ b/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StopWatch; import com.nhn.hippo.web.calltree.rpc.RPCCallTree; +import com.nhn.hippo.web.calltree.server.NodeIdGenerator; import com.nhn.hippo.web.calltree.server.ServerCallTree; import com.nhn.hippo.web.dao.ApplicationIndexDao; import com.nhn.hippo.web.dao.ApplicationTraceIndexDao; @@ -25,7 +26,7 @@ import com.nhn.hippo.web.dao.TerminalStatisticsDao; import com.nhn.hippo.web.dao.TraceDao; import com.nhn.hippo.web.dao.TraceIndexDao; import com.nhn.hippo.web.vo.BusinessTransactions; -import com.nhn.hippo.web.vo.TerminalRequest; +import com.nhn.hippo.web.vo.TerminalStatistics; import com.nhn.hippo.web.vo.TraceId; import com.nhn.hippo.web.vo.scatter.Dot; import com.profiler.common.ServiceType; @@ -124,9 +125,10 @@ public class FlowChartServiceImpl implements FlowChartService { return tree.build(); } + @Deprecated @Override public ServerCallTree selectServerCallTree(Set traceIds) { - final ServerCallTree tree = new ServerCallTree(); + final ServerCallTree tree = new ServerCallTree(NodeIdGenerator.BY_APPLICATION_NAME); List> traces = this.traceDao.selectSpans(traceIds); @@ -145,7 +147,7 @@ public class FlowChartServiceImpl implements FlowChartService { */ @Override public ServerCallTree selectServerCallTree(TraceId traceId) { - final ServerCallTree tree = new ServerCallTree(); + final ServerCallTree tree = new ServerCallTree(NodeIdGenerator.BY_SERVER_INSTANCE); List transaction = this.traceDao.selectSpans(traceId); @@ -169,7 +171,7 @@ public class FlowChartServiceImpl implements FlowChartService { if (subTransaction.getServiceType() == ServiceType.INTERNAL_METHOD) { continue; } - + // remove subspan of the rpc client if (!endPoints.contains(subTransaction.getEndPoint())) { // this is unknown cloud @@ -187,7 +189,7 @@ public class FlowChartServiceImpl implements FlowChartService { @Override public ServerCallTree selectServerCallTree(Set traceIds, String applicationName, long from, long to) { final Map terminalQueryParams = new HashMap(); - final ServerCallTree tree = new ServerCallTree(); + final ServerCallTree tree = new ServerCallTree(NodeIdGenerator.BY_APPLICATION_NAME); StopWatch watch = new StopWatch(); watch.start("scanNonTerminalSpans"); @@ -227,17 +229,17 @@ public class FlowChartServiceImpl implements FlowChartService { ServiceType svcType = param.getValue(); if (!svcType.isRpcClient() && !svcType.isUnknown() && !svcType.isTerminal()) { long start = System.currentTimeMillis(); - List> terminals = terminalStatisticsDao.selectTerminal(param.getKey(), from, to); + List> terminals = terminalStatisticsDao.selectTerminal(param.getKey(), from, to); logger.info(" Fetch terminals of {} : {}ms", param.getKey(), System.currentTimeMillis() - start); - for (List terminal : terminals) { - for (TerminalRequest t : terminal) { + for (List terminal : terminals) { + for (TerminalStatistics t : terminal) { // TODO 임시방편 if (!endPoints.contains(t.getTo())) { if (ServiceType.parse(t.getToServiceType()).isRpcClient()) { t.setToServiceType(ServiceType.UNKNOWN_CLOUD.getCode()); } - tree.addTerminal(t); + tree.addTerminalStatistics(t); } } } @@ -357,7 +359,7 @@ public class FlowChartServiceImpl implements FlowChartService { return list.iterator(); } - + @Override public BusinessTransactions selectBusinessTransactions(Set traceIds, String applicationName, long from, long to) { List> traces = this.traceDao.selectSpans(traceIds); diff --git a/src/main/java/com/nhn/hippo/web/vo/TerminalRequest.java b/src/main/java/com/nhn/hippo/web/vo/TerminalStatistics.java similarity index 87% rename from src/main/java/com/nhn/hippo/web/vo/TerminalRequest.java rename to src/main/java/com/nhn/hippo/web/vo/TerminalStatistics.java index 417aac218..692367552 100644 --- a/src/main/java/com/nhn/hippo/web/vo/TerminalRequest.java +++ b/src/main/java/com/nhn/hippo/web/vo/TerminalStatistics.java @@ -1,6 +1,6 @@ package com.nhn.hippo.web.vo; -public class TerminalRequest { +public class TerminalStatistics { private final String id; private final String from; @@ -8,7 +8,7 @@ public class TerminalRequest { private short toServiceType; private long requestCount; - public TerminalRequest(String from, String to, short toServiceType, long requestCount) { + public TerminalStatistics(String from, String to, short toServiceType, long requestCount) { this.id = from + to + toServiceType; this.from = from; this.to = to; @@ -40,7 +40,7 @@ public class TerminalRequest { this.toServiceType = toServiceType; } - public TerminalRequest mergeWith(TerminalRequest terminalRequest) { + public TerminalStatistics mergeWith(TerminalStatistics terminalRequest) { if (this.equals(terminalRequest)) { this.requestCount += terminalRequest.requestCount; return this; @@ -72,7 +72,7 @@ public class TerminalRequest { return false; if (getClass() != obj.getClass()) return false; - TerminalRequest other = (TerminalRequest) obj; + TerminalStatistics other = (TerminalStatistics) obj; if (from == null) { if (other.from != null) return false; diff --git a/src/main/resources/root-context.xml b/src/main/resources/root-context.xml index e2b1d4df2..7dee1e37b 100644 --- a/src/main/resources/root-context.xml +++ b/src/main/resources/root-context.xml @@ -23,7 +23,7 @@ - +