By Dan McGhan
March/April 2018
Two of my favorite Oracle Cloud services are Oracle Database Exadata Express Cloud Service (Exadata Express) and Oracle Application Container Cloud. Exadata Express is a fully managed Oracle Database service at an entry-level price point for small-to-medium-sized data, and Oracle Application Container Cloud is a lightweight infrastructure that provides an easy way to deploy apps in Docker containers. In this article, I’ll demonstrate how to connect these two at the most basic level.
What do I mean by “the most basic level”? The demo app will be minimalistic. Typically, I might use Oracle Developer Cloud Service to create a Git repository with an automated build process—but not here. This article will focus only on what’s needed to get Exadata Express and Oracle Application Container Cloud connected. At a high-level, the steps are
The rest of this article assumes that you have an Oracle Cloud account with access to both Exadata Express and Oracle Application Container Cloud. (If you don’t already have an Oracle Cloud account, you can sign up for a free cloud trial.
To connect and use Exadata Express and Oracle Application Container Cloud, start by creating a new directory named connection-test-app on your local machine.
Now create two files in that directory.
{ "runtime":{ "majorVersion":"8" }, "command": "node index.js", "release": {}, "notes": "" }
Oracle Application Container Cloud apps often include one or two metadata files. In this case, manifest.json specifies the version of Node.js to run and the command to use to start the application. Note that I’ve specified Node.js 8. This means the async/await constructs that I demonstrated in the last part of the async series can be used in the app.
const http = require('http'); const oracledb = require('oracledb'); const dbConfig = { user: process.env.EECS_USER, password: process.env.EECS_PASSWORD, connectString: 'dbaccess' }; let error; let user; async function runConnectionTest() { let conn; try { conn = await oracledb.getConnection(dbConfig); const result = await conn.execute('select user from dual'); user = result.rows[0][0]; error = null; } catch (err) { error = err; } finally { if (conn) { try { await conn.close(); } catch (err) { console.log(err); } } } } runConnectionTest(); http.createServer(function(request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); if (error === null) { response.end('Connection test succeeded. You connected to Exadata Express as ' + user + '!'); } else if (error instanceof Error) { response.write('Connection test failed. Check the settings and redeploy app!\n'); response.end(error.message); } else { response.end('Connection test pending. Refresh after a few seconds...'); } }).listen(process.env.PORT);
The index.js file contains logic that runs a connection test (lines 11–33) and uses a simple web server to deliver the results of the test (lines 35–46). Note that three environment variables are referenced via process.env. PORT is defined by Oracle Application Container Cloud, but the other environment variables will be created in the last step of this tutorial.
Add Exadata Express Client Credentials
To connect to Exadata Express, you must first enable client access and then download the client credentials. The client credentials are needed to encrypt communication between the client (Node.js, in this case) and the database—something that Exadata Express enforces.
Figure 1: Exadata Express console’s Manage screen (with annotations)
Enter and confirm the password, and then click Download. A file named client_credentials.zip will be downloaded to your machine. Treat the downloaded files securely to prevent unauthorized database access.
Figure 2: Contents of the connection-test-app directory
Deploy the App
At this point, you can deploy the app to Oracle Application Container Cloud.
zip -r archive.zip .
Figure 3: Contents of connection-test-app directory, including the archive.zip file
Figure 4: Oracle Application Container Cloud console
Figure 5: Oracle Application Container Cloud application platform choices
Figure 6: Creating the application
The app will appear in the list of Oracle Application Container Cloud applications, where you can obtain its URL, as shown in Figure 7.Figure 7: List of Oracle Application Container Cloud applications
If you navigate to that URL in a browser, as shown in Figure 8, you’ll see that the test has failed; this is expected.Figure 8: Application test fails
Just one last task is required to get everything working: adding environment variables.Figure 9: Adding environment variables
Figure 10: Adding the TNS_ADMIN variable
Figure 11: Apply edits after adding the environment variables
Figure 12: Connection test succeeded
As you can see, connecting Exadata Express and Oracle Application Container Cloud isn’t that difficult once you understand what’s involved. When you work with a real app, I recommend keeping the client credentials separate from the application files and any software configuration management tools, such as Git.
If you are developing apps locally, you can point the TNS_ADMIN environment variable to a local copy of the client credentials used for development. When you deploy apps to another environment in Oracle Application Container Cloud, you can use an Oracle Developer Cloud Service build process to download the correct client credentials from a storage service and add them to the app files before deploying them to Oracle Application Container Cloud.
Next Steps
LEARN more about Oracle Database Exadata Express Cloud Service.
LEARN more about Oracle Application Container Cloud.
TRY Oracle Cloud.
DISCLAIMER: We've captured these popular historical magazine articles for your reference. Links etc contained within these article possibly won't work. These articles are provided as-is with no guarantee that the information within them is the best advice for current versions of the Oracle Database.