Skip to Content
Technical Articles

Combine CAP (M) with Machine Learning SDK – Deployment Part

I’ve faced a lot of issues when I was trying to deploy the FaceRecognition app to Cloud Foundry for the first time: https://blogs.sap.com/2019/05/28/face-recognition-app/ Therefore, I’ve added a part “Deployment” to the blog series about Combining CAP with Maching Learning.

Compared to a few months ago, it already became easier. Especially because you can now test the UI directly on CF from in the SAP Web IDE.

Still, some parts are important to be checked before deploying. First of all, add the path to the “./xs-security.json” in the uaa definition.

Without this, you’ll get the following error after deployment:

We also need to make sure that the uaa service is added to the approuter and that we’re not using the “ALLOW_MOCK_AUTH_HEADER” anymore:

Next, we need to change the authentication type for the service route in the xs-app.json of the ui module: (The route of the html5 repo should already be fine)

We also need to configure the security of our service. Therefore, we’re going to add the uaa service to the java service with the following properties:

Normally added by web ide, but always check to be sure. It could happen that it won’t be added in case you used another wizard or did everything manually.

  • Add a destination to the Java service in the html5 repo
  • Add each ui module to the build-parameters of the deployer -> otherwise the ui module won’t be deployed

We also need to setup security. This is needed for:

  • users need have a login screen when accessing the UI
  • users should not be able to go directly to the OData service without login

For this, I followed all the steps in the following blog:

https://blogs.sap.com/2018/10/10/securing-cloud-platform-business-application/

A few things I struggled with, the file that we needed to download was not exaclty the same. Probably this has changed over time. This is the version of the package I used:

For creating the zip with only the needed libraries, I have used the following commands running them from the place where I unzipped the downloaded file:

mvn deploy:deploy-file -Durl=file:///repo -Dfile=xs2_security/security-commons-0.33.18.jar -DgroupId=com.sap.xs2.security -DartifactId=security-commons -Dpackaging=jar -Dversion=0.33.18

mvn deploy:deploy-file -Durl=file:///repo -Dfile=xs2_security/java-container-security-0.33.18.jar -DgroupId=com.sap.xs2.security -DartifactId=java-container-security -Dversion=0.33.18

mvn deploy:deploy-file -Durl=file:///repo -Dfile=xs2_security/java-container-security-api-0.33.18.jar -DgroupId=com.sap.xs2.security -DartifactId=java-container-security-api -Dversion=0.33.18

mvn deploy:deploy-file -Durl=file:///repo -Dfile=xs2_security/native/sapjwt.linuxx86_64-1.1.20.jar -DgroupId=com.sap.security.nw.sso.linuxx86_64.opt -DartifactId=sapjwt.linuxx86_64 -Dpackaging=jar -Dversion=1.1.20

This created a folder with everything I needed which I could zip:

And upload to SAP Web IDE:

Now, you’re ready to build the app which will generate an mtar file:

Finally, we can deploy the mtar to SCP!

If you need to deploy several times, it can help to export the mtar and use cf command line to deploy. In the CF command line, you have the option to delete already running services and deploy a completely new version of your app:

cf deploy MyCAPMWithMLApp_0.0.1.mtar --delete-services

When the deployment is finished, you’ll find all the modules under applications in your space:

It will automatically create and bind instances of services that your app is using:

Run the app by going to the “approuter” and click on the link:

Add the namespace + name of the ui module with the version to the url to go to the UI:

You can now start using the app:

You can also check the OData service (only possible after login otherwise it will ask you to login):

Full project is on GitHub: https://github.com/lemaiwo/MyCAPMAppWithML

Be the first to leave a comment
You must be Logged on to comment or reply to a post.