You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2020/03/17 17:03:57 UTC

[camel-k] 01/02: Fix #1304: fix the saga example to use default ports

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

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 741ad1bfa436f7f6244436f4e720f4a66bfcb6fc
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Mon Mar 2 12:04:19 2020 +0100

    Fix #1304: fix the saga example to use default ports
---
 examples/saga/Flight.java              |   6 +-
 examples/saga/Payment.java             |   4 +-
 examples/saga/Readme.md                |  46 ++++++--
 examples/saga/Saga.java                |   8 +-
 examples/saga/Train.java               |   6 +-
 examples/saga/lra-coordinator-kub.yaml |  98 -----------------
 examples/saga/lra-coordinator.yaml     | 188 ++++++++++++++-------------------
 7 files changed, 127 insertions(+), 229 deletions(-)

diff --git a/examples/saga/Flight.java b/examples/saga/Flight.java
index 0810c3c..f883678 100644
--- a/examples/saga/Flight.java
+++ b/examples/saga/Flight.java
@@ -27,8 +27,8 @@ public class Flight extends RouteBuilder {
                 restConfiguration().port("8080");
 
 		LRASagaService service = new LRASagaService();
-		service.setCoordinatorUrl("http://lra-coordinator:8080");
-		service.setLocalParticipantUrl("http://flight:8080");
+		service.setCoordinatorUrl("http://lra-coordinator");
+		service.setLocalParticipantUrl("http://flight");
 		getContext().addService(service);
 
 		rest("/api").post("/flight/buy")
@@ -39,7 +39,7 @@ public class Flight extends RouteBuilder {
 				.option("id", header("id"))
 				.compensation("direct:cancelPurchase")
 			.log("Buying flight #${header.id}")
-			.to("http://payment:8080/api/pay?bridgeEndpoint=true&type=flight")
+			.to("undertow:http://payment/api/pay?bridgeEndpoint=true&type=flight")
 			.log("Payment for flight #${header.id} done");
 
 		from("direct:cancelPurchase")
diff --git a/examples/saga/Payment.java b/examples/saga/Payment.java
index a4a866b..8a6e35f 100644
--- a/examples/saga/Payment.java
+++ b/examples/saga/Payment.java
@@ -27,8 +27,8 @@ public class Payment extends RouteBuilder {
                 restConfiguration().port("8080");
 
 		LRASagaService service = new LRASagaService();
-		service.setCoordinatorUrl("http://lra-coordinator:8080");
-		service.setLocalParticipantUrl("http://payment:8080");
+		service.setCoordinatorUrl("http://lra-coordinator");
+		service.setLocalParticipantUrl("http://payment");
 		getContext().addService(service);
 
 		rest("/api/").post("/pay")
diff --git a/examples/saga/Readme.md b/examples/saga/Readme.md
index 5856c85..127ef99 100644
--- a/examples/saga/Readme.md
+++ b/examples/saga/Readme.md
@@ -1,22 +1,48 @@
 # Saga example
-This example is from [camel-saga-quickstart](https://github.com/nicolaferraro/camel-saga-quickstart/) and could work with the camel-k.
 
-* Start the lra-coordinator by using the openshift
+This example is from [camel-saga-quickstart](https://github.com/nicolaferraro/camel-saga-quickstart/) adapted to work with camel-k.
+
+Make sure Camel K is installed in your namespace, or execute the following command to install it:
+
 ```
-oc create -f lra-coordinator.yaml
+kamel install
 ```
-* Or start the lra-coordinator by using the kubernetes
+
+* Start the lra-coordinator by using the `oc` or `kubectl` tool:
 ```
-kubectl create -f lra-coordiantor-kub.yaml
+kubectl apply -f lra-coordinator.yaml
 ```
+
 * Start the three demo services
 ```
-kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Flight.java
-kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Train.java
-kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Payment.java
+kamel run -d camel-undertow -d camel-lra Payment.java
+kamel run -d camel-lra Flight.java
+kamel run -d camel-lra Train.java
 ```
+
 * Start the saga application
 ```
-kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Saga.java
+kamel run -d camel-lra -t service.auto=false Saga.java
+```
+
+Then you can use ```kamel logs saga``` to check the output of the transactions.
+
+Focusing on one of the services, e.g. the flight service, you will notice that when unexpected events are found,
+the operation is subsequently cancelled, e.g.:
+
+E.g. running:
+```
+kamel logs flight
+```
+
+Possible workflow:
+```
+flight-7c8df48b88-6pzwt integration 2020-03-02 10:56:30.148 INFO  [default-workqueue-2] route2 - Buying flight #18
+flight-7c8df48b88-6pzwt integration 2020-03-02 10:56:30.165 ERROR [XNIO-1 I/O-1] DefaultErrorHandler - Failed delivery for (MessageId: ID-flight-7c8df48b88-6pzwt-1583146351094-0-106 on ExchangeId: ID-flight-7c8df48b88-6pzwt-1583146351094-0-105). Exhausted after delivery attempt: 1 caught: org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://payment/api/pay?bridgeEndpoint=true&type=flight with statusCode: 500
+...
+# after stacktrace
+...
+flight-7c8df48b88-6pzwt integration 2020-03-02 10:56:30.256 INFO  [XNIO-2 task-6] route1 - Flight purchase #18 has been cancelled
+flight-7c8df48b88-6pzwt integration 2020-03-02 10:56:35.150 INFO  [default-workqueue-3] route2 - Buying flight #19
+flight-7c8df48b88-6pzwt integration 2020-03-02 10:56:35.197 INFO  [XNIO-1 I/O-1] route2 - Payment for flight #19 done
 ```
-Then you can use ```kamel log saga``` to check the output of the transactions.
diff --git a/examples/saga/Saga.java b/examples/saga/Saga.java
index b37827c..5a97d8d 100644
--- a/examples/saga/Saga.java
+++ b/examples/saga/Saga.java
@@ -25,8 +25,8 @@ public class Saga extends RouteBuilder {
                 restConfiguration().port("8080");
 
 		LRASagaService service = new LRASagaService();
-		service.setCoordinatorUrl("http://lra-coordinator:8080");
-		service.setLocalParticipantUrl("http://saga:8080");
+		service.setCoordinatorUrl("http://lra-coordinator");
+		service.setLocalParticipantUrl("http://saga");
 		getContext().addService(service);
 
 		from("timer:clock?period=5000")
@@ -34,8 +34,8 @@ public class Saga extends RouteBuilder {
 			.setHeader("id", header(Exchange.TIMER_COUNTER))
 			.setHeader(Exchange.HTTP_METHOD, constant("POST"))
 			.log("Executing saga #${header.id}")
-			.to("http://train:8080/api/train/buy/seat")
-			.to("http://flight:8080/api/flight/buy");
+			.to("undertow:http://train/api/train/buy/seat")
+			.to("undertow:http://flight/api/flight/buy");
 
 	}
 }
diff --git a/examples/saga/Train.java b/examples/saga/Train.java
index 2c71fc5..c4613d3 100644
--- a/examples/saga/Train.java
+++ b/examples/saga/Train.java
@@ -27,8 +27,8 @@ public class Train extends RouteBuilder {
                 restConfiguration().port("8080");
 
 		LRASagaService service = new LRASagaService();
-		service.setCoordinatorUrl("http://lra-coordinator:8080");
-		service.setLocalParticipantUrl("http://train:8080");
+		service.setCoordinatorUrl("http://lra-coordinator");
+		service.setLocalParticipantUrl("http://train");
 		getContext().addService(service);
 
 		rest("/api/").post("/train/buy/seat")
@@ -39,7 +39,7 @@ public class Train extends RouteBuilder {
                         .option("id", header("id"))
                         .compensation("direct:cancelPurchase")
                     .log("Buying train seat #${header.id}")
-                    .to("http://payment:8080/api/pay?bridgeEndpoint=true&type=train")
+                    .to("undertow:http://payment/api/pay?bridgeEndpoint=true&type=train")
                     .log("Payment for train #${header.id} done");
 
                from("direct:cancelPurchase")
diff --git a/examples/saga/lra-coordinator-kub.yaml b/examples/saga/lra-coordinator-kub.yaml
deleted file mode 100644
index f43d413..0000000
--- a/examples/saga/lra-coordinator-kub.yaml
+++ /dev/null
@@ -1,98 +0,0 @@
-# ---------------------------------------------------------------------------
-# 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.
-# ---------------------------------------------------------------------------
-
-apiVersion: v1
-kind: List
-items:
-- apiVersion: v1
-  kind: Service
-  metadata:
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    ports:
-    - name: 8080-tcp
-      port: 8080
-      protocol: TCP
-      targetPort: 8080
-    selector:
-      app: lra-coordinator
-    type: ClusterIP
-- apiVersion: v1
-  kind: PersistentVolumeClaim
-  metadata:
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    accessModes:
-    - ReadWriteOnce
-    resources:
-      requests:
-        storage: 200Mi
-- apiVersion: apps/v1
-  kind: Deployment
-  metadata:
-    generation: 1
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    replicas: 1
-    selector:
-      matchLabels:
-        app: lra-coordinator
-    strategy:
-      type: Recreate
-    template:
-      metadata:
-        labels:
-          app: lra-coordinator
-      spec:
-        containers:
-        - imagePullPolicy: IfNotPresent
-          env:
-          - name: AB_JOLOKIA_OFF
-            value: "true"
-          livenessProbe:
-            httpGet:
-              path: /lra-coordinator
-              port: 8080
-              scheme: HTTP
-            initialDelaySeconds: 180
-          name: lra-coordinator
-          image: docker.io/jbosstm/lra-coordinator:5.9.4.Final
-          ports:
-          - containerPort: 8080
-            protocol: TCP
-          readinessProbe:
-            httpGet:
-              path: /lra-coordinator
-              port: 8080
-              scheme: HTTP
-            initialDelaySeconds: 10
-          volumeMounts:
-          - mountPath: /data
-            name: lra-coordinator-data
-        volumes:
-        - name: lra-coordinator-data
-          persistentVolumeClaim:
-            claimName: lra-coordinator
diff --git a/examples/saga/lra-coordinator.yaml b/examples/saga/lra-coordinator.yaml
index 8dcc9fe..ef28c9f 100644
--- a/examples/saga/lra-coordinator.yaml
+++ b/examples/saga/lra-coordinator.yaml
@@ -15,114 +15,84 @@
 # limitations under the License.
 # ---------------------------------------------------------------------------
 
+
 apiVersion: v1
-kind: List
-items:
-- apiVersion: v1
-  kind: Service
-  metadata:
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    ports:
-    - name: 8080-tcp
-      port: 8080
-      protocol: TCP
-      targetPort: 8080
-    selector:
-      app: lra-coordinator
-      deploymentconfig: lra-coordinator
-    type: ClusterIP
-- apiVersion: v1
-  kind: PersistentVolumeClaim
-  metadata:
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    accessModes:
-    - ReadWriteOnce
-    resources:
-      requests:
-        storage: 200Mi
-- apiVersion: v1
-  kind: ImageStream
-  metadata:
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    lookupPolicy:
-      local: true
-    tags:
-    - from:
-        kind: DockerImage
-        name: docker.io/jbosstm/lra-coordinator:5.9.4.Final
-      generation: 0
-      importPolicy: {}
-      name: "5.9.4.Final"
-      referencePolicy:
-        type: Source
-- apiVersion: v1
-  kind: DeploymentConfig
-  metadata:
-    generation: 1
-    labels:
-      app: lra-coordinator
-      template: lra-coordinator
-    name: lra-coordinator
-  spec:
-    replicas: 1
-    selector:
+kind: Service
+metadata:
+  labels:
+    app: lra-coordinator
+    template: lra-coordinator
+  name: lra-coordinator
+spec:
+  ports:
+  - name: http
+    port: 80
+    protocol: TCP
+    targetPort: 8080
+  selector:
+    app: lra-coordinator
+  type: ClusterIP
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  labels:
+    app: lra-coordinator
+    template: lra-coordinator
+  name: lra-coordinator
+spec:
+  accessModes:
+  - ReadWriteOnce
+  resources:
+    requests:
+      storage: 200Mi
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  generation: 1
+  labels:
+    app: lra-coordinator
+    template: lra-coordinator
+  name: lra-coordinator
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
       app: lra-coordinator
-      deploymentconfig: lra-coordinator
-    strategy:
-      type: Recreate
-    template:
-      metadata:
-        labels:
-          app: lra-coordinator
-          deploymentconfig: lra-coordinator
-      spec:
-        containers:
-        - imagePullPolicy: IfNotPresent
-          env:
-          - name: AB_JOLOKIA_OFF
-            value: "true"
-          livenessProbe:
-            httpGet:
-              path: /lra-coordinator
-              port: 8080
-              scheme: HTTP
-            initialDelaySeconds: 180
-          name: lra-coordinator
-          ports:
-          - containerPort: 8080
-            protocol: TCP
-          readinessProbe:
-            httpGet:
-              path: /lra-coordinator
-              port: 8080
-              scheme: HTTP
-            initialDelaySeconds: 10
-          volumeMounts:
-          - mountPath: /data
-            name: lra-coordinator-data
-        volumes:
-        - name: lra-coordinator-data
-          persistentVolumeClaim:
-            claimName: lra-coordinator
-    triggers:
-    - type: ConfigChange
-    - imageChangeParams:
-        automatic: true
-        containerNames:
-        - lra-coordinator
-        from:
-          kind: ImageStreamTag
-          name: "lra-coordinator:5.9.4.Final"
-      type: ImageChange
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      labels:
+        app: lra-coordinator
+    spec:
+      containers:
+      - imagePullPolicy: IfNotPresent
+        env:
+        - name: AB_JOLOKIA_OFF
+          value: "true"
+        livenessProbe:
+          httpGet:
+            path: /lra-coordinator
+            port: 8080
+            scheme: HTTP
+          initialDelaySeconds: 180
+        name: lra-coordinator
+        image: docker.io/jbosstm/lra-coordinator:5.9.8.Final
+        ports:
+        - containerPort: 8080
+          protocol: TCP
+        readinessProbe:
+          httpGet:
+            path: /lra-coordinator
+            port: 8080
+            scheme: HTTP
+          initialDelaySeconds: 10
+        volumeMounts:
+        - mountPath: /data
+          name: lra-coordinator-data
+      volumes:
+      - name: lra-coordinator-data
+        persistentVolumeClaim:
+          claimName: lra-coordinator