提交 fb9200a9 编写于 作者: P peng-yongsheng

Create cache module to provide id or name get. e.g.. application id, instance id, service id…

#423
上级 241e447e
......@@ -51,5 +51,10 @@
<artifactId>apm-network</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-cache</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -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;
......
......@@ -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.IServiceNameDAO;
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;
......
......@@ -55,8 +55,10 @@ public class ApplicationRegisterSerialWorker extends AbstractLocalAsyncWorker {
ApplicationDataDefine.Application application = (ApplicationDataDefine.Application)message;
logger.debug("register application, application code: {}", application.getApplicationCode());
org.skywalking.apm.collector.cache.dao.IApplicationDAO cacheDao = (org.skywalking.apm.collector.cache.dao.IApplicationDAO)DAOContainer.INSTANCE.get(org.skywalking.apm.collector.cache.dao.IApplicationDAO.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) {
......
......@@ -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);
}
......
......@@ -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.storage.define.register.ApplicationDataDefine;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
......@@ -27,11 +26,6 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
*/
public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
@Override public int getApplicationId(String applicationCode) {
H2Client client = getClient();
return 100;
}
@Override public int getMaxApplicationId() {
return 0;
}
......
......@@ -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();
......
/*
* 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.agentregister.worker.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.storage.dao.DAOContainer;
/**
* @author pengys5
*/
public class ApplicationCache {
private static Cache<String, Integer> CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
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);
});
} catch (Throwable e) {
return applicationId;
}
if (applicationId == 0) {
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
applicationId = dao.getApplicationId(applicationCode);
if (applicationId != 0) {
CACHE.put(applicationCode, applicationId);
}
}
return applicationId;
}
}
......@@ -33,6 +33,4 @@ public interface IInstanceDAO {
void save(InstanceDataDefine.Instance instance);
void updateHeartbeatTime(int instanceId, long heartbeatTime);
int getApplicationId(int applicationInstanceId);
}
......@@ -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;
}
}
}
......@@ -25,6 +25,7 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
* @author pengys5
*/
public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public int getInstanceId(int applicationId, String agentUUID) {
return 0;
}
......@@ -44,8 +45,4 @@ public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
}
@Override public int getApplicationId(int applicationInstanceId) {
return 0;
}
}
......@@ -55,9 +55,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());
org.skywalking.apm.collector.cache.dao.IServiceNameDAO cacheDao = (org.skywalking.apm.collector.cache.dao.IServiceNameDAO)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) {
......
......@@ -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();
......
......@@ -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();
......
......@@ -26,10 +26,6 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
*/
public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
@Override public int getServiceId(int applicationId, String serviceName) {
return 0;
}
@Override public int getMaxServiceId() {
return 0;
}
......@@ -38,10 +34,6 @@ public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
return 0;
}
@Override public String getServiceName(int serviceId) {
return null;
}
@Override public void save(ServiceNameDataDefine.ServiceName serviceName) {
}
......
......@@ -61,5 +61,10 @@
<artifactId>apm-collector-agentregister</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-cache</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* 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<Integer, String> 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;
}
}
}
......@@ -20,10 +20,10 @@ 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.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;
......
......@@ -20,11 +20,11 @@ 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.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;
......@@ -64,7 +64,7 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe
if (spanObject.getOperationNameId() == 0) {
segmentCost.setServiceName(spanObject.getOperationName());
} else {
segmentCost.setServiceName(ServiceCache.getServiceName(spanObject.getOperationNameId()));
segmentCost.setServiceName(ServiceNameCache.get(spanObject.getOperationNameId()));
}
segmentCosts.add(segmentCost);
......
......@@ -18,10 +18,10 @@
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.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;
......@@ -56,7 +56,7 @@ public class ServiceEntrySpanListener implements RefsListener, FirstSpanListener
if (spanObject.getOperationNameId() == 0) {
this.entryServiceName = spanObject.getOperationName();
} else {
this.entryServiceName = ServiceCache.getServiceName(this.entryServiceId);
this.entryServiceName = ServiceNameCache.get(this.entryServiceId);
}
this.hasEntry = true;
}
......
......@@ -20,10 +20,10 @@ 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.cache.InstanceCache;
import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.core.util.TimeBucketUtils;
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-collector</artifactId>
<groupId>org.skywalking</groupId>
<version>3.2.3-2017</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-collector-cache</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-storage</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -16,25 +16,47 @@
* 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.IApplicationDAO;
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<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
private static Cache<String, Integer> CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
public static int get(String applicationCode) {
int applicationId = 0;
try {
applicationId = CODE_CACHE.get(applicationCode, () -> {
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
return dao.getApplicationId(applicationCode);
});
} catch (Throwable e) {
return applicationId;
}
if (applicationId == 0) {
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
applicationId = dao.getApplicationId(applicationCode);
if (applicationId != 0) {
CODE_CACHE.put(applicationCode, applicationId);
}
}
return applicationId;
}
private static Cache<Integer, String> ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
public static String get(int applicationId) {
try {
return CACHE.get(applicationId, () -> {
return ID_CACHE.get(applicationId, () -> {
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
return dao.getApplicationCode(applicationId);
});
......@@ -48,7 +70,7 @@ public class ApplicationCache {
if (applicationCode.equals("Unknown")) {
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
applicationCode = dao.getApplicationCode(applicationId);
CACHE.put(applicationId, applicationCode);
ID_CACHE.put(applicationId, applicationCode);
}
return applicationCode;
}
......
......@@ -16,11 +16,11 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.agentstream.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.instance.dao.IInstanceDAO;
import org.skywalking.apm.collector.cache.dao.IInstanceDAO;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
/**
......
......@@ -16,13 +16,13 @@
* 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.IServiceNameDAO;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.ui.dao.IServiceNameDAO;
/**
* @author pengys5
......
......@@ -16,13 +16,13 @@
* 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.IServiceNameDAO;
import org.skywalking.apm.collector.core.util.Const;
import org.skywalking.apm.collector.storage.dao.DAOContainer;
import org.skywalking.apm.collector.ui.dao.IServiceNameDAO;
/**
* @author pengys5
......
......@@ -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;
......@@ -34,6 +39,24 @@ 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 String getApplicationCode(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
ElasticSearchClient client = getClient();
......
......@@ -16,8 +16,9 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.ui.dao;
package org.skywalking.apm.collector.cache.dao;
import org.skywalking.apm.collector.client.h2.H2Client;
import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
/**
......@@ -25,6 +26,11 @@ import org.skywalking.apm.collector.storage.h2.dao.H2DAO;
*/
public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
@Override public int getApplicationId(String applicationCode) {
H2Client client = getClient();
return 100;
}
@Override public String getApplicationCode(int applicationId) {
return null;
}
......
......@@ -16,11 +16,13 @@
* 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 IApplicationDAO {
int getApplicationId(String applicationCode);
String getApplicationCode(int applicationId);
}
/*
* 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 IInstanceDAO {
int getApplicationId(int applicationInstanceId);
}
......@@ -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;
/**
* @author pengys5
......
/*
* 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 InstanceEsDAO extends EsDAO implements IInstanceDAO {
private final Logger logger = LoggerFactory.getLogger(InstanceEsDAO.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;
}
}
}
/*
* 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.skywalking.apm.collector.storage.h2.dao.H2DAO;
/**
* @author pengys5
*/
public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
@Override public int getApplicationId(int applicationInstanceId) {
return 0;
}
}
......@@ -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;
......
......@@ -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.skywalking.apm.collector.storage.h2.dao.H2DAO;
......
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
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
......@@ -51,5 +51,10 @@
<artifactId>apm-collector-storage</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>apm-collector-cache</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
......
......@@ -31,14 +31,14 @@ 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.ServiceIdCache;
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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
......
......@@ -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.GCMetricH2DAO
......
......@@ -35,6 +35,7 @@
<module>apm-collector-agentregister</module>
<module>apm-collector-agentjvm</module>
<module>apm-collector-remote</module>
<module>apm-collector-cache</module>
</modules>
<parent>
<artifactId>apm</artifactId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册