Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
qmacro
Developer Advocate
Developer Advocate
This is a searchable description of the content of a live stream recording, specifically "Ep.48 – Continuing with the Business Rules service on CF" in the "Hands-on SAP dev with qmacro" series. There are links directly to specific highlights in the video recording. For links to annotations of other episodes, please see the "Catch the replays" section of the series blog post.

This episode was streamed live on Fri 13 Dec 2019 and is approximately 60 minutes in length. The stream recording is available on YouTube.



Brief synopsis: In this episode we continue on from where we left off in Ep.44 and dig further into the Business Rules service on SAP Cloud Platform Cloud Foundry environment.

00:03:55 Talking about a small "tshirt giveaway" that I can do in early 2020 - I have a few tshirts that I haven't worn and that I can give away on some sort of random lottery.

00:04:45 Don't forget to fill in the SAP Developer Insights Survey which runs until sometime in mid Jan 2020.

00:05:50 My friend and colleague iinside had his first live stream on 12 Dec 2019! Well done Max, and we'll see more in 2020, I'm sure!

00:07:20 A short discussion on the possibility of me moving my live streaming from Twitch to YouTube ... and as you may know, I made that decision over the holiday period, and from the next episode I'll be live streaming on my channel on YouTube, which you can get to here:

https://youtube.com/djadams-qmacro

00:08:40 Reminding ourselves of what we're going to do in this episode, which is to continue more or less where we left off in Ep.44, i.e. getting to a position in CF which is the equivalent of where I was in Neo. We also discussed briefly the issue we'd been left with last time, caused by my inconsistent editing of mta.yaml.

00:14:00 Looking at the Business Rules Editor project in the SAP Web IDE, and in particular the contents of that mta.yaml file, including upon which resources the editor module relies. Here's the entire contents of the mta.yaml file:

ID: businessruleseditor
_schema-version: '2.1'
parameters:
deploy_mode: html5-repo
version: 0.0.1

modules:
- name: businessruleseditor_appRouter
type: approuter.nodejs
path: businessruleseditor_appRouter
parameters:
disk-quota: 256M
memory: 256M
requires:
- name: businessruleseditor_html5_repo_runtime
- name: businessrules_uaa
- name: business-rules
resources:
- name: businessruleseditor_html5_repo_runtime
parameters:
service-plan: app-runtime
service: html5-apps-repo
type: org.cloudfoundry.managed-service
- name: business-rules
type: org.cloudfoundry.existing-service
- name: businessrules_uaa
type: com.sap.xs.uaa
parameters:
config:
xsappname: businessrules_uaa-appname
tenant-mode: dedicated
role-templates:
- name : UaaUser
description: Role template for accessing SAP Business Rule APIs.Editor via user token flow
scope-references:
- uaa.user


00:17:20 Moving over to the SAP Cloud Platform cockpit, and to my 'trial' subaccount that has a CF organisation linked to it, where we see that while I still have the 'business-rules' service in my DEV space, I have deleted the previous instance of the Business Rules Editor so we can do it again here now.

00:19:35 Building the project with the (Java-based) deprecated build tool first of all, to see what happens, and what messages are output. We note that there's a shell script invoked, called webide_mta_build.sh. Here's an example of what the build output looks like:
(MTA BUILD) Build of "cf-businessruleseditor" started.
(Executor) The "Task for mta build" process started.
(Executor) Starting process: "cd /projects/cf-businessruleseditor; webide_mta_build.sh"
(Executor) SAP Multitarget Application Archive Builder 1.1.20
(Executor) Module "businessruleseditor_appRouter": invoking npm install --production
(Executor) Module "businessruleseditor_appRouter": command output
(Executor) npm WARN deprecated scmp@1.0.0: scmp v2 uses improved core crypto comparison since Node v6.6.0
(Executor)
(Executor) > @sap/node-jwt@1.6.5 install /projects/cf-businessruleseditor/businessruleseditor_appRouter/node_modules/@sap/node-jwt
(Executor) > node ./build.js
(Executor)
(Executor) `linux-x64-v8-6.2` exists; testing
(Executor) Binary is fine; exiting
(Executor) npm notice created a lockfile as package-lock.json. You should commit this file.
(Executor) npm WARN html5-apps-approuter@ No repository field.
(Executor) npm WARN html5-apps-approuter@ No license field.
(Executor)
(Executor) added 236 packages from 133 contributors and audited 407 packages in 7.784s
(Executor) found 5 high severity vulnerabilities
(Executor) run `npm audit fix` to fix them, or `npm audit` for details
(Executor) Module "businessruleseditor_appRouter": zipping directory businessruleseditor_appRouter
(Executor) Generating archive /projects/cf-businessruleseditor/mta_archives/businessruleseditor_0.0.1.mtar
(Executor) Done
(Executor) adding: mta_archives/businessruleseditor_0.0.1.mtar (deflated 0%)
(mtaBuildTask) Build of "cf-businessruleseditor" completed.

After the build completes, there's a new archive businessruleseditor_0.0.1.mtar created ready for deployment.

00:23:50 We now deploy this archive MTAR file to CF (to my DEV space in the "I347491trial_trial" organisation). We see further log messages in the console that look like this:
(DeploymentToCF) Deployment of the "businessruleseditor" project started.
(DeployService) Deployment in progress.
(DeployService) Deploying /cf-businessruleseditor/mta_archives/businessruleseditor_0.0.1.mtar to endpoint: https://api.cf.eu10.hana.ondemand.com, organization: I347491trial_trial, space: dev.
(DeployService) Target: https://deploy-service.cfapps.eu10.hana.ondemand.com/slprot/I347491trial_trial/dev/slpPreparing to deploy /cf-businessruleseditor/mta_archives/businessruleseditor_0.0.1.mtarPrepare deployment filesChecking if there are conflicting processesFound 0 conflicting processesUploading mtar archiveStarting deploymentDeploying in org "I347491trial_trial" and space "dev"Detected MTA schema version: "3"Detected deployed MTA with ID "businessruleseditor" and version "0.0.1"Detected new MTA version: "0.0.1"Deployed MTA version: "0.0.1"Processing service "businessrules_uaa"...Processing service "businessruleseditor_html5_repo_runtime"...Updating service "businessrules_uaa"...Updating application "businessruleseditor_appRouter"...Application "businessruleseditor_appRouter" attributes are not modified and will not be updatedUploading application "businessruleseditor_appRouter"...Staging application "businessruleseditor_appRouter"...Application "businessruleseditor_appRouter" stagedStarting application "businessruleseditor_appRouter"...Application "businessruleseditor_appRouter" started and available at "i347491trial-trial-dev-businessruleseditor-approuter.cfapps.eu10.hana.ondemand.com"Deleting discontinued configuration entries for application "businessruleseditor_appRouter"...Skipping deletion of services, because the command line option "--delete-services" is not specified.To download logs of the process, use the multi-target application plug-in for the Cloud Foundry CLI command "cf dmol -i a040b006-2d32-11ea-aec7-eeee0a91b4b0" directly in your Cloud Foundry space.For more information see https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/e93b231895b64cbc9221a629535... finished successfully.
(DeploymentToCF) Could not fetch information for businessruleseditor
(DeploymentToCF) The "businessruleseditor" project has been deployed.

00:28:05 Staring at the actual artifacts in the cf-businessruleseditor project in the SAP Web IDE we see that there's hardly anything there at all - in particular, no application code. What this project does is bundle together, via configuration, things that already exist.

00:30:20 After a bit of jiggery-pokery we get a fresh Business Rules Editor app that we now use to create a very simple Business Rules project (called ep48), mainly to see that it (hopefully) survives the destruction and subsequent recreation of the app itself.

00:31:55 In a terminal, we check the results of running cf api which shows that we're connected to the EU10 (Europe - Frankfurt) CF area:
qmacro@penguin:/tmp/ep48
-> cf api
api endpoint: https://api.cf.eu10.hana.ondemand.com
api version: 3.76.0

We also check what services exist already:
qmacro@penguin:/tmp/ep48
-> cf s
Getting services in org I347491trial_trial / space dev as dj.adams@sap.com...
name service plan bound apps last operation broker upgrade available
business-rules business-rules lite businessruleseditor_appRouter create succeeded sm-businessrules-e73ec4d2-a715-4849-a5e9-77b521e7a086
businessrules_uaa xsuaa application businessruleseditor_appRouter update succeeded sm-xsuaa-9ef36350-f975-4194-a399-54db361e79b5
businessruleseditor_html5_repo_runtime html5-apps-repo app-runtime businessruleseditor_appRouter create succeeded sm-html5-apps-repo-sb-ebcb2b69-24a5-408e-be00-02066b302b78

We then proceed to enjoy using basic command line tools such as awk to modify the output of cf s and watch to bring about a simple "monitor" effect, a basic equivalent of what we have in the cockpit, in tmux panes.

00:35:50 After a brief pause while I rearrange the screen so that everything can be viewed properly, we remove the Business Rules Editor app with cf d businessruleseditor_appRouter -f, and also the two services thus: cf ds businessrules_uaa and cf ds businessruleseditor_html5_repo_runtime, leaving us with just the business-rules service itself.

