Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Maven/Java Tooling #113

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ openwhisk-master*
.idea
.vscode
**/.sts4-cache
target/
.project
.settings/
bin/
.classpath
.DS_Store
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ env:
- DOCKER_COMPOSE_VERSION: 1.13.0
matrix:
- TOOL: docker-compose
- TOOL: java-action-archetype
- TOOL: java-maven/parent
- TOOL: java-maven/annotations
- TOOL: java-maven/update-maven-plugin
- TOOL: java-maven/action-archetype

services:
- docker
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ This repository is part of [Apache OpenWhisk](http://openwhisk.incubator.apache.

* [docker-compose](docker-compose/README.md) allows testing OpenWhisk locally, using Docker Compose. This is ideal if you are contributing to core development
* [node-local](node-local/README.md) allows testing individual OpenWhisk functions locally, using only node.js. This is ideal if you are writing node.js functions to run in OpenWhisk, but need to emulate some of OpenWhisk's behavior in creating `params` and expecting promises.
* [maven-java](maven-java/README.md) allows testing OpenWhisk Java Actions. This shows how to package the function dependencies e.g. external jar.
* *java-maven* tooling to support building / deploying Java actions in OpenWhisk
* [action-archetype](java-maven/action-archetype) Archetype for creating a Java Action project using Apache Maven
* [annotations](java-maven/annotations) Java annotations to indicate OpenWhisk Actions, Packages, Rules and Triggers
* [parent](java-maven/parent) provides a baseline Maven configuration for Maven-based OpenWhisk sub-projects
* [update-maven-plugin](java-maven/update-maven-plugin) Apache Maven plugin to read the [annotations](java-maven/annotations) and automatically deploying the Actions, Packages, Rules and Trigger to OpenWhisk
* [maven-java-examplea](maven-java-example/README.md) shows how to package the function dependencies e.g. external jar.
* [java-local](java-local) allows testing OpenWhisk Java Actions

## Travis builds

Expand Down
21 changes: 21 additions & 0 deletions java-maven/action-archetype/.travis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -x -e
uname -sm

SCRIPTDIR=$(cd $(dirname "$0") && pwd)
TOOLDIR="$SCRIPTDIR/../"

# Build the parent so this compiles
mkdir -p $TOOLDIR/target
cd $TOOLDIR/target
git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git
cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent
mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install
cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/annotations
mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install
cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/update-maven-plugin
mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install

cd $TOOLDIR

mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Maven Archetype for Java Action

This module is part of the [Apache OpenWhisk](http://openwhisk.incubator.apache.org/) project.

This archetype helps to generate the Java Action template project.

## Pre-requisite

The following softwares are required to build and deploy a Java Action to OpenWhisk:

* (Maven v3.3.x)[https://maven.apache.org] or above
* [Maven v3.3.x](https://maven.apache.org) or above
* Java 8 or above

[WSK CLI](https://github.com/apache/incubator-openwhisk/blob/master/docs/cli.md) is configured
Expand All @@ -29,11 +31,10 @@ The following step shows how to deploy the function to OpenWhisk
```sh
cd demo-function
mvn clean install
wsk action create demo target/demo-function.jar --main com.example.FunctionApp
```

After successful deployment of the function, we can invoke the same via `wsk action invoke demo --result` to see the response as:

```json
{"greetings": "Hello! Welcome to OpenWhisk" }
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.openwhisk.java</groupId>
<artifactId>java-action-archetype</artifactId>
<version>1.0-SNAPSHOT</version>

<!--<parent>
<groupId>org.apache.openwhisk</groupId>
<artifactId>openwhisk</artifactId>
<packaging>pom</packaging>
<version>1-SNAPSHOT</version>
</parent> -->

<groupId>org.apache.openwhisk</groupId>
<artifactId>openwhisk-action-archetype</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>OpenWhisk:: Maven Archetype - Java Action</name>
<url>http://openwhisk.apache.org</url>
<name>Apache OpenWhisk - Java Action Maven Archetype</name>

<build>
<extensions>
<extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.openwhisk</groupId>
<artifactId>openwhisk-annotations</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -42,6 +47,21 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.openwhisk</groupId>
<artifactId>openwhisk-update-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<configuration>
<main>$groupId.FunctionApp</main>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/

import com.google.gson.JsonObject;
import org.apache.openwhisk.annotations.Action;

/**
* Hello FunctionApp
*/
@Action(name="demo")
public class FunctionApp {
public static JsonObject main(JsonObject args) {
JsonObject response = new JsonObject();
Expand Down
10 changes: 10 additions & 0 deletions java-maven/annotations/.travis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

SCRIPTDIR=$(cd $(dirname "$0") && pwd)
TOOLDIR="$SCRIPTDIR/../"

cd $TOOLDIR

mvn -V test

#TODO steps that can push this artifact to nexus
17 changes: 17 additions & 0 deletions java-maven/annotations/.travis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -x -e
uname -sm

SCRIPTDIR=$(cd $(dirname "$0") && pwd)
TOOLDIR="$SCRIPTDIR/../"

# Build the parent so this compiles
mkdir -p $TOOLDIR/target
cd $TOOLDIR/target
git clone https://github.com/klcodanr/incubator-openwhisk-devtools.git
cd $TOOLDIR/target/incubator-openwhisk-devtools/java-maven/parent
mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install

cd $TOOLDIR

mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install
68 changes: 68 additions & 0 deletions java-maven/annotations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# OpenWhisk Annotations for Java

This module is part of the [Apache OpenWhisk](http://openwhisk.incubator.apache.org/) project.

This project allows developers to define actions, packages, rules and triggers from annotations on java classes.

## Pre-requisite

The following softwares are required to use this project:

* [Maven v3.3.x](https://maven.apache.org) or above
* Java 8 or above
* OpenWhisk CLI
* [openwhisk-update-maven-plugin](../update-maven-plugin/)

## Adding the Annotations

All of the annotations are added at the class level. You can define more than one annotation per class.

### Action Annotation

The `@Action` annotation defines an OpenWhisk [action](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md):

```
@Action(name = "simple-function", packageName = "test", parameters = { @Parameter(key = "Name", value = "Bob") })
public class FunctionApp {
```



### ActionSequence Annotation

The `@ActionSequence` annotation defines an OpenWhisk [action](https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md) sequence:

```
@Action(name = "simple-function", packageName = "test", parameters = { @Parameter(key = "Name", value = "Bob") })
public class FunctionApp {
```

### Package Annotation

The `@Package` annotation defines an OpenWhisk [package](https://github.com/apache/incubator-openwhisk/blob/master/docs/packages.md):

```
@Package(name = "test")
public class FunctionApp {
```

Our recommendation would be to add this to a package-info.java class for the package containing the actions / code for a particular package.

### Rule Annotation

The `@Rule` annotation defines an OpenWhisk [rule](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md):

```
@Rule(actionName="test/simple-function", name = "dostuffrule", triggerName="dostuff")
public class FunctionApp {
```


### Trigger Annotation

The `@Trigger` annotation defines an OpenWhisk [trigger](https://github.com/apache/incubator-openwhisk/blob/master/docs/triggers_rules.md):

```
@Trigger(feed = "/whisk.system/alarms/alarm", name = "dostuff", parameters = { @Parameter(key = "cron", value = "5 * * * *")})
public class FunctionApp {
```
39 changes: 39 additions & 0 deletions java-maven/annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or
more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding
copyright ownership. The ASF licenses this file to you under the
Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain
a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions
and limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.openwhisk</groupId>
<artifactId>openwhisk</artifactId>
<version>1-SNAPSHOT</version>
<relativePath />
</parent>

<artifactId>openwhisk-annotations</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Apache OpenWhisk Annotations</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openwhisk.annotations;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* An annotation to indicate that the specified class should register an OpenWhisk action.
*
* @see https://github.com/apache/incubator-openwhisk/blob/master/docs/actions.md
*/
@Retention(RUNTIME)
@Target(TYPE)
public @interface Action {

/**
* The annotation values for the action
*/
Annotation[] annotations() default {};

/**
* The maximum log size LIMIT in MB for the action (default 10)
*/
int logsize() default -1;

/**
* the maximum memory LIMIT in MB for the action (default 256)
*/
int memory() default -1;

/**
* The name of the action
*/
String name();

/**
* The name of the package for this action
*/
String packageName() default "";

/**
* The parameter values for the action
*/
Parameter[] parameters() default {};

/**
* The timeout LIMIT in milliseconds after which the action is terminated
* (default 60000)
*/
int timeout() default -1;

/**
* Treat ACTION as a web action, a raw HTTP web action, or as a standard action;
* yes | true = web action, raw = raw HTTP web action, no | false = standard
* action
*/
String web() default "";

/**
* Secure the web action. where SECRET is true, false, or any string. Only valid
* when the ACTION is a web action
*/
String websecure() default "";
}
Loading