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 356469d  almost done for openapi
356469d is described below

commit 356469df2cb52bd80b92040bdbbacdee33d8d152
Author: xiangdong huang <[email protected]>
AuthorDate: Fri Jan 15 02:53:22 2021 +0800

    almost done for openapi
---
 openapi/go-rest/Dockerfile                         |  19 ++++
 openapi/go-rest/README.md                          |  67 ++++++++++++
 openapi/go-rest/pom.xml                            |  76 +++++++++++++
 openapi/go-rest/src/go.mod                         |  26 +++++
 openapi/go-rest/src/go.sum                         |   2 +
 .../go-rest/src/iotdbrestimpl/api_service_impl.go  | 119 +++++++++++++++++++++
 openapi/go-rest/src/main.go                        |  38 +++++++
 openapi/java-rest/pom.xml                          |  35 +-----
 openapi/pom.xml                                    |  10 +-
 9 files changed, 352 insertions(+), 40 deletions(-)

diff --git a/openapi/go-rest/Dockerfile b/openapi/go-rest/Dockerfile
new file mode 100644
index 0000000..a6d7f2b
--- /dev/null
+++ b/openapi/go-rest/Dockerfile
@@ -0,0 +1,19 @@
+FROM golang:1.13 AS build
+WORKDIR /go/src
+COPY src/iotdbrestimpl ./iotdbrestimpl
+COPY src/main.go .
+COPY src/go.mod ./go.mod
+COPY target/gen/iotdbrest ../target/gen/iotdbrest
+
+# If you compile the dockerfile in China, uncomment the followings:
+ENV GOPROXY=https://goproxy.io,direct
+
+ENV CGO_ENABLED=0
+RUN go get -d -v ./...
+
+RUN go build -a -installsuffix cgo -o iotdb-rest .
+
+FROM scratch AS runtime
+COPY --from=build /go/src/iotdb-rest ./
+EXPOSE 8080/tcp
+ENTRYPOINT ["./iotd-brest"]
diff --git a/openapi/go-rest/README.md b/openapi/go-rest/README.md
new file mode 100644
index 0000000..64619e4
--- /dev/null
+++ b/openapi/go-rest/README.md
@@ -0,0 +1,67 @@
+<!--
+
+    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.
+
+-->
+<!-- generate by openapi and modified manually-->
+
+# Go API Server for iotdbrest
+
+IoTDB Rest API for Grafana, Prometheus, etc..
+
+## Overview
+This server was generated by the [openapi-generator]
+(https://openapi-generator.tech) project.
+By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from 
a remote server, you can easily generate a server stub.  
+-
+
+To see how to make this your own, look here:
+
+[README](https://openapi-generator.tech)
+
+
+### How to use:
+
+1. run `mvn generate-sources` under the `openapi` module
+2. go to `go-rest` module, fix issues that current openapi-generator causes:
+  1. `"mime/multipart"` is forget to be imported in `router.go`
+  2. `github.com/gorilla/mux` should not be imported in `api_default.go` file.
+
+### Running the server
+To run the server, follow these simple steps:
+
+```
+cd src
+go run main.go
+```
+
+To run the server in a docker container
+```
+docker build --network=host -t iotdbrest .
+```
+
+Once image is built use
+```
+docker run --rm -it iotdbrest 
+```
+
+
+
+
+
+
diff --git a/openapi/go-rest/pom.xml b/openapi/go-rest/pom.xml
new file mode 100644
index 0000000..b55d1ed
--- /dev/null
+++ b/openapi/go-rest/pom.xml
@@ -0,0 +1,76 @@
+<?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>
+        <artifactId>openapi</artifactId>
+        <version>0.12.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>go-rest</artifactId>
+    <packaging>pom</packaging>
+
+    <build>
+        <plugins>
+            <!-- for generated go module -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.4.3</version>
+                <configuration>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>copy-go-rest-codes</id>
+                        <!-- here the phase you need -->
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <encoding>utf-8</encoding>
+                            
<outputDirectory>${project.build.directory}/gen/iotdbrest</outputDirectory>
+                            <resources>
+                                <resource>
+                                    
<directory>${basedir}/../target/generated-sources/go/iotdbrest</directory>
+                                    <excludes>
+                                        
<exclude>api_default_service.go</exclude>
+                                    </excludes>
+                                </resource>
+                                <resource>
+                                    
<directory>${basedir}/../target/generated-sources/go</directory>
+                                    <includes>
+                                        <include>go.mod</include>
+                                    </includes>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>
diff --git a/openapi/go-rest/src/go.mod b/openapi/go-rest/src/go.mod
new file mode 100644
index 0000000..90a650e
--- /dev/null
+++ b/openapi/go-rest/src/go.mod
@@ -0,0 +1,26 @@
+//
+// 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.
+//
+
+module github.com/apache/iotdb/openapi/go-rest/src
+
+go 1.13
+
+replace github.com/iotdbrest => ../target/gen/iotdbrest
+
+require github.com/iotdbrest v0.0.0-00010101000000-000000000000
diff --git a/openapi/go-rest/src/go.sum b/openapi/go-rest/src/go.sum
new file mode 100644
index 0000000..2bf9262
--- /dev/null
+++ b/openapi/go-rest/src/go.sum
@@ -0,0 +1,2 @@
+github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
+github.com/gorilla/mux v1.7.3/go.mod 
h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
diff --git a/openapi/go-rest/src/iotdbrestimpl/api_service_impl.go 
b/openapi/go-rest/src/iotdbrestimpl/api_service_impl.go
new file mode 100644
index 0000000..9b3f700
--- /dev/null
+++ b/openapi/go-rest/src/iotdbrestimpl/api_service_impl.go
@@ -0,0 +1,119 @@
+/*
+ * 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 iotdbrestimpl
+
+// this is just a demo generated by openapi generator
+
+import (
+       "context"
+       "errors"
+       "net/http"
+       . "github.com/iotdbrest"
+)
+
+// DefaultApiService is a service that implents the logic for the 
DefaultApiServicer
+// This service should implement the business logic for every endpoint for the 
DefaultApi API. 
+// Include any external packages or services that will be required by this 
service.
+type DefaultApiService struct {
+}
+
+// NewDefaultApiService creates a default api service
+func NewDefaultApiService() DefaultApiServicer {
+       return &DefaultApiService{}
+}
+
+// PostV1GrafanaData - Serve for queries from Grafana
+func (s *DefaultApiService) PostV1GrafanaData(ctx context.Context, 
groupByFillPlan GroupByFillPlan) (ImplResponse, error) {
+       // TODO - update PostV1GrafanaData with the required logic for this 
service method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
[]GrafanaDataFrameInner{}) or use other options such as http.Ok ...
+       //return Response(200, []GrafanaDataFrameInner{}), nil
+
+       //TODO: Uncomment the next line to return response Response(401, 
string{}) or use other options such as http.Ok ...
+       //return Response(401, string{}), nil
+
+       return Response(http.StatusNotImplemented, nil), 
errors.New("PostV1GrafanaData method not implemented")
+}
+
+// PostV1GrafanaDataSimplejson - Serve for queries from Grafana with 
simpleJson plugin
+func (s *DefaultApiService) PostV1GrafanaDataSimplejson(ctx context.Context, 
groupByFillPlan GroupByFillPlan) (ImplResponse, error) {
+       // TODO - update PostV1GrafanaDataSimplejson with the required logic 
for this service method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
[]GrafanaJsonInner{}) or use other options such as http.Ok ...
+       //return Response(200, []GrafanaJsonInner{}), nil
+
+       //TODO: Uncomment the next line to return response Response(401, 
string{}) or use other options such as http.Ok ...
+       //return Response(401, string{}), nil
+
+       return Response(http.StatusNotImplemented, nil), 
errors.New("PostV1GrafanaDataSimplejson method not implemented")
+}
+
+// PostV1GrafanaNode - Serve for getting time series name level by level by 
Grafana
+func (s *DefaultApiService) PostV1GrafanaNode(ctx context.Context, requestBody 
[]string) (ImplResponse, error) {
+       // TODO - update PostV1GrafanaNode with the required logic for this 
service method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
InlineResponse2001{}) or use other options such as http.Ok ...
+       //return Response(200, InlineResponse2001{}), nil
+
+       //TODO: Uncomment the next line to return response Response(401, 
string{}) or use other options such as http.Ok ...
+       //return Response(401, string{}), nil
+
+       return Response(http.StatusNotImplemented, nil), 
errors.New("PostV1GrafanaNode method not implemented")
+}
+
+// PostV1PrometheusQuery - Serve for queries from Prometheus
+func (s *DefaultApiService) PostV1PrometheusQuery(ctx context.Context, 
userAgent string, xPrometheusRemoteReadVersion string, body 
map[string]interface{}) (ImplResponse, error) {
+       // TODO - update PostV1PrometheusQuery with the required logic for this 
service method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
map[string]interface{}{}) or use other options such as http.Ok ...
+       //return Response(200, map[string]interface{}{}), nil
+
+       return Response(http.StatusNotImplemented, nil), 
errors.New("PostV1PrometheusQuery method not implemented")
+}
+
+// PostV1PrometheusReceive - Serve for writing data by Prometheus
+func (s *DefaultApiService) PostV1PrometheusReceive(ctx context.Context, 
userAgent string, xPrometheusRemoteWriteVersion string, body 
map[string]interface{}) (ImplResponse, error) {
+       // TODO - update PostV1PrometheusReceive with the required logic for 
this service method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
InlineResponse200{}) or use other options such as http.Ok ...
+       //return Response(200, InlineResponse200{}), nil
+
+       //TODO: Uncomment the next line to return response Response(401, 
string{}) or use other options such as http.Ok ...
+       //return Response(401, string{}), nil
+
+       return Response(http.StatusNotImplemented, nil), 
errors.New("PostV1PrometheusReceive method not implemented")
+}
+
+// TryPing - Your GET endpoint
+func (s *DefaultApiService) TryPing(ctx context.Context) (ImplResponse, error) 
{
+       // TODO - update TryPing with the required logic for this service 
method.
+       // Add api_default_service_go to the .openapi-generator-ignore to avoid 
overwriting this service implementation when updating open api generation.
+
+       //TODO: Uncomment the next line to return response Response(200, 
string{}) or use other options such as http.Ok ...
+       //return Response(200, string{}), nil
+
+       return Response(http.StatusNotImplemented, nil), errors.New("TryPing 
method not implemented")
+}
+
diff --git a/openapi/go-rest/src/main.go b/openapi/go-rest/src/main.go
new file mode 100644
index 0000000..46207b8
--- /dev/null
+++ b/openapi/go-rest/src/main.go
@@ -0,0 +1,38 @@
+/*
+ * 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 main
+
+import (
+       "github.com/apache/iotdb/openapi/go-rest/src/iotdbrestimpl"
+       "github.com/iotdbrest"
+       "log"
+       "net/http"
+)
+
+func main() {
+       log.Printf("Server started")
+
+       DefaultApiService := iotdbrestimpl.NewDefaultApiService()
+       DefaultApiController := 
iotdbrest.NewDefaultApiController(DefaultApiService)
+
+       router := iotdbrest.NewRouter(DefaultApiController)
+
+       log.Fatal(http.ListenAndServe(":5667", router))
+}
diff --git a/openapi/java-rest/pom.xml b/openapi/java-rest/pom.xml
index 5adad96..f8b66f7 100644
--- a/openapi/java-rest/pom.xml
+++ b/openapi/java-rest/pom.xml
@@ -24,6 +24,7 @@
         <groupId>org.apache.iotdb</groupId>
         <artifactId>openapi</artifactId>
         <version>0.12.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>java-rest</artifactId>
@@ -32,29 +33,6 @@
         <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-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>
@@ -213,17 +191,6 @@
                     <version>${beanvalidation-version}</version>
                     <scope>provided</scope>
                 </dependency>
-                <!-- -->
-                <!--                <dependency>-->
-                <!--                    
<groupId>org.glassfish.jersey.containers</groupId>-->
-                <!--                    
<artifactId>jersey-container-servlet-core</artifactId>-->
-                <!--                    
<version>${jersey2-version}</version>-->
-                <!--                </dependency>-->
-                <!--                <dependency>-->
-                <!--                    
<groupId>org.glassfish.jersey.media</groupId>-->
-                <!--                    
<artifactId>jersey-media-multipart</artifactId>-->
-                <!--                    
<version>${jersey2-version}</version>-->
-                <!--                </dependency>-->
             </dependencies>
         </profile>
     </profiles>
diff --git a/openapi/pom.xml b/openapi/pom.xml
index 1b3a6c4..5f5e47c 100644
--- a/openapi/pom.xml
+++ b/openapi/pom.xml
@@ -24,11 +24,13 @@
         <artifactId>iotdb-parent</artifactId>
         <groupId>org.apache.iotdb</groupId>
         <version>0.12.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <packaging>pom</packaging>
     <modules>
         <module>java-rest</module>
+        <module>go-rest</module>
     </modules>
     <artifactId>openapi</artifactId>
     <properties>
@@ -97,9 +99,6 @@
                                 <configuration>
                                     
<inputSpec>${project.basedir}/src/main/openapi3/iotdb-rest.yaml</inputSpec>
                                     
<output>${project.build.directory}/generated-sources/go</output>
-                                    
<apiPackage>org.apache.iotdb.openapi.gen.handler</apiPackage>
-                                    
<modelPackage>org.apache.iotdb.openapi.gen.model</modelPackage>
-                                    
<invokerPackage>org.apache.iotdb.openapi.gen.invoker</invokerPackage>
                                     <generatorName>go-server</generatorName>
                                     <groupId>org.apache.iotdb</groupId>
                                     <artifactId>iotdb-rest-service</artifactId>
@@ -107,13 +106,12 @@
                                     
<addCompileSourceRoot>false</addCompileSourceRoot>
                                     <configOptions>
                                         <licenseName>Apache License 
2.0</licenseName>
-                                        
<packageName>org.apache.iotdb</packageName>
-                                        
<packageName>org.apache.iotdb.rest</packageName>
+                                        <packageName>iotdbrest</packageName>
                                         
<packageVersion>${project.version}</packageVersion>
                                         <serverPort>5667</serverPort>
                                         <useGzipFeature>true</useGzipFeature>
                                         <!-- sourceFolder is a relative folder 
-->
-                                        <sourceFolder>gen</sourceFolder>
+                                        <sourceFolder>iotdbrest</sourceFolder>
                                     </configOptions>
                                 </configuration>
                             </execution>

Reply via email to