From 8ee8215c9cc40bbe51ed5842049a20b0f4ba18ea Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 14 Mar 2019 16:04:46 +0100 Subject: [PATCH] Migrated docs to new styles --- README.adoc | 142 +++++++- docs/pom.xml | 341 +++++++++++++++--- .../main/asciidoc/adapters/aws-readme.adoc | 2 +- docs/src/main/asciidoc/adapters/aws.adoc | 4 +- .../main/asciidoc/adapters/azure-readme.adoc | 2 +- docs/src/main/asciidoc/adapters/azure.adoc | 4 +- .../asciidoc/adapters/openwhisk-readme.adoc | 2 +- .../src/main/asciidoc/adapters/openwhisk.adoc | 4 +- docs/src/main/asciidoc/index.adoc | 21 ++ .../main/asciidoc/spring-cloud-function.adoc | 13 +- .../README.adoc | 38 +- .../README.adoc | 69 +--- .../README.adoc | 87 +---- 13 files changed, 483 insertions(+), 246 deletions(-) create mode 100644 docs/src/main/asciidoc/index.adoc diff --git a/README.adoc b/README.adoc index 45bc6da76..eb77a51f9 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,8 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// image::https://travis-ci.org/spring-cloud/spring-cloud-function.svg?branch=master[Build Status, link=https://travis-ci.org/spring-cloud/spring-cloud-function] @@ -210,6 +214,8 @@ from the `file` menu. == Contributing +:spring-cloud-build-branch: master + Spring Cloud is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want @@ -253,4 +259,136 @@ added after the original pull request but before a merge. other target branch in the main project). * When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit - message (where XXXX is the issue number). \ No newline at end of file + message (where XXXX is the issue number). + +=== Checkstyle + +Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    └── checkstyle.xml <1> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules + +==== Checkstyle configuration + +Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. + +.pom.xml +---- + +true <1> + true + <2> + true + <3> + + + + + <4> + io.spring.javaformat + spring-javaformat-maven-plugin + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + +---- +<1> Fails the build upon Checkstyle errors +<2> Fails the build upon Checkstyle violations +<3> Checkstyle analyzes also the test sources +<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules +<5> Add checkstyle plugin to your build and reporting phases + +If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example: + +.projectRoot/src/checkstyle/checkstyle-suppresions.xml +---- + + + + + + +---- + +It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: + +```bash +$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig +$ touch .springformat +``` + +=== IDE setup + +==== Intellij IDEA + +In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    ├── checkstyle.xml <1> +    └── intellij +       ├── Intellij_Project_Defaults.xml <4> +       └── Intellij_Spring_Boot_Java_Conventions.xml <5> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules +<4> Project defaults for Intellij that apply most of Checkstyle rules +<5> Project style conventions for Intellij that apply most of Checkstyle rules + +.Code style + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. + +.Inspection profiles + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. + +.Checkstyle + +To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle] + +Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: + +- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. +- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. +- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. + +IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. \ No newline at end of file diff --git a/docs/pom.xml b/docs/pom.xml index cb271b75e..83ec1198b 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-function-docs @@ -13,92 +13,331 @@ Spring Cloud Function Docs Spring Cloud Function Docs - spring-cloud-function + index ${basedir}/.. - 1.0.x + 0.1.0.RELEASE + 0.1.0.RELEASE + + 1.5.0-alpha.16 + ${main.basedir}/spring-cloud-function-adapters - - - - - maven-deploy-plugin - 2.8.2 - - true - - - - docs - - ${main.basedir}/spring-cloud-function-adapters - - org.apache.maven.plugins maven-dependency-plugin + ${maven-dependency-plugin.version} false - - - org.asciidoctor - asciidoctor-maven-plugin - false - - - com.agilejava.docbkx - docbkx-maven-plugin + + + unpack-docs + generate-resources + + unpack + + + + + org.springframework.cloud + + spring-cloud-build-docs + + ${spring-cloud-build.version} + + sources + jar + false + ${docs.resources.dir} + + + + + + + unpack-docs-resources + generate-resources + + unpack + + + + + io.spring.docresources + spring-doc-resources + ${spring-doc-resources.version} + zip + true + ${project.build.directory}/refdocs/ + + + + + org.apache.maven.plugins - maven-antrun-plugin + maven-resources-plugin - adapters + copy-asciidoc-resources + generate-resources + + copy-resources + + + ${project.build.directory}/refdocs/ + + + src/main/asciidoc + false + + ghpages.sh + + + + + + + + + + org.asciidoctor + asciidoctor-maven-plugin + ${asciidoctor-maven-plugin.version} + false + + + io.spring.asciidoctor + spring-asciidoctor-extensions + ${spring-asciidoctor-extensions.version} + + + org.asciidoctor + asciidoctorj-pdf + ${asciidoctorj-pdf.version} + + + + ${project.build.directory}/refdocs/ + + ${project.version} + + + + + generate-html-documentation + prepare-package + + process-asciidoc + + + html5 + highlight.js + book + + // these attributes are required to use the doc resources + shared + css/ + spring.css + true + font + js/highlight + atom-one-dark-reasonable + true + + left + 4 + ${project.version} + true + + + + + generate-docbook + none + + process-asciidoc + + + + generate-index + none + + process-asciidoc + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + ${maven-antrun-plugin.version} + + + ant-contrib + ant-contrib + 1.0b3 + + + ant + ant + + + + + org.apache.ant + ant-nodeps + 1.8.1 + + + org.tigris.antelope + antelopetasks + 3.2.10 + + + org.jruby + jruby-complete + 1.7.17 + + + org.asciidoctor + asciidoctorj + 1.5.8 + + + + + readme process-resources run - + - - - + value="${docs.resources.dir}/ruby/generate_readme.sh" /> + + - + - + value="${docs.resources.dir}/ruby/generate_readme.sh" /> + + value="${adapters.path}/spring-cloud-function-adapter-aws/README.adoc" /> + value="${basedir}/src/main/asciidoc/adapters/aws-readme.adoc" /> - + - + value="${docs.resources.dir}/ruby/generate_readme.sh" /> + + value="${adapters.path}/spring-cloud-function-adapter-azure/README.adoc" /> + value="${basedir}/src/main/asciidoc/adapters/azure-readme.adoc" /> + + + + + + + + assert-no-unresolved-links + prepare-package + + run + + + + + + + + + + + + + + + + setup-maven-properties + validate + + run + + + true + + + + + + + + + + + + + + + + + + copy-css + none + + run + + + + generate-documentation-index + none + + run + + + + copy-generated-html + none + + run + + + + org.codehaus.mojo build-helper-maven-plugin diff --git a/docs/src/main/asciidoc/adapters/aws-readme.adoc b/docs/src/main/asciidoc/adapters/aws-readme.adoc index 39663c048..3fd724f7e 100644 --- a/docs/src/main/asciidoc/adapters/aws-readme.adoc +++ b/docs/src/main/asciidoc/adapters/aws-readme.adoc @@ -1,3 +1,3 @@ This project provides an adapter layer for a Spring Cloud Function application onto AWS Lambda. You can write an app with a single `@Bean` of type `Function`, `Consumer` or `Supplier` and it will be deployable in AWS if you get the JAR file laid out right. The best way to make it work is to include `spring-cloud-function-context` as a dependency, but not the higher level adapters (e.g. `spring-cloud-function-stream`). -include::aws-intro.adoc[] \ No newline at end of file +include::adapters/aws-intro.adoc[] \ No newline at end of file diff --git a/docs/src/main/asciidoc/adapters/aws.adoc b/docs/src/main/asciidoc/adapters/aws.adoc index 72c130080..eea1ae4f1 100644 --- a/docs/src/main/asciidoc/adapters/aws.adoc +++ b/docs/src/main/asciidoc/adapters/aws.adoc @@ -1,8 +1,10 @@ +*{spring-cloud-function-version}* + The https://aws.amazon.com/[AWS] adapter takes a Spring Cloud Function app and converts it to a form that can run in AWS Lambda. == Introduction -include::aws-intro.adoc[] +include::adapters/aws-intro.adoc[] == Functional Bean Definitions diff --git a/docs/src/main/asciidoc/adapters/azure-readme.adoc b/docs/src/main/asciidoc/adapters/azure-readme.adoc index 9a59baa8e..7f84acb5e 100644 --- a/docs/src/main/asciidoc/adapters/azure-readme.adoc +++ b/docs/src/main/asciidoc/adapters/azure-readme.adoc @@ -1,7 +1,7 @@ This project provides an adapter layer for a Spring Cloud Function application onto Azure. You can write an app with a single `@Bean` of type `Function` and it will be deployable in Azure if you get the JAR file laid out right. -include::azure-intro.adoc[] +include::adapters/azure-intro.adoc[] == Sample Function diff --git a/docs/src/main/asciidoc/adapters/azure.adoc b/docs/src/main/asciidoc/adapters/azure.adoc index d228403c7..580bd3591 100644 --- a/docs/src/main/asciidoc/adapters/azure.adoc +++ b/docs/src/main/asciidoc/adapters/azure.adoc @@ -1,3 +1,5 @@ +*{spring-cloud-function-version}* + The https://azure.microsoft.com[Azure] adapter bootstraps a Spring Cloud Function context and channels function calls from the Azure framework into the user functions, using Spring Boot configuration where necessary. Azure Functions has quite a unique, but invasive programming model, involving annotations in user code that are specific to the platform. The easiest way to use it with Spring Cloud is to extend a base class and write a method in it with the `@FunctionName` annotation which delegates to a base class method. -include::azure-intro.adoc[] \ No newline at end of file +include::adapters/azure-intro.adoc[] \ No newline at end of file diff --git a/docs/src/main/asciidoc/adapters/openwhisk-readme.adoc b/docs/src/main/asciidoc/adapters/openwhisk-readme.adoc index 80ad76979..1fcbcaaa6 100644 --- a/docs/src/main/asciidoc/adapters/openwhisk-readme.adoc +++ b/docs/src/main/asciidoc/adapters/openwhisk-readme.adoc @@ -1,6 +1,6 @@ == Quick Start -include::openwhisk-quick-start.adoc[] +include::adapters/openwhisk-quick-start.adoc[] == Examples diff --git a/docs/src/main/asciidoc/adapters/openwhisk.adoc b/docs/src/main/asciidoc/adapters/openwhisk.adoc index 1e7d071cf..010caeef8 100644 --- a/docs/src/main/asciidoc/adapters/openwhisk.adoc +++ b/docs/src/main/asciidoc/adapters/openwhisk.adoc @@ -1,4 +1,6 @@ +*{spring-cloud-function-version}* + The https://openwhisk.apache.org/[OpenWhisk] adapter is in the form of an executable jar that can be used in a a docker image to be deployed to Openwhisk. The platform works in request-response mode, listening on port 8080 on a specific endpoint, so the adapter is a simple Spring MVC application. == Quick Start -include::openwhisk-quick-start.adoc[] +include::adapters/openwhisk-quick-start.adoc[] diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc new file mode 100644 index 000000000..a510cf8d0 --- /dev/null +++ b/docs/src/main/asciidoc/index.adoc @@ -0,0 +1,21 @@ += Spring Cloud Function Reference Documentation +Mark Fisher, Dave Syer, Oleg Zhurakousky + +*{spring-cloud-function-version}* + +:docinfo: shared + +The reference documentation consists of the following sections: + +[horizontal] +<> :: Spring Cloud Function Reference +<> :: AWS Adapter Reference +<> :: Azure Adapter Reference +<> :: Apache OpenWhisk Adapter Reference + + +Relevant Links: + +[horizontal] +https://projectreactor.io/[Reactor] :: Project Reactor +https://projectriff.io/[riff] :: Project riff diff --git a/docs/src/main/asciidoc/spring-cloud-function.adoc b/docs/src/main/asciidoc/spring-cloud-function.adoc index 62270db68..d4986ff02 100644 --- a/docs/src/main/asciidoc/spring-cloud-function.adoc +++ b/docs/src/main/asciidoc/spring-cloud-function.adoc @@ -2,6 +2,8 @@ Mark Fisher, Dave Syer, Oleg Zhurakousky +*{spring-cloud-function-version}* + --- :github: https://github.com/spring-cloud/spring-cloud-function @@ -267,14 +269,3 @@ https://projectriff.io[Riff] supports Java functions and its https://github.com/projectriff/java-function-invoker[Java Function Invoker] acts natively is an adapter for Spring Cloud Function jars. -=== AWS Lambda - -include::adapters/aws.adoc[leveloffset=+2] - -=== Azure Functions - -include::adapters/azure.adoc[leveloffset=+2] - -=== Apache Openwhisk - -include::adapters/openwhisk.adoc[leveloffset=+2] diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc index d0071ffab..ebe03bb3e 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc @@ -1,35 +1,9 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// This project provides an adapter layer for a Spring Cloud Function application onto AWS Lambda. You can write an app with a single `@Bean` of type `Function`, `Consumer` or `Supplier` and it will be deployable in AWS if you get the JAR file laid out right. The best way to make it work is to include `spring-cloud-function-context` as a dependency, but not the higher level adapters (e.g. `spring-cloud-function-stream`). -The adapter has a couple of generic request handlers that you can use. The most generic is `SpringBootStreamHandler`, which uses a Jackson `ObjectMapper` provided by Spring Boot to serialize and deserialize the objects in the function. There is also a `SpringBootRequestHandler` which you can extend, and provide the input and output types as type parameters (enabling AWS to inspect the class and do the JSON conversions itself). - -If your app has more than one `@Bean` of type `Function` etc. then you can choose the one to use by configuring `function.name` (e.g. as `FUNCTION_NAME` environment variable in AWS). The functions are extracted from the Spring Cloud `FunctionCatalog` (searching first for `Function` then `Consumer` and finally `Supplier`). - -== Notes on JAR Layout - -You don't need the Spring Cloud Function Web or Stream adapter at runtime in Lambda, so you might need to exclude those before you create the JAR you send to AWS. A Lambda application has to be shaded, but a Spring Boot standalone application does not, so you can run the same app using 2 separate jars (as per the sample). The sample app creates 2 jar files, one with an `aws` classifier for deploying in Lambda, and one executable (thin) jar that includes `spring-cloud-function-web` at runtime. Spring Cloud Function will try and locate a "main class" for you from the JAR file manifest, using the `Start-Class` attribute (which will be added for you by the Spring Boot tooling if you use the starter parent). If there is no `Start-Class` in your manifest you can use an environment variable `MAIN_CLASS` when you deploy the function to AWS. - -== Upload - -Build the sample under `spring-cloud-function-samples/function-sample-aws` and upload the `-aws` jar file to Lambda. The handler can be `example.Handler` or `org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler` (FQN of the class, _not_ a method reference, although Lambda does accept method references). - ----- -./mvnw -U clean package ----- - -Using the AWS command line tools it looks like this: - ----- -aws lambda create-function --function-name Uppercase --role arn:aws:iam::[USERID]:role/service-role/[ROLE] --zip-file fileb://function-sample-aws/target/function-sample-aws-2.0.0.BUILD-SNAPSHOT-aws.jar --handler org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler --description "Spring Cloud Function Adapter Example" --runtime java8 --region us-east-1 --timeout 30 --memory-size 1024 --publish ----- - -The input type for the function in the AWS sample is a Foo with a single property called "value". So you would need this to test it: - ----- -{ - "value": "test" -} ----- - -NOTE: The AWS sample app is written in the "functional" style (as an `ApplicationContextInitializer`). This is much faster on startup in Lambda than the traditional `@Bean` style, so if you don't need `@Beans` (or `@EnableAutoConfiguration`) it's a good choice. Warm starts are not affected. \ No newline at end of file +Unresolved directive in aws-readme.adoc - include::adapters/aws-intro.adoc[] \ No newline at end of file diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc index bb0562ae9..60fa79aca 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/README.adoc @@ -1,70 +1,13 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// This project provides an adapter layer for a Spring Cloud Function application onto Azure. You can write an app with a single `@Bean` of type `Function` and it will be deployable in Azure if you get the JAR file laid out right. -This project provides an adapter layer for a Spring Cloud Function application onto Azure. -You can write an app with a single `@Bean` of type `Function` and it will be deployable in Azure if you get the JAR file laid out right. - -There is an `AzureSpringBootRequestHandler` which you must extend, and provide the input and output types as annotated method parameters (enabling Azure to inspect the class and create JSON bindings). The base class has two useful methods (`handleRequest` and `handleOutput`) to which you can delegate the actual function call, so mostly the function will only ever have one line. - -Example: - -```java -public class FooHandler extends AzureSpringBootRequestHandler { - @FunctionName("uppercase") - public Bar execute( - @HttpTrigger(name = "req", methods = { HttpMethod.GET, - HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) - Foo foo, - ExecutionContext context) { - return handleRequest(foo, context); - } -} -``` - -This Azure handler will delegate to a `Function` bean (or a `Function,Publisher>`). Some Azure triggers (e.g. `@CosmosDBTrigger`) result in a input type of `List` and in that case you can bind to `List` in the Azure handler, or `String` (the raw JSON). The `List` input delegates to a `Function` with input type `Map`, or `Publisher` or `List` of the same type. The output of the `Function` can be a `List` (one-for-one) or a single value (aggregation), and the output binding in the Azure declaration should match. - -If your app has more than one `@Bean` of type `Function` etc. then you can choose the one to use by configuring `function.name`. Or if you make the `@FunctionName` in the Azure handler method match the function name it should work that way (also for function apps with multiple functions). The functions are extracted from the Spring Cloud `FunctionCatalog` so the default function names are the same as the bean names. - -=== Notes on JAR Layout - -You don't need the Spring Cloud Function Web at runtime in Azure, so you can exclude this before you create the JAR you deploy to Azure, but it won't be used if you include it so it doesn't hurt to leave it in. A function application on Azure is an archive generated by the Maven plugin. The function lives in the JAR file generated by this project. The sample creates it as an executable jar, using the thin layout, so that Azure can find the handler classes. If you prefer you can just use a regular flat JAR file. The dependencies should *not* be included. - -== Build - ----- -./mvnw -U clean package ----- - -== Running the sample - -You can run the sample locally, just like the other Spring Cloud Function samples: - ---- -./mvnw spring-boot:run ---- - -and `curl -H "Content-Type: text/plain" localhost:8080/function -d '{"value": "hello foobar"}'`. - -You will need the `az` CLI app (see https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven for more detail). To deploy the function on Azure runtime: - ----- -$ az login -$ mvn azure-functions:deploy ----- - -On another terminal try this: `curl https:///api/uppercase -d '{"value": "hello foobar!"}'`. Please ensure that you use the right URL for the function above. Alternatively you can test the function in the Azure Dashboard UI (click on the function name, go to the right hand side and click "Test" and to the bottom right, "Run"). - -The input type for the function in the Azure sample is a Foo with a single property called "value". So you need this to test it with something like below: - ----- -{ - "value": "foobar" -} ----- - -NOTE: The Azure sample app is written in the "non-functional" style (using `@Bean`). The functional style (with just `Function` or `ApplicationContextInitializer`) is much faster on startup in Azure than the traditional `@Bean` style, so if you don't need `@Beans` (or `@EnableAutoConfiguration`) it's a good choice. Warm starts are not affected. +Unresolved directive in azure-readme.adoc - include::adapters/azure-intro.adoc[] == Sample Function diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/README.adoc b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/README.adoc index 03fe38d75..453544785 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/README.adoc +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/README.adoc @@ -1,87 +1,12 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// == Quick Start -Implement a POF (be sure to use the `functions` package): - -``` -package functions; - -import java.util.function.Function; - -public class Uppercase implements Function { - - public String apply(String input) { - return input.toUpperCase(); - } -} -``` - -Install it into your local Maven repository: - -``` -./mvnw clean install -``` - -Create a `function.properties` file that provides its Maven coordinates. For example: - -``` -dependencies.function: com.example:pof:0.0.1-SNAPSHOT -``` - -Copy the openwhisk runner JAR to the working directory (same directory as the properties file): - -``` -cp spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/target/spring-cloud-function-adapter-openwhisk-2.0.0.BUILD-SNAPSHOT.jar runner.jar -``` - -Generate a m2 repo from the `--thin.dryrun` of the runner JAR with the above properties file: - -``` -java -jar -Dthin.root=m2 runner.jar --thin.name=function --thin.dryrun -``` - -Use the following Dockerfile: - -``` -FROM openjdk:8-jdk-alpine -VOLUME /tmp -COPY m2 /m2 -ADD runner.jar . -ADD function.properties . -ENV JAVA_OPTS="" -ENTRYPOINT [ "java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "runner.jar", "--thin.root=/m2", "--thin.name=function", "--function.name=uppercase"] -EXPOSE 8080 -``` - -> NOTE: you could use a Spring Cloud Function app, instead of just a jar with a POF in it, in which case you would have to change the way the app runs in the container so that it picks up the main class as a source file. For example, you could change the `ENTRYPOINT` above and add `--spring.main.sources=com.example.SampleApplication`. - -Build the Docker image: - -``` -docker build -t [username/appname] . -``` - -Push the Docker image: - -``` -docker push [username/appname] -``` - -Use the OpenWhisk CLI (e.g. after `vagrant ssh`) to create the action: - -``` -wsk action create example --docker [username/appname] -``` - -Invoke the action: - -``` -wsk action invoke example --result --param payload foo -{ - "result": "FOO" -} -``` +Unresolved directive in openwhisk-readme.adoc - include::adapters/openwhisk-quick-start.adoc[] == Examples