00:38:10 Looking at https://tools.hana.ondemand.com/#cloud to see the (deprecated) Multi-Target Application Archive Builder, which is a Java jar file, which we download.

00:39:30 Downloading the cf-businessruleseditor.zip file from the SAP-samples/cloud-businessrules GitHub repo so we can start again with it locally in the terminal.

00:40:20 We have a brief peek inside the downloaded ZIP file before unpacking it, to create exactly what we had in the SAP Web IDE. We can see this with the tree command thus:
qmacro@penguin:/tmp/ep48
-> tree
.
└── cf-businessruleseditor
├── businessruleseditor_appRouter
│ ├── package.json
│ └── xs-app.json
└── mta.yaml

2 directories, 3 files

Of course, we have to remember to edit the mta.yaml file to change the name references for the Business Rules service from businessrules to business-rules, which we do at this point.

00:42:05 At this stage we have a look at some of the options available to us in this (deprecated) archive builder, in particular --list-targets which shows us a list of build targets:
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> java -jar ../mta_archive_builder-1.1.20.jar --list-targets
CF
NEO
XSA

00:42:30 We can now confidently invoke the build, and messages appear that we recognise, fancy that!
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> java -jar ../mta_archive_builder-1.1.20.jar --build-target=CF build
SAP Multitarget Application Archive Builder 1.1.20
Module "businessruleseditor_appRouter": invoking npm install --production
Module "businessruleseditor_appRouter": command output
npm WARN deprecated scmp@1.0.0: scmp v2 uses improved core crypto comparison since Node v6.6.0

> @sap/node-jwt@1.6.5 install /tmp/ep48/cf-businessruleseditor/businessruleseditor_appRouter/node_modules/@sap/node-jwt
> node ./build.js

`linux-x64-v8-6.8` exists; testing
Binary is fine; exiting
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN html5-apps-approuter@ No repository field.
npm WARN html5-apps-approuter@ No license field.

added 236 packages from 133 contributors and audited 407 packages in 10.082s
found 5 high severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
Module "businessruleseditor_appRouter": zipping directory businessruleseditor_appRouter
Generating archive /tmp/ep48/cf-businessruleseditor/cf-businessruleseditor.mtar
Done

As a result of this build, we have a deployable archive file - it has a slightly different name (cf-businessruleseditor.mtar), but it's basically the same as what we had in the SAP Web IDE:
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> ls -l
total 11448
drwxr-xr-x 1 qmacro qmacro 132 Jan 2 08:32 businessruleseditor_appRouter
-rw------- 1 qmacro qmacro 11715381 Jan 2 08:32 cf-businessruleseditor.mtar
-rw-r--r-- 1 qmacro qmacro 1022 Sep 17 06:25 mta.yaml

00:45:30 Invoking cf plugins, we see the plugins I've installed for my cf command tool:
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> cf plugins
Listing installed plugins...

plugin version command name command help
multiapps 2.2.0 bg-deploy Deploy a multi-target app using blue-green deployment
multiapps 2.2.0 deploy Deploy a new multi-target app or sync changes to an existing one
multiapps 2.2.0 download-mta-op-logs, dmol Download logs of multi-target app operation
multiapps 2.2.0 mta Display health and status for a multi-target app
multiapps 2.2.0 mta-ops List multi-target app operations
multiapps 2.2.0 mtas List all multi-target apps
multiapps 2.2.0 purge-mta-config Purge no longer valid configuration entries
multiapps 2.2.0 undeploy Undeploy a multi-target app

Use 'cf repo-plugins' to list plugins in registered repos available to install.

00:46:25 We're now ready to deploy, which we do by invoking cf deploy:
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> cf deploy ./cf-businessruleseditor.mtar
Deploying multi-target app archive ./cf-businessruleseditor.mtar in org I347491trial_trial / space dev as dj.adams@sap.com...
Uploading 1 files...
/tmp/ep48/cf-businessruleseditor/cf-businessruleseditor.mtar
OK
Deploying in org "I347491trial_trial" and space "dev"
Detected MTA schema version: "3"
Detected deployed MTA with ID "businessruleseditor" and version "0.0.1"
Detected new MTA version: "0.0.1"
Deployed MTA version: "0.0.1"
Processing service "businessrules_uaa"...
Processing service "businessruleseditor_html5_repo_runtime"...
Updating service "businessrules_uaa"...
Updating application "businessruleseditor_appRouter"...
Application "businessruleseditor_appRouter" attributes are not modified and will not be updated
Uploading application "businessruleseditor_appRouter"...
Stopping application "businessruleseditor_appRouter"...
Staging application "businessruleseditor_appRouter"...
Application "businessruleseditor_appRouter" staged
Starting application "businessruleseditor_appRouter"...
Application "businessruleseditor_appRouter" started and available at "i347491trial-trial-dev-businessruleseditor-approuter.cfapps.eu10.hana.ondemand.com"
Deleting discontinued configuration entries for application "businessruleseditor_appRouter"...
Skipping deletion of services, because the command line option "--delete-services" is not specified.
Process finished.
Use "cf dmol -i 9086c32f-2d3c-11ea-b272-eeee0a8ae9c6" to download the logs of the process.

