Search in sources :

Example 11 with H2ClientException

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) Instance(org.apache.skywalking.apm.collector.storage.table.register.Instance) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 12 with H2ClientException

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) Application(org.apache.skywalking.apm.collector.storage.ui.application.Application) LinkedList(java.util.LinkedList)

Example 13 with H2ClientException

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) TraceSegmentObject(org.apache.skywalking.apm.network.proto.TraceSegmentObject)

Example 14 with H2ClientException

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;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) LinkedList(java.util.LinkedList)

Example 15 with H2ClientException

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;
}
Also used : ServiceInfo(org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) LinkedList(java.util.LinkedList)

Aggregations

H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)45 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)39 SQLException (java.sql.SQLException)37 ResultSet (java.sql.ResultSet)36 LinkedList (java.util.LinkedList)11 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)3 StorageInstallException (org.apache.skywalking.apm.collector.storage.StorageInstallException)2 Instance (org.apache.skywalking.apm.collector.storage.table.register.Instance)2 JsonObject (com.google.gson.JsonObject)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 H2SqlEntity (org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity)1 H2StorageInstaller (org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 ServiceName (org.apache.skywalking.apm.collector.storage.table.register.ServiceName)1 Application (org.apache.skywalking.apm.collector.storage.ui.application.Application)1