This is an automated email from the ASF dual-hosted git repository.
wiener pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new b2ac9a0 [STREAMPIPES-187] add template for welcome page
b2ac9a0 is described below
commit b2ac9a0268ce65375c86eea39952456f93212111
Author: Patrick Wiener <[email protected]>
AuthorDate: Tue Aug 4 22:49:12 2020 +0200
[STREAMPIPES-187] add template for welcome page
---
streampipes-wrapper-python/requirements.txt | 4 +--
streampipes-wrapper-python/setup.py | 2 ++
.../streampipes/api/resources/base.py | 8 +++---
.../streampipes/api/resources/decorator.py | 30 --------------------
.../streampipes/api/resources/welcome.py | 32 +++++++++++++++-------
.../streampipes/api/templates/index.html | 32 ++++++++++++++++++++++
.../streampipes/utils/register.py | 2 +-
7 files changed, 63 insertions(+), 47 deletions(-)
diff --git a/streampipes-wrapper-python/requirements.txt
b/streampipes-wrapper-python/requirements.txt
index 7ae7bd7..4ebe9a9 100644
--- a/streampipes-wrapper-python/requirements.txt
+++ b/streampipes-wrapper-python/requirements.txt
@@ -5,6 +5,7 @@ click==7.1.2
confluent-kafka==1.4.2
Flask==1.1.2
Flask-Classful==0.14.2
+Flask-Negotiate==0.1.0
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
@@ -13,5 +14,4 @@ python-consul==1.1.0
requests==2.24.0
six==1.15.0
urllib3==1.25.10
-waitress==1.4.4
-Werkzeug==1.0.1
\ No newline at end of file
+Werkzeug==1.0.1
diff --git a/streampipes-wrapper-python/setup.py
b/streampipes-wrapper-python/setup.py
index ea83329..7d51140 100644
--- a/streampipes-wrapper-python/setup.py
+++ b/streampipes-wrapper-python/setup.py
@@ -29,6 +29,7 @@ setup(
name='apache-streampipes-python',
version='0.67.0-SNAPSHOT',
packages=find_packages(),
+ package_data={'streampipes': ['api/templates/*']},
url='https://github.com/apache/incubator-streampipes',
license='https://www.apache.org/licenses/LICENSE-2.0',
license_files=["LICENSE", "NOTICE"],
@@ -41,6 +42,7 @@ setup(
'confluent-kafka==1.4.2',
'Flask==1.1.2',
'flask-classful==0.14.2',
+ 'Flask-Negotiate==0.1.0',
'bjoern==3.1.0',
'python-consul==1.1.0'
],
diff --git a/streampipes-wrapper-python/streampipes/api/resources/base.py
b/streampipes-wrapper-python/streampipes/api/resources/base.py
index 8faeec1..76f92f4 100644
--- a/streampipes-wrapper-python/streampipes/api/resources/base.py
+++ b/streampipes-wrapper-python/streampipes/api/resources/base.py
@@ -18,7 +18,7 @@ import abc
import os
from flask import jsonify, make_response
from flask_classful import FlaskView, route
-from streampipes.api.resources.decorator import consumes
+from flask_negotiate import consumes
class Element(FlaskView):
@@ -81,7 +81,7 @@ class InvocableElement(Element):
__metaclass__ = abc.ABC
@route('/<element_id>', methods=['POST'])
- @consumes(media_type=['application/json'])
+ @consumes('application/json')
def invoke_runtime(self, element_id: str):
# TODO: parse invocation graph
# payload = request.json
@@ -89,14 +89,14 @@ class InvocableElement(Element):
return make_response(jsonify(resp), 200)
@route('/<element_id>/configurations', methods=['POST'])
- @consumes(media_type=['application/json'])
+ @consumes('application/json')
def fetch_configurations(self, element_id: str):
# payload = request.json
resp = {'element_id': element_id, 'config': 'sucess'}
return make_response(jsonify(resp), 200)
@route('/<element_id>/output', methods=['POST'])
- @consumes(media_type=['application/json'])
+ @consumes('application/json')
def fetch_output_configurations(self, element_id: str):
# payload = request.json
resp = {'element_id': element_id, 'output': 'sucess'}
diff --git a/streampipes-wrapper-python/streampipes/api/resources/decorator.py
b/streampipes-wrapper-python/streampipes/api/resources/decorator.py
deleted file mode 100644
index 2b805a7..0000000
--- a/streampipes-wrapper-python/streampipes/api/resources/decorator.py
+++ /dev/null
@@ -1,30 +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.
-#
-import functools
-from flask import request, abort
-
-
-def consumes(media_type):
- def consumes_decorator(f):
- @functools.wraps(f)
- def decorated_function(*args, **kwargs):
- for entry in media_type:
- if request.content_type == entry:
- return f(*args, **kwargs)
- abort(404)
- return decorated_function
- return consumes_decorator
diff --git a/streampipes-wrapper-python/streampipes/api/resources/welcome.py
b/streampipes-wrapper-python/streampipes/api/resources/welcome.py
index 3f531d7..4343f47 100644
--- a/streampipes-wrapper-python/streampipes/api/resources/welcome.py
+++ b/streampipes-wrapper-python/streampipes/api/resources/welcome.py
@@ -14,18 +14,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-from flask import make_response, jsonify, request
-from flask_classful import FlaskView
-from streampipes.api.resources.decorator import consumes
+from flask import make_response, jsonify, request, render_template
+from flask_classful import FlaskView, route
+from flask_negotiate import produces
class WelcomeResource(FlaskView):
+ dummy_processors = [{
+ 'name': 'Greeter Python',
+ 'uri':
'http://localhost:5000/sepa/org.apache.streampipes.python.processor.greeter',
+ 'description': 'Greeter Python Description'
+ },
+ {
+ 'name': 'DoNothing Python',
+ 'uri':
'http://localhost:5000/sepa/org.apache.streampipes.python.processor.donothing',
+ 'description': 'Donothing Python Description'
+ }]
- @consumes(media_type=['application/json','text/html'])
- def index(self):
- if request.content_type == 'application/json':
- resp = {'welcome': 'hello-world!'}
+ @route('/', methods=['GET'])
+ @produces('application/json','text/html')
+ def welcome(self):
+ if request.accept_mimetypes['text/html']:
+ return render_template('index.html',
processors=self.dummy_processors)
+
+ if request.accept_mimetypes['application/json']:
+ resp = {'success': True}
return make_response(jsonify(resp), 200)
- elif request.content_type == 'text/html':
- return "<p>Got it!</p>"
- return 'welcome!'
+
diff --git a/streampipes-wrapper-python/streampipes/api/templates/index.html
b/streampipes-wrapper-python/streampipes/api/templates/index.html
new file mode 100644
index 0000000..dac26a7
--- /dev/null
+++ b/streampipes-wrapper-python/streampipes/api/templates/index.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>StreamPipes Python</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link type="text/css"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"
rel="stylesheet">
+ <style type="text/css">
+ body {padding-top: 70px;}
+ </style>
+ <script type="text/javascript"
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
+ <script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+</head>
+<body>
+<nav class="navbar navbar-inverse navbar-fixed-top" style="background: rgb(57,
181, 74)">
+ <div class="container">
+ <div class="navbar-header">
+ <a class="navbar-brand" style="color:white;">StreamPipes Pipeline
Element Container</a>
+ </div>
+ </div>
+</nav>
+<div class="container">
+ <h4>This is a developer-oriented view. Navigate to 'Install Pipeline
Elements' in the
+ StreamPipes UI to import the elements shown here.
+ </h4>
+ {% for processor in processors %}
+ <h3>{{ processor.name }}</h3>
+ <h4>URI: {{ processor.uri }}</h4>
+ <h4>Description: {{ processor.description }}</h4>
+ {% endfor %}
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/streampipes-wrapper-python/streampipes/utils/register.py
b/streampipes-wrapper-python/streampipes/utils/register.py
index be906ae..a4a663c 100644
--- a/streampipes-wrapper-python/streampipes/utils/register.py
+++ b/streampipes-wrapper-python/streampipes/utils/register.py
@@ -48,7 +48,7 @@ class ConsulUtils(object):
check=Check.http(url='http://' +
host + ':' + str(port),
interval=self._DEFAULT_CONSUL_CONFIG[
'HEALTHCHECK_INTERVAL'],
-
header={"Content-Type": ["application/json"]}))
+ header={"Accept":
["application/json"]}))
def register_config(self, app_id: str, env_key: str, default, description:
str, configuration_scope=None,
is_password=None):