use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class SegmentDurationH2UIDAO method loadTop.
@Override
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration, String operationName, int applicationId, int limit, int from, String... segmentIds) {
H2Client client = getClient();
String sql = "select * from {0} where {1} >= ? and {1} <= ?";
List<Object> params = new ArrayList<>();
List<Object> columns = new ArrayList<>();
columns.add(SegmentDurationTable.TABLE);
columns.add(SegmentDurationTable.COLUMN_TIME_BUCKET);
params.add(startSecondTimeBucket);
params.add(endSecondTimeBucket);
int paramIndex = 1;
if (minDuration != -1 || maxDuration != -1) {
if (minDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} >= ?";
params.add(minDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
if (maxDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} <= ?";
params.add(maxDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
}
if (StringUtils.isNotEmpty(operationName)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(operationName);
columns.add(SegmentDurationTable.COLUMN_SERVICE_NAME);
}
if (StringUtils.isNotEmpty(segmentIds)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(segmentIds);
columns.add(SegmentDurationTable.COLUMN_TRACE_ID);
}
if (applicationId != 0) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(applicationId);
columns.add(SegmentDurationTable.COLUMN_APPLICATION_ID);
}
sql = sql + " limit " + from + "," + limit;
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
TraceBrief traceBrief = new TraceBrief();
int cnt = 0;
try (ResultSet rs = client.executeQuery(sql, p)) {
while (rs.next()) {
BasicTrace basicTrace = new BasicTrace();
basicTrace.setSegmentId(rs.getString(SegmentDurationTable.COLUMN_SEGMENT_ID));
basicTrace.setDuration(rs.getInt(SegmentDurationTable.COLUMN_DURATION));
basicTrace.setStart(rs.getLong(SegmentDurationTable.COLUMN_START_TIME));
basicTrace.setOperationName(rs.getString(SegmentDurationTable.COLUMN_SERVICE_NAME));
basicTrace.setError(BooleanUtils.valueToBoolean(rs.getInt(SegmentDurationTable.COLUMN_IS_ERROR)));
traceBrief.getTraces().add(basicTrace);
cnt++;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
traceBrief.setTotal(cnt);
return traceBrief;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getApplicationId.
@Override
public int getApplicationId(int instanceId) {
logger.info("get the application id by instance id = {}", instanceId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
Object[] params = new Object[] { instanceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getInstanceIdByAgentUUID.
@Override
public int getInstanceIdByAgentUUID(int applicationId, String agentUUID) {
logger.info("get the instance id by application id = {}, agentUUID = {}", applicationId, agentUUID);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_AGENT_UUID, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] { applicationId, agentUUID, BooleanUtils.FALSE };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class InstanceH2CacheDAO method getInstanceIdByAddressId.
@Override
public int getInstanceIdByAddressId(int applicationId, int addressId) {
logger.info("get the instance id by application id = {}, address id = {}", applicationId, addressId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_ADDRESS_ID, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] { applicationId, addressId, BooleanUtils.TRUE };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(InstanceTable.COLUMN_INSTANCE_ID);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
use of org.apache.skywalking.apm.collector.client.h2.H2Client in project incubator-skywalking by apache.
the class ServiceNameH2CacheDAO method get.
@Override
public ServiceName get(int serviceId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
Object[] params = new Object[] { serviceId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
ServiceName serviceName = new ServiceName();
serviceName.setServiceId(serviceId);
serviceName.setApplicationId(rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID));
serviceName.setServiceName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
return serviceName;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
Aggregations