Enabling Multitenancy for the Previously Created Application

Objective

After completing this lesson, you will be able to enable multitenancy for the previously created application

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

In this exercise, you will enable multitenancy in your application.

Prerequisites

Create a new branch for each exercise in unit 3. If you haven't already created a new branch for the next exercise, follow the instructions provided in step 2 of task 1 of the exercise Adding a Mobile UI Application to Your Project.

If you have already deployed your application, undeploy the application manually before enabling multitenancy.

Users can use the following command line to undeploy the multitarget (MTA) application: RiskManagement).

To do so, open a new terminal and copy & paste the following command line:

cf undeploy RiskManagement --delete-services --delete-service-keys -f

System screenshot

Steps

  1. Enable multitenancy in your application. Users can do this from two locations: Project Overview or Guide Center.

    1. From the Project Overview, select Project Actions (…) to open the context menu.

    2. Choose Enable Multitenancy.

      System screenshot
    3. From the Guide Center, choose Enable Multitenancy in your Application, under Enable Multitenancy, choose Enable Multitenancy.

      System screenshot
    4. Substeps a, b, and c will lead to this page.

    5. Choose Enable Multitenancy.

      System screenshot
    6. Choose Enable.

      System screenshot
    7. SAP Business Application Studio will show a message like below in the bottom right:

      System screenshot
  2. 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.

    1. Open a terminal in SAP Business Application Studio.

      System screenshot
    2. Run the given command in the mtx/sidecar folder:

      npm install @sap/xsenv
    3. 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: System screenshot

    4. Add the following code to server.js:

      Code Snippet
      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 }) }) })
    5. The server.js will look as shown here:

      System screenshot
    6. 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.

      System screenshot
  3. 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.

  4. Subscribe to your multitenant application.

    1. Navigate to your SAP BTP subaccount and from the navigation pane, choose Instances and Subscriptions.

    2. In the Search bar, search for the destination instance of your multitenant application (<project name>-destination) and choose it to open the details pane.

      System screenshot
    3. Choose Manage Instance.

      System screenshot
    4. From the navigation pane, choose Destinations.

    5. 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.

      System screenshot

      Note

      A technical user refers to a user with relevant permissions for the provider Cloud Foundry account.
    6. Clear the Client Secret field.

    7. Choose Save.

  5. Subscribe to the multitenant application.

    1. Go to Service Marketplace.

    2. Find out the deployed multitenant application.

    3. Choose Create.

      System screenshot
    4. Leave the value as default in the next step.

    5. Choose Create.

      System screenshot
  6. Open the application.

    1. Navigate to your SAP BTP subaccount and from the navigation pane, choose Instances and Subscriptions.

    2. In the Search bar, search for the application and choose it to open the details pane.

    3. Choose Go to Application.

      System screenshot
    4. Result:

      System screenshot
  7. Test the application.

    1. Choose the Risk tile in the application home page.

    2. Choose the Go button, and check the current data.

    3. Choose Create to go to the create page.

      System screenshot
    4. Enter data in the create page.

    5. Choose the Action button in supplier_BusinessPartner to add a business partner from the external service.

    6. Select a value from the popup.

    7. Choose Create in the create page.

      System screenshot
    8. Result:

      System screenshot
    9. The new data has been created.

      System screenshot
    10. Go back to the Risks home page.

      System screenshot
    11. Check the data.

      System screenshot

Log in to track your progress & complete quizzes