|
@@ -51,9 +51,14 @@ public class DBApiEntry implements AutoCloseable {
|
|
|
private long lookBack = 10L * 60 * 1000_000_000;
|
|
|
private String currentDatabase = "default";
|
|
|
private String currentTable = TABLE_NAME;
|
|
|
-// private QuerySettings querySettings = new QuerySettings()
|
|
|
+ // private QuerySettings querySettings = new QuerySettings()
|
|
|
// .serverSetting("http_max_field_value_size", "26214400");
|
|
|
private QuerySettings querySettings = new QuerySettings();
|
|
|
+ private static String secureCertPath = "";
|
|
|
+
|
|
|
+ public static void SetCertForSecureConnection(String certPath) {
|
|
|
+ secureCertPath = certPath;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 初始化数据驱动构造方法
|
|
@@ -61,19 +66,38 @@ public class DBApiEntry implements AutoCloseable {
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public DBApiEntry(String addressHost, int publicPort) throws IOException {
|
|
|
+ this(addressHost, publicPort, "default", TABLE_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ public DBApiEntry(String addressHost, int publicPort, String token) throws IOException {
|
|
|
// this.host = addressHost;
|
|
|
// this.port = publicPort;
|
|
|
+// this.token = token;
|
|
|
// this.insertPort = this.port + 1;
|
|
|
// this.selectPort = this.port + 2;
|
|
|
- client = new Client.Builder()
|
|
|
- .addEndpoint(Protocol.HTTP, addressHost, publicPort, false)
|
|
|
+ this(addressHost, publicPort);
|
|
|
+ }
|
|
|
+
|
|
|
+ public DBApiEntry(String addressHost, int publicPort, String database, String table) throws IOException {
|
|
|
+ this(addressHost, publicPort, database, table, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public DBApiEntry(String addressHost, int publicPort, String database, String table, boolean useSecure) throws IOException {
|
|
|
+ this.currentDatabase = database;
|
|
|
+ this.currentTable = table;
|
|
|
+
|
|
|
+ Client.Builder builder = new Client.Builder()
|
|
|
+ .addEndpoint(Protocol.HTTP, addressHost, publicPort, useSecure)
|
|
|
.setUsername("default")
|
|
|
.setPassword("")
|
|
|
.compressClientRequest(true)
|
|
|
.compressServerResponse(true)
|
|
|
.serverSetting("http_max_field_value_size", "26214400")
|
|
|
- .serverSetting("empty_result_for_aggregation_by_empty_set", "1")
|
|
|
- .build();
|
|
|
+ .serverSetting("empty_result_for_aggregation_by_empty_set", "1");
|
|
|
+ if (useSecure) {
|
|
|
+ builder.setRootCertificate(secureCertPath);
|
|
|
+ }
|
|
|
+ client = builder.build();
|
|
|
|
|
|
// Init ClickHouse client
|
|
|
// client.execute("SET max_query_size = 26214400");
|
|
@@ -84,31 +108,72 @@ public class DBApiEntry implements AutoCloseable {
|
|
|
client.register(StckPointVal.class, schema);
|
|
|
}
|
|
|
|
|
|
- public DBApiEntry(String addressHost, int publicPort, String token) throws IOException {
|
|
|
-// this.host = addressHost;
|
|
|
-// this.port = publicPort;
|
|
|
-// this.token = token;
|
|
|
-// this.insertPort = this.port + 1;
|
|
|
-// this.selectPort = this.port + 2;
|
|
|
- this(addressHost, publicPort);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 静态方法初始化时序数据源驱动类
|
|
|
*
|
|
|
* @return DBApiEntry
|
|
|
*/
|
|
|
public static DBApiEntry initApiEntry(String addressHost, int publicPort) {
|
|
|
+ return initApiEntry(addressHost, publicPort, "default", TABLE_NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DBApiEntry initApiEntry(String addressHost, int publicPort, String token) {
|
|
|
+ return initApiEntry(addressHost, publicPort);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DBApiEntry initApiEntry(String addressHost, int publicPort, String database, String table) {
|
|
|
+ return initApiEntry(addressHost, publicPort, database, table, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DBApiEntry initApiEntry(String addressHost, int publicPort, String database, String table, boolean useSecure) {
|
|
|
try {
|
|
|
- return new DBApiEntry(addressHost, publicPort);
|
|
|
+ return new DBApiEntry(addressHost, publicPort, database, table, useSecure);
|
|
|
} catch (Exception e) {
|
|
|
LOG.error("initApiEntry error: ", e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static DBApiEntry initApiEntry(String addressHost, int publicPort, String token) {
|
|
|
- return initApiEntry(addressHost, publicPort);
|
|
|
+ public String getCurrentTable() {
|
|
|
+ return currentTable;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCurrentTable(String currentTable) {
|
|
|
+ this.currentTable = currentTable;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getCurrentDatabase() {
|
|
|
+ return currentDatabase;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCurrentDatabase(String currentDatabase) {
|
|
|
+ this.currentDatabase = currentDatabase;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doMigrateTable() {
|
|
|
+ // TODO...
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doMigrateDistributedTable() {
|
|
|
+ // TODO...
|
|
|
+ /*
|
|
|
+CREATE TABLE db1.tsdb_cpp_dist ON CLUSTER cluster_3S_1R
|
|
|
+(
|
|
|
+
|
|
|
+ `metric_name` LowCardinality(String) COMMENT 'Metric name',
|
|
|
+
|
|
|
+ `point_name` LowCardinality(String) COMMENT 'Point name',
|
|
|
+
|
|
|
+ `tags` Map(LowCardinality(String),
|
|
|
+ LowCardinality(String)) COMMENT 'Point tags',
|
|
|
+
|
|
|
+ `value` Float64 COMMENT 'Point value',
|
|
|
+
|
|
|
+ `nanoseconds` Int64 COMMENT 'Point time in nanoseconds' CODEC(DoubleDelta,
|
|
|
+ LZ4)
|
|
|
+)
|
|
|
+ENGINE = Distributed('cluster_3S_1R', 'db1', 'tsdb_cpp', rand())
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
/**
|