It's not a surprise by now that the output from this deploy invocation is also familiar to us - basically the same as what we saw in the console in the SAP Web IDE.

00:50:00 Attempting to access the Business Rules Editor app again shows that we've been successful. Not only that but we can also see that our simple project ep48 is still there (of course it is, we've only destroyed -- and recreated -- the editor app, not the project itself!).

00:50:50 We remove the app and the two services again, because this time we want to try out the new (non-deprecated) build tool, the Cloud MTA Build Tool, described very nicely in this blog post "Enjoy our new tool for building MTA archives!" by natalia.katunin.

00:52:55 While the removal happens, we go over and check what's already installed, from a global NPM perspective, on my machine (the new build tools is JavaScript-based and available via NPM - nice!):
qmacro@penguin:/tmp/ep48
-> npm ls -g --depth=0
/home/qmacro/.config/nvm/versions/node/v10.17.0/lib
├── @sap/cds@3.20.1
├── mbt@1.0.5
└── npm@6.13.4

As we can see, I've already installed the tool (which we'll refer to as mbt), which I did earlier with npm i -g mbt.

00:55:00 At this point we create a new directory and unpack the cf-businessruleseditor project into it again, ready for a new build with mbt. Of course, we have to remember to make the changes to mta.yaml again but after that, we're set to go with the new build tool, which completes much more quickly too!
qmacro@penguin:/tmp/ep48/cf-businessruleseditor
-> mbt build
[2020-01-02 09:05:26] INFO Cloud MTA Build Tool version 1.0.6
[2020-01-02 09:05:26] INFO generating the "Makefile_20200102090526.mta" file...
[2020-01-02 09:05:26] INFO done
[2020-01-02 09:05:26] INFO executing the "make -f Makefile_20200102090526.mta p=cf mtar= strict=true mode=" command...
[2020-01-02 09:05:26] INFO validating the MTA project
[2020-01-02 09:05:26] INFO validating the MTA project
[2020-01-02 09:05:26] INFO building the "businessruleseditor_appRouter" module...
[2020-01-02 09:05:26] INFO executing the "npm install --production" command...
....npm WARN deprecated scmp@1.0.0: scmp v2 uses improved core crypto comparison since Node v6.6.0
......
> @sap/node-jwt@1.6.5 install /tmp/ep48/cf-businessruleseditor/businessruleseditor_appRouter/node_modules/@sap/node-jwt
> node ./build.js

`linux-x64-v8-6.8` exists; testing
Binary is fine; exiting
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN html5-apps-approuter@ No repository field.
npm WARN html5-apps-approuter@ No license field.

added 236 packages from 133 contributors and audited 407 packages in 9.982s
found 5 high severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
[2020-01-02 09:05:36] INFO the build results of the "businessruleseditor_appRouter" module will be packed and saved in the "/tmp/ep48/cf-businessruleseditor/.cf-businessruleseditor_mta_build_tmp/businessruleseditor_appRouter" folder
[2020-01-02 09:05:38] INFO finished building the "businessruleseditor_appRouter" module
[2020-01-02 09:05:38] INFO generating the metadata...
[2020-01-02 09:05:38] INFO generating the MTA archive...
[2020-01-02 09:05:38] INFO the MTA archive generated at: /tmp/ep48/cf-businessruleseditor/mta_archives/businessruleseditor_0.0.1.mtar
[2020-01-02 09:05:38] INFO cleaning temporary files...

00:56:20 We go back to the SAP Web IDE to invoke the equivalent build, to check that the output in the console is the same as what we see in our terminal, and it is, of course. We note in passing that the script that the SAP Web IDE invokes in this case is webide_mbt_build.sh, as opposed to the one that was invoked with the deprecated build tool (webide_mta_build.sh) earlier.

00:58:20 We note that this new build tool creates the archive file in a similar way to what we saw in the SAP Web IDE, i.e. mta_archives/businessruleseditor_0.0.1.mtar. Deploying this in the same way as before (with cf deploy) leads to success, too. Lovely!

Hopefully this episode demystified (or "de-magic-ified") what goes on in the build and deploy features of the SAP Web IDE!