getLinks() {
+ return this.requests.values();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("RPCS=").append(rpcs);
+ sb.append("\n");
+ sb.append("REQUESTS=").append(requests.values());
+
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/com/nhn/hippo/web/calltree/Request.java b/src/main/java/com/nhn/hippo/web/calltree/Request.java
new file mode 100644
index 000000000..c4c0486ac
--- /dev/null
+++ b/src/main/java/com/nhn/hippo/web/calltree/Request.java
@@ -0,0 +1,46 @@
+package com.nhn.hippo.web.calltree;
+
+/**
+ *
+ * @author netspider
+ *
+ */
+public class Request {
+ private final String id;
+ private final RPC from;
+ private final RPC to;
+ private int callCount = 1;
+
+ public Request(RPC from, RPC to) {
+ this.from = from;
+ this.to = to;
+ this.id = from.getId() + to.getId();
+ }
+
+ public void increaseCallCount() {
+ callCount++;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public RPC getFrom() {
+ return from;
+ }
+
+ public RPC getTo() {
+ return to;
+ }
+
+ public int getCallCount() {
+ return callCount;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{from=").append(from).append(", to=").append(to).append(", cc=").append(callCount).append("}");
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/com/nhn/hippo/web/controller/FlowChartController.java b/src/main/java/com/nhn/hippo/web/controller/FlowChartController.java
index f0dd840f8..03d7f71fb 100644
--- a/src/main/java/com/nhn/hippo/web/controller/FlowChartController.java
+++ b/src/main/java/com/nhn/hippo/web/controller/FlowChartController.java
@@ -10,8 +10,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import com.nhn.hippo.web.calltree.RPCCallTree;
import com.nhn.hippo.web.service.FlowChartService;
+/**
+ * retrieve data for drawing call tree.
+ *
+ * @author netspider
+ *
+ */
@Controller
public class FlowChartController {
@@ -20,8 +27,7 @@ public class FlowChartController {
/**
*
- * testurl = http://localhost:7080/flow.hippo?host=TEST_AGENT_ID&from=1348453800000&to=1348453900000
- * testurl = http://localhost:7080/flow.hippo?host=TEST_AGENT_ID&from=0&to=1348493900000
+ * testurl = netscurl "http://localhost:7080/flow.hippo?host=TEST_AGENT_ID&from=1348565386677&to=1348565386677"
*
*
* @param model
@@ -36,18 +42,22 @@ public class FlowChartController {
* get agentId list from 'Servers'
*/
String[] selectAgentIds = flow.selectAgentIds(hosts);
-
System.out.println("selectedAgentIds=" + Arrays.toString(selectAgentIds));
/**
* get traceId list from 'TraceIndex'
*/
- List iterator = flow.selectTraceIdsFromTraceIndex(hosts, from, to);
+ List traceIds = flow.selectTraceIdsFromTraceIndex(hosts, from, to);
/**
- * get all traces from 'Trace'
+ * get call tree
*/
- flow.selectTraces(iterator);
+ RPCCallTree callTree = flow.selectCallTree(traceIds);
+ model.addAttribute("nodes", callTree.getNodes());
+ model.addAttribute("links", callTree.getLinks());
+ model.addAttribute("value", "hello world");
+
+ System.out.println(callTree.toString());
return "flow";
}
diff --git a/src/main/java/com/nhn/hippo/web/service/FlowChartService.java b/src/main/java/com/nhn/hippo/web/service/FlowChartService.java
index 2b0d3f9e4..b094fb0bf 100755
--- a/src/main/java/com/nhn/hippo/web/service/FlowChartService.java
+++ b/src/main/java/com/nhn/hippo/web/service/FlowChartService.java
@@ -2,15 +2,48 @@ package com.nhn.hippo.web.service;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
+import com.nhn.hippo.web.calltree.RPCCallTree;
import com.profiler.common.dto.thrift.Span;
+/**
+ *
+ * @author netspider
+ *
+ */
public interface FlowChartService {
+ /**
+ * select agentIds from Server table
+ *
+ * @param hosts
+ * @return
+ */
public String[] selectAgentIds(String[] hosts);
+ /**
+ * select traceIds from TraceIndex table
+ *
+ * @param agentIds
+ * @param from
+ * @param to
+ * @return
+ */
public List selectTraceIdsFromTraceIndex(String[] agentIds, long from, long to);
+ /**
+ * select Traces from Trace table
+ *
+ * @param traceIds
+ * @return
+ */
public Map> selectTraces(List traceIds);
+
+ /**
+ * select call tree
+ *
+ * @param traceIds
+ * @return
+ */
+ public RPCCallTree selectCallTree(List traceIds);
}
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 485d2d72f..11eb0dbe5 100755
--- a/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java
+++ b/src/main/java/com/nhn/hippo/web/service/FlowChartServiceImpl.java
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
+import com.nhn.hippo.web.calltree.RPCCallTree;
import com.profiler.common.dto.thrift.Span;
import com.profiler.common.hbase.HBaseClient;
import com.profiler.common.hbase.HBaseQuery;
@@ -99,20 +100,17 @@ public class FlowChartServiceImpl implements FlowChartService {
TDeserializer deserializer = new TDeserializer();
- /**
- * Map>>
- */
NavigableMap>> map = res.getMap();
for (Entry>> entry : map.entrySet()) {
- byte[] family = entry.getKey();
- System.out.println("family=" + Bytes.toString(family));
+// byte[] family = entry.getKey();
+// System.out.println("family=" + Bytes.toString(family));
NavigableMap> values = entry.getValue();
for (Entry> value : values.entrySet()) {
- byte[] colname = value.getKey();
- System.out.println("colname=" + Bytes.toString(colname));
+// byte[] colname = value.getKey();
+// System.out.println("colname=" + Bytes.toString(colname));
NavigableMap valueSeries = value.getValue();
@@ -131,4 +129,15 @@ public class FlowChartServiceImpl implements FlowChartService {
return list;
}
+ @Override
+ public RPCCallTree selectCallTree(List traceIds) {
+ List gets = new ArrayList(traceIds.size());
+ for (byte[] traceId : traceIds) {
+ gets.add(new Get(traceId));
+ }
+
+ Result[] results = client.get(HBaseTables.TRACES, gets);
+
+ return TracesProcessor.process(results);
+ }
}
diff --git a/src/main/java/com/nhn/hippo/web/service/TracesProcessor.java b/src/main/java/com/nhn/hippo/web/service/TracesProcessor.java
new file mode 100644
index 000000000..996999673
--- /dev/null
+++ b/src/main/java/com/nhn/hippo/web/service/TracesProcessor.java
@@ -0,0 +1,54 @@
+package com.nhn.hippo.web.service;
+
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.thrift.TDeserializer;
+import org.apache.thrift.TException;
+
+import com.nhn.hippo.web.calltree.RPCCallTree;
+import com.profiler.common.dto.thrift.Span;
+
+public class TracesProcessor {
+
+ public static RPCCallTree process(Result[] results) {
+ RPCCallTree callTree = new RPCCallTree();
+
+ TDeserializer deserializer = new TDeserializer();
+
+ for (Result res : results) {
+ /**
+ * res.getMap() represent
+ * "Map>>"
+ */
+ NavigableMap>> map = res.getMap();
+
+ for (Entry>> entry : map.entrySet()) {
+ NavigableMap> values = entry.getValue();
+
+ /**
+ * For each column (SpanID)
+ */
+ for (Entry> value : values.entrySet()) {
+ NavigableMap valueSeries = value.getValue();
+
+ /**
+ * Decode span object
+ */
+ for (Entry v : valueSeries.entrySet()) {
+ Span span = new Span();
+ try {
+ deserializer.deserialize(span, v.getValue());
+ callTree.addSpan(span);
+ } catch (TException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ return callTree.build();
+ }
+}
diff --git a/src/main/java/com/nhn/hippo/web/timeline/Timeline.java b/src/main/java/com/nhn/hippo/web/timeline/Timeline.java
new file mode 100644
index 000000000..611f3b691
--- /dev/null
+++ b/src/main/java/com/nhn/hippo/web/timeline/Timeline.java
@@ -0,0 +1,11 @@
+package com.nhn.hippo.web.timeline;
+
+/**
+ * Trace Timeline
+ *
+ * @author netspider
+ *
+ */
+public class Timeline {
+
+}
diff --git a/src/main/resources/hbase.properties b/src/main/resources/hbase.properties
index 1e914f623..f9e28d69c 100644
--- a/src/main/resources/hbase.properties
+++ b/src/main/resources/hbase.properties
@@ -1,4 +1,2 @@
-#hbase.client.host=localhost
-#hbase.client.port=2181
-hbase.client.host=10.25.131.38
+hbase.client.host=localhost
hbase.client.port=2181
\ No newline at end of file