Building multi-target applications (MTA) for Cloud Foundry using your favorite IDE
One of the primary features of using the SAP WebIDE for Cloud Foundry (CF) application development is the ability to create a multi-target application (MTA) easily. An MTA is an SAP construct that allows you to combine modules into a single deployable unit for lifecycle maintenance. These modules could potentially use different runtimes (one on Node.js, one on Python, etc.). For more information on MTAs for the Cloud Foundry environment, please click here.
The Web-based SAP WebIDE, however, may not be the ideal developer environment for everyone. It does not work when you’re offline and it also does not have support for development in languages such as Python, PHP, etc. Many developers prefer using their own IDE while still taking advantage of enterprise SAP features such as MTA, app router, and XSUAA. In this blog, I will show how you can use your own IDE and still build multi-target applications. It just requires a one-time setup of a few tools that are developed and fully supported by SAP Cloud Platform.
Step 1: Install the CF command line interface
You can download and install the cloud foundry command line interface (CF CLI) from the following location. There are a number of options for download on a variety of platforms and install programs.
https://github.com/cloudfoundry/cli#downloads
After a successful installation, you should be able to execute the cf command:
$ cf -v
cf version 6.33.1+c77e55743.2017-12-15
Step 2: Install the MTA Plugin for the CF CLI from SAP
SAP has developed and published an MTA plugin for Cloud Foundry CLI. This MTA plugin allows you to perform lifecycle operations like deployment and un-deployment on multi-target applications. The MTA plugin can be downloaded from SAP cloud platform tools page (search for MTA Plugin and pick your platform):
https://tools.hana.ondemand.com/#cloud
Install the MtaPlugin by running the install-plugin sub-command:
$ cf install-plugin cf-cli-mta-plugin-1.0.2-darwin-x86_64.bin
Attention: Plugins are binaries written by potentially untrusted authors.
Install and use plugins at your own risk.
Do you want to install the plugin cf-cli-mta-plugin-1.0.2-darwin-x86_64.bin? [yN]: y
Installing plugin MtaPlugin...
OK
Plugin MtaPlugin 1.0.2 successfully installed.
Step 3: Install the MTA Archive Builder
The MTA archive builder is a standalone command-line tool that builds a deployment-ready .mtar file from an MTA project using the development descriptor (mta.yaml) file. For details on the MTA archive builder and to download the jar file, please visit the following URL. Note: You will need Java 8 on your machine in order to execute this tool.
Save the download JAR file (e.g., MTABUILDER110_0-80002501.JAR) in a well-known location and add it to your Java classpath.
You now have all the software you need to build and deploy an MTA!
Step 4: Build and Deploy a sample MTA
If you are looking for a skeleton sample MTA project, then feel free to download one from my GitHub repository location below:
https://github.com/sunilwadhwa/mymta1.git
Mymta1 is a simple skeleton MTA project with three distinct modules – a Node.js module called approuter, a Python module called pymodule1, and a Java module called jmodule1. It also contains an xsuaa service used by the approuter for authentication. It is ready to be deployed to a CF space.
To build the MTAR file, cd to the root folder of the project and execute the MTA Archive Builder:
$ java -jar MTABUILDER110_0-80002501.JAR --build-target CF --mtar ./target/mymta1.mtar build
SAP Multitarget Application Archive Builder 1.1.2
Module "jmodule1": invoking maven
Module "pymodule1": zipping directory pymodule1
Module "approuter": invoking npm
Module "approuter": command output
...
> up to date in 0.662s
Module "approuter": zipping directory approuter
Module "jmodule1": command output
> [INFO] Scanning for projects...
...
...
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 0.893 s
> [INFO] Finished at: 2018-02-02T16:33:04-07:00
> [INFO] Final Memory: 15M/309M
> [INFO] ------------------------------------------------------------------------
Generating archive ./target/mymta1.mtar
Done
To deploy the generated MTAR file, run the cf deploy command:
$ cf api
api endpoint: https://api.cf.us10.hana.ondemand.com
api version: 2.99.0
$ cf deploy target/mymta1.mtar
{{output edited for clarity}}
Deploying multi-target app archive target/mymta1.mtar in org org / space dev as sunil.wadhwa01@sap.com...
Uploading 1 files...
target/mymta1.mtar
OK
Starting deployment process...
Service "mymta1-uaa" updated
Application "approuter" started and available at "..."
Application "jmodule1" started and available at "..."
Application "pymodule1" started and available at "..."
Process finished.
Step 5: Configure your IDE (Eclipse example shown below)
In this final step, I will show you how to configure an IDE like Eclipse, to build and deploy a multi-target application. You can create a new Project Builder in the Project Properties section and specify the java command that we used in the previous step.
Here is a screenshot of the MTA-Builder that I created as an example. Now, when I click on Project –> Build Project menu, the MTA is automatically built for me. In a similar way, you can create an External Tool configuration to run the deployment of the MTAR to cloud foundry.
Have fun and please comment below if you have any questions/feedback!
really usefull stuff! Thanks for sharing.
Great blog ... thanks that really helped me into getting my local HANA Express project getting deployed into CF.
I did encounter quite some issues though - like not having a node build runtime ( missing python, etc ) and getting C++ compile errors on a standard module 'fibers' ... in the end it turned out that I needed to downgrade node.js towards v6 and all problems were gone ( apparently fibers is not supporting node js +v8 - as my node version was to high it started recompiling those modules and hence all issues ).
Thanks for the valuable feedback! Currently, the MTA sample project requires you to have many different runtimes and build programs (Node, python, and Java). I am working on providing more options, so that you can pick and choose which components you want. Follow and watch this space for more details. Thanks.
Many Thanks, Helps me a lot to setup my first MTA application on CF
Thanks, helped me a lot to switch from SAP Web IDE to my beloved local development environment. Although I like SAP Web IDE it's sometimes more productive to use local tools.
Able to deploy first MTA application to cloud foundry. Thank you for the great blog
Hi Sunil,
Thank you for the nice blog. The import from Git is successful. However, eclipse does not recognized jmodule1 as a maven project. This is crucial for testing the service. Can you please explain how to import this properly?
Hi Tejas - Thanks for your feedback! This usually happens when you don't have maven installed on the command line and in your path. Can you please open up a command prompt and type the command "mvn --version"? If you don't get any output or command not found, then you will need to make sure the command is installed and in your PATH variable. Send me a PM if you have any additional problems. Thanks.
Also, since you are using Eclipse, you must make sure that the path where mvn command is located must be specified in the PATH variable in the Environment section of the tool configuration. Hope this helps! Let us know how it goes.
Thanks so much Sunil, this worked first time (!) and gave me a vital workaround for a Web IDE issue. Now I can get back to work
What can be done to investigate the "Command execution failed" ?
Robin - Check if you have node command line installed. Type the command "node --version" and you should expect to get a valid response. This is required in order to build approuter and other Node.js modules. Thanks.
After installed Node.ja, the error is :
silly fetchPackageMetaData error for @sap/approuter@2.7.1 request to https://registry.npmjs.org/@sap%2fapprouter failed, reason: connect ETIMEDOUT 172.20.5.58:8080
Robin - Also, you need to tell Node Package Manager (NPM) where to find the SAP modules. In order to do that, please run the following command line:
npm config set @sap:registry https://npm.sap.com
Hi @Sunil Wadhwa,
Very-useful blog.
I changed mta.yaml & tried below commands
C:\Users\xxxidxx\git\CAPWS\mymta1>java -jar "C:\mta_archive_builder.jar" --build-target CF --mtar ./target/mymta1.mtar build
then
cf push target\mymta1.mtar
I am getting below error
Pushing app target\mymta1.mtar to org SAP IT Cloud_sapitcfd / space vms-backend-cf as I311690...
Getting app info...
Updating app with these attributes...
name: target\mymta1.mtar
path: C:\Users\xxxidxx\git\CAPWS\mymta1
disk quota: 1G
None of the buildpacks detected a compatible application
Exit status 222
Error staging application: An app was not successfully detected by any available buildpack
TIP: Use 'cf buildpacks' to see a list of supported buildpacks.
please find attached buildpacks information
Note :
I have changed mta.yaml file CF urls
ID: mymta1
_schema-version: '2.0'
version: 1.0.0
modules:
- name: approuter
type: nodejs
path: approuter
parameters:
disk-quota: 256M
memory: 256M
properties:
TENANT_HOST_PATTERN: "^(.*)api.cf.sap.hana.ondemand.com"
destinations: >
[
{"name":"jmodule1", "url":"https://api.cf.sap.hana.ondemand.com", "forwardAuthToken": true },
{"name":"pymodule1", "url":"https://api.cf.sap.hana.ondemand.com", "forwardAuthToken": true }
]
requires:
- name: mymta1-uaa
- name: jmodule1
type: java
path: jmodule1
parameters:
disk-quota: 256M
memory: 512M
build-parameters:
builder: maven
requires:
- name: mymta1-uaa
- name: pymodule1
type: python
path: pymodule1
parameters:
disk-quota: 256M
memory: 128M
command: python hello.py
requires:
- name: mymta1-uaa
resources:
- name: mymta1-uaa
type: com.sap.xs.uaa
parameters:
service: xsuaa
service-plan: application
path: config/xs-security.json
Regards,
Showkath.
Hi Sunil,
Very useful, i was looking for an option where i can change the existing module name itself while deploying. once its possible, we can use same mtar in different cf spaces.
do we have such capabilites while deploying mta file.?
Regards,
MBR