|
| 1 | +# Set Up the ORDS Instances |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This lab walks you through the steps to set up two Oracle REST Data Services (ORDS) applications, Department 1 and Department 2. These applications are created in PL/SQL and deployed using ORDS in Oracle Database. These applications participate in the XA transaction, so they are called transaction participant services. |
| 6 | + |
| 7 | +There are 2 PDBs (pluggable database) and a catalog database running in a standalone instance of Oracle Database 23c Free to simulate the distributed transaction. Here are the details about the PDBs: |
| 8 | + |
| 9 | +* FREE: A catalog database that the `sysdba` user can access. |
| 10 | +* FREEPDB1: A pluggable database that contains the OTMM schema. This is connected to Department 1, an ORDS service. |
| 11 | +* FREEPDB2 : A pluggable database that contains the OTMM schema. This is connected to Department 2, an ORDS service. |
| 12 | + |
| 13 | +The standalone ORDS APEX service instance, runs on port 8080, and it is configured with two database pools that connect to FREEPDB1 and FREEPDB2. The ORDS service creates database pool for each PDB and exposes the REST endpoint. A single ORDS standalone service has two database connection pools connecting to different PDBs: FREEPDB1 and FREEPDB2. Department 1 and Department 2 connect to individual PDBs and the ORDS participant services expose three REST APIs, namely withdraw, deposit and get balance. The MicroTx library includes headers that enable the participant services to automatically enlist in the transaction. These microservices expose REST APIs to get the account balance and to withdraw or deposit money from a specified account. They also use resources from resource manager. |
| 14 | + |
| 15 | +Estimated Time: 15 minutes |
| 16 | + |
| 17 | +### Objectives |
| 18 | + |
| 19 | +In this lab, you will: |
| 20 | + |
| 21 | +* Start the Database service and ORDS service instances |
| 22 | +* Grant privileges to the database schema |
| 23 | +* Set Up Department 1 and Department 2 applications |
| 24 | +* Test access to the applications |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | + |
| 28 | +This lab assumes you have: |
| 29 | + |
| 30 | +* An Oracle Cloud account. |
| 31 | +* Successfully completed the previous labs: |
| 32 | + * Get Started |
| 33 | + * Lab 1: Prepare setup |
| 34 | + * Lab 2: Environment setup |
| 35 | +* Logged in using remote desktop URL as an `oracle` user. If you have connected to your instance as an `opc` user through an SSH terminal using auto-generated SSH Keys, then you must switch to the `oracle` user before proceeding with the next step. |
| 36 | + |
| 37 | + ```text |
| 38 | + <copy> |
| 39 | + sudo su - oracle |
| 40 | + </copy> |
| 41 | + ``` |
| 42 | + |
| 43 | +## Task 1: Start the Database Service and ORDS Service Instances |
| 44 | + |
| 45 | +1. Run the following command to verify that the Oracle Database 23c Free service instance is running. |
| 46 | + |
| 47 | + ```text |
| 48 | + <copy> |
| 49 | + sudo /etc/init.d/oracle-free-23c status |
| 50 | + </copy> |
| 51 | + ``` |
| 52 | +
|
| 53 | + **Example output** |
| 54 | +
|
| 55 | + ```text |
| 56 | + Status of the Oracle FREE 23c service: |
| 57 | + LISTENER status: RUNNING |
| 58 | + FREE Database status: RUNNING |
| 59 | + ``` |
| 60 | +
|
| 61 | + If the Oracle Database 23c Free service instance is not in the `RUNNING` state, then run the following command to restart the service. |
| 62 | +
|
| 63 | + ```text |
| 64 | + <copy> |
| 65 | + sudo systemctl restart oracle-free-23c |
| 66 | + </copy> |
| 67 | + ``` |
| 68 | +
|
| 69 | +2. Run the following commands in a new terminal to start the Oracle REST Data Services (ORDS) standalone service. Keep this terminal window open throughout the lab. |
| 70 | +
|
| 71 | + ```text |
| 72 | + <copy> |
| 73 | + export _JAVA_OPTIONS="-Xms8192M -Xmx8192M" |
| 74 | + ords --config ${ORDS_CONFIG} serve |
| 75 | + </copy> |
| 76 | + ``` |
| 77 | +
|
| 78 | +3. Reset the password for the `SYS` user by logging into the catalog database with the default password. |
| 79 | +
|
| 80 | + ```SQL |
| 81 | + <copy> |
| 82 | + sql sys/Passw0rd@FREE as sysdba |
| 83 | + SQL> ALTER USER SYS IDENTIFIED BY [new-user-password]; |
| 84 | + SQL> ALTER USER SYSTEM IDENTIFIED BY [new-user-password]; |
| 85 | + SQL> commit; |
| 86 | + SQL> exit; |
| 87 | + </copy> |
| 88 | + ``` |
| 89 | +
|
| 90 | + Where, `[new-user-password]` is the new password that you specify for FREE, a catalog database. |
| 91 | +
|
| 92 | +## Task 2: Grant Privileges to the Schema in FREEPDB1 |
| 93 | +
|
| 94 | +1. Login to FREEPDB1 using the default username and password. |
| 95 | +
|
| 96 | + ```SQL |
| 97 | + <copy> |
| 98 | + sql sys/Passw0rd@FREEPDB1 as sysdba |
| 99 | + </copy> |
| 100 | + ``` |
| 101 | +
|
| 102 | +2. Change the default password. |
| 103 | +
|
| 104 | + ```SQL |
| 105 | + <copy> |
| 106 | + ALTER USER OTMM IDENTIFIED BY [<new-freepdb1-password>]; |
| 107 | + commit; |
| 108 | + exit; |
| 109 | + </copy> |
| 110 | + ``` |
| 111 | +
|
| 112 | + Where, `<new-freepdb1-password>` is the new password that you want to set. |
| 113 | +
|
| 114 | +3. Run the following commands to grant privileges to the schema. |
| 115 | +
|
| 116 | + ```SQL |
| 117 | + <copy> |
| 118 | + DECLARE |
| 119 | + l_principal VARCHAR2(20) := 'OTMM'; |
| 120 | + begin |
| 121 | + DBMS_NETWORK_ACL_ADMIN.append_host_ace ( |
| 122 | + host => '*', |
| 123 | + lower_port => null, |
| 124 | + upper_port => null, |
| 125 | + ace => xs$ace_type(privilege_list => xs$name_list('http'), |
| 126 | + principal_name => l_principal, |
| 127 | + principal_type => xs_acl.ptype_db)); |
| 128 | + end; |
| 129 | + / |
| 130 | + |
| 131 | + DECLARE |
| 132 | + l_principal VARCHAR2(20) := 'OTMM'; |
| 133 | + begin |
| 134 | + DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( |
| 135 | + host => '*', |
| 136 | + ace => xs$ace_type(privilege_list => xs$name_list('connect', 'resolve'), |
| 137 | + principal_name => l_principal, |
| 138 | + principal_type => xs_acl.ptype_db)); |
| 139 | + end; |
| 140 | + / |
| 141 | + </copy> |
| 142 | + ``` |
| 143 | +
|
| 144 | + Where, `OTMM` is the username that can access the schema. |
| 145 | +
|
| 146 | +4. Commit the changes and exit from SQL prompt. |
| 147 | +
|
| 148 | + ```SQL |
| 149 | + <copy> |
| 150 | + SQL> commit; |
| 151 | + SQL> exit; |
| 152 | + </copy> |
| 153 | + ``` |
| 154 | +
|
| 155 | +## Task 3: Grant Privileges to the Schema in FREEPDB2 |
| 156 | +
|
| 157 | +1. Login to FREEPDB2 using the default username and password. |
| 158 | +
|
| 159 | + ```SQL |
| 160 | + <copy> |
| 161 | + sql sys/Passw0rd@FREEPDB2 as sysdba |
| 162 | + </copy> |
| 163 | + ``` |
| 164 | +
|
| 165 | +2. Change the default password. |
| 166 | +
|
| 167 | + ```SQL |
| 168 | + <copy> |
| 169 | + ALTER USER OTMM IDENTIFIED BY [<new-freepdb2-password>]; |
| 170 | + commit; |
| 171 | + exit; |
| 172 | + </copy> |
| 173 | + ``` |
| 174 | +
|
| 175 | + Where, `<new-freepdb2-password>` is the new password that you want to set. |
| 176 | +
|
| 177 | +3. Run the following commands to grant privileges to the schema. |
| 178 | +
|
| 179 | + ```SQL |
| 180 | + <copy> |
| 181 | + DECLARE |
| 182 | + l_principal VARCHAR2(20) := 'OTMM'; |
| 183 | + begin |
| 184 | + DBMS_NETWORK_ACL_ADMIN.append_host_ace ( |
| 185 | + host => '*', |
| 186 | + lower_port => null, |
| 187 | + upper_port => null, |
| 188 | + ace => xs$ace_type(privilege_list => xs$name_list('http'), |
| 189 | + principal_name => l_principal, |
| 190 | + principal_type => xs_acl.ptype_db)); |
| 191 | + end; |
| 192 | + / |
| 193 | + |
| 194 | + DECLARE |
| 195 | + l_principal VARCHAR2(20) := 'OTMM'; |
| 196 | + begin |
| 197 | + DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( |
| 198 | + host => '*', |
| 199 | + ace => xs$ace_type(privilege_list => xs$name_list('connect', 'resolve'), |
| 200 | + principal_name => l_principal, |
| 201 | + principal_type => xs_acl.ptype_db)); |
| 202 | + end; |
| 203 | + / |
| 204 | + </copy> |
| 205 | + ``` |
| 206 | +
|
| 207 | + Where, `OTMM` is the username that can access the schema. |
| 208 | +
|
| 209 | +4. Commit the changes and exit from SQL prompt. |
| 210 | +
|
| 211 | + ```SQL |
| 212 | + <copy> |
| 213 | + SQL> commit; |
| 214 | + SQL> exit; |
| 215 | + </copy> |
| 216 | + ``` |
| 217 | +
|
| 218 | +## Task 4: Set Up Department 1 |
| 219 | +
|
| 220 | +1. Enter the SQL Developer web URL, `http://localhost:8080/ords/sql-developer`, to access Department 1 database. |
| 221 | + A sign-in page for Database Actions is displayed. |
| 222 | +
|
| 223 | +2. Enter the new password to access the FREE database as `sysdba` user. |
| 224 | +
|
| 225 | + The Database Actions page is displayed. |
| 226 | +
|
| 227 | +3. In the **Development** box, click **SQL**. |
| 228 | +
|
| 229 | +  |
| 230 | +
|
| 231 | +4. Open the `tmmxa.sql` SQL script file which is located at `/home/oracle/OTMM/otmm-23.4.1/samples/xa/plsql/lib`. |
| 232 | +
|
| 233 | +5. Click **Run as SQL script** to run the `tmmxa.sql` SQL script file. |
| 234 | +
|
| 235 | +  |
| 236 | +
|
| 237 | +6. Open the `ordsapp.sql` SQL script file which is located at `/home/oracle/OTMM/otmm-23.4.1/samples/xa/plsql/databaseapp`. |
| 238 | +
|
| 239 | +7. In the script, search for `resManagerId` and enter a unique resource manager ID to identify the database in both the `deposit` and `withdraw` handlers. |
| 240 | +
|
| 241 | + **Example Code** |
| 242 | +
|
| 243 | + ```text |
| 244 | + <copy> |
| 245 | + resManagerId VARCHAR2(256):= ''DEPT1-RM''; |
| 246 | + </copy> |
| 247 | + ``` |
| 248 | +
|
| 249 | + ```text |
| 250 | + <copy> |
| 251 | + resManagerId VARCHAR2(256):= ''DEPT1-RM''; |
| 252 | + </copy> |
| 253 | + ``` |
| 254 | +
|
| 255 | +7. Click **Run as SQL script** to run the `ordsapp.sql` SQL script file. |
| 256 | +
|
| 257 | +  |
| 258 | +
|
| 259 | +8. Log out from SQL Developer. |
| 260 | +
|
| 261 | +## Task 5: Set Up Department 2 |
| 262 | +
|
| 263 | +1. Enter the SQL Developer web URL, `http://localhost:8080/ords/pool2/sql-developer`, to access Department 2 database. |
| 264 | + A sign-in page for Database Actions is displayed. |
| 265 | +
|
| 266 | +2. Enter the schema username and password that you have specified in the previous tasks. |
| 267 | +
|
| 268 | + The Database Actions page is displayed. |
| 269 | +
|
| 270 | +3. In the **Development** box, click **SQL**. |
| 271 | +
|
| 272 | +  |
| 273 | +
|
| 274 | +4. Open the `tmmxa.sql` SQL script file which is located at `/home/oracle/OTMM/otmm-23.4.1/samples/xa/plsql/lib`. |
| 275 | +
|
| 276 | +5. Click **Run as SQL script** to run the script file. |
| 277 | +
|
| 278 | +  |
| 279 | +
|
| 280 | +6. Open the `ordsapp.sql` SQL script file which is located at `/home/oracle/OTMM/otmm-23.4.1/samples/xa/plsql/databaseapp`. |
| 281 | +
|
| 282 | +7. In the script, search for `resManagerId` and enter a unique resource manager ID to identify the database in both the `deposit` and `withdraw` handlers. |
| 283 | +
|
| 284 | + **Example Code** |
| 285 | +
|
| 286 | + ```text |
| 287 | + <copy> |
| 288 | + resManagerId VARCHAR2(256):= ''DEPT2-RM''; |
| 289 | + </copy> |
| 290 | + ``` |
| 291 | +
|
| 292 | + ```text |
| 293 | + <copy> |
| 294 | + resManagerId VARCHAR2(256):= ''DEPT2-RM''; |
| 295 | + </copy> |
| 296 | + ``` |
| 297 | +
|
| 298 | +8. Click **Run as SQL script** to run the script file. |
| 299 | +
|
| 300 | +  |
| 301 | +
|
| 302 | +9. Log out from SQL Developer. |
| 303 | +
|
| 304 | +## Task 6: Test Access to Department 1 and Department 2 |
| 305 | +
|
| 306 | +Run the following commands to test access and verify that REST API calls to Department 1 and Department 2 are executed successfully. |
| 307 | +
|
| 308 | +1. Run the following command to retrieve the balance in account 1 of Department 1. |
| 309 | +
|
| 310 | + ```text |
| 311 | + <copy> |
| 312 | + curl --location --request GET 'http://localhost:8080/ords/otmm/accounts/account1' |
| 313 | + </copy> |
| 314 | + ``` |
| 315 | +
|
| 316 | +2. Run the following command to retrieve the balance in account 2 of Department 2. |
| 317 | +
|
| 318 | + ```text |
| 319 | + <copy> |
| 320 | + curl --location --request GET 'http://localhost:8080/ords/pool2/otmm/accounts/account2' |
| 321 | + </copy> |
| 322 | + ``` |
| 323 | +
|
| 324 | +You may now **proceed to the next lab.** |
| 325 | +
|
| 326 | +## Learn More |
| 327 | +
|
| 328 | +* [REST Data Services Developer's Guide](https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/) |
| 329 | +
|
| 330 | +## Acknowledgements |
| 331 | +
|
| 332 | +* **Author** - Sylaja Kannan |
| 333 | +* **Contributors** - Brijesh Kumar Deo and Bharath MC |
| 334 | +* **Last Updated By/Date** - Sylaja Kannan, February 2024 |
0 commit comments