Skip to content

Commit

Permalink
[JBTM-3571] LRA booking quickstart fails during recovery
Browse files Browse the repository at this point in the history
using fixed name for coordinator runner

Simplify LRA quickstart (remove LRA cancellation)

Use the latest narayana version for the lra-coordinator-quarkus
  • Loading branch information
marcosgopen committed Oct 15, 2024
1 parent 1f32612 commit 70a7160
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 106 deletions.
2 changes: 2 additions & 0 deletions rts/lra-examples/coordinator-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-coordinator-jar</artifactId>
<version>${narayana.version}</version>
</dependency>
</dependencies>

<build>
<finalName>lra-coordinator-quarkus</finalName>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
Expand Down
14 changes: 8 additions & 6 deletions rts/lra/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ mvn clean package

start LRA 1
Book hotel
start LRA 2
start LRA 3
start nested LRA 2
Book flight option 1
start LRA 4
start nested LRA 3
Book flight option 2
cancel LRA 3
close LRA 1 (results in the hotel and flight option 2 being confirmed)
cancel LRA 1 (results in the hotel and flights being cancelled)

### Before you start

Obtain and unzip the Narayana distribution containing the LRA coordinator to $NARAYANA_INSTALL_LOCATION
Make sure you export the WORKSPACE variable to the absolute path to the quickstart folder, e.g. 'export WORKSPACE=/user/myuser/quickstart/'.

Make sure you have built the lra-coordinator-quarkus module, it is in $WORKSPACE/rts/lra-examples.



### Make sure the LRA coordinator and various services are running

Expand Down
28 changes: 25 additions & 3 deletions rts/lra/flight-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
</dependencyManagement>

<build>
<finalName>lra-test</finalName>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -79,12 +78,35 @@
<artifactId>narayana-lra</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-service-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-proxy-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- JAXRS 2 Client API implementation -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>test</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
29 changes: 26 additions & 3 deletions rts/lra/hotel-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</dependencies>
</dependencyManagement>
<build>
<finalName>lra-test</finalName>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -72,19 +71,43 @@
<artifactId>narayana-lra</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-service-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-proxy-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- JAX-RS -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
<scope>compile</scope>
</dependency>

<!-- JAXRS 2 Client API implementation -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>test</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
74 changes: 44 additions & 30 deletions rts/lra/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#!/usr/bin/env bash


if [[ ! -v WORKSPACE ]]; then
echo "Please set the WORKSPACE variable to the root folder of the quickstart"
exit -1
fi

if [ ! -f $WORKSPACE/rts/lra-examples/coordinator-quarkus/target/lra-coordinator-quarkus-runner.jar ]; then
echo "Please build first the lra-coordinator-quarkus module which is needed for this demo"
exit -1
fi

function finish {
if ps -p $ID1 > /dev/null
then
Expand All @@ -24,10 +36,6 @@ function finish {
then
kill -9 $ID5
fi

if [ -d "$NARAYANA_INSTALL_LOCATION" ]; then
rm -rf $NARAYANA_INSTALL_LOCATION
fi
}
trap finish EXIT

Expand Down Expand Up @@ -59,32 +67,20 @@ function getDebugArgs {

cd "$( dirname "${BASH_SOURCE[0]}" )"

case "$(uname)" in
CYGWIN*) export NARAYANA_INSTALL_LOCATION=`cygpath -w $(pwd)/narayana-full-7.0.3.Final-SNAPSHOT` ;;
*) export NARAYANA_INSTALL_LOCATION=$(pwd)/narayana-full-7.0.3.Final-SNAPSHOT ;;
esac

rm -rf $NARAYANA_INSTALL_LOCATION
NARAYANA_ZIP="narayana-full-7.0.3.Final-SNAPSHOT-bin.zip"
[ ! -f "$WORKSPACE/$NARAYANA_ZIP" ] &&\
echo "There is no Narayana zip at \$WORKSPACE directory at '$WORKSPACE/$NARAYANA_ZIP" && exit 1
unzip "$WORKSPACE/$NARAYANA_ZIP"

CURL_IP_OPTS=""
IP_OPTS="${IPV6_OPTS}" # use setup of IPv6 if it's defined, otherwise go with IPv4
if [ -z "$IP_OPTS" ]; then
IP_OPTS="-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses"
CURL_IP_OPTS="-4"
fi

echo "Narayana installed location = $NARAYANA_INSTALL_LOCATION"
java ${IP_OPTS} -Dquarkus.http.port=8080 $(getDebugArgs $PORT) -jar $NARAYANA_INSTALL_LOCATION/rts/lra/lra-coordinator-runner.jar &
java ${IP_OPTS} -Dquarkus.http.port=8080 $(getDebugArgs $PORT) -jar $WORKSPACE/rts/lra-examples/coordinator-quarkus/target/lra-coordinator-quarkus-runner.jar &
ID1=$!
((PORT++))
java ${IP_OPTS} -Dquarkus.http.port=8081 $(getDebugArgs $PORT) -jar $NARAYANA_INSTALL_LOCATION/rts/lra/lra-coordinator-runner.jar &
java ${IP_OPTS} -Dquarkus.http.port=8081 $(getDebugArgs $PORT) -jar $WORKSPACE/rts/lra-examples/coordinator-quarkus/target/lra-coordinator-quarkus-runner.jar &
ID2=$!
((PORT++))
java ${IP_OPTS} -Dquarkus.http.port=8082 $(getDebugArgs $PORT) -jar hotel-service/target/quarkus-app/quarkus-run.jar &
java ${IP_OPTS} -Dquarkus.http.port=8082 -Dlra.http.port=8080 $(getDebugArgs $PORT) -jar hotel-service/target/quarkus-app/quarkus-run.jar &
ID3=$!
((PORT++))
java ${IP_OPTS} -Dquarkus.http.port=8083 -Dlra.http.port=8081 $(getDebugArgs $PORT) -jar flight-service/target/quarkus-app/quarkus-run.jar &
Expand All @@ -97,24 +93,42 @@ echo "Narayana installed location = $NARAYANA_INSTALL_LOCATION"
echo "Waiting for all the servers to start"
sleep `timeout_adjust 30 2>/dev/null || echo 30`

