Fixed the suggest of review.
This commit is contained in:
parent
5ae51d2fc3
commit
60f94213df
|
|
@ -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.cache.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) {
|
||||
|
|
|
|||
|
|
@ -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,7 +56,7 @@ 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());
|
||||
IApplicationCacheDAO cacheDao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
|
||||
int applicationId = cacheDao.getApplicationId(application.getApplicationCode());
|
||||
|
||||
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
|
||||
|
|
|
|||
|
|
@ -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,7 +56,7 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker {
|
|||
ServiceNameDataDefine.ServiceName serviceName = (ServiceNameDataDefine.ServiceName)message;
|
||||
logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId());
|
||||
|
||||
org.skywalking.apm.collector.cache.dao.IServiceNameDAO cacheDao = (org.skywalking.apm.collector.cache.dao.IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -135,8 +135,4 @@ public class SegmentPost {
|
|||
|
||||
return osInfoJson;
|
||||
}
|
||||
|
||||
private void newDao() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +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.segment.buffer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class OffsetManagerTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ 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.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;
|
||||
|
|
@ -37,7 +37,7 @@ public class ApplicationCache {
|
|||
private static Cache<String, Integer> CODE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(1000).build();
|
||||
|
||||
public static int get(String applicationCode) {
|
||||
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
|
||||
|
||||
int applicationId = 0;
|
||||
try {
|
||||
|
|
@ -58,7 +58,7 @@ public class ApplicationCache {
|
|||
private static Cache<Integer, String> ID_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
|
||||
|
||||
public static String get(int applicationId) {
|
||||
IApplicationDAO dao = (IApplicationDAO)DAOContainer.INSTANCE.get(IApplicationDAO.class.getName());
|
||||
IApplicationCacheDAO dao = (IApplicationCacheDAO)DAOContainer.INSTANCE.get(IApplicationCacheDAO.class.getName());
|
||||
|
||||
String applicationCode = Const.EMPTY_STRING;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ 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.IInstanceDAO;
|
||||
import org.skywalking.apm.collector.cache.dao.IInstanceCacheDAO;
|
||||
import org.skywalking.apm.collector.storage.dao.DAOContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -35,7 +35,7 @@ public class InstanceCache {
|
|||
private static Cache<Integer, Integer> INSTANCE_CACHE = CacheBuilder.newBuilder().initialCapacity(100).maximumSize(5000).build();
|
||||
|
||||
public static int get(int applicationInstanceId) {
|
||||
IInstanceDAO dao = (IInstanceDAO)DAOContainer.INSTANCE.get(IInstanceDAO.class.getName());
|
||||
IInstanceCacheDAO dao = (IInstanceCacheDAO)DAOContainer.INSTANCE.get(IInstanceCacheDAO.class.getName());
|
||||
|
||||
int applicationId = 0;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ 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.cache.dao.IServiceNameCacheDAO;
|
||||
import org.skywalking.apm.collector.core.util.Const;
|
||||
import org.skywalking.apm.collector.storage.dao.DAOContainer;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -37,7 +37,7 @@ public class ServiceIdCache {
|
|||
private static Cache<String, Integer> SERVICE_CACHE = CacheBuilder.newBuilder().maximumSize(1000).build();
|
||||
|
||||
public static int get(int applicationId, String serviceName) {
|
||||
IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
|
||||
|
||||
int serviceId = 0;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ 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.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;
|
||||
|
|
@ -38,7 +38,7 @@ public class ServiceNameCache {
|
|||
private static Cache<Integer, String> CACHE = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
|
||||
public static String get(int serviceId) {
|
||||
IServiceNameDAO dao = (IServiceNameDAO)DAOContainer.INSTANCE.get(IServiceNameDAO.class.getName());
|
||||
IServiceNameCacheDAO dao = (IServiceNameCacheDAO)DAOContainer.INSTANCE.get(IServiceNameCacheDAO.class.getName());
|
||||
|
||||
String serviceName = Const.EMPTY_STRING;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ 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();
|
||||
|
|
@ -32,23 +32,32 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author pengys5, clevertension
|
||||
*/
|
||||
public class ApplicationH2DAO extends H2DAO implements IApplicationDAO {
|
||||
public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ApplicationH2DAO.class);
|
||||
private static final String GET_APPLICATION_CODE_SQL = "select {0} from {1} where {2} = ?";
|
||||
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);
|
||||
String sql = "select " + ApplicationTable.COLUMN_APPLICATION_ID + " from " +
|
||||
ApplicationTable.TABLE + " where " + ApplicationTable.COLUMN_APPLICATION_CODE + "='" + applicationCode + "'";
|
||||
return getIntValueBySQL(sql);
|
||||
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_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
|
||||
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()) {
|
||||
|
|
@ -21,7 +21,7 @@ package org.skywalking.apm.collector.cache.dao;
|
|||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public interface IApplicationDAO {
|
||||
public interface IApplicationCacheDAO {
|
||||
int getApplicationId(String applicationCode);
|
||||
|
||||
String getApplicationCode(int applicationId);
|
||||
|
|
@ -21,6 +21,6 @@ package org.skywalking.apm.collector.cache.dao;
|
|||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public interface IInstanceDAO {
|
||||
public interface IInstanceCacheDAO {
|
||||
int getApplicationId(int applicationInstanceId);
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ 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);
|
||||
|
|
@ -27,9 +27,9 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class InstanceEsDAO extends EsDAO implements IInstanceDAO {
|
||||
public class InstanceEsCacheDAO extends EsDAO implements IInstanceCacheDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceEsDAO.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceEsCacheDAO.class);
|
||||
|
||||
@Override public int getApplicationId(int applicationInstanceId) {
|
||||
GetResponse response = getClient().prepareGet(InstanceTable.TABLE, String.valueOf(applicationInstanceId)).get();
|
||||
|
|
@ -31,9 +31,9 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
public class InstanceH2DAO extends H2DAO implements IInstanceDAO {
|
||||
public class InstanceH2CacheDAO extends H2DAO implements IInstanceCacheDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceH2DAO.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(InstanceH2CacheDAO.class);
|
||||
|
||||
private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?";
|
||||
|
||||
|
|
@ -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));
|
||||
|
|
@ -32,9 +32,9 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author pengys5, clevertension
|
||||
*/
|
||||
public class ServiceNameH2DAO extends H2DAO implements IServiceNameDAO {
|
||||
public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceNameH2DAO.class);
|
||||
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";
|
||||
|
|
@ -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<H2Client> {
|
||||
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<H2Client> {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue