-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrunme.sh
More file actions
executable file
·1603 lines (1483 loc) · 71.7 KB
/
Copy pathrunme.sh
File metadata and controls
executable file
·1603 lines (1483 loc) · 71.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
GREEN="$(tput setaf 2)"
RED="$(tput setaf 1)"
DEFAULT_VERSION="1.0-SNAPSHOT"
VERSION="${VERSION:-$DEFAULT_VERSION}"
PIDS=()
DASHBOARD_PIDS=()
MICROTX_INPUT_FILE="microtx_runme_history.log"
IS_SE_LINUX=false
CONTAINER_LOCAL_HOST="host.docker.internal"
MICROTX_DOCKER_IMAGE="container-registry.oracle.com/database/otmm:latest"
DISTRIBUTION_PACKAGE_PATH=false
DISTRIBUTION_PACKAGE_LINK="https://www.oracle.com/database/technologies/transaction-manager-for-microservices-downloads.html"
# Uncomment this if the env is Mac with Rancher desktop and podman
COORDINATOR_DOCKER_NETWORK_MODE="host"
printf "${GREEN}\n*************************\n\n Use this script to run microservices and get started with Oracle Transaction Manager for Microservices.\n
*************************\n"
cli_exists() {
command -v "$1" >/dev/null 2>&1
}
#/**
# docker -> run the microtx free with the default settign
# minikube -> basic yaml microtx free -> create a mini yaml for minikube -> direct yaml deployement
# -> ask for the distribution package realtive path
# K8s-> Ask for the distribution package realtive path
# {
# otmm distribution package - > path
#
# }
#*/
handle_environment_prerequisites() {
if [ $environment == 2 ]; then
printf "${GREEN}\nSetting up the minikube environment. Memory = 6114 and CPUs = 4"
sleep 5
minikube config set memory 6114
minikube config set cpus 4
printf "${GREEN}\nStarting minikube.\n"
export KUBECONFIG=$HOME/.kube/minikube
minikube start
eval $(minikube docker-env)
fi
}
delete_certificates() {
kubectl delete -n istio-system secret tls-credential
rm -rf $ROOT/certificates
runkeytool=/tmp/runkeytool.sh
cat << EOF > $runkeytool
#!/bin/bash
export JAVA_HOME=$JAVA_HOME
export PATH=${PATH}
keytool -delete -trustcacerts -alias tmm-dev -keystore $JAVA_HOME/lib/security/cacerts
keytool -delete -trustcacerts -alias demo-tmm-dev -keystore $JAVA_HOME/lib/security/cacerts
EOF
chmod +x $runkeytool
sudo $runkeytool
rm $runkeytool
}
create_certificates() {
mkdir $ROOT/certificates
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj '/O=tmm.dev Inc./CN=tmm.dev' -keyout $ROOT/certificates/tmm.dev.key -out $ROOT/certificates/tmm.dev.crt
openssl req -newkey rsa:2048 -nodes -subj "/CN=demo.tmm.dev/O=hello world from tmm.dev" -keyout $ROOT/certificates/demo.tmm.dev.key -out $ROOT/certificates/demo.tmm.dev.csr
openssl x509 -req -days 365 -CA $ROOT/certificates/tmm.dev.crt -CAkey $ROOT/certificates/tmm.dev.key -set_serial 0 -in $ROOT/certificates/demo.tmm.dev.csr -out $ROOT/certificates/demo.tmm.dev.crt
runkeytool=/tmp/runkeytool.sh
cat << EOF > $runkeytool
#!/bin/bash
export JAVA_HOME=$JAVA_HOME
export PATH=$PATH
# echo "$istio_ip demo.tmm.dev" | sudo tee -a /etc/hosts
if grep -q "$istio_ip demo.tmm.dev" "/etc/hosts"; then
echo "entry '$istio_ip demo.tmm.dev' already exist in /etc/hosts"
else
echo "$istio_ip demo.tmm.dev" | sudo tee -a /etc/hosts
fi
keytool -import -trustcacerts -alias tmm-dev -file $ROOT/certificates/tmm.dev.crt -keystore $JAVA_HOME/lib/security/cacerts
# sudo -E keytool -import -trustcacerts -alias tmm-dev-pem -file $ROOT/certificates/tmm.dev.pem -keystore $JAVA_HOME/lib/security/cacerts
keytool -import -trustcacerts -alias demo-tmm-dev -file $ROOT/certificates/demo.tmm.dev.crt -keystore $JAVA_HOME/lib/security/cacerts
# sudo -E keytool -import -trustcacerts -alias demo-tmm-dev-pem -file $ROOT/certificates/demo.tmm.dev.pem -keystore $JAVA_HOME/lib/security/cacerts
EOF
chmod +x $runkeytool
sudo $runkeytool
rm $runkeytool
kubectl create -n istio-system secret tls tls-credential --key=$ROOT/certificates/demo.tmm.dev.key --cert=$ROOT/certificates/demo.tmm.dev.crt
}
install_istio() {
if [ $environment == 2 ] || [ $environment == 3 ]; then
sleep 3
namespaceStatus=$(kubectl get ns istio-system -o json)
if [[ ! -z "$namespaceStatus" ]]; then
printf "${GREEN}\nIstio is already present in the system. Skipping the installation of istio."
else
printf "${GREEN}\nIstio is not installed in the cluster. Installing istio."
istioctl install --set meshConfig.accessLogFile=/dev/stdout --set meshConfig.accessLogEncoding=JSON --set meshConfig.enableTracing=true --set meshConfig.defaultConfig.tracing.sampling=100.0 --set components.cni.enabled=true -y
fi
if [ $environment == 2 ]; then
printf "${GREEN}\n\n*************************\n"
printf "${GREEN}\nOpen a new terminal, and then run the following commands."
printf "${GREEN}\n1. 'export KUBECONFIG=$HOME/.kube/minikube' - To set kubectl to execute commands on minikube"
printf "${GREEN}\n2. 'minikube tunnel' - To start a tunnel to Istio ingress gateway. If prompted for password, enter the system password."
printf "${GREEN}\n\nOnce the steps are completed, press enter key to continue"
read proceed
fi
declare -i sleep_time=5
while [[ -z "$istio_ip" ]]
do
if [[ $sleep_time -gt 1800 ]]; then
printf "${RED}Error: Istio-ingressgateway loadbancer is not provisioned."
clean_up "n" "y" "y"
fi
printf "${GREEN}\nWaiting for Istio-ingressgateway loadbancer to be provisioned. Will try again in $sleep_time seconds."
sleep $sleep_time
istio_ip=$(kubectl get service -n istio-system istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
sleep_time=`expr $sleep_time \* 2`
done
istio_url="http://$istio_ip:80"
if [ $environment == 3 ]; then
printf "${GREEN}\nCreating a self signed certificate to enable TLS connection to transaction coordinator."
printf "${GREEN}\nEnter the system/keytool password when prompted. This is required to connect to transaction coordinator running on TLS and hence the certificates should be trusted."
printf "${GREEN}\nPreceding command requires sudo access. On password prompt, please enter sudo user password.\n"
delete_certificates
create_certificates
istio_url="https://demo.tmm.dev:443"
fi
printf "${GREEN}\nIstio-ingressgateway url is $istio_url"
fi
}
install_istio_dashboards() {
if [ $environment == 3 ]; then
if [ -z "$(kubectl get pods -n istio-system --selector='app in (kiali,jaeger)' -o jsonpath='{.items[*].status.phase}')" ]; then
sleep 2
printf "${GREEN}\nDo you want to install dashboards to visualize applications deployed on istio mesh ?\n"
select yn in "Yes" "No"; do
case $yn in
Yes )
printf "${GREEN}Fetching installed istio version\n"
istio_version=$(istioctl version -o json | jq -r ".meshVersion[0].Info.version")
istio_major_version=$(echo $(istioctl version -o json | jq -r ".meshVersion[0].Info.version") | awk -F'.' '{printf "%s.%s" , $1,$2}')
printf "${GREEN}Installed istio version is ${istio_version} and major version is ${istio_major_version}\n"
printf "${GREEN}\nDo you want to deploy Kiali ?\n";
select yn in "Yes" "No"; do
case $yn in
Yes )
kialiDeploymentName=$(kubectl get deployment -n istio-system --selector=app=kiali -o jsonpath='{.items[*].metadata.name}')
if [[ ! -z "$kialiDeploymentName" ]]; then
printf "${GREEN}Kiali is already installed on istio-system namespace.\n";
else
install_prometheus ${istio_major_version}
printf "${GREEN}Deploying Kiali dashboard\n\n";
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-${istio_major_version}/samples/addons/kiali.yaml
printf "${GREEN}\nDeployed Kiali dashboard on istio-system namespace\n\n";
fi
start_istio_dashboard kiali
break;;
No )
printf "${GREEN}Kiali dashboard will not be installed.\n";
break;
esac
done
printf "${GREEN}\nDo you want to deploy Jaeger ?\n";
select yn in "Yes" "No"; do
case $yn in
Yes )
jaegerDeploymentName=$(kubectl get deployment -n istio-system --selector=app=jaeger -o jsonpath='{.items[*].metadata.name}')
if [[ ! -z "$jaegerDeploymentName" ]]; then
printf "${GREEN}Jaeger is already installed on istio-system namespace.\n";
else
printf "${GREEN}Deploying Jaeger dashboard\n\n";
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-${istio_major_version}/samples/addons/jaeger.yaml
printf "${GREEN}\nDeployed Jaeger dashboard on istio-system namespace\n\n";
fi
start_istio_dashboard jaeger
break;;
No )
printf "${GREEN}Jaeger dashboard will not be installed.\n";
break;
esac
done
printf "${GREEN}\nDashboards installation complete\n\n"
break;;
No )
printf "${GREEN}Dashboards will not be installed.\n\n";
break;
esac
done
else
printf "${GREEN}Kiali and Jaeger dashboard services are already deployed on istio-system namespace.\n";
printf "${GREEN}To open dashboard, run: istioctl dashboard <dashboard-name>\n";
printf "${GREEN}example: istioctl dashboard kiali\n\n";
fi
fi
}
install_prometheus(){
istio_major_version=$1
printf "${GREEN}\nPrometheus is required as prerequisite for Kiali\n";
prometheusDeploymentName=$(kubectl get deployment -n istio-system --selector=app=prometheus -o jsonpath='{.items[*].metadata.name}')
if [[ ! -z "$prometheusDeploymentName" ]]; then
printf "${GREEN}Prometheus is already installed on istio-system namespace. Proceeding further.\n\n";
else
printf "${GREEN}Deploying Prometheus on istio-system namespace\n\n";
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-${istio_major_version}/samples/addons/prometheus.yaml
printf "${GREEN}\nDeployed Prometheus on istio-system namespace\n\n";
fi
}
start_istio_dashboard(){
dashboard_appname=$1
printf "${GREEN}Starting ${dashboard_appname} dashboard..\n"
for i in {1..3}
do
sleep 5
dashboard_pod_status=$(kubectl get pods -n istio-system --selector=app=${dashboard_appname} -o jsonpath='{.items[*].status.phase}')
if [[ $dashboard_pod_status =~ "Running" ]]; then
nohup istioctl dashboard ${dashboard_appname} > ${dashboard_appname}-info.log 2>&1 &
DASHBOARD_PIDS+=($!)
printf "${GREEN}${dashboard_appname} dashboard is available on localhost via port forwarding.\n"
printf "${GREEN}If dashboard does not open on default browser, please check ${dashboard_appname}-info.log present in current directory.\n"
break;
else
printf "${GREEN}Waiting for ${dashboard_appname} pod to start. Current status of ${dashboard_appname} pod is ${dashboard_pod_status}\n"
fi
if [[ $i -eq 3 ]]; then
printf "${RED}${dashboard_appname} pod did not start in 15s. Current status of ${dashboard_appname} pod is ${dashboard_pod_status}\n"
printf "${RED}Fix the ${dashboard_appname} pod and run: istioctl dashboard ${dashboard_appname} on new terminal session \n"
fi;
done
}
create_namespace() {
if [ $environment = 2 ] || [ $environment = 3 ]; then
printf "${GREEN}\nCreating a namespace 'otmm' for deployment."
sleep 5
kubectl create ns otmm
printf "${GREEN}\nAdding label 'istio-injection=enabled' to namespace 'otmm' for enabling istio envoy injection."
sleep 5
kubectl label namespace otmm istio-injection=enabled
fi
}
create_image_pull_secret() {
if [ $environment == 3 ]; then
if [ -z $CLUSTER ]; then
printf "${GREEN}\nEnter docker image registry \nThis value corresponds to --docker-server parameter in docker-registry secret"
printf "${GREEN}\n(Example: iad.ocir.io): "
read CLUSTER
echo "CLUSTER=$CLUSTER" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $CLUSTER_PREFIX ]; then
printf "${GREEN}\nEnter docker image registry prefix for image tagging. (This is a requirement to tag and push images to the registry).\n Example: iad.ocir.io/<tenancy-namespace>\n"
printf "${GREEN}\nFor more information about container registry, see https://docs.oracle.com/iaas/Content/Registry/Concepts/registryconcepts.htm\n"
read CLUSTER_PREFIX
echo "CLUSTER_PREFIX=$CLUSTER_PREFIX" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $CLUSTER_USER_NAME ]; then
printf "${GREEN}\nCreating docker secret for image pull.\n"
printf "${GREEN}\nEnter registry username (Example: <tenancy-name>/<username>):"
read CLUSTER_USER_NAME
echo "CLUSTER_USER_NAME=$CLUSTER_USER_NAME" >> "$MICROTX_INPUT_FILE";
fi
printf "${GREEN}\nEnter $CLUSTER_USER_NAME user registry password for docker image registry ${CLUSTER} (Password will not appear on the screen):"
read -s CLUSTER_PASSWORD
docker login $CLUSTER -u $CLUSTER_USER_NAME -p $CLUSTER_PASSWORD
kubectl create secret -n otmm docker-registry regcred --docker-server=$CLUSTER --docker-username=$CLUSTER_USER_NAME --docker-password=$CLUSTER_PASSWORD
fi
}
install_tmm_helmchart() {
cd "helmcharts"
printf "${GREEN}\nInstalling MicroTx transaction coordinator helm chart"
if [ $environment == 2 ];then
result=$(helm install otmm --namespace otmm tmm --values ./quickstart/minikube/qs-minikube-values.yaml -o json)
elif [ $environment == 3 ];then
image_name=$(printf "$CLUSTER_PREFIX/tmm:${VERSION}" | sed 's;/;\\/;g')
sed "s/tmm:${VERSION}/$image_name/g" ./quickstart/oke/qs-oke-values.yaml > ./quickstart/oke/values1.yaml
result=$(helm install otmm --namespace otmm tmm --values ./quickstart/oke/values1.yaml -o json)
rm ./quickstart/oke/values1.yaml
fi
check_pod_running "otmm-tcs"
cd ".."
}
install_microtx_basic_minikube() {
if [ $environment == 2 ];then
result=$(helm install otmm --namespace otmm tmm --values ./helmcharts/minikube/qs-minikube-values.yaml -o json)
else
printf"${GREEN}\n Minikube environment not present, exiting the script"
result=$(helm install otmm --namespace otmm tmm --values ./quickstart/minikube/qs-minikube-values.yaml -o json)
exit 1
fi
}
load_coordinator_image(){
coordinator_image_name="tmm:${DEFAULT_VERSION}"
if [ $environment == 2 ];then
if ! minikube image ls | grep -q $coordinator_image_name; then
printf "${GREEN}\nLoading the MicroTx transaction coordinator image into minikube registry.\n"
minikube image load ./image/tmm-arm-${DEFAULT_VERSION}.tgz
minikube image load ./image/tmm-${DEFAULT_VERSION}.tgz
fi
else
if ! docker images $coordinator_image_name | awk '{print $1":"$2}' | grep -q $coordinator_image_name; then
printf "${GREEN}\nLoading transaction coordinator docker image.\n"
docker image load -i ./image/tmm-arm-${DEFAULT_VERSION}.tgz
docker image load -i ./image/tmm-${DEFAULT_VERSION}.tgz
fi
fi
}
handle_tmm() {
case $environment in
"1")
#Directly running the docker image from the official docker image
printf "${GREEN}\nRunning the MicroTx transaction coordinator in a docker container."
if [ "$(docker ps -a -q -f name=otmm)" ]; then
printf "Transaction coordinator docker container with name 'otmm' exists. Deleting and recreating."
docker container rm otmm -f
fi
if [[ "${COORDINATOR_DOCKER_NETWORK_MODE}" == "host" ]] && [[ $IS_SE_LINUX == "true" ]]; then
printf "${GREEN}\nRunning MicroTx coordinator container network in ${COORDINATOR_DOCKER_NETWORK_MODE} mode as non-root user with podman\n"
docker container run --name otmm -p 9000:9000/tcp --env LISTEN_ADDR="0.0.0.0:9000" --env INTERNAL_ADDR="http://localhost:9000" --env EXTERNAL_ADDR="http://localhost:9000" --env SERVE_TLS_ENABLED=false --env LRA_COORDINATOR_ENABLED=true --env LRA_COORDINATOR_ENABLED=true --env XA_COORDINATOR_ENABLED=true --env TCC_COORDINATOR_ENABLED=true --network=host -d ${MICROTX_DOCKER_IMAGE}
elif [ "${COORDINATOR_DOCKER_NETWORK_MODE}" == "host" ]; then
printf "${GREEN}\nRunning MicroTx coordinator container network in ${COORDINATOR_DOCKER_NETWORK_MODE} mode\n"
docker container run --name otmm -p 9000:9000/tcp --env LISTEN_ADDR="0.0.0.0:9000" --env INTERNAL_ADDR="http://localhost:9000" --env EXTERNAL_ADDR="http://localhost:9000" --env SERVE_TLS_ENABLED=false --env LRA_COORDINATOR_ENABLED=true --env LRA_COORDINATOR_ENABLED=true --env XA_COORDINATOR_ENABLED=true --env TCC_COORDINATOR_ENABLED=true --network=host -d ${MICROTX_DOCKER_IMAGE}
else
docker container run --name otmm -p 9000:9000/tcp --env LISTEN_ADDR="0.0.0.0:9000" --env INTERNAL_ADDR="http://localhost:9000" --env EXTERNAL_ADDR="http://localhost:9000" --env SERVE_TLS_ENABLED=false --env LRA_COORDINATOR_ENABLED=true --env LRA_COORDINATOR_ENABLED=true --env XA_COORDINATOR_ENABLED=true --env TCC_COORDINATOR_ENABLED=true --add-host host.docker.internal:host-gateway -d ${MICROTX_DOCKER_IMAGE}
fi
printf "${GREEN}\nTransaction coordinator url is http://localhost:9000/api/v1"
cd ".."
;;
"2")
check_for_distribution_package
if is_distribution_package_available ; then
printf "${GREEN}\nDistribution pacakge available."
pushd ${DISTRIBUTION_PACKAGE_PATH}/otmm
load_coordinator_image
install_tmm_helmchart
popd
else
printf "${GREEN}\n Running Minikube with github repository."
install_microtx_basic_minikube
fi
;;
"3")
check_for_distribution_package
if is_distribution_package_available ; then
printf "${GREEN}\nDistribution pacakge available."
pushd ${DISTRIBUTION_PACKAGE_PATH}/otmm
load_coordinator_image
printf "${GREEN}\nPushing Docker image $CLUSTER_PREFIX/tmm:${VERSION} to the registry.\n"
docker image tag tmm:${VERSION} $CLUSTER_PREFIX/tmm:${VERSION}
docker image push $CLUSTER_PREFIX/tmm:${VERSION}
install_tmm_helmchart
popd
else
printf "${GREEN}\n To deploy in kubernetes environment, please download the distribution package from ${DISTRIBUTION_PACKAGE_LINK}"
exit 1
fi
;;
esac
cd ".."
}
check_sample_appl_helmchart_deployed() {
if [ $environment == 2 ] || [ $environment == 3 ]; then
status=$(printf $1 | jq .info.status)
printf "${GREEN}\nHelmchart installation status: $status"
if [[ $status == "failed" ]]; then
printf "${GREEN}\nHelmchart installation failed. Reason:"
printf $1 | jq .info.description
printf "${GREEN}\nDo you want to clean up ?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) clean_up "y" "y" "y"; break;;
No ) break;;
esac
done
fi
printf "${GREEN}\nWaiting for the microservices to start."
sleep 25
fi
}
check_pod_running() {
phase="unknown"
pod_name="unknown"
declare -i remainging_checks=10
pod_name=$(kubectl get pods -n otmm -l=app=$1 -o jsonpath='{.items[0].metadata.name}')
phase=$(kubectl get pod -n otmm $pod_name -o jsonpath='{.status.phase}')
printf "${GREEN}\nCurrent phase of pod $pod_name: $phase"
while [[ $remainging_checks > 0 ]] && [[ $phase != "Running" ]];
do
((remainging_checks--))
printf "${GREEN}\nWaiting for pod $pod_name to be in phase running. Remaining checks: $remainging_checks"
sleep 10
phase=$(kubectl get pod -n otmm $pod_name -o jsonpath='{.status.phase}')
printf "${GREEN}\nCurrent phase of pod $pod_name: $phase"
done
if [[ $phase != "Running" ]]; then
printf "${GREEN}\nPod $pod_name is stuck in phase $phase"
printf "${GREEN}\nPrinting pod describe output for pod $pod_name"
kubectl describe pod $pod_name -n otmm
if [[ $1 == 'otmm-tcs' ]];then
clean_up "n" "y" "y"
else
clean_up "y" "y" "y"
fi
fi
}
collect_xa_database_details() {
printf "${GREEN}\n\n***** helidon/dept1 XA database details *****"
printf "${GREEN}\nEnter below details for department helidon/dept1 XA resource"
if [ -z $WALLET_LOCATION_1 ]; then
printf "${GREEN}\nIf you are using Oracle Autonomous Database, download the Database wallet and provide the downloaded location of the database wallet."
printf "${GREEN}\n(If you are not using Oracle Autonomous Database, skip this step by pressing enter): "
read WALLET_LOCATION_1
echo "WALLET_LOCATION_1=$WALLET_LOCATION_1" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $DB_CONNECT_STRING_1 ]; then
printf "${GREEN}\nEnter the Oracle database connect string (Format: jdbc:oracle:thin:@tcps://<host>:<port>/<service_name>?wallet_location=Database_Wallet):"
read DB_CONNECT_STRING_1
echo "DB_CONNECT_STRING_1=$DB_CONNECT_STRING_1" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $DB_USER_1 ]; then
printf "${GREEN}\nEnter the user name to access the Oracle database:"
read DB_USER_1
echo "DB_USER_1=$DB_USER_1" >> "$MICROTX_INPUT_FILE";
fi
printf "${GREEN}\nUsing Database connection string : $DB_CONNECT_STRING_1\n"
printf "${GREEN}\nEnter the password for database user $DB_USER_1 to access the Oracle database (password will not appear on the screen):"
read -s DB_PASSWORD_1
printf "${GREEN}\n\n***** spring/dept2 XA database details *****"
printf "${GREEN}\nEnter below details for department spring/dept2 XA resource"
if [ -z $WALLET_LOCATION_2 ]; then
printf "${GREEN}\nIf you are using Oracle Autonomous Database, download the database wallet and provide the downloaded location of the database wallet."
printf "${GREEN}\n(If you are not using Oracle Autonomous Database, skip this step by pressing enter): "
read WALLET_LOCATION_2
echo "WALLET_LOCATION_2=$WALLET_LOCATION_2" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $DB_CONNECT_STRING_2 ]; then
printf "${GREEN}\nEnter the Oracle database connect string (Format: jdbc:oracle:thin:@tcps://<host>:<port>/<service_name>?wallet_location=Database_Wallet):"
read DB_CONNECT_STRING_2
echo "DB_CONNECT_STRING_2=$DB_CONNECT_STRING_2" >> "$MICROTX_INPUT_FILE";
fi
if [ -z $DB_USER_2 ]; then
printf "${GREEN}\nEnter the user name to access the Oracle database:"
read DB_USER_2
echo "DB_USER_2=$DB_USER_2" >> "$MICROTX_INPUT_FILE";
fi
printf "${GREEN}\nUsing Database connection string : $DB_CONNECT_STRING_1\n"
printf "${GREEN}\nEnter the password for database user $DB_USER_2 to access the Oracle database (password will not appear on the screen):"
read -s DB_PASSWORD_2
printf "${GREEN}\n\n***** Building XA sample app with the provided details *****\n\n"
}
handle_xa_java_teller_application() {
cd "teller"
case $environment in
"1")
printf "${GREEN}\nRunning teller microservice on your local machine - location: samples/xa/java/teller \n"
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8080"
mvn clean package
java -jar target/teller.jar &
PIDS+=($!)
sleep 10
;;
"2")
printf "${GREEN}\nBuilding teller docker image: xa-java-teller:1.0 - location: samples/xa/java/teller\n"
minikube image build -t xa-java-teller:1.0 .
;;
"3")
printf "${GREEN}\nBuilding teller docker image $CLUSTER_PREFIX/xa-java-teller:1.0 - location: samples/xa/java/teller\n"
docker image build -t $CLUSTER_PREFIX/xa-java-teller:1.0 .
printf "${GREEN}\nPushing teller docker image $CLUSTER_PREFIX/xa-java-teller:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/xa-java-teller:1.0
;;
esac
cd ".."
}
handle_xa_java_department_helidon_application() {
cd "department-helidon"
case $environment in
"1")
printf "${GREEN}\nRunning department helidon microservice on your local machine - location: samples/xa/java/department-helidon \n"
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8081"
if [ $WALLET_LOCATION_1 ]; then
cp $WALLET_LOCATION_1/* ./Database_Wallet
fi
export DEPARTMENTDATASOURCE_URL=$(printf "$DB_CONNECT_STRING_1" | sed 's/localhost/${CONTAINER_LOCAL_HOST}/g')
export DEPARTMENTDATASOURCE_USER=$DB_USER_1
export DEPARTMENTDATASOURCE_PASSWORD=$DB_PASSWORD_1
mvn clean package
java -jar target/department.jar &
PIDS+=($!)
sleep 10
;;
"2")
if [ $WALLET_LOCATION_1 ]; then
cp $WALLET_LOCATION_1/* ./Database_Wallet
fi
printf "${GREEN}\nBuilding department helidon docker image: department-helidon:1.0 - location: samples/xa/java/department-helidon\n"
minikube image build -t department-helidon:1.0 .
;;
"3")
if [ $WALLET_LOCATION_1 ]; then
cp $WALLET_LOCATION_1/* ./Database_Wallet
fi
printf "${GREEN}\nBuilding department helidon docker image: $CLUSTER_PREFIX/department-helidon:1.0 - location: samples/xa/java/department-helidon\n"
docker image build -t $CLUSTER_PREFIX/department-helidon:1.0 .
printf "${GREEN}\nPushing XA JAVA department helidon docker image $CLUSTER_PREFIX/department-helidon:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/department-helidon:1.0
;;
esac
cd ".."
}
handle_xa_java_department_spring_application() {
cd "department-spring"
case $environment in
"1")
printf "${GREEN}\nRunning department spring microservice on your local machine - location: samples/xa/java/department-spring"
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8082"
export SPRING_MICROTX_PARTICIPANT_URL="http://${CONTAINER_LOCAL_HOST}:8082"
if [ $WALLET_LOCATION_2 ]; then
cp $WALLET_LOCATION_2/* ./Database_Wallet
fi
export DEPARTMENTDATASOURCE_URL=$(printf "$DB_CONNECT_STRING_2" | sed 's/localhost/${CONTAINER_LOCAL_HOST}/g')
export DEPARTMENTDATASOURCE_USER=$DB_USER_2
export DEPARTMENTDATASOURCE_PASSWORD=$DB_PASSWORD_2
mvn clean package
java -jar target/department.jar &
PIDS+=($!)
sleep 10
;;
"2")
if [ $WALLET_LOCATION_2 ]; then
cp $WALLET_LOCATION_2/* ./Database_Wallet
fi
printf "${GREEN}\nBuilding department spring docker image: department-spring:1.0 - location: samples/xa/java/department-spring\n"
minikube image build -t department-spring:1.0 .
;;
"3")
if [ $WALLET_LOCATION_2 ]; then
cp $WALLET_LOCATION_2/* ./Database_Wallet
fi
printf "${GREEN}\nBuilding department spring docker image: $CLUSTER_PREFIX/department-spring:1.0 - location: samples/xa/java/department-spring\n"
docker image build -t $CLUSTER_PREFIX/department-spring:1.0 .
printf "${GREEN}\nPushing department spring docker image $CLUSTER_PREFIX/department-spring:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/department-spring:1.0
;;
esac
cd ".."
}
handle_xa_java_department_helidon_embedded_application() {
cd "department-helidon-embedded"
printf "${GREEN}\nRunning department helidon embedded microservice on your local machine. Using Apache Derby as embedded database. - location: samples/xa/java/department-helidon-embedded \n"
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8081"
mvn clean package
java -jar target/department-helidon-embedded.jar &
PIDS+=($!)
sleep 10
cd ".."
}
handle_xa_java_department_spring_embedded_application() {
cd "department-spring-embedded"
printf "${GREEN}\nRunning department spring embedded microservice on your local machine. Using Apache Derby as embedded database. - location: samples/xa/java/department-spring-embedded"
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8082"
export SPRING_MICROTX_PARTICIPANT_URL="http://${CONTAINER_LOCAL_HOST}:8082"
mvn clean package
java -jar target/department-spring-embedded.jar &
PIDS+=($!)
sleep 10
cd ".."
}
handle_xa_embedded_java_applications() {
cd "java"
if [ $environment == 2 ]; then
printf "${GREEN}\n The in memory XA Sample apps not applicable to Minikube environment "
exit 1
elif [ $environment == 3 ]; then
printf "${GREEN}\n The in memory XA Sample apps not applicable to Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) environment"
exit 1
fi
printf "${GREEN}\nThis XA demo includes three microservices:"
printf "${GREEN}\nDepartment Helidon Embedded - location: samples/xa/java/department-helidon-embedded"
printf "${GREEN}\nDepartment Spring Embedded - location: samples/xa/java/department-spring-embedded"
printf "${GREEN}\nTeller - location: samples/xa/java/teller \n"
sleep 3
handle_xa_java_teller_application
handle_xa_java_department_helidon_embedded_application
handle_xa_java_department_spring_embedded_application
cd ".."
}
handle_xa_java_applications() {
cd "java"
printf "${GREEN}\nThis XA demo includes three microservices:"
printf "${GREEN}\nDepartment Helidon - location: samples/xa/java/department-helidon"
printf "${GREEN}\nDepartment Spring - location: samples/xa/java/department-spring"
printf "${GREEN}\nTeller - location: samples/xa/java/teller \n"
sleep 3
collect_xa_database_details
handle_xa_java_teller_application
handle_xa_java_department_helidon_application
handle_xa_java_department_spring_application
if [ $environment == 2 ]; then
cd "helmcharts"
URL_1=$(printf "$DB_CONNECT_STRING_1" | sed 's;/;\\/;g')
sed "s/<Fill in the connect string dept1>/$URL_1/g" ./transfer/values.yaml > ./transfer/values1.yaml
sed "s/<Fill in the database user dept1>/$DB_USER_1/g" ./transfer/values1.yaml > ./transfer/values2.yaml
sed "s/<Fill in the database password dept1>/$DB_PASSWORD_1/g" ./transfer/values2.yaml > ./transfer/values3.yaml
URL_2=$(printf "$DB_CONNECT_STRING_2" | sed 's;/;\\/;g')
sed "s/<Fill in the connect string dept2>/$URL_2/g" ./transfer/values3.yaml > ./transfer/values4.yaml
sed "s/<Fill in the database user dept2>/$DB_USER_2/g" ./transfer/values4.yaml > ./transfer/values5.yaml
sed "s/<Fill in the database password dept2>/$DB_PASSWORD_2/g" ./transfer/values5.yaml > ./transfer/values6.yaml
sed "s/<Fill the unique identifier assigned to the dept1 database>/de5eb98f-670b-49c6-a8f3-b82faf4eb883/g" ./transfer/values6.yaml > ./transfer/values7.yaml
sed "s/<Fill the unique identifier assigned to the dept2 database>/ac1b5483-66c3-4577-be72-b9149237ce2f/g" ./transfer/values7.yaml > ./transfer/values8.yaml
printf "${GREEN}\nInstalling helm chart - Location: samples/xa/java/helmcharts/transfer \n"
result=$(helm install -n otmm transfer transfer --values ./transfer/values8.yaml -o json)
rm ./transfer/values1.yaml ./transfer/values2.yaml ./transfer/values3.yaml ./transfer/values4.yaml ./transfer/values5.yaml ./transfer/values6.yaml ./transfer/values7.yaml ./transfer/values8.yaml
elif [ $environment == 3 ]; then
cd "helmcharts"
xa_image_prefix=$(printf "$CLUSTER_PREFIX" | sed 's;/;\\/;g')
sed "s/xa-java-teller:1.0/$xa_image_prefix\/xa-java-teller:1.0/g" ./transfer/values.yaml > ./transfer/values1.yaml
sed "s/department-helidon:1.0/$xa_image_prefix\/department-helidon:1.0/g" ./transfer/values1.yaml > ./transfer/values2.yaml
sed "s/department-spring:1.0/$xa_image_prefix\/department-spring:1.0/g" ./transfer/values2.yaml > ./transfer/values3.yaml
URL_1=$(printf "$DB_CONNECT_STRING_1" | sed 's;/;\\/;g')
sed "s/<Fill in the connect string dept1>/$URL_1/g" ./transfer/values3.yaml > ./transfer/values4.yaml
sed "s/<Fill in the database user dept1>/$DB_USER_1/g" ./transfer/values4.yaml > ./transfer/values5.yaml
sed "s/<Fill in the database password dept1>/$DB_PASSWORD_1/g" ./transfer/values5.yaml > ./transfer/values6.yaml
URL_2=$(printf "$DB_CONNECT_STRING_2" | sed 's;/;\\/;g')
sed "s/<Fill in the connect string dept2>/$URL_2/g" ./transfer/values6.yaml > ./transfer/values7.yaml
sed "s/<Fill in the database user dept2>/$DB_USER_2/g" ./transfer/values7.yaml > ./transfer/values8.yaml
sed "s/<Fill in the database password dept2>/$DB_PASSWORD_2/g" ./transfer/values8.yaml > ./transfer/values9.yaml
sed "s/<Fill the unique identifier assigned to the dept1 database>/de5eb98f-670b-49c6-a8f3-b82faf4eb883/g" ./transfer/values9.yaml > ./transfer/values10.yaml
sed "s/<Fill the unique identifier assigned to the dept2 database>/ac1b5483-66c3-4577-be72-b9149237ce2f/g" ./transfer/values10.yaml > ./transfer/values11.yaml
printf "${GREEN}\nInstalling helm chart - Location: samples/xa/java/helmcharts/transfer .\n"
result=$(helm install -n otmm transfer transfer --values ./transfer/values11.yaml -o json)
rm ./transfer/values1.yaml ./transfer/values2.yaml ./transfer/values3.yaml ./transfer/values4.yaml ./transfer/values5.yaml ./transfer/values6.yaml ./transfer/values7.yaml ./transfer/values8.yaml
rm ./transfer/values9.yaml ./transfer/values10.yaml ./transfer/values11.yaml
fi
if [ $environment == 2 ] || [ $environment == 3 ]; then
check_pod_running "dept1"
check_pod_running "dept2"
check_pod_running "teller"
fi
cd ".."
}
run_xa_transfer_scenario() {
if [ $environment == 1 ]; then
department_one_url="http://localhost:8081/accounts"
department_two_url="http://localhost:8082/accounts"
initiator_url="http://localhost:8080"
else
department_one_url="$istio_url/dept1"
department_two_url="$istio_url/dept2"
initiator_url="$istio_url"
fi
printf "${GREEN}\nEnter the name of the account from which you want to withdraw an amount (Example: account1):"
read account1
account1=${account1:-account1}
printf "${GREEN}\nExecuting command to fetch account balance: curl --location --request GET $department_one_url/$account1"
sleep 5
if [ $environment == 3 ]; then
output="$(curl --location -H "Host:demo.tmm.dev" --resolve "demo.tmm.dev:443:$istio_ip" --cacert $ROOT/certificates/tmm.dev.crt --request GET $department_one_url/$account1)"
else
output="$(curl --location --request GET $department_one_url/$account1)"
fi
printf "${GREEN}\nBalance in the $account1 account before the transfer is: $output\n"
sleep 5
printf "${GREEN}\nEnter the name of the account to which you want to deposit an amount (Example: account2):"
read account2
account2=${account2:-account2}
printf "${GREEN}\nExecuting command to fetch account balance: curl --location --request GET $department_two_url/$account2"
sleep 5
if [ $environment == 3 ]; then
output="$(curl --location -H "Host:demo.tmm.dev" --resolve "demo.tmm.dev:443:$istio_ip" --cacert $ROOT/certificates/tmm.dev.crt --request GET $department_two_url/$account2)"
else
output="$(curl --location --request GET $department_two_url/$account2)"
fi
printf "${GREEN}\nBalance in the $account2 account before the transfer is: $output\n"
sleep 5
printf "${GREEN}\nEnter the amount that you want to transfer (Example: 100):"
read amount
amount=${amount:-100}
printf "${GREEN}\nExecuting command to initiate a transfer: curl --location --request --header 'Content-Type: application/json
--data '{
"from": "'$account1'",
"to": "'$account2'",
"amount": '$amount'
}')
POST $initiator_url/transfers \n"
sleep 5
if [ $environment == 3 ]; then
output=$(curl --location -H "Host:demo.tmm.dev" --resolve "demo.tmm.dev:443:$istio_ip" --cacert $ROOT/certificates/tmm.dev.crt --request POST $initiator_url/transfers \
--header 'Content-Type: application/json' \
--data '{
"from": "'$account1'",
"to": "'$account2'",
"amount": '$amount'
}')
else
output=$(curl --location --request POST $initiator_url/transfers \
--header 'Content-Type: application/json' \
--data '{
"from": "'$account1'",
"to": "'$account2'",
"amount": '$amount'
}')
fi
printf "${GREEN}\nTransfer output: $output \n"
printf "${GREEN}\nExecuting command to fetch account balance: curl --location --request GET $department_one_url/$account1"
sleep 5
if [ $environment == 3 ]; then
output="$(curl --location -H "Host:demo.tmm.dev" --resolve "demo.tmm.dev:443:$istio_ip" --cacert $ROOT/certificates/tmm.dev.crt --request GET $department_one_url/$account1)"
else
output="$(curl --location --request GET $department_one_url/$account1)"
fi
printf "${GREEN}\nBalance in the $account1 account after the transfer is:$output\n"
sleep 5
printf "${GREEN}\nExecuting command to fetch account balance: curl --location --request GET $department_two_url/$account2"
sleep 5
if [ $environment == 3 ]; then
output="$(curl --location -H "Host:demo.tmm.dev" --resolve "demo.tmm.dev:443:$istio_ip" --cacert $ROOT/certificates/tmm.dev.crt --request GET $department_two_url/$account2)"
else
output="$(curl --location --request GET $department_two_url/$account2)"
fi
printf "${GREEN}\nBalance in the $account2 account after the transfer is:$output\n"
sleep 10
}
handle_xa_samples() {
cd "xa"
printf "${GREEN}\nEnter a number (1-2) to specify database type for XA samples\n"
select yn in "Embedded in-memory database" "XA DataSource"; do
case $yn in
"Embedded in-memory database" ) sample=1; handle_xa_embedded_java_applications; break;;
"XA DataSource" ) sample=2; handle_xa_java_applications; break;;
esac
done
sleep 10
printf "${GREEN}\nThe microservice implements a scenario where a Teller microservice transfers money from one department to another by creating an XA transaction. The two departments in the organization are Department Helidon and Department Spring. The XA transaction is implemented by using the Transaction Manager for Microservices. Within the XA transaction, all actions such as withdraw and deposit either succeed, or they all are rolled back in case of a failure of any one or more actions."
printf "${GREEN}\nDo you want to run microservice example scenario ?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) run_xa_transfer_scenario; break;;
No ) break;;
esac
done
cd ".."
}
handle_lra_hotel_application() {
cd "hotel"
case $environment in
"1")
printf "${GREEN}\nRunning the LRA hotel microservice on your local machine - location: samples/lra/lrademo/hotel \n"
sleep 5
export MP_LRA_PARTICIPANT_URL="http://${CONTAINER_LOCAL_HOST}:8082"
mvn clean package
java -jar target/hotel.jar &
PIDS+=($!)
sleep 5
;;
"2")
printf "${GREEN}\nBuilding the LRA hotel microservice docker image lra-hotel:1.0 - location: samples/lra/lrademo/hotel \n"
sleep 5
minikube image build -t lra-hotel:1.0 .
;;
"3")
printf "${GREEN}\nBuilding the LRA hotel microservice docker image $CLUSTER_PREFIX/lra-hotel:1.0 - location: samples/lra/lrademo/hotel \n"
sleep 5
docker image build -t $CLUSTER_PREFIX/lra-hotel:1.0 .
printf "${GREEN}\nPushing the LRA hotel microservice docker image $CLUSTER_PREFIX/lra-hotel:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/lra-hotel:1.0
;;
esac
cd ".."
}
handle_lra_flight_application() {
cd "flight-springboot"
case $environment in
"1")
printf "${GREEN}\nRunning the LRA flight microservice on your local machine - location: samples/lra/lrademo/flight-springboot \n"
sleep 5
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8083"
export SPRING_MICROTX_LRA_PARTICIPANT_URL="http://${CONTAINER_LOCAL_HOST}:8083"
mvn clean package
java -jar target/flight-sb.jar &
PIDS+=($!)
sleep 5
;;
"2")
printf "${GREEN}\nBuilding the LRA flight microservice docker image lra-flight:1.0 - location: samples/lra/lrademo/flight-springboot \n"
sleep 5
minikube image build -t lra-flight:1.0 .
;;
"3")
printf "${GREEN}\nBuilding the LRA flight microservice docker image $CLUSTER_PREFIX/lra-flight:1.0 - location: samples/lra/lrademo/flight-springboot \n"
sleep 5
docker image build -t $CLUSTER_PREFIX/lra-flight:1.0 .
printf "${GREEN}\nPushing the LRA flight microservice docker image $CLUSTER_PREFIX/lra-flight:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/lra-flight:1.0
;;
esac
cd ".."
}
handle_lra_flight_node_application() {
cd "flight"
case $environment in
"1")
printf "${GREEN}\nRunning the LRA flight microservice on your local machine - location: samples/lra/lrademo/flight \n"
sleep 5
export ORACLE_TMM_CALLBACK_URL="http://${CONTAINER_LOCAL_HOST}:8083"
npm install
npm run tsc
node ./build/server.js &
PIDS+=($!)
sleep 5
;;
"2")
printf "${GREEN}\nBuilding the LRA flight microservice docker image lra-flight:1.0 - location: samples/lra/lrademo/flight \n"
sleep 5
minikube image build -t lra-flight:1.0 .
;;
"3")
printf "${GREEN}\nBuilding the LRA flight microservice docker image $CLUSTER_PREFIX/lra-flight:1.0 - location: samples/lra/lrademo/flight \n"
sleep 5
docker image build -t $CLUSTER_PREFIX/lra-flight:1.0 .
printf "${GREEN}\nPushing the LRA flight microservice docker image $CLUSTER_PREFIX/lra-flight:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/lra-flight:1.0
;;
esac
cd ".."
}
handle_lra_trip_manager_application() {
cd "trip-manager"
case $environment in
"1")
printf "${GREEN}\nRunning the LRA Trip Manager microservice on your local machine - location: samples/lra/lrademo/trip-manager \n"
sleep 5
export MP_LRA_PARTICIPANT_URL="http://${CONTAINER_LOCAL_HOST}:8081"
mvn clean package
java -jar target/trip-manager.jar &
PIDS+=($!)
sleep 5
;;
"2")
printf "${GREEN}\nBuilding the LRA trip manager microservice docker image lra-trip-manager:1.0 - location: samples/lra/lrademo/trip-manager \n"
sleep 5
minikube image build -t lra-trip-manager:1.0 .
;;
"3")
printf "${GREEN}\nBuilding the LRA trip manager microservice docker image $CLUSTER_PREFIX/lra-trip-manager:1.0 - location: samples/lra/lrademo/trip-manager \n"
sleep 5
docker image build -t $CLUSTER_PREFIX/lra-trip-manager:1.0 .
printf "${GREEN}\nPushing the LRA trip manager microservice docker image $CLUSTER_PREFIX/lra-trip-manager:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/lra-trip-manager:1.0
;;
esac
cd ".."
}
run_lra_samples() {
printf "${GREEN}\nLocally running trip client microservice - location: samples/lra/lrademo/trip-client."
cd "lrademo/trip-client"
if [ $environment == 1 ]; then
export TRIP_SERVICE_URL="http://localhost:8081/trip-service/api/trip"
fi
if [ $environment == 2 ] || [ $environment == 3 ]; then
TRIP_MANAGER_URL="$istio_url/trip-service/api/trip"
export TRIP_SERVICE_URL=$TRIP_MANAGER_URL
fi
if [ ! -f "target/trip-client.jar" ]; then
mvn clean package
fi
java -jar target/trip-client.jar
cd "../.."
sleep 5
}
handle_lra_samples() {
cd "lra/lrademo"
printf "${GREEN}\nThis LRA demo includes three microservices:"
printf "${GREEN}\nFlight - location: samples/lra/lrademo/flight-springboot"
printf "${GREEN}\nHotel - location: samples/lra/lrademo/hotel"
printf "${GREEN}\nTrip Manager - location: samples/lra/lrademo/trip-manager\n"
sleep 5
handle_lra_hotel_application
handle_lra_flight_application
handle_lra_trip_manager_application
cd ".."
if [ $environment == 2 ]; then
printf "${GREEN}\nInstalling sampleappslra helm chart - location: samples/lra/helmcharts/sampleappslra \n"
result=$(helm install -n otmm sampleappslra helmcharts/sampleappslra -o json)
elif [ $environment == 3 ]; then
cd "./helmcharts"
printf "${GREEN}\nInstalling sampleappslra helm chart - location: samples/lra/helmcharts/sampleappslra \n"
lra_image_prefix=$(printf "$CLUSTER_PREFIX" | sed 's;/;\\/;g')
sed "s/lra-trip-manager:1.0/$lra_image_prefix\/lra-trip-manager:1.0/g" ./sampleappslra/values.yaml > ./sampleappslra/values1.yaml
sed "s/lra-flight:1.0/$lra_image_prefix\/lra-flight:1.0/g" ./sampleappslra/values1.yaml > ./sampleappslra/values2.yaml
sed "s/lra-hotel:1.0/$lra_image_prefix\/lra-hotel:1.0/g" ./sampleappslra/values2.yaml > ./sampleappslra/values3.yaml
result=$(helm install -n otmm sampleappslra sampleappslra --values ./sampleappslra/values3.yaml -o json)
rm ./sampleappslra/values1.yaml ./sampleappslra/values2.yaml ./sampleappslra/values3.yaml
cd ..
fi
if [ $environment == 2 ] || [ $environment == 3 ]; then
check_pod_running "hotel"
check_pod_running "flight"
check_pod_running "trip-manager"
fi
sleep 10
printf "${GREEN}\nThe microservices are microservices that demonstrate how services can be developed for participating in LRA transactions while using Transaction Manager for Microservices to coordinate the transactions."
printf "${GREEN}\nThe sample LRA microservice implements a scenario where a different microservices perform different tasks. One microservice books a trip, another books a flight, and a third microservice books a hotel."
printf "${GREEN}\nDo you want to run microservice example scenario ?\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) run_lra_samples; break;;
No ) break;;
esac
done
}
handle_tcc_java_hotel_application() {
cd "hotel-booking"
case $environment in
"1")
printf "${GREEN}\nRunning the TCC hotel microservice on your local machine - location: samples/tcc/java/hotel-booking \n"
export BOOKING_BASE_URL="http://${CONTAINER_LOCAL_HOST}:8081/api/bookings"
mvn clean package
java -jar target/hotel-booking.jar &
PIDS+=($!)
sleep 10
;;
"2")
printf "${GREEN}\nBuilding the TCC hotel docker image tcc-java-hotel:1.0 - location: samples/tcc/java/hotel-booking \n"
minikube image build -t tcc-java-hotel:1.0 .
;;
"3")
printf "${GREEN}\nBuilding the TCC hotel docker image $CLUSTER_PREFIX/tcc-java-hotel:1.0 - location: samples/tcc/java/hotel-booking \n"
docker image build -t $CLUSTER_PREFIX/tcc-java-hotel:1.0 .
printf "${GREEN}\nPushing the LRA Hotel docker image $CLUSTER_PREFIX/lra-hotel:1.0 to the registry.\n"
docker image push $CLUSTER_PREFIX/tcc-java-hotel:1.0
;;
esac
cd ".."
}
handle_tcc_java_flight_application() {
cd "flight-booking"