diff --git a/apm-collector/apm-collector-agentregister/pom.xml b/apm-collector/apm-collector-agentregister/pom.xml
index fccbd8c1d51d74d0ec96d1decae223724e797153..0195c1d837a5d16e6a261069dd7c0d87139bdb52 100644
--- a/apm-collector/apm-collector-agentregister/pom.xml
+++ b/apm-collector/apm-collector-agentregister/pom.xml
@@ -51,5 +51,10 @@
apm-network
${project.version}
+
+ org.skywalking
+ apm-collector-cache
+ ${project.version}
+
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/application/ApplicationIDService.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/application/ApplicationIDService.java
index 22ab9ad8f393e5ab13edf8bb1f546619aa30ffb4..bfdc125c36a1c0848c269ba93bb1ceca9b3aeab5 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/application/ApplicationIDService.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/application/ApplicationIDService.java
@@ -19,7 +19,7 @@
package org.skywalking.apm.collector.agentregister.application;
import org.skywalking.apm.collector.agentregister.worker.application.ApplicationRegisterRemoteWorker;
-import org.skywalking.apm.collector.agentregister.worker.cache.ApplicationCache;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine;
import org.skywalking.apm.collector.stream.StreamModuleContext;
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/servicename/ServiceNameService.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/servicename/ServiceNameService.java
index 1ab804fcdc2f938cbfddd43edb7efe04ffd16c54..fa0a0de23113211e0ec401279f3f2d6b19eb133d 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/servicename/ServiceNameService.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/servicename/ServiceNameService.java
@@ -19,7 +19,7 @@
package org.skywalking.apm.collector.agentregister.servicename;
import org.skywalking.apm.collector.agentregister.worker.servicename.ServiceNameRegisterRemoteWorker;
-import org.skywalking.apm.collector.agentregister.worker.servicename.dao.IServiceNameDAO;
+import org.skywalking.apm.collector.cache.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefine;
@@ -38,7 +38,7 @@ public class ServiceNameService {
private final Logger logger = LoggerFactory.getLogger(ServiceNameService.class);
public int getOrCreate(int applicationId, String serviceName) {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
+ IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
int serviceId = dao.getServiceId(applicationId, serviceName);
if (serviceId == 0) {
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/ApplicationRegisterSerialWorker.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/ApplicationRegisterSerialWorker.java
index be62b927f7c22550cce536a11bf2a838bf157dd7..fcfd356e2cf12399e1922add7a359a30a8b06faf 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/ApplicationRegisterSerialWorker.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/ApplicationRegisterSerialWorker.java
@@ -20,6 +20,7 @@ package org.skywalking.apm.collector.agentregister.worker.application;
import org.skywalking.apm.collector.agentregister.worker.IdAutoIncrement;
import org.skywalking.apm.collector.agentregister.worker.application.dao.IApplicationDAO;
+import org.skywalking.apm.collector.cache.dao.IApplicationCacheDAO;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.DataDefine;
@@ -55,8 +56,10 @@ public class ApplicationRegisterSerialWorker extends AbstractLocalAsyncWorker {
ApplicationDataDefine.Application application = (ApplicationDataDefine.Application)message;
logger.debug("register application, application code: {}", application.getApplicationCode());
+ IApplicationCacheDAO cacheDao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
+ int applicationId = cacheDao.getApplicationId(application.getApplicationCode());
+
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
- int applicationId = dao.getApplicationId(application.getApplicationCode());
if (applicationId == 0) {
int min = dao.getMinApplicationId();
if (min == 0) {
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationEsDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationEsDAO.java
index 77035cce9dbd6181d88a80b40564fa1f4ac981e7..56c9126bb89d230b0656adc9c4e605db8add9848 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationEsDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationEsDAO.java
@@ -21,12 +21,7 @@ package org.skywalking.apm.collector.agentregister.worker.application.dao;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.WriteRequest;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.SearchHit;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine;
import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
@@ -41,24 +36,6 @@ public class ApplicationEsDAO extends EsDAO implements IApplicationDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationEsDAO.class);
- @Override public int getApplicationId(String applicationCode) {
- ElasticSearchClient client = getClient();
-
- SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE);
- searchRequestBuilder.setTypes("type");
- searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
- searchRequestBuilder.setQuery(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode));
- searchRequestBuilder.setSize(1);
-
- SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
- if (searchResponse.getHits().totalHits > 0) {
- SearchHit searchHit = searchResponse.getHits().iterator().next();
- int applicationId = (int)searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID);
- return applicationId;
- }
- return 0;
- }
-
@Override public int getMaxApplicationId() {
return getMaxId(ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
}
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationH2DAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationH2DAO.java
index fdb6c963bdcaa52b0b37a667ca2a3ca82482364c..e63ceb38b4172a642786fa6ba906e4ad8f2a9187 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationH2DAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/ApplicationH2DAO.java
@@ -18,7 +18,6 @@
package org.skywalking.apm.collector.agentregister.worker.application.dao;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine;
@@ -34,14 +33,6 @@ import org.slf4j.LoggerFactory;
public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
private final Logger logger = LoggerFactory.getLogger(ApplicationH2DAO.class);
private static final String INSERT_APPLICATION_SQL = "insert into {0}({1}, {2}) values(?, ?)";
- @Override
- public int getApplicationId(String applicationCode) {
- logger.info("get the application id with application code = {}", applicationCode);
- String sql = "select " + ApplicationTable.COLUMN_APPLICATION_ID + " from " +
- ApplicationTable.TABLE + " where " + ApplicationTable.COLUMN_APPLICATION_CODE + "='" + applicationCode + "'";
-
- return getIntValueBySQL(sql);
- }
@Override
public int getMaxApplicationId() {
@@ -57,7 +48,7 @@ public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
public void save(ApplicationDataDefine.Application application) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(INSERT_APPLICATION_SQL, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID,
- ApplicationTable.COLUMN_APPLICATION_CODE);
+ ApplicationTable.COLUMN_APPLICATION_CODE);
Object[] params = new Object[] {application.getApplicationId(), application.getApplicationCode()};
try {
client.execute(sql, params);
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/IApplicationDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/IApplicationDAO.java
index ae965d6b06020bf2ee2eb4fc64640d27f72ec063..541ec632925606301ac2a7ad537f7cb3867ad110 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/IApplicationDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/application/dao/IApplicationDAO.java
@@ -24,8 +24,6 @@ import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefin
* @author pengys5
*/
public interface IApplicationDAO {
- int getApplicationId(String applicationCode);
-
int getMaxApplicationId();
int getMinApplicationId();
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/IInstanceDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/IInstanceDAO.java
index 0a51717cd6b00aed20a9442f3896ea04eafcf3bf..30d73be459ae91dc095824d1b83abc94f15911b6 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/IInstanceDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/IInstanceDAO.java
@@ -33,6 +33,4 @@ public interface IInstanceDAO {
void save(InstanceDataDefine.Instance instance);
void updateHeartbeatTime(int instanceId, long heartbeatTime);
-
- int getApplicationId(int applicationInstanceId);
}
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceEsDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceEsDAO.java
index 866d3f08e7864d7bd622e88f3f9243b4078186b2..cdebd628cc451b4b2fe8f6167f9e84447b248b03 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceEsDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceEsDAO.java
@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.agentregister.worker.instance.dao;
import java.util.HashMap;
import java.util.Map;
-import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
@@ -101,13 +100,4 @@ public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
updateRequest.doc(source);
client.update(updateRequest);
}
-
- @Override public int getApplicationId(int applicationInstanceId) {
- GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(applicationInstanceId)).get();
- if (response.isExists()) {
- return (int)response.getSource().get(InstanceTable.COLUMN_APPLICATION_ID);
- } else {
- return 0;
- }
- }
}
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceH2DAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceH2DAO.java
index 39a352d4f0f9c762a0890582d9b36891f1467f1d..11cc4f35c09e75131c7b383f2e40674ad0986300 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceH2DAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/instance/dao/InstanceH2DAO.java
@@ -22,7 +22,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
@@ -37,15 +36,16 @@ import org.slf4j.LoggerFactory;
*/
public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceH2DAO.class);
+
private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?";
- private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?";
private static final String UPDATE_HEARTBEAT_TIME_SQL = "updatte {0} set {1} = ? where {2} = ?";
+
@Override public int getInstanceId(int applicationId, String agentUUID) {
logger.info("get the application id with application id = {}, agentUUID = {}", applicationId, agentUUID);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID,
- InstanceTable.COLUMN_AGENT_UUID);
- Object[] params = new Object[]{applicationId, agentUUID};
+ InstanceTable.COLUMN_AGENT_UUID);
+ Object[] params = new Object[] {applicationId, agentUUID};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID);
@@ -85,7 +85,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME,
- InstanceTable.COLUMN_INSTANCE_ID);
+ InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] {heartbeatTime, instanceId};
try {
client.execute(sql, params);
@@ -93,19 +93,4 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
logger.error(e.getMessage(), e);
}
}
-
- @Override public int getApplicationId(int applicationInstanceId) {
- logger.info("get the application id with application id = {}", applicationInstanceId);
- H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID);
- Object[] params = new Object[]{applicationInstanceId};
- try (ResultSet rs = client.executeQuery(sql, params)) {
- if (rs.next()) {
- return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
- }
- } catch (SQLException | H2ClientException e) {
- logger.error(e.getMessage(), e);
- }
- return 0;
- }
}
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/ServiceNameRegisterSerialWorker.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/ServiceNameRegisterSerialWorker.java
index 67aa4960ece9479f154e270ce770de2dbbe99c21..396542d39a5f1376c148aa17c841c727ed1bf891 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/ServiceNameRegisterSerialWorker.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/ServiceNameRegisterSerialWorker.java
@@ -20,6 +20,7 @@ package org.skywalking.apm.collector.agentregister.worker.servicename;
import org.skywalking.apm.collector.agentregister.worker.IdAutoIncrement;
import org.skywalking.apm.collector.agentregister.worker.servicename.dao.IServiceNameDAO;
+import org.skywalking.apm.collector.cache.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.DataDefine;
@@ -55,9 +56,10 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker {
ServiceNameDataDefine.ServiceName serviceName = (ServiceNameDataDefine.ServiceName)message;
logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId());
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
- int serviceId = dao.getServiceId(serviceName.getApplicationId(), serviceName.getServiceName());
+ IServiceNameCacheDAO cacheDao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
+ int serviceId = cacheDao.getServiceId(serviceName.getApplicationId(), serviceName.getServiceName());
+ IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
if (serviceId == 0) {
int min = dao.getMinServiceId();
if (min == 0) {
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/IServiceNameDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/IServiceNameDAO.java
index a407468c0c48e697d91a73c4100fa3041943ce6a..94c5351974e9471ea6150e6c940999c00634f9f1 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/IServiceNameDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/IServiceNameDAO.java
@@ -24,10 +24,6 @@ import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefin
* @author pengys5
*/
public interface IServiceNameDAO {
- int getServiceId(int applicationId, String serviceName);
-
- String getServiceName(int serviceId);
-
int getMaxServiceId();
int getMinServiceId();
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameEsDAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameEsDAO.java
index 28b2ab01c0f1544a5393bb96f342ebce03de580c..b79d7961727e942ea7c2fcf54201d0b44435d37f 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameEsDAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameEsDAO.java
@@ -20,17 +20,9 @@ package org.skywalking.apm.collector.agentregister.worker.servicename.dao;
import java.util.HashMap;
import java.util.Map;
-import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.support.WriteRequest;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.SearchHit;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
-import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefine;
import org.skywalking.apm.collector.storage.define.register.ServiceNameTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
@@ -44,27 +36,6 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
private final Logger logger = LoggerFactory.getLogger(ServiceNameEsDAO.class);
- @Override public int getServiceId(int applicationId, String serviceName) {
- ElasticSearchClient client = getClient();
-
- SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ServiceNameTable.TABLE);
- searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
- searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
- BoolQueryBuilder builder = QueryBuilders.boolQuery();
- builder.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId));
- builder.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName));
- searchRequestBuilder.setQuery(builder);
- searchRequestBuilder.setSize(1);
-
- SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
- if (searchResponse.getHits().totalHits > 0) {
- SearchHit searchHit = searchResponse.getHits().iterator().next();
- int serviceId = (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID);
- return serviceId;
- }
- return 0;
- }
-
@Override public int getMaxServiceId() {
return getMaxId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
}
@@ -73,15 +44,6 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
}
- @Override public String getServiceName(int serviceId) {
- GetResponse response = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId)).get();
- if (response.isExists()) {
- return (String)response.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME);
- } else {
- return Const.EMPTY_STRING;
- }
- }
-
@Override public void save(ServiceNameDataDefine.ServiceName serviceName) {
logger.debug("save service name register info, application id: {}, service name: {}", serviceName.getApplicationId(), serviceName.getServiceName());
ElasticSearchClient client = getClient();
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameH2DAO.java b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameH2DAO.java
index df85fcc20eb61482e12a43119681a79531170cf7..b224a578ef2dcd73f2ea1e9517ffdc4cb1cd841b 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameH2DAO.java
+++ b/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/servicename/dao/ServiceNameH2DAO.java
@@ -18,14 +18,10 @@
package org.skywalking.apm.collector.agentregister.worker.servicename.dao;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
-import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefine;
import org.skywalking.apm.collector.storage.define.register.ServiceNameTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
@@ -38,24 +34,6 @@ import org.slf4j.LoggerFactory;
*/
public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
private final Logger logger = LoggerFactory.getLogger(ServiceNameH2DAO.class);
- private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1";
- private static final String GET_SERVICE_NAME_SQL = "select {0} from {1} where {2} = ?";
-
- @Override
- public int getServiceId(int applicationId, String serviceName) {
- H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
- ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
- Object[] params = new Object[]{applicationId, serviceName};
- try (ResultSet rs = client.executeQuery(sql, params)) {
- if (rs.next()) {
- return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
- }
- } catch (SQLException | H2ClientException e) {
- logger.error(e.getMessage(), e);
- }
- return 0;
- }
@Override
public int getMaxServiceId() {
@@ -67,28 +45,11 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
return getMinId(ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
}
-
- @Override
- public String getServiceName(int serviceId) {
- H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
- ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
- Object[] params = new Object[]{serviceId};
- try (ResultSet rs = client.executeQuery(sql, params)) {
- if (rs.next()) {
- return rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME);
- }
- } catch (SQLException | H2ClientException e) {
- logger.error(e.getMessage(), e);
- }
- return Const.EMPTY_STRING;
- }
-
@Override
public void save(ServiceNameDataDefine.ServiceName serviceName) {
logger.debug("save service name register info, application id: {}, service name: {}", serviceName.getApplicationId(), serviceName.getServiceName());
H2Client client = getClient();
- Map source = new HashMap();
+ Map source = new HashMap<>();
source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
diff --git a/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleGroupDefine.java b/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleGroupDefine.java
index 2aca5aae71d253f8c67dd0c74a18cbcef5535064..c3567257aa53dcfbc4312d6a854bfac3b2e21af0 100644
--- a/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleGroupDefine.java
+++ b/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.agentserver;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -28,10 +29,10 @@ import org.skywalking.apm.collector.core.module.ModuleInstaller;
public class AgentServerModuleGroupDefine implements ModuleGroupDefine {
public static final String GROUP_NAME = "agent_server";
- private final AgentServerCommonModuleInstaller installer;
+ private final AgentServerModuleInstaller installer;
public AgentServerModuleGroupDefine() {
- installer = new AgentServerCommonModuleInstaller();
+ installer = new AgentServerModuleInstaller();
}
@Override public String name() {
@@ -45,4 +46,8 @@ public class AgentServerModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerCommonModuleInstaller.java b/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleInstaller.java
similarity index 87%
rename from apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerCommonModuleInstaller.java
rename to apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleInstaller.java
index 6f209a55010817b00967493ab6eb4ab12734cc63..eaad79ba3bec56d13ae8f7ce27da1923a17f4545 100644
--- a/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerCommonModuleInstaller.java
+++ b/apm-collector/apm-collector-agentserver/src/main/java/org/skywalking/apm/collector/agentserver/AgentServerModuleInstaller.java
@@ -20,12 +20,12 @@ package org.skywalking.apm.collector.agentserver;
import java.util.List;
import org.skywalking.apm.collector.core.framework.Context;
-import org.skywalking.apm.collector.core.module.MultipleCommonModuleInstaller;
+import org.skywalking.apm.collector.core.module.MultipleModuleInstaller;
/**
* @author pengys5
*/
-public class AgentServerCommonModuleInstaller extends MultipleCommonModuleInstaller {
+public class AgentServerModuleInstaller extends MultipleModuleInstaller {
@Override public String groupName() {
return AgentServerModuleGroupDefine.GROUP_NAME;
diff --git a/apm-collector/apm-collector-agentstream/pom.xml b/apm-collector/apm-collector-agentstream/pom.xml
index a3cef0409be6236d95c3d8e433d5ac696a721dc8..a56cb3dc397ea5b77a73326d5aed1372c59608f2 100644
--- a/apm-collector/apm-collector-agentstream/pom.xml
+++ b/apm-collector/apm-collector-agentstream/pom.xml
@@ -61,5 +61,10 @@
apm-collector-agentregister
${project.version}
+
+ org.skywalking
+ apm-collector-cache
+ ${project.version}
+
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamCommonModuleInstaller.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamCommonModuleInstaller.java
deleted file mode 100644
index fd8ea647da64c8dd706b6a1aee50194ffc1715fd..0000000000000000000000000000000000000000
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamCommonModuleInstaller.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017, OpenSkywalking Organization All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project repository: https://github.com/OpenSkywalking/skywalking
- */
-
-package org.skywalking.apm.collector.agentstream;
-
-import java.util.List;
-import org.skywalking.apm.collector.agentstream.worker.storage.PersistenceTimer;
-import org.skywalking.apm.collector.core.client.ClientException;
-import org.skywalking.apm.collector.core.config.ConfigException;
-import org.skywalking.apm.collector.core.framework.Context;
-import org.skywalking.apm.collector.core.framework.DefineException;
-import org.skywalking.apm.collector.core.module.MultipleCommonModuleInstaller;
-import org.skywalking.apm.collector.core.server.ServerException;
-
-/**
- * @author pengys5
- */
-public class AgentStreamCommonModuleInstaller extends MultipleCommonModuleInstaller {
-
- @Override public String groupName() {
- return AgentStreamModuleGroupDefine.GROUP_NAME;
- }
-
- @Override public Context moduleContext() {
- return new AgentStreamModuleContext(groupName());
- }
-
- @Override public List dependenceModules() {
- return null;
- }
-
- @Override public void install() throws DefineException, ConfigException, ServerException, ClientException {
- super.install();
- new PersistenceTimer().start();
- }
-}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupConfigParser.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupConfigParser.java
new file mode 100644
index 0000000000000000000000000000000000000000..a22f7b331a50bb15e014361bba6cdfab8ff56cf0
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupConfigParser.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream;
+
+import java.util.Map;
+import org.skywalking.apm.collector.agentstream.config.BufferFileConfig;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
+
+/**
+ * @author pengys5
+ */
+public class AgentStreamModuleGroupConfigParser implements GroupConfigParser {
+
+ private static final String BUFFER_OFFSET_MAX_FILE_SIZE = "buffer_offset_max_file_size";
+ private static final String BUFFER_SEGMENT_MAX_FILE_SIZE = "buffer_segment_max_file_size";
+
+ @Override public void parse(Map config) {
+ if (config.containsKey(GroupConfigParser.NODE_NAME)) {
+ Map groupConfig = config.get(GroupConfigParser.NODE_NAME);
+
+ if (groupConfig.containsKey(BUFFER_OFFSET_MAX_FILE_SIZE)) {
+ String sizeStr = groupConfig.get(BUFFER_OFFSET_MAX_FILE_SIZE).toUpperCase();
+ if (sizeStr.endsWith("K")) {
+ int size = Integer.parseInt(sizeStr.replace("K", ""));
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = size * 1024;
+ } else if (sizeStr.endsWith("KB")) {
+ int size = Integer.parseInt(sizeStr.replace("KB", ""));
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = size * 1024;
+ } else if (sizeStr.endsWith("M")) {
+ int size = Integer.parseInt(sizeStr.replace("M", ""));
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = size * 1024 * 1024;
+ } else if (sizeStr.endsWith("MB")) {
+ int size = Integer.parseInt(sizeStr.replace("MB", ""));
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = size * 1024 * 1024;
+ } else {
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ }
+ } else {
+ BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ }
+
+ if (groupConfig.containsKey(BUFFER_SEGMENT_MAX_FILE_SIZE)) {
+ String sizeStr = groupConfig.get(BUFFER_SEGMENT_MAX_FILE_SIZE).toUpperCase();
+ if (sizeStr.endsWith("K")) {
+ int size = Integer.parseInt(sizeStr.replace("K", ""));
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = size * 1024;
+ } else if (sizeStr.endsWith("KB")) {
+ int size = Integer.parseInt(sizeStr.replace("KB", ""));
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = size * 1024;
+ } else if (sizeStr.endsWith("M")) {
+ int size = Integer.parseInt(sizeStr.replace("M", ""));
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = size * 1024 * 1024;
+ } else if (sizeStr.endsWith("MB")) {
+ int size = Integer.parseInt(sizeStr.replace("MB", ""));
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = size * 1024 * 1024;
+ } else {
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = 1024 * 1024;
+ }
+ } else {
+ BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE = 1024 * 1024;
+ }
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupDefine.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupDefine.java
index bd1db1bbfbe347e8f47458df389198d5e7a1f645..bfc1b745fdbaf20c35d2908e0437106b4678949f 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupDefine.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.agentstream;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -45,4 +46,8 @@ public class AgentStreamModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return new AgentStreamModuleGroupConfigParser();
+ }
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleInstaller.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleInstaller.java
index ebb9d08ded0aaf142c896d67a2ec889460489c3e..e8b941a63f807514abfd451d1f315be35d38cb6d 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleInstaller.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/AgentStreamModuleInstaller.java
@@ -24,13 +24,13 @@ import org.skywalking.apm.collector.core.client.ClientException;
import org.skywalking.apm.collector.core.config.ConfigException;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.framework.DefineException;
-import org.skywalking.apm.collector.core.module.MultipleCommonModuleInstaller;
+import org.skywalking.apm.collector.core.module.MultipleModuleInstaller;
import org.skywalking.apm.collector.core.server.ServerException;
/**
* @author pengys5
*/
-public class AgentStreamModuleInstaller extends MultipleCommonModuleInstaller {
+public class AgentStreamModuleInstaller extends MultipleModuleInstaller {
@Override public String groupName() {
return AgentStreamModuleGroupDefine.GROUP_NAME;
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/config/BufferFileConfig.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/config/BufferFileConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..4853865dd8b64b57780c5865efd0c97c6e1d6c3c
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/config/BufferFileConfig.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.config;
+
+/**
+ * @author pengys5
+ */
+public class BufferFileConfig {
+ public static int BUFFER_OFFSET_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static int BUFFER_SEGMENT_MAX_FILE_SIZE = 10 * 1024 * 1024;
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandler.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandler.java
index 5c41f697d6ed0e31019b7be579f787dec4eb7840..a5ceaae34a30ac39fe14e8edcf1bf5e21dfdf17c 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandler.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandler.java
@@ -18,15 +18,11 @@
package org.skywalking.apm.collector.agentstream.grpc.handler;
-import com.google.protobuf.InvalidProtocolBufferException;
import io.grpc.stub.StreamObserver;
-import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.segment.SegmentParse;
import org.skywalking.apm.collector.server.grpc.GRPCHandler;
import org.skywalking.apm.network.proto.Downstream;
-import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.skywalking.apm.network.proto.TraceSegmentServiceGrpc;
-import org.skywalking.apm.network.proto.UniqueId;
import org.skywalking.apm.network.proto.UpstreamSegment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,13 +39,7 @@ public class TraceSegmentServiceHandler extends TraceSegmentServiceGrpc.TraceSeg
@Override public void onNext(UpstreamSegment segment) {
logger.debug("receive segment");
SegmentParse segmentParse = new SegmentParse();
- try {
- List traceIds = segment.getGlobalTraceIdsList();
- TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment());
- segmentParse.parse(traceIds, segmentObject);
- } catch (InvalidProtocolBufferException e) {
- logger.error(e.getMessage(), e);
- }
+ segmentParse.parse(segment, SegmentParse.Source.Agent);
}
@Override public void onError(Throwable throwable) {
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/TraceSegmentServletHandler.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/TraceSegmentServletHandler.java
index 67bef6dbaf0370a8c847006ec99ffd0f63f60f4f..4bf5add42f4f182f16e11a3704b86e4605b5684f 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/TraceSegmentServletHandler.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/TraceSegmentServletHandler.java
@@ -66,7 +66,7 @@ public class TraceSegmentServletHandler extends JettyHandler {
while (reader.hasNext()) {
SegmentParse segmentParse = new SegmentParse();
TraceSegment traceSegment = jsonReader.read(reader);
- segmentParse.parse(traceSegment.getGlobalTraceIds(), traceSegment.getTraceSegmentObject());
+ segmentParse.parse(traceSegment.getUpstreamSegment(), SegmentParse.Source.Agent);
}
reader.endArray();
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/SegmentJsonReader.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/SegmentJsonReader.java
index 9a1cab79e2a9be9de1508ca24fc4a97d0d9dffa7..32d1df915bc853c0465118f09ddb0c9eb7976e0f 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/SegmentJsonReader.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/SegmentJsonReader.java
@@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
-public class SegmentJsonReader implements StreamJsonReader {
+public class SegmentJsonReader implements StreamJsonReader {
private final Logger logger = LoggerFactory.getLogger(SegmentJsonReader.class);
@@ -41,7 +41,7 @@ public class SegmentJsonReader implements StreamJsonReader {
private static final String TRACE_SEGMENT_REFERENCE = "rs";
private static final String SPANS = "ss";
- @Override public TraceSegmentObject read(JsonReader reader) throws IOException {
+ @Override public TraceSegmentObject.Builder read(JsonReader reader) throws IOException {
TraceSegmentObject.Builder builder = TraceSegmentObject.newBuilder();
reader.beginObject();
@@ -82,6 +82,6 @@ public class SegmentJsonReader implements StreamJsonReader {
}
reader.endObject();
- return builder.build();
+ return builder;
}
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegment.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegment.java
index ed87156cd6aea6bffad2647d6e05f293eb85e939..e492d939cafe7c9ef5e239fbbff39edeb5bb0a03 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegment.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegment.java
@@ -18,36 +18,30 @@
package org.skywalking.apm.collector.agentstream.jetty.handler.reader;
-import java.util.ArrayList;
-import java.util.List;
import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.skywalking.apm.network.proto.UniqueId;
+import org.skywalking.apm.network.proto.UpstreamSegment;
/**
* @author pengys5
*/
public class TraceSegment {
- private List uniqueIds;
- private TraceSegmentObject traceSegmentObject;
+ private UpstreamSegment.Builder builder;
public TraceSegment() {
- uniqueIds = new ArrayList<>();
+ builder = UpstreamSegment.newBuilder();
}
- public List getGlobalTraceIds() {
- return uniqueIds;
+ public void addGlobalTraceId(UniqueId.Builder globalTraceId) {
+ builder.addGlobalTraceIds(globalTraceId);
}
- public void addGlobalTraceId(UniqueId globalTraceId) {
- uniqueIds.add(globalTraceId);
+ public void setTraceSegmentBuilder(TraceSegmentObject.Builder traceSegmentBuilder) {
+ builder.setSegment(traceSegmentBuilder.build().toByteString());
}
- public TraceSegmentObject getTraceSegmentObject() {
- return traceSegmentObject;
- }
-
- public void setTraceSegmentObject(TraceSegmentObject traceSegmentObject) {
- this.traceSegmentObject = traceSegmentObject;
+ public UpstreamSegment getUpstreamSegment() {
+ return builder.build();
}
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegmentJsonReader.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegmentJsonReader.java
index f392195d363fc28727ff45e96f05f638154b5754..1492b16a4dea3c76a2c8930ed3e6c00365825a9f 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegmentJsonReader.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/TraceSegmentJsonReader.java
@@ -49,16 +49,9 @@ public class TraceSegmentJsonReader implements StreamJsonReader {
}
reader.endArray();
- if (logger.isDebugEnabled()) {
- traceSegment.getGlobalTraceIds().forEach(uniqueId -> {
- StringBuilder globalTraceId = new StringBuilder();
- uniqueId.getIdPartsList().forEach(idPart -> globalTraceId.append(idPart));
- logger.debug("global trace id: {}", globalTraceId.toString());
- });
- }
break;
case SEGMENT:
- traceSegment.setTraceSegmentObject(segmentJsonReader.read(reader));
+ traceSegment.setTraceSegmentBuilder(segmentJsonReader.read(reader));
break;
default:
reader.skipValue();
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/UniqueIdJsonReader.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/UniqueIdJsonReader.java
index c4b1273e184a3d84dbe4b997a36cd3076f16d9a8..04ef1fb34c52fba2a40fc44755e7fc9fcffea831 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/UniqueIdJsonReader.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/jetty/handler/reader/UniqueIdJsonReader.java
@@ -25,9 +25,9 @@ import org.skywalking.apm.network.proto.UniqueId;
/**
* @author pengys5
*/
-public class UniqueIdJsonReader implements StreamJsonReader {
+public class UniqueIdJsonReader implements StreamJsonReader {
- @Override public UniqueId read(JsonReader reader) throws IOException {
+ @Override public UniqueId.Builder read(JsonReader reader) throws IOException {
UniqueId.Builder builder = UniqueId.newBuilder();
reader.beginArray();
@@ -35,6 +35,6 @@ public class UniqueIdJsonReader implements StreamJsonReader {
builder.addIdParts(reader.nextLong());
}
reader.endArray();
- return builder.build();
+ return builder;
}
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/InstanceCache.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/InstanceCache.java
deleted file mode 100644
index 1cb74e8092161e8e0602f0a18580d54185e5c02c..0000000000000000000000000000000000000000
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/InstanceCache.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017, OpenSkywalking Organization All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project repository: https://github.com/OpenSkywalking/skywalking
- */
-
-package org.skywalking.apm.collector.agentstream.worker.cache;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import org.skywalking.apm.collector.agentregister.worker.instance.dao.IInstanceDAO;
-import org.skywalking.apm.collector.storage.dao.DAOContainer;
-
-/**
- * @author pengys5
- */
-public class InstanceCache {
-
- private static Cache CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
-
- public static int get(int applicationInstanceId) {
- try {
- return CACHE.get(applicationInstanceId, () -> {
- IInstanceDAO dao = (IInstanceDAO)DAOContainer.INSTANCE.get(IInstanceDAO.class.getName());
- return dao.getApplicationId(applicationInstanceId);
- });
- } catch (Throwable e) {
- return 0;
- }
- }
-}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/ServiceCache.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/ServiceCache.java
deleted file mode 100644
index 6730473d7742e3fb820c9fddcdcad22a7df451c0..0000000000000000000000000000000000000000
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/cache/ServiceCache.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2017, OpenSkywalking Organization All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project repository: https://github.com/OpenSkywalking/skywalking
- */
-
-package org.skywalking.apm.collector.agentstream.worker.cache;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import org.skywalking.apm.collector.agentregister.worker.servicename.dao.IServiceNameDAO;
-import org.skywalking.apm.collector.core.util.Const;
-import org.skywalking.apm.collector.storage.dao.DAOContainer;
-
-/**
- * @author pengys5
- */
-public class ServiceCache {
-
- private static Cache CACHE = CacheBuilder.newBuilder().initialCapacity(1000).maximumSize(20000).build();
-
- public static String getServiceName(int serviceId) {
- try {
- return CACHE.get(serviceId, () -> {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
- return dao.getServiceName(serviceId);
- });
- } catch (Throwable e) {
- return Const.EMPTY_STRING;
- }
- }
-}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/global/GlobalTraceSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/global/GlobalTraceSpanListener.java
index e3e7da72773362dea7dcf97d875731b617a58c09..0e2425b3dba91583aeb9c55810df7c09305bd197 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/global/GlobalTraceSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/global/GlobalTraceSpanListener.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.GlobalTraceIdsListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -30,7 +31,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
import org.skywalking.apm.network.proto.UniqueId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,8 +47,9 @@ public class GlobalTraceSpanListener implements FirstSpanListener, GlobalTraceId
private long timeBucket;
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ this.timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
this.segmentId = segmentId;
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/instance/performance/InstPerformanceSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/instance/performance/InstPerformanceSpanListener.java
index 3eea6358e43db71989bc71982125322ab618954c..55b219d65abd39037bdc2cb25c89015036490cfd 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/instance/performance/InstPerformanceSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/instance/performance/InstPerformanceSpanListener.java
@@ -20,6 +20,7 @@ package org.skywalking.apm.collector.agentstream.worker.instance.performance;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -28,7 +29,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,15 +45,17 @@ public class InstPerformanceSpanListener implements EntrySpanListener, FirstSpan
private long timeBucket;
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
}
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
this.applicationId = applicationId;
this.instanceId = applicationInstanceId;
- this.cost = spanObject.getEndTime() - spanObject.getStartTime();
- timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanObject.getStartTime());
+ this.cost = spanDecorator.getEndTime() - spanDecorator.getStartTime();
+ timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanDecorator.getStartTime());
}
@Override public void build() {
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/component/NodeComponentSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/component/NodeComponentSpanListener.java
index d6a708896c6480173d00e6d51ac5a007a70533e7..8e7582bb94630958a90b47698cc7ba215861e460 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/component/NodeComponentSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/component/NodeComponentSpanListener.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.ExitSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -31,7 +32,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,39 +46,34 @@ public class NodeComponentSpanListener implements EntrySpanListener, ExitSpanLis
private long timeBucket;
@Override
- public void parseExit(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseExit(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId) {
NodeComponentDataDefine.NodeComponent nodeComponent = new NodeComponentDataDefine.NodeComponent();
- nodeComponent.setComponentId(spanObject.getComponentId());
+ nodeComponent.setComponentId(spanDecorator.getComponentId());
String id;
- if (spanObject.getComponentId() == 0) {
- nodeComponent.setComponentName(spanObject.getComponent());
+ if (spanDecorator.getComponentId() == 0) {
+ nodeComponent.setComponentName(spanDecorator.getComponent());
id = nodeComponent.getComponentName();
} else {
nodeComponent.setComponentName(Const.EMPTY_STRING);
id = String.valueOf(nodeComponent.getComponentId());
}
- nodeComponent.setPeerId(spanObject.getPeerId());
- if (spanObject.getPeerId() == 0) {
- nodeComponent.setPeer(spanObject.getPeer());
- id = id + Const.ID_SPLIT + nodeComponent.getPeer();
- } else {
- nodeComponent.setPeer(Const.EMPTY_STRING);
- id = id + Const.ID_SPLIT + nodeComponent.getPeerId();
- }
+ nodeComponent.setPeerId(spanDecorator.getPeerId());
+ id = id + Const.ID_SPLIT + nodeComponent.getPeerId();
nodeComponent.setId(id);
nodeComponents.add(nodeComponent);
}
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
NodeComponentDataDefine.NodeComponent nodeComponent = new NodeComponentDataDefine.NodeComponent();
- nodeComponent.setComponentId(spanObject.getComponentId());
+ nodeComponent.setComponentId(spanDecorator.getComponentId());
String id;
- if (spanObject.getComponentId() == 0) {
- nodeComponent.setComponentName(spanObject.getComponent());
+ if (spanDecorator.getComponentId() == 0) {
+ nodeComponent.setComponentName(spanDecorator.getComponent());
id = nodeComponent.getComponentName();
} else {
id = String.valueOf(nodeComponent.getComponentId());
@@ -86,7 +81,6 @@ public class NodeComponentSpanListener implements EntrySpanListener, ExitSpanLis
}
nodeComponent.setPeerId(applicationId);
- nodeComponent.setPeer(Const.EMPTY_STRING);
id = id + Const.ID_SPLIT + String.valueOf(applicationId);
nodeComponent.setId(id);
@@ -94,8 +88,9 @@ public class NodeComponentSpanListener implements EntrySpanListener, ExitSpanLis
}
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
@Override public void build() {
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/mapping/NodeMappingSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/mapping/NodeMappingSpanListener.java
index 5bfc3e22a41d1780f901ed678f0e18c5d89ed7e8..7ebbdeff1cf763b3e2976cee1eb18e0cb8f2b30a 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/mapping/NodeMappingSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/node/mapping/NodeMappingSpanListener.java
@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.RefsListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -30,8 +32,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,29 +45,21 @@ public class NodeMappingSpanListener implements RefsListener, FirstSpanListener
private List nodeMappings = new ArrayList<>();
private long timeBucket;
- @Override public void parseRef(TraceSegmentReference reference, int applicationId, int applicationInstanceId,
+ @Override public void parseRef(ReferenceDecorator referenceDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
logger.debug("node mapping listener parse reference");
NodeMappingDataDefine.NodeMapping nodeMapping = new NodeMappingDataDefine.NodeMapping();
nodeMapping.setApplicationId(applicationId);
- nodeMapping.setAddressId(reference.getNetworkAddressId());
-
- String id = String.valueOf(applicationId);
- if (reference.getNetworkAddressId() != 0) {
- nodeMapping.setAddress(Const.EMPTY_STRING);
- id = id + Const.ID_SPLIT + String.valueOf(nodeMapping.getAddressId());
- } else {
- id = id + Const.ID_SPLIT + reference.getNetworkAddress();
- nodeMapping.setAddress(reference.getNetworkAddress());
- }
-
+ nodeMapping.setAddressId(referenceDecorator.getNetworkAddressId());
+ String id = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(nodeMapping.getAddressId());
nodeMapping.setId(id);
nodeMappings.add(nodeMapping);
}
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
@Override public void build() {
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/noderef/NodeReferenceSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/noderef/NodeReferenceSpanListener.java
index 76f9583c138eae9e17a832ea664c5ba766a7c95c..6c302569d14fa922e79bf3ce8b33fcf825ed4495 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/noderef/NodeReferenceSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/noderef/NodeReferenceSpanListener.java
@@ -20,10 +20,12 @@ package org.skywalking.apm.collector.agentstream.worker.noderef;
import java.util.LinkedList;
import java.util.List;
-import org.skywalking.apm.collector.agentstream.worker.cache.InstanceCache;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.ExitSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.RefsListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
+import org.skywalking.apm.collector.cache.InstanceCache;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.Const;
@@ -33,8 +35,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,59 +49,53 @@ public class NodeReferenceSpanListener implements EntrySpanListener, ExitSpanLis
private List references = new LinkedList<>();
@Override
- public void parseExit(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseExit(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId) {
NodeReferenceDataDefine.NodeReference nodeReference = new NodeReferenceDataDefine.NodeReference();
nodeReference.setFrontApplicationId(applicationId);
- nodeReference.setBehindApplicationId(spanObject.getPeerId());
- nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime()));
+ nodeReference.setBehindApplicationId(spanDecorator.getPeerId());
+ nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()));
StringBuilder idBuilder = new StringBuilder();
- idBuilder.append(nodeReference.getTimeBucket()).append(Const.ID_SPLIT).append(applicationId);
- if (spanObject.getPeerId() != 0) {
- nodeReference.setBehindPeer(Const.EMPTY_STRING);
- idBuilder.append(Const.ID_SPLIT).append(spanObject.getPeerId());
- } else {
- nodeReference.setBehindPeer(spanObject.getPeer());
- idBuilder.append(Const.ID_SPLIT).append(spanObject.getPeer());
- }
+ idBuilder.append(nodeReference.getTimeBucket()).append(Const.ID_SPLIT).append(applicationId)
+ .append(Const.ID_SPLIT).append(spanDecorator.getPeerId());
+
nodeReference.setId(idBuilder.toString());
- nodeReferences.add(buildNodeRefSum(nodeReference, spanObject.getStartTime(), spanObject.getEndTime(), spanObject.getIsError()));
+ nodeReferences.add(buildNodeRefSum(nodeReference, spanDecorator.getStartTime(), spanDecorator.getEndTime(), spanDecorator.getIsError()));
}
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
if (CollectionUtils.isNotEmpty(references)) {
references.forEach(nodeReference -> {
- nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime()));
+ nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()));
String idBuilder = String.valueOf(nodeReference.getTimeBucket()) + Const.ID_SPLIT + nodeReference.getFrontApplicationId() +
Const.ID_SPLIT + nodeReference.getBehindApplicationId();
nodeReference.setId(idBuilder);
- nodeReferences.add(buildNodeRefSum(nodeReference, spanObject.getStartTime(), spanObject.getEndTime(), spanObject.getIsError()));
+ nodeReferences.add(buildNodeRefSum(nodeReference, spanDecorator.getStartTime(), spanDecorator.getEndTime(), spanDecorator.getIsError()));
});
} else {
NodeReferenceDataDefine.NodeReference nodeReference = new NodeReferenceDataDefine.NodeReference();
nodeReference.setFrontApplicationId(Const.USER_ID);
nodeReference.setBehindApplicationId(applicationId);
- nodeReference.setBehindPeer(Const.EMPTY_STRING);
- nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime()));
+ nodeReference.setTimeBucket(TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()));
String idBuilder = String.valueOf(nodeReference.getTimeBucket()) + Const.ID_SPLIT + nodeReference.getFrontApplicationId() +
Const.ID_SPLIT + nodeReference.getBehindApplicationId();
nodeReference.setId(idBuilder);
- nodeReferences.add(buildNodeRefSum(nodeReference, spanObject.getStartTime(), spanObject.getEndTime(), spanObject.getIsError()));
+ nodeReferences.add(buildNodeRefSum(nodeReference, spanDecorator.getStartTime(), spanDecorator.getEndTime(), spanDecorator.getIsError()));
}
}
- @Override public void parseRef(TraceSegmentReference reference, int applicationId, int applicationInstanceId,
+ @Override public void parseRef(ReferenceDecorator referenceDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
- int parentApplicationId = InstanceCache.get(reference.getParentApplicationInstanceId());
+ int parentApplicationId = InstanceCache.get(referenceDecorator.getParentApplicationInstanceId());
NodeReferenceDataDefine.NodeReference referenceSum = new NodeReferenceDataDefine.NodeReference();
referenceSum.setFrontApplicationId(parentApplicationId);
referenceSum.setBehindApplicationId(applicationId);
- referenceSum.setBehindPeer(Const.EMPTY_STRING);
references.add(referenceSum);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/EntrySpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/EntrySpanListener.java
index b12c0de6a726a6541584eeb1e2820b69dcb946f9..6dc623ffa61223170345fc0064080583451be0d2 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/EntrySpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/EntrySpanListener.java
@@ -18,11 +18,11 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
-import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
/**
* @author pengys5
*/
public interface EntrySpanListener extends SpanListener {
- void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId);
+ void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/ExitSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/ExitSpanListener.java
index cf3c7cc32416d2a9d3b87822c9beee840b2625d2..619c05cb5167faf599e6f650a78e7b37f17df929 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/ExitSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/ExitSpanListener.java
@@ -18,11 +18,11 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
-import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
/**
* @author pengys5
*/
public interface ExitSpanListener extends SpanListener {
- void parseExit(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId);
+ void parseExit(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/FirstSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/FirstSpanListener.java
index 62e416497fd1e68ff4b0388d694e2383bb94b7f5..f36b9074b24712b4904f0fc2a7132965fa8f8f9a 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/FirstSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/FirstSpanListener.java
@@ -18,11 +18,11 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
-import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
/**
* @author pengys5
*/
public interface FirstSpanListener extends SpanListener {
- void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId);
+ void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/LocalSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/LocalSpanListener.java
index aa0299688e768ba8efd06d2cefd918895a3e1dee..95e48a0774b01af25a7556b026f62951b4666dad 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/LocalSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/LocalSpanListener.java
@@ -18,11 +18,11 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
-import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
/**
* @author pengys5
*/
public interface LocalSpanListener extends SpanListener {
- void parseLocal(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId);
+ void parseLocal(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/RefsListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/RefsListener.java
index 96294472b8971e7f1dc9c0b4670fda8623eea904..3e7c80cade810747f920640a3c3e1aa8f62b8b8f 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/RefsListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/RefsListener.java
@@ -18,11 +18,11 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
/**
* @author pengys5
*/
public interface RefsListener extends SpanListener {
- void parseRef(TraceSegmentReference reference, int applicationId, int applicationInstanceId, String segmentId);
+ void parseRef(ReferenceDecorator referenceDecorator, int applicationId, int applicationInstanceId, String segmentId);
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/SegmentParse.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/SegmentParse.java
index 0fca994f76835a24f11a01c5f3c98c0968030103..f5f79300c8953e14c46b0541e25526a92beac25c 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/SegmentParse.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/SegmentParse.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.agentstream.worker.segment;
+import com.google.protobuf.InvalidProtocolBufferException;
import java.util.ArrayList;
import java.util.List;
import org.skywalking.apm.collector.agentstream.worker.global.GlobalTraceSpanListener;
@@ -27,20 +28,24 @@ import org.skywalking.apm.collector.agentstream.worker.node.mapping.NodeMappingS
import org.skywalking.apm.collector.agentstream.worker.noderef.NodeReferenceSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.cost.SegmentCostSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.origin.SegmentPersistenceWorker;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceIdExchanger;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SegmentDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SegmentStandardizationWorker;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanIdExchanger;
import org.skywalking.apm.collector.agentstream.worker.service.entry.ServiceEntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.serviceref.ServiceReferenceSpanListener;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
-import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.storage.define.segment.SegmentDataDefine;
import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
import org.skywalking.apm.network.proto.SpanType;
import org.skywalking.apm.network.proto.TraceSegmentObject;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
import org.skywalking.apm.network.proto.UniqueId;
+import org.skywalking.apm.network.proto.UpstreamSegment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +57,7 @@ public class SegmentParse {
private final Logger logger = LoggerFactory.getLogger(SegmentParse.class);
private List spanListeners;
+ private String segmentId;
public SegmentParse() {
spanListeners = new ArrayList<>();
@@ -65,51 +71,83 @@ public class SegmentParse {
spanListeners.add(new InstPerformanceSpanListener());
}
- public void parse(List traceIds, TraceSegmentObject segmentObject) {
+ public boolean parse(UpstreamSegment segment, Source source) {
+ try {
+ List traceIds = segment.getGlobalTraceIdsList();
+ TraceSegmentObject segmentObject = TraceSegmentObject.parseFrom(segment.getSegment());
+
+ SegmentDecorator segmentDecorator = new SegmentDecorator(segmentObject);
+ if (!preBuild(traceIds, segmentDecorator)) {
+ logger.debug("This segment id exchange not success, write to buffer file, id: {}", segmentId);
+
+ if (source.equals(Source.Agent)) {
+ writeToBufferFile(segmentId, segment);
+ }
+ return false;
+ } else {
+ logger.debug("This segment id exchange success, id: {}", segmentId);
+ notifyListenerToBuild();
+ buildSegment(segmentId, segmentDecorator.toByteArray());
+ return true;
+ }
+ } catch (InvalidProtocolBufferException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return false;
+ }
+
+ private boolean preBuild(List traceIds, SegmentDecorator segmentDecorator) {
StringBuilder segmentIdBuilder = new StringBuilder();
- for (int i = 0; i < segmentObject.getTraceSegmentId().getIdPartsList().size(); i++) {
+ for (int i = 0; i < segmentDecorator.getTraceSegmentId().getIdPartsList().size(); i++) {
if (i == 0) {
- segmentIdBuilder.append(segmentObject.getTraceSegmentId().getIdPartsList().get(i));
+ segmentIdBuilder.append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
} else {
- segmentIdBuilder.append(".").append(segmentObject.getTraceSegmentId().getIdPartsList().get(i));
+ segmentIdBuilder.append(".").append(segmentDecorator.getTraceSegmentId().getIdPartsList().get(i));
}
}
- String segmentId = segmentIdBuilder.toString();
+ segmentId = segmentIdBuilder.toString();
for (UniqueId uniqueId : traceIds) {
notifyGlobalsListener(uniqueId);
}
- int applicationId = segmentObject.getApplicationId();
- int applicationInstanceId = segmentObject.getApplicationInstanceId();
+ int applicationId = segmentDecorator.getApplicationId();
+ int applicationInstanceId = segmentDecorator.getApplicationInstanceId();
+
+ for (int i = 0; i < segmentDecorator.getRefsCount(); i++) {
+ ReferenceDecorator referenceDecorator = segmentDecorator.getRefs(i);
+ if (!ReferenceIdExchanger.getInstance().exchange(referenceDecorator, applicationId)) {
+ return false;
+ }
- for (TraceSegmentReference reference : segmentObject.getRefsList()) {
- notifyRefsListener(reference, applicationId, applicationInstanceId, segmentId);
+ notifyRefsListener(referenceDecorator, applicationId, applicationInstanceId, segmentId);
}
- List spans = segmentObject.getSpansList();
- if (CollectionUtils.isNotEmpty(spans)) {
- for (SpanObject spanObject : spans) {
- if (spanObject.getSpanId() == 0) {
- notifyFirstListener(spanObject, applicationId, applicationInstanceId, segmentId);
- }
+ for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
+ SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
- if (SpanType.Exit.equals(spanObject.getSpanType())) {
- notifyExitListener(spanObject, applicationId, applicationInstanceId, segmentId);
- } else if (SpanType.Entry.equals(spanObject.getSpanType())) {
- notifyEntryListener(spanObject, applicationId, applicationInstanceId, segmentId);
- } else if (SpanType.Local.equals(spanObject.getSpanType())) {
- notifyLocalListener(spanObject, applicationId, applicationInstanceId, segmentId);
- } else {
- logger.error("span type error, span type: {}", spanObject.getSpanType().name());
- }
+ if (!SpanIdExchanger.getInstance().exchange(spanDecorator, applicationId)) {
+ return false;
+ }
+
+ if (spanDecorator.getSpanId() == 0) {
+ notifyFirstListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
+ }
+
+ if (SpanType.Exit.equals(spanDecorator.getSpanType())) {
+ notifyExitListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
+ } else if (SpanType.Entry.equals(spanDecorator.getSpanType())) {
+ notifyEntryListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
+ } else if (SpanType.Local.equals(spanDecorator.getSpanType())) {
+ notifyLocalListener(spanDecorator, applicationId, applicationInstanceId, segmentId);
+ } else {
+ logger.error("span type value was unexpected, span type name: {}", spanDecorator.getSpanType().name());
}
}
- notifyListenerToBuild();
- buildSegment(segmentId, segmentObject.toByteArray());
+ return true;
}
private void buildSegment(String id, byte[] dataBinary) {
@@ -126,47 +164,58 @@ public class SegmentParse {
}
}
+ private void writeToBufferFile(String id, UpstreamSegment upstreamSegment) {
+ StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME);
+
+ try {
+ logger.debug("send to segment buffer write worker, id: {}", id);
+ context.getClusterWorkerContext().lookup(SegmentStandardizationWorker.WorkerRole.INSTANCE).tell(upstreamSegment);
+ } catch (WorkerInvokeException | WorkerNotFoundException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
private void notifyListenerToBuild() {
spanListeners.forEach(SpanListener::build);
}
- private void notifyExitListener(SpanObject spanObject, int applicationId, int applicationInstanceId,
+ private void notifyExitListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof ExitSpanListener) {
- ((ExitSpanListener)listener).parseExit(spanObject, applicationId, applicationInstanceId, segmentId);
+ ((ExitSpanListener)listener).parseExit(spanDecorator, applicationId, applicationInstanceId, segmentId);
}
}
}
- private void notifyEntryListener(SpanObject spanObject, int applicationId, int applicationInstanceId,
+ private void notifyEntryListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof EntrySpanListener) {
- ((EntrySpanListener)listener).parseEntry(spanObject, applicationId, applicationInstanceId, segmentId);
+ ((EntrySpanListener)listener).parseEntry(spanDecorator, applicationId, applicationInstanceId, segmentId);
}
}
}
- private void notifyLocalListener(SpanObject spanObject, int applicationId, int applicationInstanceId,
+ private void notifyLocalListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof LocalSpanListener) {
- ((LocalSpanListener)listener).parseLocal(spanObject, applicationId, applicationInstanceId, segmentId);
+ ((LocalSpanListener)listener).parseLocal(spanDecorator, applicationId, applicationInstanceId, segmentId);
}
}
}
- private void notifyFirstListener(SpanObject spanObject, int applicationId, int applicationInstanceId,
+ private void notifyFirstListener(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof FirstSpanListener) {
- ((FirstSpanListener)listener).parseFirst(spanObject, applicationId, applicationInstanceId, segmentId);
+ ((FirstSpanListener)listener).parseFirst(spanDecorator, applicationId, applicationInstanceId, segmentId);
}
}
}
- private void notifyRefsListener(TraceSegmentReference reference, int applicationId, int applicationInstanceId,
+ private void notifyRefsListener(ReferenceDecorator reference, int applicationId, int applicationInstanceId,
String segmentId) {
for (SpanListener listener : spanListeners) {
if (listener instanceof RefsListener) {
@@ -182,4 +231,8 @@ public class SegmentParse {
}
}
}
+
+ public enum Source {
+ Agent, Buffer
+ }
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/Offset.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/Offset.java
new file mode 100644
index 0000000000000000000000000000000000000000..6b5b95f2b4bef803bbe71be0841ae8ff0ddd1ec7
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/Offset.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+/**
+ * @author pengys5
+ */
+public class Offset {
+
+ private static final String SPLIT_CHARACTER = ",";
+ private ReadOffset readOffset;
+ private WriteOffset writeOffset;
+
+ public Offset() {
+ readOffset = new ReadOffset();
+ writeOffset = new WriteOffset();
+ }
+
+ public String serialize() {
+ return readOffset.getReadFileName() + SPLIT_CHARACTER + String.valueOf(readOffset.getReadFileOffset())
+ + SPLIT_CHARACTER + writeOffset.getWriteFileName() + SPLIT_CHARACTER + String.valueOf(writeOffset.getWriteFileOffset());
+ }
+
+ public void deserialize(String value) {
+ String[] values = value.split(SPLIT_CHARACTER);
+ if (values.length == 4) {
+ this.readOffset.readFileName = values[0];
+ this.readOffset.readFileOffset = Long.parseLong(values[1]);
+ this.writeOffset.writeFileName = values[2];
+ this.writeOffset.writeFileOffset = Long.parseLong(values[3]);
+ }
+ }
+
+ public ReadOffset getReadOffset() {
+ return readOffset;
+ }
+
+ public WriteOffset getWriteOffset() {
+ return writeOffset;
+ }
+
+ public static class ReadOffset {
+ private String readFileName;
+ private long readFileOffset = 0;
+
+ public String getReadFileName() {
+ return readFileName;
+ }
+
+ public long getReadFileOffset() {
+ return readFileOffset;
+ }
+
+ public void setReadFileName(String readFileName) {
+ this.readFileName = readFileName;
+ }
+
+ public void setReadFileOffset(long readFileOffset) {
+ this.readFileOffset = readFileOffset;
+ }
+ }
+
+ public static class WriteOffset {
+ private String writeFileName;
+ private long writeFileOffset = 0;
+
+ public String getWriteFileName() {
+ return writeFileName;
+ }
+
+ public long getWriteFileOffset() {
+ return writeFileOffset;
+ }
+
+ public void setWriteFileName(String writeFileName) {
+ this.writeFileName = writeFileName;
+ }
+
+ public void setWriteFileOffset(long writeFileOffset) {
+ this.writeFileOffset = writeFileOffset;
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/OffsetManager.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/OffsetManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..58afe2505c195d835e85c89ea75142a0f1d3c91c
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/OffsetManager.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.skywalking.apm.collector.agentstream.config.BufferFileConfig;
+import org.skywalking.apm.collector.agentstream.worker.util.FileUtils;
+import org.skywalking.apm.collector.core.util.CollectionUtils;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.TimeBucketUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public enum OffsetManager {
+ INSTANCE;
+
+ private final Logger logger = LoggerFactory.getLogger(OffsetManager.class);
+
+ private static final String OFFSET_FILE_PREFIX = "offset";
+ private File offsetFile;
+ private Offset offset;
+ private boolean initialized = false;
+ private RandomAccessFile randomAccessFile = null;
+ private String lastOffsetRecord = Const.EMPTY_STRING;
+
+ public synchronized void initialize() throws IOException {
+ if (!initialized) {
+ this.offset = new Offset();
+ File dataPath = new File(SegmentBufferConfig.BUFFER_PATH);
+ if (dataPath.mkdirs()) {
+ createOffsetFile();
+ } else {
+ File[] offsetFiles = dataPath.listFiles(new PrefixFileNameFilter());
+ if (CollectionUtils.isNotEmpty(offsetFiles) && offsetFiles.length > 0) {
+ for (int i = 0; i < offsetFiles.length; i++) {
+ if (i != offsetFiles.length - 1) {
+ offsetFiles[i].delete();
+ } else {
+ offsetFile = offsetFiles[i];
+ }
+ }
+ } else {
+ createOffsetFile();
+ }
+ }
+ String offsetRecord = FileUtils.INSTANCE.readLastLine(offsetFile);
+ offset.deserialize(offsetRecord);
+ initialized = true;
+
+ Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> flush(), 10, 3, TimeUnit.SECONDS);
+ }
+ }
+
+ private void createOffsetFile() throws IOException {
+ String timeBucket = String.valueOf(TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()));
+ String offsetFileName = OFFSET_FILE_PREFIX + "_" + timeBucket + "." + Const.FILE_SUFFIX;
+ offsetFile = new File(SegmentBufferConfig.BUFFER_PATH + offsetFileName);
+ this.offset.getWriteOffset().setWriteFileName(Const.EMPTY_STRING);
+ this.offset.getWriteOffset().setWriteFileOffset(0);
+ this.offset.getReadOffset().setReadFileName(Const.EMPTY_STRING);
+ this.offset.getReadOffset().setReadFileOffset(0);
+ this.flush();
+ }
+
+ public void flush() {
+ String offsetRecord = offset.serialize();
+ if (!lastOffsetRecord.equals(offsetRecord)) {
+ if (offsetFile.length() >= BufferFileConfig.BUFFER_OFFSET_MAX_FILE_SIZE) {
+ nextFile();
+ }
+ FileUtils.INSTANCE.writeAppendToLast(offsetFile, randomAccessFile, offsetRecord);
+ lastOffsetRecord = offsetRecord;
+ }
+ }
+
+ private void nextFile() {
+ String timeBucket = String.valueOf(TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()));
+ String offsetFileName = OFFSET_FILE_PREFIX + "_" + timeBucket + "." + Const.FILE_SUFFIX;
+ File newOffsetFile = new File(SegmentBufferConfig.BUFFER_PATH + offsetFileName);
+ offsetFile.delete();
+ offsetFile = newOffsetFile;
+ this.flush();
+ }
+
+ public String getReadFileName() {
+ return offset.getReadOffset().getReadFileName();
+ }
+
+ public long getReadFileOffset() {
+ return offset.getReadOffset().getReadFileOffset();
+ }
+
+ public void setReadOffset(long readFileOffset) {
+ offset.getReadOffset().setReadFileOffset(readFileOffset);
+ }
+
+ public void setReadOffset(String readFileName, long readFileOffset) {
+ offset.getReadOffset().setReadFileName(readFileName);
+ offset.getReadOffset().setReadFileOffset(readFileOffset);
+ }
+
+ public String getWriteFileName() {
+ return offset.getWriteOffset().getWriteFileName();
+ }
+
+ public long getWriteFileOffset() {
+ return offset.getWriteOffset().getWriteFileOffset();
+ }
+
+ public void setWriteOffset(String writeFileName, long writeFileOffset) {
+ offset.getWriteOffset().setWriteFileName(writeFileName);
+ offset.getWriteOffset().setWriteFileOffset(writeFileOffset);
+ }
+
+ public void setWriteOffset(long writeFileOffset) {
+ offset.getWriteOffset().setWriteFileOffset(writeFileOffset);
+ }
+
+ class PrefixFileNameFilter implements FilenameFilter {
+ @Override public boolean accept(File dir, String name) {
+ return name.startsWith(OFFSET_FILE_PREFIX);
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferConfig.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..30bf0eb7f4809389a43046d7a6098a07a188b76d
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferConfig.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+import org.skywalking.apm.collector.core.config.SystemConfig;
+
+/**
+ * @author pengys5
+ */
+public class SegmentBufferConfig {
+ public static String BUFFER_PATH = SystemConfig.DATA_PATH + "/buffer/";
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferManager.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..661f70084a5bbc3d8def4d6c853f25f8b6fcfe40
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferManager.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import org.skywalking.apm.collector.agentstream.config.BufferFileConfig;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
+import org.skywalking.apm.collector.core.util.TimeBucketUtils;
+import org.skywalking.apm.network.proto.UpstreamSegment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public enum SegmentBufferManager {
+ INSTANCE;
+
+ private final Logger logger = LoggerFactory.getLogger(SegmentBufferManager.class);
+
+ public static final String DATA_FILE_PREFIX = "data";
+ private FileOutputStream outputStream;
+
+ public synchronized void initialize() {
+ logger.info("segment buffer initialize");
+ try {
+ OffsetManager.INSTANCE.initialize();
+ if (new File(SegmentBufferConfig.BUFFER_PATH).mkdirs()) {
+ newDataFile();
+ } else {
+ String writeFileName = OffsetManager.INSTANCE.getWriteFileName();
+ if (StringUtils.isNotEmpty(writeFileName)) {
+ File dataFile = new File(SegmentBufferConfig.BUFFER_PATH + writeFileName);
+ if (dataFile.exists()) {
+ outputStream = new FileOutputStream(new File(SegmentBufferConfig.BUFFER_PATH + writeFileName), true);
+ } else {
+ newDataFile();
+ }
+ } else {
+ newDataFile();
+ }
+ }
+ SegmentBufferReader.INSTANCE.initialize();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ public synchronized void writeBuffer(UpstreamSegment segment) {
+ try {
+ segment.writeDelimitedTo(outputStream);
+ long position = outputStream.getChannel().position();
+ if (position > BufferFileConfig.BUFFER_SEGMENT_MAX_FILE_SIZE) {
+ newDataFile();
+ } else {
+ OffsetManager.INSTANCE.setWriteOffset(position);
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ private void newDataFile() throws IOException {
+ logger.debug("create new segment buffer file");
+ String timeBucket = String.valueOf(TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()));
+ String writeFileName = DATA_FILE_PREFIX + "_" + timeBucket + "." + Const.FILE_SUFFIX;
+ File dataFile = new File(SegmentBufferConfig.BUFFER_PATH + writeFileName);
+ dataFile.createNewFile();
+ OffsetManager.INSTANCE.setWriteOffset(writeFileName, 0);
+ try {
+ if (outputStream != null) {
+ outputStream.close();
+ }
+ outputStream = new FileOutputStream(dataFile);
+ outputStream.getChannel().position(0);
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ public synchronized void flush() {
+
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferReader.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferReader.java
new file mode 100644
index 0000000000000000000000000000000000000000..3fd3f7db62612f2c4bc396da7f6863c21b4d4d17
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferReader.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+import com.google.protobuf.CodedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.skywalking.apm.collector.agentstream.worker.segment.SegmentParse;
+import org.skywalking.apm.collector.core.util.CollectionUtils;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
+import org.skywalking.apm.network.proto.UpstreamSegment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public enum SegmentBufferReader {
+ INSTANCE;
+
+ private final Logger logger = LoggerFactory.getLogger(SegmentBufferReader.class);
+ private InputStream inputStream;
+
+ public void initialize() {
+ Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::preRead, 3, 3, TimeUnit.SECONDS);
+ }
+
+ private void preRead() {
+ String readFileName = OffsetManager.INSTANCE.getReadFileName();
+ if (StringUtils.isNotEmpty(readFileName)) {
+ File readFile = new File(SegmentBufferConfig.BUFFER_PATH + readFileName);
+ if (readFile.exists()) {
+ deleteTheDataFilesBeforeReadFile(readFileName);
+ long readFileOffset = OffsetManager.INSTANCE.getReadFileOffset();
+ read(readFile, readFileOffset);
+ readEarliestCreateDataFile();
+ } else {
+ deleteTheDataFilesBeforeReadFile(readFileName);
+ readEarliestCreateDataFile();
+ }
+ } else {
+ readEarliestCreateDataFile();
+ }
+ }
+
+ private void deleteTheDataFilesBeforeReadFile(String readFileName) {
+ File[] dataFiles = new File(SegmentBufferConfig.BUFFER_PATH).listFiles(new PrefixFileNameFilter());
+
+ long readFileCreateTime = getFileCreateTime(readFileName);
+ for (File dataFile : dataFiles) {
+ long fileCreateTime = getFileCreateTime(dataFile.getName());
+ if (fileCreateTime < readFileCreateTime) {
+ dataFile.delete();
+ } else if (fileCreateTime == readFileCreateTime) {
+ break;
+ }
+ }
+ }
+
+ private long getFileCreateTime(String fileName) {
+ fileName = fileName.replace(SegmentBufferManager.DATA_FILE_PREFIX + "_", Const.EMPTY_STRING);
+ fileName = fileName.replace("." + Const.FILE_SUFFIX, Const.EMPTY_STRING);
+ return Long.valueOf(fileName);
+ }
+
+ private void readEarliestCreateDataFile() {
+ String readFileName = OffsetManager.INSTANCE.getReadFileName();
+ File[] dataFiles = new File(SegmentBufferConfig.BUFFER_PATH).listFiles(new PrefixFileNameFilter());
+
+ if (CollectionUtils.isNotEmpty(dataFiles)) {
+ if (dataFiles[0].getName().equals(readFileName)) {
+ return;
+ }
+ }
+
+ for (File dataFile : dataFiles) {
+ logger.debug("Reading segment buffer data file, file name: {}", dataFile.getAbsolutePath());
+ OffsetManager.INSTANCE.setReadOffset(dataFile.getName(), 0);
+ if (!read(dataFile, 0)) {
+ break;
+ }
+ }
+ }
+
+ private boolean read(File readFile, long readFileOffset) {
+ try {
+ inputStream = new FileInputStream(readFile);
+ inputStream.skip(readFileOffset);
+
+ String writeFileName = OffsetManager.INSTANCE.getWriteFileName();
+ long endPoint = readFile.length();
+ if (writeFileName.equals(readFile.getName())) {
+ endPoint = OffsetManager.INSTANCE.getWriteFileOffset();
+ }
+
+ while (readFile.length() > readFileOffset && readFileOffset < endPoint) {
+ UpstreamSegment upstreamSegment = UpstreamSegment.parser().parseDelimitedFrom(inputStream);
+ SegmentParse parse = new SegmentParse();
+ if (!parse.parse(upstreamSegment, SegmentParse.Source.Buffer)) {
+ return false;
+ }
+
+ final int serialized = upstreamSegment.getSerializedSize();
+ readFileOffset = readFileOffset + CodedOutputStream.computeUInt32SizeNoTag(serialized) + serialized;
+ logger.debug("read segment buffer from file: {}, offset: {}, file length: {}", readFile.getName(), readFileOffset, readFile.length());
+ OffsetManager.INSTANCE.setReadOffset(readFileOffset);
+ }
+
+ inputStream.close();
+ if (!writeFileName.equals(readFile.getName())) {
+ readFile.delete();
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ return false;
+ }
+ return true;
+ }
+
+ class PrefixFileNameFilter implements FilenameFilter {
+ @Override public boolean accept(File dir, String name) {
+ return name.startsWith(SegmentBufferManager.DATA_FILE_PREFIX);
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/SegmentCostSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/SegmentCostSpanListener.java
index ace2528747eb4bedac98c785e2bef2f4f27472a3..90be7b639cca324102c1ff7096ca3f6908ad261c 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/SegmentCostSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/SegmentCostSpanListener.java
@@ -20,11 +20,12 @@ package org.skywalking.apm.collector.agentstream.worker.segment.cost;
import java.util.ArrayList;
import java.util.List;
-import org.skywalking.apm.collector.agentstream.worker.cache.ServiceCache;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.ExitSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.LocalSpanListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.segment.SegmentCostDataDefine;
@@ -32,14 +33,13 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
-public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener,FirstSpanListener {
+public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener {
private final Logger logger = LoggerFactory.getLogger(SegmentCostSpanListener.class);
@@ -48,39 +48,42 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe
private long timeBucket;
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
SegmentCostDataDefine.SegmentCost segmentCost = new SegmentCostDataDefine.SegmentCost();
segmentCost.setSegmentId(segmentId);
segmentCost.setApplicationId(applicationId);
- segmentCost.setCost(spanObject.getEndTime() - spanObject.getStartTime());
- segmentCost.setStartTime(spanObject.getStartTime());
- segmentCost.setEndTime(spanObject.getEndTime());
+ segmentCost.setCost(spanDecorator.getEndTime() - spanDecorator.getStartTime());
+ segmentCost.setStartTime(spanDecorator.getStartTime());
+ segmentCost.setEndTime(spanDecorator.getEndTime());
segmentCost.setId(segmentId);
- if (spanObject.getOperationNameId() == 0) {
- segmentCost.setServiceName(spanObject.getOperationName());
+ if (spanDecorator.getOperationNameId() == 0) {
+ segmentCost.setServiceName(spanDecorator.getOperationName());
} else {
- segmentCost.setServiceName(ServiceCache.getServiceName(spanObject.getOperationNameId()));
+ segmentCost.setServiceName(ServiceNameCache.getSplitServiceName(ServiceNameCache.get(spanDecorator.getOperationNameId())));
}
segmentCosts.add(segmentCost);
- isError = isError || spanObject.getIsError();
+ isError = isError || spanDecorator.getIsError();
}
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- isError = isError || spanObject.getIsError();
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ isError = isError || spanDecorator.getIsError();
}
@Override
- public void parseExit(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- isError = isError || spanObject.getIsError();
+ public void parseExit(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId, String segmentId) {
+ isError = isError || spanDecorator.getIsError();
}
@Override
- public void parseLocal(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- isError = isError || spanObject.getIsError();
+ public void parseLocal(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ isError = isError || spanDecorator.getIsError();
}
@Override public void build() {
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/origin/dao/SegmentH2DAO.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/origin/dao/SegmentH2DAO.java
index 8a1ead97bce660df1f23f1160ef6ab935c71ddbf..60e04854ea5f41916ebc6f215aad1d421bd4dc00 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/origin/dao/SegmentH2DAO.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/origin/dao/SegmentH2DAO.java
@@ -18,10 +18,8 @@
package org.skywalking.apm.collector.agentstream.worker.segment.origin.dao;
-import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
-
import org.skywalking.apm.collector.agentstream.worker.segment.cost.dao.SegmentCostH2DAO;
import org.skywalking.apm.collector.core.stream.Data;
import org.skywalking.apm.collector.storage.define.DataDefine;
@@ -38,14 +36,16 @@ import org.slf4j.LoggerFactory;
*/
public class SegmentH2DAO extends H2DAO implements ISegmentDAO, IPersistenceDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentCostH2DAO.class);
+
@Override public Data get(String id, DataDefine dataDefine) {
return null;
}
+
@Override public H2SqlEntity prepareBatchInsert(Data data) {
Map source = new HashMap<>();
H2SqlEntity entity = new H2SqlEntity();
source.put("id", data.getDataString(0));
- source.put(SegmentTable.COLUMN_DATA_BINARY, Base64.getEncoder().encode(data.getDataBytes(0)));
+ source.put(SegmentTable.COLUMN_DATA_BINARY, data.getDataBytes(0));
logger.debug("segment source: {}", source.toString());
String sql = SqlBuilder.buildBatchInsertSql(SegmentTable.TABLE, source.keySet());
@@ -53,6 +53,7 @@ public class SegmentH2DAO extends H2DAO implements ISegmentDAO, IPersistenceDAO<
entity.setParams(source.values().toArray(new Object[0]));
return entity;
}
+
@Override public H2SqlEntity prepareBatchUpdate(Data data) {
return null;
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/IdExchanger.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/IdExchanger.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a88718cc189da683570f8e6d757052040716984
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/IdExchanger.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+/**
+ * @author pengys5
+ */
+public interface IdExchanger {
+ boolean exchange(T standardBuilder, int applicationId);
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceDecorator.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceDecorator.java
new file mode 100644
index 0000000000000000000000000000000000000000..17f86a0a69be7263b2ad3011fca5ea427ecd9f8d
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceDecorator.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.network.proto.RefType;
+import org.skywalking.apm.network.proto.TraceSegmentReference;
+import org.skywalking.apm.network.proto.UniqueId;
+
+/**
+ * @author pengys5
+ */
+public class ReferenceDecorator implements StandardBuilder {
+ private boolean isOrigin = true;
+ private StandardBuilder standardBuilder;
+ private TraceSegmentReference referenceObject;
+ private TraceSegmentReference.Builder referenceBuilder;
+
+ public ReferenceDecorator(TraceSegmentReference referenceObject, StandardBuilder standardBuilder) {
+ this.referenceObject = referenceObject;
+ this.standardBuilder = standardBuilder;
+ }
+
+ public ReferenceDecorator(TraceSegmentReference.Builder referenceBuilder, StandardBuilder standardBuilder) {
+ this.referenceBuilder = referenceBuilder;
+ this.standardBuilder = standardBuilder;
+ this.isOrigin = false;
+ }
+
+ public RefType getRefType() {
+ if (isOrigin) {
+ return referenceObject.getRefType();
+ } else {
+ return referenceBuilder.getRefType();
+ }
+ }
+
+ public int getRefTypeValue() {
+ if (isOrigin) {
+ return referenceObject.getRefTypeValue();
+ } else {
+ return referenceBuilder.getRefTypeValue();
+ }
+ }
+
+ public int getEntryServiceId() {
+ if (isOrigin) {
+ return referenceObject.getEntryServiceId();
+ } else {
+ return referenceBuilder.getEntryServiceId();
+ }
+ }
+
+ public void setEntryServiceId(int value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setEntryServiceId(value);
+ }
+ }
+
+ public String getEntryServiceName() {
+ if (isOrigin) {
+ return referenceObject.getEntryServiceName();
+ } else {
+ return referenceBuilder.getEntryServiceName();
+ }
+ }
+
+ public void setEntryServiceName(String value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setEntryServiceName(value);
+ }
+ }
+
+ public int getEntryApplicationInstanceId() {
+ if (isOrigin) {
+ return referenceObject.getEntryApplicationInstanceId();
+ } else {
+ return referenceBuilder.getEntryApplicationInstanceId();
+ }
+ }
+
+ public int getParentApplicationInstanceId() {
+ if (isOrigin) {
+ return referenceObject.getParentApplicationInstanceId();
+ } else {
+ return referenceBuilder.getParentApplicationInstanceId();
+ }
+ }
+
+ public int getParentServiceId() {
+ if (isOrigin) {
+ return referenceObject.getParentServiceId();
+ } else {
+ return referenceBuilder.getParentServiceId();
+ }
+ }
+
+ public void setParentServiceId(int value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setParentServiceId(value);
+ }
+ }
+
+ public int getParentSpanId() {
+ if (isOrigin) {
+ return referenceObject.getParentSpanId();
+ } else {
+ return referenceBuilder.getParentSpanId();
+ }
+ }
+
+ public String getParentServiceName() {
+ if (isOrigin) {
+ return referenceObject.getParentServiceName();
+ } else {
+ return referenceBuilder.getParentServiceName();
+ }
+ }
+
+ public void setParentServiceName(String value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setParentServiceName(value);
+ }
+ }
+
+ public UniqueId getParentTraceSegmentId() {
+ if (isOrigin) {
+ return referenceObject.getParentTraceSegmentId();
+ } else {
+ return referenceBuilder.getParentTraceSegmentId();
+ }
+ }
+
+ public int getNetworkAddressId() {
+ if (isOrigin) {
+ return referenceObject.getNetworkAddressId();
+ } else {
+ return referenceBuilder.getNetworkAddressId();
+ }
+ }
+
+ public void setNetworkAddressId(int value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setNetworkAddressId(value);
+ }
+ }
+
+ public String getNetworkAddress() {
+ if (isOrigin) {
+ return referenceObject.getNetworkAddress();
+ } else {
+ return referenceBuilder.getNetworkAddress();
+ }
+ }
+
+ public void setNetworkAddress(String value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ referenceBuilder.setNetworkAddress(value);
+ }
+ }
+
+ @Override public void toBuilder() {
+ this.isOrigin = false;
+ referenceBuilder = referenceObject.toBuilder();
+ standardBuilder.toBuilder();
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceIdExchanger.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceIdExchanger.java
new file mode 100644
index 0000000000000000000000000000000000000000..10b43955cd9e45d52c4e5e1ffc896553f6213f54
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/ReferenceIdExchanger.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.collector.cache.ApplicationCache;
+import org.skywalking.apm.collector.cache.InstanceCache;
+import org.skywalking.apm.collector.cache.ServiceIdCache;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public class ReferenceIdExchanger implements IdExchanger {
+
+ private final Logger logger = LoggerFactory.getLogger(ReferenceIdExchanger.class);
+
+ private static ReferenceIdExchanger EXCHANGER;
+
+ public static ReferenceIdExchanger getInstance() {
+ if (EXCHANGER == null) {
+ EXCHANGER = new ReferenceIdExchanger();
+ }
+ return EXCHANGER;
+ }
+
+ @Override public boolean exchange(ReferenceDecorator standardBuilder, int applicationId) {
+ if (standardBuilder.getEntryServiceId() == 0 && StringUtils.isNotEmpty(standardBuilder.getEntryServiceName())) {
+ int entryServiceId = ServiceIdCache.get(InstanceCache.get(standardBuilder.getEntryApplicationInstanceId()), standardBuilder.getEntryServiceName());
+ if (entryServiceId == 0) {
+ return false;
+ } else {
+ standardBuilder.toBuilder();
+ standardBuilder.setEntryServiceId(entryServiceId);
+ standardBuilder.setEntryServiceName(Const.EMPTY_STRING);
+ }
+ }
+
+ if (standardBuilder.getParentServiceId() == 0 && StringUtils.isNotEmpty(standardBuilder.getParentServiceName())) {
+ int parentServiceId = ServiceIdCache.get(InstanceCache.get(standardBuilder.getParentApplicationInstanceId()), standardBuilder.getParentServiceName());
+ if (parentServiceId == 0) {
+ return false;
+ } else {
+ standardBuilder.toBuilder();
+ standardBuilder.setParentServiceId(parentServiceId);
+ standardBuilder.setParentServiceName(Const.EMPTY_STRING);
+ }
+ }
+
+ if (standardBuilder.getNetworkAddressId() == 0 && StringUtils.isNotEmpty(standardBuilder.getNetworkAddress())) {
+ int networkAddressId = ApplicationCache.get(standardBuilder.getNetworkAddress());
+ if (networkAddressId == 0) {
+ return false;
+ } else {
+ standardBuilder.toBuilder();
+ standardBuilder.setNetworkAddressId(networkAddressId);
+ standardBuilder.setNetworkAddress(Const.EMPTY_STRING);
+ }
+ }
+ return true;
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentDecorator.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentDecorator.java
new file mode 100644
index 0000000000000000000000000000000000000000..ca10618cda2621dd5997e107546afef203e7efb5
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentDecorator.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.network.proto.TraceSegmentObject;
+import org.skywalking.apm.network.proto.UniqueId;
+
+/**
+ * @author pengys5
+ */
+public class SegmentDecorator implements StandardBuilder {
+ private boolean isOrigin = true;
+ private final TraceSegmentObject segmentObject;
+ private TraceSegmentObject.Builder segmentBuilder;
+
+ public SegmentDecorator(TraceSegmentObject segmentObject) {
+ this.segmentObject = segmentObject;
+ }
+
+ public int getApplicationId() {
+ return segmentObject.getApplicationId();
+ }
+
+ public int getApplicationInstanceId() {
+ return segmentObject.getApplicationInstanceId();
+ }
+
+ public UniqueId getTraceSegmentId() {
+ return segmentObject.getTraceSegmentId();
+ }
+
+ public int getSpansCount() {
+ return segmentObject.getSpansCount();
+ }
+
+ public SpanDecorator getSpans(int index) {
+ if (isOrigin) {
+ return new SpanDecorator(segmentObject.getSpans(index), this);
+ } else {
+ return new SpanDecorator(segmentBuilder.getSpansBuilder(index), this);
+ }
+ }
+
+ public int getRefsCount() {
+ return segmentObject.getRefsCount();
+ }
+
+ public ReferenceDecorator getRefs(int index) {
+ if (isOrigin) {
+ return new ReferenceDecorator(segmentObject.getRefs(index), this);
+ } else {
+ return new ReferenceDecorator(segmentBuilder.getRefsBuilder(index), this);
+ }
+ }
+
+ public byte[] toByteArray() {
+ if (isOrigin) {
+ return segmentObject.toByteArray();
+ } else {
+ return segmentBuilder.build().toByteArray();
+ }
+ }
+
+ @Override public void toBuilder() {
+ if (!isOrigin) {
+ this.isOrigin = false;
+ this.segmentBuilder = segmentObject.toBuilder();
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentStandardizationWorker.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentStandardizationWorker.java
new file mode 100644
index 0000000000000000000000000000000000000000..c46d59c662f5127d0efccfb497d5d06602997dd1
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SegmentStandardizationWorker.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.collector.agentstream.worker.segment.buffer.SegmentBufferManager;
+import org.skywalking.apm.collector.core.queue.EndOfBatchCommand;
+import org.skywalking.apm.collector.storage.define.DataDefine;
+import org.skywalking.apm.collector.stream.worker.AbstractLocalAsyncWorker;
+import org.skywalking.apm.collector.stream.worker.AbstractLocalAsyncWorkerProvider;
+import org.skywalking.apm.collector.stream.worker.ClusterWorkerContext;
+import org.skywalking.apm.collector.stream.worker.ProviderNotFoundException;
+import org.skywalking.apm.collector.stream.worker.Role;
+import org.skywalking.apm.collector.stream.worker.WorkerException;
+import org.skywalking.apm.collector.stream.worker.impl.FlushAndSwitch;
+import org.skywalking.apm.collector.stream.worker.selector.ForeverFirstSelector;
+import org.skywalking.apm.collector.stream.worker.selector.WorkerSelector;
+import org.skywalking.apm.network.proto.UpstreamSegment;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public class SegmentStandardizationWorker extends AbstractLocalAsyncWorker {
+
+ private final Logger logger = LoggerFactory.getLogger(SegmentStandardizationWorker.class);
+
+ public SegmentStandardizationWorker(Role role, ClusterWorkerContext clusterContext) {
+ super(role, clusterContext);
+ }
+
+ @Override public void preStart() throws ProviderNotFoundException {
+ super.preStart();
+ SegmentBufferManager.INSTANCE.initialize();
+ }
+
+ @Override protected void onWork(Object message) throws WorkerException {
+ if (message instanceof FlushAndSwitch) {
+ SegmentBufferManager.INSTANCE.flush();
+ } else if (message instanceof EndOfBatchCommand) {
+ } else if (message instanceof UpstreamSegment) {
+ UpstreamSegment upstreamSegment = (UpstreamSegment)message;
+ SegmentBufferManager.INSTANCE.writeBuffer(upstreamSegment);
+ } else {
+ logger.error("unhandled message, message instance must UpstreamSegment, but is %s", message.getClass().toString());
+ }
+ }
+
+ public static class Factory extends AbstractLocalAsyncWorkerProvider {
+ @Override
+ public Role role() {
+ return SegmentStandardizationWorker.WorkerRole.INSTANCE;
+ }
+
+ @Override
+ public SegmentStandardizationWorker workerInstance(ClusterWorkerContext clusterContext) {
+ return new SegmentStandardizationWorker(role(), clusterContext);
+ }
+
+ @Override public int queueSize() {
+ return 1024;
+ }
+ }
+
+ public enum WorkerRole implements Role {
+ INSTANCE;
+
+ @Override
+ public String roleName() {
+ return SegmentStandardizationWorker.class.getSimpleName();
+ }
+
+ @Override
+ public WorkerSelector workerSelector() {
+ return new ForeverFirstSelector();
+ }
+
+ @Override public DataDefine dataDefine() {
+ return null;
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanDecorator.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanDecorator.java
new file mode 100644
index 0000000000000000000000000000000000000000..08319ea3e5f3c95e9e5fdc5003b8e0e74f891686
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanDecorator.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.network.proto.SpanLayer;
+import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.network.proto.SpanType;
+
+/**
+ * @author pengys5
+ */
+public class SpanDecorator implements StandardBuilder {
+ private boolean isOrigin = true;
+ private StandardBuilder standardBuilder;
+ private SpanObject spanObject;
+ private SpanObject.Builder spanBuilder;
+
+ public SpanDecorator(SpanObject spanObject, StandardBuilder standardBuilder) {
+ this.spanObject = spanObject;
+ this.standardBuilder = standardBuilder;
+ }
+
+ public SpanDecorator(SpanObject.Builder spanBuilder, StandardBuilder standardBuilder) {
+ this.spanBuilder = spanBuilder;
+ this.standardBuilder = standardBuilder;
+ this.isOrigin = false;
+ }
+
+ public int getSpanId() {
+ if (isOrigin) {
+ return spanObject.getSpanId();
+ } else {
+ return spanBuilder.getSpanId();
+ }
+ }
+
+ public int getParentSpanId() {
+ if (isOrigin) {
+ return spanObject.getParentSpanId();
+ } else {
+ return spanBuilder.getParentSpanId();
+ }
+ }
+
+ public SpanType getSpanType() {
+ if (isOrigin) {
+ return spanObject.getSpanType();
+ } else {
+ return spanBuilder.getSpanType();
+ }
+ }
+
+ public int getSpanTypeValue() {
+ if (isOrigin) {
+ return spanObject.getSpanTypeValue();
+ } else {
+ return spanBuilder.getSpanTypeValue();
+ }
+ }
+
+ public SpanLayer getSpanLayer() {
+ if (isOrigin) {
+ return spanObject.getSpanLayer();
+ } else {
+ return spanBuilder.getSpanLayer();
+ }
+ }
+
+ public int getSpanLayerValue() {
+ if (isOrigin) {
+ return spanObject.getSpanLayerValue();
+ } else {
+ return spanBuilder.getSpanLayerValue();
+ }
+ }
+
+ public long getStartTime() {
+ if (isOrigin) {
+ return spanObject.getStartTime();
+ } else {
+ return spanBuilder.getStartTime();
+ }
+ }
+
+ public long getEndTime() {
+ if (isOrigin) {
+ return spanObject.getEndTime();
+ } else {
+ return spanBuilder.getEndTime();
+ }
+ }
+
+ public int getComponentId() {
+ if (isOrigin) {
+ return spanObject.getComponentId();
+ } else {
+ return spanBuilder.getComponentId();
+ }
+ }
+
+ public String getComponent() {
+ if (isOrigin) {
+ return spanObject.getComponent();
+ } else {
+ return spanBuilder.getComponent();
+ }
+ }
+
+ public int getPeerId() {
+ if (isOrigin) {
+ return spanObject.getPeerId();
+ } else {
+ return spanBuilder.getPeerId();
+ }
+ }
+
+ public void setPeerId(int peerId) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ spanBuilder.setPeerId(peerId);
+ }
+ }
+
+ public String getPeer() {
+ if (isOrigin) {
+ return spanObject.getPeer();
+ } else {
+ return spanBuilder.getPeer();
+ }
+ }
+
+ public void setPeer(String peer) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ spanBuilder.setPeer(peer);
+ }
+ }
+
+ public int getOperationNameId() {
+ if (isOrigin) {
+ return spanObject.getOperationNameId();
+ } else {
+ return spanBuilder.getOperationNameId();
+ }
+ }
+
+ public void setOperationNameId(int value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ spanBuilder.setOperationNameId(value);
+ }
+ }
+
+ public String getOperationName() {
+ if (isOrigin) {
+ return spanObject.getOperationName();
+ } else {
+ return spanBuilder.getOperationName();
+ }
+ }
+
+ public void setOperationName(String value) {
+ if (isOrigin) {
+ toBuilder();
+ } else {
+ spanBuilder.setOperationName(value);
+ }
+ }
+
+ public boolean getIsError() {
+ if (isOrigin) {
+ return spanObject.getIsError();
+ } else {
+ return spanBuilder.getIsError();
+ }
+ }
+
+ @Override public void toBuilder() {
+ this.isOrigin = false;
+ spanBuilder = spanObject.toBuilder();
+ standardBuilder.toBuilder();
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanIdExchanger.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanIdExchanger.java
new file mode 100644
index 0000000000000000000000000000000000000000..b06a1c54039457712ce9a30be3b47cb244fdcff9
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/SpanIdExchanger.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+import org.skywalking.apm.collector.cache.ApplicationCache;
+import org.skywalking.apm.collector.cache.ServiceIdCache;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
+
+/**
+ * @author pengys5
+ */
+public class SpanIdExchanger implements IdExchanger {
+
+ private static SpanIdExchanger EXCHANGER;
+
+ public static SpanIdExchanger getInstance() {
+ if (EXCHANGER == null) {
+ EXCHANGER = new SpanIdExchanger();
+ }
+ return EXCHANGER;
+ }
+
+ @Override public boolean exchange(SpanDecorator standardBuilder, int applicationId) {
+ if (standardBuilder.getPeerId() == 0 && StringUtils.isNotEmpty(standardBuilder.getPeer())) {
+ int peerId = ApplicationCache.get(standardBuilder.getPeer());
+ if (peerId == 0) {
+ return false;
+ } else {
+ standardBuilder.toBuilder();
+ standardBuilder.setPeerId(peerId);
+ standardBuilder.setPeer(Const.EMPTY_STRING);
+ }
+ }
+
+ if (standardBuilder.getOperationNameId() == 0 && StringUtils.isNotEmpty(standardBuilder.getOperationName())) {
+ int operationNameId = ServiceIdCache.get(applicationId, standardBuilder.getOperationName());
+ if (operationNameId == 0) {
+ return false;
+ } else {
+ standardBuilder.toBuilder();
+ standardBuilder.setOperationNameId(operationNameId);
+ standardBuilder.setOperationName(Const.EMPTY_STRING);
+ }
+ }
+ return true;
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/StandardBuilder.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/StandardBuilder.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ab7eb43f4b30c4b088a624dc1f4d82cef9bdcf6
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/standardization/StandardBuilder.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.standardization;
+
+/**
+ * @author pengys5
+ */
+public interface StandardBuilder {
+ void toBuilder();
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/ServiceEntrySpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/ServiceEntrySpanListener.java
index 0fc14aca49860d757362f09f4ef8b731c143c2fe..c93edd9fbaa7afd6ca8ce93038c85b36983a2a02 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/ServiceEntrySpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/ServiceEntrySpanListener.java
@@ -18,10 +18,12 @@
package org.skywalking.apm.collector.agentstream.worker.service.entry;
-import org.skywalking.apm.collector.agentstream.worker.cache.ServiceCache;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.RefsListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -30,8 +32,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,25 +50,23 @@ public class ServiceEntrySpanListener implements RefsListener, FirstSpanListener
private boolean hasEntry = false;
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
this.applicationId = applicationId;
- this.entryServiceId = spanObject.getOperationNameId();
- if (spanObject.getOperationNameId() == 0) {
- this.entryServiceName = spanObject.getOperationName();
- } else {
- this.entryServiceName = ServiceCache.getServiceName(this.entryServiceId);
- }
+ this.entryServiceId = spanDecorator.getOperationNameId();
+ this.entryServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(entryServiceId));
this.hasEntry = true;
}
- @Override public void parseRef(TraceSegmentReference reference, int applicationId, int applicationInstanceId,
+ @Override public void parseRef(ReferenceDecorator referenceDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
hasReference = true;
}
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
@Override public void build() {
@@ -76,7 +74,7 @@ public class ServiceEntrySpanListener implements RefsListener, FirstSpanListener
StreamModuleContext context = (StreamModuleContext)CollectorContextHelper.INSTANCE.getContext(StreamModuleGroupDefine.GROUP_NAME);
if (!hasReference && hasEntry) {
ServiceEntryDataDefine.ServiceEntry serviceEntry = new ServiceEntryDataDefine.ServiceEntry();
- serviceEntry.setId(applicationId + Const.ID_SPLIT + entryServiceName);
+ serviceEntry.setId(applicationId + Const.ID_SPLIT + entryServiceId);
serviceEntry.setApplicationId(applicationId);
serviceEntry.setEntryServiceId(entryServiceId);
serviceEntry.setEntryServiceName(entryServiceName);
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/dao/ServiceEntryH2DAO.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/dao/ServiceEntryH2DAO.java
index 6f91ba64ce7690e234b0cd2cf3784943bb240036..27140ae12560dad9b93840461c4eca876905d05d 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/dao/ServiceEntryH2DAO.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/service/entry/dao/ServiceEntryH2DAO.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.stream.Data;
@@ -42,10 +41,11 @@ import org.slf4j.LoggerFactory;
*/
public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersistenceDAO {
private final Logger logger = LoggerFactory.getLogger(ServiceEntryH2DAO.class);
- private static final String GET_SERIVCE_ENTRY_SQL = "select * from {0} where {1} = ?";
+ private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} = ?";
+
@Override public Data get(String id, DataDefine dataDefine) {
H2Client client = getClient();
- String sql = SqlBuilder.buildSql(ServiceEntryTable.TABLE, "id");
+ String sql = SqlBuilder.buildSql(GET_SERVICE_ENTRY_SQL, ServiceEntryTable.TABLE, "id");
Object[] params = new Object[] {id};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
@@ -62,6 +62,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersi
}
return null;
}
+
@Override public H2SqlEntity prepareBatchInsert(Data data) {
H2SqlEntity entity = new H2SqlEntity();
Map source = new HashMap<>();
@@ -76,6 +77,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO, IPersi
entity.setParams(source.values().toArray(new Object[0]));
return entity;
}
+
@Override public H2SqlEntity prepareBatchUpdate(Data data) {
H2SqlEntity entity = new H2SqlEntity();
Map source = new HashMap<>();
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/serviceref/ServiceReferenceSpanListener.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/serviceref/ServiceReferenceSpanListener.java
index 6a15ae294718d8d4a8921a968ac32cd1cf0b1296..d75d55c319e45e14a48b768df73b370ef55130ed 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/serviceref/ServiceReferenceSpanListener.java
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/serviceref/ServiceReferenceSpanListener.java
@@ -20,10 +20,11 @@ package org.skywalking.apm.collector.agentstream.worker.serviceref;
import java.util.LinkedList;
import java.util.List;
-import org.skywalking.apm.collector.agentstream.worker.cache.InstanceCache;
import org.skywalking.apm.collector.agentstream.worker.segment.EntrySpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.FirstSpanListener;
import org.skywalking.apm.collector.agentstream.worker.segment.RefsListener;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.ReferenceDecorator;
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SpanDecorator;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -32,8 +33,6 @@ import org.skywalking.apm.collector.stream.StreamModuleContext;
import org.skywalking.apm.collector.stream.StreamModuleGroupDefine;
import org.skywalking.apm.collector.stream.worker.WorkerInvokeException;
import org.skywalking.apm.collector.stream.worker.WorkerNotFoundException;
-import org.skywalking.apm.network.proto.SpanObject;
-import org.skywalking.apm.network.proto.TraceSegmentReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,9 +43,8 @@ public class ServiceReferenceSpanListener implements FirstSpanListener, EntrySpa
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceSpanListener.class);
- private List referenceServices = new LinkedList<>();
+ private List referenceServices = new LinkedList<>();
private int serviceId = 0;
- private String serviceName = "";
private long startTime = 0;
private long endTime = 0;
private boolean isError = false;
@@ -54,26 +52,23 @@ public class ServiceReferenceSpanListener implements FirstSpanListener, EntrySpa
private boolean hasEntry = false;
@Override
- public void parseFirst(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanObject.getStartTime());
+ public void parseFirst(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime());
}
- @Override public void parseRef(TraceSegmentReference reference, int applicationId, int applicationInstanceId,
+ @Override public void parseRef(ReferenceDecorator referenceDecorator, int applicationId, int applicationInstanceId,
String segmentId) {
- referenceServices.add(reference);
+ referenceServices.add(referenceDecorator);
}
@Override
- public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
- serviceId = spanObject.getOperationNameId();
- if (spanObject.getOperationNameId() == 0) {
- serviceName = String.valueOf(applicationId) + Const.ID_SPLIT + spanObject.getOperationName();
- } else {
- serviceName = Const.EMPTY_STRING;
- }
- startTime = spanObject.getStartTime();
- endTime = spanObject.getEndTime();
- isError = spanObject.getIsError();
+ public void parseEntry(SpanDecorator spanDecorator, int applicationId, int applicationInstanceId,
+ String segmentId) {
+ serviceId = spanDecorator.getOperationNameId();
+ startTime = spanDecorator.getStartTime();
+ endTime = spanDecorator.getEndTime();
+ isError = spanDecorator.getIsError();
this.hasEntry = true;
}
@@ -105,71 +100,39 @@ public class ServiceReferenceSpanListener implements FirstSpanListener, EntrySpa
referenceServices.forEach(reference -> {
ServiceReferenceDataDefine.ServiceReference serviceReference = new ServiceReferenceDataDefine.ServiceReference();
int entryServiceId = reference.getEntryServiceId();
- String entryServiceName = buildServiceName(reference.getEntryApplicationInstanceId(), reference.getEntryServiceId(), reference.getEntryServiceName());
-
int frontServiceId = reference.getParentServiceId();
- String frontServiceName = buildServiceName(reference.getParentApplicationInstanceId(), reference.getParentServiceId(), reference.getParentServiceName());
-
int behindServiceId = serviceId;
- String behindServiceName = serviceName;
-
calculateCost(serviceReference, startTime, endTime, isError);
- logger.debug("has reference, entryServiceId: {}, entryServiceName: {}", entryServiceId, entryServiceName);
- sendToAggregationWorker(context, serviceReference, entryServiceId, entryServiceName, frontServiceId, frontServiceName, behindServiceId, behindServiceName);
+ logger.debug("has reference, entryServiceId: {}", entryServiceId);
+ sendToAggregationWorker(context, serviceReference, entryServiceId, frontServiceId, behindServiceId);
});
} else {
ServiceReferenceDataDefine.ServiceReference serviceReference = new ServiceReferenceDataDefine.ServiceReference();
int entryServiceId = serviceId;
- String entryServiceName = serviceName;
-
int frontServiceId = Const.NONE_SERVICE_ID;
- String frontServiceName = Const.EMPTY_STRING;
-
int behindServiceId = serviceId;
- String behindServiceName = serviceName;
calculateCost(serviceReference, startTime, endTime, isError);
- sendToAggregationWorker(context, serviceReference, entryServiceId, entryServiceName, frontServiceId, frontServiceName, behindServiceId, behindServiceName);
+ sendToAggregationWorker(context, serviceReference, entryServiceId, frontServiceId, behindServiceId);
}
}
}
private void sendToAggregationWorker(StreamModuleContext context,
- ServiceReferenceDataDefine.ServiceReference serviceReference, int entryServiceId, String entryServiceName,
- int frontServiceId, String frontServiceName, int behindServiceId, String behindServiceName) {
-
+ ServiceReferenceDataDefine.ServiceReference serviceReference, int entryServiceId, int frontServiceId,
+ int behindServiceId) {
StringBuilder idBuilder = new StringBuilder();
idBuilder.append(timeBucket).append(Const.ID_SPLIT);
- if (entryServiceId == 0) {
- idBuilder.append(entryServiceName).append(Const.ID_SPLIT);
- serviceReference.setEntryServiceId(0);
- serviceReference.setEntryServiceName(entryServiceName);
- } else {
- idBuilder.append(entryServiceId).append(Const.ID_SPLIT);
- serviceReference.setEntryServiceId(entryServiceId);
- serviceReference.setEntryServiceName(Const.EMPTY_STRING);
- }
- if (frontServiceId == 0) {
- idBuilder.append(frontServiceName).append(Const.ID_SPLIT);
- serviceReference.setFrontServiceId(0);
- serviceReference.setFrontServiceName(frontServiceName);
- } else {
- idBuilder.append(frontServiceId).append(Const.ID_SPLIT);
- serviceReference.setFrontServiceId(frontServiceId);
- serviceReference.setFrontServiceName(Const.EMPTY_STRING);
- }
+ idBuilder.append(entryServiceId).append(Const.ID_SPLIT);
+ serviceReference.setEntryServiceId(entryServiceId);
- if (behindServiceId == 0) {
- idBuilder.append(behindServiceName);
- serviceReference.setBehindServiceId(0);
- serviceReference.setBehindServiceName(behindServiceName);
- } else {
- idBuilder.append(behindServiceId);
- serviceReference.setBehindServiceId(behindServiceId);
- serviceReference.setBehindServiceName(Const.EMPTY_STRING);
- }
+ idBuilder.append(frontServiceId).append(Const.ID_SPLIT);
+ serviceReference.setFrontServiceId(frontServiceId);
+
+ idBuilder.append(behindServiceId);
+ serviceReference.setBehindServiceId(behindServiceId);
serviceReference.setId(idBuilder.toString());
serviceReference.setTimeBucket(timeBucket);
@@ -180,13 +143,4 @@ public class ServiceReferenceSpanListener implements FirstSpanListener, EntrySpa
logger.error(e.getMessage(), e);
}
}
-
- private String buildServiceName(int instanceId, int serviceId, String serviceName) {
- if (serviceId == 0) {
- int applicationId = InstanceCache.get(instanceId);
- return String.valueOf(applicationId) + Const.ID_SPLIT + serviceName;
- } else {
- return Const.EMPTY_STRING;
- }
- }
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/FileUtils.java b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/FileUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..ab70f6288da71168c74d00d841a1cb496c4c75a3
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/FileUtils.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.util;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import org.skywalking.apm.collector.core.util.Const;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public enum FileUtils {
+ INSTANCE;
+
+ private final Logger logger = LoggerFactory.getLogger(FileUtils.class);
+
+ public String readLastLine(File file) {
+ RandomAccessFile randomAccessFile = null;
+ try {
+ randomAccessFile = new RandomAccessFile(file, "r");
+ long length = randomAccessFile.length();
+ if (length == 0) {
+ return Const.EMPTY_STRING;
+ } else {
+ long position = length - 1;
+ randomAccessFile.seek(position);
+ while (position >= 0) {
+ if (randomAccessFile.read() == '\n') {
+ return randomAccessFile.readLine();
+ }
+ randomAccessFile.seek(position);
+ if (position == 0) {
+ return randomAccessFile.readLine();
+ }
+ position--;
+ }
+ }
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ } finally {
+ if (randomAccessFile != null) {
+ try {
+ randomAccessFile.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }
+ return Const.EMPTY_STRING;
+ }
+
+ public void writeAppendToLast(File file, RandomAccessFile randomAccessFile, String value) {
+ if (randomAccessFile == null) {
+ try {
+ randomAccessFile = new RandomAccessFile(file, "rwd");
+ } catch (FileNotFoundException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ try {
+ long length = randomAccessFile.length();
+ randomAccessFile.seek(length);
+ randomAccessFile.writeBytes(System.lineSeparator());
+ randomAccessFile.writeBytes(value);
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/main/resources/META-INF/defines/local_worker_provider.define b/apm-collector/apm-collector-agentstream/src/main/resources/META-INF/defines/local_worker_provider.define
index 638630fa12052a18ca3499ef2f57aea0a48b2880..465adeac2503ce737b67594891d005e2ade0de8b 100644
--- a/apm-collector/apm-collector-agentstream/src/main/resources/META-INF/defines/local_worker_provider.define
+++ b/apm-collector/apm-collector-agentstream/src/main/resources/META-INF/defines/local_worker_provider.define
@@ -15,6 +15,8 @@ org.skywalking.apm.collector.agentstream.worker.serviceref.ServiceReferencePersi
org.skywalking.apm.collector.agentstream.worker.segment.origin.SegmentPersistenceWorker$Factory
org.skywalking.apm.collector.agentstream.worker.segment.cost.SegmentCostPersistenceWorker$Factory
+org.skywalking.apm.collector.agentstream.worker.segment.standardization.SegmentStandardizationWorker$Factory
+
org.skywalking.apm.collector.agentstream.worker.global.GlobalTracePersistenceWorker$Factory
org.skywalking.apm.collector.agentstream.worker.instance.performance.InstPerformancePersistenceWorker$Factory
\ No newline at end of file
diff --git a/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandlerTestCase.java b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandlerTestCase.java
index 30bb961505a879e00d392338c5fc4aa8485286c3..e23634e30b72aee8984488772c02fd775b689865 100644
--- a/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandlerTestCase.java
+++ b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/grpc/handler/TraceSegmentServiceHandlerTestCase.java
@@ -21,6 +21,7 @@ package org.skywalking.apm.collector.agentstream.grpc.handler;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.stub.StreamObserver;
+import org.junit.Test;
import org.skywalking.apm.network.proto.Downstream;
import org.skywalking.apm.network.proto.KeyWithStringValue;
import org.skywalking.apm.network.proto.LogMessage;
@@ -45,6 +46,7 @@ public class TraceSegmentServiceHandlerTestCase {
private TraceSegmentServiceGrpc.TraceSegmentServiceStub stub;
+ @Test
public void testCollect() {
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 11800).usePlaintext(true).build();
stub = TraceSegmentServiceGrpc.newStub(channel);
@@ -70,7 +72,7 @@ public class TraceSegmentServiceHandlerTestCase {
streamObserver.onCompleted();
try {
- Thread.sleep(30000);
+ Thread.sleep(10000);
} catch (InterruptedException e) {
}
}
diff --git a/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/mock/SegmentPost.java b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/mock/SegmentPost.java
index 3c6b63dc6b50f50e430e5a328ea91d7a14ab2359..f93be5463e4755c16316afa3906586d178e01101 100644
--- a/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/mock/SegmentPost.java
+++ b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/mock/SegmentPost.java
@@ -22,16 +22,21 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.IOException;
-import org.skywalking.apm.collector.agentregister.worker.application.dao.ApplicationEsDAO;
-import org.skywalking.apm.collector.agentregister.worker.instance.dao.InstanceEsDAO;
-import org.skywalking.apm.collector.agentregister.worker.servicename.dao.ServiceNameEsDAO;
+import org.skywalking.apm.collector.agentregister.worker.application.dao.IApplicationDAO;
+import org.skywalking.apm.collector.agentregister.worker.instance.dao.IInstanceDAO;
+import org.skywalking.apm.collector.agentregister.worker.servicename.dao.IServiceNameDAO;
import org.skywalking.apm.collector.agentstream.HttpClientTools;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
+import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.core.CollectorException;
+import org.skywalking.apm.collector.core.config.SystemConfig;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
+import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.register.ApplicationDataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefine;
+import org.skywalking.apm.collector.storage.elasticsearch.StorageElasticSearchModuleDefine;
+import org.skywalking.apm.collector.storage.h2.StorageH2ModuleDefine;
/**
* @author pengys5
@@ -39,39 +44,47 @@ import org.skywalking.apm.collector.storage.define.register.ServiceNameDataDefin
public class SegmentPost {
public static void main(String[] args) throws IOException, InterruptedException, CollectorException {
- ElasticSearchClient client = new ElasticSearchClient("CollectorDBCluster", true, "127.0.0.1:9300");
- client.initialize();
- long now = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis());
+ SystemConfig.DATA_PATH = "/Users/pengys5/code/sky-walking/sky-walking/apm-collector/data";
+
+ ElasticSearchClient elasticSearchClient = new ElasticSearchClient("CollectorDBCluster", true, "127.0.0.1:9300");
+ elasticSearchClient.initialize();
+ StorageElasticSearchModuleDefine storageElasticSearchModuleDefine = new StorageElasticSearchModuleDefine();
+ storageElasticSearchModuleDefine.injectClientIntoDAO(elasticSearchClient);
- InstanceEsDAO instanceEsDAO = new InstanceEsDAO();
- instanceEsDAO.setClient(client);
+ H2Client h2Client = new H2Client("jdbc:h2:tcp://localhost/~/test", "sa", "");
+ h2Client.initialize();
+ StorageH2ModuleDefine storageH2ModuleDefine = new StorageH2ModuleDefine();
+ storageH2ModuleDefine.injectClientIntoDAO(h2Client);
+
+ long now = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis());
+ IInstanceDAO instanceDAO = (IInstanceDAO)DAOContainer.INSTANCE.get(IInstanceDAO.class.getName());
InstanceDataDefine.Instance consumerInstance = new InstanceDataDefine.Instance("2", 2, "dubbox-consumer", now, 2, now, osInfo("consumer").toString());
- instanceEsDAO.save(consumerInstance);
+ instanceDAO.save(consumerInstance);
InstanceDataDefine.Instance providerInstance = new InstanceDataDefine.Instance("3", 3, "dubbox-provider", now, 3, now, osInfo("provider").toString());
- instanceEsDAO.save(providerInstance);
+ instanceDAO.save(providerInstance);
- ApplicationEsDAO applicationEsDAO = new ApplicationEsDAO();
- applicationEsDAO.setClient(client);
+ IApplicationDAO applicationDAO = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
ApplicationDataDefine.Application userApplication = new ApplicationDataDefine.Application("1", "User", 1);
- applicationEsDAO.save(userApplication);
+ applicationDAO.save(userApplication);
ApplicationDataDefine.Application consumerApplication = new ApplicationDataDefine.Application("2", "dubbox-consumer", 2);
- applicationEsDAO.save(consumerApplication);
+ applicationDAO.save(consumerApplication);
ApplicationDataDefine.Application providerApplication = new ApplicationDataDefine.Application("3", "dubbox-provider", 3);
- applicationEsDAO.save(providerApplication);
+ applicationDAO.save(providerApplication);
+ ApplicationDataDefine.Application peer = new ApplicationDataDefine.Application("4", "172.25.0.4:20880", 4);
+ applicationDAO.save(peer);
- ServiceNameEsDAO serviceNameEsDAO = new ServiceNameEsDAO();
- serviceNameEsDAO.setClient(client);
+ IServiceNameDAO serviceNameDAO = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
ServiceNameDataDefine.ServiceName serviceName1 = new ServiceNameDataDefine.ServiceName("1", "", 0, 1);
- serviceNameEsDAO.save(serviceName1);
+ serviceNameDAO.save(serviceName1);
ServiceNameDataDefine.ServiceName serviceName2 = new ServiceNameDataDefine.ServiceName("2", "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", 2, 2);
- serviceNameEsDAO.save(serviceName2);
+ serviceNameDAO.save(serviceName2);
ServiceNameDataDefine.ServiceName serviceName3 = new ServiceNameDataDefine.ServiceName("3", "/dubbox-case/case/dubbox-rest", 2, 3);
- serviceNameEsDAO.save(serviceName3);
+ serviceNameDAO.save(serviceName3);
ServiceNameDataDefine.ServiceName serviceName4 = new ServiceNameDataDefine.ServiceName("4", "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", 3, 4);
- serviceNameEsDAO.save(serviceName4);
+ serviceNameDAO.save(serviceName4);
while (true) {
JsonElement consumer = JsonFileReader.INSTANCE.read("json/segment/normal/dubbox-consumer.json");
@@ -84,6 +97,7 @@ public class SegmentPost {
DIFF = 0;
Thread.sleep(1000);
+ break;
}
}
diff --git a/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferWriteWorkerTestCase.java b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferWriteWorkerTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb733105946660108eb4b81132c00c8a72cc37f0
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/test/java/org/skywalking/apm/collector/agentstream/worker/segment/buffer/SegmentBufferWriteWorkerTestCase.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.agentstream.worker.segment.buffer;
+
+import org.skywalking.apm.collector.agentstream.worker.segment.standardization.SegmentStandardizationWorker;
+import org.skywalking.apm.collector.stream.worker.ProviderNotFoundException;
+import org.skywalking.apm.collector.stream.worker.WorkerException;
+import org.skywalking.apm.network.proto.SpanLayer;
+import org.skywalking.apm.network.proto.SpanObject;
+import org.skywalking.apm.network.proto.SpanType;
+import org.skywalking.apm.network.proto.TraceSegmentObject;
+import org.skywalking.apm.network.proto.UniqueId;
+import org.skywalking.apm.network.proto.UpstreamSegment;
+import org.skywalking.apm.network.trace.component.ComponentsDefine;
+
+/**
+ * @author pengys5
+ */
+public class SegmentBufferWriteWorkerTestCase {
+
+ public static void main(String[] args) throws WorkerException, ProviderNotFoundException {
+ SegmentBufferConfig.BUFFER_PATH = "/Users/pengys5/code/sky-walking/sky-walking/apm-collector/buffer/";
+
+ SegmentStandardizationWorker worker = new SegmentStandardizationWorker(null, null);
+ worker.preStart();
+ worker.allocateJob(buildSegment());
+ worker.allocateJob(buildSegment());
+ worker.allocateJob(buildSegment());
+ worker.allocateJob(buildSegment());
+ worker.allocateJob(buildSegment());
+ }
+
+ private static UpstreamSegment buildSegment() {
+ long now = System.currentTimeMillis();
+
+ int id = 1;
+ UniqueId.Builder builder = UniqueId.newBuilder();
+ builder.addIdParts(id);
+ builder.addIdParts(id);
+ builder.addIdParts(id);
+ UniqueId segmentId = builder.build();
+
+ UpstreamSegment.Builder upstream = UpstreamSegment.newBuilder();
+ upstream.addGlobalTraceIds(segmentId);
+
+ TraceSegmentObject.Builder segmentBuilder = TraceSegmentObject.newBuilder();
+ segmentBuilder.setApplicationId(1);
+ segmentBuilder.setApplicationInstanceId(1);
+ segmentBuilder.setTraceSegmentId(segmentId);
+
+ SpanObject.Builder entrySpan = SpanObject.newBuilder();
+ entrySpan.setSpanId(0);
+ entrySpan.setSpanType(SpanType.Entry);
+ entrySpan.setSpanLayer(SpanLayer.Http);
+ entrySpan.setParentSpanId(-1);
+ entrySpan.setStartTime(now);
+ entrySpan.setEndTime(now + 3000);
+ entrySpan.setComponentId(ComponentsDefine.TOMCAT.getId());
+ entrySpan.setOperationNameId(1);
+ entrySpan.setIsError(false);
+ segmentBuilder.addSpans(entrySpan);
+
+ SpanObject.Builder exitSpan = SpanObject.newBuilder();
+ exitSpan.setSpanId(1);
+ exitSpan.setSpanType(SpanType.Exit);
+ exitSpan.setSpanLayer(SpanLayer.Database);
+ exitSpan.setParentSpanId(0);
+ exitSpan.setStartTime(now);
+ exitSpan.setEndTime(now + 3000);
+ exitSpan.setComponentId(ComponentsDefine.MONGODB.getId());
+ exitSpan.setOperationNameId(2);
+ exitSpan.setIsError(false);
+ exitSpan.setPeer("localhost:8888");
+ segmentBuilder.addSpans(exitSpan);
+
+ upstream.setSegment(segmentBuilder.build().toByteString());
+ return upstream.build();
+ }
+}
diff --git a/apm-collector/apm-collector-agentstream/src/test/resources/log4j2.xml b/apm-collector/apm-collector-agentstream/src/test/resources/log4j2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d36a4408f43f060b1694b84af3c5c5edad097e67
--- /dev/null
+++ b/apm-collector/apm-collector-agentstream/src/test/resources/log4j2.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java
index d003e210f752d1e002248b524a28dab82b0ca0dc..c7cf0200960a4da519c169e6c98d9f78afa4c0a5 100644
--- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java
+++ b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorBootStartUp.java
@@ -19,6 +19,7 @@
package org.skywalking.apm.collector.boot;
import org.skywalking.apm.collector.core.CollectorException;
+import org.skywalking.apm.collector.core.config.SystemConfigParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,6 +32,7 @@ public class CollectorBootStartUp {
public static void main(String[] args) throws CollectorException {
logger.info("collector starting...");
+ SystemConfigParser.INSTANCE.parse();
CollectorStarter starter = new CollectorStarter();
starter.start();
logger.info("collector start successful.");
diff --git a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorStarter.java b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorStarter.java
index afc1f0cd321432ba3e8fb681690299ea467cb367..6af1db391aa34dbf666eeea17541dabcb65ddba8 100644
--- a/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorStarter.java
+++ b/apm-collector/apm-collector-boot/src/main/java/org/skywalking/apm/collector/boot/CollectorStarter.java
@@ -53,6 +53,9 @@ public class CollectorStarter implements Starter {
ServerHolder serverHolder = new ServerHolder();
for (ModuleGroupDefine moduleGroupDefine : moduleGroupDefineMap.values()) {
+ if (moduleGroupDefine.groupConfigParser() != null) {
+ moduleGroupDefine.groupConfigParser().parse(configuration.get(moduleGroupDefine.name()));
+ }
moduleGroupDefine.moduleInstaller().injectConfiguration(configuration.get(moduleGroupDefine.name()), moduleDefineMap.get(moduleGroupDefine.name()));
moduleGroupDefine.moduleInstaller().injectServerHolder(serverHolder);
moduleGroupDefine.moduleInstaller().preInstall();
diff --git a/apm-collector/apm-collector-boot/src/main/resources/application.yml b/apm-collector/apm-collector-boot/src/main/resources/application.yml
index df8a938fb3919a655fe2dcb443daec50fae9e6cb..e6d654a9d4ed97df9b2379c7fcc784004bcc7297 100644
--- a/apm-collector/apm-collector-boot/src/main/resources/application.yml
+++ b/apm-collector/apm-collector-boot/src/main/resources/application.yml
@@ -1,7 +1,7 @@
-cluster:
- zookeeper:
- hostPort: localhost:2181
- sessionTimeout: 100000
+#cluster:
+# zookeeper:
+# hostPort: localhost:2181
+# sessionTimeout: 100000
agent_server:
jetty:
host: localhost
@@ -15,6 +15,9 @@ agent_stream:
host: localhost
port: 12800
context_path: /
+ config:
+ buffer_offset_max_file_size: 10M
+ buffer_segment_max_file_size: 500M
ui:
jetty:
host: localhost
@@ -24,16 +27,10 @@ collector_inside:
grpc:
host: localhost
port: 11800
-storage:
- elasticsearch:
- cluster_name: CollectorDBCluster
- cluster_transport_sniffer: true
- cluster_nodes: localhost:9300
- index_shards_number: 2
- index_replicas_number: 0
-# uncomment to enable h2 storage
#storage:
-# h2:
-# url: jdbc:h2:~/collector
-# user_name: sa
-# password: sa
\ No newline at end of file
+# elasticsearch:
+# cluster_name: CollectorDBCluster
+# cluster_transport_sniffer: true
+# cluster_nodes: localhost:9300
+# index_shards_number: 2
+# index_replicas_number: 0
\ No newline at end of file
diff --git a/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml b/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml
index 16e66109ef8cb19ce1e75ffeb5febe75bd5c9336..a79b4567702e91f5b83912e477cb81bec70270ba 100644
--- a/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml
+++ b/apm-collector/apm-collector-boot/src/main/resources/log4j2.xml
@@ -17,7 +17,7 @@
~ Project repository: https://github.com/OpenSkywalking/skywalking
-->
-
+
@@ -27,7 +27,8 @@
-
+
+
diff --git a/apm-collector/apm-collector-cache/pom.xml b/apm-collector/apm-collector-cache/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f3fac86dc4fdb1dd1d8c1995233d88e58202f58c
--- /dev/null
+++ b/apm-collector/apm-collector-cache/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ apm-collector
+ org.skywalking
+ 3.2.3-2017
+
+ 4.0.0
+
+ apm-collector-cache
+ jar
+
+
+
+ org.skywalking
+ apm-collector-core
+ ${project.version}
+
+
+ org.skywalking
+ apm-collector-storage
+ ${project.version}
+
+
+
\ No newline at end of file
diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java
new file mode 100644
index 0000000000000000000000000000000000000000..fda776f3b7f37a48db3cadcc9a725f7d5548a55a
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ApplicationCache.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.cache;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.skywalking.apm.collector.cache.dao.IApplicationCacheDAO;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
+import org.skywalking.apm.collector.storage.dao.DAOContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public class ApplicationCache {
+
+ private static final Logger logger = LoggerFactory.getLogger(ApplicationCache.class);
+
+ private static Cache CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
+
+ public static int get(String applicationCode) {
+ IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
+
+ int applicationId = 0;
+ try {
+ applicationId = CODE_CACHE.get(applicationCode, () -> dao.getApplicationId(applicationCode));
+ } catch (Throwable e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ if (applicationId == 0) {
+ applicationId = dao.getApplicationId(applicationCode);
+ if (applicationId != 0) {
+ CODE_CACHE.put(applicationCode, applicationId);
+ }
+ }
+ return applicationId;
+ }
+
+ private static Cache ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
+
+ public static String get(int applicationId) {
+ IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
+
+ String applicationCode = Const.EMPTY_STRING;
+ try {
+ applicationCode = ID_CACHE.get(applicationId, () -> dao.getApplicationCode(applicationId));
+ } catch (Throwable e) {
+ logger.error(e.getMessage(), e);
+ }
+
+ if (StringUtils.isEmpty(applicationCode)) {
+ applicationCode = dao.getApplicationCode(applicationId);
+ if (StringUtils.isNotEmpty(applicationCode)) {
+ CODE_CACHE.put(applicationCode, applicationId);
+ }
+ }
+ return applicationCode;
+ }
+}
diff --git a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/cache/ApplicationCache.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java
similarity index 55%
rename from apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/cache/ApplicationCache.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java
index 655f32e91ecf258d64067d03290a87a56ef4a0d9..8095c609bc81e807b05f28fae3a92b096cb1c040 100644
--- a/apm-collector/apm-collector-agentregister/src/main/java/org/skywalking/apm/collector/agentregister/worker/cache/ApplicationCache.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/InstanceCache.java
@@ -16,36 +16,38 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.agentregister.worker.cache;
+package org.skywalking.apm.collector.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
-import org.skywalking.apm.collector.agentregister.worker.application.dao.IApplicationDAO;
+import org.skywalking.apm.collector.cache.dao.IInstanceCacheDAO;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
-public class ApplicationCache {
+public class InstanceCache {
- private static Cache CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
+ private static final Logger logger = LoggerFactory.getLogger(InstanceCache.class);
+
+ private static Cache INSTANCE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
+
+ public static int get(int applicationInstanceId) {
+ IInstanceCacheDAO dao = (IInstanceCacheDAO)DAOContainer.INSTANCE.get(IInstanceCacheDAO.class.getName());
- public static int get(String applicationCode) {
int applicationId = 0;
try {
- applicationId = CACHE.get(applicationCode, () -> {
- IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
- return dao.getApplicationId(applicationCode);
- });
+ applicationId = INSTANCE_CACHE.get(applicationInstanceId, () -> dao.getApplicationId(applicationInstanceId));
} catch (Throwable e) {
- return applicationId;
+ logger.error(e.getMessage(), e);
}
if (applicationId == 0) {
- IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
- applicationId = dao.getApplicationId(applicationCode);
+ applicationId = dao.getApplicationId(applicationInstanceId);
if (applicationId != 0) {
- CACHE.put(applicationCode, applicationId);
+ INSTANCE_CACHE.put(applicationInstanceId, applicationId);
}
}
return applicationId;
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceIdCache.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java
similarity index 59%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceIdCache.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java
index 077522ba49ae1e86628673f0ae46048a62899543..4cb2660935d332be72488e21ebaa126d69ddabc3 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceIdCache.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceIdCache.java
@@ -16,39 +16,41 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.cache;
+package org.skywalking.apm.collector.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
+import org.skywalking.apm.collector.cache.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
-import org.skywalking.apm.collector.ui.dao.IServiceNameDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
public class ServiceIdCache {
+ private static final Logger logger = LoggerFactory.getLogger(ServiceIdCache.class);
+
//TODO size configuration
- private static Cache CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
+ private static Cache SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
public static int get(int applicationId, String serviceName) {
+ IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
+
+ int serviceId = 0;
try {
- return CACHE.get(applicationId + Const.ID_SPLIT + serviceName, () -> {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
- return dao.getServiceId(applicationId, serviceName);
- });
+ serviceId = SERVICE_CACHE.get(applicationId + Const.ID_SPLIT + serviceName, () -> dao.getServiceId(applicationId, serviceName));
} catch (Throwable e) {
- return 0;
+ logger.error(e.getMessage(), e);
}
- }
- public static int getForUI(int applicationId, String serviceName) {
- int serviceId = get(applicationId, serviceName);
if (serviceId == 0) {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
serviceId = dao.getServiceId(applicationId, serviceName);
- CACHE.put(applicationId + Const.ID_SPLIT + serviceName, serviceId);
+ if (serviceId != 0) {
+ SERVICE_CACHE.put(applicationId + Const.ID_SPLIT + serviceName, serviceId);
+ }
}
return serviceId;
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceNameCache.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java
similarity index 52%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceNameCache.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java
index 0b2d9d28c33fe0b011a7fdec3f2b404a1ca7f964..16d1766b33a0536bbde91a37072f2b8dc52e4388 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ServiceNameCache.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/ServiceNameCache.java
@@ -16,40 +16,57 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.cache;
+package org.skywalking.apm.collector.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
+import org.skywalking.apm.collector.cache.dao.IServiceNameCacheDAO;
import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
-import org.skywalking.apm.collector.ui.dao.IServiceNameDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
public class ServiceNameCache {
+ private static final Logger logger = LoggerFactory.getLogger(ServiceNameCache.class);
+
//TODO size configuration
private static Cache CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
public static String get(int serviceId) {
+ IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
+
+ String serviceName = Const.EMPTY_STRING;
try {
- return CACHE.get(serviceId, () -> {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
- return dao.getServiceName(serviceId);
- });
+ serviceName = CACHE.get(serviceId, () -> dao.getServiceName(serviceId));
} catch (Throwable e) {
- return Const.EXCEPTION;
+ logger.error(e.getMessage(), e);
}
- }
- public static String getForUI(int serviceId) {
- String serviceName = get(serviceId);
- if (serviceName.equals("Unknown")) {
- IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
+ if (StringUtils.isEmpty(serviceName)) {
serviceName = dao.getServiceName(serviceId);
- CACHE.put(serviceId, serviceName);
+ if (StringUtils.isNotEmpty(serviceName)) {
+ CACHE.put(serviceId, serviceName);
+ }
}
+
return serviceName;
}
+
+ public static String getSplitServiceName(String serviceName) {
+ if (StringUtils.isNotEmpty(serviceName)) {
+ String[] serviceNames = serviceName.split(Const.ID_SPLIT);
+ if (serviceNames.length == 2) {
+ return serviceNames[1];
+ } else {
+ return Const.EMPTY_STRING;
+ }
+ } else {
+ return Const.EMPTY_STRING;
+ }
+ }
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationEsDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationEsCacheDAO.java
similarity index 57%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationEsDAO.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationEsCacheDAO.java
index acfd78f5b80138853c51c08844d1936e207f6f10..cfd14a85b3d6e07b57ef7bc95917765b2f48376a 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationEsDAO.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationEsCacheDAO.java
@@ -16,10 +16,15 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.cache.dao;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchType;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.SearchHit;
import org.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
@@ -30,9 +35,26 @@ import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
-public class ApplicationEsDAO extends EsDAO implements IApplicationDAO {
+public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO {
- private final Logger logger = LoggerFactory.getLogger(ApplicationEsDAO.class);
+ private final Logger logger = LoggerFactory.getLogger(ApplicationEsCacheDAO.class);
+
+ @Override public int getApplicationId(String applicationCode) {
+ ElasticSearchClient client = getClient();
+
+ SearchRequestBuilder searchRequestBuilder = client.prepareSearch(ApplicationTable.TABLE);
+ searchRequestBuilder.setTypes("type");
+ searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
+ searchRequestBuilder.setQuery(QueryBuilders.termQuery(ApplicationTable.COLUMN_APPLICATION_CODE, applicationCode));
+ searchRequestBuilder.setSize(1);
+
+ SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
+ if (searchResponse.getHits().totalHits > 0) {
+ SearchHit searchHit = searchResponse.getHits().iterator().next();
+ return (int)searchHit.getSource().get(ApplicationTable.COLUMN_APPLICATION_ID);
+ }
+ return 0;
+ }
@Override public String getApplicationCode(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
@@ -43,6 +65,6 @@ public class ApplicationEsDAO extends EsDAO implements IApplicationDAO {
if (getResponse.isExists()) {
return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE);
}
- return Const.UNKNOWN;
+ return Const.EMPTY_STRING;
}
}
diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationH2CacheDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationH2CacheDAO.java
new file mode 100644
index 0000000000000000000000000000000000000000..a22acbc1323350fa5be9d529574a0ceaa7d87bd0
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ApplicationH2CacheDAO.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.cache.dao;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import org.skywalking.apm.collector.client.h2.H2Client;
+import org.skywalking.apm.collector.client.h2.H2ClientException;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
+import org.skywalking.apm.collector.storage.h2.SqlBuilder;
+import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5, clevertension
+ */
+public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO {
+
+ private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class);
+ private static final String GET_APPLICATION_ID_OR_CODE_SQL = "select {0} from {1} where {2} = ?";
+
+ @Override
+ public int getApplicationId(String applicationCode) {
+ logger.info("get the application id with application code = {}", applicationCode);
+ H2Client client = getClient();
+ String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_ID, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_CODE);
+
+ Object[] params = new Object[] {applicationCode};
+ try (ResultSet rs = client.executeQuery(sql, params)) {
+ if (rs.next()) {
+ return rs.getInt(1);
+ }
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return 0;
+ }
+
+ @Override public String getApplicationCode(int applicationId) {
+ logger.debug("get application code, applicationId: {}", applicationId);
+ H2Client client = getClient();
+ String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_OR_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
+ Object[] params = new Object[] {applicationId};
+ try (ResultSet rs = client.executeQuery(sql, params)) {
+ if (rs.next()) {
+ return rs.getString(1);
+ }
+ } catch (SQLException | H2ClientException e) {
+ logger.error(e.getMessage(), e);
+ }
+ return Const.EMPTY_STRING;
+ }
+}
diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IApplicationCacheDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IApplicationCacheDAO.java
new file mode 100644
index 0000000000000000000000000000000000000000..54d1576ad3197cd9d50b7d1db415e65f2084a783
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IApplicationCacheDAO.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.cache.dao;
+
+/**
+ * @author pengys5
+ */
+public interface IApplicationCacheDAO {
+ int getApplicationId(String applicationCode);
+
+ String getApplicationCode(int applicationId);
+}
diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IInstanceCacheDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IInstanceCacheDAO.java
new file mode 100644
index 0000000000000000000000000000000000000000..fcd34b8f5d648a435567ea6575ae53a40c6b58ab
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IInstanceCacheDAO.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.cache.dao;
+
+/**
+ * @author pengys5
+ */
+public interface IInstanceCacheDAO {
+ int getApplicationId(int applicationInstanceId);
+}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceNameDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IServiceNameCacheDAO.java
similarity index 90%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceNameDAO.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IServiceNameCacheDAO.java
index db3d23b90a255e182f934195d59574a002c3abd3..bbf81981bde35f0b9a2d54d4a4d4ca619feaaa8f 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceNameDAO.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/IServiceNameCacheDAO.java
@@ -16,12 +16,12 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.cache.dao;
/**
* @author pengys5
*/
-public interface IServiceNameDAO {
+public interface IServiceNameCacheDAO {
String getServiceName(int serviceId);
int getServiceId(int applicationId, String serviceName);
diff --git a/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceEsCacheDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceEsCacheDAO.java
new file mode 100644
index 0000000000000000000000000000000000000000..a878901f9ce5f395d7db307ceccf007012a4812d
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceEsCacheDAO.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.cache.dao;
+
+import org.elasticsearch.action.get.GetResponse;
+import org.skywalking.apm.collector.storage.define.register.InstanceTable;
+import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author pengys5
+ */
+public class InstanceEsCacheDAO extends EsDAO implements IInstanceCacheDAO {
+
+ private final Logger logger = LoggerFactory.getLogger(InstanceEsCacheDAO.class);
+
+ @Override public int getApplicationId(int applicationInstanceId) {
+ GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(applicationInstanceId)).get();
+ if (response.isExists()) {
+ return (int)response.getSource().get(InstanceTable.COLUMN_APPLICATION_ID);
+ } else {
+ return 0;
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationH2DAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceH2CacheDAO.java
similarity index 59%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationH2DAO.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceH2CacheDAO.java
index 4a79f2f3ff624ca2d4e32114b6c4a6dc2ad04470..d1a884236134676fcda0a22df5dab6cda199e878 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ApplicationH2DAO.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/InstanceH2CacheDAO.java
@@ -16,39 +16,39 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.cache.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
-import org.skywalking.apm.collector.core.util.Const;
-import org.skywalking.apm.collector.storage.define.register.ApplicationTable;
+import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * @author pengys5, clevertension
+ * @author pengys5
*/
-public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
+public class InstanceH2CacheDAO extends H2DAO implements IInstanceCacheDAO {
+
+ private final Logger logger = LoggerFactory.getLogger(InstanceH2CacheDAO.class);
+
+ private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?";
- private final Logger logger = LoggerFactory.getLogger(ApplicationH2DAO.class);
- private static final String GET_APPLICATION_CODE_SQL = "select {0} from {1} where {2} = ?";
- @Override public String getApplicationCode(int applicationId) {
- logger.debug("get application code, applicationId: {}", applicationId);
+ @Override public int getApplicationId(int applicationInstanceId) {
+ logger.info("get the application id with application id = {}", applicationInstanceId);
H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_APPLICATION_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
- Object[] params = new Object[]{applicationId};
+ String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID);
+ Object[] params = new Object[] {applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
- return rs.getString(1);
+ return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
- return Const.UNKNOWN;
+ return 0;
}
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameEsDAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameEsCacheDAO.java
similarity index 91%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameEsDAO.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameEsCacheDAO.java
index 03da4de8eedecb8a8f5fa99d84e0028782218440..820b12020cb1b292eb9d821df42e486e40892e19 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameEsDAO.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameEsCacheDAO.java
@@ -16,7 +16,7 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.cache.dao;
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.action.get.GetResponse;
@@ -33,7 +33,7 @@ import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
/**
* @author pengys5
*/
-public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
+public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO {
@Override public String getServiceName(int serviceId) {
GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId));
@@ -44,7 +44,7 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue();
return applicationId + Const.ID_SPLIT + serviceName;
}
- return Const.UNKNOWN;
+ return Const.EMPTY_STRING;
}
@Override public int getServiceId(int applicationId, String serviceName) {
@@ -61,8 +61,7 @@ public class ServiceNameEsDAO extends EsDAO implements IServiceNameDAO {
SearchResponse searchResponse = searchRequestBuilder.get();
if (searchResponse.getHits().totalHits > 0) {
SearchHit searchHit = searchResponse.getHits().iterator().next();
- int serviceId = (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID);
- return serviceId;
+ return (int)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID);
}
return 0;
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameH2DAO.java b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameH2CacheDAO.java
similarity index 71%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameH2DAO.java
rename to apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameH2CacheDAO.java
index 34f7f577ff5a85af8e828b6bda049d386383621d..b3befc2596ce5f458f1547f680eb19798382fecc 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceNameH2DAO.java
+++ b/apm-collector/apm-collector-cache/src/main/java/org/skywalking/apm/collector/cache/dao/ServiceNameH2CacheDAO.java
@@ -16,11 +16,10 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.cache.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.Const;
@@ -33,34 +32,38 @@ import org.slf4j.LoggerFactory;
/**
* @author pengys5, clevertension
*/
-public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
- private final Logger logger = LoggerFactory.getLogger(ServiceNameH2DAO.class);
- private static final String GET_SERVICE_NAME_SQL = "select {0} from {1} where {2} = ?";
+public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO {
+
+ private final Logger logger = LoggerFactory.getLogger(ServiceNameH2CacheDAO.class);
+
+ private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?";
private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1";
+
@Override public String getServiceName(int serviceId) {
H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_SERVICE_NAME,
- ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
- Object[] params = new Object[]{serviceId};
+ String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME,
+ ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
+ Object[] params = new Object[] {serviceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
- return rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME);
+ String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME);
+ int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID);
+ return applicationId + Const.ID_SPLIT + serviceName;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
- return Const.UNKNOWN;
+ return Const.EMPTY_STRING;
}
@Override public int getServiceId(int applicationId, String serviceName) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
- ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
- Object[] params = new Object[]{applicationId, serviceName};
+ ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
+ Object[] params = new Object[] {applicationId, serviceName};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
- int serviceId = rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
- return serviceId;
+ return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
diff --git a/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/es_dao.define b/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/es_dao.define
new file mode 100644
index 0000000000000000000000000000000000000000..31e828d5ccc3522d2ccd8f6211dd564883d75a1d
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/es_dao.define
@@ -0,0 +1,3 @@
+org.skywalking.apm.collector.cache.dao.ApplicationEsDAO
+org.skywalking.apm.collector.cache.dao.InstanceEsDAO
+org.skywalking.apm.collector.cache.dao.ServiceNameEsDAO
\ No newline at end of file
diff --git a/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/h2_dao.define b/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/h2_dao.define
new file mode 100644
index 0000000000000000000000000000000000000000..2384a773a85b0aae87216af388ad5f0e65fcbbfa
--- /dev/null
+++ b/apm-collector/apm-collector-cache/src/main/resources/META-INF/defines/h2_dao.define
@@ -0,0 +1,3 @@
+org.skywalking.apm.collector.cache.dao.ApplicationH2DAO
+org.skywalking.apm.collector.cache.dao.InstanceH2DAO
+org.skywalking.apm.collector.cache.dao.ServiceNameH2DAO
\ No newline at end of file
diff --git a/apm-collector/apm-collector-client/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java b/apm-collector/apm-collector-client/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java
index 8ab7c47d86e11e7a14c757b2bb7212fc1cc5e95c..8b0b9f22ed166285698c1a37f4660cd49119809f 100644
--- a/apm-collector/apm-collector-client/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java
+++ b/apm-collector/apm-collector-client/src/main/java/org/skywalking/apm/collector/client/h2/H2Client.java
@@ -18,9 +18,12 @@
package org.skywalking.apm.collector.client.h2;
-import java.sql.*;
-
-import org.h2.jdbcx.JdbcConnectionPool;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import org.h2.util.IOUtils;
import org.skywalking.apm.collector.core.client.Client;
import org.slf4j.Logger;
@@ -33,7 +36,6 @@ public class H2Client implements Client {
private final Logger logger = LoggerFactory.getLogger(H2Client.class);
- private JdbcConnectionPool cp;
private Connection conn;
private String url;
private String userName;
@@ -53,18 +55,15 @@ public class H2Client implements Client {
@Override public void initialize() throws H2ClientException {
try {
- cp = JdbcConnectionPool.
- create(this.url, this.userName, this.password);
- conn = cp.getConnection();
+ Class.forName("org.h2.Driver");
+ conn = DriverManager.
+ getConnection(this.url, this.userName, this.password);
} catch (Exception e) {
throw new H2ClientException(e.getMessage(), e);
}
}
@Override public void shutdown() {
- if (cp != null) {
- cp.dispose();
- }
IOUtils.closeSilently(conn);
}
diff --git a/apm-collector/apm-collector-cluster/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleGroupDefine.java b/apm-collector/apm-collector-cluster/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleGroupDefine.java
index 78627ed9ec650551754a6c9f35f6d4ef9dab8eab..0873d9677d6b14575bb4517e41476f680e7a3bd3 100644
--- a/apm-collector/apm-collector-cluster/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleGroupDefine.java
+++ b/apm-collector/apm-collector-cluster/src/main/java/org/skywalking/apm/collector/cluster/ClusterModuleGroupDefine.java
@@ -19,6 +19,7 @@
package org.skywalking.apm.collector.cluster;
import org.skywalking.apm.collector.core.cluster.ClusterModuleContext;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -46,4 +47,8 @@ public class ClusterModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/ExchangeMarkUtils.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/GroupConfigParser.java
similarity index 75%
rename from apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/ExchangeMarkUtils.java
rename to apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/GroupConfigParser.java
index e67314a79f4a40d87c756819431d7ea4afbe6f11..a308c663b4f6eb0b394810156ec9c4bb6ad578fa 100644
--- a/apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/util/ExchangeMarkUtils.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/GroupConfigParser.java
@@ -16,17 +16,15 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.agentstream.worker.util;
+package org.skywalking.apm.collector.core.config;
+
+import java.util.Map;
/**
* @author pengys5
*/
-public enum ExchangeMarkUtils {
- INSTANCE;
-
- private static final String MARK_TAG = "M";
+public interface GroupConfigParser {
+ String NODE_NAME = "config";
- public String buildMarkedID(int id) {
- return MARK_TAG + id;
- }
+ void parse(Map config);
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IApplicationDAO.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfig.java
similarity index 84%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IApplicationDAO.java
rename to apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfig.java
index 4e337ca8b84bfe44a37529aceaed3c4c97616817..742b856f27280f358e86d2300c7c3a575a14c404 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IApplicationDAO.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfig.java
@@ -16,11 +16,11 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
-package org.skywalking.apm.collector.ui.dao;
+package org.skywalking.apm.collector.core.config;
/**
* @author pengys5
*/
-public interface IApplicationDAO {
- String getApplicationCode(int applicationId);
+public class SystemConfig {
+ public static String DATA_PATH = "../data";
}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfigParser.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfigParser.java
new file mode 100644
index 0000000000000000000000000000000000000000..82aa62989b2bd1d71fa7e125cb9615bbeb8e8537
--- /dev/null
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/config/SystemConfigParser.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.core.config;
+
+import org.skywalking.apm.collector.core.util.StringUtils;
+
+/**
+ * @author pengys5
+ */
+public enum SystemConfigParser {
+ INSTANCE;
+
+ private static final String DATA_PATH = "data.path";
+
+ public void parse() {
+ if (!StringUtils.isEmpty(System.getProperty(DATA_PATH))) {
+ SystemConfig.DATA_PATH = System.getProperty(DATA_PATH);
+ }
+ }
+}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CommonModuleInstaller.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CommonModuleInstaller.java
index e918347c04127bc82b9950f2c0944aeecacc53e6..223bd427d0fdaec087253dab5456c7425c369bf3 100644
--- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CommonModuleInstaller.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/CommonModuleInstaller.java
@@ -36,11 +36,11 @@ public abstract class CommonModuleInstaller implements ModuleInstaller {
this.moduleDefineMap = moduleDefineMap;
}
- protected final Map getModuleConfig() {
+ final Map getModuleConfig() {
return moduleConfig;
}
- protected final Map getModuleDefineMap() {
+ final Map getModuleDefineMap() {
return moduleDefineMap;
}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleGroupDefine.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleGroupDefine.java
index 739418ac2575d4a9e7443679c79d68c7b6702af3..48ed3bae3f2522daa6afb164e4ef249364b6c768 100644
--- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleGroupDefine.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/ModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.core.module;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
/**
@@ -29,4 +30,6 @@ public interface ModuleGroupDefine {
Context groupContext();
ModuleInstaller moduleInstaller();
+
+ GroupConfigParser groupConfigParser();
}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleCommonModuleInstaller.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleModuleInstaller.java
similarity index 95%
rename from apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleCommonModuleInstaller.java
rename to apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleModuleInstaller.java
index ab4f3a3107f60c578e54294ef3f73c83ac63147a..89899f6ef0c6a6f275d4fe70157eae51850275b3 100644
--- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleCommonModuleInstaller.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/MultipleModuleInstaller.java
@@ -37,11 +37,11 @@ import org.slf4j.LoggerFactory;
/**
* @author pengys5
*/
-public abstract class MultipleCommonModuleInstaller extends CommonModuleInstaller {
+public abstract class MultipleModuleInstaller extends CommonModuleInstaller {
- private final Logger logger = LoggerFactory.getLogger(MultipleCommonModuleInstaller.class);
+ private final Logger logger = LoggerFactory.getLogger(MultipleModuleInstaller.class);
- public MultipleCommonModuleInstaller() {
+ public MultipleModuleInstaller() {
moduleDefines = new LinkedList<>();
}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/SingleModuleInstaller.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/SingleModuleInstaller.java
index 4cc1e39f1189b2499bd1449ebea9603a40cdeca9..691f40e92caf8ef7ce02a4ad785cf685f2a02e60 100644
--- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/SingleModuleInstaller.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/module/SingleModuleInstaller.java
@@ -76,7 +76,9 @@ public abstract class SingleModuleInstaller extends CommonModuleInstaller {
throw new ClusterModuleException("single module, but configure multiple default module");
}
this.moduleDefine = moduleDefineEntry.getValue();
- this.moduleDefine.configParser().parse(null);
+ if (this.moduleDefine.configParser() != null) {
+ this.moduleDefine.configParser().parse(null);
+ }
hasDefaultModule = true;
}
}
diff --git a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java
index 95788cd3ff5ec05bfb21338ec9db07588fe35c6b..21f31856b7e92063a652a0fecc486c1f3fdf8e18 100644
--- a/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java
+++ b/apm-collector/apm-collector-core/src/main/java/org/skywalking/apm/collector/core/util/Const.java
@@ -31,4 +31,5 @@ public class Const {
public static final String UNKNOWN = "Unknown";
public static final String EXCEPTION = "Exception";
public static final String EMPTY_STRING = "";
+ public static final String FILE_SUFFIX = "sw";
}
diff --git a/apm-collector/apm-collector-queue/src/main/java/org/skywalking/apm/collector/queue/QueueModuleGroupDefine.java b/apm-collector/apm-collector-queue/src/main/java/org/skywalking/apm/collector/queue/QueueModuleGroupDefine.java
index 69b663b1b06d10be47502aafde52ed52612ba9b7..d207e7753a152c3358c65e3cf4089ca2191d77de 100644
--- a/apm-collector/apm-collector-queue/src/main/java/org/skywalking/apm/collector/queue/QueueModuleGroupDefine.java
+++ b/apm-collector/apm-collector-queue/src/main/java/org/skywalking/apm/collector/queue/QueueModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.queue;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -45,4 +46,8 @@ public class QueueModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleDefine.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleDefine.java
index 1fa83a89d1a8cbd5d5a1580297844e27c77c0a8b..6f22a30ae7fd7f0ec9d054422f4d26df55b8b0a3 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleDefine.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleDefine.java
@@ -68,10 +68,6 @@ public abstract class StorageModuleDefine extends ModuleDefine implements Cluste
return null;
}
- @Override public final boolean defaultModule() {
- return true;
- }
-
public abstract StorageInstaller storageInstaller();
public abstract void injectClientIntoDAO(Client client) throws DefineException;
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleGroupDefine.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleGroupDefine.java
index e04244f6794d67c0c8e26426dd5c5a46f984f08f..84731ae8259e45ef759cd7187e6c4bd4c84aaef6 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleGroupDefine.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/StorageModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.storage;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -45,4 +46,8 @@ public class StorageModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/service/ServiceEntryDataDefine.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/service/ServiceEntryDataDefine.java
index 2773286aff66cfa97af83653105861c77bf68724..f16d4025b413b4f68251cda86ff06530150bf92c 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/service/ServiceEntryDataDefine.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/service/ServiceEntryDataDefine.java
@@ -38,9 +38,9 @@ public class ServiceEntryDataDefine extends DataDefine {
@Override protected void attributeDefine() {
addAttribute(0, new Attribute(ServiceEntryTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
- addAttribute(1, new Attribute(ServiceEntryTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new NonOperation()));
+ addAttribute(1, new Attribute(ServiceEntryTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation()));
addAttribute(2, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID, AttributeType.INTEGER, new CoverOperation()));
- addAttribute(3, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, AttributeType.STRING, new NonOperation()));
+ addAttribute(3, new Attribute(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME, AttributeType.STRING, new CoverOperation()));
addAttribute(4, new Attribute(ServiceEntryTable.COLUMN_REGISTER_TIME, AttributeType.LONG, new NonOperation()));
addAttribute(5, new Attribute(ServiceEntryTable.COLUMN_NEWEST_TIME, AttributeType.LONG, new CoverOperation()));
}
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/elasticsearch/StorageElasticSearchModuleDefine.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/elasticsearch/StorageElasticSearchModuleDefine.java
index 06f8b2c816013b362bc7bd898bf6f29fa02b9f8f..c2e5e87f9571fd58f9fa0f6eb3038deae89636b4 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/elasticsearch/StorageElasticSearchModuleDefine.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/elasticsearch/StorageElasticSearchModuleDefine.java
@@ -46,6 +46,10 @@ public class StorageElasticSearchModuleDefine extends StorageModuleDefine {
return MODULE_NAME;
}
+ @Override public final boolean defaultModule() {
+ return false;
+ }
+
@Override protected ModuleConfigParser configParser() {
return new StorageElasticSearchConfigParser();
}
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ConfigParser.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ConfigParser.java
index 85a08c426d0d16657ed90f9d3a91fc19114ca6bb..074c531fe4d78c72257078f2d9c27efea77726e2 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ConfigParser.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ConfigParser.java
@@ -20,6 +20,7 @@ package org.skywalking.apm.collector.storage.h2;
import java.util.Map;
import org.skywalking.apm.collector.core.config.ConfigParseException;
+import org.skywalking.apm.collector.core.config.SystemConfig;
import org.skywalking.apm.collector.core.module.ModuleConfigParser;
import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
@@ -31,15 +32,20 @@ public class StorageH2ConfigParser implements ModuleConfigParser {
private static final String URL = "url";
public static final String USER_NAME = "user_name";
public static final String PASSWORD = "password";
+
@Override public void parse(Map config) throws ConfigParseException {
if (ObjectUtils.isNotEmpty(config) && StringUtils.isNotEmpty(config.get(URL))) {
StorageH2Config.URL = (String)config.get(URL);
+ } else {
+ StorageH2Config.URL = "jdbc:h2:" + SystemConfig.DATA_PATH + "/h2";
}
if (ObjectUtils.isNotEmpty(config) && StringUtils.isNotEmpty(config.get(USER_NAME))) {
StorageH2Config.USER_NAME = (String)config.get(USER_NAME);
+ } else {
+ StorageH2Config.USER_NAME = "sa";
}
if (ObjectUtils.isNotEmpty(config) && StringUtils.isNotEmpty(config.get(PASSWORD))) {
StorageH2Config.PASSWORD = (String)config.get(PASSWORD);
}
}
-}
+}
\ No newline at end of file
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ModuleDefine.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ModuleDefine.java
index 9faae085feb315438b676c260a86fd634b6b0cb8..e4ea3a81c907cf4ef98f19b056de614099d298f6 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ModuleDefine.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/StorageH2ModuleDefine.java
@@ -46,6 +46,10 @@ public class StorageH2ModuleDefine extends StorageModuleDefine {
return MODULE_NAME;
}
+ @Override public final boolean defaultModule() {
+ return true;
+ }
+
@Override protected ModuleConfigParser configParser() {
return new StorageH2ConfigParser();
}
diff --git a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/dao/H2DAO.java b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/dao/H2DAO.java
index 39dbc78e000c8c2a264a1d83343199fcbec5df8c..fd66357bf68e32d34d1386dac54de450500bf06e 100644
--- a/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/dao/H2DAO.java
+++ b/apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/h2/dao/H2DAO.java
@@ -20,7 +20,6 @@ package org.skywalking.apm.collector.storage.h2.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.storage.dao.DAO;
@@ -32,17 +31,18 @@ import org.slf4j.LoggerFactory;
*/
public abstract class H2DAO extends DAO {
private final Logger logger = LoggerFactory.getLogger(H2DAO.class);
- public final int getMaxId(String tableName, String columnName) {
+
+ protected final int getMaxId(String tableName, String columnName) {
String sql = "select max(" + columnName + ") from " + tableName;
return getIntValueBySQL(sql);
}
- public final int getMinId(String tableName, String columnName) {
+ protected final int getMinId(String tableName, String columnName) {
String sql = "select min(" + columnName + ") from " + tableName;
return getIntValueBySQL(sql);
}
- public final int getIntValueBySQL(String sql) {
+ private int getIntValueBySQL(String sql) {
H2Client client = getClient();
try (ResultSet rs = client.executeQuery(sql, null)) {
if (rs.next()) {
@@ -58,5 +58,4 @@ public abstract class H2DAO extends DAO {
}
return 0;
}
-
}
diff --git a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/StreamModuleGroupDefine.java b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/StreamModuleGroupDefine.java
index d08084dbdaad483a0be50ff91ab856a0a5e8fc56..dd590dd696bceb0e64aa60d5bc2001b56812da23 100644
--- a/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/StreamModuleGroupDefine.java
+++ b/apm-collector/apm-collector-stream/src/main/java/org/skywalking/apm/collector/stream/StreamModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.stream;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -45,4 +46,8 @@ public class StreamModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-ui/pom.xml b/apm-collector/apm-collector-ui/pom.xml
index e7bd85915b6dc5e3218b8f6aeca68d5ed4917215..fe113bb203221e76f149c723c43c7a7acade085a 100644
--- a/apm-collector/apm-collector-ui/pom.xml
+++ b/apm-collector/apm-collector-ui/pom.xml
@@ -51,5 +51,10 @@
apm-collector-storage
${project.version}
+
+ org.skywalking
+ apm-collector-cache
+ ${project.version}
+
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleGroupDefine.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleGroupDefine.java
index 4bdaf092ee3a6e38dadf91f413e48cfebcb41278..9ac9de5ad1fcc67b3da99e53747d8cbd104711be 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleGroupDefine.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleGroupDefine.java
@@ -18,6 +18,7 @@
package org.skywalking.apm.collector.ui;
+import org.skywalking.apm.collector.core.config.GroupConfigParser;
import org.skywalking.apm.collector.core.framework.Context;
import org.skywalking.apm.collector.core.module.ModuleGroupDefine;
import org.skywalking.apm.collector.core.module.ModuleInstaller;
@@ -28,10 +29,10 @@ import org.skywalking.apm.collector.core.module.ModuleInstaller;
public class UIModuleGroupDefine implements ModuleGroupDefine {
public static final String GROUP_NAME = "ui";
- private final UICommonModuleInstaller installer;
+ private final UIModuleInstaller installer;
public UIModuleGroupDefine() {
- installer = new UICommonModuleInstaller();
+ installer = new UIModuleInstaller();
}
@Override public String name() {
@@ -45,4 +46,8 @@ public class UIModuleGroupDefine implements ModuleGroupDefine {
@Override public ModuleInstaller moduleInstaller() {
return installer;
}
+
+ @Override public GroupConfigParser groupConfigParser() {
+ return null;
+ }
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UICommonModuleInstaller.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleInstaller.java
similarity index 87%
rename from apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UICommonModuleInstaller.java
rename to apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleInstaller.java
index 090a302452366a3fa16325420900fc9f01bf160b..19e516d6af0bdd87e33e139927e85712456117aa 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UICommonModuleInstaller.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/UIModuleInstaller.java
@@ -20,12 +20,12 @@ package org.skywalking.apm.collector.ui;
import java.util.List;
import org.skywalking.apm.collector.core.framework.Context;
-import org.skywalking.apm.collector.core.module.MultipleCommonModuleInstaller;
+import org.skywalking.apm.collector.core.module.MultipleModuleInstaller;
/**
* @author pengys5
*/
-public class UICommonModuleInstaller extends MultipleCommonModuleInstaller {
+public class UIModuleInstaller extends MultipleModuleInstaller {
@Override public String groupName() {
return UIModuleGroupDefine.GROUP_NAME;
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ApplicationCache.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ApplicationCache.java
deleted file mode 100644
index ed02d372e76161e3a947bd601ce335e32a46baf6..0000000000000000000000000000000000000000
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/cache/ApplicationCache.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2017, OpenSkywalking Organization All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project repository: https://github.com/OpenSkywalking/skywalking
- */
-
-package org.skywalking.apm.collector.ui.cache;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import org.skywalking.apm.collector.core.util.Const;
-import org.skywalking.apm.collector.storage.dao.DAOContainer;
-import org.skywalking.apm.collector.ui.dao.IApplicationDAO;
-
-/**
- * @author pengys5
- */
-public class ApplicationCache {
-
- //TODO size configuration
- private static Cache CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
-
- public static String get(int applicationId) {
- try {
- return CACHE.get(applicationId, () -> {
- IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
- return dao.getApplicationCode(applicationId);
- });
- } catch (Throwable e) {
- return Const.EXCEPTION;
- }
- }
-
- public static String getForUI(int applicationId) {
- String applicationCode = get(applicationId);
- if (applicationCode.equals("Unknown")) {
- IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
- applicationCode = dao.getApplicationCode(applicationId);
- CACHE.put(applicationId, applicationCode);
- }
- return applicationCode;
- }
-}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/GlobalTraceH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/GlobalTraceH2DAO.java
index 6920d915aa1e0d1bd6a6eb22ee6d8ab689b58ad2..7b00d09eaec0328a9254f6b8bb6dc5d6775212e8 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/GlobalTraceH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/GlobalTraceH2DAO.java
@@ -66,7 +66,7 @@ public class GlobalTraceH2DAO extends H2DAO implements IGlobalTraceDAO {
while (rs.next()) {
String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
- segmentIds.add(globalTraceId);
+ segmentIds.add(segmentId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceReferenceDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceReferenceDAO.java
index f2bee52daacdb89ea7fbb9e01385df97014b55ce..3f267af653b5a233a938edf5c47fc494093cb8ea 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceReferenceDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/IServiceReferenceDAO.java
@@ -18,13 +18,12 @@
package org.skywalking.apm.collector.ui.dao;
-import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import java.util.Map;
/**
* @author pengys5
*/
public interface IServiceReferenceDAO {
- JsonArray load(int entryServiceId, long startTime, long endTime);
-
- JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime);
+ Map load(int entryServiceId, long startTime, long endTime);
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
index 4ebed5c9c876d99e6f50fc2ac88aad37383835dc..4401ce9cd2f191ee91ce435b185eeddb730e2ba3 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceEsDAO.java
@@ -37,11 +37,11 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortMode;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -112,7 +112,7 @@ public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
JsonObject application = new JsonObject();
application.addProperty("applicationId", applicationId);
- application.addProperty("applicationCode", ApplicationCache.getForUI(applicationId));
+ application.addProperty("applicationCode", ApplicationCache.get(applicationId));
application.addProperty("instanceCount", instanceCount.getValue());
applications.add(application);
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
index 6b3c72fc0cbf43c243ef90476caaf4eddf8f23a7..f94c1f1efa1525dbc4e3a0df4d19ba4c6cedd1df 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/InstanceH2DAO.java
@@ -18,11 +18,13 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
-
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
@@ -30,13 +32,9 @@ import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
import org.skywalking.apm.collector.storage.define.register.InstanceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
/**
* @author pengys5, clevertension
*/
@@ -54,7 +52,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME);
- Object[] params = new Object[]{fiveMinuteBefore};
+ Object[] params = new Object[] {fiveMinuteBefore};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
@@ -71,8 +69,8 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
long fiveMinuteBefore = System.currentTimeMillis() - 5 * 60 * 1000;
fiveMinuteBefore = TimeBucketUtils.INSTANCE.getSecondTimeBucket(fiveMinuteBefore);
String sql = SqlBuilder.buildSql(GET_INST_LAST_HEARTBEAT_TIME_SQL, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.TABLE,
- InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
- Object[] params = new Object[]{fiveMinuteBefore, applicationInstanceId};
+ InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_INSTANCE_ID);
+ Object[] params = new Object[] {fiveMinuteBefore, applicationInstanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getLong(1);
@@ -88,15 +86,15 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
H2Client client = getClient();
JsonArray applications = new JsonArray();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
- InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
- Object[] params = new Object[]{startTime, endTime};
+ InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
+ Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
logger.debug("applicationId: {}", applicationId);
JsonObject application = new JsonObject();
application.addProperty("applicationId", applicationId);
- application.addProperty("applicationCode", ApplicationCache.getForUI(applicationId));
+ application.addProperty("applicationCode", ApplicationCache.get(applicationId));
application.addProperty("instanceCount", rs.getInt("cnt"));
applications.add(application);
}
@@ -110,7 +108,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
public InstanceDataDefine.Instance getInstance(int instanceId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
- Object[] params = new Object[]{instanceId};
+ Object[] params = new Object[] {instanceId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
InstanceDataDefine.Instance instance = new InstanceDataDefine.Instance();
@@ -134,7 +132,7 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
List instanceList = new LinkedList<>();
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME);
- Object[] params = new Object[]{applicationId, timeBucket};
+ Object[] params = new Object[] {applicationId, timeBucket};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
InstanceDataDefine.Instance instance = new InstanceDataDefine.Instance();
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentEsDAO.java
index 95ac9857e7870912ff0d0f51500babc1bf243dba..1b57d9440591e7fdae03af17bcecdf8271514630 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentEsDAO.java
@@ -26,10 +26,10 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeComponentTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -106,7 +106,7 @@ public class NodeComponentEsDAO extends EsDAO implements INodeComponentDAO {
int peerId = peerIdBucket.getKeyAsNumber().intValue();
if (peerId != 0) {
- String peer = ApplicationCache.getForUI(peerId);
+ String peer = ApplicationCache.get(peerId);
JsonObject nodeComponentObj = new JsonObject();
nodeComponentObj.addProperty("componentName", componentName);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentH2DAO.java
index 5fd855025d4f59bdcf73e9f4ce62b7892ebba833..54a86ca49b613782ed882616d32a62e0edab921d 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeComponentH2DAO.java
@@ -18,49 +18,49 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
-
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeComponentTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
/**
* @author pengys5, clevertension
*/
public class NodeComponentH2DAO extends H2DAO implements INodeComponentDAO {
private final Logger logger = LoggerFactory.getLogger(NodeComponentH2DAO.class);
private static final String AGGREGATE_COMPONENT_SQL = "select {0}, {1}, {2} from {3} where {4} >= ? and {4} <= ? group by {0}, {1}, {2} limit 100";
+
@Override public JsonArray load(long startTime, long endTime) {
JsonArray nodeComponentArray = new JsonArray();
nodeComponentArray.addAll(aggregationComponent(startTime, endTime));
return nodeComponentArray;
}
+
private JsonArray aggregationComponent(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeComponentArray = new JsonArray();
String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, NodeComponentTable.COLUMN_COMPONENT_ID,
- NodeComponentTable.COLUMN_PEER, NodeComponentTable.COLUMN_PEER_ID,
- NodeComponentTable.TABLE, NodeComponentTable.COLUMN_TIME_BUCKET);
- Object[] params = new Object[]{startTime, endTime};
+ NodeComponentTable.COLUMN_PEER, NodeComponentTable.COLUMN_PEER_ID,
+ NodeComponentTable.TABLE, NodeComponentTable.COLUMN_TIME_BUCKET);
+ Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int peerId = rs.getInt(NodeComponentTable.COLUMN_PEER_ID);
int componentId = rs.getInt(NodeComponentTable.COLUMN_COMPONENT_ID);
String componentName = ComponentsDefine.getInstance().getComponentName(componentId);
if (peerId != 0) {
- String peer = ApplicationCache.getForUI(peerId);
+ String peer = ApplicationCache.get(peerId);
nodeComponentArray.add(buildNodeComponent(peer, componentName));
}
String peer = rs.getString(NodeComponentTable.COLUMN_PEER);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingEsDAO.java
index ead38da4c080befe30051b3696531e27178d1daf..70ee47a59b7ebc115080a0cddb59fa343d4b7c23 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingEsDAO.java
@@ -26,10 +26,10 @@ import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeMappingTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,11 +58,11 @@ public class NodeMappingEsDAO extends EsDAO implements INodeMappingDAO {
JsonArray nodeMappingArray = new JsonArray();
for (Terms.Bucket applicationIdBucket : applicationIdTerms.getBuckets()) {
int applicationId = applicationIdBucket.getKeyAsNumber().intValue();
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(applicationId);
Terms addressIdTerms = applicationIdBucket.getAggregations().get(NodeMappingTable.COLUMN_ADDRESS_ID);
for (Terms.Bucket addressIdBucket : addressIdTerms.getBuckets()) {
int addressId = addressIdBucket.getKeyAsNumber().intValue();
- String address = ApplicationCache.getForUI(addressId);
+ String address = ApplicationCache.get(addressId);
if (addressId != 0) {
JsonObject nodeMappingObj = new JsonObject();
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingH2DAO.java
index 7febe8065a0db42768360514c6eac387675744ee..78ae8cf1c35d3de023fa8314a07ef47f7ce279f7 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeMappingH2DAO.java
@@ -18,43 +18,42 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
-
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.node.NodeMappingTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
/**
* @author pengys5, clevertension
*/
public class NodeMappingH2DAO extends H2DAO implements INodeMappingDAO {
private final Logger logger = LoggerFactory.getLogger(NodeMappingH2DAO.class);
private static final String NODE_MAPPING_SQL = "select {0}, {1}, {2} from {3} where {4} >= ? and {4} <= ? group by {0}, {1}, {2} limit 100";
+
@Override public JsonArray load(long startTime, long endTime) {
H2Client client = getClient();
JsonArray nodeMappingArray = new JsonArray();
String sql = SqlBuilder.buildSql(NODE_MAPPING_SQL, NodeMappingTable.COLUMN_APPLICATION_ID,
- NodeMappingTable.COLUMN_ADDRESS_ID, NodeMappingTable.COLUMN_ADDRESS,
- NodeMappingTable.TABLE, NodeMappingTable.COLUMN_TIME_BUCKET);
+ NodeMappingTable.COLUMN_ADDRESS_ID, NodeMappingTable.COLUMN_ADDRESS,
+ NodeMappingTable.TABLE, NodeMappingTable.COLUMN_TIME_BUCKET);
- Object[] params = new Object[]{startTime, endTime};
+ Object[] params = new Object[] {startTime, endTime};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(NodeMappingTable.COLUMN_APPLICATION_ID);
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(applicationId);
int addressId = rs.getInt(NodeMappingTable.COLUMN_ADDRESS_ID);
if (addressId != 0) {
- String address = ApplicationCache.getForUI(addressId);
+ String address = ApplicationCache.get(addressId);
JsonObject nodeMappingObj = new JsonObject();
nodeMappingObj.addProperty("applicationCode", applicationCode);
nodeMappingObj.addProperty("address", address);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceEsDAO.java
index 4715b49387382ba719923009a948eaa3309fd651..2a7f7c0d43f3817bedfb7fd16da00b1c1e3c9b48 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceEsDAO.java
@@ -28,10 +28,10 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.noderef.NodeReferenceTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -72,13 +72,13 @@ public class NodeReferenceEsDAO extends EsDAO implements INodeReferenceDAO {
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
int applicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(applicationId);
Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
if (behindApplicationId != 0) {
- String behindApplicationCode = ApplicationCache.getForUI(behindApplicationId);
+ String behindApplicationCode = ApplicationCache.get(behindApplicationId);
Sum s1LTE = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S1_LTE);
Sum s3LTE = behindApplicationIdBucket.getAggregations().get(NodeReferenceTable.COLUMN_S3_LTE);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceH2DAO.java
index 52cdf9a410fb805243c17c302c1075d9867ad556..007882c44f9467d982e21a76593582dd90c6bc06 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/NodeReferenceH2DAO.java
@@ -21,13 +21,13 @@ package org.skywalking.apm.collector.ui.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.noderef.NodeReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,10 +54,10 @@ public class NodeReferenceH2DAO extends H2DAO implements INodeReferenceDAO {
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
int applicationId = rs.getInt(NodeReferenceTable.COLUMN_FRONT_APPLICATION_ID);
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(applicationId);
int behindApplicationId = rs.getInt(NodeReferenceTable.COLUMN_BEHIND_APPLICATION_ID);
if (behindApplicationId != 0) {
- String behindApplicationCode = ApplicationCache.getForUI(behindApplicationId);
+ String behindApplicationCode = ApplicationCache.get(behindApplicationId);
JsonObject nodeRefResSumObj = new JsonObject();
nodeRefResSumObj.addProperty("front", applicationCode);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentH2DAO.java
index 079e2dc12e481d92356e4fe7a8ae0d531b5cfbda..4421167b1494dae49251d28fd49f9f8ddd1c2947 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentH2DAO.java
@@ -18,13 +18,11 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.protobuf.InvalidProtocolBufferException;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.Base64;
-
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
-import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.segment.SegmentTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
@@ -32,29 +30,25 @@ import org.skywalking.apm.network.proto.TraceSegmentObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.protobuf.InvalidProtocolBufferException;
-
/**
* @author pengys5, clevertension
*/
public class SegmentH2DAO extends H2DAO implements ISegmentDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentH2DAO.class);
private static final String GET_SEGMENT_SQL = "select {0} from {1} where {2} = ?";
+
@Override public TraceSegmentObject load(String segmentId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY,
- SegmentTable.TABLE, "id");
- Object[] params = new Object[]{segmentId};
+ SegmentTable.TABLE, "id");
+ Object[] params = new Object[] {segmentId};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
- String dataBinaryBase64 = rs.getString(SegmentTable.COLUMN_DATA_BINARY);
- if (StringUtils.isNotEmpty(dataBinaryBase64)) {
- byte[] dataBinary = Base64.getDecoder().decode(dataBinaryBase64);
- try {
- return TraceSegmentObject.parseFrom(dataBinary);
- } catch (InvalidProtocolBufferException e) {
- logger.error(e.getMessage(), e);
- }
+ byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY);
+ try {
+ return TraceSegmentObject.parseFrom(dataBinary);
+ } catch (InvalidProtocolBufferException e) {
+ logger.error(e.getMessage(), e);
}
}
} catch (SQLException | H2ClientException e) {
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryEsDAO.java
index 7a7fb9fe27a435f41ccc531e8bdbbc8f926b116e..64a20fef8c39fac1ee2af8c58d84213c73255d49 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryEsDAO.java
@@ -29,11 +29,11 @@ import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.service.ServiceEntryTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
/**
* @author pengys5
@@ -75,7 +75,7 @@ public class ServiceEntryEsDAO extends EsDAO implements IServiceEntryDAO {
for (SearchHit searchHit : searchHits.getHits()) {
int applicationId = ((Number)searchHit.getSource().get(ServiceEntryTable.COLUMN_APPLICATION_ID)).intValue();
int entryServiceId = ((Number)searchHit.getSource().get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID)).intValue();
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(applicationId);
String entryServiceName = (String)searchHit.getSource().get(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
JsonObject row = new JsonObject();
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryH2DAO.java
index dcf71a00a8898159d5fbd617732355ddefee12b4..4017b306ab379f2b6b944bd19cffc5aff1f9da7c 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceEntryH2DAO.java
@@ -18,11 +18,13 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
-
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
@@ -30,19 +32,16 @@ import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.service.ServiceEntryTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
/**
* @author pengys5
*/
public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO {
private final Logger logger = LoggerFactory.getLogger(SegmentH2DAO.class);
private static final String GET_SERVICE_ENTRY_SQL = "select * from {0} where {1} >= ? and {2} <= ?";
+
@Override public JsonObject load(int applicationId, String entryServiceName, long startTime, long endTime, int from,
int size) {
H2Client client = getClient();
@@ -77,7 +76,7 @@ public class ServiceEntryH2DAO extends H2DAO implements IServiceEntryDAO {
while (rs.next()) {
int appId = rs.getInt(ServiceEntryTable.COLUMN_APPLICATION_ID);
int entryServiceId = rs.getInt(ServiceEntryTable.COLUMN_ENTRY_SERVICE_ID);
- String applicationCode = ApplicationCache.getForUI(applicationId);
+ String applicationCode = ApplicationCache.get(appId);
String entryServiceName1 = rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
JsonObject row = new JsonObject();
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceEsDAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceEsDAO.java
index 069783623246e5c521af83fbe419978765449b0c..00e24144c6b7e2869b01a3c1f0346beee792fd70 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceEsDAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceEsDAO.java
@@ -18,9 +18,7 @@
package org.skywalking.apm.collector.ui.dao;
-import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.elasticsearch.action.search.SearchRequestBuilder;
@@ -31,14 +29,11 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.Const;
-import org.skywalking.apm.collector.core.util.ObjectUtils;
-import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
-import org.skywalking.apm.collector.ui.cache.ServiceIdCache;
-import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +44,7 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsDAO.class);
- @Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
+ @Override public Map load(int entryServiceId, long startTime, long endTime) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE);
searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
@@ -58,30 +53,7 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
- int entryServiceId = ServiceIdCache.get(entryApplicationId, entryServiceName);
- BoolQueryBuilder entryBoolQuery = QueryBuilders.boolQuery();
- if (entryServiceId != 0) {
- entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, entryServiceId));
- }
- entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, entryApplicationId + Const.ID_SPLIT + entryServiceName));
- boolQuery.must(entryBoolQuery);
-
- searchRequestBuilder.setQuery(boolQuery);
- searchRequestBuilder.setSize(0);
-
- return load(searchRequestBuilder);
- }
-
- @Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
- SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE);
- searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE);
- searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
-
- BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
- boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
- boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
-
- String entryServiceName = ServiceNameCache.get(entryServiceId);
+ String entryServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(entryServiceId));
BoolQueryBuilder entryBoolQuery = QueryBuilders.boolQuery();
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, entryServiceId));
entryBoolQuery.should().add(QueryBuilders.matchQuery(ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME, entryServiceName));
@@ -93,35 +65,9 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
return load(searchRequestBuilder);
}
- private JsonArray load(SearchRequestBuilder searchRequestBuilder) {
+ private Map load(SearchRequestBuilder searchRequestBuilder) {
searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID).size(100)
.subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).size(100)
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S3_LTE).field(ServiceReferenceTable.COLUMN_S3_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_LTE).field(ServiceReferenceTable.COLUMN_S5_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_GT).field(ServiceReferenceTable.COLUMN_S5_GT))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_ERROR).field(ServiceReferenceTable.COLUMN_ERROR))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_SUMMARY).field(ServiceReferenceTable.COLUMN_SUMMARY))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_COST_SUMMARY).field(ServiceReferenceTable.COLUMN_COST_SUMMARY)))
- .subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME).size(100)
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S3_LTE).field(ServiceReferenceTable.COLUMN_S3_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_LTE).field(ServiceReferenceTable.COLUMN_S5_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_GT).field(ServiceReferenceTable.COLUMN_S5_GT))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_ERROR).field(ServiceReferenceTable.COLUMN_ERROR))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_SUMMARY).field(ServiceReferenceTable.COLUMN_SUMMARY))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_COST_SUMMARY).field(ServiceReferenceTable.COLUMN_COST_SUMMARY))));
-
- searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME).field(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME).size(100)
- .subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID).size(100)
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S3_LTE).field(ServiceReferenceTable.COLUMN_S3_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_LTE).field(ServiceReferenceTable.COLUMN_S5_LTE))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_GT).field(ServiceReferenceTable.COLUMN_S5_GT))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_ERROR).field(ServiceReferenceTable.COLUMN_ERROR))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_SUMMARY).field(ServiceReferenceTable.COLUMN_SUMMARY))
- .subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_COST_SUMMARY).field(ServiceReferenceTable.COLUMN_COST_SUMMARY)))
- .subAggregation(AggregationBuilders.terms(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME).field(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME).size(100)
.subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S1_LTE).field(ServiceReferenceTable.COLUMN_S1_LTE))
.subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S3_LTE).field(ServiceReferenceTable.COLUMN_S3_LTE))
.subAggregation(AggregationBuilders.sum(ServiceReferenceTable.COLUMN_S5_LTE).field(ServiceReferenceTable.COLUMN_S5_LTE))
@@ -141,27 +87,7 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
}
}
- Terms frontServiceNameTerms = searchResponse.getAggregations().get(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME);
- for (Terms.Bucket frontServiceBucket : frontServiceNameTerms.getBuckets()) {
- String frontServiceName = frontServiceBucket.getKeyAsString();
- if (StringUtils.isNotEmpty(frontServiceName)) {
- String[] serviceNames = frontServiceName.split(Const.ID_SPLIT);
- int frontServiceId = ServiceIdCache.getForUI(Integer.parseInt(serviceNames[0]), serviceNames[1]);
- parseSubAggregate(serviceReferenceMap, frontServiceBucket, frontServiceId);
- }
- }
-
- JsonArray serviceReferenceArray = new JsonArray();
- JsonObject rootServiceReference = findRoot(serviceReferenceMap);
- if (ObjectUtils.isNotEmpty(rootServiceReference)) {
- serviceReferenceArray.add(rootServiceReference);
- String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
- serviceReferenceMap.remove(id);
-
- int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
- sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap);
- }
- return serviceReferenceArray;
+ return serviceReferenceMap;
}
private void parseSubAggregate(Map serviceReferenceMap,
@@ -179,47 +105,8 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
Sum summary = behindServiceIdBucket.getAggregations().get(ServiceReferenceTable.COLUMN_SUMMARY);
Sum costSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceTable.COLUMN_COST_SUMMARY);
- String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- frontServiceName = frontServiceName.split(Const.ID_SPLIT)[1];
- }
- String behindServiceName = ServiceNameCache.getForUI(behindServiceId);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- behindServiceName = behindServiceName.split(Const.ID_SPLIT)[1];
- }
-
- JsonObject serviceReference = new JsonObject();
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME), frontServiceName);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME), behindServiceName);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S1_LTE), (long)s1LteSum.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S3_LTE), (long)s3LteSum.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_LTE), (long)s5LteSum.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_GT), (long)s5GtSum.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR), (long)error.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY), (long)summary.getValue());
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY), (long)costSum.getValue());
- merge(serviceReferenceMap, serviceReference);
- }
- }
-
- Terms behindServiceNameTerms = frontServiceBucket.getAggregations().get(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME);
- for (Terms.Bucket behindServiceNameBucket : behindServiceNameTerms.getBuckets()) {
- String behindServiceName = behindServiceNameBucket.getKeyAsString();
- if (StringUtils.isNotEmpty(behindServiceName)) {
- Sum s1LteSum = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_S1_LTE);
- Sum s3LteSum = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_S3_LTE);
- Sum s5LteSum = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_S5_LTE);
- Sum s5GtSum = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_S5_GT);
- Sum error = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_ERROR);
- Sum summary = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_SUMMARY);
- Sum costSum = behindServiceNameBucket.getAggregations().get(ServiceReferenceTable.COLUMN_COST_SUMMARY);
-
- String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
- String[] serviceNames = behindServiceName.split(Const.ID_SPLIT);
- int behindServiceId = ServiceIdCache.getForUI(Integer.parseInt(serviceNames[0]), serviceNames[1]);
- behindServiceName = serviceNames[1];
+ String frontServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(frontServiceId));
+ String behindServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(behindServiceId));
JsonObject serviceReference = new JsonObject();
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
@@ -233,55 +120,9 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR), (long)error.getValue());
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY), (long)summary.getValue());
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY), (long)costSum.getValue());
- merge(serviceReferenceMap, serviceReference);
- }
- }
- }
-
- private void merge(Map serviceReferenceMap, JsonObject serviceReference) {
- String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
-
- if (serviceReferenceMap.containsKey(id)) {
- JsonObject reference = serviceReferenceMap.get(id);
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S1_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S3_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_GT));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY));
- } else {
- serviceReferenceMap.put(id, serviceReference);
- }
- }
-
- private void add(JsonObject oldReference, JsonObject newReference, String key) {
- long oldValue = oldReference.get(key).getAsLong();
- long newValue = newReference.get(key).getAsLong();
- oldReference.addProperty(key, oldValue + newValue);
- }
-
- private JsonObject findRoot(Map serviceReferenceMap) {
- for (JsonObject serviceReference : serviceReferenceMap.values()) {
- int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
- if (frontServiceId == 1) {
- return serviceReference;
- }
- }
- return null;
- }
-
- private void sortAsTree(int serviceId, JsonArray serviceReferenceArray,
- Map serviceReferenceMap) {
- Iterator iterator = serviceReferenceMap.values().iterator();
- while (iterator.hasNext()) {
- JsonObject serviceReference = iterator.next();
- int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
- if (serviceId == frontServiceId) {
- serviceReferenceArray.add(serviceReference);
- int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
- sortAsTree(behindServiceId, serviceReferenceArray, serviceReferenceMap);
+ String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
+ serviceReferenceMap.put(id, serviceReference);
}
}
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceH2DAO.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceH2DAO.java
index 37a818e0a12401898283efb2f7f75dc4a0ececa0..4a4a693eb54962531cc337fb0db26ecbbeb9daff 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceH2DAO.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ServiceReferenceH2DAO.java
@@ -18,164 +18,73 @@
package org.skywalking.apm.collector.ui.dao;
+import com.google.gson.JsonObject;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
-
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.client.h2.H2ClientException;
import org.skywalking.apm.collector.core.util.ColumnNameUtils;
import org.skywalking.apm.collector.core.util.Const;
-import org.skywalking.apm.collector.core.util.ObjectUtils;
-import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.storage.h2.SqlBuilder;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
-import org.skywalking.apm.collector.ui.cache.ServiceIdCache;
-import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-
/**
* @author pengys5, clevertension
*/
public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO {
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceH2DAO.class);
- private static final String GET_SRV_REF_LOAD1 = "select {4}, {5}, {6}, {7}, sum({8}) as cnt1, sum({9}) as cnt2, sum({10}) as cnt3" +
- ",sum({11}) as cnt4, sum({12}) cnt5, sum({13}) as cnt6, sum({14}) as cnt7 from {0} where {1} >= ? and {1} <= ? and {2} = ? and {3} = ? group by {4}, {5}, {6}, {7}";
- private static final String GET_SRV_REF_LOAD2 = "select {3}, {4}, {5}, {6}, sum({7}) as cnt1, sum({8}) as cnt2, sum({9}) as cnt3" +
- ",sum({10}) as cnt4, sum({11}) cnt5, sum({12}) as cnt6, sum({13}) as cnt7 from {0} where {1} >= ? and {1} <= ? and {2} = ? group by {3}, {4}, {5}, {6}";
+ private static final String GET_SRV_REF_LOAD1 = "select {3}, {4}, sum({5}) as {5}, sum({6}) as {6}, sum({7}) as {7}" +
+ ",sum({8}) as {8}, sum({9}) as {9}, sum({10}) as {10}, sum({11}) as {11} from {0} where {1} >= ? and {1} <= ? and {2} = ? group by {3}, {4}";
- @Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
+ @Override public Map load(int entryServiceId, long startTime, long endTime) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
- ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_S1_LTE, ServiceReferenceTable.COLUMN_S3_LTE, ServiceReferenceTable.COLUMN_S5_LTE,
- ServiceReferenceTable.COLUMN_S5_GT, ServiceReferenceTable.COLUMN_ERROR, ServiceReferenceTable.COLUMN_SUMMARY,
- ServiceReferenceTable.COLUMN_COST_SUMMARY);
- String entryServiceName = ServiceNameCache.get(entryServiceId);
- Object[] params = new Object[]{startTime, endTime, entryServiceId, entryServiceName};
- try (ResultSet rs = client.executeQuery(sql, params)) {
- if (rs.next()) {
- Map serviceReferenceMap = new LinkedHashMap<>();
-
- int frontServiceId = rs.getInt(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID);
- if (frontServiceId != 0) {
- parseSubAggregate(serviceReferenceMap, rs, frontServiceId);
- }
-
- String frontServiceName = rs.getString(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- String[] serviceNames = frontServiceName.split(Const.ID_SPLIT);
- int frontServiceId1 = ServiceIdCache.getForUI(Integer.parseInt(serviceNames[0]), serviceNames[1]);
- parseSubAggregate(serviceReferenceMap, rs, frontServiceId1);
- }
-
- JsonArray serviceReferenceArray = new JsonArray();
- JsonObject rootServiceReference = findRoot(serviceReferenceMap);
- if (ObjectUtils.isNotEmpty(rootServiceReference)) {
- serviceReferenceArray.add(rootServiceReference);
- String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
- serviceReferenceMap.remove(id);
-
- int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
- sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap);
- }
- return serviceReferenceArray;
- }
- } catch (SQLException | H2ClientException e) {
- logger.error(e.getMessage(), e);
- }
- return null;
+ ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID,
+ ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
+ ServiceReferenceTable.COLUMN_S1_LTE, ServiceReferenceTable.COLUMN_S3_LTE, ServiceReferenceTable.COLUMN_S5_LTE,
+ ServiceReferenceTable.COLUMN_S5_GT, ServiceReferenceTable.COLUMN_ERROR, ServiceReferenceTable.COLUMN_SUMMARY,
+ ServiceReferenceTable.COLUMN_COST_SUMMARY);
+ Object[] params = new Object[] {startTime, endTime, entryServiceId};
+
+ return load(client, params, sql);
}
- @Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
- H2Client client = getClient();
- String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD2, ServiceReferenceTable.TABLE,
- ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_S1_LTE, ServiceReferenceTable.COLUMN_S3_LTE, ServiceReferenceTable.COLUMN_S5_LTE,
- ServiceReferenceTable.COLUMN_S5_GT, ServiceReferenceTable.COLUMN_ERROR, ServiceReferenceTable.COLUMN_SUMMARY,
- ServiceReferenceTable.COLUMN_COST_SUMMARY);
- entryServiceName = entryApplicationId + Const.ID_SPLIT + entryServiceName;
- Object[] params = new Object[]{startTime, endTime, entryServiceName};
- int entryServiceId = ServiceIdCache.get(entryApplicationId, entryServiceName);
- if (entryServiceId != 0) {
- sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
- ServiceReferenceTable.COLUMN_TIME_BUCKET, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_ID, ServiceReferenceTable.COLUMN_ENTRY_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID,
- ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME, ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME,
- ServiceReferenceTable.COLUMN_S1_LTE, ServiceReferenceTable.COLUMN_S3_LTE, ServiceReferenceTable.COLUMN_S5_LTE,
- ServiceReferenceTable.COLUMN_S5_GT, ServiceReferenceTable.COLUMN_ERROR, ServiceReferenceTable.COLUMN_SUMMARY,
- ServiceReferenceTable.COLUMN_COST_SUMMARY);
- params = new Object[]{startTime, endTime, entryServiceId, entryServiceName};
- }
+ private Map load(H2Client client, Object[] params, String sql) {
+ Map serviceReferenceMap = new LinkedHashMap<>();
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
- Map serviceReferenceMap = new LinkedHashMap<>();
-
int frontServiceId = rs.getInt(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID);
- if (frontServiceId != 0) {
- parseSubAggregate(serviceReferenceMap, rs, frontServiceId);
- }
-
- String frontServiceName = rs.getString(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- String[] serviceNames = frontServiceName.split(Const.ID_SPLIT);
- int frontServiceId1 = ServiceIdCache.getForUI(Integer.parseInt(serviceNames[0]), serviceNames[1]);
- parseSubAggregate(serviceReferenceMap, rs, frontServiceId1);
- }
-
- JsonArray serviceReferenceArray = new JsonArray();
- JsonObject rootServiceReference = findRoot(serviceReferenceMap);
- if (ObjectUtils.isNotEmpty(rootServiceReference)) {
- serviceReferenceArray.add(rootServiceReference);
- String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
- serviceReferenceMap.remove(id);
-
- int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
- sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap);
- }
- return serviceReferenceArray;
+ parseSubAggregate(serviceReferenceMap, rs, frontServiceId);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
- return null;
+ return serviceReferenceMap;
}
- private void parseSubAggregate(Map serviceReferenceMap,
- ResultSet rs,
- int frontServiceId) {
+ private void parseSubAggregate(Map serviceReferenceMap, ResultSet rs,
+ int frontServiceId) {
try {
int behindServiceId = rs.getInt(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID);
if (behindServiceId != 0) {
- long s1LteSum = rs.getLong("cnt1");
- long s3LteSum = rs.getLong("cnt2");
- long s5LteSum = rs.getLong("cnt3");
- long s5GtSum = rs.getLong("cnt3");
- long error = rs.getLong("cnt3");
- long summary = rs.getLong("cnt3");
- long costSum = rs.getLong("cnt3");
+ long s1LteSum = rs.getLong(ServiceReferenceTable.COLUMN_S1_LTE);
+ long s3LteSum = rs.getLong(ServiceReferenceTable.COLUMN_S3_LTE);
+ long s5LteSum = rs.getLong(ServiceReferenceTable.COLUMN_S5_LTE);
+ long s5GtSum = rs.getLong(ServiceReferenceTable.COLUMN_S5_GT);
+ long error = rs.getLong(ServiceReferenceTable.COLUMN_ERROR);
+ long summary = rs.getLong(ServiceReferenceTable.COLUMN_SUMMARY);
+ long costSum = rs.getLong(ServiceReferenceTable.COLUMN_COST_SUMMARY);
- String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- frontServiceName = frontServiceName.split(Const.ID_SPLIT)[1];
- }
- String behindServiceName = ServiceNameCache.getForUI(behindServiceId);
- if (StringUtils.isNotEmpty(frontServiceName)) {
- behindServiceName = behindServiceName.split(Const.ID_SPLIT)[1];
- }
+ String frontServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(frontServiceId));
+ String behindServiceName = ServiceNameCache.getSplitServiceName(ServiceNameCache.get(behindServiceId));
JsonObject serviceReference = new JsonObject();
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
@@ -189,92 +98,12 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR), error);
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY), summary);
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY), costSum);
- merge(serviceReferenceMap, serviceReference);
- }
- } catch (SQLException e) {
- logger.error(e.getMessage(), e);
- }
-
- try {
- String behindServiceName = rs.getString(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME);
- if (StringUtils.isNotEmpty(behindServiceName)) {
- long s1LteSum = rs.getLong("cnt1");
- long s3LteSum = rs.getLong("cnt2");
- long s5LteSum = rs.getLong("cnt3");
- long s5GtSum = rs.getLong("cnt3");
- long error = rs.getLong("cnt3");
- long summary = rs.getLong("cnt3");
- long costSum = rs.getLong("cnt3");
-
- String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
- String[] serviceNames = behindServiceName.split(Const.ID_SPLIT);
- int behindServiceId = ServiceIdCache.getForUI(Integer.parseInt(serviceNames[0]), serviceNames[1]);
- behindServiceName = serviceNames[1];
- JsonObject serviceReference = new JsonObject();
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_NAME), frontServiceName);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_NAME), behindServiceName);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S1_LTE), s1LteSum);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S3_LTE), s3LteSum);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_LTE), s5LteSum);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_GT), s5GtSum);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR), error);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY), summary);
- serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY), costSum);
- merge(serviceReferenceMap, serviceReference);
+ String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
+ serviceReferenceMap.put(id, serviceReference);
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
}
-
- private void merge(Map serviceReferenceMap, JsonObject serviceReference) {
- String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
-
- if (serviceReferenceMap.containsKey(id)) {
- JsonObject reference = serviceReferenceMap.get(id);
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S1_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S3_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_LTE));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_GT));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY));
- add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY));
- } else {
- serviceReferenceMap.put(id, serviceReference);
- }
- }
-
- private void add(JsonObject oldReference, JsonObject newReference, String key) {
- long oldValue = oldReference.get(key).getAsLong();
- long newValue = newReference.get(key).getAsLong();
- oldReference.addProperty(key, oldValue + newValue);
- }
-
- private JsonObject findRoot(Map serviceReferenceMap) {
- for (JsonObject serviceReference : serviceReferenceMap.values()) {
- int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
- if (frontServiceId == 1) {
- return serviceReference;
- }
- }
- return null;
- }
-
- private void sortAsTree(int serviceId, JsonArray serviceReferenceArray,
- Map serviceReferenceMap) {
- Iterator iterator = serviceReferenceMap.values().iterator();
- while (iterator.hasNext()) {
- JsonObject serviceReference = iterator.next();
- int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
- if (serviceId == frontServiceId) {
- serviceReferenceArray.add(serviceReference);
-
- int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
- sortAsTree(behindServiceId, serviceReferenceArray, serviceReferenceMap);
- }
- }
- }
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/UIJettyModuleDefine.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/UIJettyModuleDefine.java
index a0ab797a894c3b6f61b87977edf049824dfe700a..1103e391edfb7a552af93eed55f3d8b5362fc660 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/UIJettyModuleDefine.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/UIJettyModuleDefine.java
@@ -39,7 +39,6 @@ import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetr
import org.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.EntryServiceGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler;
-import org.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByNameHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler;
import org.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler;
@@ -89,7 +88,6 @@ public class UIJettyModuleDefine extends UIModuleDefine {
handlers.add(new InstanceMetricGetRangeTimeBucketHandler());
handlers.add(new EntryServiceGetHandler());
handlers.add(new ServiceTreeGetByIdHandler());
- handlers.add(new ServiceTreeGetByNameHandler());
return handlers;
}
}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByNameHandler.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByNameHandler.java
deleted file mode 100644
index 41b36dee41970d79010f1ff8e9f4dd1feebc6408..0000000000000000000000000000000000000000
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByNameHandler.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2017, OpenSkywalking Organization All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Project repository: https://github.com/OpenSkywalking/skywalking
- */
-
-package org.skywalking.apm.collector.ui.jetty.handler.servicetree;
-
-import com.google.gson.JsonElement;
-import javax.servlet.http.HttpServletRequest;
-import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
-import org.skywalking.apm.collector.server.jetty.JettyHandler;
-import org.skywalking.apm.collector.ui.service.ServiceTreeService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author pengys5
- */
-public class ServiceTreeGetByNameHandler extends JettyHandler {
-
- private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByNameHandler.class);
-
- @Override public String pathSpec() {
- return "/service/tree/entryServiceName";
- }
-
- private ServiceTreeService service = new ServiceTreeService();
-
- @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException {
- if (!req.getParameterMap().containsKey("entryServiceName") || !req.getParameterMap().containsKey("entryApplicationId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) {
- throw new ArgumentsParseException("must contains parameters: entryServiceName, entryApplicationId, startTime, endTime");
- }
-
- String entryServiceName = req.getParameter("entryServiceName");
- String entryApplicationIdStr = req.getParameter("entryApplicationId");
- String startTimeStr = req.getParameter("startTime");
- String endTimeStr = req.getParameter("endTime");
- logger.debug("service entry get entryServiceName: {}, startTime: {}, endTime: {}", entryServiceName, startTimeStr, endTimeStr);
-
- int entryApplicationId;
- try {
- entryApplicationId = Integer.parseInt(entryApplicationIdStr);
- } catch (NumberFormatException e) {
- throw new ArgumentsParseException("entry application id must be integer");
- }
-
- long startTime;
- try {
- startTime = Long.parseLong(startTimeStr);
- } catch (NumberFormatException e) {
- throw new ArgumentsParseException("start time must be long");
- }
-
- long endTime;
- try {
- endTime = Long.parseLong(endTimeStr);
- } catch (NumberFormatException e) {
- throw new ArgumentsParseException("end time must be long");
- }
-
- return service.loadServiceTree(entryServiceName, entryApplicationId, startTime, endTime);
- }
-
- @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java
index 95bfa5209c0312c8d8a3ae7a4cbf61ae10f48d26..3a739522f3910911cd83fe8e6f250e2f332648ba 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/InstanceHealthService.java
@@ -21,10 +21,10 @@ package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.List;
+import org.skywalking.apm.collector.cache.ApplicationCache;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.storage.define.register.InstanceDataDefine;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
import org.skywalking.apm.collector.ui.dao.IGCMetricDAO;
import org.skywalking.apm.collector.ui.dao.IInstPerformanceDAO;
import org.skywalking.apm.collector.ui.dao.IInstanceDAO;
@@ -50,7 +50,7 @@ public class InstanceHealthService {
response.add("instances", instances);
instanceList.forEach(instance -> {
- response.addProperty("applicationCode", ApplicationCache.getForUI(applicationId));
+ response.addProperty("applicationCode", ApplicationCache.get(applicationId));
response.addProperty("applicationId", applicationId);
IInstPerformanceDAO instPerformanceDAO = (IInstPerformanceDAO)DAOContainer.INSTANCE.get(IInstPerformanceDAO.class.getName());
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java
index 53c09692a97297e37dae90b77298f3407cc4aeb5..ef966e3d1180507a12040b8be40915bba6828100 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/ServiceTreeService.java
@@ -20,7 +20,13 @@ package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+import java.util.Iterator;
+import java.util.Map;
+import org.skywalking.apm.collector.core.util.ColumnNameUtils;
+import org.skywalking.apm.collector.core.util.Const;
+import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
+import org.skywalking.apm.collector.storage.define.serviceref.ServiceReferenceTable;
import org.skywalking.apm.collector.ui.dao.IServiceEntryDAO;
import org.skywalking.apm.collector.ui.dao.IServiceReferenceDAO;
@@ -37,11 +43,70 @@ public class ServiceTreeService {
public JsonArray loadServiceTree(int entryServiceId, long startTime, long endTime) {
IServiceReferenceDAO serviceReferenceDAO = (IServiceReferenceDAO)DAOContainer.INSTANCE.get(IServiceReferenceDAO.class.getName());
- return serviceReferenceDAO.load(entryServiceId, startTime, endTime);
+ Map serviceReferenceMap = serviceReferenceDAO.load(entryServiceId, startTime, endTime);
+ return buildTreeData(serviceReferenceMap);
}
- public JsonArray loadServiceTree(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
- IServiceReferenceDAO serviceReferenceDAO = (IServiceReferenceDAO)DAOContainer.INSTANCE.get(IServiceReferenceDAO.class.getName());
- return serviceReferenceDAO.load(entryServiceName, entryApplicationId, startTime, endTime);
+ private JsonArray buildTreeData(Map serviceReferenceMap) {
+ JsonArray serviceReferenceArray = new JsonArray();
+ JsonObject rootServiceReference = findRoot(serviceReferenceMap);
+ if (ObjectUtils.isNotEmpty(rootServiceReference)) {
+ serviceReferenceArray.add(rootServiceReference);
+ String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
+ serviceReferenceMap.remove(id);
+
+ int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
+ sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap);
+ }
+
+ return serviceReferenceArray;
+ }
+
+ private JsonObject findRoot(Map serviceReferenceMap) {
+ for (JsonObject serviceReference : serviceReferenceMap.values()) {
+ int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
+ if (frontServiceId == 1) {
+ return serviceReference;
+ }
+ }
+ return null;
+ }
+
+ private void sortAsTree(int serviceId, JsonArray serviceReferenceArray,
+ Map serviceReferenceMap) {
+ Iterator iterator = serviceReferenceMap.values().iterator();
+ while (iterator.hasNext()) {
+ JsonObject serviceReference = iterator.next();
+ int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
+ if (serviceId == frontServiceId) {
+ serviceReferenceArray.add(serviceReference);
+
+ int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
+ sortAsTree(behindServiceId, serviceReferenceArray, serviceReferenceMap);
+ }
+ }
+ }
+
+ private void merge(Map serviceReferenceMap, JsonObject serviceReference) {
+ String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID));
+
+ if (serviceReferenceMap.containsKey(id)) {
+ JsonObject reference = serviceReferenceMap.get(id);
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S1_LTE));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S3_LTE));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_LTE));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_S5_GT));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_ERROR));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_SUMMARY));
+ add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceTable.COLUMN_COST_SUMMARY));
+ } else {
+ serviceReferenceMap.put(id, serviceReference);
+ }
+ }
+
+ private void add(JsonObject oldReference, JsonObject newReference, String key) {
+ long oldValue = oldReference.get(key).getAsLong();
+ long newValue = newReference.get(key).getAsLong();
+ oldReference.addProperty(key, oldValue + newValue);
}
}
\ No newline at end of file
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java
index 2716e7b0b648ff79bf71e962985e8369c18f6dd8..4be2bad26c05c3924d53d297da75717770c7c4ab 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/SpanService.java
@@ -21,11 +21,11 @@ package org.skywalking.apm.collector.ui.service;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.List;
+import org.skywalking.apm.collector.cache.ApplicationCache;
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
-import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
import org.skywalking.apm.collector.ui.dao.ISegmentDAO;
import org.skywalking.apm.network.proto.KeyWithStringValue;
import org.skywalking.apm.network.proto.LogMessage;
@@ -96,7 +96,7 @@ public class SpanService {
if (spanObject.getPeerId() == 0) {
peerJson.addProperty("value", spanObject.getPeer());
} else {
- peerJson.addProperty("value", ApplicationCache.getForUI(spanObject.getPeerId()));
+ peerJson.addProperty("value", ApplicationCache.get(spanObject.getPeerId()));
}
tagsArray.add(peerJson);
diff --git a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java
index 3d72be9e3ebfb01b47308e67835539ab5c273cfd..94abc71612bb278eac6ad0304c2ac71252a05a85 100644
--- a/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java
+++ b/apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/service/TraceStackService.java
@@ -22,13 +22,13 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.List;
+import org.skywalking.apm.collector.cache.ApplicationCache;
+import org.skywalking.apm.collector.cache.ServiceNameCache;
import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.core.util.StringUtils;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
-import org.skywalking.apm.collector.ui.cache.ApplicationCache;
-import org.skywalking.apm.collector.ui.cache.ServiceNameCache;
import org.skywalking.apm.collector.ui.dao.IGlobalTraceDAO;
import org.skywalking.apm.collector.ui.dao.ISegmentDAO;
import org.skywalking.apm.network.proto.SpanObject;
diff --git a/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define b/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define
index 554fbdddbf626fcb87b5858b01ebd3c553f524d8..a606efedb74c91b512cc3b7b9327898984532740 100644
--- a/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define
+++ b/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/es_dao.define
@@ -4,8 +4,6 @@ org.skywalking.apm.collector.ui.dao.NodeReferenceEsDAO
org.skywalking.apm.collector.ui.dao.SegmentCostEsDAO
org.skywalking.apm.collector.ui.dao.GlobalTraceEsDAO
org.skywalking.apm.collector.ui.dao.SegmentEsDAO
-org.skywalking.apm.collector.ui.dao.ApplicationEsDAO
-org.skywalking.apm.collector.ui.dao.ServiceNameEsDAO
org.skywalking.apm.collector.ui.dao.InstanceEsDAO
org.skywalking.apm.collector.ui.dao.InstPerformanceEsDAO
org.skywalking.apm.collector.ui.dao.CpuMetricEsDAO
diff --git a/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define b/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define
index 742176e4dc9eff76dd69f1b3892cf170d6c8fa9e..bc4d41f8b9c743dd4299292ef606d596ad3dce29 100644
--- a/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define
+++ b/apm-collector/apm-collector-ui/src/main/resources/META-INF/defines/h2_dao.define
@@ -4,8 +4,6 @@ org.skywalking.apm.collector.ui.dao.NodeReferenceH2DAO
org.skywalking.apm.collector.ui.dao.SegmentCostH2DAO
org.skywalking.apm.collector.ui.dao.GlobalTraceH2DAO
org.skywalking.apm.collector.ui.dao.SegmentH2DAO
-org.skywalking.apm.collector.ui.dao.ApplicationH2DAO
-org.skywalking.apm.collector.ui.dao.ServiceNameH2DAO
org.skywalking.apm.collector.ui.dao.InstanceH2DAO
org.skywalking.apm.collector.ui.dao.InstPerformanceH2DAO
org.skywalking.apm.collector.ui.dao.CpuMetricH2DAO
diff --git a/apm-collector/pom.xml b/apm-collector/pom.xml
index 7d11d050006185576b188d2f208f32f02c036249..edcab1970d7b0d0066209986a734d50cbf669057 100644
--- a/apm-collector/pom.xml
+++ b/apm-collector/pom.xml
@@ -35,6 +35,7 @@
apm-collector-agentregister
apm-collector-agentjvm
apm-collector-remote
+ apm-collector-cache
apm