Search in sources :

Example 36 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException 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;
}
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)

Example 37 with H2ClientException

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

Example 38 with H2ClientException

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

the class ApplicationMappingH2UIDAO method load.

@Override
public List<ApplicationMapping> load(Step step, long startTimeBucket, long endTimeBucket) {
    String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, tableName, ApplicationMappingTable.COLUMN_TIME_BUCKET);
    List<ApplicationMapping> applicationMappings = new LinkedList<>();
    Object[] params = new Object[] { startTimeBucket, endTimeBucket };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID);
            int addressId = rs.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID);
            ApplicationMapping applicationMapping = new ApplicationMapping();
            applicationMapping.setApplicationId(applicationId);
            applicationMapping.setMappingApplicationId(addressId);
            applicationMappings.add(applicationMapping);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    logger.debug("node mapping data: {}", applicationMappings.toString());
    return applicationMappings;
}
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 39 with H2ClientException

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

the class GCMetricH2UIDAO method getGCTrend.

private List<Integer> getGCTrend(int instanceId, Step step, List<DurationPoint> durationPoints, int gcPhrase) {
    String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE);
    H2Client client = getClient();
    String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, tableName, GCMetricTable.COLUMN_ID);
    List<Integer> gcTrends = new LinkedList<>();
    durationPoints.forEach(durationPoint -> {
        String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase;
        try (ResultSet rs = client.executeQuery(sql, new String[] { id })) {
            if (rs.next()) {
                long count = rs.getLong(GCMetricTable.COLUMN_COUNT);
                long times = rs.getLong(GCMetricTable.COLUMN_TIMES);
                gcTrends.add((int) (count / times));
            } else {
                gcTrends.add(0);
            }
        } catch (SQLException | H2ClientException e) {
            logger.error(e.getMessage(), e);
        }
    });
    return gcTrends;
}
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 40 with H2ClientException

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

the class InstanceMetricH2UIDAO method getResponseTimeTrend.

@Override
public List<Integer> getResponseTimeTrend(int instanceId, Step step, List<DurationPoint> durationPoints) {
    H2Client client = getClient();
    String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE);
    String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID);
    List<Integer> responseTimeTrends = new LinkedList<>();
    durationPoints.forEach(durationPoint -> {
        String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue();
        try (ResultSet rs = client.executeQuery(sql, new Object[] { id })) {
            if (rs.next()) {
                long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS);
                long durationSum = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
                responseTimeTrends.add((int) (durationSum / callTimes));
            } else {
                responseTimeTrends.add(0);
            }
        } catch (SQLException | H2ClientException e) {
            logger.error(e.getMessage(), e);
        }
    });
    return responseTimeTrends;
}
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)

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