Skip to content

Commit d39709a

Browse files
authored
feat(interactive): Init interactive python admin service (#4592)
Initialize Python-based interactive admin service.
1 parent 33e27ee commit d39709a

32 files changed

+6619
-21
lines changed

.github/workflows/interactive.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ jobs:
186186
cd ${GITHUB_WORKSPACE}/flex/tests/hqps
187187
bash hqps_admin_test.sh ${TMP_INTERACTIVE_WORKSPACE} ./interactive_config_test.yaml ${GS_TEST_DIR}
188188
189+
- name: Test Interactive Python Admin Service
190+
run:
191+
cd ${GITHUB_WORKSPACE}/flex/interactive/sdk
192+
bash generate_sdk.sh -g python -t server
193+
189194
- name: Build and test Interactive Java/Python SDK
190195
env:
191196
FLEX_DATA_DIR: ${{ github.workspace }}/flex/interactive/examples/modern_graph

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,24 @@ flex/interactive/sdk/python/pyproject.toml
158158
flex/interactive/sdk/python/gs_interactive/models/
159159
flex/interactive/sdk/python/gs_interactive/api/
160160
flex/interactive/sdk/python/gs_interactive/__init__.py
161-
flex/interactive/sdk/python/gs_interactive/api_client.py
162161
flex/interactive/sdk/python/gs_interactive/api_response.py
163-
flex/interactive/sdk/python/gs_interactive/configuration.py
164162
flex/interactive/sdk/python/gs_interactive/exceptions.py
165163
flex/interactive/sdk/python/gs_interactive/rest.py
166164
!flex/interactive/sdk/python/gs_interactive/client/generated/__init__.py
167165
!flex/interactive/sdk/python/gs_interactive/models/long_text.py
168166
!flex/interactive/sdk/python/gs_interactive/models/time_stamp_type.py
169167
!flex/interactive/sdk/python/gs_interactive/models/date_type.py
170168

169+
flex/interactive/sdk/master/.github/
170+
flex/interactive/sdk/master/Dockerfile
171+
flex/interactive/sdk/master/git_push.sh
172+
flex/interactive/sdk/master/tox.ini
173+
flex/interactive/sdk/master/.travis.yml
174+
flex/interactive/sdk/master/.dockerignore
175+
flex/interactive/sdk/master/.gitignore
176+
flex/interactive/sdk/master/gs_interactive_admin/models/
177+
flex/interactive/sdk/master/gs_interactive_admin/typing_utils.py
178+
171179
interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/
172180
interactive_engine/groot-http/.openapi-generator/
173181
interactive_engine/groot-http/src/main/java/org/

flex/interactive/sdk/generate_sdk.sh

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
PACKAGE_NAME="com.alibaba.graphscope.interactive"
2020
PYTHON_PACKAGE_NAME="gs_interactive"
21+
PYTHON_ADMIN_PACKAGE_NAME="gs_interactive_admin"
2122
GROUP_ID="com.alibaba.graphscope"
2223
ARTIFACT_ID="interactive"
2324
ARTIFACT_URL="https://github.com/alibaba/GraphScope/tree/main/flex/interactive"
@@ -29,7 +30,7 @@ developerOrganizationUrl="https://graphscope.io"
2930
DEVELOPER_NAME="GraphScope Team"
3031
LICENSE_NAME="Apache-2.0"
3132
LICENSE_URL="https://www.apache.org/licenses/LICENSE-2.0.html"
32-
LOG_LEVEL="error"
33+
LOG_LEVEL="INFO"
3334
export OPENAPI_GENERATOR_VERSION=7.2.0
3435

3536
#get current bash scrip's directory
@@ -46,6 +47,18 @@ function usage() {
4647
}
4748

4849
function do_gen_java() {
50+
if [ $# -ne 1 ]; then
51+
err "Invalid number of arguments:$#"
52+
usage
53+
exit 1
54+
fi
55+
type=$(echo $1 | tr '[:upper:]' '[:lower:]')
56+
if [ "$type" != "client" ]; then
57+
err "Currently only support client type when generating Java Code"
58+
usage
59+
exit 1
60+
fi
61+
4962
echo "Generating Java SDK"
5063
OUTPUT_PATH="${CUR_DIR}/java/"
5164

@@ -71,14 +84,35 @@ function do_gen_java() {
7184
}
7285

7386
function do_gen_python() {
74-
echo "Generating Python SDK"
75-
OUTPUT_PATH="${CUR_DIR}/python"
76-
export JAVA_OPTS="-Dlog.level=${LOG_LEVEL}"
77-
cmd="openapi-generator-cli generate -i ${OPENAPI_SPEC_PATH} -g python -o ${OUTPUT_PATH}"
78-
cmd=" ${cmd} --package-name ${PYTHON_PACKAGE_NAME}"
79-
cmd=" ${cmd} --additional-properties=packageVersion=${VERSION},pythonVersion=3"
80-
echo "Running command: ${cmd}"
81-
eval $cmd
87+
if [ $# -ne 1 ]; then
88+
err "Invalid number of arguments:$#"
89+
usage
90+
exit 1
91+
fi
92+
type=$(echo $1 | tr '[:upper:]' '[:lower:]')
93+
if [ "$type" == "client" ]; then
94+
echo "Generating Python SDK"
95+
OUTPUT_PATH="${CUR_DIR}/python"
96+
export JAVA_OPTS="-Dlog.level=${LOG_LEVEL}"
97+
cmd="openapi-generator-cli generate -i ${OPENAPI_SPEC_PATH} -g python -o ${OUTPUT_PATH}"
98+
cmd=" ${cmd} --package-name ${PYTHON_PACKAGE_NAME}"
99+
cmd=" ${cmd} --additional-properties=packageVersion=${VERSION},pythonVersion=3"
100+
echo "Running command: ${cmd}"
101+
eval $cmd
102+
elif [ "$type" == "server" ]; then
103+
echo "Generating Python Server"
104+
OUTPUT_PATH="${CUR_DIR}/master"
105+
export JAVA_OPTS="-Dlog.level=${LOG_LEVEL}"
106+
cmd="openapi-generator-cli generate -i ${OPENAPI_SPEC_PATH} -g python-flask -o ${OUTPUT_PATH}"
107+
cmd=" ${cmd} --package-name ${PYTHON_ADMIN_PACKAGE_NAME}"
108+
cmd=" ${cmd} --additional-properties=packageVersion=${VERSION},pythonVersion=3"
109+
echo "Running command: ${cmd}"
110+
eval $cmd
111+
else
112+
err "Unsupported type: $type"
113+
usage
114+
exit 1
115+
fi
82116
}
83117

84118
function do_gen_spring() {
@@ -96,20 +130,20 @@ function do_gen_spring() {
96130
}
97131

98132
function do_gen() {
99-
# expect only one argument
100-
if [ $# -ne 1 ]; then
133+
if [ $# -ne 2 ]; then
101134
err "Invalid number of arguments:$#"
102135
usage
103136
exit 1
104137
fi
105138
# to lower case
106139
lang=$(echo $1 | tr '[:upper:]' '[:lower:]')
140+
type=$(echo $2 | tr '[:upper:]' '[:lower:]')
107141
case $lang in
108142
java)
109-
do_gen_java
143+
do_gen_java $type
110144
;;
111145
python)
112-
do_gen_python
146+
do_gen_python $type
113147
;;
114148
spring)
115149
do_gen_spring
@@ -178,6 +212,8 @@ function install_generator() {
178212
}
179213

180214
install_generator
215+
type="client" # client or server
216+
language=""
181217

182218
while [[ $# -gt 0 ]]; do
183219
key="$1"
@@ -189,13 +225,20 @@ while [[ $# -gt 0 ]]; do
189225
;;
190226
-g | --lang)
191227
shift
192-
do_gen "$@"
193-
exit 0
228+
language="$1"
229+
shift
230+
;;
231+
-t | --type)
232+
shift
233+
type="$1"
234+
shift
194235
;;
195236
*) # unknown option
196237
err "unknown option $1"
197238
usage
198239
exit 1
199240
;;
200241
esac
201-
done
242+
done
243+
244+
do_gen $language $type
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
24+
25+
README.md
26+
setup.py
27+
gs_interactive_admin/controllers/admin_service_graph_management_controller.py
28+
gs_interactive_admin/controllers/admin_service_procedure_management_controller.py
29+
gs_interactive_admin/controllers/graph_service_edge_management_controller.py
30+
gs_interactive_admin/controllers/query_service_controller.py
31+
gs_interactive_admin/controllers/admin_service_job_management_controller.py
32+
gs_interactive_admin/controllers/admin_service_service_management_controller.py
33+
gs_interactive_admin/controllers/graph_service_vertex_management_controller.py
34+
gs_interactive_admin/controllers/utils_controller.py
35+
gs_interactive_admin/controllers/security_controller.py
36+
gs_interactive_admin/controllers/admin_service_service_registry_controller.py
37+
gs_interactive_admin/test/
38+
gs_interactive_admin/encoder.py
39+
requirements.txt
40+
test-requirements.txt
41+
setup.cfg
42+
gs_interactive_admin/__init__.py
43+
gs_interactive_admin/__main__.py
44+
gs_interactive_admin/util.py
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# OpenAPI generated server
2+
3+
## Overview
4+
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the
5+
[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This
6+
is an example of building a OpenAPI-enabled Flask server.
7+
8+
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
9+
10+
## Requirements
11+
Python 3.5.2+
12+
13+
## Usage
14+
To run the server, please execute the following from the root directory:
15+
16+
```
17+
pip3 install -r requirements.txt
18+
python3 -m gs_interactive_admin
19+
```
20+
21+
and open your browser to here:
22+
23+
```
24+
http://localhost:8080/ui/
25+
```
26+
27+
Your OpenAPI definition lives here:
28+
29+
```
30+
http://localhost:8080/openapi.json
31+
```
32+
33+
To launch the integration tests, use tox:
34+
```
35+
sudo pip install tox
36+
tox
37+
```
38+
39+
## Running with Docker
40+
41+
To run the server on a Docker container, please execute the following from the root directory:
42+
43+
```bash
44+
# building the image
45+
docker build -t gs_interactive_admin .
46+
47+
# starting up a container
48+
docker run -p 8080:8080 gs_interactive_admin
49+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
import connexion
20+
21+
from gs_interactive_admin import encoder
22+
23+
24+
def main():
25+
app = connexion.App(__name__, specification_dir="./openapi/")
26+
app.app.json_encoder = encoder.JSONEncoder
27+
app.add_api(
28+
"openapi.yaml",
29+
arguments={"title": "GraphScope Interactive API v0.3"},
30+
pythonic_params=True,
31+
)
32+
33+
app.run(port=8080)
34+
35+
36+
if __name__ == "__main__":
37+
main()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#

0 commit comments

Comments
 (0)