Search in sources :

Example 31 with H2ClientException

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

the class NetworkAddressH2UIDAO method getNumOfSpanLayer.

@Override
public int getNumOfSpanLayer(int spanLayer) {
    String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?";
    String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.COLUMN_NETWORK_ADDRESS, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_SPAN_LAYER);
    Object[] params = new Object[] { spanLayer };
    try (ResultSet rs = getClient().executeQuery(sql, params)) {
        if (rs.next()) {
            return rs.getInt("cnt");
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return 0;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 32 with H2ClientException

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

the class ServiceMetricH2UIDAO method getServiceSLATrend.

@Override
public List<Integer> getServiceSLATrend(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 errorCalls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
                trends.add((int) (((calls - errorCalls) / calls)) * 10000);
            } else {
                trends.add(10000);
            }
        } 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 33 with H2ClientException

use of org.apache.skywalking.apm.collector.client.h2.H2ClientException 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;
}
Also used : BasicTrace(org.apache.skywalking.apm.collector.storage.ui.trace.BasicTrace) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) TraceBrief(org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief) H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 34 with H2ClientException

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

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