Soaring through the Clouds – Part 6: Lightweight Application Container Cloud Service for Rich API Implementation with Node.js

The 6th article in the Soaring Through the Clouds series continues the exploration of an extensive demo created by a group of Oracle ACE directors that allows users to nominate and vote for music artists they want to perform at a special concert. Part 6 looks at the role of Node.js and the ACC instance it is deployed on in the demo.

Introduction

The Application Container Cloud (ACC) is a cloud service with which light weight containers can be provisioned for running complete applications created in technologies such as Node.js and Java SE. Soon, ACC will also offer containers for PHP, Ruby and Python, followed by more technologies. ACC leverages Docker container technology under the covers.

In our multi-cloud demo scenario, ACC played two roles: one as the deployment platform for the Oracle JET rich web application (to be discussed in Part Seven of this series) and the other as the host of a container with a Node.js application that exposes a REST API through which detailed artist records can be retrieved. The implementation of this API leverages several 3rd party services, such as the Spotify and Echo Nest APIs.

In this article, we will discuss this Node.js application and the ACC instance it is deployed on. The orchestration and enrichment service running on SOA CS calls out to the API published by this application to create a very rich artist record that is subsequently saved to the database in the cloud.

Lean API Juggling in Node.js

The challenge for which we used Node.js and ACC consisted of gathering rich details on the proposed artist, such as a biography, an image and a discography of released albums and pictures of their covers. This information is to be recorded from SOA CS through the database adapter in the DBaaS instance. Various APIs are available on the internet for retrieving data on artists; two examples are the Spotify API (https://developer.spotify.com/web-api/ ) and the Echo Nest API (http://developer.echonest.com/docs/v4 ). These APIs expose resources that can be accessed using REST-style interactions and are represented by JSON messages. Various API calls have to be made to collect all the bits of information required. Some of the API calls have limitations, returning a maximum number of records or accepting a restricted list of input parameters. For example, the API operation we invoke to gather the release date and cover image of albums handles no more than 20 albums per call.

Implementing the Artist API in SOA Suite 12c could probably be done as well, but not as easily as in Node.js. The types and the number of REST calls (some sequentially because of dependencies and others in parallel) and the shape of the data to be handled make a Node.js application a very good fit for our challenge: the asynchronous nature of the Node.js platform allows for easy coordination of parallel synchronous calls; the support for making HTTP(S) calls with various headers is easy in Node.js; and manipulating JSON data structures is very straightforward in JavaScript. The large number of relevant code samples and the many community borne Node packages are an extra bonus.

The figure below visualizes the Artist API Node.js application: it exposes a very simple REST API and executes over a dozen REST calls to external APIs. The SOA Composite running on SOA CS makes one simple REST call to the Artist API to collect the complete enriched artist record and merge it with the artist proposal, and persists it to DBaaS before calling out to ICS to tweet about it.

Of special interest in the application is the use of the async module to organize the sequential and parallel activities that are themselves asynchronous in nature. Check out the overarching structure of the main flow through the code, illustrated below.

Two major parallel branches can be discerned, the first dealing with the Spotify API, the second one for the Echo Nest API. The Spotify branch in the code uses the async.waterfall to organize a series of three sequential units. The third unit uses the aync.forEachOf to perform parallel calls for each of the elements in the albumArrays collection—which can contain up to four elements, resulting in four parallel calls from within that forEachOf section. The Echo Nest branch in async.parallel does two subsequent calls, organized in the traditional way: the second request is made in the callback function for the first one.It works as well, but is not as elegant as the use of the asynch module.

Deployment of the application is easily done through the ACC Cloud Service Console. Click on Create Application. In the popup, we can choose between Java SE and NodeJS (and, soon, other technologies). Click on NodeJS.

The next dialog allows me to specify the details for the application and for the ACC subscription’s billing regime as well as the instance sizing parameters. After uploading the application archive, I can click create and have the Node.js container provisioned and my application installed into it.

When the provisioning and deployment are complete, I can inspect the application in the Service Console. In this console, we can define environment variables and service bindings (see next section on integration with DBaaS).

Built-in DBaaS integration support

One valuable feature of the Node.js application container provided by ACC is the pre-installed Node.js Oracle Database driver. This driver is an open-source Node package provided by Oracle Corporation to facilitate interaction from Node.js applications with local or remote Oracle Database instances. Through this driver, a Node.js application can perform queries, DML operations, DDL statements and PL/SQL calls in a way that is very similar to how Java applications use JDBC to connect to a relational database.

Conclusion

Node.js is a server-side JavaScript platform that makes it very easy to implement REST/JSON APIs. Handling incoming HTTP requests and making multiple parallel calls; processing and composing JSON data structures; and dealing with complexities around binary data, custom HTTP headers, certificates and more are pieces of cake.

Running a Node.js application on the Oracle Public Cloud infrastructure is well supported by the Application Container Cloud (ACC). Any Node.js application can simply be packaged as a zip file and quickly deployed to a container in ACC. In the integrated multi-cloud scenario, the Artist API Node.js application leverages several 3rd party APIs to provide a simple interface for rich artist data to the orchestration running on SOA CS.

About the Author

Oracle ACE Director Lucas Jellema is solution architect and CTO at AMIS, based in the Netherlands. An Oracle, Java, and SOA specialist, he works as a consultant, architect, and instructor in diverse areas such as Database & SQL, Java/Java EE, SOA/BPM and PaaS and SaaS Cloud Solutions. The running theme through most of his activities is the transfer of knowledge and enthusiasm (and live demos). Lucas is a well-known speaker at Oracle OpenWorld, JavaOne and various Oracle User Group conferences around the world. His articles have appeared in OTN, OTech and the AMIS Technology Weblog, and he is the author of Oracle SOA Suite 11g Handbook (2014, McGraw Hill) and the Oracle SOA Suite 12c Handbook (2015, McGraw Hill).

This article represents the expertise, findings, and opinion of the author. It has been published by Oracle in this space as part of a larger effort to encourage the exchange of such information within this Community, and to promote evaluation and commentary by peers. This article has not been reviewed by the relevant Oracle product team for compliance with Oracle's standards and practices, and its publication should not be interpreted as an endorsement by Oracle of the statements expressed therein.