Usage Scenario
You will deploy your CAP application into the Cloud Foundry environment of the SAP Business Technology Platform manually using:
- The Cloud Foundry Command Line Interface (CLI).
- A Multi-target application (MTA) file. You will also replace the in-memory SQLite database with an SAP HANA Cloud instance to store the application data.
Exercise Options
You can perform this exercise in two ways:
- Live Environment – using the instructions provided below, you can perform the tasks in the SAP BTP Free Tier account.
- Platform Simulation – follow the step-by-step instructions within the simulation.
Live Environment
In this exercise, you will perform the following steps:
- Set Up SAP HANA Cloud Instance.
- Prepare the Project for Production.
- Inspect Deployed Apps in SAP BTP Cockpit.
Prerequisite
Before starting this exercise, make sure you have added an external service.
Result
You have now successfully deployed your multi-target application to Cloud Foundry on SAP BTP.
Task 1: Set Up SAP HANA Cloud Instance
Steps
Set Up SAP HANA Cloud Instance.
First, you need to set up the SAP HANA Cloud instance in your BTP account.
Note
Note that screens in the cloud may change. So, the screenshots in this solution may differ slightly from the screens in your training system.Enter the subaccount that you are using for this course.
Enter the space that you are using for this course (for example, the
dev
space).In the navigation on the left, choose SAP HANA Cloud.
Select Create and choose SAP HANA database.
You will be redirected into SAP HANA Cloud Central for the instance creation. When being asked to authenticate, use your SAP Account user credentials that you used to create your SAP BTP account. You should then see the following dialog. Select
SAP HANA Cloud
and click on Next Step.The Location settings should point to your Cloud Foundry org and space.
Use the following settings for the remaining fields:
Key Value Instance Name hana-cloud Description HANA Cloud used for exercises Administrator Password create a password according to the password policy Click on the Next Step button.
The default parameters for your SAP HANA Cloud database display. Select the Next Step button.
You have to select an availability zone for the SAP HANA Cloud Database. Confirm the default settings by clicking on Next Step.
You will see the SAP HANA Database Advanced Settings dialog. Here, you can allow or deny certain IP addresses for connection to your database instance.
You also find a setting to connect the database to remote sources via the Cloud Connector. This is especially useful in replication use cases, where you need to replicate data from on-premise sources to your SAP HANA Cloud instance. In our use case, this setting is not required.
Select the Allow all IP addresses option, then select the Review and Create button.
The Review page displays. Review the values and choose theCreate Instance button.
The overview of your database instances appears. There should be a new entry for your hana-cloud instance with Status
CREATING
.The process will take several minutes to complete. Once done, the Status should switch to
RUNNING
. Use the Refresh button to update the status. Your SAP HANA Cloud instance is now ready to be used.Return to your BTP subaccount and to your cloud foundry space and select SAP HANA Cloud.
Your hana-cloud instance displays in the SAP HANA Database Instances overview.
Task 2: Prepare the Project for Production
Steps
Prepare the Project for Production.
Configure SAP HANA Cloud in the project.
While we used SQLite as a low-cost stand-in during development, we’re going to use a managed SAP HANA database for production:
Use the displayed code.
Enable XSUAA-based Authentication.
This will also generate axs-security.json
file, which has to be configured. This file stores the configuration for the xsuaa-service on SAP BTP.Generate the
xs-security.json
file content.Create the MTA descriptor file for MTA-Based deployment.
This will generate the mta.yaml file, which contains all the services for the multi target application (MTA) deployment.
Open the mta.yaml file and specify the custom domain in the redirect-uris parameter for the xsuaa resource:
Code snippetCopy codeoauth2-configuration: # <-- add this redirect-uris: # example: - https://risk-management-approuter.cfapps.eu10-004.hana.ondemand.com/login/callback - https:///login/callback
It should be added to the config of the resource definition. At the end it schould look like:
Code snippetCopy coderesources: - name: risk-management-auth type: org.cloudfoundry.managed-service parameters: service: xsuaa service-plan: application path: ./xs-security.json config: # [...] oauth2-configuration: # <-- add this redirect-uris: # example: - https://risk-management-approuter.cfapps.eu10-004.hana.ondemand.com/login/callback - https:///login/callback
Add the managed approuter as gateway to the project.
This will set up the app router, which acts as a single point-of-entry gateway to route requests to our app. In particular, it ensures user login and authentication in combination with XSUAA. This command will also add the approuter module to the
mta.yaml
file.Configure the approuter by opening the
xs-app.json
file in theapp/
directory of your project.Code snippetCopy code{ "welcomeFile": "/app/risks/webapp/index.html", "routes": [ { "source": "^/app/(.*)$", "localDir": "./", "target": "$1" }, { "source": "^/service/(.*)$", "destination": "srv-api" } ] }
This will set up the routing to the SAP Fiori Elements file and to the backend service.
Note
The previous steps are required only once in a project’s lifetime. With that done, you can repeatedly deploy the application.Freeze Dependencies
Deployed applications should freeze all their dependencies, including transient ones.
Note
Note: You should regularly update your:package-lock.json
to consume latest versions and bug fixes. Do so by running this command again, for example, each time you deploy a new version of your application.Build MTA-project.
The following command will build the project based on the
mta.yaml
file. The output will be stored in thegen/
folder.Deploy the generated MTA-project.
Odds are, that you have to log in to your Cloud Foundry org and space first. For this run
This process can take some minutes and finally creates a log output like this:cf login
first and provide the necessary information.Code snippetCopy code[...] Application "risk-management" started and available at "[org]-[space]-risk-management.landscape-domain.com" [...]
Task 3: Inspect Deployed Apps in SAP BTP Cockpit
Steps
Inspect Deployed Apps in SAP BTP Cockpit.
In this step you will inspect the deployed risk-management application. Compared to the deployment procedure you performed in the previous steps, this will save you a lot of manual work in the long run.
Visit the "Applications" section in your SAP BTP cockpit to see the deployed apps.
Click on the
risk-management
application and then on the application route.You will notice that the external data can't be retrieved, since the API key was not set yet. For this, go back one step and select the
risk-management-srv
application. Click onUser Provided Variables
in the navigation bar on the left side and set the API key.Now, click on
Overview
on the left side and then restart the application to ensure that this variable change take effect.Now review the app again, by opening up the
risk-management
application.
Platform Simulation
Click on the Start button below to open a simulation of the platform. Then follow the step-by-step instructions to deploy a CAP Application.
ExerciseStart Exercise