You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2021/01/14 09:55:06 UTC
[iotdb] branch openapi updated: add java-rest
This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch openapi
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/openapi by this push:
new 5618299 add java-rest
5618299 is described below
commit 561829912145dd215ab889fe493fb0434eb29e51
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Thu Jan 14 17:53:25 2021 +0800
add java-rest
---
openapi/java-rest/pom.xml | 230 +++++++++++++++++++--
openapi/java-rest/src/main/java/Test.java | 1 -
.../iotdb/openapi/gen/handler/Bootstrap.java | 50 +++++
.../gen/handler/factories/V1ApiServiceFactory.java | 32 +++
.../openapi/gen/handler/impl/V1ApiServiceImpl.java | 70 +++++++
openapi/java-rest/src/main/webapp/WEB-INF/web.xml | 86 ++++++++
openapi/pom.xml | 20 ++
7 files changed, 467 insertions(+), 22 deletions(-)
diff --git a/openapi/java-rest/pom.xml b/openapi/java-rest/pom.xml
index fbe75c9..68a513d 100644
--- a/openapi/java-rest/pom.xml
+++ b/openapi/java-rest/pom.xml
@@ -1,4 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.iotdb</groupId>
@@ -11,27 +31,195 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.4</version>
- <executions>
- <execution>
- <id>add-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
+<!-- <build>-->
+<!-- <plugins>-->
+<!-- <plugin>-->
+<!-- <groupId>org.codehaus.mojo</groupId>-->
+<!-- <artifactId>build-helper-maven-plugin</artifactId>-->
+<!-- <version>1.4</version>-->
+<!-- <executions>-->
+<!-- <execution>-->
+<!-- <id>add-java-rest-source</id>-->
+<!-- <phase>generate-sources</phase>-->
+<!-- <goals>-->
+<!-- <goal>add-source</goal>-->
+<!-- </goals>-->
+<!-- <configuration>-->
+<!-- <sources>-->
+<!-- <source>${project.basedir}/../target/generated-sources/java/src/gen/java</source>-->
+<!-- </sources>-->
+<!-- </configuration>-->
+<!-- </execution>-->
+<!-- </executions>-->
+<!-- </plugin>-->
+<!-- </plugins>-->
+<!-- </build>-->
+
+ <profiles>
+ <profile>
+ <id>java-rest-pom-by-openapi</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <!-- The following are generated by openapi-->
+ <!-- <source>src/gen/java</source> should be change to
+ <source>${project.basedir}/../target/generated-sources/java/src/gen/java</source>-->
+ <properties>
+ <swagger-core-version>1.5.18</swagger-core-version>
+ <beanvalidation-version>1.1.0.Final</beanvalidation-version>
+ <jetty-version>9.2.9.v20150224</jetty-version>
+ <jersey2-version>2.22.2</jersey2-version>
+ <jackson-version>${jackson.version}</jackson-version>
+ <junit-version>${junit.version}</junit-version>
+ <logback-version>${logback.version}</logback-version>
+ <servlet-api-version>2.5</servlet-api-version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>3.1.0</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>${jetty-version}</version>
<configuration>
- <sources>
- <source>${basedir}/src/labs/java</source>
- </sources>
+ <webApp>
+ <contextPath>/</contextPath>
+ </webApp>
+ <webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
+ <stopPort>8079</stopPort>
+ <stopKey>stopit</stopKey>
+ <stopWait>10</stopWait>
+ <httpConnector>
+ <port>5667</port>
+ <idleTimeout>60000</idleTimeout>
+ </httpConnector>
</configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>${beanvalidation-version}</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>start-jetty</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <daemon>true</daemon>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop-jetty</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.9.1</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.basedir}/../target/generated-sources/java/src/gen/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-jersey2-jaxrs</artifactId>
+ <scope>compile</scope>
+ <version>${swagger-core-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${logback-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>${logback-version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet-api-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-jsr310</artifactId>
+ <version>${jackson-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.jaxrs</groupId>
+ <artifactId>jackson-jaxrs-json-provider</artifactId>
+ <version>${jackson-version}</version>
+ </dependency>
+ <!-- Base64 encoding that works in both JVM and Android -->
+ <dependency>
+ <groupId>com.brsanthu</groupId>
+ <artifactId>migbase64</artifactId>
+ <version>2.2</version>
+ </dependency>
+
+
+ <!-- Bean Validation API support -->
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>${beanvalidation-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ </profile>
+ </profiles>
+
</project>
diff --git a/openapi/java-rest/src/main/java/Test.java b/openapi/java-rest/src/main/java/Test.java
deleted file mode 100644
index 0ee28d1..0000000
--- a/openapi/java-rest/src/main/java/Test.java
+++ /dev/null
@@ -1 +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 r [...]
\ No newline at end of file
diff --git a/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/Bootstrap.java b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/Bootstrap.java
new file mode 100644
index 0000000..e619fe2
--- /dev/null
+++ b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/Bootstrap.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+// this file is generated by openapi generator
+
+package org.apache.iotdb.openapi.gen.handler;
+
+import io.swagger.jaxrs.config.SwaggerContextService;
+import io.swagger.models.*;
+
+import io.swagger.models.auth.*;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+public class Bootstrap extends HttpServlet {
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ Info info = new Info()
+ .title("OpenAPI Server")
+ .description("IoTDB Rest API for Grafana, Prometheus, etc..")
+ .termsOfService("")
+ .contact(new Contact()
+ .email(""))
+ .license(new License()
+ .name("Apache 2.0")
+ .url("http://unlicense.org"));
+
+ ServletContext context = config.getServletContext();
+ Swagger swagger = new Swagger().info(info);
+
+ new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
+ }
+}
diff --git a/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/factories/V1ApiServiceFactory.java b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/factories/V1ApiServiceFactory.java
new file mode 100644
index 0000000..c696a46
--- /dev/null
+++ b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/factories/V1ApiServiceFactory.java
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+// this file is generated by openapi generator
+
+package org.apache.iotdb.openapi.gen.handler.factories;
+
+import org.apache.iotdb.openapi.gen.handler.V1ApiService;
+import org.apache.iotdb.openapi.gen.handler.impl.V1ApiServiceImpl;
+
+@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", date = "2021-01-13T21:45:03.765+08:00[Asia/Shanghai]")
+public class V1ApiServiceFactory {
+ private static final V1ApiService service = new V1ApiServiceImpl();
+
+ public static V1ApiService getV1Api() {
+ return service;
+ }
+}
diff --git a/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/impl/V1ApiServiceImpl.java b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/impl/V1ApiServiceImpl.java
new file mode 100644
index 0000000..7b476f5
--- /dev/null
+++ b/openapi/java-rest/src/main/java/org/apache/iotdb/openapi/gen/handler/impl/V1ApiServiceImpl.java
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+// this file is generated by openapi generator
+
+package org.apache.iotdb.openapi.gen.handler.impl;
+
+import org.apache.iotdb.openapi.gen.handler.*;
+import org.apache.iotdb.openapi.gen.model.*;
+
+import org.apache.iotdb.openapi.gen.model.GrafanaDataFrameInner;
+import org.apache.iotdb.openapi.gen.model.GrafanaJsonInner;
+import org.apache.iotdb.openapi.gen.model.GroupByFillPlan;
+import org.apache.iotdb.openapi.gen.model.InlineResponse200;
+import org.apache.iotdb.openapi.gen.model.InlineResponse2001;
+import java.util.List;
+import java.util.Set;
+
+import java.util.List;
+import org.apache.iotdb.openapi.gen.handler.NotFoundException;
+
+import java.io.InputStream;
+
+import org.glassfish.jersey.media.multipart.FormDataBodyPart;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.validation.constraints.*;
+@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJerseyServerCodegen", date = "2021-01-13T21:45:03.765+08:00[Asia/Shanghai]")
+public class V1ApiServiceImpl extends V1ApiService {
+ @Override
+ public Response postV1GrafanaData(GroupByFillPlan groupByFillPlan, SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+ @Override
+ public Response postV1GrafanaDataSimplejson(GroupByFillPlan groupByFillPlan, SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+ @Override
+ public Response postV1GrafanaNode(List<String> requestBody, SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+ @Override
+ public Response postV1PrometheusQuery(String userAgent, String xPrometheusRemoteReadVersion, Object body, SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+ @Override
+ public Response postV1PrometheusReceive(String userAgent, String xPrometheusRemoteWriteVersion, Object body, SecurityContext securityContext) throws NotFoundException {
+ // do some magic!
+ return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
+ }
+}
diff --git a/openapi/java-rest/src/main/webapp/WEB-INF/web.xml b/openapi/java-rest/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..24e86f8
--- /dev/null
+++ b/openapi/java-rest/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<!-- This file is generated by openapi generator tool.-->
+
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <servlet>
+ <servlet-name>jersey</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>
+ io.swagger.jaxrs.listing,
+ io.swagger.sample.resource,
+ org.apache.iotdb.openapi.gen.handler
+ </param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.provider.classnames</param-name>
+ <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
+ </init-param>
+ <init-param>
+ <param-name>jersey.config.server.wadl.disableWadl</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <servlet-name>Jersey2Config</servlet-name>
+ <servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
+ <init-param>
+ <param-name>api.version</param-name>
+ <param-value>1.0.0</param-value>
+ </init-param>
+ <init-param>
+ <param-name>swagger.api.title</param-name>
+ <param-value>OpenAPI Server</param-value>
+ </init-param>
+ <init-param>
+ <param-name>swagger.api.basepath</param-name>
+ <param-value>https://virtserver.swaggerhub.com/jixuan1989/iotdb/1.0.0</param-value>
+ </init-param>
+
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+ <servlet>
+ <servlet-name>Bootstrap</servlet-name>
+ <servlet-class>org.apache.iotdb.openapi.gen.handler.Bootstrap</servlet-class>
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>jersey</servlet-name>
+ <url-pattern>/jixuan1989/iotdb/1.0.0/*</url-pattern>
+ </servlet-mapping>
+ <filter>
+ <filter-name>ApiOriginFilter</filter-name>
+ <filter-class>org.apache.iotdb.openapi.gen.handler.ApiOriginFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ApiOriginFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
diff --git a/openapi/pom.xml b/openapi/pom.xml
index 36107fb..12bcb17 100644
--- a/openapi/pom.xml
+++ b/openapi/pom.xml
@@ -1,4 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iotdb-parent</artifactId>