Skip to content

Conversation

@sjwiesman
Copy link
Contributor

This replaces the old Java walkthrough, which we all agreed was lacking, with an updated Python walkthrough. I think having python only is fine but I'm also comfortable adding Java as a follow up if there is consensus.

@sjwiesman sjwiesman force-pushed the walkthroughv2 branch 3 times, most recently from 4181369 to 61b208d Compare March 26, 2020 22:30
Copy link
Contributor

@rmetzger rmetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, left some comments

It reads and updates the number of times that user has been seen and sends a greeting to the egress.
## Configuring for Runtime

The Apache Flink runtime makes requests to the greeter function by making `http` calls to the `Flask` server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought: Not sure how we are positioning StateFun, but this sounds like something coming directly from Flink?
Maybe we could somehow phrase this to come from the "server side" of statefun running in Flink?

If we are doing a good job, we might have users who are not even really aware that this is powered by Flink.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll find a way to rephrase it, you're right, you don't need to understand Flink for this getting started.

That said, I don't think you could go to production without understanding the project's relationship to Flink. We may want to follow up with a dedicated page explaining how these projects are related.

$ docker-compose exec kafka-broker kafka-console-producer.sh \
--broker-list localhost:9092 \
--topic names
$ docker-compose up -d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to work?

Building master
Step 1/3 : FROM statefun
ERROR: Service 'master' failed to build: pull access denied for statefun, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Copy link
Contributor Author

@sjwiesman sjwiesman Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet because we haven't released :) In the mean time you can build the image locally using the ./tools/docker/build-stateful-functions.sh script in the tools folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx. That worked

Step 5/9 : RUN pip install -r requirements.txt
 ---> Running in 7a9ee7fda4f7
ERROR: Could not find a version that satisfies the requirement apache-flink-statefun (from -r requirements.txt (line 17)) (from versions: none)
ERROR: No matching distribution found for apache-flink-statefun (from -r requirements.txt (line 17))
ERROR: Service 'python-worker' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

How do I get apache-flink-statefun into that Docker build?

I managed to create a RELEASE_VERSION=2.0 ./create_python_sdk_release.sh release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update greeter/Dockerfile to be

FROM python:3.7-alpine

RUN mkdir -p /app
WORKDIR /app

COPY apache_flink_statefun-snapshot-py3-none-any.whl /app
RUN pip install apache_flink_statefun-snapshot-py3-none-any.whl

COPY requirements.txt /app
RUN pip install -r requirements.txt

COPY greeter.py /app
COPY messages_pb2.py /app

EXPOSE 8000

CMD ["gunicorn", "-b", "0.0.0.0:8000", "-w 4", "greeter:app"]

Again, just a stop gap until the first release. This is why I have the warning that we do not publish snapshot versions of the python sdk.

@rmetzger
Copy link
Contributor

I think it would be very nice to have this for Java as well!

## Persistence
{% highlight python %}
@functions.bind("example/greeter")
def greet(context, message: GreetRequest):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def greet(context, message: GreetRequest):
def greet(context, greet_request: GreetRequest):

Because I get

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/greeter.py", line 72, in handle
    response_data = handler(request.data)
  File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 39, in __call__
    reply = self.handle_invocation(request)
  File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 54, in handle_invocation
    self.invoke_batch(batch, context, target_function)
  File "/usr/local/lib/python3.7/site-packages/statefun/request_reply.py", line 99, in invoke_batch
    fun(context, invocation.argument)
  File "/app/greeter.py", line 52, in greet
    response = compute_greeting(greet_request.name, state.seen)
NameError: name 'greet_request' is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

Copy link
Contributor

@rmetzger rmetzger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your work! It is a really nice step by step guide to interactively get a simple development environment for statefun.

Except for one potential issue, I'm +1 on merging this.

Let me know if you are happy with it, I can merge it for you.

@sjwiesman
Copy link
Contributor Author

Thanks for taking the time to review @rmetzger. I just squashed my commits and am happy for you to commit.

@rmetzger rmetzger merged commit f894eb7 into apache:master Mar 27, 2020
@tzulitai
Copy link
Contributor

Backporting to release-2.0 to be included in RC3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants