mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-23 11:46:46 +10:00
[유치수] [NOBTS] get application name from agentIdApplicationIndex table.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-server/trunk@913 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.profiler.server.dao;
|
||||
|
||||
public interface AgentIdApplicationIndex {
|
||||
void insert(String agentId, String applicationName);
|
||||
|
||||
String selectApplicationName(String agentId);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.profiler.server.dao.hbase;
|
||||
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
|
||||
import com.profiler.common.hbase.HBaseTables;
|
||||
import com.profiler.common.hbase.HbaseOperations2;
|
||||
import com.profiler.server.dao.AgentIdApplicationIndex;
|
||||
|
||||
/**
|
||||
* find applicationname by agentId
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class HbaseAgentIdApplicationIndexDao implements AgentIdApplicationIndex {
|
||||
|
||||
String TABLE_NAME = HBaseTables.AGENTID_APPLICATION_INDEX;
|
||||
byte[] COLFAM_TRACE = HBaseTables.AGENTID_APPLICATION_INDEX_CF_APPLICATION;
|
||||
|
||||
@Autowired
|
||||
private HbaseOperations2 hbaseTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("applicationNameMapper")
|
||||
private RowMapper<String> applicationNameMapper;
|
||||
|
||||
@Override
|
||||
public void insert(String agentId, String applicationName) {
|
||||
byte[] agentIdByte = Bytes.toBytes(agentId);
|
||||
byte[] appNameByte = Bytes.toBytes(applicationName);
|
||||
|
||||
Put put = new Put(agentIdByte);
|
||||
put.add(COLFAM_TRACE, appNameByte, appNameByte);
|
||||
|
||||
hbaseTemplate.put(TABLE_NAME, put);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String selectApplicationName(String agentId) {
|
||||
byte[] rowKey = Bytes.toBytes(agentId);
|
||||
Get get = new Get(rowKey);
|
||||
get.addFamily(HBaseTables.AGENTID_APPLICATION_INDEX_CF_APPLICATION);
|
||||
|
||||
return hbaseTemplate.get(TABLE_NAME, get, applicationNameMapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.profiler.server.dao.mapper;
|
||||
|
||||
import org.apache.hadoop.hbase.KeyValue;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ApplicationNameMapper implements RowMapper<String> {
|
||||
@Override
|
||||
public String mapRow(Result result, int rowNum) throws Exception {
|
||||
KeyValue[] raw = result.raw();
|
||||
|
||||
if (raw.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] ret = new String[raw.length];
|
||||
int index = 0;
|
||||
|
||||
for (KeyValue kv : raw) {
|
||||
ret[index++] = new String(kv.getQualifier(), "UTF-8");
|
||||
}
|
||||
|
||||
return ret[0];
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.profiler.common.dto.thrift.AgentInfo;
|
||||
import com.profiler.common.dto.thrift.Span;
|
||||
import com.profiler.server.dao.AgentIdApplicationIndex;
|
||||
import com.profiler.server.dao.ApplicationIndex;
|
||||
|
||||
public class AgentInfoHandler implements Handler {
|
||||
@@ -18,6 +19,9 @@ public class AgentInfoHandler implements Handler {
|
||||
@Autowired
|
||||
private ApplicationIndex applicationIndexDao;
|
||||
|
||||
@Autowired
|
||||
private AgentIdApplicationIndex agentIdApplicationIndexDao;
|
||||
|
||||
public void handler(TBase<?, ?> tbase, DatagramPacket datagramPacket) {
|
||||
assert (tbase instanceof Span);
|
||||
|
||||
@@ -27,6 +31,7 @@ public class AgentInfoHandler implements Handler {
|
||||
logger.debug("Received AgentInfo=%s", agentInfo);
|
||||
|
||||
applicationIndexDao.insert(agentInfo);
|
||||
agentIdApplicationIndexDao.insert(agentInfo.getAgentId(), agentInfo.getApplicationName());
|
||||
} catch (Exception e) {
|
||||
logger.warn("Span handle error " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.profiler.common.dto.thrift.Span;
|
||||
import com.profiler.server.dao.AgentIdApplicationIndex;
|
||||
import com.profiler.server.dao.ApplicationTraceIndex;
|
||||
import com.profiler.server.dao.RootTraceIndexDao;
|
||||
import com.profiler.server.dao.TraceIndex;
|
||||
@@ -29,6 +30,9 @@ public class SpanHandler implements Handler {
|
||||
@Autowired
|
||||
private ApplicationTraceIndex applicationTraceIndexDao;
|
||||
|
||||
@Autowired
|
||||
private AgentIdApplicationIndex agentIdApplicationIndexDao;
|
||||
|
||||
public void handler(TBase<?, ?> tbase, DatagramPacket datagramPacket) {
|
||||
assert (tbase instanceof Span);
|
||||
|
||||
@@ -39,11 +43,14 @@ public class SpanHandler implements Handler {
|
||||
logger.info("Received SPAN=" + span);
|
||||
}
|
||||
|
||||
String applicationName = span.getServiceName();
|
||||
String applicationName = agentIdApplicationIndexDao.selectApplicationName(span.getAgentId());
|
||||
// String applicationName = span.getServiceName();
|
||||
|
||||
if (applicationName == null) {
|
||||
logger.info("Applicationname '{}' not found. Drop the log.", applicationName);
|
||||
return;
|
||||
} else {
|
||||
logger.info("Applicationname '{}' found. Write the log.", applicationName);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
||||
@@ -41,4 +41,7 @@
|
||||
<bean class="com.profiler.server.dao.hbase.HbaseJvmInfoDao"></bean>
|
||||
<bean class="com.profiler.server.dao.hbase.HbaseApplicationIndexDao"></bean>
|
||||
<bean class="com.profiler.server.dao.hbase.HbaseApplicationTraceIndex"></bean>
|
||||
<bean class="com.profiler.server.dao.hbase.HbaseAgentIdApplicationIndexDao"></bean>
|
||||
|
||||
<bean id="applicationNameMapper" class="com.profiler.server.dao.mapper.ApplicationNameMapper"></bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user