From 25d1132e23b6690e36f706708d43eede04c42548 Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 21 Jan 2026 17:43:55 +0800 Subject: [PATCH 01/10] Move rest to independent module --- distribution/pom.xml | 6 + distribution/src/assembly/all.xml | 4 + distribution/src/assembly/datanode.xml | 4 + .../src/assembly/external-service-impl.xml | 4 + external-service-impl/pom.xml | 1 + external-service-impl/rest/pom.xml | 84 +++++ .../org/apache/iotdb/rest}/RestService.java | 4 +- .../protocol}/filter/ApiOriginFilter.java | 2 +- .../protocol}/filter/AuthorizationFilter.java | 4 +- .../filter/BasicSecurityContext.java | 2 +- .../iotdb/rest/protocol}/filter/User.java | 2 +- .../rest/protocol}/filter/UserCache.java | 2 +- .../handler/AuthorizationHandler.java | 4 +- .../protocol}/impl/PingApiServiceImpl.java | 6 +- .../table/v1/handler/ExceptionHandler.java | 4 +- .../v1/handler/ExecuteStatementHandler.java | 2 +- .../table/v1/handler/QueryDataSetHandler.java | 6 +- .../v1/handler/RequestValidationHandler.java | 6 +- .../handler/StatementConstructionHandler.java | 4 +- .../table/v1/impl/RestApiServiceImpl.java | 26 +- .../protocol}/utils/InsertRowDataUtils.java | 2 +- .../utils/InsertTabletSortDataUtils.java | 2 +- .../v1}/handler/ExceptionHandler.java | 4 +- .../v1/handler/ExecuteStatementHandler.java | 2 +- .../v1/handler/QueryDataSetHandler.java | 26 +- .../v1/handler/RequestValidationHandler.java | 8 +- .../handler/StatementConstructionHandler.java | 4 +- .../v1/impl/GrafanaApiServiceImpl.java | 18 +- .../protocol}/v1/impl/RestApiServiceImpl.java | 32 +- .../v2}/handler/ExceptionHandler.java | 4 +- .../v2/handler/ExecuteStatementHandler.java | 2 +- .../protocol}/v2/handler/FastLastHandler.java | 10 +- .../v2/handler/QueryDataSetHandler.java | 22 +- .../v2/handler/RequestValidationHandler.java | 12 +- .../handler/StatementConstructionHandler.java | 8 +- .../v2/impl/GrafanaApiServiceImpl.java | 18 +- .../protocol}/v2/impl/RestApiServiceImpl.java | 36 +- .../apache/iotdb/rest/EnvironmentUtils.java | 334 ++++++++++++++++++ .../iotdb}/rest/GrafanaApiServiceTest.java | 4 +- .../iotdb}/rest/IoTDBRestServiceTest.java | 3 +- .../org/apache/iotdb/db/service/DataNode.java | 4 - .../BuiltinExternalServices.java | 4 +- iotdb-protocol/openapi/pom.xml | 24 +- 43 files changed, 595 insertions(+), 165 deletions(-) create mode 100644 external-service-impl/rest/pom.xml rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service => external-service-impl/rest/src/main/java/org/apache/iotdb/rest}/RestService.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/filter/ApiOriginFilter.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/filter/AuthorizationFilter.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/filter/BasicSecurityContext.java (96%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/filter/User.java (96%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/filter/UserCache.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/handler/AuthorizationHandler.java (93%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/impl/PingApiServiceImpl.java (91%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/handler/ExceptionHandler.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/handler/ExecuteStatementHandler.java (99%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/handler/QueryDataSetHandler.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/handler/RequestValidationHandler.java (95%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/handler/StatementConstructionHandler.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/table/v1/impl/RestApiServiceImpl.java (92%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/utils/InsertRowDataUtils.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/utils/InsertTabletSortDataUtils.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2 => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1}/handler/ExceptionHandler.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/handler/ExecuteStatementHandler.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/handler/QueryDataSetHandler.java (93%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/handler/RequestValidationHandler.java (90%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/handler/StatementConstructionHandler.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/impl/GrafanaApiServiceImpl.java (94%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v1/impl/RestApiServiceImpl.java (91%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1 => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2}/handler/ExceptionHandler.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/handler/ExecuteStatementHandler.java (98%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/handler/FastLastHandler.java (87%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/handler/QueryDataSetHandler.java (94%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/handler/RequestValidationHandler.java (93%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/handler/StatementConstructionHandler.java (97%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/impl/GrafanaApiServiceImpl.java (94%) rename {iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest => external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol}/v2/impl/RestApiServiceImpl.java (94%) create mode 100644 external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java rename {iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol => external-service-impl/rest/src/test/java/org/apache/iotdb}/rest/GrafanaApiServiceTest.java (99%) rename {iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol => external-service-impl/rest/src/test/java/org/apache/iotdb}/rest/IoTDBRestServiceTest.java (99%) diff --git a/distribution/pom.xml b/distribution/pom.xml index 025a67b379d66..65a3572fd3a55 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -59,6 +59,12 @@ 2.0.7-SNAPSHOT provided + + org.apache.iotdb + rest + 2.0.7-SNAPSHOT + provided + diff --git a/distribution/src/assembly/all.xml b/distribution/src/assembly/all.xml index 255912d75e611..1b2e1be054f3e 100644 --- a/distribution/src/assembly/all.xml +++ b/distribution/src/assembly/all.xml @@ -96,6 +96,10 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/mqtt/target/mqtt-${project.version}-jar-with-dependencies.jar lib + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar + lib + common-files.xml diff --git a/distribution/src/assembly/datanode.xml b/distribution/src/assembly/datanode.xml index 8994667fb873a..225fa5a7e7d28 100644 --- a/distribution/src/assembly/datanode.xml +++ b/distribution/src/assembly/datanode.xml @@ -79,6 +79,10 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/mqtt/target/mqtt-${project.version}-jar-with-dependencies.jar lib + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar + lib + common-files.xml diff --git a/distribution/src/assembly/external-service-impl.xml b/distribution/src/assembly/external-service-impl.xml index 273efe6eddfb5..c743fa8559720 100644 --- a/distribution/src/assembly/external-service-impl.xml +++ b/distribution/src/assembly/external-service-impl.xml @@ -47,5 +47,9 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/mqtt/target/mqtt-${project.version}-jar-with-dependencies.jar / + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar + / + diff --git a/external-service-impl/pom.xml b/external-service-impl/pom.xml index 986522e6275d2..9c484ff270448 100644 --- a/external-service-impl/pom.xml +++ b/external-service-impl/pom.xml @@ -31,6 +31,7 @@ pom mqtt + rest 8 diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml new file mode 100644 index 0000000000000..24f52dd2bcadb --- /dev/null +++ b/external-service-impl/rest/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + org.apache.iotdb + external-service-impl + 2.0.7-SNAPSHOT + + rest + IoTDB: External-Service-Impl: Rest + + 8 + 8 + UTF-8 + + + + org.apache.iotdb + node-commons + 2.0.7-SNAPSHOT + provided + + + org.apache.iotdb + iotdb-server + 2.0.7-SNAPSHOT + provided + + + org.apache.httpcomponents + httpcore + test + + + org.apache.httpcomponents + httpclient + test + + + + + + maven-assembly-plugin + ${maven.assembly.version} + + + jar-with-dependencies + + + + + make-assembly + + + single + + + package + + + + + + diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/RestService.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/RestService.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java index 7fc4d788380ef..a9512f3e90f8d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/RestService.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java @@ -14,14 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.iotdb.db.service; +package org.apache.iotdb.rest; import org.apache.iotdb.commons.exception.StartupException; import org.apache.iotdb.commons.service.IService; import org.apache.iotdb.commons.service.ServiceType; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceConfig; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; -import org.apache.iotdb.db.protocol.rest.filter.ApiOriginFilter; +import org.apache.iotdb.rest.protocol.filter.ApiOriginFilter; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.HttpConfiguration; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/ApiOriginFilter.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/ApiOriginFilter.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/ApiOriginFilter.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/ApiOriginFilter.java index aacc2bcc09aa6..578b8b3574868 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/ApiOriginFilter.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/ApiOriginFilter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.filter; +package org.apache.iotdb.rest.protocol.filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/AuthorizationFilter.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/AuthorizationFilter.java index 1f4da4c5a6a8c..a31e5b953abbc 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/AuthorizationFilter.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/AuthorizationFilter.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.filter; +package org.apache.iotdb.rest.protocol.filter; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.auth.AuthException; @@ -23,9 +23,9 @@ import org.apache.iotdb.db.auth.AuthorityChecker; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceConfig; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; import org.apache.iotdb.db.protocol.session.RestClientSession; import org.apache.iotdb.db.protocol.session.SessionManager; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import javax.servlet.annotation.WebFilter; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/BasicSecurityContext.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/BasicSecurityContext.java similarity index 96% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/BasicSecurityContext.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/BasicSecurityContext.java index 28030577a93bc..5bea8d520dd7a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/BasicSecurityContext.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/BasicSecurityContext.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.filter; +package org.apache.iotdb.rest.protocol.filter; import javax.ws.rs.core.SecurityContext; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/User.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/User.java similarity index 96% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/User.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/User.java index af4b27e2a61c6..b6deb5825e3ac 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/User.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/User.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.filter; +package org.apache.iotdb.rest.protocol.filter; public class User { private long userId = -1; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/UserCache.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/UserCache.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/UserCache.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/UserCache.java index f53273def2d05..8c8a55f25b596 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/filter/UserCache.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/filter/UserCache.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.filter; +package org.apache.iotdb.rest.protocol.filter; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceConfig; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/handler/AuthorizationHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/handler/AuthorizationHandler.java similarity index 93% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/handler/AuthorizationHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/handler/AuthorizationHandler.java index 3c30e3e95a97e..4826a39fadd59 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/handler/AuthorizationHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/handler/AuthorizationHandler.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.handler; +package org.apache.iotdb.rest.protocol.handler; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.audit.UserEntity; import org.apache.iotdb.db.auth.AuthorityChecker; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; import org.apache.iotdb.db.queryengine.plan.statement.Statement; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import javax.ws.rs.core.Response; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/impl/PingApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/impl/PingApiServiceImpl.java similarity index 91% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/impl/PingApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/impl/PingApiServiceImpl.java index f85de024b4780..740bb28b069d4 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/impl/PingApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/impl/PingApiServiceImpl.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.impl; +package org.apache.iotdb.rest.protocol.impl; import org.apache.iotdb.commons.service.ThriftService; -import org.apache.iotdb.db.protocol.rest.PingApiService; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; import org.apache.iotdb.db.service.ExternalRPCService; +import org.apache.iotdb.rest.protocol.PingApiService; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import javax.ws.rs.core.Response; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExceptionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java index 1d2da9ad57a82..61e64465a0678 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExceptionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExceptionHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.handler; +package org.apache.iotdb.rest.protocol.table.v1.handler; import org.apache.iotdb.commons.auth.AuthException; import org.apache.iotdb.commons.exception.IllegalPathException; @@ -27,8 +27,8 @@ import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.sql.SemanticException; import org.apache.iotdb.db.exception.sql.StatementAnalyzeException; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; import org.apache.iotdb.db.queryengine.plan.relational.sql.parser.ParsingException; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import org.antlr.v4.runtime.misc.ParseCancellationException; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExecuteStatementHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java similarity index 99% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExecuteStatementHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java index 1b2737531396f..4fa749dd567be 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/ExecuteStatementHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/ExecuteStatementHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.handler; +package org.apache.iotdb.rest.protocol.table.v1.handler; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.CountDevice; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.DescribeTable; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/QueryDataSetHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/QueryDataSetHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java index 25e331b38a81e..ec22f478b8b70 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/QueryDataSetHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/QueryDataSetHandler.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.handler; +package org.apache.iotdb.rest.protocol.table.v1.handler; import org.apache.iotdb.commons.exception.IoTDBException; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.table.v1.model.QueryDataSet; import org.apache.iotdb.db.queryengine.common.header.DatasetHeader; import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Query; import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.table.v1.model.QueryDataSet; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.tsfile.block.column.Column; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/RequestValidationHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/RequestValidationHandler.java similarity index 95% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/RequestValidationHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/RequestValidationHandler.java index 66958785ce51f..fc546212caf43 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/RequestValidationHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/RequestValidationHandler.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.handler; +package org.apache.iotdb.rest.protocol.table.v1.handler; -import org.apache.iotdb.db.protocol.rest.table.v1.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.table.v1.model.SQL; +import org.apache.iotdb.rest.protocol.table.v1.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.table.v1.model.SQL; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.external.commons.lang3.Validate; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/StatementConstructionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java index bda0627ce6110..b7f712c41f779 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/handler/StatementConstructionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/handler/StatementConstructionHandler.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.handler; +package org.apache.iotdb.rest.protocol.table.v1.handler; import org.apache.iotdb.commons.exception.IllegalPathException; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory; import org.apache.iotdb.db.exception.WriteProcessRejectException; -import org.apache.iotdb.db.protocol.rest.table.v1.model.InsertTabletRequest; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; import org.apache.iotdb.db.utils.TimestampPrecisionUtils; +import org.apache.iotdb.rest.protocol.table.v1.model.InsertTabletRequest; import org.apache.tsfile.enums.ColumnCategory; import org.apache.tsfile.enums.TSDataType; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/impl/RestApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java similarity index 92% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/impl/RestApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java index ec0237f13ea98..b35e9d27f595c 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/table/v1/impl/RestApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/table/v1/impl/RestApiServiceImpl.java @@ -15,22 +15,12 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.table.v1.impl; +package org.apache.iotdb.rest.protocol.table.v1.impl; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; -import org.apache.iotdb.db.protocol.rest.table.v1.NotFoundException; -import org.apache.iotdb.db.protocol.rest.table.v1.RestApiService; -import org.apache.iotdb.db.protocol.rest.table.v1.handler.ExceptionHandler; -import org.apache.iotdb.db.protocol.rest.table.v1.handler.ExecuteStatementHandler; -import org.apache.iotdb.db.protocol.rest.table.v1.handler.QueryDataSetHandler; -import org.apache.iotdb.db.protocol.rest.table.v1.handler.RequestValidationHandler; -import org.apache.iotdb.db.protocol.rest.table.v1.handler.StatementConstructionHandler; -import org.apache.iotdb.db.protocol.rest.table.v1.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.table.v1.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.table.v1.model.SQL; import org.apache.iotdb.db.protocol.session.IClientSession; import org.apache.iotdb.db.protocol.session.SessionManager; import org.apache.iotdb.db.protocol.thrift.OperationType; @@ -46,6 +36,16 @@ import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; import org.apache.iotdb.db.utils.CommonUtils; import org.apache.iotdb.db.utils.SetThreadName; +import org.apache.iotdb.rest.protocol.table.v1.NotFoundException; +import org.apache.iotdb.rest.protocol.table.v1.RestApiService; +import org.apache.iotdb.rest.protocol.table.v1.handler.ExceptionHandler; +import org.apache.iotdb.rest.protocol.table.v1.handler.ExecuteStatementHandler; +import org.apache.iotdb.rest.protocol.table.v1.handler.QueryDataSetHandler; +import org.apache.iotdb.rest.protocol.table.v1.handler.RequestValidationHandler; +import org.apache.iotdb.rest.protocol.table.v1.handler.StatementConstructionHandler; +import org.apache.iotdb.rest.protocol.table.v1.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.table.v1.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.table.v1.model.SQL; import org.apache.iotdb.rpc.TSStatusCode; import javax.ws.rs.core.Response; @@ -294,7 +294,7 @@ private Response validateStatement(Statement statement, boolean userQuery) { if (statement == null) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.SQL_PARSE_ERROR.getStatusCode()) .message("This operation type is not supported")) .build(); @@ -304,7 +304,7 @@ private Response validateStatement(Statement statement, boolean userQuery) { if (userQuery == isQueryStmt) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()) .message(TSStatusCode.EXECUTE_STATEMENT_ERROR.name())) .build(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertRowDataUtils.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertRowDataUtils.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertRowDataUtils.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertRowDataUtils.java index fae611dcf7774..08deec903c957 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertRowDataUtils.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertRowDataUtils.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.utils; +package org.apache.iotdb.rest.protocol.utils; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.NoValidValueException; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertTabletSortDataUtils.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertTabletSortDataUtils.java index e2e3d2f79762f..82969f46bf234 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertTabletSortDataUtils.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/utils/InsertTabletSortDataUtils.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.utils; +package org.apache.iotdb.rest.protocol.utils; import java.util.ArrayList; import java.util.Arrays; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExceptionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java index 69994577f09d2..6edcb57ab4d9a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExceptionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExceptionHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v1.handler; import org.apache.iotdb.commons.auth.AuthException; import org.apache.iotdb.commons.exception.IllegalPathException; @@ -27,7 +27,7 @@ import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.sql.SemanticException; import org.apache.iotdb.db.exception.sql.StatementAnalyzeException; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.v1.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import org.antlr.v4.runtime.misc.ParseCancellationException; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExecuteStatementHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExecuteStatementHandler.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExecuteStatementHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExecuteStatementHandler.java index f1c621a4aa445..ab3811cf11684 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExecuteStatementHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/ExecuteStatementHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.handler; +package org.apache.iotdb.rest.protocol.v1.handler; import org.apache.iotdb.db.queryengine.plan.statement.Statement; import org.apache.iotdb.db.queryengine.plan.statement.StatementType; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/QueryDataSetHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/QueryDataSetHandler.java similarity index 93% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/QueryDataSetHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/QueryDataSetHandler.java index 55623ecad21a8..c2fe52440a779 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/QueryDataSetHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/QueryDataSetHandler.java @@ -15,10 +15,9 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.handler; +package org.apache.iotdb.rest.protocol.v1.handler; import org.apache.iotdb.commons.exception.IoTDBException; -import org.apache.iotdb.db.protocol.rest.v1.model.ExecutionStatus; import org.apache.iotdb.db.queryengine.common.header.DatasetHeader; import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution; import org.apache.iotdb.db.queryengine.plan.statement.Statement; @@ -30,6 +29,7 @@ import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowLoadedModelsStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowModelsStatement; import org.apache.iotdb.db.queryengine.plan.statement.sys.AuthorStatement; +import org.apache.iotdb.rest.protocol.v1.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.tsfile.block.column.Column; @@ -83,8 +83,8 @@ public static Response fillQueryDataSet( public static Response fillDataSetWithTimestamps( IQueryExecution queryExecution, final int actualRowSizeLimit, final long timePrecision) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v1.model.QueryDataSet(); return fillQueryDataSetWithTimestamps( queryExecution, actualRowSizeLimit, targetDataSet, timePrecision); @@ -93,8 +93,8 @@ public static Response fillDataSetWithTimestamps( public static Response fillAggregationPlanDataSet( IQueryExecution queryExecution, final int actualRowSizeLimit) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v1.model.QueryDataSet(); DatasetHeader datasetHeader = queryExecution.getDatasetHeader(); List dataTypes = new ArrayList<>(); @@ -117,8 +117,8 @@ public static Response fillAggregationPlanDataSet( private static Response fillShowPlanDataSet( IQueryExecution queryExecution, final int actualRowSizeLimit) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v1.model.QueryDataSet(); int[] targetDataSetIndexToSourceDataSetIndex = new int[queryExecution.getDatasetHeader().getRespColumns().size()]; initTargetDatasetOrderByOrderWithSourceDataSet( @@ -135,7 +135,7 @@ private static Response fillShowPlanDataSet( private static void initTargetDatasetOrderByOrderWithSourceDataSet( DatasetHeader datasetHeader, int[] targetDataSetIndexToSourceDataSetIndex, - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet) { + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet) { if (datasetHeader.getRespColumns() != null) { for (int i = 0; i < datasetHeader.getRespColumns().size(); i++) { targetDataSet.addColumnNamesItem(datasetHeader.getRespColumns().get(i)); @@ -148,7 +148,7 @@ private static void initTargetDatasetOrderByOrderWithSourceDataSet( private static Response fillQueryDataSetWithTimestamps( IQueryExecution queryExecution, int actualRowSizeLimit, - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet, + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet, final long timePrecision) throws IoTDBException { int fetched = 0; @@ -167,7 +167,7 @@ private static Response fillQueryDataSetWithTimestamps( if (0 < actualRowSizeLimit && actualRowSizeLimit <= fetched) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode()) .message( String.format( @@ -216,7 +216,7 @@ private static Response fillQueryDataSetWithoutTimestamps( IQueryExecution queryExecution, int[] targetDataSetIndexToSourceDataSetIndex, int actualRowSizeLimit, - org.apache.iotdb.db.protocol.rest.v1.model.QueryDataSet targetDataSet, + org.apache.iotdb.rest.protocol.v1.model.QueryDataSet targetDataSet, List dataTypes) throws IoTDBException { int fetched = 0; @@ -225,7 +225,7 @@ private static Response fillQueryDataSetWithoutTimestamps( if (0 < actualRowSizeLimit && actualRowSizeLimit <= fetched) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.QUERY_PROCESS_ERROR.getStatusCode()) .message( String.format( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/RequestValidationHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/RequestValidationHandler.java similarity index 90% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/RequestValidationHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/RequestValidationHandler.java index d7239f9fe620d..dc81322cc7880 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/RequestValidationHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/RequestValidationHandler.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.handler; +package org.apache.iotdb.rest.protocol.v1.handler; -import org.apache.iotdb.db.protocol.rest.v1.model.ExpressionRequest; -import org.apache.iotdb.db.protocol.rest.v1.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.v1.model.SQL; +import org.apache.iotdb.rest.protocol.v1.model.ExpressionRequest; +import org.apache.iotdb.rest.protocol.v1.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.v1.model.SQL; import org.apache.tsfile.external.commons.lang3.Validate; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java index 523b8ccfb6af6..65ec7a966f1e0 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/StatementConstructionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/handler/StatementConstructionHandler.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.handler; +package org.apache.iotdb.rest.protocol.v1.handler; import org.apache.iotdb.commons.exception.MetadataException; import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.db.exception.WriteProcessRejectException; -import org.apache.iotdb.db.protocol.rest.v1.model.InsertTabletRequest; import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; import org.apache.iotdb.db.utils.TimestampPrecisionUtils; +import org.apache.iotdb.rest.protocol.v1.model.InsertTabletRequest; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.utils.Binary; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/GrafanaApiServiceImpl.java similarity index 94% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/GrafanaApiServiceImpl.java index c9a4f8f9ee11c..0db4cd06c669f 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/GrafanaApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/GrafanaApiServiceImpl.java @@ -15,20 +15,12 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.impl; +package org.apache.iotdb.rest.protocol.v1.impl; import org.apache.iotdb.commons.conf.CommonDescriptor; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; -import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler; -import org.apache.iotdb.db.protocol.rest.v1.GrafanaApiService; -import org.apache.iotdb.db.protocol.rest.v1.handler.ExceptionHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.QueryDataSetHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.RequestValidationHandler; -import org.apache.iotdb.db.protocol.rest.v1.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.v1.model.ExpressionRequest; -import org.apache.iotdb.db.protocol.rest.v1.model.SQL; import org.apache.iotdb.db.protocol.session.SessionManager; import org.apache.iotdb.db.queryengine.plan.Coordinator; import org.apache.iotdb.db.queryengine.plan.analyze.ClusterPartitionFetcher; @@ -42,6 +34,14 @@ import org.apache.iotdb.db.queryengine.plan.statement.crud.QueryStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowStatement; import org.apache.iotdb.db.utils.SetThreadName; +import org.apache.iotdb.rest.protocol.handler.AuthorizationHandler; +import org.apache.iotdb.rest.protocol.v1.GrafanaApiService; +import org.apache.iotdb.rest.protocol.v1.handler.ExceptionHandler; +import org.apache.iotdb.rest.protocol.v1.handler.QueryDataSetHandler; +import org.apache.iotdb.rest.protocol.v1.handler.RequestValidationHandler; +import org.apache.iotdb.rest.protocol.v1.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.v1.model.ExpressionRequest; +import org.apache.iotdb.rest.protocol.v1.model.SQL; import org.apache.iotdb.rpc.TSStatusCode; import com.google.common.base.Joiner; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/RestApiServiceImpl.java similarity index 91% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/RestApiServiceImpl.java index 6982fb0b53368..329ac47034bdb 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/impl/RestApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v1/impl/RestApiServiceImpl.java @@ -15,22 +15,11 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.impl; +package org.apache.iotdb.rest.protocol.v1.impl; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; -import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler; -import org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils; -import org.apache.iotdb.db.protocol.rest.v1.RestApiService; -import org.apache.iotdb.db.protocol.rest.v1.handler.ExceptionHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.ExecuteStatementHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.QueryDataSetHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.RequestValidationHandler; -import org.apache.iotdb.db.protocol.rest.v1.handler.StatementConstructionHandler; -import org.apache.iotdb.db.protocol.rest.v1.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.v1.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.v1.model.SQL; import org.apache.iotdb.db.protocol.session.SessionManager; import org.apache.iotdb.db.protocol.thrift.OperationType; import org.apache.iotdb.db.queryengine.plan.Coordinator; @@ -48,6 +37,17 @@ import org.apache.iotdb.db.queryengine.plan.statement.metadata.view.CreateTableViewStatement; import org.apache.iotdb.db.utils.CommonUtils; import org.apache.iotdb.db.utils.SetThreadName; +import org.apache.iotdb.rest.protocol.handler.AuthorizationHandler; +import org.apache.iotdb.rest.protocol.utils.InsertTabletSortDataUtils; +import org.apache.iotdb.rest.protocol.v1.RestApiService; +import org.apache.iotdb.rest.protocol.v1.handler.ExceptionHandler; +import org.apache.iotdb.rest.protocol.v1.handler.ExecuteStatementHandler; +import org.apache.iotdb.rest.protocol.v1.handler.QueryDataSetHandler; +import org.apache.iotdb.rest.protocol.v1.handler.RequestValidationHandler; +import org.apache.iotdb.rest.protocol.v1.handler.StatementConstructionHandler; +import org.apache.iotdb.rest.protocol.v1.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.v1.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.v1.model.SQL; import org.apache.iotdb.rpc.TSStatusCode; import javax.ws.rs.core.Response; @@ -91,7 +91,7 @@ public Response executeNonQueryStatement(SQL sql, SecurityContext securityContex if (statement == null) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.SQL_PARSE_ERROR.getStatusCode()) .message("This operation type is not supported")) .build(); @@ -99,7 +99,7 @@ public Response executeNonQueryStatement(SQL sql, SecurityContext securityContex if (!ExecuteStatementHandler.validateStatement(statement)) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()) .message(TSStatusCode.EXECUTE_STATEMENT_ERROR.name())) .build(); @@ -181,7 +181,7 @@ public Response executeQueryStatement(SQL sql, SecurityContext securityContext) if (statement == null) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.SQL_PARSE_ERROR.getStatusCode()) .message("This operation type is not supported")) .build(); @@ -189,7 +189,7 @@ public Response executeQueryStatement(SQL sql, SecurityContext securityContext) if (ExecuteStatementHandler.validateStatement(statement)) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()) .message(TSStatusCode.EXECUTE_STATEMENT_ERROR.name())) .build(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExceptionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExceptionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java index 8784d4ff72172..931ec0cec002b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v1/handler/ExceptionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExceptionHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v1.handler; +package org.apache.iotdb.rest.protocol.v2.handler; import org.apache.iotdb.commons.auth.AuthException; import org.apache.iotdb.commons.exception.IllegalPathException; @@ -27,7 +27,7 @@ import org.apache.iotdb.db.exception.query.QueryProcessException; import org.apache.iotdb.db.exception.sql.SemanticException; import org.apache.iotdb.db.exception.sql.StatementAnalyzeException; -import org.apache.iotdb.db.protocol.rest.v1.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import org.antlr.v4.runtime.misc.ParseCancellationException; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExecuteStatementHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExecuteStatementHandler.java similarity index 98% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExecuteStatementHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExecuteStatementHandler.java index 00e43d17cce69..1e937f0c8aa2e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/ExecuteStatementHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/ExecuteStatementHandler.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v2.handler; import org.apache.iotdb.db.queryengine.plan.statement.Statement; import org.apache.iotdb.db.queryengine.plan.statement.StatementType; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/FastLastHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/FastLastHandler.java similarity index 87% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/FastLastHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/FastLastHandler.java index 59ebb57ffbb1f..2895e0b198e54 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/FastLastHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/FastLastHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v2.handler; import org.apache.iotdb.common.rpc.thrift.TSStatus; -import org.apache.iotdb.db.protocol.rest.v2.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.v2.model.PrefixPathList; import org.apache.iotdb.db.protocol.session.IClientSession; +import org.apache.iotdb.rest.protocol.v2.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.v2.model.PrefixPathList; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSLastDataQueryReq; @@ -45,7 +45,7 @@ public static TSLastDataQueryReq createTSLastDataQueryReq( public static Response buildErrorResponse(TSStatusCode statusCode) { return Response.ok() .entity( - new org.apache.iotdb.db.protocol.rest.model.ExecutionStatus() + new org.apache.iotdb.rest.protocol.model.ExecutionStatus() .code(statusCode.getStatusCode()) .message(statusCode.name())) .build(); @@ -58,7 +58,7 @@ public static Response buildExecutionStatusResponse(TSStatus status) { } public static void setupTargetDataSet( - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet dataSet) { + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet dataSet) { dataSet.addExpressionsItem("Timeseries"); dataSet.addExpressionsItem("Value"); dataSet.addExpressionsItem("DataType"); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/QueryDataSetHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/QueryDataSetHandler.java similarity index 94% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/QueryDataSetHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/QueryDataSetHandler.java index b89c4f768a730..188b37ebb1eda 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/QueryDataSetHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/QueryDataSetHandler.java @@ -15,10 +15,9 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v2.handler; import org.apache.iotdb.commons.exception.IoTDBException; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; import org.apache.iotdb.db.queryengine.common.header.DatasetHeader; import org.apache.iotdb.db.queryengine.plan.execution.IQueryExecution; import org.apache.iotdb.db.queryengine.plan.statement.Statement; @@ -30,6 +29,7 @@ import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowLoadedModelsStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.model.ShowModelsStatement; import org.apache.iotdb.db.queryengine.plan.statement.sys.AuthorStatement; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.tsfile.block.column.Column; @@ -83,8 +83,8 @@ public static Response fillQueryDataSet( public static Response fillDataSetWithTimestamps( IQueryExecution queryExecution, final int actualRowSizeLimit, final long timePrecision) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v2.model.QueryDataSet(); return fillQueryDataSetWithTimestamps( queryExecution, actualRowSizeLimit, targetDataSet, timePrecision); @@ -93,8 +93,8 @@ public static Response fillDataSetWithTimestamps( public static Response fillAggregationPlanDataSet( IQueryExecution queryExecution, final int actualRowSizeLimit) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v2.model.QueryDataSet(); DatasetHeader datasetHeader = queryExecution.getDatasetHeader(); int[] targetDataSetIndexToSourceDataSetIndex = new int[datasetHeader.getRespColumns().size()]; @@ -113,8 +113,8 @@ public static Response fillAggregationPlanDataSet( private static Response fillShowPlanDataSet( IQueryExecution queryExecution, final int actualRowSizeLimit) throws IoTDBException { - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet = - new org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet(); + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet = + new org.apache.iotdb.rest.protocol.v2.model.QueryDataSet(); int[] targetDataSetIndexToSourceDataSetIndex = new int[queryExecution.getDatasetHeader().getRespColumns().size()]; initTargetDatasetOrderByOrderWithSourceDataSet( @@ -127,7 +127,7 @@ private static Response fillShowPlanDataSet( private static void initTargetDatasetOrderByOrderWithSourceDataSet( DatasetHeader datasetHeader, int[] targetDataSetIndexToSourceDataSetIndex, - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet) { + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet) { if (datasetHeader.getRespColumns() != null) { for (int i = 0; i < datasetHeader.getRespColumns().size(); i++) { targetDataSet.addColumnNamesItem(datasetHeader.getRespColumns().get(i)); @@ -140,7 +140,7 @@ private static void initTargetDatasetOrderByOrderWithSourceDataSet( private static Response fillQueryDataSetWithTimestamps( IQueryExecution queryExecution, int actualRowSizeLimit, - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet, + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet, final long timePrecision) throws IoTDBException { int fetched = 0; @@ -209,7 +209,7 @@ private static Response fillQueryDataSetWithoutTimestamps( IQueryExecution queryExecution, int[] targetDataSetIndexToSourceDataSetIndex, int actualRowSizeLimit, - org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet targetDataSet) + org.apache.iotdb.rest.protocol.v2.model.QueryDataSet targetDataSet) throws IoTDBException { int fetched = 0; int columnNum = queryExecution.getOutputValueColumnCount(); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/RequestValidationHandler.java similarity index 93% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/RequestValidationHandler.java index 4192caaeca281..5f999b3ddccdf 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/RequestValidationHandler.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v2.handler; -import org.apache.iotdb.db.protocol.rest.v2.model.ExpressionRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertRecordsRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.PrefixPathList; -import org.apache.iotdb.db.protocol.rest.v2.model.SQL; +import org.apache.iotdb.rest.protocol.v2.model.ExpressionRequest; +import org.apache.iotdb.rest.protocol.v2.model.InsertRecordsRequest; +import org.apache.iotdb.rest.protocol.v2.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.v2.model.PrefixPathList; +import org.apache.iotdb.rest.protocol.v2.model.SQL; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.external.commons.lang3.Validate; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java similarity index 97% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java index 4bf9a1a55106b..6668244e9e4f0 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/StatementConstructionHandler.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/handler/StatementConstructionHandler.java @@ -15,20 +15,20 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.handler; +package org.apache.iotdb.rest.protocol.v2.handler; import org.apache.iotdb.commons.exception.MetadataException; import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.db.exception.WriteProcessRejectException; import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException; -import org.apache.iotdb.db.protocol.rest.utils.InsertRowDataUtils; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertRecordsRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest; import org.apache.iotdb.db.queryengine.plan.analyze.cache.schema.DataNodeDevicePathCache; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowStatement; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowsStatement; import org.apache.iotdb.db.queryengine.plan.statement.crud.InsertTabletStatement; import org.apache.iotdb.db.utils.TimestampPrecisionUtils; +import org.apache.iotdb.rest.protocol.utils.InsertRowDataUtils; +import org.apache.iotdb.rest.protocol.v2.model.InsertRecordsRequest; +import org.apache.iotdb.rest.protocol.v2.model.InsertTabletRequest; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.tsfile.enums.TSDataType; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/GrafanaApiServiceImpl.java similarity index 94% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/GrafanaApiServiceImpl.java index 229e9a41b27fc..5b120b9c1d7a3 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/GrafanaApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/GrafanaApiServiceImpl.java @@ -15,20 +15,12 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.impl; +package org.apache.iotdb.rest.protocol.v2.impl; import org.apache.iotdb.commons.conf.CommonDescriptor; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; -import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler; -import org.apache.iotdb.db.protocol.rest.v2.GrafanaApiService; -import org.apache.iotdb.db.protocol.rest.v2.handler.ExceptionHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.QueryDataSetHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.RequestValidationHandler; -import org.apache.iotdb.db.protocol.rest.v2.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.v2.model.ExpressionRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.SQL; import org.apache.iotdb.db.protocol.session.SessionManager; import org.apache.iotdb.db.queryengine.plan.Coordinator; import org.apache.iotdb.db.queryengine.plan.analyze.ClusterPartitionFetcher; @@ -42,6 +34,14 @@ import org.apache.iotdb.db.queryengine.plan.statement.crud.QueryStatement; import org.apache.iotdb.db.queryengine.plan.statement.metadata.ShowStatement; import org.apache.iotdb.db.utils.SetThreadName; +import org.apache.iotdb.rest.protocol.handler.AuthorizationHandler; +import org.apache.iotdb.rest.protocol.v2.GrafanaApiService; +import org.apache.iotdb.rest.protocol.v2.handler.ExceptionHandler; +import org.apache.iotdb.rest.protocol.v2.handler.QueryDataSetHandler; +import org.apache.iotdb.rest.protocol.v2.handler.RequestValidationHandler; +import org.apache.iotdb.rest.protocol.v2.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.v2.model.ExpressionRequest; +import org.apache.iotdb.rest.protocol.v2.model.SQL; import org.apache.iotdb.rpc.TSStatusCode; import com.google.common.base.Joiner; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java similarity index 94% rename from iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java rename to external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java index b657523987dc1..1ea82c606576b 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/impl/RestApiServiceImpl.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/protocol/v2/impl/RestApiServiceImpl.java @@ -15,29 +15,13 @@ * limitations under the License. */ -package org.apache.iotdb.db.protocol.rest.v2.impl; +package org.apache.iotdb.rest.protocol.v2.impl; import org.apache.iotdb.common.rpc.thrift.TSStatus; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; -import org.apache.iotdb.db.protocol.rest.handler.AuthorizationHandler; -import org.apache.iotdb.db.protocol.rest.model.ExecutionStatus; -import org.apache.iotdb.db.protocol.rest.utils.InsertTabletSortDataUtils; -import org.apache.iotdb.db.protocol.rest.v2.NotFoundException; -import org.apache.iotdb.db.protocol.rest.v2.RestApiService; -import org.apache.iotdb.db.protocol.rest.v2.handler.ExceptionHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.ExecuteStatementHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.FastLastHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.QueryDataSetHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.RequestValidationHandler; -import org.apache.iotdb.db.protocol.rest.v2.handler.StatementConstructionHandler; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertRecordsRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest; -import org.apache.iotdb.db.protocol.rest.v2.model.PrefixPathList; -import org.apache.iotdb.db.protocol.rest.v2.model.QueryDataSet; -import org.apache.iotdb.db.protocol.rest.v2.model.SQL; import org.apache.iotdb.db.protocol.session.IClientSession; import org.apache.iotdb.db.protocol.session.SessionManager; import org.apache.iotdb.db.protocol.thrift.OperationType; @@ -60,6 +44,22 @@ import org.apache.iotdb.db.schemaengine.schemaregion.ISchemaRegion; import org.apache.iotdb.db.utils.CommonUtils; import org.apache.iotdb.db.utils.SetThreadName; +import org.apache.iotdb.rest.protocol.handler.AuthorizationHandler; +import org.apache.iotdb.rest.protocol.model.ExecutionStatus; +import org.apache.iotdb.rest.protocol.utils.InsertTabletSortDataUtils; +import org.apache.iotdb.rest.protocol.v2.NotFoundException; +import org.apache.iotdb.rest.protocol.v2.RestApiService; +import org.apache.iotdb.rest.protocol.v2.handler.ExceptionHandler; +import org.apache.iotdb.rest.protocol.v2.handler.ExecuteStatementHandler; +import org.apache.iotdb.rest.protocol.v2.handler.FastLastHandler; +import org.apache.iotdb.rest.protocol.v2.handler.QueryDataSetHandler; +import org.apache.iotdb.rest.protocol.v2.handler.RequestValidationHandler; +import org.apache.iotdb.rest.protocol.v2.handler.StatementConstructionHandler; +import org.apache.iotdb.rest.protocol.v2.model.InsertRecordsRequest; +import org.apache.iotdb.rest.protocol.v2.model.InsertTabletRequest; +import org.apache.iotdb.rest.protocol.v2.model.PrefixPathList; +import org.apache.iotdb.rest.protocol.v2.model.QueryDataSet; +import org.apache.iotdb.rest.protocol.v2.model.SQL; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.service.rpc.thrift.TSLastDataQueryReq; @@ -90,7 +90,7 @@ public class RestApiServiceImpl extends RestApiService { private static final SessionManager SESSION_MANAGER = SessionManager.getInstance(); - private static final String FORMAT = "rest/v2/fastLastQuery %s"; + private static final String FORMAT = "org/apache/iotdb/rest/protocol/v2/fastLastQuery %s"; private final IPartitionFetcher partitionFetcher; diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java new file mode 100644 index 0000000000000..7ffcef0220718 --- /dev/null +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java @@ -0,0 +1,334 @@ +/* + * 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.iotdb.rest; + +import org.apache.iotdb.commons.cluster.NodeStatus; +import org.apache.iotdb.commons.conf.CommonConfig; +import org.apache.iotdb.commons.conf.CommonDescriptor; +import org.apache.iotdb.commons.exception.StartupException; +import org.apache.iotdb.db.conf.DataNodeMemoryConfig; +import org.apache.iotdb.db.conf.IoTDBConfig; +import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.db.exception.StorageEngineException; +import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext; +import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext; +import org.apache.iotdb.db.queryengine.plan.udf.UDFManagementService; +import org.apache.iotdb.db.schemaengine.SchemaEngine; +import org.apache.iotdb.db.storageengine.StorageEngine; +import org.apache.iotdb.db.storageengine.buffer.BloomFilterCache; +import org.apache.iotdb.db.storageengine.buffer.ChunkCache; +import org.apache.iotdb.db.storageengine.buffer.TimeSeriesMetadataCache; +import org.apache.iotdb.db.storageengine.dataregion.compaction.schedule.CompactionTaskManager; +import org.apache.iotdb.db.storageengine.dataregion.flush.FlushManager; +import org.apache.iotdb.db.storageengine.dataregion.read.control.FileReaderManager; +import org.apache.iotdb.db.storageengine.dataregion.read.control.QueryResourceManager; +import org.apache.iotdb.db.storageengine.dataregion.tsfile.timeindex.FileTimeIndexCacheRecorder; +import org.apache.iotdb.db.storageengine.dataregion.wal.WALManager; +import org.apache.iotdb.db.storageengine.dataregion.wal.recover.WALRecoverManager; +import org.apache.iotdb.db.storageengine.rescon.disk.TierManager; +import org.apache.iotdb.db.storageengine.rescon.memory.MemTableManager; +import org.apache.iotdb.db.storageengine.rescon.memory.PrimitiveArrayManager; +import org.apache.iotdb.db.storageengine.rescon.memory.SystemInfo; +import org.apache.iotdb.db.storageengine.rescon.memory.TsFileResourceManager; +import org.apache.iotdb.db.utils.constant.TestConstant; +import org.apache.iotdb.rpc.TConfigurationConst; +import org.apache.iotdb.rpc.TSocketWrapper; +import org.apache.iotdb.udf.api.exception.UDFManagementException; + +import org.apache.thrift.TConfiguration; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.tsfile.external.commons.io.FileUtils; +import org.apache.tsfile.fileSystem.FSFactoryProducer; +import org.apache.tsfile.utils.FilePathUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.fail; + +/** This class is used for cleaning test environment in unit test and integration test */ +public class EnvironmentUtils { + + private static final Logger logger = LoggerFactory.getLogger(EnvironmentUtils.class); + + private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); + private static final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig(); + private static final DataNodeMemoryConfig memoryConfig = + IoTDBDescriptor.getInstance().getMemoryConfig(); + private static final TierManager tierManager = TierManager.getInstance(); + + public static long TEST_QUERY_JOB_ID = 1; + public static QueryContext TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID); + public static FragmentInstanceContext TEST_QUERY_FI_CONTEXT = + FragmentInstanceContext.createFragmentInstanceContextForCompaction(TEST_QUERY_JOB_ID); + + private static final long oldSeqTsFileSize = config.getSeqTsFileSize(); + private static final long oldUnSeqTsFileSize = config.getUnSeqTsFileSize(); + private static TConfiguration tConfiguration = TConfigurationConst.defaultTConfiguration; + + public static boolean examinePorts = + Boolean.parseBoolean(System.getProperty("test.port.closed", "false")); + + public static void cleanEnv() throws IOException, StorageEngineException { + // wait all compaction finished + CompactionTaskManager.getInstance().waitAllCompactionFinish(); + // deregister all user defined classes + try { + if (UDFManagementService.getInstance() != null) { + UDFManagementService.getInstance().deregisterAll(); + } + } catch (UDFManagementException e) { + fail(e.getMessage()); + } + + logger.debug("EnvironmentUtil cleanEnv..."); + + QueryResourceManager.getInstance().endQuery(TEST_QUERY_JOB_ID); + // clear opened file streams + FileReaderManager.getInstance().closeAndRemoveAllOpenedReaders(); + + if (examinePorts) { + // TODO: this is just too slow, especially on Windows, consider a better way + boolean closed = examinePorts(); + if (!closed) { + // sleep 10 seconds + try { + TimeUnit.SECONDS.sleep(10); + } catch (InterruptedException e) { + // do nothing + } + + if (!examinePorts()) { + fail("failed to close some ports"); + } + } + } + // clean wal manager + WALManager.getInstance().stop(); + WALRecoverManager.getInstance().clear(); + StorageEngine.getInstance().stop(); + SchemaEngine.getInstance().clear(); + FlushManager.getInstance().stop(); + CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.Running); + // We must disable MQTT service as it will cost a lot of time to be shutdown, which may slow our + // unit tests. + IoTDBDescriptor.getInstance().getConfig().setEnableMQTTService(false); + + // clean cache + if (memoryConfig.isMetaDataCacheEnable()) { + ChunkCache.getInstance().clear(); + TimeSeriesMetadataCache.getInstance().clear(); + BloomFilterCache.getInstance().clear(); + } + + // close array manager + PrimitiveArrayManager.close(); + + // clear system info + SystemInfo.getInstance().close(); + + // clear memtable manager info + MemTableManager.getInstance().close(); + + // clear tsFileResource manager info + TsFileResourceManager.getInstance().clear(); + + // sleep to wait other background threads to exit + try { + TimeUnit.MILLISECONDS.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + // delete all directory + cleanAllDir(); + config.setSeqTsFileSize(oldSeqTsFileSize); + config.setUnSeqTsFileSize(oldUnSeqTsFileSize); + } + + private static boolean examinePorts() { + TTransport transport = TSocketWrapper.wrap(tConfiguration, "127.0.0.1", 6667, 100); + if (transport != null && !transport.isOpen()) { + try { + transport.open(); + logger.error("stop daemon failed. 6667 can be connected now."); + transport.close(); + return false; + } catch (TTransportException e) { + // do nothing + } + } + // try sync service + transport = TSocketWrapper.wrap(tConfiguration, "127.0.0.1", 5555, 100); + if (transport != null && !transport.isOpen()) { + try { + transport.open(); + logger.error("stop Sync daemon failed. 5555 can be connected now."); + transport.close(); + return false; + } catch (TTransportException e) { + // do nothing + } + } + // try jmx connection + try { + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:31999/jmxrmi"); + JMXConnector jmxConnector = JMXConnectorFactory.connect(url); + logger.error("stop JMX failed. 31999 can be connected now."); + jmxConnector.close(); + return false; + } catch (IOException e) { + // do nothing + } + // try MetricService + try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress("127.0.0.1", 9091), 100); + logger.error("stop MetricService failed. 9091 can be connected now."); + return false; + } catch (Exception e) { + // do nothing + } + // do nothing + return true; + } + + public static void cleanAllDir() throws IOException { + // delete sequential files + for (String path : tierManager.getAllLocalSequenceFileFolders()) { + cleanDir(path); + } + // delete unsequence files + for (String path : tierManager.getAllLocalUnSequenceFileFolders()) { + cleanDir(path); + } + FileTimeIndexCacheRecorder.getInstance().close(); + // delete system info + cleanDir(config.getSystemDir()); + // delete query + cleanDir(config.getQueryDir()); + // delete ulog + cleanDir(config.getUdfDir()); + // delete tlog + cleanDir(config.getTriggerDir()); + // delete extPipe + cleanDir(config.getExtPipeDir()); + // delete ext + cleanDir(config.getExtDir()); + // delete mqtt dir + cleanDir(config.getMqttDir()); + // delete wal + for (String walDir : commonConfig.getWalDirs()) { + cleanDir(walDir); + } + // delete sync dir + cleanDir(commonConfig.getSyncDir()); + // delete data files + for (String dataDir : config.getDataDirs()) { + cleanDir(dataDir); + } + } + + public static void cleanDir(String dir) throws IOException { + FSFactoryProducer.getFSFactory().deleteDirectory(dir); + } + + /** disable memory control
this function should be called before all code in the setup */ + public static void envSetUp() { + logger.debug("EnvironmentUtil setup..."); + config.setThriftServerAwaitTimeForStopService(60); + + createAllDir(); + + try { + StorageEngine.getInstance().start(); + + SchemaEngine.getInstance().init(); + + CompactionTaskManager.getInstance().start(); + WALManager.getInstance().start(); + FlushManager.getInstance().start(); + } catch (StartupException e) { + throw new RuntimeException(e); + } + + TEST_QUERY_JOB_ID = QueryResourceManager.getInstance().assignQueryId(); + TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID); + } + + private static void createAllDir() { + // create sequential files + for (String path : tierManager.getAllLocalSequenceFileFolders()) { + createDir(path); + } + // create unsequential files + for (String path : tierManager.getAllLocalUnSequenceFileFolders()) { + createDir(path); + } + // create database + createDir(config.getSystemDir()); + // create sg dir + String sgDir = FilePathUtils.regularizePath(config.getSystemDir()) + "databases"; + createDir(sgDir); + // create sync + createDir(commonConfig.getSyncDir()); + // create query + createDir(config.getQueryDir()); + createDir(TestConstant.OUTPUT_DATA_DIR); + // create wal + for (String walDir : commonConfig.getWalDirs()) { + createDir(walDir); + } + // create data + for (String dataDir : config.getDataDirs()) { + createDir(dataDir); + } + } + + private static void createDir(String dir) { + File file = FSFactoryProducer.getFSFactory().getFile(dir); + file.mkdirs(); + } + + public static void recursiveDeleteFolder(String path) throws IOException { + File file = new File(path); + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files == null || files.length == 0) { + FileUtils.deleteDirectory(file); + } else { + for (File f : files) { + recursiveDeleteFolder(f.getAbsolutePath()); + } + FileUtils.deleteDirectory(file); + } + } else { + FileUtils.delete(file); + } + } +} diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java similarity index 99% rename from iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java rename to external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java index 55d7474245340..c8189e5883651 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/GrafanaApiServiceTest.java +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java @@ -16,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.iotdb.db.protocol.rest; - -import org.apache.iotdb.db.utils.EnvironmentUtils; +package org.apache.iotdb.rest; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java similarity index 99% rename from iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java rename to external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java index 4c15d3635acac..4ce73914d5185 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/protocol/rest/IoTDBRestServiceTest.java +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java @@ -16,11 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.iotdb.db.protocol.rest; +package org.apache.iotdb.rest; import org.apache.iotdb.commons.exception.StartupException; import org.apache.iotdb.db.service.ExternalRPCService; -import org.apache.iotdb.db.utils.EnvironmentUtils; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java index d0eef468d4f94..eaa4fa0a4e992 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java @@ -75,7 +75,6 @@ import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.conf.IoTDBStartCheck; -import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; import org.apache.iotdb.db.consensus.DataRegionConsensusImpl; import org.apache.iotdb.db.consensus.SchemaRegionConsensusImpl; import org.apache.iotdb.db.pipe.agent.PipeDataNodeAgent; @@ -1311,9 +1310,6 @@ public void stop() { } private void initProtocols() throws StartupException { - if (IoTDBRestServiceDescriptor.getInstance().getConfig().isEnableRestService()) { - registerManager.register(RestService.getInstance()); - } prepareExternalServiceResources(); if (PipeConfig.getInstance().getPipeAirGapReceiverEnabled()) { registerManager.register(PipeDataNodeAgent.receiver().airGap()); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java index 4dee890e65fd8..157734aef56ce 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/externalservice/BuiltinExternalServices.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.service.externalservice; import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; import java.util.function.Supplier; @@ -31,8 +32,7 @@ public enum BuiltinExternalServices { REST( "REST", "org.apache.iotdb.rest.RestService", - // IoTDBRestServiceDescriptor.getInstance().getConfig()::isEnableRestService - () -> false); + IoTDBRestServiceDescriptor.getInstance().getConfig()::isEnableRestService); private final String serviceName; private final String className; diff --git a/iotdb-protocol/openapi/pom.xml b/iotdb-protocol/openapi/pom.xml index f31e3ba1d097d..3f1d65db1b733 100644 --- a/iotdb-protocol/openapi/pom.xml +++ b/iotdb-protocol/openapi/pom.xml @@ -91,9 +91,9 @@ ${project.basedir}/src/main/openapi3/iotdb_rest_common.yaml ${project.build.directory}/generated-sources/java - org.apache.iotdb.db.protocol.rest - org.apache.iotdb.db.protocol.rest.model - org.apache.iotdb.db.protocol.rest.invoker + org.apache.iotdb.rest.protocol + org.apache.iotdb.rest.protocol.model + org.apache.iotdb.rest.protocol.invoker jaxrs-jersey org.apache.iotdb iotdb-rest-service @@ -118,9 +118,9 @@ ${project.basedir}/src/main/openapi3/iotdb_rest_v1.yaml ${project.build.directory}/generated-sources/java - org.apache.iotdb.db.protocol.rest.v1 - org.apache.iotdb.db.protocol.rest.v1.model - org.apache.iotdb.db.protocol.rest.v1.invoker + org.apache.iotdb.rest.protocol.v1 + org.apache.iotdb.rest.protocol.v1.model + org.apache.iotdb.rest.protocol.v1.invoker jaxrs-jersey org.apache.iotdb iotdb-rest-service @@ -145,9 +145,9 @@ ${project.basedir}/src/main/openapi3/iotdb_rest_v2.yaml ${project.build.directory}/generated-sources/java - org.apache.iotdb.db.protocol.rest.v2 - org.apache.iotdb.db.protocol.rest.v2.model - org.apache.iotdb.db.protocol.rest.v2.invoker + org.apache.iotdb.rest.protocol.v2 + org.apache.iotdb.rest.protocol.v2.model + org.apache.iotdb.rest.protocol.v2.invoker jaxrs-jersey org.apache.iotdb iotdb-rest-service @@ -172,9 +172,9 @@ ${project.basedir}/src/main/openapi3/iotdb_rest_table_v1.yaml ${project.build.directory}/generated-sources/java - org.apache.iotdb.db.protocol.rest.table.v1 - org.apache.iotdb.db.protocol.rest.table.v1.model - org.apache.iotdb.db.protocol.rest.table.v1.invoker + org.apache.iotdb.rest.protocol.table.v1 + org.apache.iotdb.rest.protocol.table.v1.model + org.apache.iotdb.rest.protocol.table.v1.invoker jaxrs-jersey org.apache.iotdb iotdb-rest-service From a4bf091b27beb673baaec03843b5080b6cd27c3b Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Thu, 22 Jan 2026 14:44:00 +0800 Subject: [PATCH 02/10] Move openapi to independent module + Fix tests --- distribution/pom.xml | 6 + distribution/src/assembly/all.xml | 4 + distribution/src/assembly/datanode.xml | 4 + .../src/assembly/external-service-impl.xml | 4 + external-service-impl/pom.xml | 1 + .../rest-openapi}/pom.xml | 26 +- .../src/main/openapi3/iotdb_rest_common.yaml | 0 .../main/openapi3/iotdb_rest_table_v1.yaml | 0 .../src/main/openapi3/iotdb_rest_v1.yaml | 0 .../src/main/openapi3/iotdb_rest_v2.yaml | 0 external-service-impl/rest/pom.xml | 6 + .../org/apache/iotdb/rest/RestService.java | 26 +- .../iotdb/rest/GrafanaApiServiceTest.java | 39 +- .../iotdb/rest/IoTDBRestServiceTest.java | 355 ++++++------------ integration-test/pom.xml | 14 + integration-test/src/assembly/mpp-share.xml | 8 + iotdb-core/datanode/pom.xml | 5 - .../iotdb/commons/service/ServiceType.java | 2 +- iotdb-protocol/pom.xml | 1 - 19 files changed, 219 insertions(+), 282 deletions(-) rename {iotdb-protocol/openapi => external-service-impl/rest-openapi}/pom.xml (92%) rename {iotdb-protocol/openapi => external-service-impl/rest-openapi}/src/main/openapi3/iotdb_rest_common.yaml (100%) rename {iotdb-protocol/openapi => external-service-impl/rest-openapi}/src/main/openapi3/iotdb_rest_table_v1.yaml (100%) rename {iotdb-protocol/openapi => external-service-impl/rest-openapi}/src/main/openapi3/iotdb_rest_v1.yaml (100%) rename {iotdb-protocol/openapi => external-service-impl/rest-openapi}/src/main/openapi3/iotdb_rest_v2.yaml (100%) diff --git a/distribution/pom.xml b/distribution/pom.xml index 65a3572fd3a55..f7732a95d0ca5 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -65,6 +65,12 @@ 2.0.7-SNAPSHOT provided + + org.apache.iotdb + rest-openapi + 2.0.7-SNAPSHOT + provided + diff --git a/distribution/src/assembly/all.xml b/distribution/src/assembly/all.xml index 1b2e1be054f3e..1a927fc613f0e 100644 --- a/distribution/src/assembly/all.xml +++ b/distribution/src/assembly/all.xml @@ -100,6 +100,10 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar lib + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar + lib + common-files.xml diff --git a/distribution/src/assembly/datanode.xml b/distribution/src/assembly/datanode.xml index 225fa5a7e7d28..87d4f027783d2 100644 --- a/distribution/src/assembly/datanode.xml +++ b/distribution/src/assembly/datanode.xml @@ -83,6 +83,10 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar lib + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar + lib + common-files.xml diff --git a/distribution/src/assembly/external-service-impl.xml b/distribution/src/assembly/external-service-impl.xml index c743fa8559720..0cb610563a581 100644 --- a/distribution/src/assembly/external-service-impl.xml +++ b/distribution/src/assembly/external-service-impl.xml @@ -51,5 +51,9 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar / + + ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar + / + diff --git a/external-service-impl/pom.xml b/external-service-impl/pom.xml index 9c484ff270448..04483b289f32f 100644 --- a/external-service-impl/pom.xml +++ b/external-service-impl/pom.xml @@ -32,6 +32,7 @@ mqtt rest + rest-openapi 8 diff --git a/iotdb-protocol/openapi/pom.xml b/external-service-impl/rest-openapi/pom.xml similarity index 92% rename from iotdb-protocol/openapi/pom.xml rename to external-service-impl/rest-openapi/pom.xml index 3f1d65db1b733..b1a2fe475c696 100644 --- a/iotdb-protocol/openapi/pom.xml +++ b/external-service-impl/rest-openapi/pom.xml @@ -23,11 +23,11 @@ 4.0.0 org.apache.iotdb - iotdb-protocol + external-service-impl 2.0.7-SNAPSHOT - openapi - IoTDB: Protocol: OpenAPI + rest-openapi + IoTDB: External-Service-Impl: Rest-OpenAPI io.swagger @@ -234,6 +234,26 @@ + + maven-assembly-plugin + ${maven.assembly.version} + + + jar-with-dependencies + + + + + make-assembly + + + single + + + package + + +
diff --git a/iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_common.yaml b/external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_common.yaml similarity index 100% rename from iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_common.yaml rename to external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_common.yaml diff --git a/iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_table_v1.yaml b/external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_table_v1.yaml similarity index 100% rename from iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_table_v1.yaml rename to external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_table_v1.yaml diff --git a/iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_v1.yaml b/external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_v1.yaml similarity index 100% rename from iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_v1.yaml rename to external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_v1.yaml diff --git a/iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_v2.yaml b/external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_v2.yaml similarity index 100% rename from iotdb-protocol/openapi/src/main/openapi3/iotdb_rest_v2.yaml rename to external-service-impl/rest-openapi/src/main/openapi3/iotdb_rest_v2.yaml diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index 24f52dd2bcadb..6f3116366fdcd 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -56,6 +56,12 @@ httpclient test + + org.apache.iotdb + rest-openapi + 2.0.7-SNAPSHOT + compile + diff --git a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java index a9512f3e90f8d..9a90e6b18f2ea 100644 --- a/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java +++ b/external-service-impl/rest/src/main/java/org/apache/iotdb/rest/RestService.java @@ -16,11 +16,9 @@ */ package org.apache.iotdb.rest; -import org.apache.iotdb.commons.exception.StartupException; -import org.apache.iotdb.commons.service.IService; -import org.apache.iotdb.commons.service.ServiceType; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceConfig; import org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor; +import org.apache.iotdb.externalservice.api.IExternalService; import org.apache.iotdb.rest.protocol.filter.ApiOriginFilter; import org.eclipse.jetty.http.HttpVersion; @@ -41,7 +39,7 @@ import java.util.EnumSet; -public class RestService implements IService { +public class RestService implements IExternalService { private static final Logger LOGGER = LoggerFactory.getLogger(RestService.class); @@ -97,7 +95,7 @@ private ServletContextHandler constructServletContextHandler() { holder.setInitOrder(1); holder.setInitParameter( "jersey.config.server.provider.packages", - "io.swagger.jaxrs.listing, io.swagger.sample.resource, org.apache.iotdb.db.protocol.rest"); + "io.swagger.jaxrs.listing, io.swagger.sample.resource, org.apache.iotdb.rest.protocol"); holder.setInitParameter( "jersey.config.server.provider.classnames", "org.glassfish.jersey.media.multipart.MultiPartFeature"); @@ -117,7 +115,7 @@ private void serverStart() { } @Override - public void start() throws StartupException { + public void start() { IoTDBRestServiceConfig config = IoTDBRestServiceDescriptor.getInstance().getConfig(); if (IoTDBRestServiceDescriptor.getInstance().getConfig().isEnableHttps()) { startSSL( @@ -143,20 +141,4 @@ public void stop() { server.destroy(); } } - - @Override - public ServiceType getID() { - return ServiceType.REST_SERVICE; - } - - public static RestService getInstance() { - return RestServiceHolder.INSTANCE; - } - - private static class RestServiceHolder { - - private static final RestService INSTANCE = new RestService(); - - private RestServiceHolder() {} - } } diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java index c8189e5883651..3706598602d92 100644 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java @@ -29,11 +29,11 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; +import org.junit.runners.MethodSorters; import java.io.IOException; import java.nio.charset.Charset; @@ -47,16 +47,8 @@ // move to integration-test @Ignore +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GrafanaApiServiceTest { - @Before - public void setUp() throws Exception { - EnvironmentUtils.envSetUp(); - } - - @After - public void tearDown() throws Exception { - EnvironmentUtils.cleanEnv(); - } private String getAuthorization(String username, String password) { return Base64.getEncoder() @@ -445,4 +437,29 @@ public void expressionWithAggGroupByLevelTest() { fail(e.getMessage()); } } + + @Test + public void zDeleteTablet() { + CloseableHttpResponse response = null; + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + try { + HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/nonQuery"); + String sql = "{\"sql\":\"drop database root.sg25\"}"; + httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); + response = httpClient.execute(httpPost); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } finally { + try { + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + } } diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java index 4ce73914d5185..c29cc1d7392fe 100644 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java @@ -18,9 +18,6 @@ */ package org.apache.iotdb.rest; -import org.apache.iotdb.commons.exception.StartupException; -import org.apache.iotdb.db.service.ExternalRPCService; - import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -32,9 +29,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; @@ -54,17 +49,8 @@ // Move it to integration-test @Ignore -@FixMethodOrder(MethodSorters.JVM) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class IoTDBRestServiceTest { - @Before - public void setUp() throws Exception { - EnvironmentUtils.envSetUp(); - } - - @After - public void tearDown() throws Exception { - EnvironmentUtils.cleanEnv(); - } private String getAuthorization(String username, String password) { return Base64.getEncoder() @@ -72,7 +58,7 @@ private String getAuthorization(String username, String password) { } @Test - public void ping() { + public void aPing() { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/ping"); CloseableHttpResponse response = null; @@ -84,17 +70,7 @@ public void ping() { assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(200, Integer.parseInt(result.get("code").toString())); - // Shutdown RPCService to test - ExternalRPCService.getInstance().stop(); - response = httpClient.execute(httpGet); - responseEntity = response.getEntity(); - message = EntityUtils.toString(responseEntity, "utf-8"); - result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(503, response.getStatusLine().getStatusCode()); - assertEquals(500, Integer.parseInt(result.get("code").toString())); - ExternalRPCService.getInstance().start(); - - } catch (IOException | StartupException e) { + } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); } finally { @@ -161,7 +137,7 @@ public void errorInsertTablet() { HttpEntity responseEntity = response.getEntity(); String message = EntityUtils.toString(responseEntity, "utf-8"); JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(413, Integer.parseInt(result.get("code").toString())); + assertEquals(606, Integer.parseInt(result.get("code").toString())); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -222,7 +198,7 @@ public void queryWithUnsetAuthorization() { Assert.assertEquals(401, response.getStatusLine().getStatusCode()); String message = EntityUtils.toString(response.getEntity(), "utf-8"); JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(603, Integer.parseInt(result.get("code").toString())); + assertEquals(800, Integer.parseInt(result.get("code").toString())); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -254,7 +230,32 @@ public void queryWithWrongAuthorization() { Assert.assertEquals(401, response.getStatusLine().getStatusCode()); String message = EntityUtils.toString(response.getEntity(), "utf-8"); JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(600, Integer.parseInt(result.get("code").toString())); + Assert.assertEquals(801, Integer.parseInt(result.get("code").toString())); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } finally { + try { + if (response != null) { + response.close(); + } + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + } + + @Test + public void zDeleteTablet() { + CloseableHttpResponse response = null; + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + try { + HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/nonQuery"); + String sql = "{\"sql\":\"drop database root.sg25\"}"; + httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); + response = httpClient.execute(httpPost); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); @@ -468,23 +469,17 @@ public void queryShowChildPaths(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("child paths"); - add("node types"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); + add("ChildPaths"); + add("NodeTypes"); } }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); + String targetPath = "root.sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetPath)); } public void queryShowNodes(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show child nodes root\",\"rowLimit\":1}"; + String sql = "{\"sql\":\"show child nodes root\"}"; Map map = queryMetaData(httpClient, sql); List columnNamesResult = (List) map.get("columnNames"); List> valuesResult = (List>) map.get("values"); @@ -492,18 +487,12 @@ public void queryShowNodes(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("child nodes"); + add("ChildNodes"); } }; - List values1 = - new ArrayList() { - { - add("sg25"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); + String targetNode = "sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetNode)); } public void showAllTTL(CloseableHttpClient httpClient) { @@ -515,25 +504,11 @@ public void showAllTTL(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("database"); - add("ttl"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); - } - }; - List values2 = - new ArrayList() { - { - add(null); + add("Device"); + add("TTL(ms)"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); } public void showStorageGroup(CloseableHttpClient httpClient) { @@ -545,17 +520,16 @@ public void showStorageGroup(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("database"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); + add("Database"); + add("SchemaReplicationFactor"); + add("DataReplicationFactor"); + add("TimePartitionOrigin"); + add("TimePartitionInterval"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); + String targetDatabase = "root.sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetDatabase)); } public void showFunctions(CloseableHttpClient httpClient) { @@ -563,8 +537,8 @@ public void showFunctions(CloseableHttpClient httpClient) { Map map = queryMetaData(httpClient, sql); List columnNamesResult = (List) map.get("columnNames"); List> valuesResult = (List>) map.get("values"); - assertEquals(3, columnNamesResult.size()); - assertEquals(3, valuesResult.size()); + assertEquals(4, columnNamesResult.size()); + assertEquals(4, valuesResult.size()); } public void showTimeseries(CloseableHttpClient httpClient) { @@ -576,16 +550,17 @@ public void showTimeseries(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("timeseries"); - add("alias"); - add("database"); - add("dataType"); - add("encoding"); - add("compression"); - add("tags"); - add("attributes"); - add("deadband"); - add("deadbandparameters"); + add("Timeseries"); + add("Alias"); + add("Database"); + add("DataType"); + add("Encoding"); + add("Compression"); + add("Tags"); + add("Attributes"); + add("Deadband"); + add("DeadbandParameters"); + add("ViewType"); } }; List values1 = @@ -599,33 +574,10 @@ public void showTimeseries(CloseableHttpClient httpClient) { add("root.sg25.s8"); } }; - List values2 = - new ArrayList() { - { - add(null); - add(null); - add(null); - add(null); - add(null); - add(null); - } - }; - List values3 = - new ArrayList() { - { - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); - Assert.assertEquals(values3, valuesResult.get(2)); + for (Object timeSeries : values1) { + Assert.assertTrue(valuesResult.get(0).contains(timeSeries)); + } } public void showLastTimeseries(CloseableHttpClient httpClient) { @@ -637,16 +589,17 @@ public void showLastTimeseries(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("timeseries"); - add("alias"); - add("database"); - add("dataType"); - add("encoding"); - add("compression"); - add("tags"); - add("attributes"); - add("deadband"); - add("deadbandparameters"); + add("Timeseries"); + add("Alias"); + add("Database"); + add("DataType"); + add("Encoding"); + add("Compression"); + add("Tags"); + add("Attributes"); + add("Deadband"); + add("DeadbandParameters"); + add("ViewType"); } }; List values1 = @@ -660,33 +613,10 @@ public void showLastTimeseries(CloseableHttpClient httpClient) { add("root.sg25.s6"); } }; - List values2 = - new ArrayList() { - { - add(null); - add(null); - add(null); - add(null); - add(null); - add(null); - } - }; - List values3 = - new ArrayList() { - { - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - add("root.sg25"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); - Assert.assertEquals(values3, valuesResult.get(2)); + for (Object timeSeries : values1) { + Assert.assertTrue(valuesResult.get(0).contains(timeSeries)); + } } public void countTimeseries(CloseableHttpClient httpClient) { @@ -698,26 +628,16 @@ public void countTimeseries(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("column"); - add("count"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); + add("Column"); + add("count(timeseries)"); } }; - List values2 = - new ArrayList() { - { - add(6); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); + String targetDatabase = "root.sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetDatabase)); + int rowIndex = valuesResult.get(0).indexOf(targetDatabase); + int targetCount = 6; + Assert.assertEquals(targetCount, valuesResult.get(1).get(rowIndex)); } public void countNodes(CloseableHttpClient httpClient) { @@ -729,17 +649,11 @@ public void countNodes(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("count"); - } - }; - List values1 = - new ArrayList() { - { - add(6); + add("count(nodes)"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); + Assert.assertTrue((int) valuesResult.get(0).get(0) > 6); } public void showDevices(CloseableHttpClient httpClient) { @@ -751,32 +665,19 @@ public void showDevices(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("devices"); - add("isAligned"); + add("Device"); + add("IsAligned"); add("Template"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); - } - }; - List values2 = - new ArrayList() { - { - add(false); - } - }; - List values3 = - new ArrayList() { - { - add("null"); + add("TTL(ms)"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - // Assert.assertEquals(values2, valuesResult.get(1)); + String targetDevice = "root.sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetDevice)); + int rowIndex = valuesResult.get(0).indexOf(targetDevice); + Assert.assertEquals("false", valuesResult.get(1).get(rowIndex)); + Assert.assertNull(valuesResult.get(2).get(rowIndex)); + Assert.assertEquals("INF", valuesResult.get(3).get(rowIndex)); } public void showDevicesWithStroage(CloseableHttpClient httpClient) { @@ -788,41 +689,21 @@ public void showDevicesWithStroage(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("devices"); - add("database"); - add("isAligned"); + add("Device"); + add("Database"); + add("IsAligned"); add("Template"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25"); - } - }; - List values2 = - new ArrayList() { - { - add("root.sg25"); - } - }; - List values3 = - new ArrayList() { - { - add("false"); - } - }; - List values4 = - new ArrayList() { - { - add("null"); + add("TTL(ms)"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); - Assert.assertEquals(values3, valuesResult.get(2)); - Assert.assertEquals(values4, valuesResult.get(3)); + String targetDevice = "root.sg25"; + Assert.assertTrue(valuesResult.get(0).contains(targetDevice)); + int rowIndex = valuesResult.get(0).indexOf(targetDevice); + Assert.assertEquals(targetDevice, valuesResult.get(1).get(rowIndex)); + Assert.assertEquals("false", valuesResult.get(2).get(rowIndex)); + Assert.assertNull(valuesResult.get(3).get(rowIndex)); + Assert.assertEquals("INF", valuesResult.get(4).get(rowIndex)); } public void listUser(CloseableHttpClient httpClient) { @@ -834,23 +715,19 @@ public void listUser(CloseableHttpClient httpClient) { List columnNames = new ArrayList() { { - add("user"); - } - }; - List values1 = - new ArrayList() { - { - add("root"); + add("UserId"); + add("User"); } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); + Assert.assertTrue(valuesResult.get(0).contains(0)); + Assert.assertTrue(valuesResult.get(1).contains("root")); } public void selectCount(CloseableHttpClient httpClient) { String sql = "{\"sql\":\"select count(s3) from root.** group by level = 1\"}"; Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); + List columnNamesResult = (List) map.get("expressions"); List> valuesResult = (List>) map.get("values"); Assert.assertTrue(map.size() > 0); List columnNames = @@ -872,16 +749,16 @@ public void selectCount(CloseableHttpClient httpClient) { public void selectLast(CloseableHttpClient httpClient) { String sql = "{\"sql\":\"select last s4 from root.sg25\"}"; Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); + List columnNamesResult = (List) map.get("expressions"); List> valuesResult = (List>) map.get("values"); List timestampsResult = (List) map.get("timestamps"); Assert.assertTrue(map.size() > 0); List columnNames = new ArrayList() { { - add("timeseries"); - add("value"); - add("dataType"); + add("Timeseries"); + add("Value"); + add("DataType"); } }; List timestamps = diff --git a/integration-test/pom.xml b/integration-test/pom.xml index c82a63c3f3b15..4c6730ebb6c03 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -239,6 +239,20 @@ provided + + org.apache.iotdb + rest + 2.0.7-SNAPSHOT + + provided + + + org.apache.iotdb + rest-openapi + 2.0.7-SNAPSHOT + + provided + diff --git a/integration-test/src/assembly/mpp-share.xml b/integration-test/src/assembly/mpp-share.xml index 96ac13e64d179..fae1b09f7bc51 100644 --- a/integration-test/src/assembly/mpp-share.xml +++ b/integration-test/src/assembly/mpp-share.xml @@ -35,5 +35,13 @@ ${project.basedir}/../external-service-impl/mqtt/target/mqtt-${project.version}-jar-with-dependencies.jar lib + + ${project.basedir}/../external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar + lib + + + ${project.basedir}/../external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar + lib + diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml index b55fd8e5c6827..dac6878209c71 100644 --- a/iotdb-core/datanode/pom.xml +++ b/iotdb-core/datanode/pom.xml @@ -59,11 +59,6 @@ external-api 2.0.7-SNAPSHOT - - org.apache.iotdb - openapi - 2.0.7-SNAPSHOT - org.apache.iotdb node-commons diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java index 55fad14e5a10f..e8d5a98af5e2d 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java @@ -67,7 +67,7 @@ public enum ServiceType { "Cluster Data Heartbeat RPC Service", "ClusterDataHeartbeatRPCService"), CLUSTER_META_ENGINE("Cluster Meta Engine", "ClusterMetaEngine"), CLUSTER_DATA_ENGINE("Cluster Data Engine", "ClusterDataEngine"), - REST_SERVICE("REST Service", "REST Service"), + // REST_SERVICE("REST Service", "REST Service"), CONFIG_NODE_SERVICE("Config Node service", "ConfigNodeRPCServer"), DATA_NODE_REGION_MIGRATE_SERVICE("Data Node Region Migrate service", ""), DATA_NODE_MANAGEMENT_SERVICE("Data Node management service", "DataNodeManagementServer"), diff --git a/iotdb-protocol/pom.xml b/iotdb-protocol/pom.xml index 853a97ab20938..3d1cfa12effcc 100644 --- a/iotdb-protocol/pom.xml +++ b/iotdb-protocol/pom.xml @@ -30,7 +30,6 @@ pom IoTDB: Protocol - openapi thrift-datanode thrift-commons thrift-confignode From c684121626235ac646a5cbcd8e1598993943a56e Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Mon, 26 Jan 2026 19:20:09 +0800 Subject: [PATCH 03/10] Fix dependencies --- distribution/pom.xml | 6 - distribution/src/assembly/all.xml | 4 - distribution/src/assembly/datanode.xml | 4 - .../src/assembly/external-service-impl.xml | 4 - external-service-impl/mqtt/pom.xml | 11 ++ external-service-impl/pom.xml | 22 +-- external-service-impl/rest/pom.xml | 144 +++++++++++++++++- .../iotdb/rest/IoTDBRestServiceTest.java | 2 +- iotdb-core/datanode/pom.xml | 39 ----- 9 files changed, 163 insertions(+), 73 deletions(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index f7732a95d0ca5..65a3572fd3a55 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -65,12 +65,6 @@ 2.0.7-SNAPSHOT provided - - org.apache.iotdb - rest-openapi - 2.0.7-SNAPSHOT - provided - diff --git a/distribution/src/assembly/all.xml b/distribution/src/assembly/all.xml index 1a927fc613f0e..1b2e1be054f3e 100644 --- a/distribution/src/assembly/all.xml +++ b/distribution/src/assembly/all.xml @@ -100,10 +100,6 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar lib - - ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar - lib - common-files.xml diff --git a/distribution/src/assembly/datanode.xml b/distribution/src/assembly/datanode.xml index 87d4f027783d2..225fa5a7e7d28 100644 --- a/distribution/src/assembly/datanode.xml +++ b/distribution/src/assembly/datanode.xml @@ -83,10 +83,6 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar lib - - ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar - lib - common-files.xml diff --git a/distribution/src/assembly/external-service-impl.xml b/distribution/src/assembly/external-service-impl.xml index 0cb610563a581..c743fa8559720 100644 --- a/distribution/src/assembly/external-service-impl.xml +++ b/distribution/src/assembly/external-service-impl.xml @@ -51,9 +51,5 @@ ${maven.multiModuleProjectDirectory}/external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar / - - ${maven.multiModuleProjectDirectory}/external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar - / - diff --git a/external-service-impl/mqtt/pom.xml b/external-service-impl/mqtt/pom.xml index 5ec51069b212e..9509d443ed3ea 100644 --- a/external-service-impl/mqtt/pom.xml +++ b/external-service-impl/mqtt/pom.xml @@ -34,6 +34,17 @@ UTF-8 + + org.apache.iotdb + external-service-api + provided + 2.0.7-SNAPSHOT + + + junit + junit + test + com.github.moquette-io.moquette moquette-broker diff --git a/external-service-impl/pom.xml b/external-service-impl/pom.xml index 04483b289f32f..e150b92ba590d 100644 --- a/external-service-impl/pom.xml +++ b/external-service-impl/pom.xml @@ -40,16 +40,16 @@ UTF-8 - - org.apache.iotdb - external-service-api - provided - 2.0.7-SNAPSHOT - - - junit - junit - test - + + + + + + + + + + + diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index 6f3116366fdcd..45f7e045df8ab 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -34,6 +34,52 @@ UTF-8 + + + org.apache.iotdb + rest-openapi + 2.0.7-SNAPSHOT + + + jakarta.servlet + jakarta.servlet-api + + + com.fasterxml.jackson.core + jackson-databind + + + + + jakarta.servlet + jakarta.servlet-api + + + org.glassfish.jersey.containers + jersey-container-servlet-core + + + org.eclipse.jetty + jetty-servlet + + + org.eclipse.jetty + jetty-util + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-http + + + org.apache.iotdb + external-service-api + provided + 2.0.7-SNAPSHOT + org.apache.iotdb node-commons @@ -46,21 +92,102 @@ 2.0.7-SNAPSHOT provided + + org.apache.iotdb + iotdb-session + 2.0.7-SNAPSHOT + provided + + + org.apache.iotdb + udf-api + 2.0.7-SNAPSHOT + provided + + + com.google.guava + guava + provided + + + org.slf4j + slf4j-api + provided + + + com.google.code.gson + gson + provided + + + com.github.ben-manes.caffeine + caffeine + provided + + + org.apache.iotdb + service-rpc + 2.0.7-SNAPSHOT + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + org.apache.iotdb + iotdb-thrift + 2.0.7-SNAPSHOT + provided + + + org.apache.tsfile + tsfile + ${tsfile.version} + provided + + + org.apache.tsfile + common + ${tsfile.version} + provided + + + org.apache.thrift + libthrift + provided + + + org.apache.iotdb + iotdb-thrift-commons + 2.0.7-SNAPSHOT + provided + + + org.antlr + antlr4-runtime + provided + org.apache.httpcomponents httpcore test + + com.fasterxml.jackson.core + jackson-databind + test + org.apache.httpcomponents httpclient test - org.apache.iotdb - rest-openapi - 2.0.7-SNAPSHOT - compile + junit + junit + test @@ -85,6 +212,15 @@ + + org.apache.maven.plugins + maven-dependency-plugin + + + org.apache.tsfile:common + + + diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java index c29cc1d7392fe..42eb8a9e3d077 100644 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java +++ b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java @@ -653,7 +653,7 @@ public void countNodes(CloseableHttpClient httpClient) { } }; Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertTrue((int) valuesResult.get(0).get(0) > 6); + Assert.assertTrue((int) valuesResult.get(0).get(0) >= 6); } public void showDevices(CloseableHttpClient httpClient) { diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml index dac6878209c71..2198a2ab0d624 100644 --- a/iotdb-core/datanode/pom.xml +++ b/iotdb-core/datanode/pom.xml @@ -183,10 +183,6 @@ org.eclipse.milo sdk-core - - jakarta.servlet - jakarta.servlet-api - org.eclipse.milo stack-server @@ -203,10 +199,6 @@ org.bouncycastle bcprov-jdk18on - - org.eclipse.jetty - jetty-http - org.apache.commons commons-pool2 @@ -215,18 +207,10 @@ org.antlr antlr4-runtime - - org.eclipse.jetty - jetty-util - io.airlift airline - - org.eclipse.jetty - jetty-server - org.eclipse.milo sdk-server @@ -254,28 +238,15 @@ - - org.glassfish.jersey.containers - jersey-container-servlet-core - com.google.code.gson gson - - org.eclipse.jetty - jetty-servlet - org.glassfish.jersey.inject jersey-hk2 runtime - - com.fasterxml.jackson.core - jackson-databind - runtime - com.github.ben-manes.caffeine caffeine @@ -325,11 +296,6 @@ json-smart test - - org.apache.httpcomponents - httpcore - test - org.apache.ratis ratis-thirdparty-misc @@ -340,11 +306,6 @@ oauth2-oidc-sdk test - - org.apache.httpcomponents - httpclient - test - org.powermock powermock-core From 48abc0b2b5cc7b2e09b227f4f7e29b09ac653cda Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Tue, 27 Jan 2026 20:13:34 +0800 Subject: [PATCH 04/10] Fix dependencies --- external-service-impl/rest/pom.xml | 44 +++++++++++++++++++++++------- iotdb-core/datanode/pom.xml | 7 ----- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index 45f7e045df8ab..c5da3b3a1349e 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -34,19 +34,23 @@ UTF-8 - + + org.glassfish.jersey.inject + jersey-hk2 + runtime + org.apache.iotdb rest-openapi 2.0.7-SNAPSHOT - jakarta.servlet - jakarta.servlet-api + jakarta.xml.bind + jakarta.xml.bind-api - com.fasterxml.jackson.core - jackson-databind + jakarta.validation + jakarta.validation-api @@ -57,6 +61,16 @@ org.glassfish.jersey.containers jersey-container-servlet-core + + + jakarta.validation + jakarta.validation-api + + + + + com.fasterxml.jackson.core + jackson-databind org.eclipse.jetty @@ -174,11 +188,6 @@ httpcore test - - com.fasterxml.jackson.core - jackson-databind - test - org.apache.httpcomponents httpclient @@ -216,10 +225,25 @@ org.apache.maven.plugins maven-dependency-plugin + ${project.build.directory}/dependency + runtime org.apache.tsfile:common + + + org.glassfish.jersey.inject:jersey-hk2 + + + + copy-dependencies + package + + copy-dependencies + + + diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml index 2198a2ab0d624..3b43e040f2343 100644 --- a/iotdb-core/datanode/pom.xml +++ b/iotdb-core/datanode/pom.xml @@ -242,11 +242,6 @@ com.google.code.gson gson - - org.glassfish.jersey.inject - jersey-hk2 - runtime - com.github.ben-manes.caffeine caffeine @@ -494,8 +489,6 @@ io.jsonwebtoken:jjwt-impl io.jsonwebtoken:jjwt-jackson - - org.glassfish.jersey.inject:jersey-hk2 From 3fbe138203b26b77f501858b0745d893ccf562b3 Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 14:37:37 +0800 Subject: [PATCH 05/10] Remove unnecessary code --- external-service-impl/pom.xml | 13 ------ external-service-impl/rest/pom.xml | 46 +++++++++++++------ iotdb-core/confignode/pom.xml | 6 --- iotdb-core/datanode/pom.xml | 6 +++ .../iotdb/commons/service/ServiceType.java | 1 - 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/external-service-impl/pom.xml b/external-service-impl/pom.xml index e150b92ba590d..3b57780cef430 100644 --- a/external-service-impl/pom.xml +++ b/external-service-impl/pom.xml @@ -39,17 +39,4 @@ 8 UTF-8 - - - - - - - - - - - - - diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index c5da3b3a1349e..d9778dca6b450 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -38,20 +38,39 @@ org.glassfish.jersey.inject jersey-hk2 runtime + + + + jakarta.annotation + jakarta.annotation-api + + + + + com.fasterxml.jackson.core + jackson-databind + runtime org.apache.iotdb rest-openapi 2.0.7-SNAPSHOT + jakarta.xml.bind jakarta.xml.bind-api + jakarta.validation jakarta.validation-api + + + org.javassist + javassist + @@ -62,16 +81,18 @@ org.glassfish.jersey.containers jersey-container-servlet-core + jakarta.validation jakarta.validation-api + + + jakarta.annotation + jakarta.annotation-api + - - com.fasterxml.jackson.core - jackson-databind - org.eclipse.jetty jetty-servlet @@ -137,6 +158,12 @@ com.github.ben-manes.caffeine caffeine provided + + + org.checkerframework + checker-qual + + org.apache.iotdb @@ -225,8 +252,6 @@ org.apache.maven.plugins maven-dependency-plugin - ${project.build.directory}/dependency - runtime org.apache.tsfile:common @@ -235,15 +260,6 @@ org.glassfish.jersey.inject:jersey-hk2 - - - copy-dependencies - package - - copy-dependencies - - - diff --git a/iotdb-core/confignode/pom.xml b/iotdb-core/confignode/pom.xml index 805848aadaf0e..1112363f46631 100644 --- a/iotdb-core/confignode/pom.xml +++ b/iotdb-core/confignode/pom.xml @@ -132,12 +132,6 @@ org.reflections reflections test - - - org.javassist - javassist - - com.google.code.findbugs diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml index 3b43e040f2343..6c131b5ed081c 100644 --- a/iotdb-core/datanode/pom.xml +++ b/iotdb-core/datanode/pom.xml @@ -245,6 +245,12 @@ com.github.ben-manes.caffeine caffeine + + + org.checkerframework + checker-qual + + com.google.guava diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java index e8d5a98af5e2d..7180f1e092c0b 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/ServiceType.java @@ -67,7 +67,6 @@ public enum ServiceType { "Cluster Data Heartbeat RPC Service", "ClusterDataHeartbeatRPCService"), CLUSTER_META_ENGINE("Cluster Meta Engine", "ClusterMetaEngine"), CLUSTER_DATA_ENGINE("Cluster Data Engine", "ClusterDataEngine"), - // REST_SERVICE("REST Service", "REST Service"), CONFIG_NODE_SERVICE("Config Node service", "ConfigNodeRPCServer"), DATA_NODE_REGION_MIGRATE_SERVICE("Data Node Region Migrate service", ""), DATA_NODE_MANAGEMENT_SERVICE("Data Node management service", "DataNodeManagementServer"), From c984e4866db272ce0b395e6adcf3764c825d4cad Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 14:47:28 +0800 Subject: [PATCH 06/10] Add comments --- external-service-impl/rest/pom.xml | 1 + iotdb-core/datanode/pom.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index d9778dca6b450..f834c03c0d206 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -159,6 +159,7 @@ caffeine provided + org.checkerframework checker-qual diff --git a/iotdb-core/datanode/pom.xml b/iotdb-core/datanode/pom.xml index 6c131b5ed081c..2ccae580549f2 100644 --- a/iotdb-core/datanode/pom.xml +++ b/iotdb-core/datanode/pom.xml @@ -246,6 +246,7 @@ com.github.ben-manes.caffeine caffeine + org.checkerframework checker-qual From 3a15324d319944ca253baaef8b71d175a91305e4 Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 15:08:58 +0800 Subject: [PATCH 07/10] Remove unnecessary code --- external-service-impl/rest-openapi/pom.xml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/external-service-impl/rest-openapi/pom.xml b/external-service-impl/rest-openapi/pom.xml index b1a2fe475c696..940c4925cf71c 100644 --- a/external-service-impl/rest-openapi/pom.xml +++ b/external-service-impl/rest-openapi/pom.xml @@ -234,26 +234,6 @@ - - maven-assembly-plugin - ${maven.assembly.version} - - - jar-with-dependencies - - - - - make-assembly - - - single - - - package - - - From b50a9568b6313120ae5ebec0d691cc608f6b826e Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 16:40:33 +0800 Subject: [PATCH 08/10] Remove unnecessary code + Move dependencies --- external-service-impl/mqtt/pom.xml | 11 ----------- external-service-impl/pom.xml | 13 +++++++++++++ external-service-impl/rest-openapi/pom.xml | 4 ++++ external-service-impl/rest/pom.xml | 11 ----------- integration-test/pom.xml | 7 ------- integration-test/src/assembly/mpp-share.xml | 4 ---- 6 files changed, 17 insertions(+), 33 deletions(-) diff --git a/external-service-impl/mqtt/pom.xml b/external-service-impl/mqtt/pom.xml index 9509d443ed3ea..5ec51069b212e 100644 --- a/external-service-impl/mqtt/pom.xml +++ b/external-service-impl/mqtt/pom.xml @@ -34,17 +34,6 @@ UTF-8 - - org.apache.iotdb - external-service-api - provided - 2.0.7-SNAPSHOT - - - junit - junit - test - com.github.moquette-io.moquette moquette-broker diff --git a/external-service-impl/pom.xml b/external-service-impl/pom.xml index 3b57780cef430..04483b289f32f 100644 --- a/external-service-impl/pom.xml +++ b/external-service-impl/pom.xml @@ -39,4 +39,17 @@ 8 UTF-8 + + + org.apache.iotdb + external-service-api + provided + 2.0.7-SNAPSHOT + + + junit + junit + test + + diff --git a/external-service-impl/rest-openapi/pom.xml b/external-service-impl/rest-openapi/pom.xml index 940c4925cf71c..3b46227cf61f1 100644 --- a/external-service-impl/rest-openapi/pom.xml +++ b/external-service-impl/rest-openapi/pom.xml @@ -232,6 +232,10 @@ org.glassfish.jersey.media:jersey-media-multipart + + org.apache.iotdb:external-service-api + junit:junit + diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index f834c03c0d206..787dea180e3e3 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -109,12 +109,6 @@ org.eclipse.jetty jetty-http - - org.apache.iotdb - external-service-api - provided - 2.0.7-SNAPSHOT - org.apache.iotdb node-commons @@ -221,11 +215,6 @@ httpclient test - - junit - junit - test - diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 4c6730ebb6c03..a4776a57c55f0 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -246,13 +246,6 @@ provided - - org.apache.iotdb - rest-openapi - 2.0.7-SNAPSHOT - - provided - diff --git a/integration-test/src/assembly/mpp-share.xml b/integration-test/src/assembly/mpp-share.xml index fae1b09f7bc51..70072e8282ec6 100644 --- a/integration-test/src/assembly/mpp-share.xml +++ b/integration-test/src/assembly/mpp-share.xml @@ -39,9 +39,5 @@ ${project.basedir}/../external-service-impl/rest/target/rest-${project.version}-jar-with-dependencies.jar lib - - ${project.basedir}/../external-service-impl/rest-openapi/target/rest-openapi-${project.version}-jar-with-dependencies.jar - lib - From 2288a13454366f4c43b09b8354c55c62fd10d453 Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 16:57:33 +0800 Subject: [PATCH 09/10] Remove unnecessary tests --- .../apache/iotdb/rest/EnvironmentUtils.java | 334 -------- .../iotdb/rest/GrafanaApiServiceTest.java | 465 ---------- .../iotdb/rest/IoTDBRestServiceTest.java | 794 ------------------ 3 files changed, 1593 deletions(-) delete mode 100644 external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java delete mode 100644 external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java delete mode 100644 external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java deleted file mode 100644 index 7ffcef0220718..0000000000000 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/EnvironmentUtils.java +++ /dev/null @@ -1,334 +0,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.iotdb.rest; - -import org.apache.iotdb.commons.cluster.NodeStatus; -import org.apache.iotdb.commons.conf.CommonConfig; -import org.apache.iotdb.commons.conf.CommonDescriptor; -import org.apache.iotdb.commons.exception.StartupException; -import org.apache.iotdb.db.conf.DataNodeMemoryConfig; -import org.apache.iotdb.db.conf.IoTDBConfig; -import org.apache.iotdb.db.conf.IoTDBDescriptor; -import org.apache.iotdb.db.exception.StorageEngineException; -import org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext; -import org.apache.iotdb.db.queryengine.execution.fragment.QueryContext; -import org.apache.iotdb.db.queryengine.plan.udf.UDFManagementService; -import org.apache.iotdb.db.schemaengine.SchemaEngine; -import org.apache.iotdb.db.storageengine.StorageEngine; -import org.apache.iotdb.db.storageengine.buffer.BloomFilterCache; -import org.apache.iotdb.db.storageengine.buffer.ChunkCache; -import org.apache.iotdb.db.storageengine.buffer.TimeSeriesMetadataCache; -import org.apache.iotdb.db.storageengine.dataregion.compaction.schedule.CompactionTaskManager; -import org.apache.iotdb.db.storageengine.dataregion.flush.FlushManager; -import org.apache.iotdb.db.storageengine.dataregion.read.control.FileReaderManager; -import org.apache.iotdb.db.storageengine.dataregion.read.control.QueryResourceManager; -import org.apache.iotdb.db.storageengine.dataregion.tsfile.timeindex.FileTimeIndexCacheRecorder; -import org.apache.iotdb.db.storageengine.dataregion.wal.WALManager; -import org.apache.iotdb.db.storageengine.dataregion.wal.recover.WALRecoverManager; -import org.apache.iotdb.db.storageengine.rescon.disk.TierManager; -import org.apache.iotdb.db.storageengine.rescon.memory.MemTableManager; -import org.apache.iotdb.db.storageengine.rescon.memory.PrimitiveArrayManager; -import org.apache.iotdb.db.storageengine.rescon.memory.SystemInfo; -import org.apache.iotdb.db.storageengine.rescon.memory.TsFileResourceManager; -import org.apache.iotdb.db.utils.constant.TestConstant; -import org.apache.iotdb.rpc.TConfigurationConst; -import org.apache.iotdb.rpc.TSocketWrapper; -import org.apache.iotdb.udf.api.exception.UDFManagementException; - -import org.apache.thrift.TConfiguration; -import org.apache.thrift.transport.TTransport; -import org.apache.thrift.transport.TTransportException; -import org.apache.tsfile.external.commons.io.FileUtils; -import org.apache.tsfile.fileSystem.FSFactoryProducer; -import org.apache.tsfile.utils.FilePathUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.management.remote.JMXConnector; -import javax.management.remote.JMXConnectorFactory; -import javax.management.remote.JMXServiceURL; - -import java.io.File; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.fail; - -/** This class is used for cleaning test environment in unit test and integration test */ -public class EnvironmentUtils { - - private static final Logger logger = LoggerFactory.getLogger(EnvironmentUtils.class); - - private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); - private static final CommonConfig commonConfig = CommonDescriptor.getInstance().getConfig(); - private static final DataNodeMemoryConfig memoryConfig = - IoTDBDescriptor.getInstance().getMemoryConfig(); - private static final TierManager tierManager = TierManager.getInstance(); - - public static long TEST_QUERY_JOB_ID = 1; - public static QueryContext TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID); - public static FragmentInstanceContext TEST_QUERY_FI_CONTEXT = - FragmentInstanceContext.createFragmentInstanceContextForCompaction(TEST_QUERY_JOB_ID); - - private static final long oldSeqTsFileSize = config.getSeqTsFileSize(); - private static final long oldUnSeqTsFileSize = config.getUnSeqTsFileSize(); - private static TConfiguration tConfiguration = TConfigurationConst.defaultTConfiguration; - - public static boolean examinePorts = - Boolean.parseBoolean(System.getProperty("test.port.closed", "false")); - - public static void cleanEnv() throws IOException, StorageEngineException { - // wait all compaction finished - CompactionTaskManager.getInstance().waitAllCompactionFinish(); - // deregister all user defined classes - try { - if (UDFManagementService.getInstance() != null) { - UDFManagementService.getInstance().deregisterAll(); - } - } catch (UDFManagementException e) { - fail(e.getMessage()); - } - - logger.debug("EnvironmentUtil cleanEnv..."); - - QueryResourceManager.getInstance().endQuery(TEST_QUERY_JOB_ID); - // clear opened file streams - FileReaderManager.getInstance().closeAndRemoveAllOpenedReaders(); - - if (examinePorts) { - // TODO: this is just too slow, especially on Windows, consider a better way - boolean closed = examinePorts(); - if (!closed) { - // sleep 10 seconds - try { - TimeUnit.SECONDS.sleep(10); - } catch (InterruptedException e) { - // do nothing - } - - if (!examinePorts()) { - fail("failed to close some ports"); - } - } - } - // clean wal manager - WALManager.getInstance().stop(); - WALRecoverManager.getInstance().clear(); - StorageEngine.getInstance().stop(); - SchemaEngine.getInstance().clear(); - FlushManager.getInstance().stop(); - CommonDescriptor.getInstance().getConfig().setNodeStatus(NodeStatus.Running); - // We must disable MQTT service as it will cost a lot of time to be shutdown, which may slow our - // unit tests. - IoTDBDescriptor.getInstance().getConfig().setEnableMQTTService(false); - - // clean cache - if (memoryConfig.isMetaDataCacheEnable()) { - ChunkCache.getInstance().clear(); - TimeSeriesMetadataCache.getInstance().clear(); - BloomFilterCache.getInstance().clear(); - } - - // close array manager - PrimitiveArrayManager.close(); - - // clear system info - SystemInfo.getInstance().close(); - - // clear memtable manager info - MemTableManager.getInstance().close(); - - // clear tsFileResource manager info - TsFileResourceManager.getInstance().clear(); - - // sleep to wait other background threads to exit - try { - TimeUnit.MILLISECONDS.sleep(100); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - // delete all directory - cleanAllDir(); - config.setSeqTsFileSize(oldSeqTsFileSize); - config.setUnSeqTsFileSize(oldUnSeqTsFileSize); - } - - private static boolean examinePorts() { - TTransport transport = TSocketWrapper.wrap(tConfiguration, "127.0.0.1", 6667, 100); - if (transport != null && !transport.isOpen()) { - try { - transport.open(); - logger.error("stop daemon failed. 6667 can be connected now."); - transport.close(); - return false; - } catch (TTransportException e) { - // do nothing - } - } - // try sync service - transport = TSocketWrapper.wrap(tConfiguration, "127.0.0.1", 5555, 100); - if (transport != null && !transport.isOpen()) { - try { - transport.open(); - logger.error("stop Sync daemon failed. 5555 can be connected now."); - transport.close(); - return false; - } catch (TTransportException e) { - // do nothing - } - } - // try jmx connection - try { - JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:31999/jmxrmi"); - JMXConnector jmxConnector = JMXConnectorFactory.connect(url); - logger.error("stop JMX failed. 31999 can be connected now."); - jmxConnector.close(); - return false; - } catch (IOException e) { - // do nothing - } - // try MetricService - try (Socket socket = new Socket()) { - socket.connect(new InetSocketAddress("127.0.0.1", 9091), 100); - logger.error("stop MetricService failed. 9091 can be connected now."); - return false; - } catch (Exception e) { - // do nothing - } - // do nothing - return true; - } - - public static void cleanAllDir() throws IOException { - // delete sequential files - for (String path : tierManager.getAllLocalSequenceFileFolders()) { - cleanDir(path); - } - // delete unsequence files - for (String path : tierManager.getAllLocalUnSequenceFileFolders()) { - cleanDir(path); - } - FileTimeIndexCacheRecorder.getInstance().close(); - // delete system info - cleanDir(config.getSystemDir()); - // delete query - cleanDir(config.getQueryDir()); - // delete ulog - cleanDir(config.getUdfDir()); - // delete tlog - cleanDir(config.getTriggerDir()); - // delete extPipe - cleanDir(config.getExtPipeDir()); - // delete ext - cleanDir(config.getExtDir()); - // delete mqtt dir - cleanDir(config.getMqttDir()); - // delete wal - for (String walDir : commonConfig.getWalDirs()) { - cleanDir(walDir); - } - // delete sync dir - cleanDir(commonConfig.getSyncDir()); - // delete data files - for (String dataDir : config.getDataDirs()) { - cleanDir(dataDir); - } - } - - public static void cleanDir(String dir) throws IOException { - FSFactoryProducer.getFSFactory().deleteDirectory(dir); - } - - /** disable memory control
this function should be called before all code in the setup */ - public static void envSetUp() { - logger.debug("EnvironmentUtil setup..."); - config.setThriftServerAwaitTimeForStopService(60); - - createAllDir(); - - try { - StorageEngine.getInstance().start(); - - SchemaEngine.getInstance().init(); - - CompactionTaskManager.getInstance().start(); - WALManager.getInstance().start(); - FlushManager.getInstance().start(); - } catch (StartupException e) { - throw new RuntimeException(e); - } - - TEST_QUERY_JOB_ID = QueryResourceManager.getInstance().assignQueryId(); - TEST_QUERY_CONTEXT = new QueryContext(TEST_QUERY_JOB_ID); - } - - private static void createAllDir() { - // create sequential files - for (String path : tierManager.getAllLocalSequenceFileFolders()) { - createDir(path); - } - // create unsequential files - for (String path : tierManager.getAllLocalUnSequenceFileFolders()) { - createDir(path); - } - // create database - createDir(config.getSystemDir()); - // create sg dir - String sgDir = FilePathUtils.regularizePath(config.getSystemDir()) + "databases"; - createDir(sgDir); - // create sync - createDir(commonConfig.getSyncDir()); - // create query - createDir(config.getQueryDir()); - createDir(TestConstant.OUTPUT_DATA_DIR); - // create wal - for (String walDir : commonConfig.getWalDirs()) { - createDir(walDir); - } - // create data - for (String dataDir : config.getDataDirs()) { - createDir(dataDir); - } - } - - private static void createDir(String dir) { - File file = FSFactoryProducer.getFSFactory().getFile(dir); - file.mkdirs(); - } - - public static void recursiveDeleteFolder(String path) throws IOException { - File file = new File(path); - if (file.isDirectory()) { - File[] files = file.listFiles(); - if (files == null || files.length == 0) { - FileUtils.deleteDirectory(file); - } else { - for (File f : files) { - recursiveDeleteFolder(f.getAbsolutePath()); - } - FileUtils.deleteDirectory(file); - } - } else { - FileUtils.delete(file); - } - } -} diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java deleted file mode 100644 index 3706598602d92..0000000000000 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/GrafanaApiServiceTest.java +++ /dev/null @@ -1,465 +0,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.iotdb.rest; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -// move to integration-test -@Ignore -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class GrafanaApiServiceTest { - - private String getAuthorization(String username, String password) { - return Base64.getEncoder() - .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8)); - } - - private HttpPost getHttpPost(String url) { - HttpPost httpPost = new HttpPost(url); - httpPost.addHeader("Content-type", "application/json; charset=utf-8"); - httpPost.setHeader("Accept", "application/json"); - String authorization = getAuthorization("root", "root"); - httpPost.setHeader("Authorization", authorization); - return httpPost; - } - - @Test - public void login() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/grafana/v1/login"); - CloseableHttpResponse response = null; - try { - String authorization = getAuthorization("root", "root"); - httpGet.setHeader("Authorization", authorization); - response = httpClient.execute(httpGet); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(200, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (httpClient != null) { - httpClient.close(); - } - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void rightInsertTablet(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet"); - String json = - "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s4\",\"s5\"],\"dataTypes\":[\"INT32\",\"INT32\"],\"values\":[[11,2],[15,13]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; - httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(200, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void expressionAggGroupByTimeAndLevel(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by([1635232143960,1635232153960),1s),level=1\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - List timestampsResult = (List) map.get("timestamps"); - List expressionsResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - Assert.assertTrue(timestampsResult.size() == 10); - Assert.assertTrue(valuesResult.size() == 1); - Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0))); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void expression(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"s4\",\"s5\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - String[] expressionsResult = {"root.sg25.s4", "root.sg25.s5"}; - Long[] timestamps = {1635232143960L, 1635232153960L}; - Object[] values1 = {11, 2}; - Object[] values2 = {15, 13}; - Assert.assertArrayEquals( - expressionsResult, (map.get("expressions")).toArray(new String[] {})); - Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {})); - Assert.assertArrayEquals( - values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {})); - Assert.assertArrayEquals( - values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {})); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void expressionWithControl(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"}; - Long[] timestamps = {1635232133960L, 1635232153960L}; - Object[] values1 = {11.0, 2.0}; - Object[] values2 = {15.0, 13.0}; - Assert.assertArrayEquals( - expressionsResult, (map.get("expressions")).toArray(new String[] {})); - Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {})); - Assert.assertArrayEquals( - values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {})); - Assert.assertArrayEquals( - values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {})); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void expressionWithConditionControl(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"sum(s4)\",\"avg(s5)\"],\"prefixPath\":[\"root.sg25\"],\"condition\":\"timestamp=1635232143960\",\"startTime\":1635232133960,\"endTime\":1635232163960,\"control\":\"group by([1635232133960,1635232163960),20s)\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - String[] expressionsResult = {"sum(root.sg25.s4)", "avg(root.sg25.s5)"}; - Long[] timestamps = {1635232133960L, 1635232153960L}; - Object[] values1 = {11.0, null}; - Object[] values2 = {15.0, null}; - Assert.assertArrayEquals(expressionsResult, map.get("expressions").toArray(new String[] {})); - Assert.assertArrayEquals(timestamps, (map.get("timestamps")).toArray(new Long[] {})); - Assert.assertArrayEquals( - values1, ((List) (map.get("values")).get(0)).toArray(new Object[] {})); - Assert.assertArrayEquals( - values2, ((List) (map.get("values")).get(1)).toArray(new Object[] {})); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void variable(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/variable"); - String sql = "{\"sql\":\"show child paths root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - List list = mapper.readValue(message, List.class); - String[] expectedResult = {"s4", "s5"}; - Assert.assertArrayEquals(expectedResult, list.toArray(new String[] {})); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - @Test - public void expressionWithConditionControlTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - expressionWithConditionControl(httpClient); - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void expressionTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - expression(httpClient); - expressionAggGroupByTimeAndLevel(httpClient); - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void expressionWithControlTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - expressionWithControl(httpClient); - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void variableTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - variable(httpClient); - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void expressionWithAggGroupByTimeTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by([1635232143960,1635232153960),1s)\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - List timestampsResult = (List) map.get("timestamps"); - List expressionsResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - Assert.assertTrue(timestampsResult.size() == 10); - Assert.assertTrue(valuesResult.size() == 1); - Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0))); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void expressionWithAggGroupByLevelTest() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/grafana/v1/query/expression"); - String sql = - "{\"expression\":[\"count(s4)\"],\"prefixPath\":[\"root.sg25\"],\"startTime\":1635232143960,\"endTime\":1635232153960,\"control\":\"group by level = 1\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - List timestampsResult = (List) map.get("timestamps"); - List expressionsResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - Assert.assertTrue(timestampsResult == null); - Assert.assertTrue(valuesResult.size() == 1); - Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0))); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void zDeleteTablet() { - CloseableHttpResponse response = null; - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/nonQuery"); - String sql = "{\"sql\":\"drop database root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } -} diff --git a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java b/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java deleted file mode 100644 index 42eb8a9e3d077..0000000000000 --- a/external-service-impl/rest/src/test/java/org/apache/iotdb/rest/IoTDBRestServiceTest.java +++ /dev/null @@ -1,794 +0,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.iotdb.rest; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -// Move it to integration-test -@Ignore -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class IoTDBRestServiceTest { - - private String getAuthorization(String username, String password) { - return Base64.getEncoder() - .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8)); - } - - @Test - public void aPing() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpGet httpGet = new HttpGet("http://127.0.0.1:18080/ping"); - CloseableHttpResponse response = null; - try { - response = httpClient.execute(httpGet); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(200, response.getStatusLine().getStatusCode()); - assertEquals(200, Integer.parseInt(result.get("code").toString())); - - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (httpClient != null) { - httpClient.close(); - } - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - private HttpPost getHttpPost(String url) { - HttpPost httpPost = new HttpPost(url); - httpPost.addHeader("Content-type", "application/json; charset=utf-8"); - httpPost.setHeader("Accept", "application/json"); - String authorization = getAuthorization("root", "root"); - httpPost.setHeader("Authorization", authorization); - return httpPost; - } - - public void rightInsertTablet(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet"); - String json = - "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[11,2],[1635000012345555,1635000012345556],[1.41,null],[null,false],[null,3.5555]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; - httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(200, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - @Test - public void errorInsertTablet() { - CloseableHttpResponse response = null; - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/insertTablet"); - String json = - "{\"timestamps\":[1635232143960,1635232153960],\"measurements\":[\"s3\",\"s4\",\"s5\",\"s6\",\"s7\",\"s8\"],\"dataTypes\":[\"TEXT\",\"INT32\",\"INT64\",\"FLOAT\",\"BOOLEAN\",\"DOUBLE\"],\"values\":[[\"2aa\",\"\"],[111111112312312442352545452323123,2],[16,15],[1.41,null],[null,false],[null,3.55555555555555555555555555555555555555555555312234235345123127318927461482308478123645555555555555555555555555555555555555555555531223423534512312731892746148230847812364]],\"isAligned\":false,\"deviceId\":\"root.sg25\"}"; - httpPost.setEntity(new StringEntity(json, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(606, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - @Test - public void insertAndQuery() { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - rightInsertTablet(httpClient); - query(httpClient); - queryGroupByLevel(httpClient); - queryRowLimit(httpClient); - queryShowChildPaths(httpClient); - queryShowNodes(httpClient); - showAllTTL(httpClient); - showStorageGroup(httpClient); - showFunctions(httpClient); - showTimeseries(httpClient); - - showLastTimeseries(httpClient); - countTimeseries(httpClient); - countNodes(httpClient); - showDevices(httpClient); - - showDevicesWithStroage(httpClient); - listUser(httpClient); - selectCount(httpClient); - selectLast(httpClient); - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - - @Test - public void queryWithUnsetAuthorization() { - CloseableHttpResponse response = null; - try { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpPost httpPost = new HttpPost("http://127.0.0.1:18080/rest/v1/query"); - httpPost.addHeader("Content-type", "application/json; charset=utf-8"); - httpPost.setHeader("Accept", "application/json"); - String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - Assert.assertEquals(401, response.getStatusLine().getStatusCode()); - String message = EntityUtils.toString(response.getEntity(), "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - assertEquals(800, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - @Test - public void queryWithWrongAuthorization() { - CloseableHttpResponse response = null; - try { - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - HttpPost httpPost = new HttpPost("http://127.0.0.1:18080/rest/v1/query"); - httpPost.addHeader("Content-type", "application/json; charset=utf-8"); - httpPost.setHeader("Accept", "application/json"); - String authorization = getAuthorization("abc", "def"); - httpPost.setHeader("Authorization", authorization); - String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - Assert.assertEquals(401, response.getStatusLine().getStatusCode()); - String message = EntityUtils.toString(response.getEntity(), "utf-8"); - JsonObject result = JsonParser.parseString(message).getAsJsonObject(); - Assert.assertEquals(801, Integer.parseInt(result.get("code").toString())); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - @Test - public void zDeleteTablet() { - CloseableHttpResponse response = null; - CloseableHttpClient httpClient = HttpClientBuilder.create().build(); - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/nonQuery"); - String sql = "{\"sql\":\"drop database root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - Assert.assertEquals(200, response.getStatusLine().getStatusCode()); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void query(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query"); - String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - List timestampsResult = (List) map.get("timestamps"); - List expressionsResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List expressions = - new ArrayList() { - { - add("root.sg25.s3"); - add("root.sg25.s4"); - add("root.sg25.s5"); - add("root.sg25.s6"); - add("root.sg25.s7"); - add("root.sg25.s8"); - add("root.sg25.s4 + 1"); - add("root.sg25.s4 + 1"); - } - }; - List timestamps = - new ArrayList() { - { - add(1635232143960l); - add(1635232153960l); - } - }; - List values1 = - new ArrayList() { - { - add("2aa"); - add(""); - } - }; - List values2 = - new ArrayList() { - { - add(11); - add(2); - } - }; - List values3 = - new ArrayList() { - { - add(1635000012345555l); - add(1635000012345556l); - } - }; - - List values4 = - new ArrayList() { - { - add(1.41); - add(null); - } - }; - List values5 = - new ArrayList() { - { - add(null); - add(false); - } - }; - List values6 = - new ArrayList() { - { - add(null); - add(3.5555); - } - }; - - Assert.assertEquals(expressions, expressionsResult); - Assert.assertEquals(timestamps, timestampsResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2, valuesResult.get(1)); - Assert.assertEquals(values3, valuesResult.get(2)); - Assert.assertEquals(values4, valuesResult.get(3)); - Assert.assertEquals(values5, valuesResult.get(4)); - Assert.assertEquals(values6, valuesResult.get(5)); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void queryGroupByLevel(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query"); - String sql = - "{\"sql\":\"select count(s4) from root.sg25 group by([1635232143960,1635232153960),1s),level=1\"}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - List timestampsResult = (List) map.get("timestamps"); - List expressionsResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - Assert.assertTrue(timestampsResult.size() == 10); - Assert.assertTrue(valuesResult.size() == 1); - Assert.assertTrue("count(root.sg25.s4)".equals(expressionsResult.get(0))); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public void queryRowLimit(CloseableHttpClient httpClient) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query"); - String sql = "{\"sql\":\"select *,s4+1,s4+1 from root.sg25\",\"rowLimit\":1}"; - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - assertTrue(message.contains("row size exceeded the given max row size")); - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - } - - public Map queryMetaData(CloseableHttpClient httpClient, String sql) { - CloseableHttpResponse response = null; - try { - HttpPost httpPost = getHttpPost("http://127.0.0.1:18080/rest/v1/query"); - httpPost.setEntity(new StringEntity(sql, Charset.defaultCharset())); - response = httpClient.execute(httpPost); - HttpEntity responseEntity = response.getEntity(); - String message = EntityUtils.toString(responseEntity, "utf-8"); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(message, Map.class); - return map; - - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - try { - if (response != null) { - response.close(); - } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } - } - return null; - } - - public void queryShowChildPaths(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show child paths root\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("ChildPaths"); - add("NodeTypes"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetPath = "root.sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetPath)); - } - - public void queryShowNodes(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show child nodes root\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("ChildNodes"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetNode = "sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetNode)); - } - - public void showAllTTL(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show all ttl\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Device"); - add("TTL(ms)"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - } - - public void showStorageGroup(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"SHOW DATABASES root.*\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Database"); - add("SchemaReplicationFactor"); - add("DataReplicationFactor"); - add("TimePartitionOrigin"); - add("TimePartitionInterval"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetDatabase = "root.sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetDatabase)); - } - - public void showFunctions(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show functions\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - assertEquals(4, columnNamesResult.size()); - assertEquals(4, valuesResult.size()); - } - - public void showTimeseries(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show timeseries\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Timeseries"); - add("Alias"); - add("Database"); - add("DataType"); - add("Encoding"); - add("Compression"); - add("Tags"); - add("Attributes"); - add("Deadband"); - add("DeadbandParameters"); - add("ViewType"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25.s3"); - add("root.sg25.s4"); - add("root.sg25.s5"); - add("root.sg25.s6"); - add("root.sg25.s7"); - add("root.sg25.s8"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - for (Object timeSeries : values1) { - Assert.assertTrue(valuesResult.get(0).contains(timeSeries)); - } - } - - public void showLastTimeseries(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"SHOW LATEST TIMESERIES\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Timeseries"); - add("Alias"); - add("Database"); - add("DataType"); - add("Encoding"); - add("Compression"); - add("Tags"); - add("Attributes"); - add("Deadband"); - add("DeadbandParameters"); - add("ViewType"); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25.s3"); - add("root.sg25.s4"); - add("root.sg25.s5"); - add("root.sg25.s7"); - add("root.sg25.s8"); - add("root.sg25.s6"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - for (Object timeSeries : values1) { - Assert.assertTrue(valuesResult.get(0).contains(timeSeries)); - } - } - - public void countTimeseries(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"COUNT TIMESERIES root.** GROUP BY LEVEL=1\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Column"); - add("count(timeseries)"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetDatabase = "root.sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetDatabase)); - int rowIndex = valuesResult.get(0).indexOf(targetDatabase); - int targetCount = 6; - Assert.assertEquals(targetCount, valuesResult.get(1).get(rowIndex)); - } - - public void countNodes(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"count nodes root.** level=2\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("count(nodes)"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertTrue((int) valuesResult.get(0).get(0) >= 6); - } - - public void showDevices(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show devices\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Device"); - add("IsAligned"); - add("Template"); - add("TTL(ms)"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetDevice = "root.sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetDevice)); - int rowIndex = valuesResult.get(0).indexOf(targetDevice); - Assert.assertEquals("false", valuesResult.get(1).get(rowIndex)); - Assert.assertNull(valuesResult.get(2).get(rowIndex)); - Assert.assertEquals("INF", valuesResult.get(3).get(rowIndex)); - } - - public void showDevicesWithStroage(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"show devices with database\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Device"); - add("Database"); - add("IsAligned"); - add("Template"); - add("TTL(ms)"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - String targetDevice = "root.sg25"; - Assert.assertTrue(valuesResult.get(0).contains(targetDevice)); - int rowIndex = valuesResult.get(0).indexOf(targetDevice); - Assert.assertEquals(targetDevice, valuesResult.get(1).get(rowIndex)); - Assert.assertEquals("false", valuesResult.get(2).get(rowIndex)); - Assert.assertNull(valuesResult.get(3).get(rowIndex)); - Assert.assertEquals("INF", valuesResult.get(4).get(rowIndex)); - } - - public void listUser(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"list user\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("columnNames"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("UserId"); - add("User"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertTrue(valuesResult.get(0).contains(0)); - Assert.assertTrue(valuesResult.get(1).contains("root")); - } - - public void selectCount(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"select count(s3) from root.** group by level = 1\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("count(root.sg25.s3)"); - } - }; - List values1 = - new ArrayList() { - { - add(2); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(values1, valuesResult.get(0)); - } - - public void selectLast(CloseableHttpClient httpClient) { - String sql = "{\"sql\":\"select last s4 from root.sg25\"}"; - Map map = queryMetaData(httpClient, sql); - List columnNamesResult = (List) map.get("expressions"); - List> valuesResult = (List>) map.get("values"); - List timestampsResult = (List) map.get("timestamps"); - Assert.assertTrue(map.size() > 0); - List columnNames = - new ArrayList() { - { - add("Timeseries"); - add("Value"); - add("DataType"); - } - }; - List timestamps = - new ArrayList() { - { - add(1635232153960l); - } - }; - List values1 = - new ArrayList() { - { - add("root.sg25.s4"); - } - }; - List values2 = - new ArrayList() { - { - add("2"); - } - }; - List values3 = - new ArrayList() { - { - add("INT32"); - } - }; - Assert.assertEquals(columnNames, columnNamesResult); - Assert.assertEquals(timestamps, timestampsResult); - Assert.assertEquals(values1, valuesResult.get(0)); - Assert.assertEquals(values2.get(0), valuesResult.get(1).get(0)); - Assert.assertEquals(values3, valuesResult.get(2)); - } -} From 14d34daec5971ae4f1ea9e4f8f63ba48393be835 Mon Sep 17 00:00:00 2001 From: LimJiaWenBrenda Date: Wed, 28 Jan 2026 17:19:07 +0800 Subject: [PATCH 10/10] Remove unused dependencies --- external-service-impl/rest/pom.xml | 32 +----------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/external-service-impl/rest/pom.xml b/external-service-impl/rest/pom.xml index 787dea180e3e3..edb8aa3fc3371 100644 --- a/external-service-impl/rest/pom.xml +++ b/external-service-impl/rest/pom.xml @@ -46,11 +46,6 @@ - - com.fasterxml.jackson.core - jackson-databind - runtime - org.apache.iotdb rest-openapi @@ -127,12 +122,6 @@ 2.0.7-SNAPSHOT provided - - org.apache.iotdb - udf-api - 2.0.7-SNAPSHOT - provided - com.google.guava guava @@ -143,11 +132,6 @@ slf4j-api provided - - com.google.code.gson - gson - provided - com.github.ben-manes.caffeine caffeine @@ -189,11 +173,6 @@ ${tsfile.version} provided - - org.apache.thrift - libthrift - provided - org.apache.iotdb iotdb-thrift-commons @@ -205,16 +184,6 @@ antlr4-runtime provided - - org.apache.httpcomponents - httpcore - test - - - org.apache.httpcomponents - httpclient - test - @@ -244,6 +213,7 @@ org.apache.tsfile:common + junit:junit