From 9934ae8aa5d88af1b9666ceb1212263890d967ed Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Thu, 21 Mar 2024 12:33:10 -0300 Subject: [PATCH 1/2] Introduce Newsletter Subs Deployment for Operator Signed-off-by: Ricardo Zanini --- .../README.md | 0 .../deploy/kubernetes/01-postgres.yaml | 86 ++++++++++ .../kubernetes/02-sonataflow-platform.yaml | 46 ++++++ .../03-newsletter-subs-service.yaml | 36 ++++ .../deploy/kubernetes/kustomization.yaml | 24 +++ .../deploy/openshift/kustomization.yaml | 10 ++ .../workflow/application-knative.properties | 76 +++++++++ .../workflow/application.properties | 52 ++++++ ...figmap_01-subscription-flow-resources.yaml | 23 +++ .../01-sonataflow_subscription-flow.yaml | 142 ++++++++++++++++ ...figmap_02-subscription-flow-resources.yaml | 138 ++++++++++++++++ .../03-configmap_subscription-flow-props.yaml | 59 +++++++ .../workflow/schemas/subscription-schema.json | 15 ++ .../workflow/specs/subscription-service.yaml | 130 +++++++++++++++ .../workflow/subscription-flow.svg | 1 + .../workflow/subscription-flow.sw.json | 154 ++++++++++++++++++ .../resources/application-knative.properties | 2 +- 17 files changed, 993 insertions(+), 1 deletion(-) create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/README.md create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/01-postgres.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/02-sonataflow-platform.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/03-newsletter-subs-service.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/kustomization.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/deploy/openshift/kustomization.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application-knative.properties create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties create mode 100755 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-configmap_01-subscription-flow-resources.yaml create mode 100755 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml create mode 100755 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/02-configmap_02-subscription-flow-resources.yaml create mode 100755 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/schemas/subscription-schema.json create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/specs/subscription-service.yaml create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.sw.json diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/README.md b/serverless-operator-examples/sonataflow-newsletter-subscription/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/01-postgres.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/01-postgres.yaml new file mode 100644 index 0000000000..4cc26768ce --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/01-postgres.yaml @@ -0,0 +1,86 @@ +# Copyright 2024 Apache Software Foundation (ASF) +# +# 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. + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + labels: + app.kubernetes.io/name: postgres + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: postgres + name: postgres +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: postgres + template: + metadata: + labels: + app.kubernetes.io/name: postgres + spec: + containers: + - name: postgres + image: postgres + imagePullPolicy: 'IfNotPresent' + ports: + - containerPort: 5432 + volumeMounts: + - name: storage + mountPath: /var/lib/pgsql/data + envFrom: + - secretRef: + name: postgres-secrets + readinessProbe: + exec: + command: ["pg_isready"] + initialDelaySeconds: 15 + timeoutSeconds: 2 + livenessProbe: + exec: + command: ["pg_isready"] + initialDelaySeconds: 15 + timeoutSeconds: 2 + resources: + limits: + memory: "256Mi" + cpu: "500m" + volumes: + - name: storage + persistentVolumeClaim: + claimName: postgres-pvc +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/name: postgres + name: postgres +spec: + selector: + app.kubernetes.io/name: postgres + ports: + - port: 5432 diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/02-sonataflow-platform.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/02-sonataflow-platform.yaml new file mode 100644 index 0000000000..14bcee08d5 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/02-sonataflow-platform.yaml @@ -0,0 +1,46 @@ +# Copyright 2024 Apache Software Foundation (ASF) +# +# 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. + +apiVersion: sonataflow.org/v1alpha08 +kind: SonataFlowPlatform +metadata: + name: sonataflow-platform +spec: + services: + dataIndex: + enabled: true + persistence: + postgresql: + secretRef: + name: postgres-secrets + jdbcUrl: jdbc:postgresql://postgres:5432/sonataflow?currentSchema=data-index-service + podTemplate: + initContainers: + - name: init-postgres + image: registry.access.redhat.com/ubi9/ubi-micro:latest + imagePullPolicy: IfNotPresent + command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ] + jobService: + enabled: true + persistence: + postgresql: + secretRef: + name: postgres-secrets + jdbcUrl: jdbc:postgresql://postgres:5432/sonataflow?currentSchema=jobs-service + podTemplate: + initContainers: + - name: init-postgres + image: registry.access.redhat.com/ubi9/ubi-micro:latest + imagePullPolicy: IfNotPresent + command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ] diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/03-newsletter-subs-service.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/03-newsletter-subs-service.yaml new file mode 100644 index 0000000000..55788a6f73 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/03-newsletter-subs-service.yaml @@ -0,0 +1,36 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + annotations: + app.quarkus.io/commit-id: eeb187b96e1d3526959459ca0c9e0d618eeede46 + app.quarkus.io/build-timestamp: 2024-03-20 - 17:25:36 +0000 + labels: + app.kubernetes.io/version: "1.0" + app.kubernetes.io/name: subscription-service + name: subscription-service +spec: + template: + spec: + containers: + - env: + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + key: POSTGRESQL_PASSWORD + name: postgres-secrets + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + key: POSTGRESQL_USER + name: postgres-secrets + - name: POSTGRES_HOST + value: postgres + image: newsletter-subs-service + imagePullPolicy: IfNotPresent + name: subscription-service + securityContext: + runAsNonRoot: true + ports: + - containerPort: 8080 + name: http1 + protocol: TCP diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/kustomization.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/kustomization.yaml new file mode 100644 index 0000000000..760006965e --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/kubernetes/kustomization.yaml @@ -0,0 +1,24 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- 01-postgres.yaml +- 02-sonataflow-platform.yaml +- 03-newsletter-subs-service.yaml + +images: +- name: postgres + newName: postgres + newTag: 13.2-alpine +- name: newsletter-subs-service + newName: quay.io/ricardozanini/sonataflow-newsletter-subs-service + newTag: "2.0" + +secretGenerator: + - name: postgres-secrets + options: + disableNameSuffixHash: true + literals: + - POSTGRESQL_USER=sonataflow + - POSTGRESQL_PASSWORD=sonataflow + - POSTGRESQL_DATABASE=sonataflow + - PGDATA=/var/lib/pgsql/data diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/openshift/kustomization.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/openshift/kustomization.yaml new file mode 100644 index 0000000000..58a77be336 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/deploy/openshift/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - "../kubernetes" + +images: +- name: postgres + newName: registry.redhat.io/rhel9/postgresql-13 + newTag: 1-173 diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application-knative.properties b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application-knative.properties new file mode 100644 index 0000000000..8ce2a74312 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application-knative.properties @@ -0,0 +1,76 @@ +# +# 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. +# + +# Use the Kogito service discovery mechanism to get the current service url. +# For more information see: https://kiegroup.github.io/kogito-docs/serverlessworkflow/latest/cloud/kubernetes-service-discovery.html +kogito.service.url=${knative:services.v1.serving.knative.dev/newsletter-showcase/subscription-flow} + +# When the application is generated with the knative profile, it'll require a PostgreSQL database. +# Kogito persistence configurations for enabling the serverless workflow persistence +quarkus.datasource.db-kind=postgresql +quarkus.flyway.migrate-at-start=true +kogito.persistence.type=jdbc +kogito.persistence.proto.marshaller=false +kogito.persistence.query.timeout.millis=10000 + +# The POSTGRES_HOST env var will be generated by quarkus-kubernetes plugin. See below. +quarkus.datasource.jdbc.url=jdbc:postgresql://${POSTGRES_HOST:localhost}:5432/postgres?currentSchema=runtimes +quarkus.datasource.username=postgres +# The POSTGRES_PASSWORD env var will be generated by the quarkus-kubernetes plugin. See below. +quarkus.datasource.password=${POSTGRES_PASSWORD:pass} + +# Events produced by kogito-addons-quarkus-jobs-knative-eventing to program the timers on the jobs service. +mp.messaging.outgoing.kogito-job-service-job-request-events.connector=quarkus-http +mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} +mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST + +kogito.events.usertasks.enabled=false +kogito.events.variables.enabled=false +kogito.addon.messaging.outgoing.cloudEventMode=structured + +## Knative integration: + +# Use the Kogito service discovery mechanism to get the subscription-service url +# For more information see: +# https://kiegroup.github.io/kogito-docs/serverlessworkflow/latest/cloud/kubernetes-service-discovery.html +quarkus.rest-client.subscription_service_yaml.url=${knative:services.v1.serving.knative.dev/newsletter-showcase/subscription-service} + +# Configure current deployment to set an env var with name POSTGRES_HOST +# For more information see: https://quarkus.io/guides/deploying-to-kubernetes#environment-variables-from-keyvalue-pairs +quarkus.knative.env.vars.postgres_host=newsletter-postgres + +# Configure current deployment to be linked with the kubernetes secret newsletter-postgres, and to set an env +# var POSTGRES_PASSWORD that will get it's value form the secret entry with key postgrespass. +# For more information see: https://quarkus.io/guides/deploying-to-kubernetes#secret-mapping +#quarkus.knative.env.secrets=newsletter-postgres +#quarkus.knative.env.mapping.postgres_password.from-secret=newsletter-postgres +#quarkus.knative.env.mapping.postgres_password.with-key=postgrespass + +# This configuration enables Knative to fetch the image information on Minikube. +# you can change this property with -Pknative -Dquarkus.container-image.group from the command line. +quarkus.container-image.group=dev.local +quarkus.kubernetes.deployment-target=knative +# The name of the application. This value will be used for naming Kubernetes resources like: Deployment, Service, etc. +quarkus.knative.name=subscription-flow +quarkus.container-image.name=${quarkus.knative.name} +quarkus.knative.image-pull-policy=IfNotPresent + +# Kogito Knative integration +# We opt to use the Knative objects instead of the Kogito Source. +org.kie.kogito.addons.knative.eventing.generate-kogito-source=false diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties new file mode 100644 index 0000000000..b16f4a9576 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties @@ -0,0 +1,52 @@ +# +# 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. +# + +quarkus.native.native-image-xmx=8g +quarkus.swagger-ui.always-include=true + +# Use the Kogito service discovery mechanism to get the current service url. +kogito.service.url=${knative:services.v1.serving.knative.dev/subscription-flow} + +quarkus.log.category."org.kie.kogito.addon.quarkus.messaging".level=DEBUG +# Uncomment to use a broader log category. +#quarkus.log.category."org.kie.kogito".level=DEBUG + +quarkus.rest-client.subscription_service_yaml.url=${knative:services.v1.serving.knative.dev/subscription-service} + +mp.messaging.incoming.kogito_incoming_stream.connector=quarkus-http +mp.messaging.incoming.kogito_incoming_stream.path=/ +kogito.addon.messaging.outgoing.cloudEventMode=structured + +# The K_SINK variable is automatically injected by the Knative ecosystem. The default value http://localhost:8181 +# is used for local testing, which correspond to the event-display local container. +mp.messaging.outgoing.kogito_outgoing_stream.connector=quarkus-http +mp.messaging.outgoing.kogito_outgoing_stream.url=${K_SINK:http://localhost:8181} + +# Events produced by kogito-addons-quarkus-jobs-knative-eventing to program the timers on the jobs service. +mp.messaging.outgoing.kogito-job-service-job-request-events.connector=quarkus-http +mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} +mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST + +mp.messaging.outgoing.kogito-processdefinitions-events.connector=quarkus-http +mp.messaging.outgoing.kogito-processinstances-events.connector=quarkus-http + + +kogito.events.usertasks.enabled=false +kogito.events.variables.enabled=false + diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-configmap_01-subscription-flow-resources.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-configmap_01-subscription-flow-resources.yaml new file mode 100755 index 0000000000..c1513c8771 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-configmap_01-subscription-flow-resources.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +data: + subscription-schema.json: |- + { + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string" + } + }, + "required": [ + "email" + ] + } +kind: ConfigMap +metadata: + creationTimestamp: null + name: 01-subscription-flow-resources + namespace: newsletter-subscription diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml new file mode 100755 index 0000000000..42708464a3 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml @@ -0,0 +1,142 @@ +apiVersion: sonataflow.org/v1alpha08 +kind: SonataFlow +metadata: + annotations: + sonataflow.org/description: "" + sonataflow.org/expressionLang: jq + sonataflow.org/version: "1.0" + creationTimestamp: null + labels: + app: subscription-flow + sonataflow.org/workflow-app: subscription-flow + name: subscription-flow + namespace: newsletter-subscription +spec: + flow: + dataInputSchema: + failOnValidationErrors: true + schema: schemas/subscription-schema.json + events: + - dataOnly: true + kind: produced + name: NewSubscriptionEvent + type: new.subscription + - dataOnly: true + kind: consumed + name: ConfirmSubscriptionEvent + type: confirm.subscription + functions: + - name: subscribeToNewsletter + operation: specs/subscription-service.yaml#subscribe + type: rest + - name: confirmSubscription + operation: specs/subscription-service.yaml#confirm + type: rest + - name: deleteSubscription + operation: specs/subscription-service.yaml#delete + type: rest + - name: verifyEmail + operation: specs/subscription-service.yaml#verify + type: rest + start: + stateName: VerifyEmail + states: + - actionMode: sequential + actions: + - actionDataFilter: + useResults: true + functionRef: + arguments: + email: ${ .email } + invoke: sync + refName: verifyEmail + name: VerifyEmail + transition: + nextState: ExitIfEmailExists + type: operation + - dataConditions: + - condition: ${ .emailExists == false } + transition: + nextState: SubscribeAndWaitForConfirmation + defaultCondition: + transition: + nextState: NoSubscription + name: ExitIfEmailExists + type: switch + - action: + actionDataFilter: + useResults: true + functionRef: + arguments: + email: ${ .email } + id: $WORKFLOW.instanceId + name: ${ .name } + invoke: sync + refName: subscribeToNewsletter + eventRef: ConfirmSubscriptionEvent + name: SubscribeAndWaitForConfirmation + timeouts: + eventTimeout: PT3M + transition: + nextState: CheckConfirmation + type: callback + - dataConditions: + - condition: ${ .confirmed == true } + transition: + nextState: ConfirmSubscription + defaultCondition: + transition: + nextState: DeleteSubscription + name: CheckConfirmation + type: switch + - actionMode: sequential + actions: + - actionDataFilter: + useResults: true + functionRef: + arguments: + email: ${ .email } + id: $WORKFLOW.instanceId + name: ${ .name } + invoke: sync + refName: confirmSubscription + end: + produceEvents: + - data: null + eventRef: NewSubscriptionEvent + terminate: true + name: ConfirmSubscription + type: operation + - actionMode: sequential + actions: + - actionDataFilter: + useResults: true + functionRef: + arguments: + id: $WORKFLOW.instanceId + invoke: sync + refName: deleteSubscription + end: + terminate: true + name: DeleteSubscription + type: operation + - data: + subscribed: true + end: + terminate: true + name: NoSubscription + type: inject + podTemplate: + container: + resources: {} + resources: + configMaps: + - configMap: + name: 01-subscription-flow-resources + workflowPath: schemas + - configMap: + name: 02-subscription-flow-resources + workflowPath: specs +status: + address: {} + lastTimeRecoverAttempt: null diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/02-configmap_02-subscription-flow-resources.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/02-configmap_02-subscription-flow-resources.yaml new file mode 100755 index 0000000000..10d05e1f08 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/02-configmap_02-subscription-flow-resources.yaml @@ -0,0 +1,138 @@ +apiVersion: v1 +data: + subscription-service.yaml: | + # + # 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. + # + + --- + openapi: 3.0.3 + info: + title: serverless-workflow-newsletter-subscription-service API + version: 999-SNAPSHOT + paths: + /subscription: + get: + tags: + - Subscription Resource + operationId: fetch + parameters: + - name: email + in: query + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + post: + tags: + - Subscription Resource + operationId: subscribe + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/{id}: + delete: + tags: + - Subscription Resource + operationId: delete + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/confirm: + put: + tags: + - Subscription Resource + operationId: confirm + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/verify: + get: + tags: + - Subscription Resource + operationId: verify + parameters: + - name: email + in: query + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/EmailVerificationReply' + components: + schemas: + EmailVerificationReply: + type: object + properties: + email: + type: string + emailExists: + type: boolean + Subscription: + type: object + properties: + email: + type: string + id: + type: string + name: + type: string + verified: + type: boolean +kind: ConfigMap +metadata: + creationTimestamp: null + name: 02-subscription-flow-resources + namespace: newsletter-subscription diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml new file mode 100755 index 0000000000..7de2de35be --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml @@ -0,0 +1,59 @@ +apiVersion: v1 +data: + application.properties: |+ + # + # 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. + # + + quarkus.native.native-image-xmx=8g + quarkus.swagger-ui.always-include=true + + # Use the Kogito service discovery mechanism to get the current service url. + kogito.service.url=${knative:services.v1.serving.knative.dev/subscription-flow} + + quarkus.log.category."org.kie.kogito.addon.quarkus.messaging".level=DEBUG + # Uncomment to use a broader log category. + #quarkus.log.category."org.kie.kogito".level=DEBUG + + quarkus.rest-client.subscription_service_yaml.url=${knative:services.v1.serving.knative.dev/subscription-service} + + mp.messaging.incoming.kogito_incoming_stream.connector=quarkus-http + mp.messaging.incoming.kogito_incoming_stream.path=/ + kogito.addon.messaging.outgoing.cloudEventMode=structured + + # The K_SINK variable is automatically injected by the Knative ecosystem. The default value http://localhost:8181 + # is used for local testing, which correspond to the event-display local container. + mp.messaging.outgoing.kogito_outgoing_stream.connector=quarkus-http + mp.messaging.outgoing.kogito_outgoing_stream.url=${K_SINK:http://localhost:8181} + + # Events produced by kogito-addons-quarkus-jobs-knative-eventing to program the timers on the jobs service. + mp.messaging.outgoing.kogito-job-service-job-request-events.connector=quarkus-http + mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} + mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST + + kogito.events.usertasks.enabled=false + kogito.events.variables.enabled=false + +kind: ConfigMap +metadata: + creationTimestamp: null + labels: + app: subscription-flow + sonataflow.org/workflow-app: subscription-flow + name: subscription-flow-props + namespace: newsletter-subscription diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/schemas/subscription-schema.json b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/schemas/subscription-schema.json new file mode 100644 index 0000000000..de6f2e44fa --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/schemas/subscription-schema.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string" + } + }, + "required": [ + "email" + ] +} \ No newline at end of file diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/specs/subscription-service.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/specs/subscription-service.yaml new file mode 100644 index 0000000000..02b3ccb932 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/specs/subscription-service.yaml @@ -0,0 +1,130 @@ +# +# 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. +# + +--- +openapi: 3.0.3 +info: + title: serverless-workflow-newsletter-subscription-service API + version: 999-SNAPSHOT +paths: + /subscription: + get: + tags: + - Subscription Resource + operationId: fetch + parameters: + - name: email + in: query + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + post: + tags: + - Subscription Resource + operationId: subscribe + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/{id}: + delete: + tags: + - Subscription Resource + operationId: delete + parameters: + - name: id + in: path + required: true + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/confirm: + put: + tags: + - Subscription Resource + operationId: confirm + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/Subscription' + /subscription/verify: + get: + tags: + - Subscription Resource + operationId: verify + parameters: + - name: email + in: query + schema: + type: string + responses: + "200": + description: success + content: + application/json: + schema: + $ref: '#/components/schemas/EmailVerificationReply' +components: + schemas: + EmailVerificationReply: + type: object + properties: + email: + type: string + emailExists: + type: boolean + Subscription: + type: object + properties: + email: + type: string + id: + type: string + name: + type: string + verified: + type: boolean diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg new file mode 100644 index 0000000000..817c2d9852 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg @@ -0,0 +1 @@ +StartVerifyEmailExitIfEmailExistsSubscribeAndWaitF orConfirmation CheckConfirmationConfirmSubscriptio n EndDeleteSubscriptionEndNoSubscriptionEnd${ .emailEx... ${ .emailEx... ${ .confirm... ${ .confirm... \ No newline at end of file diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.sw.json b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.sw.json new file mode 100644 index 0000000000..6eba0e0fb9 --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.sw.json @@ -0,0 +1,154 @@ +{ + "id": "subscription-flow", + "dataInputSchema": "schemas/subscription-schema.json", + "specVersion": "0.8", + "version": "1.0", + "start": "VerifyEmail", + "events": [ + { + "kind": "produced", + "type": "new.subscription", + "name": "NewSubscriptionEvent" + }, + { + "kind": "consumed", + "type": "confirm.subscription", + "name": "ConfirmSubscriptionEvent" + } + ], + "functions": [ + { + "name": "subscribeToNewsletter", + "operation": "specs/subscription-service.yaml#subscribe" + }, + { + "name": "confirmSubscription", + "operation": "specs/subscription-service.yaml#confirm" + }, + { + "name": "deleteSubscription", + "operation": "specs/subscription-service.yaml#delete" + }, + { + "name": "verifyEmail", + "operation": "specs/subscription-service.yaml#verify" + } + ], + "states": [ + { + "name": "VerifyEmail", + "type": "operation", + "actions": [ + { + "functionRef": { + "refName": "verifyEmail", + "arguments": { + "email": "${ .email }" + } + } + } + ], + "transition": { + "nextState": "ExitIfEmailExists" + } + }, + { + "name": "ExitIfEmailExists", + "type": "switch", + "defaultCondition": { + "transition": { + "nextState": "NoSubscription" + } + }, + "dataConditions": [ + { + "condition": "${ .emailExists == false }", + "transition": { + "nextState": "SubscribeAndWaitForConfirmation" + } + } + ] + }, + { + "name": "SubscribeAndWaitForConfirmation", + "type": "callback", + "action": { + "functionRef": { + "refName": "subscribeToNewsletter", + "arguments": { + "email": "${ .email }", + "id": "$WORKFLOW.instanceId", + "name": "${ .name }" + } + } + }, + "eventRef": "ConfirmSubscriptionEvent", + "transition": { + "nextState": "CheckConfirmation" + }, + "timeouts": { + "eventTimeout": "PT3M" + } + }, + { + "name" : "CheckConfirmation", + "type" : "switch", + "dataConditions": [ + { + "condition": "${ .confirmed == true }", + "transition": "ConfirmSubscription" + } + ], + "defaultCondition": { + "transition": "DeleteSubscription" + } + }, + { + "name": "ConfirmSubscription", + "type": "operation", + "actions": [ + { + "functionRef": { + "refName": "confirmSubscription", + "arguments": { + "email": "${ .email }", + "id": "$WORKFLOW.instanceId", + "name": "${ .name }" + } + } + } + ], + "end": { + "produceEvents": [ + { + "eventRef": "NewSubscriptionEvent" + } + ], + "terminate": true + } + }, + { + "name": "DeleteSubscription", + "type": "operation", + "actions": [ + { + "functionRef": { + "refName": "deleteSubscription", + "arguments": { + "id": "$WORKFLOW.instanceId" + } + } + } + ], + "end": true + }, + { + "name": "NoSubscription", + "type": "inject", + "data": { + "subscribed": true + }, + "end": true + } + ] +} \ No newline at end of file diff --git a/serverless-workflow-examples/serverless-workflow-newsletter-subscription/subscription-service/src/main/resources/application-knative.properties b/serverless-workflow-examples/serverless-workflow-newsletter-subscription/subscription-service/src/main/resources/application-knative.properties index 421aeb2bd4..5ed48d55cb 100644 --- a/serverless-workflow-examples/serverless-workflow-newsletter-subscription/subscription-service/src/main/resources/application-knative.properties +++ b/serverless-workflow-examples/serverless-workflow-newsletter-subscription/subscription-service/src/main/resources/application-knative.properties @@ -27,7 +27,7 @@ quarkus.datasource.db-kind=postgresql # The POSTGRES_HOST env var will be generated by quarkus-kubernetes plugin. See below. quarkus.datasource.reactive.url=postgresql://${POSTGRES_HOST:localhost}:5432/postgres -quarkus.datasource.username=postgres +quarkus.datasource.username=${POSTGRES_USER:postgres} # The POSTGRES_PASSWORD env var will be generated by the quarkus-kubernetes plugin. See below. quarkus.datasource.password=${POSTGRES_PASSWORD:pass} From 6b1d80f0c50e9f3e0760e7d962a8d5356d364c46 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Thu, 21 Mar 2024 15:38:32 -0300 Subject: [PATCH 2/2] Incorporating changes to reflect the bad image definition Signed-off-by: Ricardo Zanini --- .../sonataflow-newsletter-subscription/ce.json | 13 +++++++++++++ .../workflow/application.properties | 8 -------- .../manifests/01-sonataflow_subscription-flow.yaml | 12 +++++------- .../03-configmap_subscription-flow-props.yaml | 4 ++++ .../workflow/subscription-flow.svg | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 serverless-operator-examples/sonataflow-newsletter-subscription/ce.json diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/ce.json b/serverless-operator-examples/sonataflow-newsletter-subscription/ce.json new file mode 100644 index 0000000000..5c1058366f --- /dev/null +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/ce.json @@ -0,0 +1,13 @@ +{ + "specversion": "1.0", + "id": "dad76364-1cf1-48ca-bf95-485a511f8707", + "source": "demo", + "type": "confirm.subscription", + "kogitoprocrefid": "378e64f6-dbff-4486-932c-390ade04f65b", + "datacontenttype": "application/json", + "time": "2024-03-20T15:35:29.967831-03:00", + "data": { + "id": "378e64f6-dbff-4486-932c-390ade04f65b", + "confirmed": true + } +} \ No newline at end of file diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties index b16f4a9576..88ed984197 100644 --- a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/application.properties @@ -38,14 +38,6 @@ kogito.addon.messaging.outgoing.cloudEventMode=structured mp.messaging.outgoing.kogito_outgoing_stream.connector=quarkus-http mp.messaging.outgoing.kogito_outgoing_stream.url=${K_SINK:http://localhost:8181} -# Events produced by kogito-addons-quarkus-jobs-knative-eventing to program the timers on the jobs service. -mp.messaging.outgoing.kogito-job-service-job-request-events.connector=quarkus-http -mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} -mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST - -mp.messaging.outgoing.kogito-processdefinitions-events.connector=quarkus-http -mp.messaging.outgoing.kogito-processinstances-events.connector=quarkus-http - kogito.events.usertasks.enabled=false kogito.events.variables.enabled=false diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml index 42708464a3..93b1ea1aba 100755 --- a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/01-sonataflow_subscription-flow.yaml @@ -15,7 +15,7 @@ spec: flow: dataInputSchema: failOnValidationErrors: true - schema: schemas/subscription-schema.json + schema: subscription-schema.json events: - dataOnly: true kind: produced @@ -27,16 +27,16 @@ spec: type: confirm.subscription functions: - name: subscribeToNewsletter - operation: specs/subscription-service.yaml#subscribe + operation: subscription-service.yaml#subscribe type: rest - name: confirmSubscription - operation: specs/subscription-service.yaml#confirm + operation: subscription-service.yaml#confirm type: rest - name: deleteSubscription - operation: specs/subscription-service.yaml#delete + operation: subscription-service.yaml#delete type: rest - name: verifyEmail - operation: specs/subscription-service.yaml#verify + operation: subscription-service.yaml#verify type: rest start: stateName: VerifyEmail @@ -133,10 +133,8 @@ spec: configMaps: - configMap: name: 01-subscription-flow-resources - workflowPath: schemas - configMap: name: 02-subscription-flow-resources - workflowPath: specs status: address: {} lastTimeRecoverAttempt: null diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml index 7de2de35be..5647bf518d 100755 --- a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/manifests/03-configmap_subscription-flow-props.yaml @@ -46,6 +46,10 @@ data: mp.messaging.outgoing.kogito-job-service-job-request-events.url=${K_SINK:http://localhost:8280/v2/jobs/events} mp.messaging.outgoing.kogito-job-service-job-request-events.method=POST + mp.messaging.outgoing.kogito-processdefinitions-events.connector=quarkus-http + + mp.messaging.outgoing.kogito-processinstances-events.connector=quarkus-http + kogito.events.usertasks.enabled=false kogito.events.variables.enabled=false diff --git a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg index 817c2d9852..329685cdcb 100644 --- a/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg +++ b/serverless-operator-examples/sonataflow-newsletter-subscription/workflow/subscription-flow.svg @@ -1 +1 @@ -StartVerifyEmailExitIfEmailExistsSubscribeAndWaitF orConfirmation CheckConfirmationConfirmSubscriptio n EndDeleteSubscriptionEndNoSubscriptionEnd${ .emailEx... ${ .emailEx... ${ .confirm... ${ .confirm... \ No newline at end of file +StartVerifyEmailExitIfEmailExistsSubscribeAndWaitF orConfirmation CheckConfirmationConfirmSubscriptio n EndDeleteSubscriptionEndNoSubscriptionEnd${ .emailEx... ${ .emailEx... ${ .confirm... ${ .confirm... \ No newline at end of file