Wednesday, May 24, 2017

Ballerina in the Cloud

As discussed in other posts, Ballerina provides integration capabilities in a lean, mobile distribution. Its graphical and textual syntax parity makes it ideal for developers coming in from different backgrounds. Someone who wishes to avoid the textual syntax can do so without losing any programming mobility. Regardless of the syntax chosen, the end result of a designed ballerina program would be a file with a “.bal” extension or a combination of such files archived into files with either “.bsz” or “.bmz” extensions.

WSO2 Integration Cloud is a SaaS imagination of WSO2’s industry trusted enterprise integration solution, apart from handling WSO2 EI projects it is now capable of providing a cost effective means of serving your ballerina projects to the world. This post is meant to help you get started with serving your ballerina services from the cloud,

Creating Ballerina Services


Ballerina services that are meant for the integration cloud maybe created the same manner as any other ballerina service. However, they must be packed into archives prior to uploading. Look to the ballerina packaging documentation[1] if you’re not familiar with this task.

For the moment it is advisable to limit your services to the HTTP transport and to a single archive(if it's a service spanning multiple ballerina files).

Uploading the Services to the Cloud  

Integration Cloud takes care of the administration and configuration tasks associated with serving ballerina integration projects, from containerization of the archives to scaling on demand.

Uploading a ballerina archive to the integration cloud is as easy as logging in, specifying an application name, version and uploading the archive from your local file system. Users may also select instance specifications and pass in environmental variables if required. It is advisable to select a container specification with moderate amount of ram(think 512).

Example


The example below shows the ease at which ballerina integration projects maybe created and served from the cloud. Note that this example was written for Ballerina 0.87.

Prerequisites

Integration Cloud Access: WSO2 integration cloud provides a 2 week trial program, you may avail this offer to try out the example.

Geoname Username: Geoname is a geolocation service made available free of charge for educational purposes. Create an account with Geonames and activate free web service usage through ManageAccounts.

Walk-through


  1. Create the folder structure <BALLERINA_HOME>/geochain/sample
  2. Copy the contents of the gist found below into <BALLERINA_HOME>/geochain/sample/GeoChainService.bal
  3. Navigate to <BALLERINA_HOME> and execute the package command on the service with ./bin/ballerina build service geochain/sample -o GeoChainService.bsz
  4. Login to the integration cloud with your credentials and start creating a new ballerina application (new application -> ballerina -> local file system)
  5. Put in “GeoChain” as the application name, “1.0.0” as the version and upload the newly created archive found at <BALLERINA_HOME>.
  6. Expand the advanced settings section and select a container specification which is more powerful than the one selected by default.
  7. Complete the upload by clicking “Create”.
  8. Give the integration cloud a moment to deploy the service and navigate to the application list to find the GeoChain service deployed. Click on it to get to its overview page and find the service host. It will look like,
    1. http://dumiduh-geochain.wso2apps.com
    2. The service will be available at, <your service host>/geochain



Make a GET to the service with a JSON payload that contains the country code and your geoname username. Example payload and invocation,

curl -X GET -d @payload http://dumiduh-geochain.wso2apps.com/geochain
{"country":"LK","username":"username1102"} 


[1] - http://ballerinalang.org/docs/user-guide/0.8/tutorials/create-archive/



No comments:

Post a Comment