mvn -f trip-client/pom.xml exec:java -Dexec.args="${IP_OPTS} confirm"
mvn -f trip-client/pom.xml exec:java -Dexec.args="${IP_OPTS} cancel"
MAVEN_OPTS=${IP_OPTS} mvn -f trip-client/pom.xml exec:java -Dexec.args="confirm"
MAVEN_OPTS=${IP_OPTS} mvn -f trip-client/pom.xml exec:java -Dexec.args="cancel"

echo -e "\n\n\n"
BOOKINGID=$(curl ${CURL_IP_OPTS} -X POST "http://localhost:8084/?hotelName=TheGrand&flightNumber1=BA123&flightNumber2=RH456" -sS | jq -r ".id")
echo "Booking ID was: $BOOKINGID"


###### START not working
#When a coordinator killed and then restarted everything should keep working as usual
#instead when restarting the coordinator the final status of the nested LRAs is not correct
kill -9 $ID1
java ${IP_OPTS} -Dquarkus.http.port=8080 $(getDebugArgs 8787) -jar $NARAYANA_INSTALL_LOCATION/rts/lra/lra-coordinator-runner.jar &
java ${IP_OPTS} -Dquarkus.http.port=8080 $(getDebugArgs 8787) -jar $WORKSPACE/rts/lra-examples/coordinator-quarkus/target/lra-coordinator-quarkus-runner.jar &
ID1=$!
echo "Waiting for all the coordinator to recover"
sleep `timeout_adjust 40 2>/dev/null || echo 40`
echo -e "\n\n\n"
########## END not working

echo "Waiting for all coordinators to recover"

sleep 40
echo -e "\n\n\n"
set +x
echo "Confirming with curl ${CURL_IP_OPTS} -X PUT http://localhost:8084/`urlencode $BOOKINGID`"
curl ${CURL_IP_OPTS} -X PUT http://localhost:8084/`urlencode $BOOKINGID`
echo ""
set -x

[ $DEBUG ] && echo "Processes are still running ($ID1 $ID2 $ID3 $ID4 $ID5) press any key to end them" && read
echo "Cancelling with curl ${CURL_IP_OPTS} -X DELETE http://localhost:8084/`urlencode $BOOKINGID`"
BOOKINIDENCODED=`urlencode $BOOKINGID`
set -x
echo $BOOKINIDENCODED
RESPONSE=$(curl ${CURL_IP_OPTS} -X DELETE http://localhost:8084/$BOOKINIDENCODED -sS)
echo -e "\nresponse is: \n $RESPONSE\n"

STATUS=$(echo $RESPONSE | jq -r ".status")
if [ "$STATUS" != "CANCELLED" ]; then
echo "The status is not 'CANCELLED': $STATUS"
exit -1
fi

if [ "$DEBUG" ]; then
echo "Processes are still running ($ID1 $ID2 $ID3 $ID4 $ID5) press any key to end them"
read
fi
18 changes: 17 additions & 1 deletion rts/lra/trip-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<version>3.1.0</version>
<configuration>
<mainClass>TripClient</mainClass>
</configuration>
Expand All @@ -41,11 +41,27 @@
<artifactId>narayana-lra</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-service-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-proxy-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- JAXRS 2 Client API implementation -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
28 changes: 25 additions & 3 deletions rts/lra/trip-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
</dependencyManagement>

<build>
<finalName>lra-test</finalName>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -77,6 +76,21 @@
<artifactId>narayana-lra</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-service-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>lra-proxy-api</artifactId>
<version>${project.version}</version>
</dependency>

<!-- JAX-RS -->
<dependency>
Expand All @@ -89,8 +103,16 @@
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${version.resteasy}</version>
<scope>test</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import jakarta.ws.rs.core.Response;
import java.util.Arrays;

import com.fasterxml.jackson.core.JsonProcessingException;

/**
* For testing - verify that the business data returned when ending an LRA is the same as that returned by directly
* interrogating each sra.demo.service involved in the booking
Expand Down Expand Up @@ -37,14 +39,27 @@ static boolean validateBooking(Booking booking, boolean isConfirm, WebTarget hot
});

if (isConfirm) {
// the hotel and only one of the flight bookings should be confirmed
if (confirmCount[0] != 2 || cancelCount[0] != 1) {
System.out.printf("TripCheck: validateBooking: the hotel and only one of the flight bookings should have been confirmed%n");
if (confirmCount[0] != 3) {
try {
System.out.println(
"TripCheck: validateBooking: the hotel and 2 flight bookings should have been confirmed, but are "
+ confirmCount[0] + "\n" + booking.toJson());
}
catch (JsonProcessingException e) {
e.printStackTrace();
}
return false;
}
} else {
if (cancelCount[0] != 3) {
System.out.printf("TripCheck: validateBooking: the hotel and both flight bookings should have be cancelled%n");
try {
System.out.println(
"TripCheck: validateBooking: the hotel and both flight bookings should have been cancelled, but are "
+ cancelCount[0] + "\n" + booking.toJson());
}
catch (JsonProcessingException e) {
e.printStackTrace();
}
return false;
}
}
Expand Down
Loading

0 comments on commit 70a7160

Please sign in to comment.