This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


The following commit(s) were added to refs/heads/main by this push:
     new e189c76  Postman on openshift (#337)
e189c76 is described below

commit e189c765e29fd146049b12305cfde8f3ae0963f3
Author: Marat Gubaidullin <marat.gubaidul...@gmail.com>
AuthorDate: Mon May 9 17:09:23 2022 -0400

    Postman on openshift (#337)
    
    * Fix #332
    
    * Postman Opanshift
    
    * Postman on OpenShift
---
 .../postman-openshift/CustomProcessor.java         |  11 ++
 karavan-demo/postman-openshift/README.md           |  54 +++++++
 .../postman-openshift/application.properties       |  36 +++++
 .../manifests/instances/amq-broker.yaml            |  50 ++++++
 .../manifests/instances/amq-streams.yaml           |  34 +++++
 .../manifests/instances/kustomization.yaml         |   7 +
 .../manifests/instances/postgresql.yaml            | 170 +++++++++++++++++++++
 .../postman-openshift/manifests/kustomization.yaml |   8 +
 .../manifests/operators/amq-operator.yaml          |  11 ++
 .../manifests/operators/amq-streams-operator.yaml  |  13 ++
 .../manifests/operators/kustomization.yaml         |   8 +
 .../manifests/operators/namespace.yaml             |   7 +
 .../manifests/operators/operator-group.yaml        |   7 +
 karavan-demo/postman-openshift/operators.png       | Bin 0 -> 96712 bytes
 karavan-demo/postman-openshift/parcels.png         | Bin 0 -> 326798 bytes
 karavan-demo/postman-openshift/postman.yaml        | 133 ++++++++++++++++
 16 files changed, 549 insertions(+)

diff --git a/karavan-demo/postman-openshift/CustomProcessor.java 
b/karavan-demo/postman-openshift/CustomProcessor.java
new file mode 100644
index 0000000..17399cf
--- /dev/null
+++ b/karavan-demo/postman-openshift/CustomProcessor.java
@@ -0,0 +1,11 @@
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+@BindToRegistry("myBean")
+public class CustomProcessor implements Processor {
+
+  public void process(Exchange exchange) throws Exception {
+      exchange.getIn().setBody("Hello world");
+  }
+}
diff --git a/karavan-demo/postman-openshift/README.md 
b/karavan-demo/postman-openshift/README.md
new file mode 100644
index 0000000..ba37d97
--- /dev/null
+++ b/karavan-demo/postman-openshift/README.md
@@ -0,0 +1,54 @@
+# Demo: Parcels Delivery Service on OpenShfit
+
+![Demo](parcels.png)
+
+## Prerequisites
+
+1. [VSCode](https://code.visualstudio.com/download)  installed
+2. Apache Camel 
[Karavan](https://marketplace.visualstudio.com/items?itemName=camel-karavan.karavan)
 extension installed
+3. [Jbang](https://www.jbang.dev/download/) installed
+4. OpenShift 4.9+ cluster up and running
+4. OpenShift 4.9+ CLI installed
+
+## How-to
+### Install AMQ and AMQ Streams Operators
+Also creates `postman` namespace required for the demo
+```
+oc apply -k manifests/operators
+```
+Check that operators are succesfully installed
+![operators](operators.png)
+
+### Create AMQ, Kafka and Postgres demo instances 
+```
+oc apply -k manifests/instances
+```
+
+### Publish postman
+```
+
+```
+
+
+
+
+
+
+
+
+### Publish parcel
+```
+curl -X POST -H "Content-Type: application/json" --data 
'{"id":"1","address":"666 Sin Street, Holy City"}' http://0.0.0.0:8080/parcels
+```
+### Publish payment
+Open AMQ7 Broker Management [Console](http://localhost:8161)
+
+Send message to `payments` queue
+```
+<?xml version="1.0" encoding="UTF-8" ?>
+<root>
+  <id>1</id>
+  <amount>777</amount>
+  <status>confirmed</status>  
+</root>
+```
diff --git a/karavan-demo/postman-openshift/application.properties 
b/karavan-demo/postman-openshift/application.properties
new file mode 100644
index 0000000..224103b
--- /dev/null
+++ b/karavan-demo/postman-openshift/application.properties
@@ -0,0 +1,36 @@
+
+camel.jbang.project.name=postman
+camel.jbang.project.version=1.0.0
+camel.jbang.project.namespace=postman
+camel.jbang.project.cleanup=true
+camel.jbang.package=true
+camel.jbang.package.uber-jar.jar=camel-runner.jar
+camel.jbang.package.uber-jar.fresh=true
+camel.main.routesIncludePattern=file:CustomProcessor.java,file:postman.yaml
+camel.jbang.build.image=true
+camel.jbang.build.image.openshift=true
+camel.jbang.build.image.minikube=false
+camel.jbang.build.image.jar=camel-runner.jar
+camel.jbang.build.image.tag=postman/postman:1.0.0
+camel.jbang.build.image.source-image=java:openjdk-11-ubi8
+camel.jbang.build.image.from=gcr.io/distroless/java:11
+camel.jbang.build.image.server=https://api.cluster-wjw7l.wjw7l.sandbox1208.opentlc.com:6443
+camel.jbang.deploy=true
+camel.jbang.deploy.openshift=true
+camel.jbang.deploy.minikube=false
+camel.jbang.deploy.image=postman/postman:1.0.0
+camel.jbang.deploy.replicas=1
+camel.jbang.deploy.node-port=30777
+camel.jbang.deploy.server=https://api.cluster-wjw7l.wjw7l.sandbox1208.opentlc.com:6443
+camel.jbang.undeploy.openshift=true
+camel.jbang.undeploy.minikube=false
+camel.jbang.undeploy.server=https://api.cluster-wjw7l.wjw7l.sandbox1208.opentlc.com:6443
+camel.jbang.manifests=true
+camel.jbang.manifests.path=true
+camel.jbang.manifests.openshift=true
+camel.jbang.manifests.minikube=false
+camel.jbang.manifests.image=postman/postman:1.0.0
+camel.jbang.manifests.replicas=1
+camel.jbang.manifests.node-port=30777
+camel.jbang.manifests.server=https://api.cluster-wjw7l.wjw7l.sandbox1208.opentlc.com:6443
+camel.jbang.manifests.jar=camel-runner.jar
\ No newline at end of file
diff --git a/karavan-demo/postman-openshift/manifests/instances/amq-broker.yaml 
b/karavan-demo/postman-openshift/manifests/instances/amq-broker.yaml
new file mode 100644
index 0000000..e83b987
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/instances/amq-broker.yaml
@@ -0,0 +1,50 @@
+apiVersion: broker.amq.io/v2alpha5
+kind: ActiveMQArtemis
+metadata:
+  name: amq
+  application: amq
+  namespace: postman
+spec:
+  acceptors:
+    - port: 61616
+      expose: true
+      name: all
+      protocols: all
+      anycastPrefix: jms.queue.
+      verifyHost: false
+      sslEnabled: false
+    - port: 1883
+      expose: true
+      name: mqtt
+      protocols: mqtt
+      anycastPrefix: jms.queue.
+      verifyHost: false
+      sslEnabled: false  
+  adminPassword: admin
+  deploymentPlan:
+    size: 1
+    persistenceEnabled: true
+    requireLogin: false
+    messageMigration: false
+    managementRBACEnabled: true
+    journalType: nio
+    jolokiaAgentEnabled: false
+    image: placeholder
+  console:
+    expose: true
+  adminUser: admin
+
+---
+kind: Route
+apiVersion: route.openshift.io/v1
+metadata:
+  name: console
+  namespace: amq
+spec:
+  to:
+    kind: Service
+    name: amq-hdls-svc
+    weight: 100
+  port:
+    targetPort: console-jolokia
+  wildcardPolicy: None
diff --git 
a/karavan-demo/postman-openshift/manifests/instances/amq-streams.yaml 
b/karavan-demo/postman-openshift/manifests/instances/amq-streams.yaml
new file mode 100644
index 0000000..bd1ba85
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/instances/amq-streams.yaml
@@ -0,0 +1,34 @@
+kind: Kafka
+apiVersion: kafka.strimzi.io/v1beta2
+metadata:
+  name: kafka
+  namespace: postman
+spec:
+  kafka:
+    version: 3.1.0
+    replicas: 1
+    listeners:
+      - name: plain
+        port: 9092
+        type: internal
+        tls: false
+      - name: tls
+        port: 9093
+        type: internal
+        tls: true
+    config:
+      offsets.topic.replication.factor: 1
+      transaction.state.log.replication.factor: 1
+      transaction.state.log.min.isr: 1
+      default.replication.factor: 1
+      min.insync.replicas: 1
+      inter.broker.protocol.version: '3.1'
+    storage:
+      type: ephemeral
+  zookeeper:
+    replicas: 1
+    storage:
+      type: ephemeral
+  entityOperator:
+    topicOperator: {}
+    userOperator: {}
\ No newline at end of file
diff --git 
a/karavan-demo/postman-openshift/manifests/instances/kustomization.yaml 
b/karavan-demo/postman-openshift/manifests/instances/kustomization.yaml
new file mode 100644
index 0000000..e0c09bd
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/instances/kustomization.yaml
@@ -0,0 +1,7 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: postman
+resources:
+- postgresql.yaml
+- amq-broker.yaml
+- amq-streams.yaml
\ No newline at end of file
diff --git a/karavan-demo/postman-openshift/manifests/instances/postgresql.yaml 
b/karavan-demo/postman-openshift/manifests/instances/postgresql.yaml
new file mode 100644
index 0000000..fe33b72
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/instances/postgresql.yaml
@@ -0,0 +1,170 @@
+apiVersion: apps.openshift.io/v1
+kind: DeploymentConfig
+metadata:
+  labels:
+    app: postgres
+    app.kubernetes.io/component: postgres-dc
+    app.kubernetes.io/instance: postgres
+    app.kubernetes.io/part-of: postgres
+    app.openshift.io/runtime: postgres
+    deploymentconfig: postgres
+  name: postgres
+  namespace: postman
+  annotations:
+    argocd.argoproj.io/sync-options: Validate=false
+spec:
+  replicas: 1
+  revisionHistoryLimit: 3
+  selector:
+    name: postgres
+    app: postgres
+    deploymentconfig: postgres
+  strategy:
+    activeDeadlineSeconds: 21600
+    recreateParams:
+      timeoutSeconds: 600
+    resources: {}
+    type: Recreate
+  template:
+    metadata:
+      name: postgres
+      labels:
+        app: postgres
+        name: postgres
+        deploymentconfig: postgres
+    spec:
+      containers:
+      - env:
+        - name: POSTGRESQL_USER
+          value: postgres
+        - name: POSTGRESQL_PASSWORD
+          value: postgres
+        - name: POSTGRESQL_DATABASE
+          value: demo
+        imagePullPolicy: IfNotPresent
+        lifecycle:
+          postStart:
+            exec:
+              command:
+              - /bin/sh
+              - -c
+              - /var/lib/pgsql/demo/postStart.sh
+          # postStart:
+            # exec:
+            #  command:
+                  # - sleep 10 && echo ${SQL_TABLE} | psql -U 
${POSTGRESQL_USER} -d ${POSTGRESQL_DATABASE};
+                  # - sleep 10 && echo ${SQL_DB} | psql -U ${POSTGRESQL_USER} 
&& echo ${SQL_TABLE} | psql -U ${POSTGRESQL_USER} -d ${POSTGRESQL_DATABASE};
+          failureThreshold: 3
+          initialDelaySeconds: 30
+          periodSeconds: 10
+          successThreshold: 1
+          tcpSocket:
+            port: 5432
+          timeoutSeconds: 1
+        name: postgresql
+        ports:
+        - containerPort: 5432
+          protocol: TCP
+        readinessProbe:
+          exec:
+            command:
+            - /bin/sh
+            - -i
+            - -c
+            - psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -d $POSTGRESQL_DATABASE 
-c 'SELECT 1'
+          failureThreshold: 3
+          initialDelaySeconds: 5
+          periodSeconds: 10
+          successThreshold: 1
+          timeoutSeconds: 1
+        resources:
+          limits:
+            cpu: '1'
+            memory: 512Mi
+          requests:
+            cpu: 250m
+            memory: 256Mi
+        securityContext:
+          capabilities: {}
+          privileged: false
+          procMount: Default
+        terminationMessagePath: /dev/termination-log
+        terminationMessagePolicy: File
+        volumeMounts:
+        - mountPath: /var/lib/pgsql/data
+          name: postgres-data
+        - mountPath: /var/lib/pgsql/demo
+          name: postgres-config 
+      dnsPolicy: ClusterFirst
+      restartPolicy: Always
+      schedulerName: default-scheduler
+      securityContext: {}
+      terminationGracePeriodSeconds: 30
+      volumes:
+      - name: postgres-data
+        emptyDir: {}
+      - configMap:
+          defaultMode: 511
+          name: postgres-config
+        name: postgres-config  
+  test: false
+  triggers:
+  - imageChangeParams:
+      automatic: true
+      containerNames:
+      - postgresql
+      from:
+        kind: ImageStreamTag
+        name: postgresql:latest
+        namespace: openshift
+    type: ImageChange
+  - type: ConfigChange
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  labels:
+    app: postgres
+    component: postgres
+  name: postgres-config  
+data:
+  add-sample-db.sh: |
+    #!/bin/bash
+    until bash -c "psql -h 127.0.0.1 -U $POSTGRESQL_USER -q -c 'SELECT 1'"; do
+      echo "Waiting for Postgres server..."
+      sleep 1
+    done 
+    echo "----- creating sampledb"
+    psql <<EOF 
+      CREATE DATABASE demo OWNER postgres;
+    EOF
+    psql -d demo -U postgres <<'EOF'
+      CREATE TABLE IF NOT EXISTS parcels (id varchar(250) NOT NULL, address 
varchar(250) NOT NULL, status varchar(250), PRIMARY KEY (id));
+    EOF
+  postStart.sh: |
+    #!/bin/bash
+    /var/lib/pgsql/demo/add-sample-db.sh &>  /proc/1/fd/1
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    app: postgres
+    app.kubernetes.io/component: postgres-svc
+    app.kubernetes.io/instance: postgres
+    app.kubernetes.io/part-of: postgres
+  name: postgres
+  namespace: postman
+spec:
+  ports:
+  - name: postgresql
+    port: 5432
+    protocol: TCP
+    targetPort: 5432
+  selector:
+    app: postgres
+    deploymentconfig: postgres
+  sessionAffinity: None
+  type: ClusterIP
+status:
+  loadBalancer: {}
diff --git a/karavan-demo/postman-openshift/manifests/kustomization.yaml 
b/karavan-demo/postman-openshift/manifests/kustomization.yaml
new file mode 100644
index 0000000..e011f60
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/kustomization.yaml
@@ -0,0 +1,8 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+resources:
+  - namespace.yaml
+  - ./operators
+  # - ../postgres
+  - ./amq
+  - ./amq-streams
diff --git 
a/karavan-demo/postman-openshift/manifests/operators/amq-operator.yaml 
b/karavan-demo/postman-openshift/manifests/operators/amq-operator.yaml
new file mode 100644
index 0000000..d83442f
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/operators/amq-operator.yaml
@@ -0,0 +1,11 @@
+apiVersion: operators.coreos.com/v1alpha1
+kind: Subscription
+metadata:
+  name: amq-broker-rhel8
+  namespace: openshift-operators
+spec:
+  channel: 7.x
+  installPlanApproval: Automatic
+  name: amq-broker-rhel8
+  source: redhat-operators
+  sourceNamespace: openshift-marketplace
diff --git 
a/karavan-demo/postman-openshift/manifests/operators/amq-streams-operator.yaml 
b/karavan-demo/postman-openshift/manifests/operators/amq-streams-operator.yaml
new file mode 100644
index 0000000..b9109c3
--- /dev/null
+++ 
b/karavan-demo/postman-openshift/manifests/operators/amq-streams-operator.yaml
@@ -0,0 +1,13 @@
+apiVersion: operators.coreos.com/v1alpha1
+kind: Subscription
+metadata:
+  labels:
+    operators.coreos.com/amq-streams.openshift-operators: ""
+  name: amq-streams
+  namespace: openshift-operators
+spec:
+  channel: stable
+  installPlanApproval: Automatic
+  name: amq-streams
+  source: redhat-operators
+  sourceNamespace: openshift-marketplace
\ No newline at end of file
diff --git 
a/karavan-demo/postman-openshift/manifests/operators/kustomization.yaml 
b/karavan-demo/postman-openshift/manifests/operators/kustomization.yaml
new file mode 100644
index 0000000..01a6fbb
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/operators/kustomization.yaml
@@ -0,0 +1,8 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+
+resources:
+  - namespace.yaml 
+  - operator-group.yaml
+  - amq-operator.yaml
+  - amq-streams-operator.yaml
diff --git a/karavan-demo/postman-openshift/manifests/operators/namespace.yaml 
b/karavan-demo/postman-openshift/manifests/operators/namespace.yaml
new file mode 100644
index 0000000..6a1655c
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/operators/namespace.yaml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  annotations:
+    openshift.io/description: postman
+    openshift.io/display-name: postman
+  name: postman
diff --git 
a/karavan-demo/postman-openshift/manifests/operators/operator-group.yaml 
b/karavan-demo/postman-openshift/manifests/operators/operator-group.yaml
new file mode 100644
index 0000000..09b869c
--- /dev/null
+++ b/karavan-demo/postman-openshift/manifests/operators/operator-group.yaml
@@ -0,0 +1,7 @@
+apiVersion: operators.coreos.com/v1
+kind: OperatorGroup
+metadata:
+  name: postman
+spec:
+  targetNamespaces:
+  - postman
diff --git a/karavan-demo/postman-openshift/operators.png 
b/karavan-demo/postman-openshift/operators.png
new file mode 100644
index 0000000..3582bcb
Binary files /dev/null and b/karavan-demo/postman-openshift/operators.png differ
diff --git a/karavan-demo/postman-openshift/parcels.png 
b/karavan-demo/postman-openshift/parcels.png
new file mode 100644
index 0000000..3cb70ff
Binary files /dev/null and b/karavan-demo/postman-openshift/parcels.png differ
diff --git a/karavan-demo/postman-openshift/postman.yaml 
b/karavan-demo/postman-openshift/postman.yaml
new file mode 100644
index 0000000..c7e473b
--- /dev/null
+++ b/karavan-demo/postman-openshift/postman.yaml
@@ -0,0 +1,133 @@
+apiVersion: camel.apache.org/v1
+kind: Integration
+metadata:
+  name: Postman Demo
+spec:
+  flows:
+    - rest:
+        post:
+          - to: direct:post
+        path: /parcels
+        consumes: application/json
+        produces: application/json
+    - route:
+        from:
+          uri: direct:post
+          steps:
+            - log:
+                message: 'Received: ${body}'
+            - multicast:
+                steps:
+                  - to:
+                      uri: kamelet:kafka-not-secured-sink
+                      parameters:
+                        topic: parcels
+                        bootstrapServers: kafka-kafka-bootstrap:9092
+                  - to:
+                      uri: kamelet:postgresql-sink
+                      parameters:
+                        serverName: postgres
+                        serverPort: '5432'
+                        username: postgres
+                        password: postgres
+                        databaseName: demo
+                        query: >-
+                          INSERT INTO parcels (id,address) VALUES
+                          (:#id,:#address) ON CONFLICT (id)  DO NOTHING
+                aggregationStrategy: >-
+                  
#class:org.apache.camel.processor.aggregate.UseOriginalAggregationStrategy
+                parallelProcessing: true
+                streaming: true
+        id: post
+    - route:
+        from:
+          uri: kamelet:jms-apache-artemis-source
+          steps:
+            - to:
+                uri: xj:identity
+                parameters:
+                  transformDirection: XML2JSON
+            - to:
+                uri: kamelet:kafka-not-secured-sink
+                parameters:
+                  topic: payments
+                  bootstrapServers: kafka-kafka-bootstrap:9092
+          parameters:
+            destinationType: queue
+            destinationName: payments
+            brokerURL: tcp://amq-all-0-svc:61616
+        id: payment
+    - route:
+        from:
+          uri: kamelet:kafka-not-secured-source
+          steps:
+            - log:
+                message: 'Aggegating: ${body}'
+            - unmarshal:
+                json:
+                  library: jackson
+            - aggregate:
+                steps:
+                  - choice:
+                      when:
+                        - expression:
+                            groovy:
+                              expression: >-
+                                body.find { it.containsKey('status') }.status 
==
+                                'confirmed'
+                          steps:
+                            - marshal:
+                                json:
+                                  library: jackson
+                            - log:
+                                message: 'Send to MQTT : ${body}'
+                            - to:
+                                uri: kamelet:mqtt-sink
+                                parameters:
+                                  topic: deliveries
+                                  brokerUrl: tcp://amq-mqtt-0-svc:1883
+                      otherwise:
+                        steps:
+                          - setBody:
+                              expression:
+                                groovy:
+                                  expression: 'body.find { 
it.containsKey(''status'') } '
+                          - marshal:
+                              json:
+                                library: jackson
+                          - log:
+                              message: 'Send to database: ${body}'
+                          - to:
+                              uri: kamelet:postgresql-sink
+                              parameters:
+                                serverName: postgres
+                                serverPort: '5432'
+                                username: postgres
+                                password: postgres
+                                databaseName: demo
+                                query: >-
+                                  UPDATE parcels set status = 'CANCELED' WHERE
+                                  id = :#id
+                aggregationStrategy: aggregator
+                completionSize: 2
+                correlationExpression:
+                  groovy:
+                    expression: body.get('id')
+          parameters:
+            topic: parcels,payments
+            bootstrapServers: kafka-kafka-bootstrap:9092
+            autoCommitEnable: true
+            consumerGroup: postman
+        id: aggregator
+    - route:
+        from:
+          uri: kamelet:mqtt-source
+          steps:
+            - log:
+                message: 'Delivery: ${body}'
+          parameters:
+            topic: deliveries
+            brokerUrl: tcp://amq-mqtt-0-svc:1883
+    - beans:
+        - name: aggregator
+          type: 
org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy

Reply via email to