Skip to content

Commit

Permalink
funktionio#112 groovy example for funktion
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Nov 7, 2016
1 parent 31d72cb commit 603fc9f
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 1 deletion.
118 changes: 118 additions & 0 deletions examples/example-groovy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!--
~ Copyright 2016 Red Hat, Inc.
~ <p>
~ Red Hat 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
~ <p>
~ http://www.apache.org/licenses/LICENSE-2.0
~ <p>
~ 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>io.fabric8.funktion.examples</groupId>
<artifactId>examples</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>example-groovy</artifactId>
<packaging>jar</packaging>

<name>Example Groovy</name>
<description>Funktion :: Examples :: Groovy</description>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>io.fabric8.funktion</groupId>
<artifactId>funktion-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>k8s</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<configuration>
<enricher>
<config>
<fmp-service>
<type>LoadBalancer</type>
</fmp-service>
</config>
</enricher>
</configuration>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016 Red Hat, Inc.
* <p>
* Red Hat 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 io.fabric8.funktion.example

import org.apache.camel.Header

/**
* A plain java class which implements the funktion
*/
class Main {

/**
* The method used as funktion
*
* @param body the message body
* @param name the header with the key name
* @return the response from the funktion
*/
Object beer(String body, @Header("name") String name) {
return "Hello " + name + ". I got payload `" + body + "` and I am on host: " + System.getenv("HOSTNAME");
}

}
5 changes: 5 additions & 0 deletions examples/example-groovy/src/main/resources/funktion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rules:
- trigger: http
name: dude
action: io.fabric8.funktion.example.Main::beer
trace: false
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@

<modules>
<module>example-java</module>
<module>example-groovy</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<module>parent</module>
<module>funktion-model</module>
<module>funktion-runtime</module>
<module>examples</module>
<module>starter-parent</module>
<module>examples</module>
</modules>

<build>
Expand Down

0 comments on commit 603fc9f

Please sign in to comment.