Skip to content

Commit bcd9a39

Browse files
Initial upload
0 parents  commit bcd9a39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2323
-0
lines changed

.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Package Files #
11+
*.jar
12+
*.war
13+
*.nar
14+
*.ear
15+
*.zip
16+
*.tar.gz
17+
*.rar
18+
backend/target/*
19+
backend/.settings/*
20+
backend/.project
21+
backend/.classpath
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
*~
25+
26+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
27+
28+
# dependencies
29+
frontend/node_modules
30+
frontend/.pnp
31+
.pnp.js
32+
33+
# testing
34+
frontend/coverage
35+
36+
# production
37+
frontend/build
38+
39+
# misc
40+
.DS_Store
41+
.env.local
42+
.env.development.local
43+
.env.test.local
44+
.env.production.local
45+
46+
frontend/package-lock.json
47+
frontend/npm-debug.log*
48+
frontend/yarn-debug.log*
49+
frontend/yarn-error.log*

backend/README.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
## MyToDoReact version 1.0.
2+
Copyright (c) 2021 Oracle, Inc.
3+
4+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
# Part II -- Backend (Java/Helidon)
7+
8+
## **Summary**
9+
10+
In this Part, you will build and deploy the Helidon Java backend Docker image to OKE, then configure the API Gateway
11+
12+
As with most React applications (https://reactjs.org/), this application uses remote APIs to handle data persistence. The backend implements 5 REST APIs including:
13+
- 1) retrieving the current list of todo items
14+
- 2) Adding a new todo item
15+
- 3) finding a todo item by its id
16+
- 4) updating an existing todo item
17+
- 5) deleting a todo item.
18+
19+
The APIs are documented using Swagger @ http://130.61.67.158:8780/swagger-ui/#/
20+
21+
The backend is implemented using the following Java classes (under ./backend/src/...):
22+
- Main.java: starts and configure the main entry points.
23+
- ToDoItem.java: maps a Todo Item instance to/from JSON document
24+
- ToDoItemStorage.java: stores the Todo item in a persistent store i.e., the Oracle Autonomous database
25+
- ToDoListAppService.java: implements the Helidon service and exposes the REST APIs
26+
27+
![](images/Backend-APIs.png " ")
28+
29+
## **Objectives**
30+
31+
* Set values for environment variables
32+
* Build and deploy the Docker image of the application
33+
* Deploy the image on the Oracle Kubernetes Engine (OKE)
34+
* Describe the steps for Undeploying
35+
* Configure the API Gateway
36+
* Test the backend application
37+
38+
39+
## **STEP 1**: Set values for workshop environment variables
40+
41+
1. Set the root directory of the workshop
42+
```
43+
<copy>export MTDRWORKSHOP_LOCATION=~/mtdrworkshop</copy>
44+
```
45+
2. Run source addAndSourcePropertiesInBashrc.sh
46+
47+
The following command will set the values of environment variables in mtdrworkshop.properties and source ~/.bashrc
48+
49+
```
50+
<copy>cd $MTDRWORKSHOP_LOCATION; source addAndSourcePropertiesInBashrc.sh
51+
</copy>
52+
```
53+
54+
## **STEP 2**: Build and push the Docker images to the OCI Registry
55+
56+
1. Ensure that the "DOCKER_REGISTRY" variable is set
57+
58+
Example: <region-key>.ocir.io/<object-storage-namespace>/<firstname.lastname>/<repo-name>"
59+
If the variable is not set or is an empty string, the push will fail (but the docker image will be built).
60+
61+
2. Make sure to be in backend/target/classes/wallet directory then execute
62+
```
63+
<copy>unzip ~/mtdrworkshop/setup-dev-environment/wallet.zip</copy>
64+
```
65+
66+
3. Pick mtdrb_tp service alias (see the list of aliases in
67+
./backend/target/classes/wallet/tnsnames.ora)
68+
69+
![](images/tnsnames-ora.png " ")
70+
71+
4. Edit ./backend/target/classes/application.yaml to set the database service and user password
72+
![](images/application-yaml.png " ")
73+
74+
5. Copy the edited ./backend/target/classes/application.yaml to backend./src/main/resources/application.yaml
75+
76+
6. Edit ./backend/src/main/java/com/oracle/todoapp/Main.java
77+
- Locate the following code fragment
78+
![](images/CORS-Main.png " ")
79+
- Replace `eu-frankfurt-1` in `"https://objectstorage.eu-frankfurt-1.oraclecloud.com"` by your region
80+
81+
- Save the file
82+
83+
7. Run the `build.sh` script to build and push the
84+
microservices images into the repository
85+
86+
```
87+
<copy>cd $MTDRWORKSHOP_LOCATION/backend; ./build.sh</copy>
88+
```
89+
In a couple of minutes, you should have successfully built and pushed the images into the OCIR repository.
90+
91+
8. Check your container registry from the root compartment
92+
- Go to the Console, click the hamburger menu in the top-left corner and open
93+
**Developer Services > Container Registry**.
94+
95+
![](images/Registry-root-compart.png " ")
96+
97+
9. Mark Access as Public (if Private) (**Actions** > **Change to Public**):
98+
99+
![](images/Public-access.png " ")
100+
101+
## **STEP 3**: Deploy on Kubernetes and Check the Status
102+
103+
1. Run the `deploy.sh` script
104+
105+
```
106+
<copy>cd $MTDRWORKSHOP_LOCATION/backend; ./deploy.sh</copy>
107+
```
108+
109+
--> service/todolistapp-helidon-se-service created
110+
--> deployment.apps/todolistapp-helidon-se-deployment created
111+
112+
2. Check the status using the following commands
113+
$ kubectl get services
114+
115+
The following command returns the Kubernetes service of MyToDo application with a load balancer exposed through an external API
116+
```
117+
<copy>kubectl get services</copy>
118+
```
119+
120+
![](images/K8-service-Ext-IP.png " ")
121+
122+
4. $ kubectl get pods
123+
```
124+
<copy>kubectl get pods</copy>
125+
```
126+
127+
![](images/k8-pods.png " ")
128+
129+
5. Continuously tailing the log of one of the pods
130+
131+
$ kubectl logs -f <pod name>
132+
Examaple kubectl lgs -f todolistapp-helidon-se-deployment-7fd6dcb778-c9dbv
133+
134+
Returns:
135+
http://130.61.66.27/todolist
136+
137+
## **STEP 4**: UnDeploy (optional)
138+
139+
If you make changes to the image, you need to delete the service and the pods by running undeploy.sh then redo Steps 2 & 3.
140+
141+
1. Run the `undeploy.sh` script
142+
```
143+
<copy>cd $MTDRWORKSHOP_LOCATION/backend; ./undeploy.sh</copy>
144+
```
145+
2. Rebuild the image + Deploy + (Re)Configure the API Gateway
146+
147+
148+
## **STEP 5**: Configure the API Gateway
149+
150+
The API Gateway protects any RESTful service running on Container Engine for Kubernetes, Compute, or other endpoints through policy enforcement, metrics and logging.
151+
Rather than exposing the Helidon service directly, we will use the API Gateway to define cross-origin resource sharing (CORS).
152+
153+
1. From the hamburger menu navigate **Developer Services** > **API Management > Create Gateway**
154+
![](images/API-Gateway-menu.png " ")
155+
156+
2. Configure the basic info: name, compartment, VCN and Subnet
157+
- VCN: pick on of the vitual circuit network
158+
- Subnet pick the public subnet
159+
The click "Create"
160+
![](images/Basic-gateway.png " ")
161+
162+
3. Click on Todolist gateway
163+
![](images/Gateway.png " ")
164+
165+
4. Click on Deployments
166+
![](images/Deployment-menu.png " ")
167+
168+
5. Create a todolist deployment
169+
![](images/Deployment.png " ")
170+
171+
172+
6. Configure Cross-origin resource sharing (CORS) policies
173+
CORS is a security mechanism that will prevent running application loaded from origin A from using resources from another origin B.
174+
Allowed Origins: is the list of all servers (origins) that are allowed to access the API deployment typically your Kubernetes cluster IP.
175+
Allowed methods: GET, PUT, DELETE, POST, OPTIONS are all needed.
176+
![](images/Origins-Methods.png " ")
177+
178+
7. Configure the Headers
179+
![](images/Headers.png " ")
180+
181+
8. Configure the routes: we will define two routes:
182+
- /todolist for the first two APIs: GET, POST and OPTIONS
183+
![](images/Route-1.png " ")
184+
185+
- /todolist/{id} for the remaining three APIs: (GET, PUT and DELETE)
186+
![](images/Route-2.png " ")
187+
188+
189+
## **STEP 6**: Testing the backend application through the API Gateway
190+
191+
1. Navigate to the newly create Gateway Deployment Detail an copy the endpoint
192+
![](images/Gateway-endpoint.png " ")
193+
194+
2. Testing through the API Gateway endpoint
195+
postfix the gateway endpoint with "/todolist" as shown in the image below
196+
![](images/Backend-Testing.png " ")
197+
198+
It should display the Todo Item(s) in the TodoItem table. At least the row you have created in Part I.
199+
200+
Congratulations, you have completed Part II; you may now proceed to the final part (i.e., Part III).
201+
202+
## Acknowledgements
203+
* **Workshop by** - Kuassi Mensah, Dir. Product Management, Java Database Access
204+
* **Application by** - Jean de Lavarene, Sr. Director of Development, JDBC/UCP
205+
* **Original scripts by** - Paul Parkinson, Developer Evangelist, Microservices
206+
207+
## Need Help?
208+
Please submit feedback or ask for help using this [LiveLabs Support Forum](https://community.oracle.com/tech/developers/categories/building-microservices-with-oracle-converged-database). Please login using your Oracle Sign On and click the **Ask A Question** button to the left. You can include screenshots and attach files. Communicate directly with the authors and support contacts. Include the *lab* and *step* in your request.

backend/build.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
## MyToDoReact version 1.0.
3+
##
4+
## Copyright (c) 2021 Oracle, Inc.
5+
## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
7+
SCRIPT_DIR=$(dirname $0)
8+
9+
IMAGE_NAME=todolistapp-helidon-se
10+
IMAGE_VERSION=0.1
11+
12+
if [ -z "DOCKER_REGISTRY" ]; then
13+
echo "Error: DOCKER_REGISTRY env variable needs to be set!"
14+
exit 1
15+
fi
16+
17+
export IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}:${IMAGE_VERSION}
18+
mvn install
19+
docker build -f src/main/docker/Dockerfile -t $IMAGE .
20+
# mvn package docker:build
21+
22+
# if [ $DOCKERBUILD_RETCODE -ne 0 ]; then
23+
if [ $? -ne 0 ]; then
24+
exit 1
25+
fi
26+
docker push $IMAGE
27+
# if [ $? -eq 0 ]; then
28+
# docker rmi ${IMAGE}
29+
# fi

backend/deploy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
## MyToDoReact version 1.0.
3+
##
4+
## Copyright (c) 2021 Oracle, Inc.
5+
## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
SCRIPT_DIR=$(dirname $0)
7+
export CURRENTTIME=$( date '+%F_%H:%M:%S' )
8+
echo CURRENTTIME is $CURRENTTIME ...this will be appended to generated deployment yaml
9+
cp src/main/k8s/app.yaml todolistapp-helidon-se-deployment-$CURRENTTIME.yaml
10+
#may hit sed incompat issue with mac
11+
sed -i "s|%DOCKER_REGISTRY%|${DOCKER_REGISTRY}|g" todolistapp-helidon-se-deployment-$CURRENTTIME.yaml
12+
kubectl apply -f $SCRIPT_DIR/todolistapp-helidon-se-deployment-$CURRENTTIME.yaml
13+
14+
#kubectl create -f $SCRIPT_DIR/todolistapp-helidon-se-service.yaml -n todoapplication
26.2 KB
Loading

backend/images/Backend-APIs.png

45.4 KB
Loading

backend/images/Backend-Testing.png

42.1 KB
Loading

backend/images/Basic-gateway.png

57.2 KB
Loading
68.2 KB
Loading

backend/images/CORS-Main.png

48.1 KB
Loading

0 commit comments

Comments
 (0)