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/11/27 10:43:20 UTC

[flink-statefun] 06/08: [FLINK-20268] [python] Update all Python examples to declare state with SDK

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 f1b30fbf2b69156a3bf15580f964c3b878e7d163
Author: Tzu-Li (Gordon) Tai <tz...@apache.org>
AuthorDate: Thu Nov 26 16:20:13 2020 +0800

    [FLINK-20268] [python] Update all Python examples to declare state with SDK
---
 statefun-examples/statefun-async-python-example/greeter/greeter.py  | 5 ++++-
 .../statefun-async-python-example/statefun/module.yaml              | 2 --
 .../statefun-python-greeter-example/greeter/greeter.py              | 5 ++++-
 statefun-examples/statefun-python-greeter-example/module.yaml       | 2 --
 statefun-examples/statefun-python-k8s-example/main.py               | 6 ++++--
 statefun-examples/statefun-python-k8s-example/module.yaml           | 2 --
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/statefun-examples/statefun-async-python-example/greeter/greeter.py b/statefun-examples/statefun-async-python-example/greeter/greeter.py
index e2e0527..80f1552 100644
--- a/statefun-examples/statefun-async-python-example/greeter/greeter.py
+++ b/statefun-examples/statefun-async-python-example/greeter/greeter.py
@@ -18,6 +18,7 @@
 from messages_pb2 import SeenCount, GreetRequest, GreetResponse
 
 from statefun import StatefulFunctions
+from statefun import StateSpec
 from statefun import AsyncRequestReplyHandler
 from statefun import kafka_egress_record
 
@@ -26,7 +27,9 @@ import asyncio
 functions = StatefulFunctions()
 
 
-@functions.bind("example/greeter")
+@functions.bind(
+    typename="example/greeter",
+    states=[StateSpec('seen_count')])
 async def greet(context, greet_request: GreetRequest):
     state = context.state('seen_count').unpack(SeenCount)
     if not state:
diff --git a/statefun-examples/statefun-async-python-example/statefun/module.yaml b/statefun-examples/statefun-async-python-example/statefun/module.yaml
index 146e947..762e464 100644
--- a/statefun-examples/statefun-async-python-example/statefun/module.yaml
+++ b/statefun-examples/statefun-async-python-example/statefun/module.yaml
@@ -24,8 +24,6 @@ module:
             type: example/greeter
           spec:
             endpoint: http://python-worker:8000/statefun
-            states:
-              - seen_count
             maxNumBatchRequests: 500
             timeout: 2min
     ingresses:
diff --git a/statefun-examples/statefun-python-greeter-example/greeter/greeter.py b/statefun-examples/statefun-python-greeter-example/greeter/greeter.py
index bc56a12..8f9c5bf 100644
--- a/statefun-examples/statefun-python-greeter-example/greeter/greeter.py
+++ b/statefun-examples/statefun-python-greeter-example/greeter/greeter.py
@@ -18,13 +18,16 @@
 from messages_pb2 import SeenCount, GreetRequest, GreetResponse
 
 from statefun import StatefulFunctions
+from statefun import StateSpec
 from statefun import RequestReplyHandler
 from statefun import kafka_egress_record
 
 functions = StatefulFunctions()
 
 
-@functions.bind("example/greeter")
+@functions.bind(
+    typename="example/greeter",
+    states=[StateSpec('seen_count')])
 def greet(context, greet_request: GreetRequest):
     state = context.state('seen_count').unpack(SeenCount)
     if not state:
diff --git a/statefun-examples/statefun-python-greeter-example/module.yaml b/statefun-examples/statefun-python-greeter-example/module.yaml
index 146e947..762e464 100644
--- a/statefun-examples/statefun-python-greeter-example/module.yaml
+++ b/statefun-examples/statefun-python-greeter-example/module.yaml
@@ -24,8 +24,6 @@ module:
             type: example/greeter
           spec:
             endpoint: http://python-worker:8000/statefun
-            states:
-              - seen_count
             maxNumBatchRequests: 500
             timeout: 2min
     ingresses:
diff --git a/statefun-examples/statefun-python-k8s-example/main.py b/statefun-examples/statefun-python-k8s-example/main.py
index 67d3fce..f9df7c2 100644
--- a/statefun-examples/statefun-python-k8s-example/main.py
+++ b/statefun-examples/statefun-python-k8s-example/main.py
@@ -19,14 +19,16 @@ from messages_pb2 import LoginEvent
 from messages_pb2 import SeenCount
 
 from statefun import StatefulFunctions
-
+from statefun import StateSpec
 from statefun import RequestReplyHandler
 from statefun import kafka_egress_record
 
 functions = StatefulFunctions()
 
 
-@functions.bind("k8s-demo/greeter")
+@functions.bind(
+    typename="k8s-demo/greeter",
+    states=[StateSpec('seen_count')])
 def greet(context, message: LoginEvent):
     state = context.state('seen_count').unpack(SeenCount)
     if not state:
diff --git a/statefun-examples/statefun-python-k8s-example/module.yaml b/statefun-examples/statefun-python-k8s-example/module.yaml
index dee3eea..cb59fd5 100644
--- a/statefun-examples/statefun-python-k8s-example/module.yaml
+++ b/statefun-examples/statefun-python-k8s-example/module.yaml
@@ -24,8 +24,6 @@ module:
             type: k8s-demo/greeter
           spec:
             endpoint: http://statefun-python:8000/statefun
-            states:
-              - seen_count
             maxNumBatchRequests: 500
             timeout: 2min
     ingresses: