Deploy The Material Availability Service to SAP BTP, Cloud Foundry
In this section, you will deploy the Material Availability service from your CAP project to SAP BTP, Cloud Foundry.
This will expose your service, to provide an additional "Vendor Available to Promise (ATP)" capability (so others can also query the material availability status of your company as a vendor).
Pre-requisites:
- You must have an SAP BTP subaccount with the Cloud Foundry environment enabled, and a Cloud Foundry space created in it.
- You must have a user with Space Developer role which is a member of this Cloud Foundry space.
- In case the Cloud Foundry space you would like to use is not under the SAP BTP subaccount which is subscribed to SAP Business Application Studio, make sure to copy the destination to SAP S/4HANA and configure connectivity to the Cloud Connector also from the SAP BTP subaccount hosting your Cloud Foundry space.
Prepare your project for production:
Open Terminal in your project root context and execute
cds add xsuaa --for production
. This will configure your service for XSUAA-based authentication.From the Explorer view, open the package.json file. For each required OData service, clone the
"[live]"
profile including the service credentials, into a new"[production]"
profile. Final result should include:"cds": {
"requires": {
"SalesOrderA2X": {
"kind": "odata-v2",
"model": "srv/external/SalesOrderA2X",
"[sandbox]": {
. . .
},
"[live]": {
. . .
},
"[production]": {
"credentials": {
"destination": "<DESTINATION NAME>",
"path": "/sap/opu/odata/sap/API_PRODUCT_SRV/"
}
}
},
"ProductMasterA2X": {
"kind": "odata-v2",
"model": "srv/external/ProductMasterA2X",
"[sandbox]": {
. . .
},
"[live]": {
. . .
},
"[production]": {
"credentials": {
"destination": "<DESTINATION NAME>",
"path": "/sap/opu/odata/sap/API_PRODUCT_SRV/"
}
}
},
"BasicProductAvailabilityInfo": {
"kind": "odata-v2",
"model": "srv/external/BasicProductAvailabilityInfo",
"[sandbox]": {
. . .
},
"[live]": {
. . .
},
"[production]": {
"credentials": {
"destination": "<DESTINATION NAME>",
"path": "/sap/opu/odata/sap/API_PRODUCT_AVAILY_INFO_BASIC/"
}
}
},Make sure to replace the
<DESTINATION NAME>
placeholder with the SAP BTP destination name as created in the previous section.Make sure the
"name"
property in your package.json file includes only alphanumeric characters, "_" or "-". This to ensure the module names and application's xsappname that will be generated out of this name, will be valid in Cloud Foundry. For example, use the name: "material-availability".From the Terminal, execute
cds add approuter --for production
to enhance the application with App Router that will act as a single point-of-entry gateway to route the service requests to. In particular, it ensures user login and authentication in combination with XSUAA when accessing through browser.Execute
npm update --package-lock-only
to freeze all dependencies, including transient ones. This is best practice for deployed applications.Execute
cds add mta
to generate an mta.yaml descriptor file, configuring all the modules and services required for MTA-based deployment of your CAP project.Right-click the generated mta.yaml file, select Open With... and then select the Text Editor option. After the
resources
section in the file, add the following resources to add the destination and connectivity SAP BTP service instances and make them accessible from the deployed application:resources:
- name: material-availability-destination
type: org.cloudfoundry.managed-service
parameters:
service: destination
service-plan: lite
- name: material-availability-connectivity
type: org.cloudfoundry.managed-service
parameters:
service: connectivity
service-plan: liteThen add these resources as required from the service module (for example: material-availability-srv):
modules:
- name: material-availability-srv
. . .
requires:
- name: material-availability-auth
- name: material-availability-destination
- name: material-availability-connectivityPay attention to indentation when editing the mta.yaml file.
For more information on preparing CAP project for production, see here.
Note: In this section, you will deploy only the service module in order to expose it as a Vendor API. To deploy also the Material Dashboard Fiori application and setup its access to the service endpoint, see the end-to-end tutorial for the necessary configurations in the mta.yaml file and on the Material Dashboard Fiori application.
Deploy to Cloud Foundry:
- Assemble the required modules into one MTA archive file by right clicking the mta.yaml file from the Explorer view, and select Build MTA Project option. The MTA archive files are created under the mta_archives folder in your project.
- Expand the mta_archives folder and right click the appropriate
.mtar
file for deployment. From the context menu, select the Deploy MTA Archive option. - Once prompted, sign-in to Cloud Foundry with your user credentials or by using SSO and select the Cloud Foundry organization and space to which you would like to deploy your application modules.
- Wait for the
Process finished.
output from the Terminal opened to perform the deployment operation. - Go to SAP BTP cockpit and access the Cloud Foundry space to which you deployed the application modules. From the Applications tab click on the App Router application name, for example: material-availability, and click on the link under the Application Routes.
- Login with the same user you logged-in to the SAP BTP Cockpit.
- Test the deployed service by adding the paths as you did in the previous section, in step 8 of testing with the "live" profile from SAP Business Application Studio. Note: the access through the App router application module is required only when accessing through browser, to allow UI-based login. When accessing the service from any other application or service, the entrypoint of the deployed service application (for example, material-availability-srv) should be used directly, with JWT token credentials, initiated by SAP BTP XSUAA service.
Congratulations! You have completed the Advanced scope and have your Material Availability Dashboard application ready, including UI, service logic and access to live SAP S/4HANA system. You also have the service available from Cloud Foundry as a downstream Vendor API.
See the Outlook section for more post-deployment considerations, such as authentication and access by partners to your service and SAP S/4HANA system data.