Change the method which called by H2 Dao implements.
This commit is contained in:
parent
e7696ef252
commit
cdd9e88a8d
|
|
@ -27,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
|
||||
# elasticsearch:
|
||||
# cluster_name: CollectorDBCluster
|
||||
# cluster_transport_sniffer: true
|
||||
# cluster_nodes: localhost:9300
|
||||
# index_shards_number: 2
|
||||
# index_replicas_number: 0
|
||||
|
|
@ -18,11 +18,15 @@
|
|||
|
||||
package org.skywalking.apm.collector.client.h2;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import org.h2.jdbcx.JdbcConnectionPool;
|
||||
import org.h2.util.IOUtils;
|
||||
import org.skywalking.apm.collector.core.client.Client;
|
||||
import org.skywalking.apm.collector.core.config.SystemConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -40,21 +44,15 @@ public class H2Client implements Client {
|
|||
private String password;
|
||||
|
||||
public H2Client() {
|
||||
this.url = "jdbc:h2:mem:collector";
|
||||
this.url = "jdbc:h2:" + SystemConfig.DATA_PATH + "/h2";
|
||||
this.userName = "";
|
||||
this.password = "";
|
||||
}
|
||||
|
||||
public H2Client(String url, String userName, String password) {
|
||||
this.url = url;
|
||||
this.userName = userName;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override public void initialize() throws H2ClientException {
|
||||
try {
|
||||
cp = JdbcConnectionPool.
|
||||
create(this.url, this.userName, this.password);
|
||||
create(this.url, this.userName, this.password);
|
||||
conn = cp.getConnection();
|
||||
} catch (Exception e) {
|
||||
throw new H2ClientException(e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +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.storage.h2;
|
||||
|
||||
/**
|
||||
* @author clevertension
|
||||
*/
|
||||
public class StorageH2Config {
|
||||
public static String URL;
|
||||
public static String USER_NAME;
|
||||
public static String PASSWORD;
|
||||
}
|
||||
|
|
@ -1,45 +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.storage.h2;
|
||||
|
||||
import java.util.Map;
|
||||
import org.skywalking.apm.collector.core.config.ConfigParseException;
|
||||
import org.skywalking.apm.collector.core.module.ModuleConfigParser;
|
||||
import org.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.skywalking.apm.collector.core.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author pengys5
|
||||
*/
|
||||
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);
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(config) && StringUtils.isNotEmpty(config.get(USER_NAME))) {
|
||||
StorageH2Config.USER_NAME = (String)config.get(USER_NAME);
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(config) && StringUtils.isNotEmpty(config.get(PASSWORD))) {
|
||||
StorageH2Config.PASSWORD = (String)config.get(PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,12 +46,16 @@ public class StorageH2ModuleDefine extends StorageModuleDefine {
|
|||
return MODULE_NAME;
|
||||
}
|
||||
|
||||
@Override public final boolean defaultModule() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override protected ModuleConfigParser configParser() {
|
||||
return new StorageH2ConfigParser();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override protected Client createClient() {
|
||||
return new H2Client(StorageH2Config.URL, StorageH2Config.USER_NAME, StorageH2Config.PASSWORD);
|
||||
return new H2Client();
|
||||
}
|
||||
|
||||
@Override public StorageInstaller storageInstaller() {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@
|
|||
|
||||
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);
|
||||
Map<String, JsonObject> load(int entryServiceId, long startTime, long endTime);
|
||||
|
||||
JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime);
|
||||
Map<String, JsonObject> load(String entryServiceName, int entryApplicationId, long startTime, long endTime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<InstanceDataDefine.Instance> 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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(applicationId);
|
||||
String entryServiceName1 = rs.getString(ServiceEntryTable.COLUMN_ENTRY_SERVICE_NAME);
|
||||
|
||||
JsonObject row = new JsonObject();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -35,7 +33,6 @@ 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;
|
||||
|
|
@ -49,7 +46,8 @@ 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<String, JsonObject> load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceTable.TABLE);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
|
@ -72,7 +70,7 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
|
|||
return load(searchRequestBuilder);
|
||||
}
|
||||
|
||||
@Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
|
||||
@Override public Map<String, JsonObject> 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);
|
||||
|
|
@ -93,35 +91,9 @@ public class ServiceReferenceEsDAO extends EsDAO implements IServiceReferenceDAO
|
|||
return load(searchRequestBuilder);
|
||||
}
|
||||
|
||||
private JsonArray load(SearchRequestBuilder searchRequestBuilder) {
|
||||
private Map<String, JsonObject> 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 +113,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.get(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<String, JsonObject> serviceReferenceMap,
|
||||
|
|
@ -200,88 +152,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);
|
||||
}
|
||||
}
|
||||
|
||||
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.get(frontServiceId);
|
||||
String[] serviceNames = behindServiceName.split(Const.ID_SPLIT);
|
||||
int behindServiceId = ServiceIdCache.get(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), (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void merge(Map<String, JsonObject> 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<String, JsonObject> 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<String, JsonObject> serviceReferenceMap) {
|
||||
Iterator<JsonObject> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,29 +18,24 @@
|
|||
|
||||
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.ServiceIdCache;
|
||||
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
|
||||
*/
|
||||
|
|
@ -48,115 +43,69 @@ 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}";
|
||||
",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}";
|
||||
",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}";
|
||||
|
||||
@Override public JsonArray load(int entryServiceId, long startTime, long endTime) {
|
||||
@Override
|
||||
public Map<String, JsonObject> load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
|
||||
H2Client client = getClient();
|
||||
String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceTable.TABLE,
|
||||
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);
|
||||
|
||||
Object[] params = new Object[] {startTime, endTime, entryServiceName};
|
||||
entryServiceName = entryApplicationId + Const.ID_SPLIT + 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);
|
||||
String entryServiceName = ServiceNameCache.get(entryServiceId);
|
||||
Object[] params = new Object[]{startTime, endTime, entryServiceId, entryServiceName};
|
||||
try (ResultSet rs = client.executeQuery(sql, params)) {
|
||||
if (rs.next()) {
|
||||
Map<String, JsonObject> 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);
|
||||
params = new Object[] {startTime, endTime, entryServiceId, entryServiceName};
|
||||
}
|
||||
return null;
|
||||
|
||||
return load(client, params, sql);
|
||||
}
|
||||
|
||||
@Override public JsonArray load(String entryServiceName, int entryApplicationId, long startTime, long endTime) {
|
||||
@Override public Map<String, JsonObject> load(int entryServiceId, 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};
|
||||
}
|
||||
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};
|
||||
|
||||
return load(client, params, sql);
|
||||
}
|
||||
|
||||
private Map<String, JsonObject> load(H2Client client, Object[] params, String sql) {
|
||||
Map<String, JsonObject> serviceReferenceMap = new LinkedHashMap<>();
|
||||
|
||||
try (ResultSet rs = client.executeQuery(sql, params)) {
|
||||
if (rs.next()) {
|
||||
Map<String, JsonObject> 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<String, JsonObject> serviceReferenceMap,
|
||||
ResultSet rs,
|
||||
int frontServiceId) {
|
||||
private void parseSubAggregate(Map<String, JsonObject> serviceReferenceMap, ResultSet rs,
|
||||
int frontServiceId) {
|
||||
try {
|
||||
int behindServiceId = rs.getInt(ServiceReferenceTable.COLUMN_BEHIND_SERVICE_ID);
|
||||
if (behindServiceId != 0) {
|
||||
|
|
@ -168,11 +117,11 @@ public class ServiceReferenceH2DAO extends H2DAO implements IServiceReferenceDAO
|
|||
long summary = rs.getLong("cnt3");
|
||||
long costSum = rs.getLong("cnt3");
|
||||
|
||||
String frontServiceName = ServiceNameCache.getForUI(frontServiceId);
|
||||
String frontServiceName = ServiceNameCache.get(frontServiceId);
|
||||
if (StringUtils.isNotEmpty(frontServiceName)) {
|
||||
frontServiceName = frontServiceName.split(Const.ID_SPLIT)[1];
|
||||
}
|
||||
String behindServiceName = ServiceNameCache.getForUI(behindServiceId);
|
||||
String behindServiceName = ServiceNameCache.get(behindServiceId);
|
||||
if (StringUtils.isNotEmpty(frontServiceName)) {
|
||||
behindServiceName = behindServiceName.split(Const.ID_SPLIT)[1];
|
||||
}
|
||||
|
|
@ -189,92 +138,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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void merge(Map<String, JsonObject> 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<String, JsonObject> 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<String, JsonObject> serviceReferenceMap) {
|
||||
Iterator<JsonObject> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,76 @@ 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<String, JsonObject> 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);
|
||||
Map<String, JsonObject> serviceReferenceMap = serviceReferenceDAO.load(entryServiceName, entryApplicationId, startTime, endTime);
|
||||
return buildTreeData(serviceReferenceMap);
|
||||
}
|
||||
|
||||
private JsonArray buildTreeData(Map<String, JsonObject> 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<String, JsonObject> 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<String, JsonObject> serviceReferenceMap) {
|
||||
Iterator<JsonObject> 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<String, JsonObject> 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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue