Friday, 17 August 2018

Develop, Deploy & Debug a Hana Node.js app (xsjs) using Hana DBaaS on cloud foundry.

This blog will cover 4 steps in end to end development and deployment of the app to cf.

1. Create the Hana database using the Hana Service (DBaaS) on cloud foundry (CF)
2. Configure Web IDE Full stack to work with cloud foundry.
3. Deploy the App on CF.
4. Debugging using webide fullstack.

Step 1: Configure Hana service on CF.


Goto space -> Service marketplace -> SAP Hana Service.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Click on the different plans based on your entitlements.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Set the password and other parameters like size .(eg min size is 32 GB and can be increased in 16GB block increments)

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Step 2: Configure Web IDE Full stack to work with cloud foundry.


Web IDE fullstack is available on  neo but not on CF.

So , we need to configure the webideFullStack from neo to work with CF. Basically, we need to deploy a builder app that would be used for building/deploying apps built in webidefullstack.

Goto neo subaccount -> Services -> Web IDE Full stack

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Click on Configure service and then provide necessary authorizations to your user (say P12345).

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now click on goto service which opens the webide full-stack.

In web ide fullstack, Goto Settings -> cloud foundry ->

Select your CF endpoint. You will be asked for CF login emailed / password. After you enter the login credentials, select the Org & Space to deploy the builder App.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Finally click on the Install builder and save it.

Also enable hana and Node dev features in Web IDE full stack as shown below.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now if you goto your space in the CF environment, you should be able to see the builder app(webide-builde-sapwebide-ID) under your applications.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Step 3: Deploying a nodejs application to CF.


Goto webide fullstack and create a new project from template.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now create a new Hana Database module in the MTA.(Multitarget application)

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Make sure to select the correct version. Based on the info in the Hana service cockpit.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

i.e goto the Hana cockpit to find the version info in cloud foundry. CF->space->services -> service market place -> Hana service -> instance

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Also make a note of the Database ID highlighted below. Hana service dashboard*****

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now create a new node Js module in webide full stack.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Enable the XSJS support.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now click on mta.yaml and use the MTA editor.

Click on the nodejs module and select requires(+). And select the db module & save.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now edit the mta.yaml file to configure the Hana DBaaS settings. Refer Hana service dashboard*****

above for the database ID. Use space instead of tabs to avoid indentation errors.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

First build the DB module and then the nodejs module.i.e right click -> build module.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

You can edit the Index.xsjs in the lib folder of the node module to establish a db connection and do a select from the dummy table.

$.response.contentType = “text/html”;

var output = “Welcome <br><br>”;

var connectn = $.db.getConnection(); //Open a database conn

//PrepareSQL statement on the sys table “DUMMY”

var pstatement = connectn.prepareStatement(“select * from DUMMY”);

var result = pstatement.executeQuery();

//Check the query result

if (!result.next()) {

$.response.setBody(“Failed to retrieve info!!”); // Return error

$.response.status = $.net.http.INTERNAL_SERVER_ERROR;

} else {

output = output + “Query execution result:  ” + result.getString(1);

}

result.close();

pstatement.close();

connectn.close(); //Close the  connections

$.response.setBody(output);

Now , if you click on node module & Run -> Run as node application, you will see a an application deployed and running on CF under applications. This might take couple of minutes.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

4. Debugging using WebIDE fullstack.


Start the application.

Click on the debug icon on the right as shown below.

Click on the connect icon to attach the debugger to the application.

Set some breakpoint at the beginning of index.xsjs.

Rerun the application url,

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

Now you will be able to see the control coming to the breakpoint in index.xsjs.

SAP HANA Guides, SAP HANA Learning, SAP HANA Tutorial and Material, SAP HANA Study Materials

6 comments:

  1. Thanks for sharing an excellent post, which is helped to me. Surely I suggest to this blog for my friends and I got extra knowledge from your post. Keep it up and I like more new posts...
    Linux Training in Chennai
    Linux Course in Chennai
    Pega Training in Chennai
    Primavera Training in Chennai
    Unix Training in Chennai
    Embedded System Course Chennai
    Linux Training in OMR
    Linux Training in Velachery

    ReplyDelete