From 260a9b49ed07b124ebe44a7fa43ae22b99fa39ee Mon Sep 17 00:00:00 2001 From: Hyun Jeong Date: Wed, 22 Oct 2014 10:32:56 +0900 Subject: [PATCH] [#15] implemented backend handling of server meta data --- .../dao/hbase/HbaseAgentInfoDao.java | 29 +- .../mapper/thrift/AgentInfoBoMapper.java | 32 ++ .../mapper/thrift/ServerMetaDataBoMapper.java | 43 +++ .../thrift/ServerMetaDataBoMapperTest.java | 70 +++++ .../pinpoint/common/bo/AgentInfoBo.java | 290 +++++++++++------- .../pinpoint/common/bo/ServerMetaDataBo.java | 152 +++++++++ .../pinpoint/common/bo/ServiceInfoBo.java | 118 +++++++ .../pinpoint/common/hbase/HBaseTables.java | 1 + .../common/bo/ServerMetaDataBoTest.java | 43 +++ .../pinpoint/common/bo/ServiceInfoBoTest.java | 42 +++ .../web/applicationmap/ServerInstance.java | 2 +- .../web/dao/hbase/HbaseAgentInfoDao.java | 51 ++- .../pinpoint/web/mapper/AgentInfoMapper.java | 8 +- .../web/service/AgentInfoServiceImpl.java | 2 +- web/src/main/resources-local/hbase.properties | 2 +- .../webapp/scripts/directives/agentInfo.js | 2 +- web/src/main/webapp/views/agentInfoMain.html | 2 +- .../ServerInstanceListSerializerTest.java | 5 +- 18 files changed, 724 insertions(+), 170 deletions(-) create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/AgentInfoBoMapper.java create mode 100644 collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapper.java create mode 100644 collector/src/test/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapperTest.java create mode 100644 commons/src/main/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBo.java create mode 100644 commons/src/main/java/com/navercorp/pinpoint/common/bo/ServiceInfoBo.java create mode 100644 commons/src/test/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBoTest.java create mode 100644 commons/src/test/java/com/navercorp/pinpoint/common/bo/ServiceInfoBoTest.java diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java index 6881bb5ad..902a2f8bb 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/dao/hbase/HbaseAgentInfoDao.java @@ -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 agentInfoBoMapper; + + @Autowired + @Qualifier("serverMetaDataBoMapper") + private ThriftBoMapper 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); } } diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/AgentInfoBoMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/AgentInfoBoMapper.java new file mode 100644 index 000000000..c5fe8b14f --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/AgentInfoBoMapper.java @@ -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 { + + @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(); + } + +} diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapper.java b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapper.java new file mode 100644 index 000000000..31c8ddc09 --- /dev/null +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapper.java @@ -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 { + + @Override + public ServerMetaDataBo map(TServerMetaData thriftObject) { + final String serverInfo = thriftObject.getServerInfo(); + final List vmArgs = thriftObject.getVmArgs(); + ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder().serverInfo(serverInfo).vmArgs(vmArgs); + if (thriftObject.isSetServiceInfos()) { + final List serviceInfos = new ArrayList(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. emptyList()).build(); + } + } + + private ServiceInfoBo mapServiceInfo(TServiceInfo serviceInfo) { + final String serviceName = serviceInfo.getServiceName(); + final List serviceLibs = serviceInfo.getServiceLibs(); + return new ServiceInfoBo.Builder().serviceName(serviceName).serviceLibs(serviceLibs).build(); + } + +} diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapperTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapperTest.java new file mode 100644 index 000000000..d589b6b83 --- /dev/null +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/mapper/thrift/ServerMetaDataBoMapperTest.java @@ -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 tServiceInfos = Arrays.asList(tServiceInfo); + tServerMetaData.setServiceInfos(tServiceInfos); + // When + ServerMetaDataBo serverMetaData = mapper.map(tServerMetaData); + List 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()); + } + +} diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/bo/AgentInfoBo.java b/commons/src/main/java/com/navercorp/pinpoint/common/bo/AgentInfoBo.java index 7a7ed04ff..7bce742b8 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/bo/AgentInfoBo.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/bo/AgentInfoBo.java @@ -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 AGENT_NAME_ASC_COMPARATOR = new Comparator() { @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); + } + } } diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBo.java b/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBo.java new file mode 100644 index 000000000..e531890f8 --- /dev/null +++ b/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBo.java @@ -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 vmArgs; + private final List 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 getVmArgs() { + return this.vmArgs; + } + + public List 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 vmArgs; + private List 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(numVmArgs); + for (int i = 0; i < numVmArgs; ++i) { + this.vmArgs.add(buffer.read2PrefixedString()); + } + final int numServiceInfos = buffer.readVarInt(); + this.serviceInfos = new ArrayList(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 vmArgs) { + this.vmArgs = vmArgs; + return this; + } + + public Builder serviceInfos(List serviceInfos) { + this.serviceInfos = serviceInfos; + return this; + } + + public ServerMetaDataBo build() { + if (this.serverInfo == null) { + this.serverInfo = ""; + } + if (this.vmArgs == null) { + this.vmArgs = Collections. emptyList(); + } + if (this.serviceInfos == null) { + this.serviceInfos = Collections. emptyList(); + } + return new ServerMetaDataBo(this); + } + } +} diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServiceInfoBo.java b/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServiceInfoBo.java new file mode 100644 index 000000000..8031a00be --- /dev/null +++ b/commons/src/main/java/com/navercorp/pinpoint/common/bo/ServiceInfoBo.java @@ -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 serviceLibs; + + private ServiceInfoBo(Builder builder) { + this.serviceName = builder.serviceName; + this.serviceLibs = builder.serviceLibs; + } + + public String getServiceName() { + return this.serviceName; + } + + public List 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 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(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 serviceLibs) { + this.serviceLibs = serviceLibs; + return this; + } + + public ServiceInfoBo build() { + if (this.serviceName == null) { + this.serviceName = ""; + } + if (this.serviceLibs == null) { + this.serviceLibs = Collections.emptyList(); + } + return new ServiceInfoBo(this); + } + } +} diff --git a/commons/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java b/commons/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java index 5b9765101..316e70fdc 100644 --- a/commons/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java +++ b/commons/src/main/java/com/navercorp/pinpoint/common/hbase/HBaseTables.java @@ -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"; diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBoTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBoTest.java new file mode 100644 index 000000000..aa5b041f7 --- /dev/null +++ b/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServerMetaDataBoTest.java @@ -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 vmArgs, List serviceInfos) { + final ServerMetaDataBo.Builder builder = new ServerMetaDataBo.Builder(); + return builder.serverInfo(serverInfo).vmArgs(vmArgs).serviceInfos(serviceInfos).build(); + } + +} diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServiceInfoBoTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServiceInfoBoTest.java new file mode 100644 index 000000000..e873c3558 --- /dev/null +++ b/commons/src/test/java/com/navercorp/pinpoint/common/bo/ServiceInfoBoTest.java @@ -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 serviceLibs) { + final ServiceInfoBo.Builder builder = new ServiceInfoBo.Builder(); + return builder.serviceName(serviceName).serviceLibs(serviceLibs).build(); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstance.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstance.java index d90db93e8..055dcfe4c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstance.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerInstance.java @@ -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; diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java index 027c8bae0..9df8e2ac8 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentInfoDao.java @@ -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> 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 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); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoMapper.java b/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoMapper.java index f4eb703d7..50bf5bf13 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoMapper.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/mapper/AgentInfoMapper.java @@ -42,19 +42,13 @@ public class AgentInfoMapper implements RowMapper> { } 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; } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java index 5e76e9b20..057ba58fc 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java @@ -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); diff --git a/web/src/main/resources-local/hbase.properties b/web/src/main/resources-local/hbase.properties index 286867a44..db5d365e0 100644 --- a/web/src/main/resources-local/hbase.properties +++ b/web/src/main/resources-local/hbase.properties @@ -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 \ No newline at end of file +hbase.htable.threads.max=4 \ No newline at end of file diff --git a/web/src/main/webapp/scripts/directives/agentInfo.js b/web/src/main/webapp/scripts/directives/agentInfo.js index d37eb62a0..8313fabc8 100644 --- a/web/src/main/webapp/scripts/directives/agentInfo.js +++ b/web/src/main/webapp/scripts/directives/agentInfo.js @@ -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, diff --git a/web/src/main/webapp/views/agentInfoMain.html b/web/src/main/webapp/views/agentInfoMain.html index 1b263b7a9..5227326f3 100644 --- a/web/src/main/webapp/views/agentInfoMain.html +++ b/web/src/main/webapp/views/agentInfoMain.html @@ -21,7 +21,7 @@ Hostname : - {{info.hostname}} + {{info.hostName}} IP : diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java index dd3f7c1a6..008f2bf73 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java @@ -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 set = new HashSet(); set.add(agentInfoBo); builder.addAgentInfo(set);