From 4340417ff7add2857ea711022fd85fa987e12fed Mon Sep 17 00:00:00 2001 From: wanjunlei Date: Wed, 14 Jun 2023 14:22:27 +0800 Subject: [PATCH] release 1.2.0 Signed-off-by: wanjunlei --- CHANGLOG.md | 6 ++ README.md | 4 +- .../invoker/context/RuntimeContext.java | 2 +- .../samples/hooks/ExampleHook.java | 8 +- .../samples/plugins/ExamplePlugin.java | 88 ------------------- .../resources/function/binding-function.yaml | 23 +++-- .../function/cloudevent-function.yaml | 15 ++-- .../resources/function/http-function.yaml | 15 ++-- .../resources/function/http-with-output.yaml | 19 ++-- .../function/subcreibe-function.yaml | 37 ++++---- 10 files changed, 62 insertions(+), 155 deletions(-) delete mode 100644 samples/src/main/java/dev/openfunction/samples/plugins/ExamplePlugin.java diff --git a/CHANGLOG.md b/CHANGLOG.md index d937173c..8abceb2c 100644 --- a/CHANGLOG.md +++ b/CHANGLOG.md @@ -1,3 +1,9 @@ +## 1.2.0 / 2023-06-14 + +### Features + +- Add support for OpenFunction v1beta2 API [#15](https://github.com/OpenFunction/functions-framework-java/pull/15). + ## 1.1.0 / 2023-06-01 ### Features diff --git a/README.md b/README.md index a09176ca..f5d53aa5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ that supports Maven to create the Maven project. Add this dependency in the dev.openfunction.functions functions-framework-api - 1.0.0 + 1.2.0 ``` @@ -23,7 +23,7 @@ Framework dependency in your `build.gradle` project file as follows: ```groovy dependencies { - implementation 'dev.openfunction.functions:functions-framework-api:1.0.0' + implementation 'dev.openfunction.functions:functions-framework-api:1.2.0' } ``` diff --git a/functions-framework-invoker/src/main/java/dev/openfunction/invoker/context/RuntimeContext.java b/functions-framework-invoker/src/main/java/dev/openfunction/invoker/context/RuntimeContext.java index 8a0cec8d..d116426c 100644 --- a/functions-framework-invoker/src/main/java/dev/openfunction/invoker/context/RuntimeContext.java +++ b/functions-framework-invoker/src/main/java/dev/openfunction/invoker/context/RuntimeContext.java @@ -187,7 +187,7 @@ public boolean hasDaprTrigger() { return true; } - return functionContext.getTriggers() != null && ArrayUtils.isEmpty(functionContext.getTriggers().getDapr()); + return functionContext.getTriggers() != null && ArrayUtils.isNotEmpty(functionContext.getTriggers().getDapr()); } public Map getDaprTrigger() { diff --git a/samples/src/main/java/dev/openfunction/samples/hooks/ExampleHook.java b/samples/src/main/java/dev/openfunction/samples/hooks/ExampleHook.java index 15e06013..9bfa6058 100644 --- a/samples/src/main/java/dev/openfunction/samples/hooks/ExampleHook.java +++ b/samples/src/main/java/dev/openfunction/samples/hooks/ExampleHook.java @@ -45,14 +45,14 @@ public Hook init() { public Error execute(Context ctx) { String ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.XXX").format(new Date()); if (ctx.getBindingEvent() != null) { - System.out.printf("hook %s:%s exec for binding %s at %s, seq %d, function %s", name(), version(), ctx.getBindingEvent().getName(), ts, seq, ctx.getName()).println(); + System.out.printf("hook %s:%s exec for binding %s at %s, seq %d", name(), version(), ctx.getBindingEvent().getName(), ts, seq).println(); } else if (ctx.getTopicEvent() != null) { - System.out.printf("hook %s:%s exec for pubsub %s at %s, seq %d, function %s", name(), version(), ctx.getTopicEvent().getName(), ts, seq, ctx.getName()).println(); + System.out.printf("hook %s:%s exec for pubsub %s at %s, seq %d", name(), version(), ctx.getTopicEvent().getName(), ts, seq).println(); } else if (ctx.getHttpRequest() != null) { if (ctx.getCloudEvent() != null) { - System.out.printf("hook %s:%s exec for cloudevent function %s at %s, seq %d", name(), version(), ctx.getName(), ts, seq).println(); + System.out.printf("hook %s:%s exec for cloudevent function at %s, seq %d", name(), version(), ts, seq).println(); } else { - System.out.printf("hook %s:%s exec for http function %s at %s, seq %d", name(), version(), ctx.getName(), ts, seq).println(); + System.out.printf("hook %s:%s exec for http function at %s, seq %d", name(), version(), ts, seq).println(); } } else { System.out.println("unknown function type"); diff --git a/samples/src/main/java/dev/openfunction/samples/plugins/ExamplePlugin.java b/samples/src/main/java/dev/openfunction/samples/plugins/ExamplePlugin.java deleted file mode 100644 index d69b097a..00000000 --- a/samples/src/main/java/dev/openfunction/samples/plugins/ExamplePlugin.java +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright 2022 The OpenFunction Authors. - -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 dev.openfunction.samples.plugins; - -import dev.openfunction.functions.Context; -import dev.openfunction.functions.Plugin; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Map; - -public class ExamplePlugin implements Plugin { - private int seq = 0; - - @Override - public String name() { - return "plugin-example"; - } - - @Override - public String version() { - return "v1.0.0"; - } - - @Override - public Plugin init() { - return this; - } - - @Override - public Error execPreHook(Context ctx) { - execHook(ctx, "pre"); - return null; - } - - @Override - public Error execPostHook(Context ctx) { - execHook(ctx, "post"); - return null; - } - - private void execHook(Context ctx, String type) { - String ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.XXX").format(new Date()); - if (ctx.getBindingEvent() != null) { - System.out.printf("%s plugin %s:%s exec for binding %s at %s, seq %d, function %s", type, name(), version(), ctx.getBindingEvent().getName(), ts, seq, ctx.getName()).println(); - } else if (ctx.getTopicEvent() != null) { - System.out.printf("%s plugin %s:%s exec for pubsub %s at %s, seq %d, function %s", type, name(), version(), ctx.getTopicEvent().getName(), ts, seq, ctx.getName()).println(); - } else if (ctx.getHttpRequest() != null) { - if (ctx.getCloudEvent() != null) { - System.out.printf("%s plugin %s:%s exec for cloudevent function %s at %s, seq %d", type, name(), version(), ctx.getName(), ts, seq).println(); - } else { - System.out.printf("%s plugin %s:%s exec for http function %s at %s, seq %d", type, name(), version(), ctx.getName(), ts, seq).println(); - } - } else { - System.out.println("unknown function type"); - } - seq++; - } - - @Override - public Object getField(String fieldName) { - return null; - } - - @Override - public Boolean needToTracing() { - return true; - } - - @Override - public Map tagsAddToTracing() { - return null; - } -} diff --git a/samples/src/main/resources/function/binding-function.yaml b/samples/src/main/resources/function/binding-function.yaml index 8e8ca370..68575e5a 100644 --- a/samples/src/main/resources/function/binding-function.yaml +++ b/samples/src/main/resources/function/binding-function.yaml @@ -2,12 +2,6 @@ apiVersion: core.openfunction.io/v1beta1 kind: Function metadata: name: cron-input-kafka-output - annotations: - plugins: | - pre: - - dev.openfunction.samples.plugins.ExamplePlugin - post: - - dev.openfunction.samples.plugins.ExamplePlugin spec: version: "v2.0.0" image: openfunctiondev/cron-input-kafka-output-java:v1 @@ -27,13 +21,9 @@ spec: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "async" - inputs: - - name: cron - component: cron outputs: - - name: sample - component: kafka-server + - name: kafka-server + type: bindings.kafka operation: "create" bindings: cron: @@ -56,3 +46,12 @@ spec: value: "sample-topic" - name: authRequired value: "false" + triggers: + dapr: + - name: cron + type: bindings.cron + hooks: + post: + - dev.openfunction.samples.hooks.ExampleHook + pre: + - dev.openfunction.samples.hooks.ExampleHook \ No newline at end of file diff --git a/samples/src/main/resources/function/cloudevent-function.yaml b/samples/src/main/resources/function/cloudevent-function.yaml index 39d829e9..79443956 100644 --- a/samples/src/main/resources/function/cloudevent-function.yaml +++ b/samples/src/main/resources/function/cloudevent-function.yaml @@ -1,19 +1,12 @@ -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-cloudevent - annotations: - plugins: | - pre: - - dev.openfunction.samples.plugins.ExamplePlugin - post: - - dev.openfunction.samples.plugins.ExamplePlugin spec: version: "v2.0.0" image: "openfunctiondev/function-cloudevent-java:v1" imageCredentials: name: push-secret - port: 8080 # default to 8080 build: builder: openfunctiondev/builder-java:v2-18 env: @@ -28,4 +21,8 @@ spec: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "knative" + hooks: + post: + - dev.openfunction.samples.hooks.ExampleHook + pre: + - dev.openfunction.samples.hooks.ExampleHook \ No newline at end of file diff --git a/samples/src/main/resources/function/http-function.yaml b/samples/src/main/resources/function/http-function.yaml index 74180cfc..81751431 100644 --- a/samples/src/main/resources/function/http-function.yaml +++ b/samples/src/main/resources/function/http-function.yaml @@ -1,19 +1,12 @@ -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample - annotations: - plugins: | - pre: - - dev.openfunction.samples.plugins.ExamplePlugin - post: - - dev.openfunction.samples.plugins.ExamplePlugin spec: version: "v2.0.0" image: "openfunctiondev/sample-go-func-java:v1" imageCredentials: name: push-secret - port: 8080 # default to 8080 build: builder: openfunctiondev/builder-java:v2-17 env: @@ -28,4 +21,8 @@ spec: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "knative" + hooks: + post: + - dev.openfunction.samples.hooks.ExampleHook + pre: + - dev.openfunction.samples.hooks.ExampleHook \ No newline at end of file diff --git a/samples/src/main/resources/function/http-with-output.yaml b/samples/src/main/resources/function/http-with-output.yaml index ac2da21d..252582dd 100644 --- a/samples/src/main/resources/function/http-with-output.yaml +++ b/samples/src/main/resources/function/http-with-output.yaml @@ -1,19 +1,12 @@ -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: http-with-output - annotations: - plugins: | - pre: - - dev.openfunction.samples.plugins.ExamplePlugin - post: - - dev.openfunction.samples.plugins.ExamplePlugin spec: version: "v2.0.0" image: "openfunctiondev/http-with-output-java:v1" imageCredentials: name: push-secret - port: 8080 # default to 8080 build: builder: openfunctiondev/builder-java:v2-17 env: @@ -28,10 +21,9 @@ spec: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "knative" outputs: - - name: sample - component: kafka-server + - name: kafka-server + type: bindings.kafka operation: "create" bindings: kafka-server: @@ -48,3 +40,8 @@ spec: value: "sample-topic" - name: authRequired value: "false" + hooks: + post: + - dev.openfunction.samples.hooks.ExampleHook + pre: + - dev.openfunction.samples.hooks.ExampleHook \ No newline at end of file diff --git a/samples/src/main/resources/function/subcreibe-function.yaml b/samples/src/main/resources/function/subcreibe-function.yaml index 954b34d8..0bb808bf 100644 --- a/samples/src/main/resources/function/subcreibe-function.yaml +++ b/samples/src/main/resources/function/subcreibe-function.yaml @@ -1,12 +1,6 @@ -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: - annotations: - plugins: | - pre: - - dev.openfunction.samples.plugins.ExamplePlugin - post: - - dev.openfunction.samples.plugins.ExamplePlugin name: autoscaling-subscriber spec: version: "v2.0.0" @@ -25,9 +19,15 @@ spec: sourceSubPath: "samples" revision: "java" serving: - runtime: "async" scaleOptions: keda: + triggers: + - type: kafka + metadata: + topic: "sample-topic" + bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 + consumerGroup: autoscaling-subscriber + lagThreshold: "20" scaledObject: pollingInterval: 15 minReplicaCount: 0 @@ -44,21 +44,10 @@ spec: periodSeconds: 15 scaleUp: stabilizationWindowSeconds: 0 - triggers: - - type: kafka - metadata: - topic: "sample-topic" - bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: autoscaling-subscriber - lagThreshold: "20" template: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - inputs: - - name: producer - component: kafka-server - topic: "sample-topic" pubsub: kafka-server: type: pubsub.kafka @@ -72,3 +61,13 @@ spec: value: "sample-topic" - name: consumerID value: "autoscaling-subscriber" + triggers: + dapr: + - name: kafka-server + type: bindings.cron + topic: "sample-topic" + hooks: + post: + - dev.openfunction.samples.hooks.ExampleHook + pre: + - dev.openfunction.samples.hooks.ExampleHook \ No newline at end of file