Search in sources :

Example 26 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class AbstractPersistenceH2DAO method get.

@Override
public final STREAM_DATA get(String id) {
    String sql = SqlBuilder.buildSql(GET_SQL, tableName(), CommonTable.COLUMN_ID);
    Object[] params = new Object[] { id };
    try (ResultSet resultSet = getClient().executeQuery(sql, params)) {
        if (resultSet.next()) {
            return h2DataToStreamData(resultSet);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 27 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class InstanceHeartBeatH2PersistenceDAO method get.

@Override
public Instance get(String id) {
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_INSTANCE_ID);
    Object[] params = new Object[] { id };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            Instance instance = new Instance();
            instance.setId(id);
            instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
            instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME));
            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 28 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class GlobalTraceH2UIDAO method getSegmentIds.

@Override
public List<String> getSegmentIds(String globalTraceId) {
    List<String> segmentIds = new ArrayList<>();
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_SEGMENT_IDS_SQL, GlobalTraceTable.COLUMN_SEGMENT_ID, GlobalTraceTable.TABLE, GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
    Object[] params = new Object[] { globalTraceId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            String segmentId = rs.getString(GlobalTraceTable.COLUMN_SEGMENT_ID);
            logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
            segmentIds.add(segmentId);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return segmentIds;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 29 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class InstanceH2UIDAO method buildAppServerInfo.

private List<AppServerInfo> buildAppServerInfo(String sql, Object[] params) {
    H2Client client = getClient();
    List<AppServerInfo> appServerInfos = new LinkedList<>();
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            AppServerInfo appServerInfo = new AppServerInfo();
            appServerInfo.setId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID));
            appServerInfo.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO));
            appServerInfos.add(appServerInfo);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return appServerInfos;
}
Also used : AppServerInfo(org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo) 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 30 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException in project incubator-skywalking by apache.

the class MemoryMetricH2UIDAO method getMemoryTrend.

private Trend getMemoryTrend(int instanceId, Step step, List<DurationPoint> durationPoints, boolean isHeap) {
    String tableName = TimePyramidTableNameBuilder.build(step, MemoryMetricTable.TABLE);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, tableName, MemoryMetricTable.COLUMN_ID);
    Trend trend = new Trend();
    durationPoints.forEach(durationPoint -> {
        String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + BooleanUtils.booleanToValue(isHeap);
        try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
            if (rs.next()) {
                long max = rs.getLong(MemoryMetricTable.COLUMN_MAX);
                long used = rs.getLong(MemoryMetricTable.COLUMN_USED);
                long times = rs.getLong(MemoryMetricTable.COLUMN_TIMES);
                trend.getMetrics().add((int) (used / times));
                if (max < 0) {
                    trend.getMaxMetrics().add((int) (used / times));
                } else {
                    trend.getMaxMetrics().add((int) (max / times));
                }
            } else {
                trend.getMetrics().add(0);
                trend.getMaxMetrics().add(0);
            }
        } catch (SQLException | H2ClientException e) {
            logger.error(e.getMessage(), e);
        }
    });
    return trend;
}
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)

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