Skip to Content

In this blog we will be enabling communication from SAP HANA system on SAP HANA Cloud Platform to the Virtual Machine and then enable R server for HANA.

Before we proceed some pointers that has to be taken into account:

  1. You have created a Virtual Machine and have key to connect.
  2. You have opened tunnel for communicating to the virtual machine.
  3. You have logged in to the virtual machine as a root user.
  4. You have Java installed.
  5. Environment variable JAVA_HOME is set to the Java installation folder.
  6. You have set up your development environment in Eclipse IDE with SAP HANA Tools.
  7. You have a user in HANA having system privilege “CREATE R SCRIPT”. If you do not have permissions to do so, request permissions by reporting an incident in component BC-NEO-PERS.
  8. You have downloaded and installed SAP HANA Cloud Paltform SDK.
  9. You have basic understanding of Eclipse, Linux, HANA and SAP HANA Cloud Platform Cockpit.
  10. When you execute the commands try to use the latest version.

Exercise 1: Install and Configure R

In this exercise we will install R.

1. Execute:
zypper addrepo -f https://slesrepo.hana.ondemand.com/repo/SUSE/Products/SLE-SERVER/12/x86_64/product/ SUSE12

2. Execute
zypper addrepo -f https://slesrepo.hana.ondemand.com/repo/SUSE/Products/SLE-SDK/12/x86_64/product/ SUSE12SDK

Note: The steps 1-2 are performed so that we can have the repositories required to install R.

3. Execute: zypper repos

Note: This command will list all the added repositories.

4. Execute: zypper install gcc gcc-c++ gcc-fortran

Note: This command will install the dependencies required for compiling R.

5. Press “1” and enter.

Note: When you execute the above step there are some versioning issue with gcc-fortran, to continue the installation you are provided with some solution.

This step is done to downgrade the version by pressing the number of the solution as shown in the figure. (Order might change)

6. Press “y” and enter.

Note: This will retrieve the packages and install them.

7. Execute the command to download R source package.

wget http://ftp.iitm.ac.in/cran/src/base/R-2/R-2.15.0.tar.gz

Note: For information about supported versions of R and Rserve, see SAP HANA and R compatibility and support.

8. Execute:  tar zxf R-2.15.0.tar.gz

Note: This is done to extract the tar.gz file

9. Execute: ls

Note: This step is done to list the contents of the directory.

10. Execute: cd R-2.15.0/

Note: This will change the directory to R-2.15.0

11. Execute:  ./configure –enable-R-shlib –with-readline=no –with-x=no

12. Execute:  make clean

Note: This step is done to compile R.

13. Execute: make

Note: This step might take some time.

14. Execute: make install

15. Execute:  R

Note: This step is done to check if R has been installed. You should see the following output.

16. Execute:  q()

Note: This step is done to exit from R. Note: When prompted to Save workspace image: Press “n” and Enter.

Summary: You have built R from source and installed it on the virtual machine.

Exercise 2: Install and Configure R server

In this step we will install and configure R server.

1. Execute command to download the Rserve package:

wget http://cran.rstudio.com/src/contrib/Rserve_1.7-3.tar.gz

2. Execute R and then execute:

install.packages(“Rserve_1.7-3.tar.gz”, repos = NULL)

Note: This command will install the package.

3. Execute: library(“Rserve”)

Note: Successful installation should return no output.

4. Execute: q()
5. When prompted to Save Workspace image. Press “n”.
6. Press Enter.

7. Execute:  vi /etc/Rserv.conf

Follow the steps below to insert and save the entry.

Press I 
Type remote enable
Press the keys in the following order Esc<space>:wq!

8. Execute:  useradd ruser

Note: This step is done to create a user.

9. Execute: passwd ruser

Note: This step is done to add password to ruser.

10. Execute:  su –l ruser

Note: This step is done to login as ruser.

11. Execute: R CMD Rserve –RS-port <port_number> –no-save –RS-encoding “utf8”

R server has started in daemon mode.

Note: The port that you will provide here is the one that you will create in next exercise “Enabling Communication to Virtual Machine”.

Summary: You have installed R server on your VM and successfully started it in daemon mode.

Exercise 3: Enabling Communication to Virtual Machine.

By default, outbound communication from the virtual machines to the Internet and other systems is allowed, but inbound communication has to be enabled.

In this exercise we will be enabling communication from SAP HANA system to the virtual machine.

1. Login to your cockpit.
2. Click on “Databases & Schemas”. Copy the ID of the HANA system.
3. Execute:

neo create-security-rule –account <your_hcp_account_name> –host hana.ondemand.com –user <s/p/i user id> –name <your_vm_name> –source-id <id of HANA system> –source-type HANA –from-port 4000 –to-port 4000

Note: This step is to create the security rule to specify the ports allowed for inbound communication.
Also use this port number in Exercise 2 Step 11.

Summary: You have enabled communication on the virtual machine by creating security rule, now the HANA system can connect to this VM.

Exercise 4: Configure SAP HANA

Depending on your system landscape and your R requirements, you may need to modify some of the SAP HANA database configurations, from the Administration editor in the SAP HANA studio.

To enable calling R procedures from the index server, the configuration parameters are under indexserver.inicalcEngine.

1. Open Eclipse.
2. Click on “Open Perspective

3. Scroll down and select “SAP HANA Administration Console”.
4. On the left pane “Right click” and click on “Add Cloud System
5. Enter the details as follows:

Landscape host: eu1.hana.ondemand.com
Account name: Your hcp account name
Username: your s/p/i userid.
Password: your s/p/i password. Click Next.

6. Enter the details as:

Databases: your database id
Database user: your database user
Database password: Your HANA db password. Click Finish.

7. You can now see the SAP HANA Cloud system that you have added on the left pane.

8. Right click on the cloud system and then on “Configuration and Monitoring” and then “Open Administration
9. Click on “Configuration” then click on “indexserver.ini” and click on “calcengine”.

Note: This step is done to change some of the configuration properties required to run R specifically ip address .

10. Copy the IP address of VM from cockpit and the port number that you created in Exercise 3 Step 3 and put it in the new value as shown below: Click Save.

Exercise 5: Using R with SAP HANA

In this exercise we will test the connection between SAP HANA and R Server installed on the virtual machine

To create some initial data for our example, we use the dataset ‘spam’ provided by R and upload it to the SAP HANA database.

Note: To execute the R procedure successfully you have to download kernlab package and install it.
Note: You are logged in to VM as ruser.

1. Execute:

wget https://cran.r-project.org/src/contrib/kernlab_0.9-24.tar.gz

Note: This command will download Kernlab package

2. Execute R.
Execute:

install.packages(“kernlab_0.9-24.tar.gz”, repos = NULL)

3. Execute: library(“kernlab”)

Note: Successful installation should return no output.

4. Execute q(). Press “n” when prompted to save workspace. Press Enter
5. In Eclipse on your cloud system that you have added open the “SQL Console
6. Copy the below script and paste on the SQL console and execute:

DROP TABLE "spam";
CREATE COLUMN TABLE "spam"(
"make" DOUBLE, "address" DOUBLE, "all" DOUBLE, "num3d" DOUBLE, "our" DOUBLE,
"over" DOUBLE, "remove" DOUBLE, "internet" DOUBLE, "order" DOUBLE, "mail" DOUBLE, "receive" DOUBLE, "will" DOUBLE, "people" DOUBLE, "report" DOUBLE,
"addresses" DOUBLE, "free" DOUBLE, "business" DOUBLE, "email" DOUBLE, "you" DOUBLE, "credit" DOUBLE, "your" DOUBLE, "font" DOUBLE, "num000" DOUBLE, "money" DOUBLE, "hp" DOUBLE, "hpl" DOUBLE, "george" DOUBLE, "num650" DOUBLE, "lab" DOUBLE,
"labs" DOUBLE, "telnet" DOUBLE, "num857" DOUBLE, "data" DOUBLE, "num415" DOUBLE,
"num85" DOUBLE, "technology" DOUBLE, "num1999" DOUBLE, "parts" DOUBLE,
"pm" DOUBLE, "direct" DOUBLE, "cs" DOUBLE,"meeting" DOUBLE, "original" DOUBLE, "project" DOUBLE, "re" DOUBLE, "edu" DOUBLE, "table" DOUBLE, "conference" DOUBLE, "charSemicolon" DOUBLE, "charRoundbracket" DOUBLE, "charSquarebracket" DOUBLE, "charExclamation" DOUBLE, "charDollar" DOUBLE, "charHash" DOUBLE,
"capitalAve" DOUBLE, "capitalLong" DOUBLE, "capitalTotal" DOUBLE,
"type" VARCHAR(5000), "group" INTEGER);
DROP PROCEDURE LOAD_SPAMDATA;
CREATE PROCEDURE LOAD_SPAMDATA(OUT spam "spam")
LANGUAGE RLANG AS
BEGIN
##--if the kernlab package is missing see Requirements
library(kernlab)
data(spam)
ind <- sample(1:dim(spam)[1],2500)
group <- as.integer(c(1:dim(spam)[1]) %in% ind)
spam <- cbind(spam, group)
END;
DROP TABLE "spamTraining";
DROP TABLE "spamEval";
CREATE COLUMN TABLE "spamTraining" like "spam";
CREATE COLUMN TABLE "spamEval" like "spam";
DROP PROCEDURE DIVIDE_SPAMDATA;
CREATE PROCEDURE DIVIDE_SPAMDATA()
AS BEGIN
CALL LOAD_SPAMDATA(spam);
Insert into "spamTraining" select * from :spam where "group"=1;
Insert into "spamEval" select * from :spam where "group"=0;
END;
CALL DIVIDE_SPAMDATA();
Alter Table "spamTraining" DROP ("group");
Alter Table "spamEval" DROP ("group");

After executing the R procedure, your SAP HANA database instance should contain the following two new tables: spamTraining and spamEval.

The log from R server call:
Statement ‘CALL DIVIDE_SPAMDATA()’
Successfully executed in 1.292 seconds (server processing time: 1.256 seconds) – Rows Affected: 4601

Congratulations! You have successfully used R with SAP HANA.

Whats Next?

You can manage volumes for your Virtual Machines.

What are volumes ?

Volumes are persistent storage that is created automatically when a virtual machine is created. It stores the file system and all software installed on it. Using the volume a new VM can be created.

Try these commands:

List the volumes:

neo list-volumes –account <your_account_name> –host hana.ondemand.com –user <s/p/i userid>

Create a new VM from the volume:

neo create-vm –volume-id myvolumeid –size x-small –name myvm –account myaccount –host hana.ondemand.com –user <s/p/i userid>

Delete a volume:

neo delete-volume –volume-id myvolumeid –account myaccount –host hana.ondemand.com –user <s/p/i userid>

To report this post you need to login first.

8 Comments

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

  1. Daniel Kraus

    Hi Gaurav,

     

    could I use a hana virtual machine to deploy my own java stack / glassfish application server?

     

    Could I use other databases than HANA itself?

     

    Best

    Daniel

    (1) 
    1. Gaurav Dey Post author

      Hi Daniel,

      When you create a VM you get a core Linux box, where you can install any of your application/OS not supported by the platform.

      Using SAP HANA provided from HCP would be the recommendation which works out of the box with the VM and is one of the use case, other DB’s like MongoDB, postgres, mysql can also be used.

       

      Regards,

      Gaurav Dey

      (0) 
    1. Gaurav Dey Post author

      Hi Anup,

      Thanks. As I said by default, outbound communication from the virtual machines to the Internet and other systems is allowed.

      Regards,

      Gaurav Dey

      (0) 

Leave a Reply