Search in sources :

Example 31 with H2Client

use of org.apache.skywalking.apm.collector.client.h2.H2Client 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 32 with H2Client

use of org.apache.skywalking.apm.collector.client.h2.H2Client 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 33 with H2Client

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

Example 34 with H2Client

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

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

Aggregations

H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)41 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)40 ResultSet (java.sql.ResultSet)32 SQLException (java.sql.SQLException)32 LinkedList (java.util.LinkedList)10 HashMap (java.util.HashMap)5 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 StandaloneModuleListenerService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleListenerService)1 StandaloneModuleRegisterService (org.apache.skywalking.apm.collector.cluster.standalone.service.StandaloneModuleRegisterService)1 StorageException (org.apache.skywalking.apm.collector.storage.StorageException)1 BatchH2DAO (org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO)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