Skip to Content

Here comes the Xs engine!

( or how to schedule jobs for hana using the Xsengine ) 

Blog series starts here

What ‘s this?

In short ,  the Xsengine is a built-in application/web server, and development framework aimed at creating lightweight web applications… And the only thing I’m really interested in with the XS engine right now is… Xscron: the xsengine jobs scheduler…

In the way I build the reporting solution for Hana, I want to use integrated tools as much as possible. There are possibilities to schedule SQL scripts for hana from the outside (using OS cron and hdsql command line for example) but I don’t want that.

In the XSengine scheduler, I’ll create the jobs’ definition and schedules to perform the data loads and housekeeping.

For a deeper review of the XS engine features please review this blog by Thomas Jung.

Hands-on !

To schedule jobs in the xsengine I’ll need to create some objects :

  • xsapp file

This application-descriptor file is required whenever you create an XS application.

More information about this file is available here . These are the steps followed to create it :

Type in “xs a” in order to get the xs related wizards  :

And I just created an empty .xsapp file in my package :

  • xsaccess file

SAP HANA XS enables you to define access to each individual application package that you want to develop and deploy.The application-access file enables you to specify who or what is authorized to access the content exposed by a SAP HANA XS application package and what content they are allowed to see. For example, you use the application-access file to specify if authentication is to be used to check access to package content and if rewrite rules are in place that hide or expose target and source URLs.

Full information about this file, syntax etc … can be found here .I created it just as before in my package using this wizard this time :

I used a very basic template. The syntax is as follows :

{
     "exposed" : true,  
     "authentication" :                                            
            {
               "method": "Form"   
            },
     "cache_control" : "must-revalidate", 
     "cors" :                      
            {
             "enabled" : false
            }, 
     "enable_etags" : false,
     "force_ssl" : false,
     "prevent_xsrf" : true
}

XS Java Scripts & XS Jobs

I chose to schedule the stored procedure through XS Java scripts. These xs java scripts will call the stored procedures defined before ( < link to previous blog ). In order to perform the data loads regularly and automatically, these will be called by the XS jobs we’ll define later on.

  • xsjs scripts

I won’t go into much details about xsjs scripting. To be honest, I didn’t deep dive into it but just overlooked in order to get what I needed for the job to be done :). Should you need more details, resources are available here and there as a starting point.

To define an XS java script, you go through the HDB studio and create an xsjs in your package.

Then the xsjs edition screen opens.

Here, I’ll focus on the syntax I used to schedule the stored procedures. This is a really simplistic code.

function UPDATE_CURRENT_DISKS_USAGE_STATS()
{
    var conn = $.db.getConnection();
    var query = conn.prepareStatement("CALL \"Z_MARKH\".\"Z_MARKH::Z_UPLOAD_HANA_GLOBAL_DISKS_USAGE_CURRENT\" ('%','-1')");
    query.execute();
    conn.commit();
    query.close();
    conn.close();
}

 

This function will:

  1. get the connection details
  2. set the statement to execute. Here I call the stored procedure with the necessary input parameters
  3. execute the statement
  4. perform the commit
  5. close the query
  6. and close the connection to the database

Once you’re fine with your script, you have to activate it just like a table or stored procedure.

  • xsjobs

Now everything is set, we can define a job. To do so, you select the xsjobs wizard :

 

Then the xsjob edition screen opens with a default job definition :

{
    "description": "Read stock value",
    "action": "sample.test:job.xsjs::my_readStock",
    "schedules": [
       {
          "description": "Read current stock value",
          "xscron": "* * * * 9 * 59",
          "parameter": {
             "stock": "SAP.DE"
             }
       }
    ]
}

You can remove it and update with your own job defnition. Mine looks like this :

{
    "description": "HANA daily DISKS statistics update",
    "action": "Z_MARKH:Z_UPDATE_CURRENT_DISKS_USAGE.xsjs::UPDATE_CURRENT_DISKS_USAGE_STATS",
    "schedules": 
    [
       {
          "description": "Current DISKS STAST Update",
          "xscron": "* * * * 5 55 0"
       }
    ]
}

 

A quick review of the fields :

description

Text string used to provide context when the XSjob file is displayed in the SAP HANA XS Administration tool.

action

Text string used to specify the path to the function to be called as part of the job.

schedules

The schedules keyword enables you define the details of the XS job you want to run. Use the following additional keywords to provide the required information:

  • description (optional)

    Short text string to provide context

  • xscron

    Uses cron-like syntax to define the schedule at which the job runs

  • parameter  (optional)

    Defines any values to be used as input parameters by the (XSJS or SQLScript) function called as part of the job

 

More information is available here , and a tutorial more detailed on XSjobs scheduling is available there .

Just like any object, once the XSjob is defined, you have to activate it.

 

Time to wrap it up a little! 

So what have we got so far? Up to now, I have :

  • created a user with the required rights to create and manage the metrics mart,
  • created my development workspace,
  • created the required objects to pull out ( stored procedures ) and store the metrics data ( tables ),
  • defined the jobs required to perform the data loads.

 

Next step 

BOBJ & HANA for Basis (5) …

 

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply