use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2UIDAO method getInstance.
@Override
public 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 };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
Instance instance = new Instance();
instance.setId(rs.getString(InstanceTable.COLUMN_ID));
instance.setApplicationId(rs.getInt(InstanceTable.COLUMN_APPLICATION_ID));
instance.setAgentUUID(rs.getString(InstanceTable.COLUMN_AGENT_UUID));
instance.setRegisterTime(rs.getLong(InstanceTable.COLUMN_REGISTER_TIME));
instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
instance.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
return instance;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class InstanceH2UIDAO method getApplications.
@Override
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
H2Client client = getClient();
List<Application> applications = new LinkedList<>();
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[] { startSecondTimeBucket };
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
logger.debug("applicationId: {}", applicationId);
Application application = new Application();
application.setId(applicationId);
application.setNumOfServer(rs.getInt("cnt"));
applications.add(application);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return applications;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class SegmentH2UIDAO method load.
@Override
public TraceSegmentObject load(String segmentId) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SEGMENT_SQL, SegmentTable.COLUMN_DATA_BINARY, SegmentTable.TABLE, SegmentTable.COLUMN_ID);
Object[] params = new Object[] { segmentId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
byte[] dataBinary = rs.getBytes(SegmentTable.COLUMN_DATA_BINARY);
try {
return TraceSegmentObject.parseFrom(dataBinary);
} catch (InvalidProtocolBufferException e) {
logger.error(e.getMessage(), e);
}
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class ServiceMetricH2UIDAO method getServiceResponseTimeTrend.
@Override
public List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
H2Client client = getClient();
String dynamicSql = "select * from {0} where {1} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, tableName, ServiceMetricTable.COLUMN_ID);
List<Integer> trends = new LinkedList<>();
durationPoints.forEach(durationPoint -> {
String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
if (rs.next()) {
long calls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
long durationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
trends.add((int) (durationSum / calls));
} else {
trends.add(0);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
});
return trends;
}
use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.
the class ServiceNameServiceH2UIDAO method searchService.
@Override
public List<ServiceInfo> searchService(String keyword, int topN) {
String dynamicSql = "select {0},{1} from {2} where {3} like ? and {4} = ? limit ?";
String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.COLUMN_SRC_SPAN_TYPE);
Object[] params = new Object[] { keyword, SpanType.Entry_VALUE, topN };
List<ServiceInfo> serviceInfos = new LinkedList<>();
try (ResultSet rs = getClient().executeQuery(sql, params)) {
while (rs.next()) {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setId(rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID));
serviceInfo.setName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
serviceInfos.add(serviceInfo);
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return serviceInfos;
}
Aggregations