Search in sources :

Example 41 with H2ClientException

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

the class ApplicationRegisterH2DAO method save.

@Override
public void save(Application application) {
    H2Client client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(ApplicationTable.COLUMN_ID, application.getId());
    source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
    source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId());
    source.put(ApplicationTable.COLUMN_ADDRESS_ID, application.getAddressId());
    source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
    String sql = SqlBuilder.buildBatchInsertSql(ApplicationTable.TABLE, source.keySet());
    Object[] params = source.values().toArray(new Object[0]);
    try {
        client.execute(sql, params);
    } catch (H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) HashMap(java.util.HashMap) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 42 with H2ClientException

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

the class NetworkAddressRegisterH2DAO method update.

@Override
public void update(String id, int spanLayer, int serverType) {
    H2Client client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayer);
    source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, serverType);
    String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, source.keySet(), InstanceTable.COLUMN_INSTANCE_ID);
    Object[] params = source.values().toArray(new Object[] { id });
    try {
        client.execute(sql, params);
    } catch (H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) HashMap(java.util.HashMap) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Example 43 with H2ClientException

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

the class ApplicationComponentH2UIDAO method load.

@Override
public List<ApplicationComponent> load(Step step, long startTimeBucket, long endTimeBucket) {
    H2Client client = getClient();
    String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE);
    List<ApplicationComponent> applicationComponents = new LinkedList<>();
    String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_APPLICATION_ID, tableName, ApplicationComponentTable.COLUMN_TIME_BUCKET);
    Object[] params = new Object[] { startTimeBucket, endTimeBucket };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        while (rs.next()) {
            int applicationId = rs.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID);
            int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID);
            ApplicationComponent applicationComponent = new ApplicationComponent();
            applicationComponent.setComponentId(componentId);
            applicationComponent.setApplicationId(applicationId);
            applicationComponents.add(applicationComponent);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return applicationComponents;
}
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 44 with H2ClientException

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

the class ServiceNameServiceH2UIDAO method getCount.

@Override
public int getCount() {
    String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?";
    String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SRC_SPAN_TYPE);
    Object[] params = new Object[] { SpanType.Entry_VALUE };
    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 45 with H2ClientException

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

the class MemoryPoolMetricH2UIDAO method getMetric.

@Override
public JsonObject getMetric(int instanceId, long timeBucket, int poolType) {
    H2Client client = getClient();
    String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType;
    String sql = SqlBuilder.buildSql(GET_MEMORY_POOL_METRIC_SQL, MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.COLUMN_ID);
    Object[] params = new Object[] { id };
    JsonObject metric = new JsonObject();
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            metric.addProperty("max", rs.getInt(MemoryPoolMetricTable.COLUMN_MAX));
            metric.addProperty("init", rs.getInt(MemoryPoolMetricTable.COLUMN_INIT));
            metric.addProperty("used", rs.getInt(MemoryPoolMetricTable.COLUMN_USED));
        } else {
            metric.addProperty("max", 0);
            metric.addProperty("init", 0);
            metric.addProperty("used", 0);
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return metric;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JsonObject(com.google.gson.JsonObject) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException) JsonObject(com.google.gson.JsonObject)

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