Technical Articles
Accessing and integrating real-time data between two HANA Clouds using the latest development tools (SAP Business Application Studio) | Virtualization and Smart Data Integration
The aim of this blog is to show how to do real-time replication from one SAP HANA Cloud instance to another. With applying of the latest development technologies, I will build an interesting scenario that will integrate between two cloud instances in such a way that when the data in the original table located in HANA Cloud instance B is changed, the change is automatically reflected in the replicated table located in a remote HANA Cloud instance A without any additional effort.
Prerequisites
For this scenario are needed two different instances of SAP HANA Cloud and for one of them, SAP Business Application Studio for Development should be Set Up.
- Create two SAP HANA Cloud instances in one or two different (trial account has a limit of one SAP HANA Cloud instance per account) global accounts: HANA_A and HANA_B, following the tutorial Deploy SAP HANA Cloud.
- At least for one of the accounts Set Up SAP Business Application Studio for Development (for my scenario this is the account where HANA_A is located)
Goal
To establish successful integration and real-time replication from one SAP HANA Cloud instance to another, which means when the data in the original table, located in instance A is changed, the change is automatically reflected in a replicated table located in a remote instance B without any additional effort.
Set up the development environment
Once the two instances are created, make sure they are started and running (especially if they were created earlier)
Create a table and insert some data
In the Database Explorer of the HANA_B instance, you can log in with the DBADMIN and create schema, table and insert some data into the table.
CREATE SCHEMA MYDATA;
SET SCHEMA MYDATA;
CREATE COLUMN TABLE HOTEL (
HNO INTEGER NOT NULL,
NAME VARCHAR(50) NOT NULL,
ZIP VARCHAR(5),
ADDRESS VARCHAR(40) NOT NULL,
PRIMARY KEY (HNO)
);
INSERT INTO HOTEL VALUES (10, 'Long Island', '11788', '1499 Grove Street');
INSERT INTO HOTEL VALUES (30, 'Lake Michigan', '60601', '354 Oak Terrace');
INSERT INTO HOTEL VALUES (100, 'Beachside', '32018', '1980 34th St.');
INSERT INTO HOTEL VALUES (110, 'Atlantic', '33441', '111 78th St.');
INSERT INTO HOTEL VALUES (120, 'Calypso', '90804', '35 Broadway');
INSERT INTO HOTEL VALUES (130, 'Evening Star', '90029', '13 Beechwood Place');
INSERT INTO HOTEL VALUES (140, 'Steamboat Louis Armstrong', '70112', '788 Main St.');
Set up the instances to be able to see data from the remote instance
1. Create a technical user in the instance HANA_B, to log in with it from the remote instance HANA_A.
CREATE USER MYUSER
PASSWORD <password>
NO FORCE_FIRST_PASSWORD_CHANGE
SET USERGROUP DEFAULT;
GRANT SELECT ON SCHEMA MYDATA TO MYUSER;
SELECT * FROM MYDATA.HOTEL;
2. Set the allowed access of the instance where the data is located, HANA_B
- We can set ‘Allow all IP addresses’ (not recommended for production environment) or
- We can set ‘Allow specific IP addresses and IP ranges’ if we want to have a more secure and protected system.
3. Add a certificate
To download the root certificate, you can go directly to the link: https://dl.cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem (*source)
4. Create a remote source to test the access
You can choose the Name you want, and then specify how to connect, so you are going to use HANA(ODBC). Next, specify the ‘Server’ and for that, you need to go again to the HANA_B instance and copy its Endpoint, paste and remove the port and the semicolon on the end and add the port on the line that follows. Choose the ‘DML Mode’ you need. In the ‘Extra Adapter Properties’ you must specify encrypt=true. For the Credentials, I am going to use the Technical User which I already created in the HANA_B instance in the beginning. Once it is created if you can see the list of the schemas, then all is set up correctly, if not, something is missing then please check again the allowance and the certificate again.
Connect to the Cloud Foundry and create a new project in the SAP Business Application Studio
Create User Provided Service
You need User Provided Service to enable your HDI container to access the objects within your classical schema in Hana Cloud, or in this case, the remote source HANA_B_REMOTE.
1. Create a user in the HANA_A classical schema and grant the required roles to it.
Go back to the SAP Database Explorer of the HANA_A and create the user:
CREATE USER DEVUSER PASSWORD Password1 NO
FORCE_FIRST_PASSWORD_CHANGE SET USERGROUP DEFAULT;
GRANT CATALOG READ TO DEVUSER WITH ADMIN OPTION;
GRANT CREATE SCHEMA TO DEVUSER WITH ADMIN OPTION;
GRANT CREATE REMOTE SOURCE TO DEVUSER WITH ADMIN OPTION;
2. Create the User Provider Service
{
"user": "DEVUSER",
"password": "Password1",
"schema": "DEVUSER",
"tags": [
"hana"
]
}
3. Create the Remote Source
4. Configuration within the HDI container
- Adjust the mta.yaml, declaring the user provided service you created before, and deploy (or Build in WebIDE) the project to be sure that everything works correct.
- Create the specific grants that we want to access within our XS classic schema
{ "grant-service":{ "object_owner":{ "global_object_privileges":[ { "name":"HANA_B_REMOTE", "type":"REMOTE SOURCE", "privileges":[ "CREATE VIRTUAL TABLE", "CREATE VIRTUAL FUNCTION", "CREATE REMOTE SUBSCRIPTION", "PROCESS REMOTE SUBSCRIPTION EXCEPTION", "ALTER", "DROP" ] } ] }, "application_user":{ "global_object_privileges":[ { "name":"HANA_B_REMOTE", "type":"REMOTE SOURCE", "privileges":[ "CREATE VIRTUAL TABLE", "CREATE VIRTUAL FUNCTION", "CREATE REMOTE SUBSCRIPTION", "PROCESS REMOTE SUBSCRIPTION EXCEPTION", "ALTER", "DROP" ] } ] } } }
Create Replication Task
Test the integration
To test the real-time replication, you can run an update on the target table on the source system and see if is replicated in the remote instance.
First, go back to HANA_B and run an update:
set schema MYDATA;
update HOTEL set ADDRESS = '77 Broadway' where HNO = 120;
select * from HOTEL order by HNO;
You can of course perform more tests by inserting or deleting data.
Conclusion
With this scenario, real-time data from a table in remote HANA Cloud is successfully replicated, but with the whole scenario, you can see how to access data from one HANA Cloud instance to another and how to access data from the HDI container to the HANA Cloud instance. Most important, the scenario is built one time and the replicated data is real-time forever.
If you are interested in the topics of HANA Cloud, you can find very nice content in the SAP HANA Academy: SAP HANA Cloud
If you like the approach, of building an interesting scenario by applying the various possibilities offered by Hana, follow me for similar content.