Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.relational.it.query.recent.informationschema;

import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import static org.apache.iotdb.commons.schema.table.InformationSchema.INFORMATION_DATABASE;
import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT;
import static org.apache.iotdb.itbase.env.BaseEnv.TREE_SQL_DIALECT;
import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
public class IoTDBServicesIT {
private static final String ADMIN_NAME =
CommonDescriptor.getInstance().getConfig().getDefaultAdminName();
private static final String ADMIN_PWD =
CommonDescriptor.getInstance().getConfig().getAdminPassword();

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
createUser("test", "TimechoDB@2021");
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void testQueryResult() {
String[] retArray =
new String[] {
"MQTT,1,STOPPED,", "REST,1,STOPPED,",
};

// TableModel
String[] header =
new String[] {
"service_name", "datanode_id", "state",
};

String sql = "SELECT * FROM services where datanode_id = 1";
tableResultSetEqualTest(sql, header, retArray, INFORMATION_DATABASE);
sql = "show services on 1";
tableResultSetEqualTest(sql, header, retArray, INFORMATION_DATABASE);

// TreeModel
header =
new String[] {
"ServiceName", "DataNodeId", "State",
};

resultSetEqualTest(sql, header, retArray);
}

@Test
public void testPrivilege() {
testTargetModelPrivilege(TABLE_SQL_DIALECT);
testTargetModelPrivilege(TREE_SQL_DIALECT);
}

private void testTargetModelPrivilege(String model) {
String sql = "show services";
try (Connection connection =
EnvFactory.getEnv().getConnection("test", "TimechoDB@2021", model);
Statement statement = connection.createStatement()) {
statement.executeQuery(sql);
} catch (SQLException e) {
Assert.assertTrue(
e.getMessage()
.contains("No permissions for this operation, please add privilege SYSTEM"));
}

try (Connection connection2 = EnvFactory.getEnv().getConnection(ADMIN_NAME, ADMIN_PWD, model);
Statement statement2 = connection2.createStatement()) {
statement2.executeQuery(sql);
} catch (Exception e) {
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ public void testInformationSchema() throws SQLException {
"queries,INF,",
"queries_costs_histogram,INF,",
"regions,INF,",
"services,INF,",
"subscriptions,INF,",
"tables,INF,",
"topics,INF,",
Expand Down Expand Up @@ -497,6 +498,14 @@ public void testInformationSchema() throws SQLException {
"topic_name,STRING,TAG,",
"consumer_group_name,STRING,TAG,",
"subscribed_consumers,STRING,ATTRIBUTE,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("desc services"),
"ColumnName,DataType,Category,",
new HashSet<>(
Arrays.asList(
"service_name,STRING,TAG,",
"datanode_id,INT32,ATTRIBUTE,",
"state,STRING,ATTRIBUTE,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("desc views"),
"ColumnName,DataType,Category,",
Expand Down Expand Up @@ -627,6 +636,7 @@ public void testInformationSchema() throws SQLException {
"information_schema,topics,INF,USING,null,SYSTEM VIEW,",
"information_schema,pipe_plugins,INF,USING,null,SYSTEM VIEW,",
"information_schema,pipes,INF,USING,null,SYSTEM VIEW,",
"information_schema,services,INF,USING,null,SYSTEM VIEW,",
"information_schema,subscriptions,INF,USING,null,SYSTEM VIEW,",
"information_schema,views,INF,USING,null,SYSTEM VIEW,",
"information_schema,functions,INF,USING,null,SYSTEM VIEW,",
Expand All @@ -643,7 +653,7 @@ public void testInformationSchema() throws SQLException {
TestUtils.assertResultSetEqual(
statement.executeQuery("count devices from tables where status = 'USING'"),
"count(devices),",
Collections.singleton("21,"));
Collections.singleton("22,"));
TestUtils.assertResultSetEqual(
statement.executeQuery(
"select * from columns where table_name = 'queries' or database = 'test'"),
Expand Down
60 changes: 60 additions & 0 deletions iotdb-api/external-service-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-api</artifactId>
<version>2.0.7-SNAPSHOT</version>
</parent>
<artifactId>external-service-api</artifactId>
<name>IoTDB: API: External Service API</name>
<profiles>
<profile>
<id>get-jar-with-dependencies</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
<!-- this is used for inheritance merges -->
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.externalservice.api;

/** An interface to support user-defined service. */
public interface IExternalService {

/** Start current service. */
void start();

/**
* Stop current service. If current service uses thread or thread pool, current service should
* guarantee to putBack thread or thread pool.
*/
void stop();
}
1 change: 1 addition & 0 deletions iotdb-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<name>IoTDB: API</name>
<modules>
<module>external-api</module>
<module>external-service-api</module>
<module>pipe-api</module>
<module>trigger-api</module>
<module>udf-api</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ public enum TSStatusCode {
RATIS_READ_UNAVAILABLE(2207),
PIPE_CONSENSUS_CLOSE_ERROR(2208),
PIPE_CONSENSUS_WAIT_ORDER_TIMEOUT(2209),

// ExternalService
NO_SUCH_EXTERNAL_SERVICE(2300),
EXTERNAL_SERVICE_ALREADY_EXIST(2301),
GET_BUILTIN_EXTERNAL_SERVICE_ERROR(2302),
EXTERNAL_SERVICE_INSTANCE_CREATE_ERROR(2303),
CANNOT_DROP_BUILTIN_EXTERNAL_SERVICE(2304),
CANNOT_DROP_RUNNING_EXTERNAL_SERVICE(2305),
;

private final int statusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ keyWords
| FIRST
| FLUSH
| FOR
| FORCEDLY
| FROM
| FULL
| FUNCTION
Expand Down Expand Up @@ -214,6 +215,8 @@ keyWords
| SECURITY
| SELECT
| SERIESSLOTID
| SERVICE
| SERVICES
| SESSION
| SET
| SETTLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ ddlStatement
| createFunction | dropFunction | showFunctions
// Trigger
| createTrigger | dropTrigger | showTriggers | startTrigger | stopTrigger
// ExternalService
| createService | startService | stopService | dropService | showService
// Pipe Task
| createPipe | alterPipe | dropPipe | startPipe | stopPipe | showPipes
// Pipe Plugin
Expand Down Expand Up @@ -437,6 +439,28 @@ stopTrigger
: STOP TRIGGER triggerName=identifier
;

// ExternalService =========================================================================================
createService
: CREATE SERVICE serviceName=identifier
AS className=STRING_LITERAL
;

startService
: START SERVICE serviceName=identifier
;

stopService
: STOP SERVICE serviceName=identifier
;

dropService
: DROP SERVICE serviceName=identifier FORCEDLY?

;

showService
: SHOW SERVICES (ON targetDataNodeId=INTEGER_LITERAL)?
;

// CQ ==============================================================================================
// ---- Create Continuous Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ FOR
: F O R
;

FORCEDLY
: F O R C E D L Y
;


FROM
: F R O M
;
Expand Down Expand Up @@ -786,6 +791,14 @@ SERIESSLOTID
: S E R I E S S L O T I D
;

SERVICE
: S E R V I C E
;

SERVICES
: S E R V I C E S
;

SESSION
: S E S S I O N
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public enum CnToDnAsyncRequestType {
INACTIVE_TRIGGER_INSTANCE,
UPDATE_TRIGGER_LOCATION,

// ExternalService
GET_BUILTIN_SERVICE,

// Pipe Plugin
CREATE_PIPE_PLUGIN,
DROP_PIPE_PLUGIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.iotdb.confignode.client.async.handlers.rpc.DataNodeAsyncRequestRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.DataNodeTSStatusRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.FetchSchemaBlackListRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.GetBuiltInExternalServiceRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.PipeHeartbeatRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.PipePushMetaRPCHandler;
import org.apache.iotdb.confignode.client.async.handlers.rpc.SchemaUpdateRPCHandler;
Expand Down Expand Up @@ -486,6 +487,10 @@ protected void initActionMapBuilder() {
CnToDnAsyncRequestType.ENABLE_SEPARATION_OF_ADMIN_POWERS,
(req, client, handler) ->
client.enableSeparationOfAdminPower((DataNodeTSStatusRPCHandler) handler));
actionMapBuilder.put(
CnToDnAsyncRequestType.GET_BUILTIN_SERVICE,
(req, client, handler) ->
client.getBuiltInService((GetBuiltInExternalServiceRPCHandler) handler));
}

@Override
Expand Down
Loading
Loading