Skip to content

Latest commit

 

History

History

mass-stop-start-cf-apps

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Mass Stop/Start Cloud Foundry Apps

Table of Contents

Description

If your BTP global account uses the consumption-based commercial model (such as CPEA or Pay-As-You-Go), Cloud Foundry applications are billed based on their usage. Therefore, you can reduce the monthly cost by stopping applications which are used only for testing and development purposes. With the help of SAP Automation Pilot, such resources can be automatically stopped outside of working hours and started again the next day. To find out more about the Cloud Foundry's billng costs, please feel free to consult SAP BTP, Cloud Foundry Runtime.

SAP Automation Pilot has the capabilities to perform mass operations on tens or even hundreds of Cloud Foundry applications, including stop, start or restart. In addition to this, these operations can be performed regularly with the Scheduled Executions functionality.

This example includes a total of four commands. MassStopCfAppsInSpace and MassStartCfAppsInSpace dynamically find and stop/start all applications in the given space. Similarly, MassStopCfAppsInOrg and MassStartCfAppsInOrg do the same thing but on organization level - the applications across all spaces are collected and then started/stopped. In addition, it's possible to ignore certain spaces and do not perform any operations on them.

Mass Stop Apps in Org Mass Start Apps in Org

After a successful execution, each command outputs a short summary which is useful for transparency and traceability:

Mass Stop Summary

⚠️ The commands within this example might cause downtime for a large amount of applications. Please make sure that you are not using them on productive systems.

Requirements

To use this example you'll need the following:

  • Multiple Cloud Foundry spaces with at least one application in each
  • Technical user with Space Developer role in each space

⚠️ If you are planning to use SAP Universal ID, please keep SAP Note 3085908 in mind

Check out the documentation for more information.

How to use

Import the content of examples catalog in your Automation Pilot tenant. The examples includes four commands - MassStopCfAppsInSpace, MassStartCfAppsInSpace, MassStopCfAppsInOrg and MassStartCfAppsInOrg. Navigate to any of them and to trigger them.

You'll need to provide values for the following input keys:

  • region - Technical name of your SAP BTP region, e.g. cf-eu10, cf-us20
  • subAccount - Name of your Cloud Foundry organization
  • resourceGroup - Name of your Cloud Foundry space
  • user - Email or ID of your technical user
  • password - Password of your technical user
  • identityProvider - Optional: origin key of your identity provider. Defaults to sap.ids
  • excludedSpaces - Technical names of the Cloud Foundry spaces in which the applications should not be started/stopped. Example value: ["prod-1", "prod-2"]
  • excludedLabels - If an application has any of the specified labels, it will not be started/stopped. Example value: { "env": "production" }"

ℹ️ Most of the needed information is available in your subaccount's Overview page under Cloud Foundry Environment.

As mentioned before, Automation Pilot allows executions to be automatically triggered on regular intervals - hourly, daily, weekly, monthly or yearly. We can create two Scheduled Executions - one to stop all applications after working hours and another to start them up again on the next morning.

ℹ️ Scheduled Executions use the UTC time zone.

Here are the some example schedule configurations:

  • MassStopCfAppsInOrg - executed every weekday at 16:30 UTC

    • Schedule - Weekly on Monday, Tuesday, Wednesday, Thursday and Friday
    • Hours - 16
    • Minutes - 30
  • MassStartCfAppsInOrg - every weekday at 06:30 UTC

    • Schedule - Weekly on Monday, Tuesday, Wednesday, Thursday and Friday
    • Hours - 6
    • Minutes - 30

How to Label Cloud Foundry Apps

Using CF CLI

To add a label to an application using the CF CLI, use the following command:

cf set-label app my-app environment=production

Using Manifest YAML

To add labels to an application using a manifest YAML file, include the labels section under metadata.

Example manifest.yml:

applications:
  - name: my-app
    memory: 512M
    instances: 1
    path: .
    metadata:
      labels:
        environment: production
        owner: team-a