From 24e5b13adcda6e7330cb141d0b26a8b5704d19e3 Mon Sep 17 00:00:00 2001 From: Mike Eltsufin Date: Thu, 2 Apr 2020 11:56:45 -0400 Subject: [PATCH] Adds Readme to GCP sample app Also, fixing a bug in the default constructor of the invoker. Fixes: #478. --- .../adapter/gcloud/FunctionInvoker.java | 7 ++- .../function-sample-gcp/README.adoc | 49 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-function-samples/function-sample-gcp/README.adoc diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/src/main/java/org/springframework/cloud/function/adapter/gcloud/FunctionInvoker.java b/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/src/main/java/org/springframework/cloud/function/adapter/gcloud/FunctionInvoker.java index 9d2d087bf..2a6b2666e 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/src/main/java/org/springframework/cloud/function/adapter/gcloud/FunctionInvoker.java +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-gcp/src/main/java/org/springframework/cloud/function/adapter/gcloud/FunctionInvoker.java @@ -46,13 +46,18 @@ public class FunctionInvoker public FunctionInvoker() { super(); + init(); } public FunctionInvoker(Class configurationClass) { super(configurationClass); + init(); + } + + private void init() { System.setProperty("spring.http.converters.preferred-json-mapper", "gson"); Thread.currentThread() //TODO investigate if it is necessary - .setContextClassLoader(FunctionInvoker.class.getClassLoader()); + .setContextClassLoader(FunctionInvoker.class.getClassLoader()); initialize(null); } diff --git a/spring-cloud-function-samples/function-sample-gcp/README.adoc b/spring-cloud-function-samples/function-sample-gcp/README.adoc new file mode 100644 index 000000000..86da52659 --- /dev/null +++ b/spring-cloud-function-samples/function-sample-gcp/README.adoc @@ -0,0 +1,49 @@ +:branch: master + +=== Google Cloud Functions Sample Application + +===== Test locally + +Run the function: + +---- +mvn function:run +---- + +Invoke the HTTP function: + +---- +curl http://localhost:8080/ -d "hello" +---- + +===== Deploy to GCP + +As of March 2020, Google Cloud Functions for Java is in Alpha. +You can get on the https://docs.google.com/forms/d/e/1FAIpQLScC98jGi7CfG0n3UYlj7Xad8XScvZC8-BBOg7Pk3uSZx_2cdQ/viewform[whitelist] to try it out. + +Package the application. + +---- +mvn package +---- + +You should see the fat jar in the `deploy` directory. + +Make sure that you have the https://cloud.google.com/sdk/install[Cloud SDK CLI] installed. + +Run the following command from the project root to deploy. + +---- +gcloud alpha functions deploy function-sample-gcp \ +--entry-point org.springframework.cloud.function.adapter.gcloud.FunctionInvoker \ +--runtime java11 \ +--trigger-http \ +--source deploy \ +--memory 512MB +---- + +Invoke the HTTP function: + +---- +curl https://REGION-PROJECT_ID.cloudfunctions.net/function-sample-gcp -d "hello" +----