Designing and Running your Application in SAP BTP, Cloud Foundry Runtime

Objective

After completing this lesson, you will be able to develop applications in the SAP BTP, Cloud Foundry runtime.

Application Development in the SAP BTP, Cloud Foundry Runtime

Introduction

Your company has decided to modernize its application development process by transitioning to cloud-native solutions. As part of this initiative, you've been tasked with understanding the development ecosystem within the SAP Business Technology Platform (BTP), specifically focusing on the Cloud Foundry runtime. This knowledge will empower you to make informed decisions about application architecture and development methodologies in a cloud-native environment.

Overview

The SAP BTP, Cloud Foundry runtime offers a robust platform-as-a-service (PaaS) solution tailored for cloud-native application development and orchestration. Leveraging open standards, developers can build, deploy, and scale applications efficiently in a polyglot environment.

Development Options Overview

The Cloud Foundry runtime provides developers with flexibility in choosing their development path. Whether leveraging SAP's recommended approach based on the SAP Cloud Application Programming Model (CAP) or opting for custom solutions, developers can select from a range of programming languages and development tools.

Choose Your Own Path

In the polyglot nature of the Cloud Foundry runtime, developers are not limited to specific programming languages or tools. They have the flexibility to choose their preferred development and deployment tools. The three languages supported by SAP are Java, Node.js, and Python. However, there are buildpacks available for many other programming languages, including Golang, ASP.NET, PHP, and more. Choose appropriate buildpacks based on the requirements of your application.

Find more information on the three languages supported by SAP using the following links:

Note

Java, Node.js, and Python have enterprise support from SAP. Please consider that issues with unsupported buildpacks must be resolved on your own. You also have to make sure that both the provider and the buildpack are trustworthy.

The Recommended Path

SAP recommends following a structured development approach based on the SAP Cloud Application Programming Model (CAP). By utilizing Java and Node.js, developers can benefit from extensive tooling support and best practices tailored for cloud-native application development. However, the order of development steps is flexible, allowing adaptation to specific use cases.

Developing Multitenant Applications in the Cloud Foundry Runtime

In the Cloud Foundry runtime of SAP BTP, you can develop and run multitenant applications accessed by multiple consumers through a dedicated URL.

What Is the Recommended Multitenancy Model?

Multitenancy allows application providers to own, deploy, and operate tenant-aware applications for multiple consumers, reducing costs by sharing resources and updating applications in a single step. In Cloud Foundry, the favored multitenancy concept leverages that each consumer accesses the application via a dedicated URL, ensuring data separation and security. You can find detailed information on Multitenancy, Roles and how it works in the SAP documentation here.

Development Guidelines

When developing tenant-aware applications, follow these guidelines:

  • Avoid shared in-memory data (for example, Java static fields).
  • Prevent users from executing custom code or accessing the file system.
  • Implement Subscription callbacks for tenant onboarding with SAP SaaS Provisioning service (saas-registry).

Procedure

You can find detailed implementation procedures in the SAP documentation here.

Related Information

Multitarget Applications in the Cloud Foundry Runtime

A multitarget application (MTA) is essentially a single application that consists of multiple parts. These parts are created using various technologies and share the same lifecycle.

The MTA developers outline the intended outcomes using the MTA model. This model consists of MTA modules, MTA resources, and the interdependencies between them. Afterward, the SAP Cloud Deployment service validates it, orchestrates the necessary actions, and automates the MTA deployment. The outcome is the formation of Cloud Foundry applications, services, and the generation of SAP-specific content. SAP BTP Cloud Foundry runtime is specifically designed to support the deployment of such applications. For more information about the Multitarget Application model, see the official specification documents: The Multitarget Application Model v.2 and The Multitarget Application Model v.3.

Note

Note that MTA is not related to Cloud Foundry. It's a concept unknown in Cloud Foundry and was created separately by SAP. That's the reason why customers do not find the "cf deploy" command in the CF CLI. To use "cf deploy", you have to install a respective CF CLI plugin.

Key Concepts and Terminology

  • MTA Descriptor (mta.yaml)

    A YAML file that lists all components of the MTA, such as modules, resources, properties, and their interdependencies. This file is central to defining how the MTA is structured and deployed. An example of an MTA descriptor is provided here

  • Module

    Each self-contained part of an MTA, like a Java or HTML5 module, representing different tiers or components of the application.

  • Resource

    External services or properties required by a module at runtime, which are not part of the module itself.

  • Property

    Key-value pairs used during deployment or runtime to configure modules or resources.

  • Dependency

    Links between modules and resources, crucial for resolving runtime and deployment dependencies.

Different Approaches to Create a Multitarget Application

