This project shows how to deploy a simple Java function to Pivotal Function Service (PFS).
Using PFS, you focus on your code, and you just deploy functions: the platform automatically optimizes resources usage, and takes care of packaging your functions to running containers.
This project contains the smallest possible Java function implementation,
using the plain JDK
Function
interface. There are no external dependencies required. No even a Dockerfile
!
public class Hello implements Function<String, String> {
public String apply(String name) {
final String n;
if (name == null || name.isEmpty()) {
n = "world";
} else {
n = name;
}
return "Hello " + n;
}
}
As soon as you push this code to PFS, the platform compiles source code and generates a JAR file, which is then turned into an OCI container image using the Cloud Native Buildpack project.
Publish this function to PFS using this command:
$ pfs function create hello \
--git-repo https://github.com/alexandreroman/pfs-hellofun.git \
--handler fr.alexandreroman.demos.hellofun.Hello \
--image $REGISTRY/$REGISTRY_USER/hello \
--verbose
Invoke the function using this command:
$ pfs service invoke hello --text -- -w '\n' -d 'PFS'
curl 104.155.125.168/ -H 'Host: hello.hello.example.com' -H 'Content-Type: text/plain' -w '\n' -d PFS
Hello PFS
You can also use this function with a pipe:
$ whoami | pfs service invoke hello --text -- -w '\n' -d @-
curl 104.155.125.168/ -H 'Host: hello.hello.example.com' -H 'Content-Type: text/plain' -w '\n' -d PFS
Hello <username>
Contributions are always welcome!
Feel free to open issues & send PR.
Copyright © 2018 Pivotal Software, Inc.
This project is licensed under the Apache Software License version 2.0.