Multitenancy for Applications
SAP Business Application Studio’s Productivity Toolkit provides a multitenant architecture that enables the service provider (host) to serve multiple tenants through single clusters of microservice instances. This ensures strict isolation of the tenants' data and access to it. In a multitenant architecture, tenants are clients using the solution application.
Applications in multitenant mode wait for tenants to subscribe, enabling the service provider to manage resources more efficiently. Additionally, the service provider can easily update and maintain the application for all tenants, reducing the time and costs associated with managing multiple instances. Enabling multitenancy provides significant benefits for both the service provider and the tenants, including reduced costs, increased scalability, and improved security.
Enable Multitenancy in Your Application
Business Scenario
Prerequisites
Steps
Enable multitenancy in your application. Users can do this from two locations: Project Overview or Guide Center.
From the Project Overview, select Project Actions (…) to open the context menu.
Choose Enable Multitenancy.
From the Guide Center, choose Enable Multitenancy in your Application, under Enable Multitenancy, choose Enable Multitenancy.
Substeps a, b, and c will lead to this page.
Choose Enable Multitenancy.
Choose Enable.
SAP Business Application Studio will show a message like below in the bottom right:
Enable External Services in a Multitenant Application. By default, multitenant applications don't expose a destination or other services to subscribers. However, you can follow the steps provided below to add the destination services to the SAP BTP SaaS Provisioning Service dependencies to allow subscribers to use them.
Open a terminal in SAP Business Application Studio.
Run the given command in the mtx/sidecar folder:
npm install @sap/xsenv
Open the Explorer and navigate to the mtx/sidecar folder. Open the server.js file.
If the Explorer isn't visible, you can open it using the steps shown in the following snapshot:
Add the following code to server.js:
12345678910111213141516171819
const xsenv = require('@sap/xsenv');
cds.on('served', async () => {
const { 'cds.xt.SaasProvisioningService':provisioning } = cds.services
await provisioning.prepend(() => {
provisioning.on('dependencies', async (req, next) => {
await next()
const services = xsenv.getServices({
dest: { label: 'destination' }
})
let dependencies = [
{
xsappname: services.dest.xsappname
}
]
return dependencies
})
})
})
The server.js will look as shown here:
Users can also find the steps described above in the Guide Center of SAP Business Application Studio under the section Enable Multitenancy in your Application.
Deploy to Cloud Foundry.
This step is described in the Unit Developing a Risk Management Application to Extend SAP S/4HANA. You can do this step in the same way as before.
If you have deployed this before in the same SAP Business Application Studio account and if you are already logged in to Cloud Foundry you can also open the Project Overview then choose the action button at the right of the project name. Then choose Deploy Project. The deployment starts and the progress can be tracked in the Terminal.
Subscribe to your multitenant application.
Navigate to your SAP BTP subaccount and from the navigation pane, choose Instances and Subscriptions.
In the Search bar, search for the destination instance of your multitenant application (<project name>-destination) and choose it to open the details pane.
Choose Manage Instance.
From the navigation pane, choose Destinations.
You can see the destination configured for your multitenant application. Choose Edit. In the User and Password fields, fill in the username and password for a technical user.
Note
A technical user refers to a user with relevant permissions for the provider Cloud Foundry account.
Clear the Client Secret field.
Choose Save.
Subscribe to the multitenant application.
Go to Service Marketplace.
Find out the deployed multitenant application.
Choose Create.
Leave the value as default in the next step.
Choose Create.
Open the application.
Navigate to your SAP BTP subaccount and from the navigation pane, choose Instances and Subscriptions.
In the Search bar, search for the application and choose it to open the details pane.
Choose Go to Application.
Result:
Test the application.
Choose the Risk tile in the application home page.
Choose the Go button, and check the current data.
Choose Create to go to the create page.
Enter data in the create page.
Choose the Action button in supplier_BusinessPartner to add a business partner from the external service.
Select a value from the popup.
Choose Create in the create page.
Result:
The new data has been created.
Go back to the Risks home page.
Check the data.