Skip to content

Commit 86815c5

Browse files
saga ws mods (#313)
* observability work * observability work * observability work * observability work * observability work * observability work * observability work * observability work * observability work * observability work * observability work * dotnet work * dotnet work * dotnet work * dotnet work * dotnet work * observability, dotnet, go, etc. work - move kafka etc. build to nonjava * observability, dotnet, go, etc. work - move kafka etc. build to nonjava * observability, dotnet, go, etc. work - move kafka etc. build to nonjava * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * enable teq * observability * enable teq * enable teq * enable teq * enable teq * enable teq * observability work * observability work * enable teq * enable teq * enable teq * observ * enable teq * observability dash * observability * osbservability * enable teq * enable teq * enable teq * obs * obs * enable teq * obs * enable teq * observ * obs * converged wording change * fix k6 command * correct workshop link * update workshop link * modifiy python impl to conn.autocommit = False * enable teq * various including security fix in inventory-nodejs * various including security fix in inventory-nodejs * various including security fix in inventory-nodejs * enable teq * inventory-micronaut * inventory-micronaut * inventory-quarkus * inventory-micronaut-native-image * upgrade helidon and db versions * mn and quarkus build wrappers * mn native-image build and deploy fixes * mn native-image build and deploy fixes * mn native-image use JsonObject instead of Jackson * dotnet vault work, etc. * vault work, various languages * Go OCI Vault/Secrets client * displaysetuplogs util script * displaysetuplogs util script * displaysetuplogs util script * displaysetuplogs util script * createsecretfromwallet * createsecretfromwallet * createsecretfromwallet * set order and inventory helidon versions back to 2.4.0 * travelagency readme * createsecretfromwallet * temp eventmesh and osaga java api * travelagencysaga * observability workshop and various fixes * travelagency saga ws work * saga ws work * saga ws * saga ws * saga ws * saga ws * saga ws * osaga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * obs ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws * saga ws
1 parent a610b95 commit 86815c5

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

travelbooking/installGraalVM.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Copyright (c) 2021 Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
curl -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz | tar xz
6+
mv graalvm-ce-java11-20.1.0 ~/

travelbooking/travelagency-java/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
</plugins>
7878
</build>
7979
<dependencies>
80+
<dependency>
81+
<groupId>org.json</groupId>
82+
<artifactId>json</artifactId>
83+
<version>20211205</version>
84+
</dependency>
8085
<dependency>
8186
<groupId>javax.jms</groupId>
8287
<artifactId>javax.jms-api</artifactId>

travelbooking/travelagency-java/src/main/java/osaga/travelagency/TravelAgencyApplication.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
import oracle.ucp.jdbc.PoolDataSource;
55
import oracle.ucp.jdbc.PoolDataSourceFactory;
66

7-
import javax.jms.JMSException;
8-
import java.io.IOException;
97
import java.nio.file.Path;
108
import java.nio.file.Paths;
119
import java.sql.CallableStatement;
1210
import java.sql.Connection;
13-
import java.util.HashMap;
14-
import java.util.Map;
11+
12+
import org.json.*;
1513

1614
import static java.lang.System.*;
1715

1816

1917
public class TravelAgencyApplication {
2018

21-
Map<String, TravelBookingSaga> sagaParticipantReplies = new HashMap();
22-
2319
public static void main(String[] args) throws Exception {
2420
setProperty("oracle.jdbc.fanEnabled", "false");
2521
new TravelAgencyApplication().bookTravel();
2622
}
2723

24+
//very simple single requests (ie does not support concurrent requests)
25+
String flightStatus = "", hotelStatus = "", carStatus = "";
26+
2827
public void bookTravel() throws Exception {
2928
//Get all values...
3029
String password = PromptUtil.getValueFromPromptSecure("Enter password", null);
@@ -64,12 +63,11 @@ public void bookTravel() throws Exception {
6463
runSaga(initiator, saga);
6564
}
6665

67-
private void runSaga(String initiator, AQjmsSaga saga) throws JMSException, IOException {
66+
private void runSaga(String initiator, AQjmsSaga saga) throws Exception {
6867
out.println("Beginning saga...");
6968
String sagaId = saga.beginSaga(initiator);
7069
out.println("Saga begun sagaId:" + sagaId);
7170

72-
//Prompt for coordinator...
7371
// String coordinator = PromptUtil.getValueFromPrompt("Enter coordinator name", "TravelCoordinator");
7472
String coordinator = "TravelCoordinator";
7573

@@ -82,33 +80,44 @@ private void runSaga(String initiator, AQjmsSaga saga) throws JMSException, IOEx
8280
String payload = "[{\"flight\" : \"myflight\"}]";
8381
out.println("Enrolling Flight(Java) participant in sagaId:" + sagaId);
8482
saga.enrollParticipant(sagaId, "admin", initiator, "FlightJava", coordinator, payload);
83+
flightStatus = "waitingforreply";
8584
}
8685
if (isAddHotel) {
8786
String payload = "[{\"hotel\" : \"myhotel\"}]";
8887
out.println("Enrolling Hotel(Java) participant in sagaId:" + sagaId);
8988
saga.enrollParticipant(sagaId, "admin", initiator, "HotelJava", coordinator, payload);
89+
hotelStatus = "waitingforreply";
9090
}
9191
if (isAddCar) {
9292
String payload = "[{\"car\" : \"mycar\"}]";
9393
out.println("Enrolling Car(Java) participant in sagaId:" + sagaId);
9494
saga.enrollParticipant(sagaId, "admin", initiator, "CarJava", coordinator, payload);
95+
carStatus = "waitingforreply";
96+
}
97+
boolean isAllRepliesReceived = false;
98+
while (flightStatus.equals("waitingforreply") || hotelStatus.equals("waitingforreply") || carStatus.equals("waitingforreply")) {
99+
Thread.sleep(3 * 1000);
95100
}
96-
97-
//todo wait/poll for all replies
98-
out.println("----> Hit enter once all replies are received ");
99-
in.read();
100101
String commitOrRollback = PromptUtil.getValueFromPrompt("Commit or Rollback Saga? (c or r)", "r");
101102
if (commitOrRollback.equalsIgnoreCase("c")) {
102103
log("about to commit");
103104
saga.commitSaga(sagaId, initiator);
104105
log("finished commit");
106+
createParticipantStatesForSagaId(sagaId);
105107
} else {
106108
log("about to rollback");
107109
saga.rollbackSaga(sagaId, initiator);
108110
log("finished rollback");
111+
createParticipantStatesForSagaId(sagaId);
109112
}
110113
}
111114

115+
private void createParticipantStatesForSagaId(String sagaId) {
116+
flightStatus = "";
117+
hotelStatus = "";
118+
carStatus = "";
119+
}
120+
112121

113122
public class TravelAgencyTestListener extends AQjmsSagaMessageListener{
114123

@@ -119,15 +128,11 @@ public String request(String sagaId, String payload) {
119128

120129
@Override
121130
public void response(String sagaId, String payload) {
122-
err.println(payload);
123-
out.println("Got re!");
124-
synchronized (sagaParticipantReplies) {
125-
TravelBookingSaga travelBookingSaga = sagaParticipantReplies.get(sagaId);
126-
if (travelBookingSaga == null) {
127-
TravelBookingSaga newTravelBookingSaga = new TravelBookingSaga();
128-
newTravelBookingSaga.carStatus = payload;
129-
}
130-
}
131+
out.println("Response received:" + payload);
132+
JSONObject obj = new JSONObject(payload);
133+
if (obj.getString("HotelJava") != null) hotelStatus = "replyReceived";
134+
else if (obj.getString("CarJava") != null) carStatus = "replyReceived";
135+
else if (obj.getString("FlightJava") != null) flightStatus = "replyReceived";
131136
}
132137

133138
@Override
@@ -153,10 +158,6 @@ public void afterRollback(String sagaId) {
153158
}
154159

155160

156-
class TravelBookingSaga {
157-
String hotelStatus, carStatus, flightStatus;
158-
}
159-
160161
void log (String msg) {
161162
out.println("TravelAgencyApplication.log msg:" + msg);
162163
}

travelbooking/travelparticipant-java/src/main/java/osaga/travelagency/TravelParticipantApplication.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import AQSaga.AQjmsSagaMessageListener;
55
import oracle.ucp.jdbc.PoolDataSource;
66
import oracle.ucp.jdbc.PoolDataSourceFactory;
7-
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8-
//import org.springframework.boot.autoconfigure.SpringBootApplication;
9-
//import org.springframework.context.annotation.ComponentScan;
10-
//import org.springframework.context.annotation.Configuration;
117

128
import java.nio.file.Path;
139
import java.nio.file.Paths;
@@ -16,12 +12,10 @@
1612

1713
import static java.lang.System.out;
1814

19-
//@Configuration
20-
//@EnableAutoConfiguration
21-
//@ComponentScan
22-
//@SpringBootApplication
2315
public class TravelParticipantApplication {
2416

17+
String participant;
18+
2519
public static void main(String[] args) throws Exception {
2620
System.setProperty("oracle.jdbc.fanEnabled", "false");
2721
new TravelParticipantApplication().participate();
@@ -37,7 +31,7 @@ public void participate() throws Exception {
3731
String user = "admin";
3832
out.println("TravelParticipantApplication jdbcUrl:" + jdbcUrl);
3933

40-
String participant = PromptUtil.getValueFromPrompt("Enter participant type (1) HotelJava, (2) CarJava, or (3) FlightJava", "1");
34+
participant = PromptUtil.getValueFromPrompt("Enter participant type (1) HotelJava, (2) CarJava, or (3) FlightJava", "1");
4135
if (participant.equalsIgnoreCase("2")) participant = "CarJava";
4236
else if (participant.equalsIgnoreCase("3")) participant = "FlightJava";
4337
else participant = "HotelJava";
@@ -77,9 +71,9 @@ public String request(String sagaId, String payload) {
7771
System.out.println("request called sagaId = " + sagaId + ", payload = " + payload);
7872
System.out.println("Tickets remaining : " + --tickets);
7973
if(tickets >= 0)
80-
return "[{\"result\":\"success\"}]";
74+
return "{\"" + participant + "\":\"success\"}";
8175
else
82-
return "[{\"result\":\"failure\"}]";
76+
return "{\"" + participant + "\":\"failed\"}";
8377
}
8478

8579
@Override

0 commit comments

Comments
 (0)