提交 6279c8dd 编写于 作者: 林嘉琦 Lin Jiaqi 提交者: wu-sheng

support shardingjdbc database storage feature (#1347)

* support shardingjdbc database storage feature
上级 cab42447
......@@ -146,6 +146,11 @@
<artifactId>collector-storage-h2-provider</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>collector-storage-shardingjdbc-provider</artifactId>
<version>${project.version}</version>
</dependency>
<!-- storage provider -->
<!-- remote provider -->
<dependency>
......
......@@ -101,5 +101,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-core</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
</dependencies>
</project>
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.client.shardingjdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.skywalking.apm.collector.client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.shardingjdbc.core.api.ShardingDataSourceFactory;
import io.shardingjdbc.core.api.config.ShardingRuleConfiguration;
/**
* @author linjiaqi
*/
public class ShardingjdbcClient implements Client {
private final Logger logger = LoggerFactory.getLogger(ShardingjdbcClient.class);
private Map<String, ShardingjdbcClientConfig> shardingjdbcClientConfig;
private ShardingRuleConfiguration shardingRuleConfiguration;
private Map<String, DataSource> shardingDataSource = new HashMap<String, DataSource>();
private DataSource dataSource;
public ShardingjdbcClient(Map<String, ShardingjdbcClientConfig> shardingjdbcClientConfig, ShardingRuleConfiguration shardingRuleConfiguration) {
this.shardingjdbcClientConfig = shardingjdbcClientConfig;
this.shardingRuleConfiguration = shardingRuleConfiguration;
}
@Override public void initialize() throws ShardingjdbcClientException {
try {
shardingjdbcClientConfig.forEach((key, value) -> {
BasicDataSource basicDataSource = new BasicDataSource();
basicDataSource.setDriverClassName(value.getDriverClass());
basicDataSource.setUrl(value.getUrl());
basicDataSource.setUsername(value.getUserName());
basicDataSource.setPassword(value.getPassword());
shardingDataSource.put(key, basicDataSource);
logger.info("add sharding datasource: {}, url: {}", key, value.getUrl());
});
dataSource = ShardingDataSourceFactory.createDataSource(shardingDataSource, shardingRuleConfiguration,
new HashMap<String, Object>(), new Properties());
} catch (Exception e) {
logger.error("case the exception is 'Cannot load JDBC driver class', please add the driver mysql-connector-java-5.1.36.jar to collector-libs manual");
throw new ShardingjdbcClientException(e.getMessage(), e);
}
}
@Override public void shutdown() {
}
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
public void execute(String sql) throws ShardingjdbcClientException {
Connection conn = null;
Statement statement = null;
try {
conn = getConnection();
statement = conn.createStatement();
statement.execute(sql);
} catch (SQLException e) {
throw new ShardingjdbcClientException(e.getMessage(), e);
} finally {
try {
if (statement != null) {
statement.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
throw new ShardingjdbcClientException(e.getMessage(), e);
}
}
}
public ResultSet executeQuery(String sql, Object[] params) throws ShardingjdbcClientException {
logger.debug("execute query with result: {}", sql);
ResultSet rs;
PreparedStatement statement;
try {
statement = getConnection().prepareStatement(sql);
if (params != null) {
for (int i = 0; i < params.length; i++) {
statement.setObject(i + 1, params[i]);
}
}
rs = statement.executeQuery();
} catch (SQLException e) {
throw new ShardingjdbcClientException(e.getMessage(), e);
}
return rs;
}
public boolean execute(String sql, Object[] params) throws ShardingjdbcClientException {
logger.debug("execute insert/update/delete: {}", sql);
boolean flag;
Connection conn = null;
PreparedStatement statement = null;
try {
conn = getConnection();
conn.setAutoCommit(true);
statement = conn.prepareStatement(sql);
if (params != null) {
for (int i = 0; i < params.length; i++) {
statement.setObject(i + 1, params[i]);
}
}
flag = statement.execute();
} catch (SQLException e) {
throw new ShardingjdbcClientException(e.getMessage(), e);
} finally {
try {
if (statement != null) {
statement.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
throw new ShardingjdbcClientException(e.getMessage(), e);
}
}
return flag;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.client.shardingjdbc;
import org.apache.skywalking.apm.collector.core.module.ModuleConfig;
/**
* @author linjiaqi
*/
public class ShardingjdbcClientConfig extends ModuleConfig {
private String driverClass;
private String url;
private String userName;
private String password;
public ShardingjdbcClientConfig() {
}
public ShardingjdbcClientConfig(String driverClass, String url, String username, String password) {
this.driverClass = driverClass;
this.url = url;
this.userName = username;
this.password = password;
}
public String getDriverClass() {
return driverClass;
}
public void setDriverClass(String driverClass) {
this.driverClass = driverClass;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.client.shardingjdbc;
import org.apache.skywalking.apm.collector.client.ClientException;
/**
* @author linjiaqi
*/
public class ShardingjdbcClientException extends ClientException {
public ShardingjdbcClientException(String message) {
super(message);
}
public ShardingjdbcClientException(String message, Throwable cause) {
super(message, cause);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-collector-storage</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>5.0.0-beta2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>collector-storage-shardingjdbc-provider</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>collector-storage-define</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import org.apache.skywalking.apm.collector.storage.table.Metric;
import org.apache.skywalking.apm.collector.storage.table.MetricColumns;
/**
* @author linjiaqi
*/
public enum MetricTransformUtil {
INSTANCE;
public void shardingjdbcDataToStreamData(ResultSet source, Metric target) throws SQLException {
target.setSourceValue(source.getInt(MetricColumns.SOURCE_VALUE.getName()));
target.setTimeBucket(source.getLong(MetricColumns.TIME_BUCKET.getName()));
target.setTransactionCalls(source.getLong(MetricColumns.TRANSACTION_CALLS.getName()));
target.setTransactionErrorCalls(source.getLong(MetricColumns.TRANSACTION_ERROR_CALLS.getName()));
target.setTransactionDurationSum(source.getLong(MetricColumns.TRANSACTION_DURATION_SUM.getName()));
target.setTransactionErrorDurationSum(source.getLong(MetricColumns.TRANSACTION_ERROR_DURATION_SUM.getName()));
target.setTransactionAverageDuration(source.getLong(MetricColumns.TRANSACTION_AVERAGE_DURATION.getName()));
target.setBusinessTransactionCalls(source.getLong(MetricColumns.BUSINESS_TRANSACTION_CALLS.getName()));
target.setBusinessTransactionErrorCalls(source.getLong(MetricColumns.BUSINESS_TRANSACTION_ERROR_CALLS.getName()));
target.setBusinessTransactionDurationSum(source.getLong(MetricColumns.BUSINESS_TRANSACTION_DURATION_SUM.getName()));
target.setBusinessTransactionErrorDurationSum(source.getLong(MetricColumns.BUSINESS_TRANSACTION_ERROR_DURATION_SUM.getName()));
target.setBusinessTransactionAverageDuration(source.getLong(MetricColumns.BUSINESS_TRANSACTION_AVERAGE_DURATION.getName()));
target.setMqTransactionCalls(source.getLong(MetricColumns.MQ_TRANSACTION_CALLS.getName()));
target.setMqTransactionErrorCalls(source.getLong(MetricColumns.MQ_TRANSACTION_ERROR_CALLS.getName()));
target.setMqTransactionDurationSum(source.getLong(MetricColumns.MQ_TRANSACTION_DURATION_SUM.getName()));
target.setMqTransactionErrorDurationSum(source.getLong(MetricColumns.MQ_TRANSACTION_ERROR_DURATION_SUM.getName()));
target.setMqTransactionAverageDuration(source.getLong(MetricColumns.MQ_TRANSACTION_AVERAGE_DURATION.getName()));
}
public void streamDataToShardingjdbcData(Metric source, Map<String, Object> target) {
target.put(MetricColumns.SOURCE_VALUE.getName(), source.getSourceValue());
target.put(MetricColumns.TIME_BUCKET.getName(), source.getTimeBucket());
target.put(MetricColumns.TRANSACTION_CALLS.getName(), source.getTransactionCalls());
target.put(MetricColumns.TRANSACTION_ERROR_CALLS.getName(), source.getTransactionErrorCalls());
target.put(MetricColumns.TRANSACTION_DURATION_SUM.getName(), source.getTransactionDurationSum());
target.put(MetricColumns.TRANSACTION_ERROR_DURATION_SUM.getName(), source.getTransactionErrorDurationSum());
target.put(MetricColumns.TRANSACTION_AVERAGE_DURATION.getName(), source.getTransactionAverageDuration());
target.put(MetricColumns.BUSINESS_TRANSACTION_CALLS.getName(), source.getBusinessTransactionCalls());
target.put(MetricColumns.BUSINESS_TRANSACTION_ERROR_CALLS.getName(), source.getBusinessTransactionErrorCalls());
target.put(MetricColumns.BUSINESS_TRANSACTION_DURATION_SUM.getName(), source.getBusinessTransactionDurationSum());
target.put(MetricColumns.BUSINESS_TRANSACTION_ERROR_DURATION_SUM.getName(), source.getBusinessTransactionErrorDurationSum());
target.put(MetricColumns.BUSINESS_TRANSACTION_AVERAGE_DURATION.getName(), source.getBusinessTransactionAverageDuration());
target.put(MetricColumns.MQ_TRANSACTION_CALLS.getName(), source.getMqTransactionCalls());
target.put(MetricColumns.MQ_TRANSACTION_ERROR_CALLS.getName(), source.getMqTransactionErrorCalls());
target.put(MetricColumns.MQ_TRANSACTION_DURATION_SUM.getName(), source.getMqTransactionDurationSum());
target.put(MetricColumns.MQ_TRANSACTION_ERROR_DURATION_SUM.getName(), source.getMqTransactionErrorDurationSum());
target.put(MetricColumns.MQ_TRANSACTION_AVERAGE_DURATION.getName(), source.getMqTransactionAverageDuration());
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientConfig;
/**
* @author linjiaqi
*/
class StorageModuleShardingjdbcConfig extends ShardingjdbcClientConfig {
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.core.data.CommonTable;
import org.apache.skywalking.apm.collector.core.data.StreamData;
import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public abstract class AbstractPersistenceShardingjdbcDAO<STREAM_DATA extends StreamData> extends ShardingjdbcDAO implements IPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, STREAM_DATA> {
private static final Logger logger = LoggerFactory.getLogger(AbstractPersistenceShardingjdbcDAO.class);
public AbstractPersistenceShardingjdbcDAO(ShardingjdbcClient client) {
super(client);
}
private static final String GET_SQL = "select * from {0} where {1} = ?";
protected abstract STREAM_DATA shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException;
protected abstract String tableName();
@Override public STREAM_DATA get(String id) {
String sql = SqlBuilder.buildSql(GET_SQL, tableName(), CommonTable.ID.getName());
Object[] params = new Object[] {id};
try (
ResultSet rs = getClient().executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return shardingjdbcDataToStreamData(rs);
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
protected abstract Map<String, Object> streamDataToShardingjdbcData(STREAM_DATA streamData);
@Override public final ShardingjdbcSqlEntity prepareBatchInsert(STREAM_DATA streamData) {
Map<String, Object> source = streamDataToShardingjdbcData(streamData);
source.put(CommonTable.ID.getName(), streamData.getId());
ShardingjdbcSqlEntity entity = new ShardingjdbcSqlEntity();
String sql = SqlBuilder.buildBatchInsertSql(tableName(), source.keySet());
entity.setSql(sql);
entity.setParams(source.values().toArray(new Object[0]));
return entity;
}
@Override public final ShardingjdbcSqlEntity prepareBatchUpdate(STREAM_DATA streamData) {
Map<String, Object> source = streamDataToShardingjdbcData(streamData);
ShardingjdbcSqlEntity entity = new ShardingjdbcSqlEntity();
String sql = SqlBuilder.buildBatchUpdateSql(tableName(), source.keySet(), CommonTable.ID.getName());
entity.setSql(sql);
List<Object> values = new ArrayList<>(source.values());
values.add(streamData.getId());
entity.setParams(values.toArray(new Object[0]));
return entity;
}
protected abstract String timeBucketColumnNameForDelete();
@Override public void deleteHistory(Long timeBucketBefore) {
ShardingjdbcClient client = getClient();
String dynamicSql = "delete from {0} where {1} <= ?";
String sql = SqlBuilder.buildSql(dynamicSql, tableName(), timeBucketColumnNameForDelete());
Object[] params = new Object[] {timeBucketBefore};
try {
client.execute(sql, params);
logger.info("Deleted history rows from {} table.", tableName());
} catch (ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class BatchShardingjdbcDAO extends ShardingjdbcDAO implements IBatchDAO {
private static final Logger logger = LoggerFactory.getLogger(BatchShardingjdbcDAO.class);
public BatchShardingjdbcDAO(ShardingjdbcClient client) {
super(client);
}
@Override
public void batchPersistence(List<?> batchCollection) {
if (batchCollection != null && batchCollection.size() > 0) {
logger.debug("the batch collection size is {}", batchCollection.size());
Connection conn;
final Map<String, PreparedStatement> batchSqls = new HashMap<>();
try {
conn = getClient().getConnection();
conn.setAutoCommit(true);
PreparedStatement ps;
for (Object entity : batchCollection) {
ShardingjdbcSqlEntity e = getShardingjdbcSqlEntity(entity);
String sql = e.getSql();
if (batchSqls.containsKey(sql)) {
ps = batchSqls.get(sql);
} else {
ps = conn.prepareStatement(sql);
batchSqls.put(sql, ps);
}
Object[] params = e.getParams();
if (params != null) {
logger.debug("the sql is {}, params size is {}, params: {}", e.getSql(), params.length, params);
for (int i = 0; i < params.length; i++) {
ps.setObject(i + 1, params[i]);
}
}
ps.addBatch();
}
for (String k : batchSqls.keySet()) {
batchSqls.get(k).executeBatch();
}
} catch (SQLException e) {
logger.error(e.getMessage(), e);
}
batchSqls.clear();
}
}
private ShardingjdbcSqlEntity getShardingjdbcSqlEntity(Object entity) {
if (entity instanceof ShardingjdbcSqlEntity) {
return (ShardingjdbcSqlEntity)entity;
}
return null;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.storage.base.dao.AbstractDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public abstract class ShardingjdbcDAO extends AbstractDAO<ShardingjdbcClient> {
private static final Logger logger = LoggerFactory.getLogger(ShardingjdbcDAO.class);
public ShardingjdbcDAO(ShardingjdbcClient client) {
super(client);
}
protected final int getMaxId(String tableName, String columnName) {
String sql = "select max(" + columnName + ") from " + tableName;
return getIntValueBySQL(sql);
}
protected final int getMinId(String tableName, String columnName) {
String sql = "select min(" + columnName + ") from " + tableName;
return getIntValueBySQL(sql);
}
private int getIntValueBySQL(String sql) {
ShardingjdbcClient client = getClient();
try (
ResultSet rs = client.executeQuery(sql, null);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
int id = rs.getInt(1);
if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) {
return 0;
} else {
return id;
}
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define;
import org.apache.skywalking.apm.collector.core.data.ColumnDefine;
import org.apache.skywalking.apm.collector.core.data.ColumnName;
/**
* @author linjiaqi
*/
public class ShardingjdbcColumnDefine extends ColumnDefine {
public ShardingjdbcColumnDefine(ColumnName columnName, String type) {
super(columnName, type);
}
public enum Type {
Varchar, Int, Bigint, BINARY, Double, BLOB
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define;
/**
* @author linjiaqi
*/
public class ShardingjdbcSqlEntity {
private String sql;
private Object[] params;
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public Object[] getParams() {
return params;
}
public void setParams(Object[] params) {
this.params = params;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define;
import java.util.List;
import org.apache.skywalking.apm.collector.client.Client;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.core.data.TableDefine;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.StorageException;
import org.apache.skywalking.apm.collector.storage.StorageInstallException;
import org.apache.skywalking.apm.collector.storage.StorageInstaller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class ShardingjdbcStorageInstaller extends StorageInstaller {
private final Logger logger = LoggerFactory.getLogger(ShardingjdbcStorageInstaller.class);
public ShardingjdbcStorageInstaller(boolean isHighPerformanceMode) {
super(isHighPerformanceMode);
}
@Override protected void defineFilter(List<TableDefine> tableDefines) {
int size = tableDefines.size();
for (int i = size - 1; i >= 0; i--) {
if (!(tableDefines.get(i) instanceof ShardingjdbcTableDefine)) {
tableDefines.remove(i);
}
}
}
@Override protected boolean isExists(Client client, TableDefine tableDefine) throws StorageException {
logger.info("check if table {} exist ", tableDefine.getName());
return false;
}
@Override protected void columnCheck(Client client, TableDefine tableDefine) throws StorageException {
}
@Override protected void deleteTable(Client client, TableDefine tableDefine) throws StorageException {
ShardingjdbcClient shardingjdbcClient = (ShardingjdbcClient)client;
try {
shardingjdbcClient.execute("DROP TABLE IF EXISTS " + tableDefine.getName());
} catch (ShardingjdbcClientException e) {
throw new StorageInstallException(e.getMessage(), e);
}
}
@Override protected void createTable(Client client, TableDefine tableDefine) throws StorageException {
ShardingjdbcClient shardingjdbcClient = (ShardingjdbcClient)client;
ShardingjdbcTableDefine shardingjdbcTableDefine = (ShardingjdbcTableDefine)tableDefine;
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("CREATE TABLE IF NOT EXISTS ").append(shardingjdbcTableDefine.getName()).append(" (");
shardingjdbcTableDefine.getColumnDefines().forEach(columnDefine -> {
ShardingjdbcColumnDefine shardingjdbcColumnDefine = (ShardingjdbcColumnDefine)columnDefine;
if (shardingjdbcColumnDefine.getType().equals(ShardingjdbcColumnDefine.Type.Varchar.name())) {
sqlBuilder.append(shardingjdbcColumnDefine.getColumnName().getName()).append(" ").append(shardingjdbcColumnDefine.getType()).append("(255),");
} else {
sqlBuilder.append(shardingjdbcColumnDefine.getColumnName().getName()).append(" ").append(shardingjdbcColumnDefine.getType()).append(",");
}
});
sqlBuilder.append(" PRIMARY KEY (id)");
if (shardingjdbcTableDefine.getIndex() != null) {
sqlBuilder.append(", KEY " + shardingjdbcTableDefine.getName() + Const.ID_SPLIT + shardingjdbcTableDefine.getIndex() + " (" + shardingjdbcTableDefine.getIndex() + ")");
}
sqlBuilder.append(")");
try {
logger.info("create if not exists shardingjdbc table with sql {}", sqlBuilder);
shardingjdbcClient.execute(sqlBuilder.toString());
} catch (ShardingjdbcClientException e) {
throw new StorageInstallException(e.getMessage(), e);
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define;
import org.apache.skywalking.apm.collector.core.data.TableDefine;
/**
* @author linjiaqi
*/
public abstract class ShardingjdbcTableDefine extends TableDefine {
private final String index;
public ShardingjdbcTableDefine(String name, String index) {
super(name);
this.index = index;
}
public String getIndex() {
return index;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.global.GlobalTrace;
import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable;
/**
* @author linjiaqi
*/
public class GlobalTraceShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<GlobalTrace> implements IGlobalTracePersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, GlobalTrace> {
public GlobalTraceShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return GlobalTraceTable.TABLE;
}
@Override protected GlobalTrace shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
GlobalTrace globalTrace = new GlobalTrace();
globalTrace.setSegmentId(resultSet.getString(GlobalTraceTable.SEGMENT_ID.getName()));
globalTrace.setTraceId(resultSet.getString(GlobalTraceTable.TRACE_ID.getName()));
globalTrace.setTimeBucket(resultSet.getLong(GlobalTraceTable.TIME_BUCKET.getName()));
return globalTrace;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(GlobalTrace streamData) {
Map<String, Object> target = new HashMap<>();
target.put(GlobalTraceTable.SEGMENT_ID.getName(), streamData.getSegmentId());
target.put(GlobalTraceTable.TRACE_ID.getName(), streamData.getTraceId());
target.put(GlobalTraceTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return GlobalTraceTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + GlobalTraceTable.TABLE)
@Override public GlobalTrace get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.shardingjdbc.*;
import org.apache.skywalking.apm.collector.core.UnexpectedException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.register.*;
import org.slf4j.*;
/**
* @author linjiaqi
*/
public class InstanceHeartBeatShardingjdbcPersistenceDAO extends ShardingjdbcDAO implements IInstanceHeartBeatPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, Instance> {
private static final Logger logger = LoggerFactory.getLogger(InstanceHeartBeatShardingjdbcPersistenceDAO.class);
public InstanceHeartBeatShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
private static final String GET_INSTANCE_HEARTBEAT_SQL = "select * from {0} where {1} = ?";
@Override public Instance get(String id) {
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_HEARTBEAT_SQL, InstanceTable.TABLE, InstanceTable.INSTANCE_ID.getName());
Object[] params = new Object[] {id};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
Instance instance = new Instance();
instance.setId(id);
instance.setInstanceId(rs.getInt(InstanceTable.INSTANCE_ID.getName()));
instance.setHeartBeatTime(rs.getLong(InstanceTable.HEARTBEAT_TIME.getName()));
return instance;
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override public ShardingjdbcSqlEntity prepareBatchInsert(Instance data) {
throw new UnexpectedException("There is no need to merge stream data with database data.");
}
@Override public ShardingjdbcSqlEntity prepareBatchUpdate(Instance data) {
ShardingjdbcSqlEntity entity = new ShardingjdbcSqlEntity();
Map<String, Object> target = new HashMap<>();
target.put(InstanceTable.HEARTBEAT_TIME.getName(), data.getHeartBeatTime());
String sql = SqlBuilder.buildBatchUpdateSql(InstanceTable.TABLE, target.keySet(), InstanceTable.INSTANCE_ID.getName());
entity.setSql(sql);
List<Object> params = new ArrayList<>(target.values());
params.add(data.getId());
entity.setParams(params.toArray(new Object[0]));
return entity;
}
@Override public void deleteHistory(Long timeBucketBefore) {
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao;
import java.util.*;
import org.apache.skywalking.apm.collector.client.shardingjdbc.*;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.segment.*;
import org.slf4j.*;
/**
* @author linjiaqi
*/
public class SegmentDurationShardingjdbcPersistenceDAO extends ShardingjdbcDAO implements ISegmentDurationPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, SegmentDuration> {
private static final Logger logger = LoggerFactory.getLogger(SegmentDurationShardingjdbcPersistenceDAO.class);
public SegmentDurationShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override public SegmentDuration get(String id) {
return null;
}
@Override public ShardingjdbcSqlEntity prepareBatchInsert(SegmentDuration data) {
logger.debug("segment cost prepareBatchInsert, getApplicationId: {}", data.getId());
ShardingjdbcSqlEntity entity = new ShardingjdbcSqlEntity();
Map<String, Object> target = new HashMap<>();
target.put(SegmentDurationTable.ID.getName(), data.getId());
target.put(SegmentDurationTable.SEGMENT_ID.getName(), data.getSegmentId());
target.put(SegmentDurationTable.APPLICATION_ID.getName(), data.getApplicationId());
target.put(SegmentDurationTable.SERVICE_NAME.getName(), data.getServiceName());
target.put(SegmentDurationTable.DURATION.getName(), data.getDuration());
target.put(SegmentDurationTable.START_TIME.getName(), data.getStartTime());
target.put(SegmentDurationTable.END_TIME.getName(), data.getEndTime());
target.put(SegmentDurationTable.IS_ERROR.getName(), data.getIsError());
target.put(SegmentDurationTable.TIME_BUCKET.getName(), data.getTimeBucket());
logger.debug("segment cost source: {}", target.toString());
String sql = SqlBuilder.buildBatchInsertSql(SegmentDurationTable.TABLE, target.keySet());
entity.setSql(sql);
entity.setParams(target.values().toArray(new Object[0]));
return entity;
}
@Override public ShardingjdbcSqlEntity prepareBatchUpdate(SegmentDuration data) {
return null;
}
@Override public void deleteHistory(Long timeBucketBefore) {
ShardingjdbcClient client = getClient();
String dynamicSql = "delete from {0} where {1} <= ?";
String sql = SqlBuilder.buildSql(dynamicSql, SegmentDurationTable.TABLE, SegmentDurationTable.TIME_BUCKET.getName());
Object[] params = new Object[] {timeBucketBefore};
try {
client.execute(sql, params);
logger.info("Deleted history rows from {} table.", SegmentDurationTable.TABLE);
} catch (ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.segment.Segment;
import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable;
/**
* @author linjiaqi
*/
public class SegmentShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<Segment> implements ISegmentPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, Segment> {
public SegmentShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return SegmentTable.TABLE;
}
@Override protected Segment shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
Segment segment = new Segment();
segment.setDataBinary(Base64.getDecoder().decode(resultSet.getString(SegmentTable.DATA_BINARY.getName())));
segment.setTimeBucket(resultSet.getLong(SegmentTable.TIME_BUCKET.getName()));
return segment;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(Segment streamData) {
Map<String, Object> target = new HashMap<>();
target.put(SegmentTable.DATA_BINARY.getName(), new String(Base64.getEncoder().encode(streamData.getDataBinary())));
target.put(SegmentTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return SegmentTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + SegmentTable.TABLE)
@Override public Segment get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.core.UnexpectedException;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.IServiceNameHeartBeatPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class ServiceNameHeartBeatShardingjdbcPersistenceDAO extends ShardingjdbcDAO implements IServiceNameHeartBeatPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ServiceName> {
private static final Logger logger = LoggerFactory.getLogger(ServiceNameHeartBeatShardingjdbcPersistenceDAO.class);
public ServiceNameHeartBeatShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
private static final String GET_SERVICENAME_HEARTBEAT_SQL = "select * from {0} where {1} = ?";
@GraphComputingMetric(name = "/persistence/get/" + ServiceNameTable.TABLE + "/heartbeat")
@Override public ServiceName get(String id) {
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICENAME_HEARTBEAT_SQL, ServiceNameTable.TABLE, ServiceNameTable.SERVICE_ID.getName());
Object[] params = new Object[] {id};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
ServiceName serviceName = new ServiceName();
serviceName.setId(id);
serviceName.setServiceId(rs.getInt(ServiceNameTable.SERVICE_ID.getName()));
serviceName.setHeartBeatTime(rs.getLong(ServiceNameTable.HEARTBEAT_TIME.getName()));
return serviceName;
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override public ShardingjdbcSqlEntity prepareBatchInsert(ServiceName data) {
throw new UnexpectedException("Received an service name heart beat message under service id= " + data.getId() + " , which doesn't exist.");
}
@Override public ShardingjdbcSqlEntity prepareBatchUpdate(ServiceName data) {
ShardingjdbcSqlEntity entity = new ShardingjdbcSqlEntity();
Map<String, Object> target = new HashMap<>();
target.put(ServiceNameTable.HEARTBEAT_TIME.getName(), data.getHeartBeatTime());
String sql = SqlBuilder.buildBatchUpdateSql(ServiceNameTable.TABLE, target.keySet(), ServiceNameTable.SERVICE_ID.getName());
entity.setSql(sql);
List<Object> params = new ArrayList<>(target.values());
params.add(data.getId());
entity.setParams(params.toArray(new Object[0]));
return entity;
}
@Override public void deleteHistory(Long timeBucketBefore) {
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.acp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
/**
* @author linjiaqi
*/
public abstract class AbstractApplicationComponentShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationComponent> {
AbstractApplicationComponentShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return ApplicationComponentTable.TIME_BUCKET.getName();
}
@Override protected final ApplicationComponent shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationComponent applicationComponent = new ApplicationComponent();
applicationComponent.setId(resultSet.getString(ApplicationComponentTable.ID.getName()));
applicationComponent.setMetricId(resultSet.getString(ApplicationComponentTable.METRIC_ID.getName()));
applicationComponent.setComponentId(resultSet.getInt(ApplicationComponentTable.COMPONENT_ID.getName()));
applicationComponent.setApplicationId(resultSet.getInt(ApplicationComponentTable.APPLICATION_ID.getName()));
applicationComponent.setTimeBucket(resultSet.getLong(ApplicationComponentTable.TIME_BUCKET.getName()));
return applicationComponent;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(ApplicationComponent streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationComponentTable.ID.getName(), streamData.getId());
target.put(ApplicationComponentTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(ApplicationComponentTable.COMPONENT_ID.getName(), streamData.getComponentId());
target.put(ApplicationComponentTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ApplicationComponentTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationComponentTable.TABLE)
@Override public final ApplicationComponent get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.acp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
/**
* @author linjiaqi
*/
public class ApplicationComponentDayShardingjdbcPersistenceDAO extends AbstractApplicationComponentShardingjdbcPersistenceDAO implements IApplicationComponentDayPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationComponent> {
public ApplicationComponentDayShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationComponentTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.acp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
/**
* @author linjiaqi
*/
public class ApplicationComponentHourShardingjdbcPersistenceDAO extends AbstractApplicationComponentShardingjdbcPersistenceDAO implements IApplicationComponentHourPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationComponent> {
public ApplicationComponentHourShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationComponentTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.acp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMinutePersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
/**
* @author linjiaqi
*/
public class ApplicationComponentMinuteShardingjdbcPersistenceDAO extends AbstractApplicationComponentShardingjdbcPersistenceDAO implements IApplicationComponentMinutePersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationComponent> {
public ApplicationComponentMinuteShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationComponentTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.acp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMonthPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponent;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable;
/**
* @author linjiaqi
*/
public class ApplicationComponentMonthShardingjdbcPersistenceDAO extends AbstractApplicationComponentShardingjdbcPersistenceDAO implements IApplicationComponentMonthPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationComponent> {
public ApplicationComponentMonthShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationComponentTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
/**
* @author linjiaqi
*/
public abstract class AbstractApplicationAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationAlarmList> {
AbstractApplicationAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return ApplicationAlarmListTable.TIME_BUCKET.getName();
}
@Override protected final ApplicationAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationAlarmList applicationAlarmList = new ApplicationAlarmList();
applicationAlarmList.setId(resultSet.getString(ApplicationAlarmListTable.ID.getName()));
applicationAlarmList.setMetricId(resultSet.getString(ApplicationAlarmListTable.METRIC_ID.getName()));
applicationAlarmList.setSourceValue(resultSet.getInt(ApplicationAlarmListTable.SOURCE_VALUE.getName()));
applicationAlarmList.setAlarmType(resultSet.getInt(ApplicationAlarmListTable.ALARM_TYPE.getName()));
applicationAlarmList.setApplicationId(resultSet.getInt(ApplicationAlarmListTable.APPLICATION_ID.getName()));
applicationAlarmList.setTimeBucket(resultSet.getLong(ApplicationAlarmListTable.TIME_BUCKET.getName()));
applicationAlarmList.setAlarmContent(resultSet.getString(ApplicationAlarmListTable.ALARM_CONTENT.getName()));
return applicationAlarmList;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(ApplicationAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationAlarmListTable.ID.getName(), streamData.getId());
target.put(ApplicationAlarmListTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(ApplicationAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ApplicationAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ApplicationAlarmListTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ApplicationAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(ApplicationAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationAlarmListTable.TABLE)
@Override public final ApplicationAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationAlarmListDayPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
/**
* @author linjiaqi
*/
public class ApplicationAlarmListShardingjdbcDayPersistenceDAO extends AbstractApplicationAlarmListShardingjdbcPersistenceDAO implements IApplicationAlarmListDayPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationAlarmList> {
public ApplicationAlarmListShardingjdbcDayPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationAlarmListTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationAlarmListHourPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
/**
* @author linjiaqi
*/
public class ApplicationAlarmListShardingjdbcHourPersistenceDAO extends AbstractApplicationAlarmListShardingjdbcPersistenceDAO implements IApplicationAlarmListHourPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationAlarmList> {
public ApplicationAlarmListShardingjdbcHourPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationAlarmListTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationAlarmListMinutePersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
/**
* @author linjiaqi
*/
public class ApplicationAlarmListShardingjdbcMinutePersistenceDAO extends AbstractApplicationAlarmListShardingjdbcPersistenceDAO implements IApplicationAlarmListMinutePersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationAlarmList> {
public ApplicationAlarmListShardingjdbcMinutePersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationAlarmListTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationAlarmListMonthPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmListTable;
/**
* @author linjiaqi
*/
public class ApplicationAlarmListShardingjdbcMonthPersistenceDAO extends AbstractApplicationAlarmListShardingjdbcPersistenceDAO implements IApplicationAlarmListMonthPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationAlarmList> {
public ApplicationAlarmListShardingjdbcMonthPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationAlarmListTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationAlarmTable;
/**
* @author linjiaqi
*/
public class ApplicationAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationAlarm> implements IApplicationAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationAlarm> {
public ApplicationAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationAlarmTable.TABLE;
}
@Override protected ApplicationAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationAlarm applicationAlarm = new ApplicationAlarm();
applicationAlarm.setId(resultSet.getString(ApplicationAlarmTable.ID.getName()));
applicationAlarm.setSourceValue(resultSet.getInt(ApplicationAlarmTable.SOURCE_VALUE.getName()));
applicationAlarm.setAlarmType(resultSet.getInt(ApplicationAlarmTable.ALARM_TYPE.getName()));
applicationAlarm.setApplicationId(resultSet.getInt(ApplicationAlarmTable.APPLICATION_ID.getName()));
applicationAlarm.setLastTimeBucket(resultSet.getLong(ApplicationAlarmTable.LAST_TIME_BUCKET.getName()));
applicationAlarm.setAlarmContent(resultSet.getString(ApplicationAlarmTable.ALARM_CONTENT.getName()));
return applicationAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ApplicationAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationAlarmTable.ID.getName(), streamData.getId());
target.put(ApplicationAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ApplicationAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ApplicationAlarmTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ApplicationAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(ApplicationAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ApplicationAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationAlarmTable.TABLE)
@Override public ApplicationAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationReferenceAlarmListPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationReferenceAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationReferenceAlarmListTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationReferenceAlarmList> implements IApplicationReferenceAlarmListPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceAlarmList> {
public ApplicationReferenceAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceAlarmListTable.TABLE;
}
@Override protected ApplicationReferenceAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationReferenceAlarmList applicationReferenceAlarmList = new ApplicationReferenceAlarmList();
applicationReferenceAlarmList.setId(resultSet.getString(ApplicationReferenceAlarmListTable.ID.getName()));
applicationReferenceAlarmList.setSourceValue(resultSet.getInt(ApplicationReferenceAlarmListTable.SOURCE_VALUE.getName()));
applicationReferenceAlarmList.setAlarmType(resultSet.getInt(ApplicationReferenceAlarmListTable.ALARM_TYPE.getName()));
applicationReferenceAlarmList.setFrontApplicationId(resultSet.getInt(ApplicationReferenceAlarmListTable.FRONT_APPLICATION_ID.getName()));
applicationReferenceAlarmList.setBehindApplicationId(resultSet.getInt(ApplicationReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName()));
applicationReferenceAlarmList.setTimeBucket(resultSet.getLong(ApplicationReferenceAlarmListTable.TIME_BUCKET.getName()));
applicationReferenceAlarmList.setAlarmContent(resultSet.getString(ApplicationReferenceAlarmListTable.ALARM_CONTENT.getName()));
return applicationReferenceAlarmList;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ApplicationReferenceAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationReferenceAlarmListTable.ID.getName(), streamData.getId());
target.put(ApplicationReferenceAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ApplicationReferenceAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ApplicationReferenceAlarmListTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ApplicationReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(ApplicationReferenceAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(ApplicationReferenceAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ApplicationReferenceAlarmListTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationReferenceAlarmListTable.TABLE)
@Override public ApplicationReferenceAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IApplicationReferenceAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationReferenceAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.ApplicationReferenceAlarmTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationReferenceAlarm> implements IApplicationReferenceAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceAlarm> {
public ApplicationReferenceAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceAlarmTable.TABLE;
}
@Override protected ApplicationReferenceAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationReferenceAlarm applicationReferenceAlarm = new ApplicationReferenceAlarm();
applicationReferenceAlarm.setId(resultSet.getString(ApplicationReferenceAlarmTable.ID.getName()));
applicationReferenceAlarm.setSourceValue(resultSet.getInt(ApplicationReferenceAlarmTable.SOURCE_VALUE.getName()));
applicationReferenceAlarm.setAlarmType(resultSet.getInt(ApplicationReferenceAlarmTable.ALARM_TYPE.getName()));
applicationReferenceAlarm.setFrontApplicationId(resultSet.getInt(ApplicationReferenceAlarmTable.FRONT_APPLICATION_ID.getName()));
applicationReferenceAlarm.setBehindApplicationId(resultSet.getInt(ApplicationReferenceAlarmTable.BEHIND_APPLICATION_ID.getName()));
applicationReferenceAlarm.setLastTimeBucket(resultSet.getLong(ApplicationReferenceAlarmTable.LAST_TIME_BUCKET.getName()));
applicationReferenceAlarm.setAlarmContent(resultSet.getString(ApplicationReferenceAlarmTable.ALARM_CONTENT.getName()));
return applicationReferenceAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ApplicationReferenceAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationReferenceAlarmTable.ID.getName(), streamData.getId());
target.put(ApplicationReferenceAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ApplicationReferenceAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ApplicationReferenceAlarmTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ApplicationReferenceAlarmTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(ApplicationReferenceAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(ApplicationReferenceAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ApplicationReferenceAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationReferenceAlarmTable.TABLE)
@Override public final ApplicationReferenceAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IInstanceAlarmListPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceAlarmListTable;
/**
* @author linjiaqi
*/
public class InstanceAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<InstanceAlarmList> implements IInstanceAlarmListPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, InstanceAlarmList> {
public InstanceAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return InstanceAlarmListTable.TABLE;
}
@Override protected InstanceAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
InstanceAlarmList instanceAlarmList = new InstanceAlarmList();
instanceAlarmList.setId(resultSet.getString(InstanceAlarmListTable.ID.getName()));
instanceAlarmList.setSourceValue(resultSet.getInt(InstanceAlarmListTable.SOURCE_VALUE.getName()));
instanceAlarmList.setAlarmType(resultSet.getInt(InstanceAlarmListTable.ALARM_TYPE.getName()));
instanceAlarmList.setApplicationId(resultSet.getInt(InstanceAlarmListTable.APPLICATION_ID.getName()));
instanceAlarmList.setInstanceId(resultSet.getInt(InstanceAlarmListTable.INSTANCE_ID.getName()));
instanceAlarmList.setTimeBucket(resultSet.getLong(InstanceAlarmListTable.TIME_BUCKET.getName()));
instanceAlarmList.setAlarmContent(resultSet.getString(InstanceAlarmListTable.ALARM_CONTENT.getName()));
return instanceAlarmList;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(InstanceAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(InstanceAlarmListTable.ID.getName(), streamData.getId());
target.put(InstanceAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(InstanceAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(InstanceAlarmListTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(InstanceAlarmListTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(InstanceAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(InstanceAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return InstanceAlarmListTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + InstanceAlarmListTable.TABLE)
@Override public InstanceAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IInstanceAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceAlarmTable;
/**
* @author linjiaqi
*/
public class InstanceAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<InstanceAlarm> implements IInstanceAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, InstanceAlarm> {
public InstanceAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return InstanceAlarmTable.TABLE;
}
@Override protected InstanceAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
InstanceAlarm instanceAlarm = new InstanceAlarm();
instanceAlarm.setId(resultSet.getString(InstanceAlarmTable.ID.getName()));
instanceAlarm.setSourceValue(resultSet.getInt(InstanceAlarmTable.SOURCE_VALUE.getName()));
instanceAlarm.setAlarmType(resultSet.getInt(InstanceAlarmTable.ALARM_TYPE.getName()));
instanceAlarm.setApplicationId(resultSet.getInt(InstanceAlarmTable.APPLICATION_ID.getName()));
instanceAlarm.setInstanceId(resultSet.getInt(InstanceAlarmTable.INSTANCE_ID.getName()));
instanceAlarm.setLastTimeBucket(resultSet.getLong(InstanceAlarmTable.LAST_TIME_BUCKET.getName()));
instanceAlarm.setAlarmContent(resultSet.getString(InstanceAlarmTable.ALARM_CONTENT.getName()));
return instanceAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(InstanceAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(InstanceAlarmTable.ID.getName(), streamData.getId());
target.put(InstanceAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(InstanceAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(InstanceAlarmTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(InstanceAlarmTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(InstanceAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(InstanceAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return InstanceAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + InstanceAlarmTable.TABLE)
@Override public InstanceAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IInstanceReferenceAlarmListPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceReferenceAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceReferenceAlarmListTable;
/**
* @author linjiaqi
*/
public class InstanceReferenceAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<InstanceReferenceAlarmList> implements IInstanceReferenceAlarmListPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, InstanceReferenceAlarmList> {
public InstanceReferenceAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return InstanceReferenceAlarmListTable.TABLE;
}
@Override protected InstanceReferenceAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
InstanceReferenceAlarmList instanceReferenceAlarmList = new InstanceReferenceAlarmList();
instanceReferenceAlarmList.setId(resultSet.getString(InstanceReferenceAlarmListTable.ID.getName()));
instanceReferenceAlarmList.setSourceValue(resultSet.getInt(InstanceReferenceAlarmListTable.SOURCE_VALUE.getName()));
instanceReferenceAlarmList.setAlarmType(resultSet.getInt(InstanceReferenceAlarmListTable.ALARM_TYPE.getName()));
instanceReferenceAlarmList.setFrontApplicationId(resultSet.getInt(InstanceReferenceAlarmListTable.FRONT_APPLICATION_ID.getName()));
instanceReferenceAlarmList.setFrontInstanceId(resultSet.getInt(InstanceReferenceAlarmListTable.FRONT_INSTANCE_ID.getName()));
instanceReferenceAlarmList.setBehindApplicationId(resultSet.getInt(InstanceReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName()));
instanceReferenceAlarmList.setBehindInstanceId(resultSet.getInt(InstanceReferenceAlarmListTable.BEHIND_INSTANCE_ID.getName()));
instanceReferenceAlarmList.setTimeBucket(resultSet.getLong(InstanceReferenceAlarmListTable.TIME_BUCKET.getName()));
instanceReferenceAlarmList.setAlarmContent(resultSet.getString(InstanceReferenceAlarmListTable.ALARM_CONTENT.getName()));
return instanceReferenceAlarmList;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(InstanceReferenceAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(InstanceReferenceAlarmListTable.ID.getName(), streamData.getId());
target.put(InstanceReferenceAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(InstanceReferenceAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(InstanceReferenceAlarmListTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(InstanceReferenceAlarmListTable.FRONT_INSTANCE_ID.getName(), streamData.getFrontInstanceId());
target.put(InstanceReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(InstanceReferenceAlarmListTable.BEHIND_INSTANCE_ID.getName(), streamData.getBehindInstanceId());
target.put(InstanceReferenceAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(InstanceReferenceAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return InstanceReferenceAlarmListTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + InstanceReferenceAlarmListTable.TABLE)
@Override public InstanceReferenceAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IInstanceReferenceAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceReferenceAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.InstanceReferenceAlarmTable;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceReferenceAlarmTable;
/**
* @author linjiaqi
*/
public class InstanceReferenceAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<InstanceReferenceAlarm> implements IInstanceReferenceAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, InstanceReferenceAlarm> {
public InstanceReferenceAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return InstanceReferenceAlarmTable.TABLE;
}
@Override protected InstanceReferenceAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
InstanceReferenceAlarm instanceReferenceAlarm = new InstanceReferenceAlarm();
instanceReferenceAlarm.setId(resultSet.getString(ServiceReferenceAlarmTable.ID.getName()));
instanceReferenceAlarm.setSourceValue(resultSet.getInt(ServiceReferenceAlarmTable.SOURCE_VALUE.getName()));
instanceReferenceAlarm.setAlarmType(resultSet.getInt(ServiceReferenceAlarmTable.ALARM_TYPE.getName()));
instanceReferenceAlarm.setFrontApplicationId(resultSet.getInt(ServiceReferenceAlarmTable.FRONT_APPLICATION_ID.getName()));
instanceReferenceAlarm.setFrontInstanceId(resultSet.getInt(ServiceReferenceAlarmTable.FRONT_INSTANCE_ID.getName()));
instanceReferenceAlarm.setBehindApplicationId(resultSet.getInt(ServiceReferenceAlarmTable.BEHIND_APPLICATION_ID.getName()));
instanceReferenceAlarm.setBehindInstanceId(resultSet.getInt(ServiceReferenceAlarmTable.BEHIND_INSTANCE_ID.getName()));
instanceReferenceAlarm.setLastTimeBucket(resultSet.getLong(ServiceReferenceAlarmTable.LAST_TIME_BUCKET.getName()));
instanceReferenceAlarm.setAlarmContent(resultSet.getString(ServiceReferenceAlarmTable.ALARM_CONTENT.getName()));
return instanceReferenceAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(InstanceReferenceAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ServiceReferenceAlarmTable.ID.getName(), streamData.getId());
target.put(ServiceReferenceAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ServiceReferenceAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ServiceReferenceAlarmTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ServiceReferenceAlarmTable.FRONT_INSTANCE_ID.getName(), streamData.getFrontInstanceId());
target.put(ServiceReferenceAlarmTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(ServiceReferenceAlarmTable.BEHIND_INSTANCE_ID.getName(), streamData.getBehindInstanceId());
target.put(ServiceReferenceAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(ServiceReferenceAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return InstanceReferenceAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + InstanceReferenceAlarmTable.TABLE)
@Override public InstanceReferenceAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IServiceAlarmListPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceAlarmListTable;
/**
* @author linjiaqi
*/
public class ServiceAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ServiceAlarmList> implements IServiceAlarmListPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ServiceAlarmList> {
public ServiceAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ServiceAlarmListTable.TABLE;
}
@Override protected ServiceAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ServiceAlarmList serviceAlarmList = new ServiceAlarmList();
serviceAlarmList.setId(resultSet.getString(ServiceAlarmListTable.ID.getName()));
serviceAlarmList.setSourceValue(resultSet.getInt(ServiceAlarmListTable.SOURCE_VALUE.getName()));
serviceAlarmList.setAlarmType(resultSet.getInt(ServiceAlarmListTable.ALARM_TYPE.getName()));
serviceAlarmList.setApplicationId(resultSet.getInt(ServiceAlarmListTable.APPLICATION_ID.getName()));
serviceAlarmList.setInstanceId(resultSet.getInt(ServiceAlarmListTable.INSTANCE_ID.getName()));
serviceAlarmList.setServiceId(resultSet.getInt(ServiceAlarmListTable.SERVICE_ID.getName()));
serviceAlarmList.setTimeBucket(resultSet.getLong(ServiceAlarmListTable.TIME_BUCKET.getName()));
serviceAlarmList.setAlarmContent(resultSet.getString(ServiceAlarmListTable.ALARM_CONTENT.getName()));
return serviceAlarmList;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ServiceAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ServiceAlarmListTable.ID.getName(), streamData.getId());
target.put(ServiceAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ServiceAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ServiceAlarmListTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ServiceAlarmListTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(ServiceAlarmListTable.SERVICE_ID.getName(), streamData.getServiceId());
target.put(ServiceAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(ServiceAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ServiceAlarmListTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ServiceAlarmListTable.TABLE)
@Override public ServiceAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IServiceAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceAlarmTable;
/**
* @author linjiaqi
*/
public class ServiceAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ServiceAlarm> implements IServiceAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ServiceAlarm> {
public ServiceAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ServiceAlarmTable.TABLE;
}
@Override protected ServiceAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ServiceAlarm serviceAlarm = new ServiceAlarm();
serviceAlarm.setId(resultSet.getString(ServiceAlarmTable.ID.getName()));
serviceAlarm.setSourceValue(resultSet.getInt(ServiceAlarmTable.SOURCE_VALUE.getName()));
serviceAlarm.setAlarmType(resultSet.getInt(ServiceAlarmTable.ALARM_TYPE.getName()));
serviceAlarm.setApplicationId(resultSet.getInt(ServiceAlarmTable.APPLICATION_ID.getName()));
serviceAlarm.setInstanceId(resultSet.getInt(ServiceAlarmTable.INSTANCE_ID.getName()));
serviceAlarm.setServiceId(resultSet.getInt(ServiceAlarmTable.SERVICE_ID.getName()));
serviceAlarm.setLastTimeBucket(resultSet.getLong(ServiceAlarmTable.LAST_TIME_BUCKET.getName()));
serviceAlarm.setAlarmContent(resultSet.getString(ServiceAlarmTable.ALARM_CONTENT.getName()));
return serviceAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ServiceAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ServiceAlarmTable.ID.getName(), streamData.getId());
target.put(ServiceAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ServiceAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ServiceAlarmTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ServiceAlarmTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(ServiceAlarmTable.SERVICE_ID.getName(), streamData.getServiceId());
target.put(ServiceAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(ServiceAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ServiceAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ServiceAlarmTable.TABLE)
@Override public ServiceAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IServiceReferenceAlarmListPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceReferenceAlarmList;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceReferenceAlarmListTable;
/**
* @author linjiaqi
*/
public class ServiceReferenceAlarmListShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ServiceReferenceAlarmList> implements IServiceReferenceAlarmListPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ServiceReferenceAlarmList> {
public ServiceReferenceAlarmListShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ServiceReferenceAlarmListTable.TABLE;
}
@Override protected ServiceReferenceAlarmList shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ServiceReferenceAlarmList serviceReferenceAlarmList = new ServiceReferenceAlarmList();
serviceReferenceAlarmList.setId(resultSet.getString(ServiceReferenceAlarmListTable.ID.getName()));
serviceReferenceAlarmList.setSourceValue(resultSet.getInt(ServiceReferenceAlarmListTable.SOURCE_VALUE.getName()));
serviceReferenceAlarmList.setAlarmType(resultSet.getInt(ServiceReferenceAlarmListTable.ALARM_TYPE.getName()));
serviceReferenceAlarmList.setFrontApplicationId(resultSet.getInt(ServiceReferenceAlarmListTable.FRONT_APPLICATION_ID.getName()));
serviceReferenceAlarmList.setFrontInstanceId(resultSet.getInt(ServiceReferenceAlarmListTable.FRONT_INSTANCE_ID.getName()));
serviceReferenceAlarmList.setFrontServiceId(resultSet.getInt(ServiceReferenceAlarmListTable.FRONT_SERVICE_ID.getName()));
serviceReferenceAlarmList.setBehindApplicationId(resultSet.getInt(ServiceReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName()));
serviceReferenceAlarmList.setBehindInstanceId(resultSet.getInt(ServiceReferenceAlarmListTable.BEHIND_INSTANCE_ID.getName()));
serviceReferenceAlarmList.setBehindServiceId(resultSet.getInt(ServiceReferenceAlarmListTable.BEHIND_SERVICE_ID.getName()));
serviceReferenceAlarmList.setTimeBucket(resultSet.getLong(ServiceReferenceAlarmListTable.TIME_BUCKET.getName()));
serviceReferenceAlarmList.setAlarmContent(resultSet.getString(ServiceReferenceAlarmListTable.ALARM_CONTENT.getName()));
return serviceReferenceAlarmList;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ServiceReferenceAlarmList streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ServiceReferenceAlarmListTable.ID.getName(), streamData.getId());
target.put(ServiceReferenceAlarmListTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ServiceReferenceAlarmListTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ServiceReferenceAlarmListTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ServiceReferenceAlarmListTable.FRONT_INSTANCE_ID.getName(), streamData.getFrontInstanceId());
target.put(ServiceReferenceAlarmListTable.FRONT_SERVICE_ID.getName(), streamData.getFrontServiceId());
target.put(ServiceReferenceAlarmListTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(ServiceReferenceAlarmListTable.BEHIND_INSTANCE_ID.getName(), streamData.getBehindInstanceId());
target.put(ServiceReferenceAlarmListTable.BEHIND_SERVICE_ID.getName(), streamData.getBehindServiceId());
target.put(ServiceReferenceAlarmListTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
target.put(ServiceReferenceAlarmListTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ServiceReferenceAlarmListTable.TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ServiceReferenceAlarmListTable.TABLE)
@Override public ServiceReferenceAlarmList get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.alarm;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.dao.alarm.IServiceReferenceAlarmPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceReferenceAlarm;
import org.apache.skywalking.apm.collector.storage.table.alarm.ServiceReferenceAlarmTable;
/**
* @author linjiaqi
*/
public class ServiceReferenceAlarmShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ServiceReferenceAlarm> implements IServiceReferenceAlarmPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ServiceReferenceAlarm> {
public ServiceReferenceAlarmShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ServiceReferenceAlarmTable.TABLE;
}
@Override protected ServiceReferenceAlarm shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ServiceReferenceAlarm serviceReferenceAlarm = new ServiceReferenceAlarm();
serviceReferenceAlarm.setId(resultSet.getString(ServiceReferenceAlarmTable.ID.getName()));
serviceReferenceAlarm.setSourceValue(resultSet.getInt(ServiceReferenceAlarmTable.SOURCE_VALUE.getName()));
serviceReferenceAlarm.setAlarmType(resultSet.getInt(ServiceReferenceAlarmTable.ALARM_TYPE.getName()));
serviceReferenceAlarm.setFrontApplicationId(resultSet.getInt(ServiceReferenceAlarmTable.FRONT_APPLICATION_ID.getName()));
serviceReferenceAlarm.setFrontInstanceId(resultSet.getInt(ServiceReferenceAlarmTable.FRONT_INSTANCE_ID.getName()));
serviceReferenceAlarm.setFrontServiceId(resultSet.getInt(ServiceReferenceAlarmTable.FRONT_SERVICE_ID.getName()));
serviceReferenceAlarm.setBehindApplicationId(resultSet.getInt(ServiceReferenceAlarmTable.BEHIND_APPLICATION_ID.getName()));
serviceReferenceAlarm.setBehindInstanceId(resultSet.getInt(ServiceReferenceAlarmTable.BEHIND_INSTANCE_ID.getName()));
serviceReferenceAlarm.setBehindServiceId(resultSet.getInt(ServiceReferenceAlarmTable.BEHIND_SERVICE_ID.getName()));
serviceReferenceAlarm.setLastTimeBucket(resultSet.getLong(ServiceReferenceAlarmTable.LAST_TIME_BUCKET.getName()));
serviceReferenceAlarm.setAlarmContent(resultSet.getString(ServiceReferenceAlarmTable.ALARM_CONTENT.getName()));
return serviceReferenceAlarm;
}
@Override protected Map<String, Object> streamDataToShardingjdbcData(ServiceReferenceAlarm streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ServiceReferenceAlarmTable.ID.getName(), streamData.getId());
target.put(ServiceReferenceAlarmTable.SOURCE_VALUE.getName(), streamData.getSourceValue());
target.put(ServiceReferenceAlarmTable.ALARM_TYPE.getName(), streamData.getAlarmType());
target.put(ServiceReferenceAlarmTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ServiceReferenceAlarmTable.FRONT_INSTANCE_ID.getName(), streamData.getFrontInstanceId());
target.put(ServiceReferenceAlarmTable.FRONT_SERVICE_ID.getName(), streamData.getFrontServiceId());
target.put(ServiceReferenceAlarmTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
target.put(ServiceReferenceAlarmTable.BEHIND_INSTANCE_ID.getName(), streamData.getBehindInstanceId());
target.put(ServiceReferenceAlarmTable.BEHIND_SERVICE_ID.getName(), streamData.getBehindServiceId());
target.put(ServiceReferenceAlarmTable.LAST_TIME_BUCKET.getName(), streamData.getLastTimeBucket());
target.put(ServiceReferenceAlarmTable.ALARM_CONTENT.getName(), streamData.getAlarmContent());
return target;
}
@Override protected String timeBucketColumnNameForDelete() {
return ServiceReferenceAlarmTable.LAST_TIME_BUCKET.getName();
}
@GraphComputingMetric(name = "/persistence/get/" + ServiceReferenceAlarmTable.TABLE)
@Override public ServiceReferenceAlarm get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.amp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.MetricTransformUtil;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
/**
* @author linjiaqi
*/
public abstract class AbstractApplicationMetricShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationMetric> {
AbstractApplicationMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return ApplicationMetricTable.TIME_BUCKET.getName();
}
@Override protected final ApplicationMetric shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationMetric applicationMetric = new ApplicationMetric();
applicationMetric.setId(resultSet.getString(ApplicationMetricTable.ID.getName()));
applicationMetric.setMetricId(resultSet.getString(ApplicationMetricTable.METRIC_ID.getName()));
applicationMetric.setApplicationId(resultSet.getInt(ApplicationMetricTable.APPLICATION_ID.getName()));
MetricTransformUtil.INSTANCE.shardingjdbcDataToStreamData(resultSet, applicationMetric);
applicationMetric.setSatisfiedCount(resultSet.getLong(ApplicationMetricTable.SATISFIED_COUNT.getName()));
applicationMetric.setToleratingCount(resultSet.getLong(ApplicationMetricTable.TOLERATING_COUNT.getName()));
applicationMetric.setFrustratedCount(resultSet.getLong(ApplicationMetricTable.FRUSTRATED_COUNT.getName()));
return applicationMetric;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(ApplicationMetric streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationMetricTable.ID.getName(), streamData.getId());
target.put(ApplicationMetricTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(ApplicationMetricTable.APPLICATION_ID.getName(), streamData.getApplicationId());
MetricTransformUtil.INSTANCE.streamDataToShardingjdbcData(streamData, target);
target.put(ApplicationMetricTable.SATISFIED_COUNT.getName(), streamData.getSatisfiedCount());
target.put(ApplicationMetricTable.TOLERATING_COUNT.getName(), streamData.getToleratingCount());
target.put(ApplicationMetricTable.FRUSTRATED_COUNT.getName(), streamData.getFrustratedCount());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationMetricTable.TABLE)
@Override public final ApplicationMetric get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.amp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.amp.IApplicationDayMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationDayMetricShardingjdbcPersistenceDAO extends AbstractApplicationMetricShardingjdbcPersistenceDAO implements IApplicationDayMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMetric> {
public ApplicationDayMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.amp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.amp.IApplicationHourMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationHourMetricShardingjdbcPersistenceDAO extends AbstractApplicationMetricShardingjdbcPersistenceDAO implements IApplicationHourMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMetric> {
public ApplicationHourMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.amp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.amp.IApplicationMinuteMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationMinuteMetricShardingjdbcPersistenceDAO extends AbstractApplicationMetricShardingjdbcPersistenceDAO implements IApplicationMinuteMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMetric> {
public ApplicationMinuteMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.amp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.amp.IApplicationMonthMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationMonthMetricShardingjdbcPersistenceDAO extends AbstractApplicationMetricShardingjdbcPersistenceDAO implements IApplicationMonthMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMetric> {
public ApplicationMonthMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.ampp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
/**
* @author linjiaqi
*/
public abstract class AbstractApplicationMappingShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationMapping> {
AbstractApplicationMappingShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return ApplicationMappingTable.TIME_BUCKET.getName();
}
@Override protected final ApplicationMapping shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationMapping applicationMapping = new ApplicationMapping();
applicationMapping.setId(resultSet.getString(ApplicationMappingTable.ID.getName()));
applicationMapping.setMetricId(resultSet.getString(ApplicationMappingTable.METRIC_ID.getName()));
applicationMapping.setApplicationId(resultSet.getInt(ApplicationMappingTable.APPLICATION_ID.getName()));
applicationMapping.setMappingApplicationId(resultSet.getInt(ApplicationMappingTable.MAPPING_APPLICATION_ID.getName()));
applicationMapping.setTimeBucket(resultSet.getLong(ApplicationMappingTable.TIME_BUCKET.getName()));
return applicationMapping;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(ApplicationMapping streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationMappingTable.ID.getName(), streamData.getId());
target.put(ApplicationMappingTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(ApplicationMappingTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(ApplicationMappingTable.MAPPING_APPLICATION_ID.getName(), streamData.getMappingApplicationId());
target.put(ApplicationMappingTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationMappingTable.TABLE)
@Override public final ApplicationMapping get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.ampp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ampp.IApplicationMappingDayPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
/**
* @author linjiaqi
*/
public class ApplicationMappingDayShardingjdbcPersistenceDAO extends AbstractApplicationMappingShardingjdbcPersistenceDAO implements IApplicationMappingDayPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMapping> {
public ApplicationMappingDayShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMappingTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.ampp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ampp.IApplicationMappingHourPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
/**
* @author linjiaqi
*/
public class ApplicationMappingHourShardingjdbcPersistenceDAO extends AbstractApplicationMappingShardingjdbcPersistenceDAO implements IApplicationMappingHourPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMapping> {
public ApplicationMappingHourShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMappingTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.ampp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ampp.IApplicationMappingMinutePersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
/**
* @author linjiaqi
*/
public class ApplicationMappingMinuteShardingjdbcPersistenceDAO extends AbstractApplicationMappingShardingjdbcPersistenceDAO implements IApplicationMappingMinutePersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMapping> {
public ApplicationMappingMinuteShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMappingTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.ampp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ampp.IApplicationMappingMonthPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMapping;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable;
/**
* @author linjiaqi
*/
public class ApplicationMappingMonthShardingjdbcPersistenceDAO extends AbstractApplicationMappingShardingjdbcPersistenceDAO implements IApplicationMappingMonthPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationMapping> {
public ApplicationMappingMonthShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationMappingTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.armp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.MetricTransformUtil;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
/**
* @author linjiaqi
*/
public abstract class AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<ApplicationReferenceMetric> {
AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return ApplicationReferenceMetricTable.TIME_BUCKET.getName();
}
@Override protected final ApplicationReferenceMetric shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
ApplicationReferenceMetric applicationReferenceMetric = new ApplicationReferenceMetric();
applicationReferenceMetric.setId(resultSet.getString(ApplicationReferenceMetricTable.ID.getName()));
applicationReferenceMetric.setMetricId(resultSet.getString(ApplicationReferenceMetricTable.METRIC_ID.getName()));
applicationReferenceMetric.setFrontApplicationId(resultSet.getInt(ApplicationReferenceMetricTable.FRONT_APPLICATION_ID.getName()));
applicationReferenceMetric.setBehindApplicationId(resultSet.getInt(ApplicationReferenceMetricTable.BEHIND_APPLICATION_ID.getName()));
MetricTransformUtil.INSTANCE.shardingjdbcDataToStreamData(resultSet, applicationReferenceMetric);
applicationReferenceMetric.setSatisfiedCount(resultSet.getLong(ApplicationReferenceMetricTable.SATISFIED_COUNT.getName()));
applicationReferenceMetric.setToleratingCount(resultSet.getLong(ApplicationReferenceMetricTable.TOLERATING_COUNT.getName()));
applicationReferenceMetric.setFrustratedCount(resultSet.getLong(ApplicationReferenceMetricTable.FRUSTRATED_COUNT.getName()));
return applicationReferenceMetric;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(ApplicationReferenceMetric streamData) {
Map<String, Object> target = new HashMap<>();
target.put(ApplicationReferenceMetricTable.ID.getName(), streamData.getId());
target.put(ApplicationReferenceMetricTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(ApplicationReferenceMetricTable.FRONT_APPLICATION_ID.getName(), streamData.getFrontApplicationId());
target.put(ApplicationReferenceMetricTable.BEHIND_APPLICATION_ID.getName(), streamData.getBehindApplicationId());
MetricTransformUtil.INSTANCE.streamDataToShardingjdbcData(streamData, target);
target.put(ApplicationReferenceMetricTable.SATISFIED_COUNT.getName(), streamData.getSatisfiedCount());
target.put(ApplicationReferenceMetricTable.TOLERATING_COUNT.getName(), streamData.getToleratingCount());
target.put(ApplicationReferenceMetricTable.FRUSTRATED_COUNT.getName(), streamData.getFrustratedCount());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + ApplicationReferenceMetricTable.TABLE)
@Override public final ApplicationReferenceMetric get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.armp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.armp.IApplicationReferenceDayMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceDayMetricShardingjdbcPersistenceDAO extends AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO implements IApplicationReferenceDayMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceMetric> {
public ApplicationReferenceDayMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.armp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.armp.IApplicationReferenceHourMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceHourMetricShardingjdbcPersistenceDAO extends AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO implements IApplicationReferenceHourMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceMetric> {
public ApplicationReferenceHourMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.armp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.armp.IApplicationReferenceMinuteMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceMinuteMetricShardingjdbcPersistenceDAO extends AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO implements IApplicationReferenceMinuteMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceMetric> {
public ApplicationReferenceMinuteMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.armp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.armp.IApplicationReferenceMonthMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetric;
import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable;
/**
* @author linjiaqi
*/
public class ApplicationReferenceMonthMetricShardingjdbcPersistenceDAO extends AbstractApplicationReferenceMetricShardingjdbcPersistenceDAO implements IApplicationReferenceMonthMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, ApplicationReferenceMetric> {
public ApplicationReferenceMonthMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return ApplicationReferenceMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cache;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class ApplicationShardingjdbcCacheDAO extends ShardingjdbcDAO implements IApplicationCacheDAO {
private static final Logger logger = LoggerFactory.getLogger(ApplicationShardingjdbcCacheDAO.class);
private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?";
private static final String GET_APPLICATION_SQL = "select {0},{1} from {2} where {3} = ?";
public ApplicationShardingjdbcCacheDAO(ShardingjdbcClient client) {
super(client);
}
@Override
public int getApplicationIdByCode(String applicationCode) {
logger.info("get the application id with application code = {}", applicationCode);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, ApplicationTable.APPLICATION_ID.getName(), ApplicationTable.TABLE, ApplicationTable.APPLICATION_CODE.getName(), ApplicationTable.IS_ADDRESS.getName());
Object[] params = new Object[] {applicationCode, false};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public Application getApplication(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_SQL, ApplicationTable.APPLICATION_CODE.getName(), ApplicationTable.IS_ADDRESS.getName(), ApplicationTable.TABLE, ApplicationTable.APPLICATION_ID.getName());
Object[] params = new Object[] {applicationId};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
Application application = new Application();
application.setApplicationId(applicationId);
application.setApplicationCode(rs.getString(1));
application.setIsAddress(rs.getInt(2));
return application;
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override public int getApplicationIdByAddressId(int addressId) {
logger.info("get the application id with address id = {}", addressId);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, ApplicationTable.APPLICATION_ID.getName(), ApplicationTable.TABLE, ApplicationTable.ADDRESS_ID.getName(), ApplicationTable.IS_ADDRESS.getName());
Object[] params = new Object[] {addressId, true};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cache;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.cache.IInstanceCacheDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class InstanceShardingjdbcCacheDAO extends ShardingjdbcDAO implements IInstanceCacheDAO {
private static final Logger logger = LoggerFactory.getLogger(InstanceShardingjdbcCacheDAO.class);
private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ?";
private static final String GET_INSTANCE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? and {4} = ?";
public InstanceShardingjdbcCacheDAO(ShardingjdbcClient client) {
super(client);
}
@Override public int getApplicationId(int instanceId) {
logger.info("get the application id by instance id = {}", instanceId);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_ID_SQL, InstanceTable.APPLICATION_ID.getName(), InstanceTable.TABLE, InstanceTable.INSTANCE_ID.getName());
Object[] params = new Object[] {instanceId};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(InstanceTable.APPLICATION_ID.getName());
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public int getInstanceIdByAgentUUID(int applicationId, String agentUUID) {
logger.info("get the instance id by application id = {}, agentUUID = {}", applicationId, agentUUID);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.INSTANCE_ID.getName(), InstanceTable.TABLE, InstanceTable.APPLICATION_ID.getName(),
InstanceTable.AGENT_UUID.getName(), InstanceTable.IS_ADDRESS.getName());
Object[] params = new Object[] {applicationId, agentUUID, BooleanUtils.FALSE};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(InstanceTable.INSTANCE_ID.getName());
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
@Override public int getInstanceIdByAddressId(int applicationId, int addressId) {
logger.info("get the instance id by application id = {}, address id = {}", applicationId, addressId);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_INSTANCE_ID_SQL, InstanceTable.INSTANCE_ID.getName(), InstanceTable.TABLE, InstanceTable.APPLICATION_ID.getName(),
InstanceTable.ADDRESS_ID.getName(), InstanceTable.IS_ADDRESS.getName());
Object[] params = new Object[] {applicationId, addressId, BooleanUtils.TRUE};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(InstanceTable.INSTANCE_ID.getName());
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cache;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.cache.INetworkAddressCacheDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress;
import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class NetworkAddressShardingjdbcCacheDAO extends ShardingjdbcDAO implements INetworkAddressCacheDAO {
private static final Logger logger = LoggerFactory.getLogger(NetworkAddressShardingjdbcCacheDAO.class);
private static final String GET_ADDRESS_ID_OR_CODE_SQL = "select {0} from {1} where {2} = ?";
public NetworkAddressShardingjdbcCacheDAO(ShardingjdbcClient client) {
super(client);
}
@Override
public int getAddressId(String networkAddress) {
logger.info("get the address id with network address = {}", networkAddress);
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_ADDRESS_ID_OR_CODE_SQL, NetworkAddressTable.ADDRESS_ID.getName(), NetworkAddressTable.TABLE, NetworkAddressTable.NETWORK_ADDRESS.getName());
Object[] params = new Object[] {networkAddress};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return Const.NONE;
}
@Override public NetworkAddress getAddressById(int addressId) {
logger.debug("get network address, address id: {}", addressId);
ShardingjdbcClient client = getClient();
String dynamicSql = "select * from {0} where {1} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.TABLE, NetworkAddressTable.ADDRESS_ID.getName());
Object[] params = new Object[] {addressId};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
NetworkAddress networkAddress = new NetworkAddress();
networkAddress.setId(rs.getString(NetworkAddressTable.ID.getName()));
networkAddress.setAddressId(rs.getInt(NetworkAddressTable.ADDRESS_ID.getName()));
networkAddress.setNetworkAddress(rs.getString(NetworkAddressTable.NETWORK_ADDRESS.getName()));
networkAddress.setSrcSpanLayer(rs.getInt(NetworkAddressTable.SRC_SPAN_LAYER.getName()));
networkAddress.setServerType(rs.getInt(NetworkAddressTable.SERVER_TYPE.getName()));
return networkAddress;
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cache;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClientException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.ShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author linjiaqi
*/
public class ServiceNameShardingjdbcCacheDAO extends ShardingjdbcDAO implements IServiceNameCacheDAO {
private static final Logger logger = LoggerFactory.getLogger(ServiceNameShardingjdbcCacheDAO.class);
private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?";
private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? and {4} = ? limit 1";
public ServiceNameShardingjdbcCacheDAO(ShardingjdbcClient client) {
super(client);
}
@Override public ServiceName get(int serviceId) {
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.APPLICATION_ID.getName(), ServiceNameTable.SERVICE_NAME.getName(),
ServiceNameTable.TABLE, ServiceNameTable.SERVICE_ID.getName());
Object[] params = new Object[] {serviceId};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
ServiceName serviceName = new ServiceName();
serviceName.setServiceId(serviceId);
serviceName.setApplicationId(rs.getInt(ServiceNameTable.APPLICATION_ID.getName()));
serviceName.setServiceName(rs.getString(ServiceNameTable.SERVICE_NAME.getName()));
return serviceName;
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
@Override public int getServiceId(int applicationId, int srcSpanType, String serviceName) {
ShardingjdbcClient client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.SERVICE_ID.getName(), ServiceNameTable.TABLE,
ServiceNameTable.APPLICATION_ID.getName(), ServiceNameTable.SRC_SPAN_TYPE.getName(), ServiceNameTable.SERVICE_NAME.getName());
Object[] params = new Object[] {applicationId, srcSpanType, serviceName};
try (
ResultSet rs = client.executeQuery(sql, params);
Statement statement = rs.getStatement();
Connection conn = statement.getConnection();
) {
if (rs.next()) {
return rs.getInt(ServiceNameTable.SERVICE_ID.getName());
}
} catch (SQLException | ShardingjdbcClientException e) {
logger.error(e.getMessage(), e);
}
return 0;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cpu;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author linjiaqi
*/
public abstract class AbstractCpuMetricShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<CpuMetric> {
AbstractCpuMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return CpuMetricTable.TIME_BUCKET.getName();
}
@Override protected final CpuMetric shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
CpuMetric cpuMetric = new CpuMetric();
cpuMetric.setId(resultSet.getString(CpuMetricTable.ID.getName()));
cpuMetric.setMetricId(resultSet.getString(CpuMetricTable.METRIC_ID.getName()));
cpuMetric.setInstanceId(resultSet.getInt(CpuMetricTable.INSTANCE_ID.getName()));
cpuMetric.setUsagePercent(resultSet.getDouble(CpuMetricTable.USAGE_PERCENT.getName()));
cpuMetric.setTimes(resultSet.getLong(CpuMetricTable.TIMES.getName()));
cpuMetric.setTimeBucket(resultSet.getLong(CpuMetricTable.TIME_BUCKET.getName()));
return cpuMetric;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(CpuMetric streamData) {
Map<String, Object> target = new HashMap<>();
target.put(CpuMetricTable.ID.getName(), streamData.getId());
target.put(CpuMetricTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(CpuMetricTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(CpuMetricTable.USAGE_PERCENT.getName(), streamData.getUsagePercent());
target.put(CpuMetricTable.TIMES.getName(), streamData.getTimes());
target.put(CpuMetricTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + CpuMetricTable.TABLE)
@Override public final CpuMetric get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cpu;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.cpu.ICpuDayMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author linjiaqi
*/
public class CpuDayMetricShardingjdbcPersistenceDAO extends AbstractCpuMetricShardingjdbcPersistenceDAO implements ICpuDayMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, CpuMetric> {
public CpuDayMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return CpuMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cpu;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.cpu.ICpuHourMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author linjiaqi
*/
public class CpuHourMetricShardingjdbcPersistenceDAO extends AbstractCpuMetricShardingjdbcPersistenceDAO implements ICpuHourMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, CpuMetric> {
public CpuHourMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return CpuMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cpu;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.cpu.ICpuMinuteMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author linjiaqi
*/
public class CpuMinuteMetricShardingjdbcPersistenceDAO extends AbstractCpuMetricShardingjdbcPersistenceDAO implements ICpuMinuteMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, CpuMetric> {
public CpuMinuteMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return CpuMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.cpu;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.cpu.ICpuMonthMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable;
/**
* @author linjiaqi
*/
public class CpuMonthMetricShardingjdbcPersistenceDAO extends AbstractCpuMetricShardingjdbcPersistenceDAO implements ICpuMonthMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, CpuMetric> {
public CpuMonthMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return CpuMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.gc;
import java.sql.*;
import java.util.*;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.jvm.*;
/**
* @author linjiaqi
*/
public abstract class AbstractGCMetricShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<GCMetric> {
AbstractGCMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return GCMetricTable.TIME_BUCKET.getName();
}
@Override protected final GCMetric shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
GCMetric gcMetric = new GCMetric();
gcMetric.setId(resultSet.getString(GCMetricTable.ID.getName()));
gcMetric.setMetricId(resultSet.getString(GCMetricTable.METRIC_ID.getName()));
gcMetric.setInstanceId(resultSet.getInt(GCMetricTable.INSTANCE_ID.getName()));
gcMetric.setPhrase(resultSet.getInt(GCMetricTable.PHRASE.getName()));
gcMetric.setCount(resultSet.getLong(GCMetricTable.COUNT.getName()));
gcMetric.setTimes(resultSet.getLong(GCMetricTable.TIMES.getName()));
gcMetric.setDuration(resultSet.getLong(GCMetricTable.DURATION.getName()));
gcMetric.setTimeBucket(resultSet.getLong(GCMetricTable.TIME_BUCKET.getName()));
return gcMetric;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(GCMetric streamData) {
Map<String, Object> target = new HashMap<>();
target.put(GCMetricTable.ID.getName(), streamData.getId());
target.put(GCMetricTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(GCMetricTable.INSTANCE_ID.getName(), streamData.getInstanceId());
target.put(GCMetricTable.PHRASE.getName(), streamData.getPhrase());
target.put(GCMetricTable.COUNT.getName(), streamData.getCount());
target.put(GCMetricTable.TIMES.getName(), streamData.getTimes());
target.put(GCMetricTable.DURATION.getName(), streamData.getDuration());
target.put(GCMetricTable.TIME_BUCKET.getName(), streamData.getTimeBucket());
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + GCMetricTable.TABLE)
@Override public final GCMetric get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.gc;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.gc.IGCDayMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author linjiaqi
*/
public class GCDayMetricShardingjdbcPersistenceDAO extends AbstractGCMetricShardingjdbcPersistenceDAO implements IGCDayMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, GCMetric> {
public GCDayMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return GCMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.gc;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.gc.IGCHourMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author linjiaqi
*/
public class GCHourMetricShardingjdbcPersistenceDAO extends AbstractGCMetricShardingjdbcPersistenceDAO implements IGCHourMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, GCMetric> {
public GCHourMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return GCMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Hour.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.gc;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.gc.IGCMinuteMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author linjiaqi
*/
public class GCMinuteMetricShardingjdbcPersistenceDAO extends AbstractGCMetricShardingjdbcPersistenceDAO implements IGCMinuteMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, GCMetric> {
public GCMinuteMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return GCMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Minute.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.gc;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.gc.IGCMonthMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetric;
import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable;
/**
* @author linjiaqi
*/
public class GCMonthMetricShardingjdbcPersistenceDAO extends AbstractGCMetricShardingjdbcPersistenceDAO implements IGCMonthMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, GCMetric> {
public GCMonthMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return GCMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Month.getName();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.imp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.MetricTransformUtil;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.dao.AbstractPersistenceShardingjdbcDAO;
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric;
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
/**
* @author linjiaqi
*/
public abstract class AbstractInstanceMetricShardingjdbcPersistenceDAO extends AbstractPersistenceShardingjdbcDAO<InstanceMetric> {
AbstractInstanceMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected final String timeBucketColumnNameForDelete() {
return InstanceMetricTable.TIME_BUCKET.getName();
}
@Override protected final InstanceMetric shardingjdbcDataToStreamData(ResultSet resultSet) throws SQLException {
InstanceMetric instanceMetric = new InstanceMetric();
instanceMetric.setId(resultSet.getString(InstanceMetricTable.ID.getName()));
instanceMetric.setMetricId(resultSet.getString(InstanceMetricTable.METRIC_ID.getName()));
instanceMetric.setApplicationId(resultSet.getInt(InstanceMetricTable.APPLICATION_ID.getName()));
instanceMetric.setInstanceId(resultSet.getInt(InstanceMetricTable.INSTANCE_ID.getName()));
MetricTransformUtil.INSTANCE.shardingjdbcDataToStreamData(resultSet, instanceMetric);
return instanceMetric;
}
@Override protected final Map<String, Object> streamDataToShardingjdbcData(InstanceMetric streamData) {
Map<String, Object> target = new HashMap<>();
target.put(InstanceMetricTable.ID.getName(), streamData.getId());
target.put(InstanceMetricTable.METRIC_ID.getName(), streamData.getMetricId());
target.put(InstanceMetricTable.APPLICATION_ID.getName(), streamData.getApplicationId());
target.put(InstanceMetricTable.INSTANCE_ID.getName(), streamData.getInstanceId());
MetricTransformUtil.INSTANCE.streamDataToShardingjdbcData(streamData, target);
return target;
}
@GraphComputingMetric(name = "/persistence/get/" + InstanceMetricTable.TABLE)
@Override public final InstanceMetric get(String id) {
return super.get(id);
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.collector.storage.shardingjdbc.dao.imp;
import org.apache.skywalking.apm.collector.client.shardingjdbc.ShardingjdbcClient;
import org.apache.skywalking.apm.collector.core.storage.TimePyramid;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.imp.IInstanceDayMetricPersistenceDAO;
import org.apache.skywalking.apm.collector.storage.shardingjdbc.base.define.ShardingjdbcSqlEntity;
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetric;
import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable;
/**
* @author linjiaqi
*/
public class InstanceDayMetricShardingjdbcPersistenceDAO extends AbstractInstanceMetricShardingjdbcPersistenceDAO implements IInstanceDayMetricPersistenceDAO<ShardingjdbcSqlEntity, ShardingjdbcSqlEntity, InstanceMetric> {
public InstanceDayMetricShardingjdbcPersistenceDAO(ShardingjdbcClient client) {
super(client);
}
@Override protected String tableName() {
return InstanceMetricTable.TABLE + Const.ID_SPLIT + TimePyramid.Day.getName();
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册