You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tz...@apache.org on 2020/03/12 02:45:52 UTC
[flink-statefun] 07/08: [FLINK-16515][docs] Add remote modules to
deployment
This is an automated email from the ASF dual-hosted git repository.
tzulitai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git
commit 72e686ebbdb0f5fb49643eb7a54f94ea33fe556a
Author: Seth Wiesman <sj...@gmail.com>
AuthorDate: Mon Mar 9 21:35:02 2020 -0500
[FLINK-16515][docs] Add remote modules to deployment
---
statefun-docs/docs/deployment_operations/packaging.rst | 9 ++++++---
statefun-docs/docs/sdk/java/index.rst | 2 +-
statefun-docs/docs/sdk/python.rst | 8 +++++++-
statefun-docs/src/main/python/Caller.py | 6 +++---
statefun-docs/src/main/python/Counter.py | 4 ++--
statefun-docs/src/main/python/Delayed.py | 13 +++++++------
statefun-docs/src/main/python/HelloWorld.py | 4 ++--
statefun-docs/src/main/python/TypeHint.py | 6 +++---
statefun-docs/src/main/resources/module.yaml | 11 ++++++-----
9 files changed, 37 insertions(+), 26 deletions(-)
diff --git a/statefun-docs/docs/deployment_operations/packaging.rst b/statefun-docs/docs/deployment_operations/packaging.rst
index 3151114..01bb8d2 100644
--- a/statefun-docs/docs/deployment_operations/packaging.rst
+++ b/statefun-docs/docs/deployment_operations/packaging.rst
@@ -28,14 +28,17 @@ The recommended deployment mode for Stateful Functions applications is to build
This way, user code does not need to package any Apache Flink components.
The provided base image allows teams to package their applications with all the necessary runtime dependencies quickly.
-Below is an example Dockerfile for building a Stateful Functions image for an application called ``statefun-example``.
+Below is an example Dockerfile for building a Stateful Functions image with both an :ref:`embedded module <embedded_module>` and a :ref:`remote module <remote_module>` for an application called ``statefun-example``.
-.. code-block:: java
+.. code-block:: dockerfile
FROM statefun
RUN mkdir -p /opt/statefun/modules/statefun-example
+ RUN mkdir -p /opt/statefun/modules/remote
+
COPY target/statefun-example*jar /opt/statefun/modules/statefun-example/
+ COPY module.yaml /opt/statefun/modules/remote/module.yaml
Flink Jar
^^^^^^^^^
@@ -59,4 +62,4 @@ You do not need to take any action beyond adding the dependency to your POM.
.. code-block:: bash
- ./bin/flink run ./statefun-example.jar
\ No newline at end of file
+ ./bin/flink run ./statefun-example.jar
diff --git a/statefun-docs/docs/sdk/java/index.rst b/statefun-docs/docs/sdk/java/index.rst
index a9a46e9..4d60a73 100644
--- a/statefun-docs/docs/sdk/java/index.rst
+++ b/statefun-docs/docs/sdk/java/index.rst
@@ -61,7 +61,7 @@ Functions are invoked based on a function type and unique identifier.
Function Types and Messaging
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-In Java, function types are defined as a stringly typed reference containing a namespace and name.
+In Java, function types are defined as a _stringly_ typed reference containing a namespace and name.
The type is bound to the implementing class in the :ref:`module <embedded_module>` definition.
Below is an example function type for the hello world function.
diff --git a/statefun-docs/docs/sdk/python.rst b/statefun-docs/docs/sdk/python.rst
index f394eb7..3075b18 100644
--- a/statefun-docs/docs/sdk/python.rst
+++ b/statefun-docs/docs/sdk/python.rst
@@ -43,7 +43,7 @@ The following is an example of a simple hello world function.
:language: python
:lines: 19-
-This code declares a function with in the namespace ``flink`` and of type ``hello`` and binds it to the ``hello_function`` Python instance.
+This code declares a function with in the namespace ``example`` and of type ``hello`` and binds it to the ``hello_function`` Python instance.
Messages's are untyped and passed through the system as ``google.protobuf.Any`` so one function can potentially process multiple types of messages.
@@ -72,6 +72,12 @@ Function types can then be referenced from other functions to create an address
:language: python
:lines: 19-
+Alternatively, functions can be manually bound to the runtime.
+
+.. code-block:: python
+
+ functions.register("example/caller", caller_function)
+
Sending Delayed Messages
^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/statefun-docs/src/main/python/Caller.py b/statefun-docs/src/main/python/Caller.py
index c176b80..23ac196 100644
--- a/statefun-docs/src/main/python/Caller.py
+++ b/statefun-docs/src/main/python/Caller.py
@@ -21,8 +21,8 @@ from statefun import StatefulFunctions
functions = StatefulFunctions()
-@functions.bind("flink/caller")
-def caller(context, message):
+@functions.bind("example/caller")
+def caller_function(context, message):
"""A simple stateful function that sends a message to the user with id `user1`"""
user = User()
@@ -32,4 +32,4 @@ def caller(context, message):
envelope = Any()
envelope.Pack(user)
- context.send("flink/hello", user.user_id, envelope)
\ No newline at end of file
+ context.send("example/hello", user.user_id, envelope)
diff --git a/statefun-docs/src/main/python/Counter.py b/statefun-docs/src/main/python/Counter.py
index 4c1a79d..4cf806d 100644
--- a/statefun-docs/src/main/python/Counter.py
+++ b/statefun-docs/src/main/python/Counter.py
@@ -21,7 +21,7 @@ from statefun import StatefulFunctions
functions = StatefulFunctions()
-@functions.bind("flink/count")
+@functions.bind("example/count")
def count_greeter(context, message):
"""Function that greets a user based on
the number of times it has been called"""
@@ -52,4 +52,4 @@ def generate_message(count, user):
elif count == 3:
return "Third time's the charm"
else:
- return "Hello for the " + count + "th time"
\ No newline at end of file
+ return "Hello for the " + count + "th time"
diff --git a/statefun-docs/src/main/python/Delayed.py b/statefun-docs/src/main/python/Delayed.py
index a68a048..939026b 100644
--- a/statefun-docs/src/main/python/Delayed.py
+++ b/statefun-docs/src/main/python/Delayed.py
@@ -16,21 +16,22 @@
# limitations under the License.
################################################################################
+import typing
from google.protobuf.any_pb2 import Any
from datetime import timedelta
from statefun import StatefulFunctions
functions = StatefulFunctions()
-@functions.bind("flink/delayed")
-def delayed(context, message):
+@functions.bind("example/delayed")
+def delayed(context, message: typing.Union[BeginEvent, FutureEvent]):
"""A function that sends itself a message after a delay """
- if message.Is(Message.DESCRIPTOR):
+ if isinstance(message, BeginEvent):
print("Hello!")
envelope = Any()
- envelope.Pack(DelayedMessage())
+ envelope.Pack(FutureEvent())
context.send_after(
context.self.typename(),
@@ -39,6 +40,6 @@ def delayed(context, message):
envelope)
return
- if message.Is(DelayedMessage.DESCRIPTOR):
+ if isinstance(message, FutureEvent):
print("Hello from the future!")
- return
\ No newline at end of file
+ return
diff --git a/statefun-docs/src/main/python/HelloWorld.py b/statefun-docs/src/main/python/HelloWorld.py
index 9d7ea72..37447a1 100644
--- a/statefun-docs/src/main/python/HelloWorld.py
+++ b/statefun-docs/src/main/python/HelloWorld.py
@@ -20,10 +20,10 @@ from statefun import StatefulFunctions
functions = StatefulFunctions()
-@functions.bind("flink/hello")
+@functions.bind("example/hello")
def hello_function(context, message):
"""A simple hello world function"""
user = User()
message.Unpack(user)
- print("Hello " + user.name)
\ No newline at end of file
+ print("Hello " + user.name)
diff --git a/statefun-docs/src/main/python/TypeHint.py b/statefun-docs/src/main/python/TypeHint.py
index 2af4d47..7337e00 100644
--- a/statefun-docs/src/main/python/TypeHint.py
+++ b/statefun-docs/src/main/python/TypeHint.py
@@ -21,17 +21,17 @@ from statefun import StatefulFunctions
functions = StatefulFunctions()
-@functions.bind("flink/hello")
+@functions.bind("example/hello")
def hello_function(context, message: User):
"""A simple hello world function with typing"""
print("Hello " + message.name)
-@function.bind("flink/goodbye")
+@function.bind("example/goodbye")
def goodbye_function(context, message: typing.Union[User, Admin]):
"""A function that dispatches on types"""
if isinstance(message, User):
print("Goodbye user")
elif isinstance(message, Admin):
- print("Goodbye Admin")
\ No newline at end of file
+ print("Goodbye Admin")
diff --git a/statefun-docs/src/main/resources/module.yaml b/statefun-docs/src/main/resources/module.yaml
index e3e6425..360f98b 100644
--- a/statefun-docs/src/main/resources/module.yaml
+++ b/statefun-docs/src/main/resources/module.yaml
@@ -14,18 +14,19 @@
# limitations under the License.
# This file is the base for the Apache Flink configuration
+version: "1.0"
module:
meta:
type: remote
spec:
functions:
- - function:
+ - function:
meta:
kind: http
- type: flink/greeter
+ type: example/greeter
spec:
- endpoint: http://greeter:8000/statefun
+ endpoint: http://<host-name>/statefun
states:
- - seen_count
+ - seen_count
maxNumBatchRequests: 500
- timeout: 2m
\ No newline at end of file
+ timeout: 2min