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 2019/12/13 08:23:11 UTC
[camel-k] branch master updated (02ef597 -> 91313a3)
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from 02ef597 Fix #1125: fix failing tests
new 08661ff Update to add the saga example
new 91313a3 Update lra-coordinator to 5.9.4.Final by including the fix of JBTM-3118 Add the lra-coordiantor-kub.yaml to use for create the lra-coordinator on kubernetes
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
examples/saga/Flight.java | 48 +++++++++
examples/saga/Payment.java | 51 ++++++++++
examples/saga/Readme.md | 22 ++++
.../SampleKafkaConsumer.java => saga/Saga.java} | 33 +++---
examples/saga/Train.java | 48 +++++++++
examples/saga/lra-coordinator-kub.yaml | 81 +++++++++++++++
examples/saga/lra-coordinator.yaml | 111 +++++++++++++++++++++
7 files changed, 382 insertions(+), 12 deletions(-)
create mode 100644 examples/saga/Flight.java
create mode 100644 examples/saga/Payment.java
create mode 100644 examples/saga/Readme.md
copy examples/{kafka/SampleKafkaConsumer.java => saga/Saga.java} (54%)
create mode 100644 examples/saga/Train.java
create mode 100644 examples/saga/lra-coordinator-kub.yaml
create mode 100644 examples/saga/lra-coordinator.yaml
[camel-k] 02/02: Update lra-coordinator to 5.9.4.Final by including
the fix of JBTM-3118 Add the lra-coordiantor-kub.yaml to use for create the
lra-coordinator on kubernetes
Posted by nf...@apache.org.
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 91313a3aa8584b1d53795f80dfef77610c88df13
Author: Amos Feng <zf...@redhat.com>
AuthorDate: Thu Dec 12 20:52:54 2019 +0800
Update lra-coordinator to 5.9.4.Final by including the fix of JBTM-3118
Add the lra-coordiantor-kub.yaml to use for create the lra-coordinator
on kubernetes
---
examples/saga/Readme.md | 8 +++--
...a-coordinator.yaml => lra-coordinator-kub.yaml} | 40 +++-------------------
examples/saga/lra-coordinator.yaml | 8 ++---
3 files changed, 15 insertions(+), 41 deletions(-)
diff --git a/examples/saga/Readme.md b/examples/saga/Readme.md
index 275524f..5856c85 100644
--- a/examples/saga/Readme.md
+++ b/examples/saga/Readme.md
@@ -1,10 +1,14 @@
# 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
+* Start the lra-coordinator by using the openshift
```
oc create -f lra-coordinator.yaml
```
+* Or start the lra-coordinator by using the kubernetes
+```
+kubectl create -f lra-coordiantor-kub.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
@@ -15,4 +19,4 @@ kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=ca
```
kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Saga.java
```
-Then you can use ```kamel log saga``` to check the output of the transactions.
\ No newline at end of file
+Then you can use ```kamel log saga``` to check the output of the transactions.
diff --git a/examples/saga/lra-coordinator.yaml b/examples/saga/lra-coordinator-kub.yaml
similarity index 66%
copy from examples/saga/lra-coordinator.yaml
copy to examples/saga/lra-coordinator-kub.yaml
index 328879e..c854fc2 100644
--- a/examples/saga/lra-coordinator.yaml
+++ b/examples/saga/lra-coordinator-kub.yaml
@@ -16,7 +16,6 @@ items:
targetPort: 8080
selector:
app: lra-coordinator
- deploymentconfig: lra-coordinator
type: ClusterIP
- apiVersion: v1
kind: PersistentVolumeClaim
@@ -31,27 +30,8 @@ items:
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.8.2.Final
- generation: 0
- importPolicy: {}
- name: "5.8.2.Final"
- referencePolicy:
- type: Source
-- apiVersion: v1
- kind: DeploymentConfig
+- apiVersion: apps/v1
+ kind: Deployment
metadata:
generation: 1
labels:
@@ -61,15 +41,14 @@ items:
spec:
replicas: 1
selector:
- app: lra-coordinator
- deploymentconfig: lra-coordinator
+ matchLabels:
+ app: lra-coordinator
strategy:
type: Recreate
template:
metadata:
labels:
app: lra-coordinator
- deploymentconfig: lra-coordinator
spec:
containers:
- imagePullPolicy: IfNotPresent
@@ -83,6 +62,7 @@ items:
scheme: HTTP
initialDelaySeconds: 180
name: lra-coordinator
+ image: docker.io/jbosstm/lra-coordinator:5.9.4.Final
ports:
- containerPort: 8080
protocol: TCP
@@ -99,13 +79,3 @@ items:
- name: lra-coordinator-data
persistentVolumeClaim:
claimName: lra-coordinator
- triggers:
- - type: ConfigChange
- - imageChangeParams:
- automatic: true
- containerNames:
- - lra-coordinator
- from:
- kind: ImageStreamTag
- name: "lra-coordinator:5.8.2.Final"
- type: ImageChange
\ No newline at end of file
diff --git a/examples/saga/lra-coordinator.yaml b/examples/saga/lra-coordinator.yaml
index 328879e..c59fe26 100644
--- a/examples/saga/lra-coordinator.yaml
+++ b/examples/saga/lra-coordinator.yaml
@@ -44,10 +44,10 @@ items:
tags:
- from:
kind: DockerImage
- name: docker.io/jbosstm/lra-coordinator:5.8.2.Final
+ name: docker.io/jbosstm/lra-coordinator:5.9.4.Final
generation: 0
importPolicy: {}
- name: "5.8.2.Final"
+ name: "5.9.4.Final"
referencePolicy:
type: Source
- apiVersion: v1
@@ -107,5 +107,5 @@ items:
- lra-coordinator
from:
kind: ImageStreamTag
- name: "lra-coordinator:5.8.2.Final"
- type: ImageChange
\ No newline at end of file
+ name: "lra-coordinator:5.9.4.Final"
+ type: ImageChange
[camel-k] 01/02: Update to add the saga example
Posted by nf...@apache.org.
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 08661fffdbfe6aab8cbb53e55dd5b37f80add0bf
Author: Amos Feng <zf...@redhat.com>
AuthorDate: Fri Nov 29 13:53:28 2019 +0800
Update to add the saga example
---
examples/saga/Flight.java | 48 ++++++++++++++++
examples/saga/Payment.java | 51 +++++++++++++++++
examples/saga/Readme.md | 18 ++++++
examples/saga/Saga.java | 41 ++++++++++++++
examples/saga/Train.java | 48 ++++++++++++++++
examples/saga/lra-coordinator.yaml | 111 +++++++++++++++++++++++++++++++++++++
6 files changed, 317 insertions(+)
diff --git a/examples/saga/Flight.java b/examples/saga/Flight.java
new file mode 100644
index 0000000..0810c3c
--- /dev/null
+++ b/examples/saga/Flight.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.SagaPropagation;
+import org.apache.camel.model.rest.RestParamType;
+import org.apache.camel.service.lra.LRASagaService;
+import org.apache.camel.Exchange;
+
+public class Flight extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().port("8080");
+
+ LRASagaService service = new LRASagaService();
+ service.setCoordinatorUrl("http://lra-coordinator:8080");
+ service.setLocalParticipantUrl("http://flight:8080");
+ getContext().addService(service);
+
+ rest("/api").post("/flight/buy")
+ .param().type(RestParamType.header).name("id").required(true).endParam()
+ .route()
+ .saga()
+ .propagation(SagaPropagation.MANDATORY)
+ .option("id", header("id"))
+ .compensation("direct:cancelPurchase")
+ .log("Buying flight #${header.id}")
+ .to("http://payment:8080/api/pay?bridgeEndpoint=true&type=flight")
+ .log("Payment for flight #${header.id} done");
+
+ from("direct:cancelPurchase")
+ .log("Flight purchase #${header.id} has been cancelled");
+ }
+}
diff --git a/examples/saga/Payment.java b/examples/saga/Payment.java
new file mode 100644
index 0000000..a4a866b
--- /dev/null
+++ b/examples/saga/Payment.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.SagaPropagation;
+import org.apache.camel.model.rest.RestParamType;
+import org.apache.camel.service.lra.LRASagaService;
+import org.apache.camel.Exchange;
+
+public class Payment extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().port("8080");
+
+ LRASagaService service = new LRASagaService();
+ service.setCoordinatorUrl("http://lra-coordinator:8080");
+ service.setLocalParticipantUrl("http://payment:8080");
+ getContext().addService(service);
+
+ rest("/api/").post("/pay")
+ .param().type(RestParamType.query).name("type").required(true).endParam()
+ .param().type(RestParamType.header).name("id").required(true).endParam()
+ .route()
+ .saga()
+ .propagation(SagaPropagation.MANDATORY)
+ .option("id", header("id"))
+ .compensation("direct:cancelPayment")
+ .log("Paying ${header.type} for order #${header.id}")
+ .choice()
+ .when(x -> Math.random() >= 0.85)
+ .throwException(new RuntimeException("Random failure during payment"))
+ .end();
+
+ from("direct:cancelPayment")
+ .log("Payment #${header.id} has been cancelled");
+ }
+}
diff --git a/examples/saga/Readme.md b/examples/saga/Readme.md
new file mode 100644
index 0000000..275524f
--- /dev/null
+++ b/examples/saga/Readme.md
@@ -0,0 +1,18 @@
+# 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
+```
+oc create -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
+```
+* Start the saga application
+```
+kamel run -t container.service-port=8080 --dependency=camel-rest --dependency=camel-undertow --dependency=camel-lra examples/saga/Saga.java
+```
+Then you can use ```kamel log saga``` to check the output of the transactions.
\ No newline at end of file
diff --git a/examples/saga/Saga.java b/examples/saga/Saga.java
new file mode 100644
index 0000000..ff127b5
--- /dev/null
+++ b/examples/saga/Saga.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.service.lra.LRASagaService;
+import org.apache.camel.Exchange;
+
+public class Saga extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().port("8080");
+
+ LRASagaService service = new LRASagaService();
+ service.setCoordinatorUrl("http://lra-coordinator:8080");
+ service.setLocalParticipantUrl("http://saga:8080");
+ getContext().addService(service);
+
+ from("timer:clock?period=5s")
+ .saga()
+ .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");
+
+ }
+}
diff --git a/examples/saga/Train.java b/examples/saga/Train.java
new file mode 100644
index 0000000..2c71fc5
--- /dev/null
+++ b/examples/saga/Train.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.SagaPropagation;
+import org.apache.camel.model.rest.RestParamType;
+import org.apache.camel.service.lra.LRASagaService;
+import org.apache.camel.Exchange;
+
+public class Train extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().port("8080");
+
+ LRASagaService service = new LRASagaService();
+ service.setCoordinatorUrl("http://lra-coordinator:8080");
+ service.setLocalParticipantUrl("http://train:8080");
+ getContext().addService(service);
+
+ rest("/api/").post("/train/buy/seat")
+ .param().type(RestParamType.header).name("id").required(true).endParam()
+ .route()
+ .saga()
+ .propagation(SagaPropagation.SUPPORTS)
+ .option("id", header("id"))
+ .compensation("direct:cancelPurchase")
+ .log("Buying train seat #${header.id}")
+ .to("http://payment:8080/api/pay?bridgeEndpoint=true&type=train")
+ .log("Payment for train #${header.id} done");
+
+ from("direct:cancelPurchase")
+ .log("Train purchase #${header.id} has been cancelled");
+ }
+}
diff --git a/examples/saga/lra-coordinator.yaml b/examples/saga/lra-coordinator.yaml
new file mode 100644
index 0000000..328879e
--- /dev/null
+++ b/examples/saga/lra-coordinator.yaml
@@ -0,0 +1,111 @@
+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.8.2.Final
+ generation: 0
+ importPolicy: {}
+ name: "5.8.2.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:
+ 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.8.2.Final"
+ type: ImageChange
\ No newline at end of file