[#15] implemented backend handling of server meta data

This commit is contained in:
Hyun Jeong
2014-10-22 17:21:58 +09:00
parent 8720aff2ee
commit 260a9b49ed
18 changed files with 724 additions and 170 deletions
@@ -1,18 +1,24 @@
package com.nhn.pinpoint.collector.dao.hbase;
import com.nhn.pinpoint.thrift.dto.TAgentInfo;
import com.nhn.pinpoint.thrift.dto.TServerMetaData;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.nhn.pinpoint.common.bo.AgentInfoBo;
import com.nhn.pinpoint.common.bo.ServerMetaDataBo;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.common.util.RowKeyUtils;
import com.nhn.pinpoint.common.util.TimeUtils;
import com.nhn.pinpoint.collector.dao.AgentInfoDao;
import com.nhn.pinpoint.collector.mapper.thrift.ThriftBoMapper;
import org.springframework.stereotype.Repository;
/**
@@ -25,6 +31,14 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
@Autowired
private HbaseOperations2 hbaseTemplate;
@Autowired
@Qualifier("agentInfoBoMapper")
private ThriftBoMapper<AgentInfoBo, TAgentInfo> agentInfoBoMapper;
@Autowired
@Qualifier("serverMetaDataBoMapper")
private ThriftBoMapper<ServerMetaDataBo, TServerMetaData> serverMetaDataBoMapper;
@Override
public void insert(TAgentInfo agentInfo) {
@@ -42,11 +56,16 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
Put put = new Put(rowKey);
// 추가 agent 정보를 넣어야 됨. 일단 sqlMetaData에 필요한 starttime만 넣음.
AgentInfoBo agentInfoBo = new AgentInfoBo(agentInfo);
byte[] bytes = agentInfoBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER, bytes);
AgentInfoBo agentInfoBo = this.agentInfoBoMapper.map(agentInfo);
byte[] agentInfoBoValue = agentInfoBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER, agentInfoBoValue);
if (agentInfo.isSetServerMetaData()) {
ServerMetaDataBo serverMetaDataBo = this.serverMetaDataBoMapper.map(agentInfo.getServerMetaData());
byte[] serverMetaDataBoValue = serverMetaDataBo.writeValue();
put.add(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_SERVER_META_DATA, serverMetaDataBoValue);
}
hbaseTemplate.put(HBaseTables.AGENTINFO, put);
}
}
@@ -0,0 +1,32 @@
package com.nhn.pinpoint.collector.mapper.thrift;
import org.springframework.stereotype.Component;
import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.bo.AgentInfoBo;
import com.nhn.pinpoint.thrift.dto.TAgentInfo;
/**
* @author hyungil.jeong
*/
@Component
public class AgentInfoBoMapper implements ThriftBoMapper<AgentInfoBo, TAgentInfo> {
@Override
public AgentInfoBo map(TAgentInfo thriftObject) {
final String hostName = thriftObject.getHostname();
final String ip = thriftObject.getIp();
final String ports = thriftObject.getPorts();
final String agentId = thriftObject.getAgentId();
final String applicationName = thriftObject.getApplicationName();
final ServiceType serviceType = ServiceType.findServiceType(thriftObject.getServiceType());
final int pid = thriftObject.getPid();
final String version = thriftObject.getVersion();
final long startTime = thriftObject.getStartTimestamp();
final long endTimeStamp = thriftObject.getEndTimestamp();
final int endStatus = thriftObject.getEndStatus();
return new AgentInfoBo.Builder().hostName(hostName).ip(ip).ports(ports).agentId(agentId).applicationName(applicationName).serviceType(serviceType)
.pid(pid).version(version).startTime(startTime).endTimeStamp(endTimeStamp).endStatus(endStatus).build();
}
}
@@ -0,0 +1,43 @@
package com.nhn.pinpoint.collector.mapper.thrift;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.stereotype.Component;
import com.nhn.pinpoint.common.bo.ServerMetaDataBo;
import com.nhn.pinpoint.common.bo.ServiceInfoBo;
import com.nhn.pinpoint.thrift.dto.TServerMetaData;
import com.nhn.pinpoint.thrift.dto.TServiceInfo;
/**
* @author hyungil.jeong
*/
@Component
public class ServerMetaDataBoMapper implements ThriftBoMapper<ServerMetaDataBo, TServerMetaData> {
@Override
public ServerMetaDataBo map(TServerMetaData thriftObject) {
final String serverInfo = thriftObject.getServerInfo();
final List<String> vmArgs = thriftObject.getVmArgs();
ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder().serverInfo(serverInfo).vmArgs(vmArgs);
if (thriftObject.isSetServiceInfos()) {
final List<ServiceInfoBo> serviceInfos = new ArrayList<ServiceInfoBo>(thriftObject.getServiceInfosSize());
for (TServiceInfo tServiceInfo : thriftObject.getServiceInfos()) {
final ServiceInfoBo serviceInfoBo = mapServiceInfo(tServiceInfo);
serviceInfos.add(serviceInfoBo);
}
return builder.serviceInfos(serviceInfos).build();
} else {
return builder.serviceInfos(Collections.<ServiceInfoBo> emptyList()).build();
}
}
private ServiceInfoBo mapServiceInfo(TServiceInfo serviceInfo) {
final String serviceName = serviceInfo.getServiceName();
final List<String> serviceLibs = serviceInfo.getServiceLibs();
return new ServiceInfoBo.Builder().serviceName(serviceName).serviceLibs(serviceLibs).build();
}
}
@@ -0,0 +1,70 @@
package com.nhn.pinpoint.collector.mapper.thrift;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.nhn.pinpoint.common.bo.ServerMetaDataBo;
import com.nhn.pinpoint.common.bo.ServiceInfoBo;
import com.nhn.pinpoint.thrift.dto.TServerMetaData;
import com.nhn.pinpoint.thrift.dto.TServiceInfo;
/**
* @author hyungil.jeong
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext-test.xml")
public class ServerMetaDataBoMapperTest {
@Autowired
private ServerMetaDataBoMapper mapper;
@Test
public void testValidMap() {
// Given
final TServerMetaData tServerMetaData = new TServerMetaData();
tServerMetaData.setServerInfo("serverInfo");
tServerMetaData.setVmArgs(Arrays.asList("arg1", "arg2"));
final TServiceInfo tServiceInfo = new TServiceInfo();
tServiceInfo.setServiceName("serviceName");
tServiceInfo.setServiceLibs(Arrays.asList("lib1", "lib2"));
List<TServiceInfo> tServiceInfos = Arrays.asList(tServiceInfo);
tServerMetaData.setServiceInfos(tServiceInfos);
// When
ServerMetaDataBo serverMetaData = mapper.map(tServerMetaData);
List<ServiceInfoBo> serviceInfos = serverMetaData.getServiceInfos();
// Then
assertEquals(tServerMetaData.getServerInfo(), serverMetaData.getServerInfo());
assertEquals(tServerMetaData.getVmArgs(), serverMetaData.getVmArgs());
assertEquals(tServiceInfos.size(), serviceInfos.size());
for (int i = 0; i < tServiceInfos.size(); ++i) {
assertEquals(tServiceInfos.get(i).getServiceName(), serviceInfos.get(i).getServiceName());
assertEquals(tServiceInfos.get(i).getServiceLibs(), serviceInfos.get(i).getServiceLibs());
}
}
@Test
public void mapShouldNotThrowExceptionForNullValues() {
// Given
final TServerMetaData tServerMetaData = new TServerMetaData();
tServerMetaData.setServerInfo(null);
tServerMetaData.setVmArgs(null);
tServerMetaData.setServiceInfos(null);
// When
ServerMetaDataBo serverMetaData = mapper.map(tServerMetaData);
// Then
assertEquals("", serverMetaData.getServerInfo());
assertEquals(Collections.emptyList(), serverMetaData.getVmArgs());
assertEquals(Collections.emptyList(), serverMetaData.getServiceInfos());
}
}
@@ -4,14 +4,14 @@ import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.common.buffer.AutomaticBuffer;
import com.nhn.pinpoint.common.buffer.Buffer;
import com.nhn.pinpoint.common.buffer.FixedBuffer;
import com.nhn.pinpoint.thrift.dto.TAgentInfo;
import java.util.Comparator;
/**
* @author emeroad
* @author hyungil.jeong
*/
public class AgentInfoBo {
public class AgentInfoBo {
public static final Comparator<AgentInfoBo> AGENT_NAME_ASC_COMPARATOR = new Comparator<AgentInfoBo>() {
@Override
@@ -27,92 +27,62 @@ public class AgentInfoBo {
}
};
private final String hostName;
private final String ip;
private final String ports;
private final String agentId;
private final String applicationName;
private final ServiceType serviceType;
private final int pid;
private final String version;
private String hostname;
private String ip;
private String ports;
private String agentId;
private String applicationName;
private ServiceType serviceType;
private int pid;
private String version;
private final long startTime;
private long startTime;
private final long endTimeStamp;
private final int endStatus;
private long endTimeStamp;
private int endStatus;
// Should be serialized separately
private final ServerMetaDataBo serverMetaData;
public AgentInfoBo(TAgentInfo agentInfo) {
if (agentInfo == null) {
throw new NullPointerException("agentInfo must not be null");
}
this.hostname = agentInfo.getHostname();
this.ip = agentInfo.getIp();
this.ports = agentInfo.getPorts();
this.agentId = agentInfo.getAgentId();
this.applicationName = agentInfo.getApplicationName();
this.serviceType = ServiceType.findServiceType(agentInfo.getServiceType());
this.pid = agentInfo.getPid();
this.version = agentInfo.getVersion();
this.startTime = agentInfo.getStartTimestamp();
this.endTimeStamp = agentInfo.getEndTimestamp();
this.endStatus = agentInfo.getEndStatus();
private AgentInfoBo(Builder builder) {
this.hostName = builder.hostName;
this.ip = builder.ip;
this.ports = builder.ports;
this.agentId = builder.agentId;
this.applicationName = builder.applicationName;
this.serviceType = builder.serviceType;
this.pid = builder.pid;
this.version = builder.version;
this.startTime = builder.startTime;
this.endTimeStamp = builder.endTimeStamp;
this.endStatus = builder.endStatus;
this.serverMetaData = builder.serverMetaData;
}
public AgentInfoBo() {
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getHostname() {
return hostname;
return ip;
}
public void setHostname(String hostname) {
this.hostname = hostname;
public String getHostName() {
return hostName;
}
public String getPorts() {
return ports;
}
public void setPorts(String ports) {
this.ports = ports;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public long getEndTimeStamp() {
return endTimeStamp;
}
@@ -125,29 +95,21 @@ public class AgentInfoBo {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public ServiceType getServiceType() {
return serviceType;
}
public void setServiceType(ServiceType serviceType) {
this.serviceType = serviceType;
}
public ServiceType getServiceType() {
return serviceType;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
public ServerMetaDataBo getServerMetaData() {
return this.serverMetaData;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.putPrefixedString(this.getHostname());
buffer.putPrefixedString(this.getHostName());
buffer.putPrefixedString(this.getIp());
buffer.putPrefixedString(this.getPorts());
buffer.putPrefixedString(this.getApplicationName());
@@ -162,52 +124,35 @@ public class AgentInfoBo {
return buffer.getBuffer();
}
public int readValue(byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.hostname = buffer.readPrefixedString();
this.ip = buffer.readPrefixedString();
this.ports = buffer.readPrefixedString();
this.applicationName = buffer.readPrefixedString();
this.serviceType = ServiceType.findServiceType(buffer.readShort());
this.pid = buffer.readInt();
this.version = buffer.readPrefixedString();
this.startTime = buffer.readLong();
this.endTimeStamp = buffer.readLong();
this.endStatus = buffer.readInt();
return buffer.getOffset();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((agentId == null) ? 0 : agentId.hashCode());
return result;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((agentId == null) ? 0 : agentId.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;
AgentInfoBo other = (AgentInfoBo) obj;
if (agentId == null) {
if (other.agentId != null)
return false;
} else if (!agentId.equals(other.agentId))
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AgentInfoBo other = (AgentInfoBo)obj;
if (agentId == null) {
if (other.agentId != null)
return false;
} else if (!agentId.equals(other.agentId))
return false;
return true;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AgentInfoBo{");
sb.append("hostname='").append(hostname).append('\'');
sb.append("hostName='").append(hostName).append('\'');
sb.append(", ip='").append(ip).append('\'');
sb.append(", ports='").append(ports).append('\'');
sb.append(", agentId='").append(agentId).append('\'');
@@ -222,4 +167,117 @@ public class AgentInfoBo {
return sb.toString();
}
public static class Builder {
private String hostName;
private String ip;
private String ports;
private String agentId;
private String applicationName;
private ServiceType serviceType;
private int pid;
private String version;
private long startTime;
private long endTimeStamp;
private int endStatus;
// Should be serialized separately
private ServerMetaDataBo serverMetaData;
public Builder() {
}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.hostName = buffer.readPrefixedString();
this.ip = buffer.readPrefixedString();
this.ports = buffer.readPrefixedString();
this.applicationName = buffer.readPrefixedString();
this.serviceType = ServiceType.findServiceType(buffer.readShort());
this.pid = buffer.readInt();
this.version = buffer.readPrefixedString();
this.startTime = buffer.readLong();
this.endTimeStamp = buffer.readLong();
this.endStatus = buffer.readInt();
}
public Builder hostName(String hostName) {
this.hostName = hostName;
return this;
}
public Builder ip(String ip) {
this.ip = ip;
return this;
}
public Builder ports(String ports) {
this.ports = ports;
return this;
}
public Builder agentId(String agentId) {
this.agentId = agentId;
return this;
}
public Builder applicationName(String applicationName) {
this.applicationName = applicationName;
return this;
}
public Builder serviceType(ServiceType serviceType) {
this.serviceType = serviceType;
return this;
}
public Builder pid(int pid) {
this.pid = pid;
return this;
}
public Builder version(String version) {
this.version = version;
return this;
}
public Builder startTime(long startTime) {
this.startTime = startTime;
return this;
}
public Builder endTimeStamp(long endTimeStamp) {
this.endTimeStamp = endTimeStamp;
return this;
}
public Builder endStatus(int endStatus) {
this.endStatus = endStatus;
return this;
}
public Builder serverMetaData(ServerMetaDataBo serverMetaData) {
this.serverMetaData = serverMetaData;
return this;
}
public AgentInfoBo build() {
if (this.hostName == null)
this.hostName = "";
if (this.ip == null)
this.ip = "";
if (this.ports == null)
this.ports = "";
if (this.agentId == null)
this.agentId = "";
if (this.applicationName == null)
this.applicationName = "";
if (this.version == null)
this.version = "";
if (this.serviceType == null)
this.serviceType = ServiceType.UNKNOWN;
return new AgentInfoBo(this);
}
}
}
@@ -0,0 +1,152 @@
package com.nhn.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.nhn.pinpoint.common.buffer.AutomaticBuffer;
import com.nhn.pinpoint.common.buffer.Buffer;
import com.nhn.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBo {
private final String serverInfo;
private final List<String> vmArgs;
private final List<ServiceInfoBo> serviceInfos;
private ServerMetaDataBo(Builder builder) {
this.serverInfo = builder.serverInfo;
this.vmArgs = builder.vmArgs;
this.serviceInfos = builder.serviceInfos;
}
public String getServerInfo() {
return this.serverInfo;
}
public List<String> getVmArgs() {
return this.vmArgs;
}
public List<ServiceInfoBo> getServiceInfos() {
return this.serviceInfos;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serverInfo);
final int numVmArgs = this.vmArgs == null ? 0 : this.vmArgs.size();
buffer.putVar(numVmArgs);
for (String vmArg : this.vmArgs) {
buffer.put2PrefixedString(vmArg);
}
final int numServiceInfos = this.serviceInfos == null ? 0 : this.serviceInfos.size();
buffer.putVar(numServiceInfos);
for (ServiceInfoBo serviceInfo : this.serviceInfos) {
buffer.putPrefixedBytes(serviceInfo.writeValue());
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServerMetaDataBo{");
sb.append("serverInfo='").append(this.serverInfo).append('\'');
sb.append(", vmArgs=").append(this.vmArgs);
sb.append(", serviceInfos=").append(this.serviceInfos.toString());
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serverInfo == null) ? 0 : serverInfo.hashCode());
result = prime * result + ((serviceInfos == null) ? 0 : serviceInfos.hashCode());
result = prime * result + ((vmArgs == null) ? 0 : vmArgs.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;
ServerMetaDataBo other = (ServerMetaDataBo)obj;
if (serverInfo == null) {
if (other.serverInfo != null)
return false;
} else if (!serverInfo.equals(other.serverInfo))
return false;
if (serviceInfos == null) {
if (other.serviceInfos != null)
return false;
} else if (!serviceInfos.equals(other.serviceInfos))
return false;
if (vmArgs == null) {
if (other.vmArgs != null)
return false;
} else if (!vmArgs.equals(other.vmArgs))
return false;
return true;
}
public static class Builder {
private String serverInfo;
private List<String> vmArgs;
private List<ServiceInfoBo> serviceInfos;
public Builder() {
}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serverInfo = buffer.read2PrefixedString();
final int numVmArgs = buffer.readVarInt();
this.vmArgs = new ArrayList<String>(numVmArgs);
for (int i = 0; i < numVmArgs; ++i) {
this.vmArgs.add(buffer.read2PrefixedString());
}
final int numServiceInfos = buffer.readVarInt();
this.serviceInfos = new ArrayList<ServiceInfoBo>(numServiceInfos);
for (int i = 0; i < numServiceInfos; ++i) {
ServiceInfoBo serviceInfoBo = new ServiceInfoBo.Builder(buffer.readPrefixedBytes()).build();
this.serviceInfos.add(serviceInfoBo);
}
}
public Builder serverInfo(String serverInfo) {
this.serverInfo = serverInfo;
return this;
}
public Builder vmArgs(List<String> vmArgs) {
this.vmArgs = vmArgs;
return this;
}
public Builder serviceInfos(List<ServiceInfoBo> serviceInfos) {
this.serviceInfos = serviceInfos;
return this;
}
public ServerMetaDataBo build() {
if (this.serverInfo == null) {
this.serverInfo = "";
}
if (this.vmArgs == null) {
this.vmArgs = Collections.<String> emptyList();
}
if (this.serviceInfos == null) {
this.serviceInfos = Collections.<ServiceInfoBo> emptyList();
}
return new ServerMetaDataBo(this);
}
}
}
@@ -0,0 +1,118 @@
package com.nhn.pinpoint.common.bo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.nhn.pinpoint.common.buffer.AutomaticBuffer;
import com.nhn.pinpoint.common.buffer.Buffer;
import com.nhn.pinpoint.common.buffer.FixedBuffer;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBo {
private final String serviceName;
private final List<String> serviceLibs;
private ServiceInfoBo(Builder builder) {
this.serviceName = builder.serviceName;
this.serviceLibs = builder.serviceLibs;
}
public String getServiceName() {
return this.serviceName;
}
public List<String> getServiceLibs() {
return this.serviceLibs;
}
public byte[] writeValue() {
final Buffer buffer = new AutomaticBuffer();
buffer.put2PrefixedString(this.serviceName);
int numServiceLibs = this.serviceLibs == null ? 0 : this.serviceLibs.size();
buffer.putVar(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
buffer.put2PrefixedString(this.serviceLibs.get(i));
}
return buffer.getBuffer();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ServiceInfoBo{");
sb.append("serviceName='").append(this.serviceName).append('\'');
sb.append(", serviceLibs=").append(this.serviceLibs).append('}');
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((serviceLibs == null) ? 0 : serviceLibs.hashCode());
result = prime * result + ((serviceName == null) ? 0 : serviceName.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;
ServiceInfoBo other = (ServiceInfoBo)obj;
if (serviceLibs == null) {
if (other.serviceLibs != null)
return false;
} else if (!serviceLibs.equals(other.serviceLibs))
return false;
if (serviceName == null) {
if (other.serviceName != null)
return false;
} else if (!serviceName.equals(other.serviceName))
return false;
return true;
}
public static class Builder {
private String serviceName;
private List<String> serviceLibs;
public Builder() {}
public Builder(final byte[] value) {
final Buffer buffer = new FixedBuffer(value);
this.serviceName = buffer.read2PrefixedString();
final int numServiceLibs = buffer.readVarInt();
this.serviceLibs = new ArrayList<String>(numServiceLibs);
for (int i = 0; i < numServiceLibs; ++i) {
this.serviceLibs.add(buffer.read2PrefixedString());
}
}
public Builder serviceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
public Builder serviceLibs(List<String> serviceLibs) {
this.serviceLibs = serviceLibs;
return this;
}
public ServiceInfoBo build() {
if (this.serviceName == null) {
this.serviceName = "";
}
if (this.serviceLibs == null) {
this.serviceLibs = Collections.<String>emptyList();
}
return new ServiceInfoBo(this);
}
}
}
@@ -34,6 +34,7 @@ public final class HBaseTables {
public static final String AGENTINFO = "AgentInfo";
public static final byte[] AGENTINFO_CF_INFO = Bytes.toBytes("Info");
public static final byte[] AGENTINFO_CF_INFO_IDENTIFIER = Bytes.toBytes("i");
public static final byte[] AGENTINFO_CF_INFO_SERVER_META_DATA = Bytes.toBytes("m");
@Deprecated
public static final String AGENTID_APPLICATION_INDEX = "AgentIdApplicationIndex";
@@ -0,0 +1,43 @@
package com.nhn.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
/**
* @author hyungil.jeong
*/
public class ServerMetaDataBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServerMetaDataBo testBo = createTestBo("testServer", Arrays.asList("arg1", "arg2"),
Arrays.asList(ServiceInfoBoTest.createTestBo("testService", Arrays.asList("lib1", "lib2"))));
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServerMetaDataBo testBo = createTestBo(null, null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServerMetaDataBo deserializedBo = new ServerMetaDataBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServerMetaDataBo createTestBo(String serverInfo, List<String> vmArgs, List<ServiceInfoBo> serviceInfos) {
final ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder();
return builder.serverInfo(serverInfo).vmArgs(vmArgs).serviceInfos(serviceInfos).build();
}
}
@@ -0,0 +1,42 @@
package com.nhn.pinpoint.common.bo;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
/**
* @author hyungil.jeong
*/
public class ServiceInfoBoTest {
@Test
public void testByteArrayConversion() {
// Given
final ServiceInfoBo testBo = createTestBo("testService", Arrays.asList("lib1", "lib2"));
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
@Test
public void testByteArrayConversionNullValues() {
// Given
final ServiceInfoBo testBo = createTestBo(null, null);
// When
final byte[] serializedBo = testBo.writeValue();
final ServiceInfoBo deserializedBo = new ServiceInfoBo.Builder(serializedBo).build();
// Then
assertEquals(testBo, deserializedBo);
}
static ServiceInfoBo createTestBo(String serviceName, List<String> serviceLibs) {
final ServiceInfoBo.Builder builder = new ServiceInfoBo.Builder();
return builder.serviceName(serviceName).serviceLibs(serviceLibs).build();
}
}
@@ -34,7 +34,7 @@ public class ServerInstance {
if (agentInfo == null) {
throw new NullPointerException("agentInfo must not be null");
}
this.hostName = agentInfo.getHostname();
this.hostName = agentInfo.getHostName();
this.name = agentInfo.getAgentId();
this.serviceType = agentInfo.getServiceType();
this.agentInfo = agentInfo;
@@ -1,18 +1,18 @@
package com.nhn.pinpoint.web.dao.hbase;
import com.nhn.pinpoint.common.bo.AgentInfoBo;
import com.nhn.pinpoint.common.bo.ServerMetaDataBo;
import com.nhn.pinpoint.common.util.BytesUtils;
import com.nhn.pinpoint.common.util.RowKeyUtils;
import com.nhn.pinpoint.common.util.TimeUtils;
import com.nhn.pinpoint.web.mapper.AgentInfoMapper;
import com.nhn.pinpoint.web.vo.Range;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.ResultsExtractor;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.stereotype.Repository;
import com.nhn.pinpoint.web.dao.AgentInfoDao;
@@ -33,8 +33,6 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
@Autowired
private HbaseOperations2 hbaseOperations2;
private RowMapper<List<AgentInfoBo>> agentInfoMapper = new AgentInfoMapper();
/**
* agentId, startTime을 기반으로 유니크한 AgentInfo를 찾아낸다.
* @param agentId
@@ -77,8 +75,9 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
byte[] row = next.getRow();
long reverseStartTime = BytesUtils.bytesToLong(row, HBaseTables.AGENT_NAME_MAX_LEN);
long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime);
byte[] value = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER);
byte[] serializedAgentInfo = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER);
byte[] serializedServerMetaData = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_SERVER_META_DATA);
logger.debug("found={}, {}, start={}", found, range, startTime);
if (found > 1 && startTime <= range.getFrom()) {
@@ -86,10 +85,11 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
break;
}
final AgentInfoBo agentInfoBo = new AgentInfoBo();
agentInfoBo.setAgentId(agentId);
agentInfoBo.setStartTime(startTime);
agentInfoBo.readValue(value);
final AgentInfoBo.Builder agentInfoBoBuilder = new AgentInfoBo.Builder(serializedAgentInfo).agentId(agentId).startTime(startTime);
if (serializedServerMetaData != null) {
agentInfoBoBuilder.serverMetaData(new ServerMetaDataBo.Builder(serializedServerMetaData).build());
}
final AgentInfoBo agentInfoBo = agentInfoBoBuilder.build();
logger.debug("found agentInfoBo {}", agentInfoBo);
result.add(agentInfoBo);
@@ -102,24 +102,6 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
logger.debug("get agentInfo result, {}", found);
return found;
// F 1382320380000
// S 1382579080389
// T 1382579580000
// F 1382557980000
// S 1382579080389
// T 1382579580000
// byte[] agentIdBytes = Bytes.toBytes(agentId);
// long reverseStartTime = TimeUtils.reverseTimeMillis(from);
// byte[] rowKey = RowKeyUtils.concatFixedByteAndLong(agentIdBytes, HBaseTables.AGENT_NAME_MAX_LEN, reverseStartTime);
//
// Get get = new Get(rowKey);
// get.addFamily(HBaseTables.AGENTINFO_CF_INFO);
//
// List<AgentInfoBo> agentInfoBoList = hbaseOperations2.get(HBaseTables.AGENTINFO, get, agentInfoMapper);
// return agentInfoBoList;
}
/**
@@ -148,11 +130,14 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
logger.debug("agent:{} startTime value {}", agentId, startTime);
// 바로 전 시작 시간을 찾아야 한다.
if (startTime < currentTime) {
byte[] value = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER);
AgentInfoBo agentInfoBo = new AgentInfoBo();
agentInfoBo.setAgentId(agentId);
agentInfoBo.setStartTime(startTime);
agentInfoBo.readValue(value);
byte[] serializedAgentInfo = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_IDENTIFIER);
byte[] serializedServerMetaData = next.getValue(HBaseTables.AGENTINFO_CF_INFO, HBaseTables.AGENTINFO_CF_INFO_SERVER_META_DATA);
final AgentInfoBo.Builder agentInfoBoBuilder = new AgentInfoBo.Builder(serializedAgentInfo).agentId(agentId).startTime(startTime);
if (serializedServerMetaData != null) {
agentInfoBoBuilder.serverMetaData(new ServerMetaDataBo.Builder(serializedServerMetaData).build());
}
final AgentInfoBo agentInfoBo = agentInfoBoBuilder.build();
logger.debug("agent:{} startTime find {}", agentId, startTime);
@@ -42,19 +42,13 @@ public class AgentInfoMapper implements RowMapper<List<AgentInfoBo>> {
}
private AgentInfoBo mappingAgentInfo(KeyValue keyValue) {
AgentInfoBo agentInfoBo = new AgentInfoBo();
agentInfoBo.readValue(keyValue.getValue());
byte[] rowKey = keyValue.getRow();
String agentId = Bytes.toString(rowKey, 0, PinpointConstants.AGENT_NAME_MAX_LEN - 1).trim();
agentInfoBo.setAgentId(agentId);
long reverseStartTime = BytesUtils.bytesToLong(rowKey, PinpointConstants.AGENT_NAME_MAX_LEN);
long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime);
agentInfoBo.setStartTime(startTime);
AgentInfoBo agentInfoBo = new AgentInfoBo.Builder(keyValue.getValue()).agentId(agentId).startTime(startTime).build();
logger.debug("agentInfo:{}", agentInfoBo);
return agentInfoBo;
}
}
@@ -62,7 +62,7 @@ public class AgentInfoServiceImpl implements AgentInfoService {
// FIXME 지금은 그냥 첫 번재꺼 사용. 여러개 검사?는 나중에 생각해볼 예정.
AgentInfoBo agentInfo = agentInfoList.get(0);
String hostname = agentInfo.getHostname();
String hostname = agentInfo.getHostName();
if (result.containsKey(hostname)) {
result.get(hostname).add(agentInfo);
@@ -7,4 +7,4 @@ hbase.client.host=10.101.17.108
# ??
#hbase.client.host=10.25.149.61
hbase.client.port=2181
hbase.htable.threads.max=128
hbase.htable.threads.max=4
@@ -35,7 +35,7 @@ pinpointApp.directive('agentInfo', [ 'agentInfoConfig', '$timeout', 'Alerts', 'P
scope.info = {
'agentId': agent.agentId,
'applicationName': agent.applicationName,
'hostname': agent.hostname,
'hostName': agent.hostName,
'ip': agent.ip,
'serviceType': agent.serviceType,
'pid': agent.pid,
+1 -1
View File
@@ -21,7 +21,7 @@
</tr>
<tr>
<td class="text-right">Hostname :</td>
<td>{{info.hostname}}</td>
<td>{{info.hostName}}</td>
</tr>
<tr>
<td class="text-right">IP :</td>
@@ -23,10 +23,7 @@ public class ServerInstanceListSerializerTest {
@Test
public void testSerialize() throws Exception {
ServerBuilder builder = new ServerBuilder();
AgentInfoBo agentInfoBo = new AgentInfoBo();
agentInfoBo.setAgentId("agentId");
agentInfoBo.setServiceType(ServiceType.TOMCAT);
agentInfoBo.setHostname("testcomputer");
AgentInfoBo agentInfoBo = new AgentInfoBo.Builder().agentId("agentId").serviceType(ServiceType.TOMCAT).hostName("testcomputer").build();
HashSet<AgentInfoBo> set = new HashSet<AgentInfoBo>();
set.add(agentInfoBo);
builder.addAgentInfo(set);