From b1acc3a2ebb763f40665b1805a4c219b6e424a0f Mon Sep 17 00:00:00 2001 From: XuYi Date: Thu, 29 Nov 2018 18:50:43 +0800 Subject: [PATCH] Fix issue 464 (#465) --- codecov.yml | 15 + .../cli/bin}/export-csv.bat | 0 .../cli/bin}/export-csv.sh | 0 .../cli/bin}/import-csv.bat | 0 .../cli/bin}/import-csv.sh | 0 .../cli}/bin/run-client.bat | 0 .../cli}/bin/start-client.bat | 0 .../cli}/bin/start-client.sh | 0 iotdb-cli/pom.xml | 118 +++ .../tsinghua/iotdb/client/AbstractClient.java | 57 +- .../cn/edu/tsinghua/iotdb/client/Client.java | 6 +- .../edu/tsinghua/iotdb/client/WinClient.java | 6 +- .../iotdb/exception/ArgsErrorException.java | 11 + .../tsinghua/iotdb/tool/AbstractCsvTool.java | 0 .../tsinghua/iotdb/tool/CsvTestDataGen.java | 244 +++--- .../cn/edu/tsinghua/iotdb/tool/ExportCsv.java | 0 .../cn/edu/tsinghua/iotdb/tool/ImportCsv.java | 14 +- .../iotdb/client/AbstractClientTest.java | 185 +++++ iotdb/pom.xml | 40 +- .../postback/receiver/ServerServiceImpl.java | 9 +- .../iotdb/postback/sender/FileSenderImpl.java | 4 +- .../tsinghua/iotdb/service/TSServiceImpl.java | 12 + jdbc/pom.xml | 25 +- .../tsinghua/iotdb/jdbc/TsfileConnection.java | 5 + .../iotdb/jdbc/TsfileConnectionTest.java | 20 +- pom.xml | 43 +- service-rpc/interface/rpc.thrift | 9 +- .../service/rpc/thrift/ServerProperties.java | 526 +++++++++++++ .../service/rpc/thrift/TSIService.java | 733 ++++++++++++++++++ tsfile/pom.xml | 76 +- 30 files changed, 1918 insertions(+), 240 deletions(-) create mode 100644 codecov.yml rename {iotdb/script => iotdb-cli/cli/bin}/export-csv.bat (100%) rename {iotdb/script => iotdb-cli/cli/bin}/export-csv.sh (100%) rename {iotdb/script => iotdb-cli/cli/bin}/import-csv.bat (100%) rename {iotdb/script => iotdb-cli/cli/bin}/import-csv.sh (100%) rename {iotdb/iotdb => iotdb-cli/cli}/bin/run-client.bat (100%) rename {iotdb/iotdb => iotdb-cli/cli}/bin/start-client.bat (100%) rename {iotdb/iotdb => iotdb-cli/cli}/bin/start-client.sh (100%) create mode 100644 iotdb-cli/pom.xml rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java (91%) rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java (98%) rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java (95%) create mode 100644 iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/exception/ArgsErrorException.java rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/tool/AbstractCsvTool.java (100%) rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java (96%) rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/tool/ExportCsv.java (100%) rename {iotdb => iotdb-cli}/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java (98%) create mode 100644 iotdb-cli/src/test/java/cn/edu/tsinghua/iotdb/client/AbstractClientTest.java create mode 100644 service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/ServerProperties.java diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000000..7e30bb54918 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,15 @@ +coverage: + precision: 2 + round: down + range: "70...100" + + status: + project: yes + patch: no + changes: no + +ignore: + - "*/interface/thrift/**/*.java" # ignore thrift-gen folders and all its contents + - "grafana/**/*.java" + - "spark/**/*.java" + - "hadoop/**/*.java" \ No newline at end of file diff --git a/iotdb/script/export-csv.bat b/iotdb-cli/cli/bin/export-csv.bat similarity index 100% rename from iotdb/script/export-csv.bat rename to iotdb-cli/cli/bin/export-csv.bat diff --git a/iotdb/script/export-csv.sh b/iotdb-cli/cli/bin/export-csv.sh similarity index 100% rename from iotdb/script/export-csv.sh rename to iotdb-cli/cli/bin/export-csv.sh diff --git a/iotdb/script/import-csv.bat b/iotdb-cli/cli/bin/import-csv.bat similarity index 100% rename from iotdb/script/import-csv.bat rename to iotdb-cli/cli/bin/import-csv.bat diff --git a/iotdb/script/import-csv.sh b/iotdb-cli/cli/bin/import-csv.sh similarity index 100% rename from iotdb/script/import-csv.sh rename to iotdb-cli/cli/bin/import-csv.sh diff --git a/iotdb/iotdb/bin/run-client.bat b/iotdb-cli/cli/bin/run-client.bat similarity index 100% rename from iotdb/iotdb/bin/run-client.bat rename to iotdb-cli/cli/bin/run-client.bat diff --git a/iotdb/iotdb/bin/start-client.bat b/iotdb-cli/cli/bin/start-client.bat similarity index 100% rename from iotdb/iotdb/bin/start-client.bat rename to iotdb-cli/cli/bin/start-client.bat diff --git a/iotdb/iotdb/bin/start-client.sh b/iotdb-cli/cli/bin/start-client.sh similarity index 100% rename from iotdb/iotdb/bin/start-client.sh rename to iotdb-cli/cli/bin/start-client.sh diff --git a/iotdb-cli/pom.xml b/iotdb-cli/pom.xml new file mode 100644 index 00000000000..d11b9da9e6d --- /dev/null +++ b/iotdb-cli/pom.xml @@ -0,0 +1,118 @@ + + 4.0.0 + + + cn.edu.tsinghua + root + 0.8.0-SNAPSHOT + ../pom.xml + + + iotdb-cli + jar + + IoTDB Cli + A Client tool. + https://github.com/thulab/iotdb/tree/master/cli + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + false + 1.3.1 + 2.14.5 + + + + + cn.edu.tsinghua + iotdb-jdbc + ${project.version} + + + commons-cli + commons-cli + ${common.cli.version} + + + jline + jline + ${jline.version} + + + + + + + maven-clean-plugin + 3.1.0 + + + + ${project.basedir}/cli/lib + + **/*.jar + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + copy-dependencies + package + + copy-dependencies + + + ${project.basedir}/cli/lib + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + copy-native-libraries + package + + run + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + ${cli.test.skip} + + + + + diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java similarity index 91% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java index bfc8b55ee3f..c7c6fc96435 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/AbstractClient.java @@ -1,13 +1,11 @@ package cn.edu.tsinghua.iotdb.client; -import cn.edu.tsinghua.iotdb.conf.TsFileDBConstant; import cn.edu.tsinghua.iotdb.exception.ArgsErrorException; import cn.edu.tsinghua.iotdb.jdbc.TsfileDatabaseMetadata; import cn.edu.tsinghua.iotdb.jdbc.TsfileMetadataResultSet; import cn.edu.tsinghua.iotdb.tool.ImportCsv; - +import cn.edu.tsinghua.service.rpc.thrift.ServerProperties; import cn.edu.tsinghua.iotdb.jdbc.TsfileConnection; -import cn.edu.tsinghua.iotdb.query.aggregation.AggregationConstant; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -66,16 +64,33 @@ public abstract class AbstractClient { protected static final String IOTDB_CLI_PREFIX = "IoTDB"; protected static final String SCRIPT_HINT = "./start-client.sh(start-client.bat if Windows)"; - private static final String QUIT_COMMAND = "quit"; - private static final String EXIT_COMMAND = "exit"; - private static final String SHOW_METADATA_COMMAND = "show timeseries"; + protected static final String QUIT_COMMAND = "quit"; + protected static final String EXIT_COMMAND = "exit"; + protected static final String SHOW_METADATA_COMMAND = "show timeseries"; protected static final int MAX_HELP_CONSOLE_WIDTH = 88; protected static final String TIMESTAMP_STR = "Time"; protected static final int ISO_DATETIME_LEN = 23; protected static int maxTimeLength = ISO_DATETIME_LEN; protected static int maxValueLength = 15; - protected static int[] maxValueLengthForShow = new int[]{75, 45, 8, 8};// control the width of columns for 'show timeseries ' and 'show storage group' + /** + * control the width of columns for 'show timeseries ' and 'show storage group' + *

for 'show timeseries ': + * + * + * + * + *
Timeseries (width:75) Storage Group (width:45) DataType width:8) Encoding (width:8)
root.vehicle.d1.s1 root.vehicle INT32 PLAIN
... ... ... ...
+ *

+ *

for show storage group ': + * + * + * + * + *
STORAGE_GROUP (width:75)
root.vehicle
...
+ *

+ */ + protected static int[] maxValueLengthForShow = new int[]{75, 45, 8, 8}; protected static String formatTime = "%" + maxTimeLength + "s|"; protected static String formatValue = "%" + maxValueLength + "s|"; @@ -94,6 +109,8 @@ public abstract class AbstractClient { protected static boolean printToConsole = true; protected static Set keywordSet = new HashSet<>(); + + protected static ServerProperties properties = null; protected static void init(){ keywordSet.add("-"+HOST_ARGS); @@ -103,9 +120,6 @@ public abstract class AbstractClient { keywordSet.add("-"+USERNAME_ARGS); keywordSet.add("-"+ISO8601_ARGS); keywordSet.add("-"+MAX_PRINT_ROW_COUNT_ARGS); - - AGGREGRATE_TIME_LIST.add(AggregationConstant.MAX_TIME); - AGGREGRATE_TIME_LIST.add(AggregationConstant.MIN_TIME); } public static void output(ResultSet res, boolean printToConsole, String statement, DateTimeZone timeZone) throws SQLException { @@ -253,7 +267,7 @@ public abstract class AbstractClient { System.out.println("Use -help for more information"); throw new ArgsErrorException(msg); } else if (defaultValue == null){ - String msg = String.format("%s: Required values for option '%s' is null", IOTDB_CLI_PREFIX, name); + String msg = String.format("%s: Required values for option '%s' is null.", IOTDB_CLI_PREFIX, name); throw new ArgsErrorException(msg); } else { return defaultValue; @@ -286,13 +300,20 @@ public abstract class AbstractClient { } private static void setFetchSize(String fetchSizeString){ - fetchSize = Integer.parseInt(fetchSizeString.trim()); + long tmp = Long.parseLong(fetchSizeString.trim()); + if(tmp > Integer.MAX_VALUE || tmp < 0) { + fetchSize = Integer.MAX_VALUE; + } else { + fetchSize = Integer.parseInt(fetchSizeString.trim()); + } } protected static void setMaxDisplayNumber(String maxDisplayNum){ - maxPrintRowCount = Integer.parseInt(maxDisplayNum.trim()); - if (maxPrintRowCount < 0) { + long tmp = Long.parseLong(maxDisplayNum.trim()); + if(tmp > Integer.MAX_VALUE || tmp < 0) { maxPrintRowCount = Integer.MAX_VALUE; + } else { + maxPrintRowCount = Integer.parseInt(maxDisplayNum.trim()); } } @@ -341,7 +362,7 @@ public abstract class AbstractClient { System.out.printf("\n"); } - protected static String[] checkPasswordArgs(String[] args) { + protected static String[] removePasswordArgs(String[] args) { int index = -1; for(int i = 0; i < args.length; i++){ if(args[i].equals("-"+PASSWORD_ARGS)){ @@ -349,7 +370,7 @@ public abstract class AbstractClient { break; } } - if(index > 0){ + if(index >= 0){ if((index+1 >= args.length) || (index+1 < args.length && keywordSet.contains(args[index+1]))){ return ArrayUtils.remove(args, index); } @@ -357,14 +378,14 @@ public abstract class AbstractClient { return args; } - protected static void displayLogo(){ + protected static void displayLogo(String version){ System.out.println( " _____ _________ ______ ______ \n" + "|_ _| | _ _ ||_ _ `.|_ _ \\ \n" + " | | .--.|_/ | | \\_| | | `. \\ | |_) | \n" + " | | / .'`\\ \\ | | | | | | | __'. \n" + " _| |_| \\__. | _| |_ _| |_.' /_| |__) | \n" + - "|_____|'.__.' |_____| |______.'|_______/ version "+TsFileDBConstant.VERSION+"\n" + + "|_____|'.__.' |_____| |______.'|_______/ version "+version+"\n" + " \n"); } diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java similarity index 98% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java index 4298422f29a..a3d335d5cf3 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/Client.java @@ -66,7 +66,7 @@ public class Client extends AbstractClient { return; } init(); - args = checkPasswordArgs(args); + args = removePasswordArgs(args); try { commandLine = parser.parse(options, args); if (commandLine.hasOption(HELP_ARGS)) { @@ -111,6 +111,8 @@ public class Client extends AbstractClient { } try { connection = (TsfileConnection) DriverManager.getConnection("jdbc:tsfile://" + host + ":" + port + "/", username, password); + properties = connection.getServerProperties(); + AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations()); } catch (SQLException e) { System.out.println(String.format("%s> %s. Host is %s, port is %s.", IOTDB_CLI_PREFIX, e.getMessage(), host, port)); return; @@ -121,7 +123,7 @@ public class Client extends AbstractClient { return; } - displayLogo(); + displayLogo(properties.getVersion()); System.out.println(IOTDB_CLI_PREFIX + "> login successfully"); while (true) { diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java similarity index 95% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java index 783d47032e3..09990109194 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/client/WinClient.java @@ -35,7 +35,7 @@ public class WinClient extends AbstractClient { init(); - args = checkPasswordArgs(args); + args = removePasswordArgs(args); try { commandLine = parser.parse(options, args); @@ -78,6 +78,8 @@ public class WinClient extends AbstractClient { try { connection = (TsfileConnection) DriverManager.getConnection("jdbc:tsfile://" + host + ":" + port + "/", username, password); + properties = connection.getServerProperties(); + AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations()); } catch (SQLException e) { System.out.println(IOTDB_CLI_PREFIX + "> " + e.getMessage()); return; @@ -87,7 +89,7 @@ public class WinClient extends AbstractClient { return; } - displayLogo(); + displayLogo(properties.getVersion()); System.out.println(IOTDB_CLI_PREFIX + "> login successfully"); scanner = new Scanner(System.in); diff --git a/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/exception/ArgsErrorException.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/exception/ArgsErrorException.java new file mode 100644 index 00000000000..3d903302ac4 --- /dev/null +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/exception/ArgsErrorException.java @@ -0,0 +1,11 @@ +package cn.edu.tsinghua.iotdb.exception; + +public class ArgsErrorException extends Exception{ + + private static final long serialVersionUID = -3614543017182165265L; + + public ArgsErrorException(String msg){ + super(msg); + } + +} diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/AbstractCsvTool.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/AbstractCsvTool.java similarity index 100% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/AbstractCsvTool.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/AbstractCsvTool.java diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java similarity index 96% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java index de96a1f62e9..9c718d28472 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/CsvTestDataGen.java @@ -1,122 +1,122 @@ -package cn.edu.tsinghua.iotdb.tool; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; - -public class CsvTestDataGen { - private static String [] iso = { - "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", - "1970-01-01T08:00:00.001+08:00,,1,pass,1,1", - "1970-01-01T08:00:00.002+08:00,,2,pass,,", - "1970-01-01T08:00:00.003+08:00,,3,pass,,", - "1970-01-01T08:00:00.004+08:00,4,,,4,4" - }; - private static String [] defaultLong = { - "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", - "1,,1,pass,1,1", - "2,,2,pass,,", - "1970-01-01T08:00:00.003+08:00,,3,pass,,", - "3,4,,,4,4" - }; - private static String [] userSelfDefine = { - "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", - "1971,,1,pass,1,1", - "1972,,2,pass,,", - "1973-01-01T08:00:00.003+08:00,,3,pass,,", - "1974,4,,,4,4" - }; - private static BufferedWriter bw = null; - - public static String isoDataGen() { - String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/iso.csv"; - File file = new File(path); - - try { - if(!file.exists()) { - file.createNewFile(); - } - bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); - for(String str : iso) { - bw.write(str + "\n"); - } - bw.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }finally { - try { - bw.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return path; - } - public static String defaultLongDataGen() { - String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/defaultLong.csv"; - File file = new File(path); - try { - if(!file.exists()) { - file.createNewFile(); - } - bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); - for(String str : defaultLong) { - bw.write(str + "\n"); - } - bw.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }finally { - try { - bw.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return path; - } - - public static String userSelfDataGen() { - String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/userSelfDefine.csv"; - File file = new File(path); - try { - if(!file.exists()) { - file.createNewFile(); - } - bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); - for(String str : userSelfDefine) { - bw.write(str + "\n"); - } - bw.flush(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }finally { - try { - bw.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return path; - } - - public static void main(String[] args){ - System.out.println(defaultLongDataGen()); - } - -} +package cn.edu.tsinghua.iotdb.tool; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; + +public class CsvTestDataGen { + private static String [] iso = { + "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", + "1970-01-01T08:00:00.001+08:00,,1,pass,1,1", + "1970-01-01T08:00:00.002+08:00,,2,pass,,", + "1970-01-01T08:00:00.003+08:00,,3,pass,,", + "1970-01-01T08:00:00.004+08:00,4,,,4,4" + }; + private static String [] defaultLong = { + "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", + "1,,1,pass,1,1", + "2,,2,pass,,", + "1970-01-01T08:00:00.003+08:00,,3,pass,,", + "3,4,,,4,4" + }; + private static String [] userSelfDefine = { + "Time,root.fit.p.s1,root.fit.d1.s1,root.fit.d1.s2,root.fit.d2.s1,root.fit.d2.s3", + "1971,,1,pass,1,1", + "1972,,2,pass,,", + "1973-01-01T08:00:00.003+08:00,,3,pass,,", + "1974,4,,,4,4" + }; + private static BufferedWriter bw = null; + + public static String isoDataGen() { + String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/iso.csv"; + File file = new File(path); + + try { + if(!file.exists()) { + file.createNewFile(); + } + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); + for(String str : iso) { + bw.write(str + "\n"); + } + bw.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return path; + } + public static String defaultLongDataGen() { + String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/defaultLong.csv"; + File file = new File(path); + try { + if(!file.exists()) { + file.createNewFile(); + } + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); + for(String str : defaultLong) { + bw.write(str + "\n"); + } + bw.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return path; + } + + public static String userSelfDataGen() { + String path = System.getProperties().getProperty("user.dir") + "/src/test/resources/userSelfDefine.csv"; + File file = new File(path); + try { + if(!file.exists()) { + file.createNewFile(); + } + bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); + for(String str : userSelfDefine) { + bw.write(str + "\n"); + } + bw.flush(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally { + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return path; + } + + public static void main(String[] args){ + System.out.println(defaultLongDataGen()); + } + +} diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/ExportCsv.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/ExportCsv.java similarity index 100% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/ExportCsv.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/ExportCsv.java diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java similarity index 98% rename from iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java rename to iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java index b03d6ba1cf3..fb94eb265a4 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java +++ b/iotdb-cli/src/main/java/cn/edu/tsinghua/iotdb/tool/ImportCsv.java @@ -20,6 +20,7 @@ import java.util.Map; import cn.edu.tsinghua.iotdb.jdbc.TsfileConnection; import cn.edu.tsinghua.iotdb.jdbc.TsfileJDBCConfig; + import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; @@ -30,7 +31,6 @@ import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; import org.apache.thrift.TException; -import cn.edu.tsinghua.iotdb.conf.TsFileDBConstant; import cn.edu.tsinghua.iotdb.exception.ArgsErrorException; import jline.console.ConsoleReader; @@ -330,16 +330,18 @@ public class ImportCsv extends AbstractCsvTool{ } public static void importCsvFromFile(String ip,String port, String username, String password, String filename, String timeZone) throws SQLException{ - if (System.getProperty(TsFileDBConstant.IOTDB_HOME) == null) { - errorInsertInfo = ERROR_INFO_STR; - } else { - errorInsertInfo = System.getProperty(TsFileDBConstant.IOTDB_HOME) + File.separatorChar + ERROR_INFO_STR; - } + String property = System.getProperty("IOTDB_HOME"); + if (property == null) { + errorInsertInfo = ERROR_INFO_STR; + } else { + errorInsertInfo = property + File.separatorChar + ERROR_INFO_STR; + } try { Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); connection = (TsfileConnection) DriverManager.getConnection("jdbc:tsfile://" + ip + ":" + port + "/", username, password); timeZoneID = timeZone; setTimeZone(); + File file = new File(filename); if(file.isFile()){ if(file.getName().endsWith(FILE_SUFFIX)){ diff --git a/iotdb-cli/src/test/java/cn/edu/tsinghua/iotdb/client/AbstractClientTest.java b/iotdb-cli/src/test/java/cn/edu/tsinghua/iotdb/client/AbstractClientTest.java new file mode 100644 index 00000000000..b71ab3ca1c3 --- /dev/null +++ b/iotdb-cli/src/test/java/cn/edu/tsinghua/iotdb/client/AbstractClientTest.java @@ -0,0 +1,185 @@ +package cn.edu.tsinghua.iotdb.client; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import cn.edu.tsinghua.iotdb.client.AbstractClient.OPERATION_RESULT; +import cn.edu.tsinghua.iotdb.exception.ArgsErrorException; +import cn.edu.tsinghua.iotdb.jdbc.TsfileConnection; +import cn.edu.tsinghua.iotdb.jdbc.TsfileDatabaseMetadata; + +public class AbstractClientTest { + + + @Mock + private TsfileConnection connection; + + @Mock + private TsfileDatabaseMetadata databaseMetadata; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(connection.getMetaData()).thenReturn(databaseMetadata); + when(connection.getTimeZone()).thenReturn("Asia/Shanghai"); + when(databaseMetadata.getMetadataInJson()).thenReturn("test metadata"); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testInit() { + AbstractClient.init(); + String[] keywords = { + AbstractClient.HOST_ARGS, + AbstractClient.HELP_ARGS, + AbstractClient.PORT_ARGS, + AbstractClient.PASSWORD_ARGS, + AbstractClient.USERNAME_ARGS, + AbstractClient.ISO8601_ARGS, + AbstractClient.MAX_PRINT_ROW_COUNT_ARGS, + }; + for(String keyword: keywords) { + if(!AbstractClient.keywordSet.contains("-"+keyword)) { + System.out.println(keyword); + fail(); + } + } + } + + @Test + public void testCheckRequiredArg() throws ParseException, ArgsErrorException { + Options options = AbstractClient.createOptions(); + CommandLineParser parser = new DefaultParser(); + String[] args = new String[]{"-u", "user1"}; + CommandLine commandLine = parser.parse(options, args); + String str = AbstractClient.checkRequiredArg(AbstractClient.USERNAME_ARGS, AbstractClient.USERNAME_NAME, commandLine, true, "root"); + assertEquals(str, "user1"); + + args = new String[]{"-u", "root",}; + commandLine = parser.parse(options, args); + str = AbstractClient.checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine, false, "127.0.0.1"); + assertEquals(str, "127.0.0.1"); + try { + str = AbstractClient.checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine, true, "127.0.0.1"); + } catch (ArgsErrorException e) { + assertEquals(e.getMessage(), "IoTDB: Required values for option 'host' not provided"); + } + try { + str = AbstractClient.checkRequiredArg(AbstractClient.HOST_ARGS, AbstractClient.HOST_NAME, commandLine, false, null); + } catch (ArgsErrorException e) { + assertEquals(e.getMessage(), "IoTDB: Required values for option 'host' is null."); + } + } + + @Test + public void testRemovePasswordArgs() { + AbstractClient.init(); + String[] input = new String[] {"-h", "127.0.0.1", "-p", "6667", "-u", "root", "-pw", "root"}; + String[] res = new String[] {"-h", "127.0.0.1", "-p", "6667", "-u", "root", "-pw", "root"}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + + input = new String[]{"-h", "127.0.0.1", "-p", "6667", "-pw", "root", "-u", "root"}; + res = new String[]{"-h", "127.0.0.1", "-p", "6667", "-pw", "root", "-u", "root"}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + + input = new String[]{"-h", "127.0.0.1", "-p", "6667", "root", "-u", "root", "-pw"}; + res = new String[]{"-h", "127.0.0.1", "-p", "6667", "root", "-u", "root"}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + + input = new String[]{"-h", "127.0.0.1", "-p", "6667", "-pw", "-u", "root"}; + res = new String[]{"-h", "127.0.0.1", "-p", "6667", "-u", "root"}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + + input = new String[]{"-pw", "-h", "127.0.0.1", "-p", "6667", "root", "-u", "root"}; + res = new String[]{"-h", "127.0.0.1", "-p", "6667", "root", "-u", "root"}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + + input = new String[]{}; + res = new String[]{}; + isTwoStringArrayEqual(res, AbstractClient.removePasswordArgs(input)); + } + + private void isTwoStringArrayEqual(String[] expected, String[] actual) { + for(int i = 0; i < expected.length;i++) { + assertEquals(expected[i], actual[i]); + } + } + + @Test + public void testHandleInputInputCmd() { + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.EXIT_COMMAND, connection), OPERATION_RESULT.RETURN_OPER); + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.QUIT_COMMAND, connection), OPERATION_RESULT.RETURN_OPER); + + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_METADATA_COMMAND, connection), OPERATION_RESULT.CONTINUE_OPER); + + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=default", AbstractClient.SET_TIMESTAMP_DISPLAY), connection), OPERATION_RESULT.CONTINUE_OPER); + testSetTimeFormat(); + + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=xxx", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=1", AbstractClient.SET_MAX_DISPLAY_NUM), connection), OPERATION_RESULT.CONTINUE_OPER); + testSetMaxDisplayNumber(); + + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMEZONE, connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_TIMESTAMP_DISPLAY, connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(AbstractClient.SHOW_FETCH_SIZE, connection), OPERATION_RESULT.CONTINUE_OPER); + + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_TIME_ZONE), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=+08:00", AbstractClient.SET_TIME_ZONE), connection), OPERATION_RESULT.CONTINUE_OPER); + + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=", AbstractClient.SET_FETCH_SIZE), connection), OPERATION_RESULT.CONTINUE_OPER); + assertEquals(AbstractClient.handleInputInputCmd(String.format("%s=111", AbstractClient.SET_FETCH_SIZE), connection), OPERATION_RESULT.CONTINUE_OPER); + } + + private void testSetTimeFormat() { + AbstractClient.setTimeFormat("long"); + assertEquals(AbstractClient.maxTimeLength, AbstractClient.maxValueLength); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + AbstractClient.setTimeFormat("number"); + assertEquals(AbstractClient.maxTimeLength, AbstractClient.maxValueLength); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + AbstractClient.setTimeFormat("default"); + assertEquals(AbstractClient.maxTimeLength, AbstractClient.ISO_DATETIME_LEN); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + AbstractClient.setTimeFormat("iso8601"); + assertEquals(AbstractClient.maxTimeLength, AbstractClient.ISO_DATETIME_LEN); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + AbstractClient.setTimeFormat("yyyy-MM-dd HH:mm:ssZZ"); + assertEquals(AbstractClient.maxTimeLength, "yyyy-MM-dd HH:mm:ssZZ".length()); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + AbstractClient.setTimeFormat("dd"); + assertEquals(AbstractClient.maxTimeLength, AbstractClient.TIMESTAMP_STR.length()); + assertEquals(AbstractClient.formatTime, "%" + AbstractClient.maxTimeLength + "s|"); + + } + + private void testSetMaxDisplayNumber() { + AbstractClient.setMaxDisplayNumber("10"); + assertEquals(AbstractClient.maxPrintRowCount, 10); + AbstractClient.setMaxDisplayNumber("111111111111111"); + assertEquals(AbstractClient.maxPrintRowCount, Integer.MAX_VALUE); + AbstractClient.setMaxDisplayNumber("-10"); + assertEquals(AbstractClient.maxPrintRowCount, Integer.MAX_VALUE); + } +} diff --git a/iotdb/pom.xml b/iotdb/pom.xml index 3601018d65b..9a0ca79a8f0 100644 --- a/iotdb/pom.xml +++ b/iotdb/pom.xml @@ -16,19 +16,28 @@ https://github.com/thulab/iotdb/tree/master/iotdb - 1.3.1 3.5.2 - 2.14.5 false **/*Test.java **/NoTest.java + + cn.edu.tsinghua + service-rpc + ${project.version} + + + cn.edu.tsinghua + tsfile + ${project.version} + cn.edu.tsinghua iotdb-jdbc ${project.version} + test cn.edu.fudan.dsm @@ -57,11 +66,7 @@ - - commons-cli - commons-cli - ${common.cli.version} - + org.apache.commons commons-collections4 @@ -72,11 +77,6 @@ antlr3-maven-plugin ${antlr3.version} - - jline - jline - ${jline.version} - @@ -124,6 +124,22 @@ + + maven-clean-plugin + 3.1.0 + + + + ${project.basedir}/iotdb/lib + + **/*.jar + + false + + + + + org.apache.maven.plugins maven-dependency-plugin diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/receiver/ServerServiceImpl.java b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/receiver/ServerServiceImpl.java index 4c887bcdb8c..bd2b410574b 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/receiver/ServerServiceImpl.java +++ b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/receiver/ServerServiceImpl.java @@ -36,7 +36,6 @@ import cn.edu.tsinghua.iotdb.engine.filenode.FileNodeManager; import cn.edu.tsinghua.iotdb.engine.filenode.IntervalFileNode; import cn.edu.tsinghua.iotdb.engine.filenode.OverflowChangeType; import cn.edu.tsinghua.iotdb.exception.FileNodeManagerException; -import cn.edu.tsinghua.iotdb.jdbc.TsfileJDBCConfig; import cn.edu.tsinghua.tsfile.file.metadata.RowGroupMetaData; import cn.edu.tsinghua.tsfile.file.metadata.TimeSeriesChunkMetaData; import cn.edu.tsinghua.tsfile.file.metadata.TimeSeriesChunkProperties; @@ -56,7 +55,7 @@ import cn.edu.tsinghua.tsfile.timeseries.read.support.Path; * @author lta */ public class ServerServiceImpl implements ServerService.Iface { - + private final String JDBC_DRIVER_NAME = "cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"; private ThreadLocal uuid = new ThreadLocal(); private ThreadLocal>> fileNodeMap = new ThreadLocal<>(); // String means Storage Group, // List means the set of new Files(AbsulutePath) in local IoTDB @@ -191,7 +190,7 @@ public class ServerServiceImpl implements ServerService.Iface { Connection connection = null; Statement statement = null; try { - Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); + Class.forName(JDBC_DRIVER_NAME); connection = DriverManager.getConnection("jdbc:tsfile://localhost:" + tsfileDBConfig.rpcPort + "/", "root", "root"); statement = connection.createStatement(); @@ -349,7 +348,7 @@ public class ServerServiceImpl implements ServerService.Iface { Connection connection = null; Statement statement = null; try { - Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); + Class.forName(JDBC_DRIVER_NAME); connection = DriverManager.getConnection("jdbc:tsfile://localhost:" + tsfileDBConfig.rpcPort + "/", "root", "root"); statement = connection.createStatement(); @@ -455,7 +454,7 @@ public class ServerServiceImpl implements ServerService.Iface { Connection connection = null; Statement statement = null; try { - Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); + Class.forName(JDBC_DRIVER_NAME); connection = DriverManager.getConnection("jdbc:tsfile://localhost:" + tsfileDBConfig.rpcPort + "/", "root", "root"); statement = connection.createStatement(); diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/sender/FileSenderImpl.java b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/sender/FileSenderImpl.java index 93428c89251..0026f1f3ee4 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/sender/FileSenderImpl.java +++ b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/postback/sender/FileSenderImpl.java @@ -45,7 +45,6 @@ import org.slf4j.LoggerFactory; import cn.edu.tsinghua.tsfile.file.metadata.TsDeltaObject; import cn.edu.tsinghua.tsfile.timeseries.read.TsRandomAccessLocalFileReader; import cn.edu.tsinghua.iotdb.conf.TsfileDBDescriptor; -import cn.edu.tsinghua.iotdb.jdbc.TsfileJDBCConfig; import cn.edu.tsinghua.iotdb.postback.conf.PostBackSenderConfig; import cn.edu.tsinghua.iotdb.postback.conf.PostBackSenderDescriptor; import cn.edu.tsinghua.iotdb.utils.PostbackUtils; @@ -55,6 +54,7 @@ import cn.edu.tsinghua.iotdb.utils.PostbackUtils; * @author lta */ public class FileSenderImpl implements FileSender{ + private final String JDBC_DRIVER_NAME = "cn.edu.tsinghua.iotdb.jdbc.TsfileDriver"; private TTransport transport; private ServerService.Client clientOfServer; @@ -310,7 +310,7 @@ public class FileSenderImpl implements FileSender{ TsRandomAccessLocalFileReader input = null; String deleteFormat = "delete from %s.* where time <= %s"; try { - Class.forName(TsfileJDBCConfig.JDBC_DRIVER_NAME); + Class.forName(JDBC_DRIVER_NAME); connection = DriverManager.getConnection( "jdbc:tsfile://localhost:" + TsfileDBDescriptor.getInstance().getConfig().rpcPort + "/", "root", "root"); diff --git a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java index 81006f74f60..a48975a5363 100644 --- a/iotdb/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java +++ b/iotdb/src/main/java/cn/edu/tsinghua/iotdb/service/TSServiceImpl.java @@ -24,6 +24,8 @@ import cn.edu.tsinghua.iotdb.qp.physical.PhysicalPlan; import cn.edu.tsinghua.iotdb.qp.physical.crud.IndexQueryPlan; import cn.edu.tsinghua.iotdb.qp.physical.crud.MultiQueryPlan; import cn.edu.tsinghua.iotdb.qp.physical.sys.AuthorPlan; +import cn.edu.tsinghua.iotdb.query.aggregation.AggregateFunction; +import cn.edu.tsinghua.iotdb.query.aggregation.AggregationConstant; import cn.edu.tsinghua.iotdb.query.management.ReadCacheManager; import cn.edu.tsinghua.iotdb.queryV2.engine.control.QueryJobManager; import cn.edu.tsinghua.service.rpc.thrift.*; @@ -752,4 +754,14 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext { TSSetTimeZoneResp resp = new TSSetTimeZoneResp(ts_status); return resp; } + + @Override + public ServerProperties getProperties() throws TException { + ServerProperties properties = new ServerProperties(); + properties.setVersion(TsFileDBConstant.VERSION); + properties.setSupportedTimeAggregationOperations(new ArrayList<>()); + properties.getSupportedTimeAggregationOperations().add(AggregationConstant.MAX_TIME); + properties.getSupportedTimeAggregationOperations().add(AggregationConstant.MIN_TIME); + return properties; + } } diff --git a/jdbc/pom.xml b/jdbc/pom.xml index caeca72d692..cd21a519d9e 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -44,11 +44,6 @@ tsfile ${project.version} - - joda-time - joda-time - ${joda.version} - cn.edu.tsinghua service-rpc @@ -76,6 +71,26 @@ + + maven-assembly-plugin + 3.1.0 + + + jar-with-dependencies + + + + + make-assembly + + package + + + single + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/jdbc/src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnection.java b/jdbc/src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnection.java index b14976da748..841820143c2 100644 --- a/jdbc/src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnection.java +++ b/jdbc/src/main/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnection.java @@ -6,6 +6,7 @@ import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransportException; import org.joda.time.DateTimeZone; +import cn.edu.tsinghua.service.rpc.thrift.ServerProperties; import cn.edu.tsinghua.service.rpc.thrift.TSCloseSessionReq; import cn.edu.tsinghua.service.rpc.thrift.TSGetTimeZoneResp; import cn.edu.tsinghua.service.rpc.thrift.TSIService; @@ -455,6 +456,10 @@ public class TsfileConnection implements Connection { return resp.getTimeZone(); } + public ServerProperties getServerProperties() throws TException { + return client.getProperties(); + } + public static TSIService.Iface newSynchronizedClient(TSIService.Iface client) { return (TSIService.Iface) Proxy.newProxyInstance(TsfileConnection.class.getClassLoader(), new Class[] { TSIService.Iface.class }, new SynchronizedHandler(client)); diff --git a/jdbc/src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionTest.java b/jdbc/src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionTest.java index daac7ecd0b8..d8dd5dcb215 100644 --- a/jdbc/src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionTest.java +++ b/jdbc/src/test/java/cn/edu/tsinghua/iotdb/jdbc/TsfileConnectionTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import cn.edu.tsinghua.service.rpc.thrift.ServerProperties; import cn.edu.tsinghua.service.rpc.thrift.TSGetTimeZoneResp; import cn.edu.tsinghua.service.rpc.thrift.TSIService; import cn.edu.tsinghua.service.rpc.thrift.TSSetTimeZoneReq; @@ -18,6 +19,9 @@ import cn.edu.tsinghua.service.rpc.thrift.TS_StatusCode; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; + import org.apache.thrift.TException; @@ -54,5 +58,19 @@ public class TsfileConnectionTest { assertEquals(connection.getTimeZone(), timeZone); } - + @Test + public void testGetServerProperties() throws TsfileSQLException, TException { + final String version = "v0.1"; + @SuppressWarnings("serial") + final List supportedAggregationTime = new ArrayList() {{ + add("max_time"); + add("min_time"); + }}; + when(client.getProperties()).thenReturn(new ServerProperties(version, supportedAggregationTime)); + connection.client = client; + assertEquals(connection.getServerProperties().getVersion(), version); + for(int i = 0; i < supportedAggregationTime.size();i++) { + assertEquals(connection.getServerProperties().getSupportedTimeAggregationOperations().get(i), supportedAggregationTime.get(i)); + } + } } diff --git a/pom.xml b/pom.xml index b241c4b5dd3..c56903f7836 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,11 @@ ${junit.version} test + + joda-time + joda-time + ${joda.version} + org.mockito mockito-all @@ -136,6 +141,7 @@ iotdb grafana service-rpc + iotdb-cli @@ -180,42 +186,7 @@ - - org.apache.maven.plugins - maven-dependency-plugin - 2.10 - - - copy-dependencies - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.5.5 - - - - - jar-with-dependencies - - - make-assembly - package - - single - - - - + org.codehaus.mojo diff --git a/service-rpc/interface/rpc.thrift b/service-rpc/interface/rpc.thrift index 8aa277e8899..3112aaf95f8 100644 --- a/service-rpc/interface/rpc.thrift +++ b/service-rpc/interface/rpc.thrift @@ -229,6 +229,11 @@ struct TSSetTimeZoneResp { 1: required TS_Status status } +struct ServerProperties { + 1: required string version; + 2: required list supportedTimeAggregationOperations; +} + service TSIService { TSOpenSessionResp openSession(1:TSOpenSessionReq req); @@ -253,4 +258,6 @@ service TSIService { TSGetTimeZoneResp getTimeZone(); TSSetTimeZoneResp setTimeZone(1:TSSetTimeZoneReq req); -} + + ServerProperties getProperties(); + } diff --git a/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/ServerProperties.java b/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/ServerProperties.java new file mode 100644 index 00000000000..e7717b3de69 --- /dev/null +++ b/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/ServerProperties.java @@ -0,0 +1,526 @@ +/** + * Autogenerated by Thrift Compiler (0.9.1) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package cn.edu.tsinghua.service.rpc.thrift; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServerProperties implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ServerProperties"); + + private static final org.apache.thrift.protocol.TField VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("version", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField SUPPORTED_TIME_AGGREGATION_OPERATIONS_FIELD_DESC = new org.apache.thrift.protocol.TField("supportedTimeAggregationOperations", org.apache.thrift.protocol.TType.LIST, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new ServerPropertiesStandardSchemeFactory()); + schemes.put(TupleScheme.class, new ServerPropertiesTupleSchemeFactory()); + } + + public String version; // required + public List supportedTimeAggregationOperations; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + VERSION((short)1, "version"), + SUPPORTED_TIME_AGGREGATION_OPERATIONS((short)2, "supportedTimeAggregationOperations"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // VERSION + return VERSION; + case 2: // SUPPORTED_TIME_AGGREGATION_OPERATIONS + return SUPPORTED_TIME_AGGREGATION_OPERATIONS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.VERSION, new org.apache.thrift.meta_data.FieldMetaData("version", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.SUPPORTED_TIME_AGGREGATION_OPERATIONS, new org.apache.thrift.meta_data.FieldMetaData("supportedTimeAggregationOperations", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ServerProperties.class, metaDataMap); + } + + public ServerProperties() { + } + + public ServerProperties( + String version, + List supportedTimeAggregationOperations) + { + this(); + this.version = version; + this.supportedTimeAggregationOperations = supportedTimeAggregationOperations; + } + + /** + * Performs a deep copy on other. + */ + public ServerProperties(ServerProperties other) { + if (other.isSetVersion()) { + this.version = other.version; + } + if (other.isSetSupportedTimeAggregationOperations()) { + List __this__supportedTimeAggregationOperations = new ArrayList(other.supportedTimeAggregationOperations); + this.supportedTimeAggregationOperations = __this__supportedTimeAggregationOperations; + } + } + + public ServerProperties deepCopy() { + return new ServerProperties(this); + } + + @Override + public void clear() { + this.version = null; + this.supportedTimeAggregationOperations = null; + } + + public String getVersion() { + return this.version; + } + + public ServerProperties setVersion(String version) { + this.version = version; + return this; + } + + public void unsetVersion() { + this.version = null; + } + + /** Returns true if field version is set (has been assigned a value) and false otherwise */ + public boolean isSetVersion() { + return this.version != null; + } + + public void setVersionIsSet(boolean value) { + if (!value) { + this.version = null; + } + } + + public int getSupportedTimeAggregationOperationsSize() { + return (this.supportedTimeAggregationOperations == null) ? 0 : this.supportedTimeAggregationOperations.size(); + } + + public java.util.Iterator getSupportedTimeAggregationOperationsIterator() { + return (this.supportedTimeAggregationOperations == null) ? null : this.supportedTimeAggregationOperations.iterator(); + } + + public void addToSupportedTimeAggregationOperations(String elem) { + if (this.supportedTimeAggregationOperations == null) { + this.supportedTimeAggregationOperations = new ArrayList(); + } + this.supportedTimeAggregationOperations.add(elem); + } + + public List getSupportedTimeAggregationOperations() { + return this.supportedTimeAggregationOperations; + } + + public ServerProperties setSupportedTimeAggregationOperations(List supportedTimeAggregationOperations) { + this.supportedTimeAggregationOperations = supportedTimeAggregationOperations; + return this; + } + + public void unsetSupportedTimeAggregationOperations() { + this.supportedTimeAggregationOperations = null; + } + + /** Returns true if field supportedTimeAggregationOperations is set (has been assigned a value) and false otherwise */ + public boolean isSetSupportedTimeAggregationOperations() { + return this.supportedTimeAggregationOperations != null; + } + + public void setSupportedTimeAggregationOperationsIsSet(boolean value) { + if (!value) { + this.supportedTimeAggregationOperations = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case VERSION: + if (value == null) { + unsetVersion(); + } else { + setVersion((String)value); + } + break; + + case SUPPORTED_TIME_AGGREGATION_OPERATIONS: + if (value == null) { + unsetSupportedTimeAggregationOperations(); + } else { + setSupportedTimeAggregationOperations((List)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case VERSION: + return getVersion(); + + case SUPPORTED_TIME_AGGREGATION_OPERATIONS: + return getSupportedTimeAggregationOperations(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case VERSION: + return isSetVersion(); + case SUPPORTED_TIME_AGGREGATION_OPERATIONS: + return isSetSupportedTimeAggregationOperations(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof ServerProperties) + return this.equals((ServerProperties)that); + return false; + } + + public boolean equals(ServerProperties that) { + if (that == null) + return false; + + boolean this_present_version = true && this.isSetVersion(); + boolean that_present_version = true && that.isSetVersion(); + if (this_present_version || that_present_version) { + if (!(this_present_version && that_present_version)) + return false; + if (!this.version.equals(that.version)) + return false; + } + + boolean this_present_supportedTimeAggregationOperations = true && this.isSetSupportedTimeAggregationOperations(); + boolean that_present_supportedTimeAggregationOperations = true && that.isSetSupportedTimeAggregationOperations(); + if (this_present_supportedTimeAggregationOperations || that_present_supportedTimeAggregationOperations) { + if (!(this_present_supportedTimeAggregationOperations && that_present_supportedTimeAggregationOperations)) + return false; + if (!this.supportedTimeAggregationOperations.equals(that.supportedTimeAggregationOperations)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public int compareTo(ServerProperties other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetVersion()).compareTo(other.isSetVersion()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetVersion()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.version, other.version); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetSupportedTimeAggregationOperations()).compareTo(other.isSetSupportedTimeAggregationOperations()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSupportedTimeAggregationOperations()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.supportedTimeAggregationOperations, other.supportedTimeAggregationOperations); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("ServerProperties("); + boolean first = true; + + sb.append("version:"); + if (this.version == null) { + sb.append("null"); + } else { + sb.append(this.version); + } + first = false; + if (!first) sb.append(", "); + sb.append("supportedTimeAggregationOperations:"); + if (this.supportedTimeAggregationOperations == null) { + sb.append("null"); + } else { + sb.append(this.supportedTimeAggregationOperations); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (version == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'version' was not present! Struct: " + toString()); + } + if (supportedTimeAggregationOperations == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'supportedTimeAggregationOperations' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ServerPropertiesStandardSchemeFactory implements SchemeFactory { + public ServerPropertiesStandardScheme getScheme() { + return new ServerPropertiesStandardScheme(); + } + } + + private static class ServerPropertiesStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, ServerProperties struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // VERSION + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.version = iprot.readString(); + struct.setVersionIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // SUPPORTED_TIME_AGGREGATION_OPERATIONS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list118 = iprot.readListBegin(); + struct.supportedTimeAggregationOperations = new ArrayList(_list118.size); + for (int _i119 = 0; _i119 < _list118.size; ++_i119) + { + String _elem120; + _elem120 = iprot.readString(); + struct.supportedTimeAggregationOperations.add(_elem120); + } + iprot.readListEnd(); + } + struct.setSupportedTimeAggregationOperationsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, ServerProperties struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.version != null) { + oprot.writeFieldBegin(VERSION_FIELD_DESC); + oprot.writeString(struct.version); + oprot.writeFieldEnd(); + } + if (struct.supportedTimeAggregationOperations != null) { + oprot.writeFieldBegin(SUPPORTED_TIME_AGGREGATION_OPERATIONS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.supportedTimeAggregationOperations.size())); + for (String _iter121 : struct.supportedTimeAggregationOperations) + { + oprot.writeString(_iter121); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ServerPropertiesTupleSchemeFactory implements SchemeFactory { + public ServerPropertiesTupleScheme getScheme() { + return new ServerPropertiesTupleScheme(); + } + } + + private static class ServerPropertiesTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, ServerProperties struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + oprot.writeString(struct.version); + { + oprot.writeI32(struct.supportedTimeAggregationOperations.size()); + for (String _iter122 : struct.supportedTimeAggregationOperations) + { + oprot.writeString(_iter122); + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, ServerProperties struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + struct.version = iprot.readString(); + struct.setVersionIsSet(true); + { + org.apache.thrift.protocol.TList _list123 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32()); + struct.supportedTimeAggregationOperations = new ArrayList(_list123.size); + for (int _i124 = 0; _i124 < _list123.size; ++_i124) + { + String _elem125; + _elem125 = iprot.readString(); + struct.supportedTimeAggregationOperations.add(_elem125); + } + } + struct.setSupportedTimeAggregationOperationsIsSet(true); + } + } + +} + diff --git a/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/TSIService.java b/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/TSIService.java index ca2390381dc..ccf4b449eee 100644 --- a/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/TSIService.java +++ b/service-rpc/interface/thrift/cn/edu/tsinghua/service/rpc/thrift/TSIService.java @@ -60,6 +60,8 @@ public class TSIService { public TSSetTimeZoneResp setTimeZone(TSSetTimeZoneReq req) throws org.apache.thrift.TException; + public ServerProperties getProperties() throws org.apache.thrift.TException; + } public interface AsyncIface { @@ -88,6 +90,8 @@ public class TSIService { public void setTimeZone(TSSetTimeZoneReq req, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void getProperties(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + } public static class Client extends org.apache.thrift.TServiceClient implements Iface { @@ -385,6 +389,28 @@ public class TSIService { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "setTimeZone failed: unknown result"); } + public ServerProperties getProperties() throws org.apache.thrift.TException + { + send_getProperties(); + return recv_getProperties(); + } + + public void send_getProperties() throws org.apache.thrift.TException + { + getProperties_args args = new getProperties_args(); + sendBase("getProperties", args); + } + + public ServerProperties recv_getProperties() throws org.apache.thrift.TException + { + getProperties_result result = new getProperties_result(); + receiveBase(result, "getProperties"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getProperties failed: unknown result"); + } + } public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { @@ -784,6 +810,35 @@ public class TSIService { } } + public void getProperties(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + getProperties_call method_call = new getProperties_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class getProperties_call extends org.apache.thrift.async.TAsyncMethodCall { + public getProperties_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getProperties", org.apache.thrift.protocol.TMessageType.CALL, 0)); + getProperties_args args = new getProperties_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public ServerProperties getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_getProperties(); + } + } + } public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { @@ -809,6 +864,7 @@ public class TSIService { processMap.put("closeOperation", new closeOperation()); processMap.put("getTimeZone", new getTimeZone()); processMap.put("setTimeZone", new setTimeZone()); + processMap.put("getProperties", new getProperties()); return processMap; } @@ -1052,6 +1108,26 @@ public class TSIService { } } + public static class getProperties extends org.apache.thrift.ProcessFunction { + public getProperties() { + super("getProperties"); + } + + public getProperties_args getEmptyArgsInstance() { + return new getProperties_args(); + } + + protected boolean isOneway() { + return false; + } + + public getProperties_result getResult(I iface, getProperties_args args) throws org.apache.thrift.TException { + getProperties_result result = new getProperties_result(); + result.success = iface.getProperties(); + return result; + } + } + } public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { @@ -1077,6 +1153,7 @@ public class TSIService { processMap.put("closeOperation", new closeOperation()); processMap.put("getTimeZone", new getTimeZone()); processMap.put("setTimeZone", new setTimeZone()); + processMap.put("getProperties", new getProperties()); return processMap; } @@ -1692,6 +1769,57 @@ public class TSIService { } } + public static class getProperties extends org.apache.thrift.AsyncProcessFunction { + public getProperties() { + super("getProperties"); + } + + public getProperties_args getEmptyArgsInstance() { + return new getProperties_args(); + } + + public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback() { + public void onComplete(ServerProperties o) { + getProperties_result result = new getProperties_result(); + result.success = o; + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + getProperties_result result = new getProperties_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, getProperties_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.getProperties(resultHandler); + } + } + } public static class openSession_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { @@ -10197,4 +10325,609 @@ public class TSIService { } + public static class getProperties_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getProperties_args"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getProperties_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getProperties_argsTupleSchemeFactory()); + } + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getProperties_args.class, metaDataMap); + } + + public getProperties_args() { + } + + /** + * Performs a deep copy on other. + */ + public getProperties_args(getProperties_args other) { + } + + public getProperties_args deepCopy() { + return new getProperties_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getProperties_args) + return this.equals((getProperties_args)that); + return false; + } + + public boolean equals(getProperties_args that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public int compareTo(getProperties_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getProperties_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getProperties_argsStandardSchemeFactory implements SchemeFactory { + public getProperties_argsStandardScheme getScheme() { + return new getProperties_argsStandardScheme(); + } + } + + private static class getProperties_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getProperties_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getProperties_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getProperties_argsTupleSchemeFactory implements SchemeFactory { + public getProperties_argsTupleScheme getScheme() { + return new getProperties_argsTupleScheme(); + } + } + + private static class getProperties_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getProperties_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getProperties_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + } + + } + + public static class getProperties_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getProperties_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getProperties_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getProperties_resultTupleSchemeFactory()); + } + + public ServerProperties success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ServerProperties.class))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getProperties_result.class, metaDataMap); + } + + public getProperties_result() { + } + + public getProperties_result( + ServerProperties success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public getProperties_result(getProperties_result other) { + if (other.isSetSuccess()) { + this.success = new ServerProperties(other.success); + } + } + + public getProperties_result deepCopy() { + return new getProperties_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public ServerProperties getSuccess() { + return this.success; + } + + public getProperties_result setSuccess(ServerProperties success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((ServerProperties)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getProperties_result) + return this.equals((getProperties_result)that); + return false; + } + + public boolean equals(getProperties_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + + @Override + public int compareTo(getProperties_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getProperties_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getProperties_resultStandardSchemeFactory implements SchemeFactory { + public getProperties_resultStandardScheme getScheme() { + return new getProperties_resultStandardScheme(); + } + } + + private static class getProperties_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getProperties_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new ServerProperties(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getProperties_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getProperties_resultTupleSchemeFactory implements SchemeFactory { + public getProperties_resultTupleScheme getScheme() { + return new getProperties_resultTupleScheme(); + } + } + + private static class getProperties_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getProperties_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getProperties_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = new ServerProperties(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + } + } + + } + } diff --git a/tsfile/pom.xml b/tsfile/pom.xml index 5429f6705f9..a63b2fc8ad0 100644 --- a/tsfile/pom.xml +++ b/tsfile/pom.xml @@ -126,34 +126,54 @@ - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - generate-sources - - add-source - - - - interface/thrift - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - - ${tsfile.test.skip} - - - + + + org.codehaus.mojo + build-helper-maven-plugin + 3.0.0 + + + generate-sources + + add-source + + + + interface/thrift + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + ${tsfile.test.skip} + + + + maven-assembly-plugin + 3.1.0 + + + jar-with-dependencies + + + + + make-assembly + + package + + + single + + + + +