Thursday, 8 August 2019

Develop a Spring Boot (Java) application with HANA database on SAP Cloud Platform (Cloud Foundry) – PART 3

We will continue from where we left off in the previous part where we finished configuring the HANA Database and the user that will communicate with the database.

STEP 4: Deploy the Application


Let’s build the war file first. If you are using Eclipse, then perform a maven build and specify profile as cf. Otherwise, you can also build the application using maven command line tool with the following command –

mvn clean install -P cf

Let’s push the application to cloud foundry space now.To deploy the application, execute the following command from project root –

cf push

If everything goes alright, you should have your application deployed in Cloud Foundry. You can check the status of the application using –

cf app spring-hana-cloud-foundry

SAP HANA Tutorial and Material, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Online Exam

Yay ! The application is deployed. You can try out the endpoints as follows –

1. GET <APP-ROOT>/employee/count -> Returns count of total employees in database.
2. GET <APP-ROOT>/employee/all -> Returns all employees in database.
3. GET <APP-ROOT>/employee/id/{id} -> Returns the employee instance corresponding to the ID.
4. POST <APP-ROOT>/employee/add -> Add a new employee in database. Use the following payload in body –

{
"id":"1",
"firstName":"Boudhayan",
"lastName":"Dev",
"email":"email@example.com",
"contact":"12121212"
}

5. DELETE <APP-ROOT>/employee/delete/{id} -> Delete particular employee from database.

STEP 5: Check Database content.


Execute few POST requests as listed above to insert some items in the database. We will now check the database with the Database user to see those records –

Launch SAP HANA Cockpit with the Database user –

SAP HANA Tutorial and Material, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Online Exam

If you are still logged on with the SYSTEM user, try logging out by clicking Clear Credentials. This would prompt you to enter credentials. Use the credentials found in the service key that we created earlier in step 3.

Once logged in, click Open SQL Console. This will open the database explorer where you can check the database artifacts created by this user –

SAP HANA Tutorial and Material, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Online Exam

As you can see, the table – EMPLOYEE exists for the database user. If you open the contents of this data, you’ll find the records that were inserted.

SAP HANA Tutorial and Material, SAP HANA Guides, SAP HANA Study Materials, SAP HANA Online Exam

I have inserted 3 records earlier, which can be seen in the database above. We have successfully, bound HANA DB to our application in SAP Cloud Platform (CF).

This completes the 3 part blog series where we saw how to create a Spring Boot Application and bind it t HANA database. In case of any doubts or queries, do leave out your message.

Find the remaining parts here –


No comments:

Post a Comment