You can create and deploy a multitarget application in the Cloud Foundry runtime by selecting from several outlined approaches below, each capable of achieving the same result:

  • Using SAP Web IDE Full-Stack as described in Developing Multitarget Applications – both the development descriptor mta.yaml and the deployment descriptor mtad.yaml are created automatically. The mta.yaml is generated when you create the application project, and the mtad.yaml file is created when you build the project.

    Note

    It might be required to edit the development descriptor.

    Development descriptors are used to generate MTA deployment descriptors, which define the required deployment data. That is, the MTA development descriptor data specifies what you want to build and how to build it, while the deployment descriptor data specifies as what and how to deploy it.

  • Using SAP Business Application Studio – the flow is similar to WebIDE but the development is done from SAP Business Application Studio, as described here.

  • Using the Cloud MTA Build Tool. Afterward, you deploy the MTA using the Cloud Foundry Command Line Interface.

    Note

    An MTA development descriptor mta.yaml is required. You have to create it manually.
  • Manually – Create the required files manually, and deploy them using the Cloud Foundry Command Line Interface.

    Note

    An MTA development descriptor mta.yaml is not explicitly required. In this case, a deployment descriptor is maintained instead.

    1. Create the required files using an IDE of your choice.
    2. To produce your custom artifacts, use a build technology of your choice.
    3. Maintain your deployment descriptor document (mtad.yaml).
      1. (Optional) If you want to have an MTA archive package, use the mbt assemble. Otherwise, deploy the mtad.yaml directly by pushing your files individually.
      2. Otherwise, deploy the mtad.yaml directly by pushing your files individually.

Best Practices for Developing Modern Apps for SAP BTP, Cloud Foundry Runtime

Avoid Writing to the Local File System

Cloud Foundry only supports cloud native applications. Best principles for building cloud native applications are outlined in the 12 Factor App methodology. Developers are encouraged to consult these principles for guidance on developing robust and scalable applications in the Cloud Foundry runtime.

Apps running on Cloud Foundry must avoid writing files to the local file system due to its short-lived and nonpersistent nature and lack of file sharing among instances. Instead, utilize cloud storage services such as SAP HANA Cloud, or other relational databases, or hyperscaler solutions for persistent data storage.

Note

Consider that all major browsers are moving away from using cookies, and, as a result, have limited their functionality in recent years. Therefore, it may be a risk to use cookies here.

Cookies Accessible Across Apps

In environments with shared domains, cookies may be accessible across apps. Developers must decide whether to set cookies at the highest available domain to ensure consistent behavior across applications.

Port Considerations

Clients connect to Cloud Foundry apps via URLs associated with the app. HTTP requests are allowed on ports 80 and 443, with support for WebSocket connections.

High Availability

To avoid temporary unavailability, you have to run multiple instances of the app. Cloud Foundry uses a process called evacuation to relocate app instances, which frequently happens and is a common internal system operation.

It recreates instances on another virtual machine (VM) and then shuts down the old ones. Singleton app instances might be temporarily unavailable if the new instance doesn't become healthy within the evacuation timeout (default is 12 minutes). Additionally, for a short period, your singleton may have two instances, which can lead to issues if not properly managed.

To minimize downtime, running multiple instances of your app is essential. Select here to find more information about: High availability at platform and application level and The application container life cycle on the Diego architecture.

Ignore Unnecessary Files When Pushing

By default, all files in an app's project directory are uploaded to Cloud Foundry during deployment. Exclude unnecessary files using a .cfignore file to improve deployment efficiency.

Application Timeouts: Key Considerations

In SAP BTP, Cloud Foundry, your app must adhere to strict time limits:

  • Upload: Complete within 15 minutes.
  • Staging: Must finish in 15 minutes.
  • Start: The app must start within 60 minutes (configurable).

Critical Shutdown Timeout

When an app receives a shutdown signal (SIGTERM), it has 60 seconds to close gracefully before being forcibly terminated by SIGKILL. Failure to shut down properly can lead to data corruption or other issues, especially with persistence. It's crucial to ensure that your app can handle this within the 60-second window.

App Autoscaler

Set up the SAP BTP, Cloud Foundry runtime App Autoscaler service, which lets you automatically increase or decrease the number of your application instances based on the policies you have defined. The service will then automatically adjust the number of app instances based on the current load, ensuring more resilient and scalable applications.

Cloud Logging and Application Logging

Utilize SAP BTP's logging capabilities for better observability. Use centralized logging services like Cloud Logging and Application Loggingto monitor and analyze app performance and behavior.

Alert Notification Service

Set up the SAP BTP, Cloud Foundry runtime Alert Notification Service to receive real-time notifications about critical events, improving the ability to respond to issues promptly.

Summary

In this lesson, you've explored key aspects of application development within the SAP BTP, Cloud Foundry runtime. You've learned about flexible development paths, including the use of the Cloud Application Programming Model (CAP) and options among Java, Node.js, and Python, supported by SAP. The lesson also delved into developing multitenant applications and the multitarget application model. Additionally, it discussed migration strategies and best practices for cloud-native development. This knowledge will help you design and develop cloud-native applications effectively.

Log in to track your progress & complete quizzes