I've refactored my project to use the new Cloud Platform Application Programming Model.
My project structure looks file this:
<my_project_name> - hdb (db module) - srv (service module) - ui (ui module) - cdsrc.json - package.json - mta.yaml cdsrc.json:
{ "build": { "target": ".", "tasks": [ {"src":"hdb","for":"hana","options":{"model":["hdb","srv"]}}, {"src":"srv","for":"node-cf","options":{"model":["hdb","srv"]}} ] } } package.json:
{ "name": "<my_project_name>", "description": "", "version": "1.0.0", "engines": { "node": "^8.9" }, "files": [ "hdb", "srv" ], "dependencies": { "@sap/cds": "^3.7.1", "express": "^4.16.4", "hdb": "^0.17.0" }, "devDependencies": { "sqlite3": "^4.0.8" }, "scripts": { "start": "cds run", "build": "cds build/all --clean", "deploy": "cds deploy" }, "cds": { "requires": { "db": { "kind": "sqlite", "model": [ "hdb", "srv" ], "credentials": { "database": "sqlite.db" } } }, "folders": { "db": "hdb", "srv": "srv" } } } srv/package.json:
{ "name": "srv", "dependencies": { "@sap/cds": "^3.7.1", "@sap/xssec": "^2.1.12", <other_packages> }, "scripts": { "start": "node server.js" }, "cds": { "requires": { "db": { "kind": "hana", "model": "gen/csn.json" } } } } srv/server.js:
const cds = require("@sap/cds"); const express = require("express"); //other imports var app = express(); //other middleware cds.connect(); cds.serve("gen/csn.json", { crashOnError: false }) .in(app) .catch((err) => { console.log(err); }); app.listen(port, () => { console.info(`App listening on port: ${port}`); }); When I build my project in WebIDE, it builds all .cds files successfully, and writes the output like this to console:
> <my_project_name>@1.0.0 build /hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/ > cds build/all --clean [cds] - cds [3.10.0], compiler [1.13.4], home [/hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/ [cds] - building project [/hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/ clean [true] [cds] - building module [hdb] using [Hana DB Module Builder] [cds] - model: hdb/<file1>.cds, hdb/<file2>.cds, <all_other_cds_files> [cds] - building module [srv] using [Node CF Module Builder] [cds] - model: model: hdb/<file1>.cds, hdb/<file2>.cds, <all_other_cds_files> 12:03:53 PM (DIBuild) [cds] - done > wrote output to: hdb/src/gen/.hdinamespace hdb/src/gen/csv/<file1>_<entity1>.hdbcds hdb/src/gen/csv/<file1>_<entity2>.hdbcds hdb/src/gen/csv/<file2>_<entity1>.hdbcds ... srv/gen/csn.json srv/gen/_i18n/i18n.json [cds] - time: 2600.051ms CDS return code: 0 Even though "cds build" command generates those files in "hdb/src/gen" and "srv/gen" folders (I saw all files by SSH-ing to the matchine where SAP Hana is installed, on path from the output above: /hana/shared/HXE/xs/controller_data/executionagent/executionroot/269f9533-c450-4f35-ab0e-b62990473bb5/app/META-INF/.sap_java_buildpack/tomcat/temp/builder/), they are not displayed in Project explorer of WebIDE.
When i build my db module (hdb), it deploys artifacts to HDI container without any error, and I can browse the container with Database Explorer
But running the "srv" module gives me this error:
{ Error: Couldn't find a CDS model at: gen/csn.json at notFound (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/models/load.js:59:39) at EventEmitter.load (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/models/load.js:10:50) at _loadModel (/hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/node_modules/@sap/cds/lib/runtime/serve.js:78:35) at <anonymous> at runMicrotasksCallback (internal/process/next_tick.js:122:5) at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickCallback (internal/process/next_tick.js:181:9) at Function.Module.runMain (module.js:696:11) at startup (bootstrap_node.js:225:16) at bootstrap_node.js:646:3 code: 'MODEL_NOT_FOUND', model: 'gen/csn.json' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! serve@ start: `node server.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the serve@ start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /hana/shared/HXE/xs/controller_data/executionagent/executionroot/2dff31be-8521-4d87-a173-f71c65f6b69c/app/.npm/_logs/2019-06-17T11_49_21_417Z-debug.log Sure, path where "cds build" generates csn.json, and path where serve.js wants to load that model are different. But, doesn't it copy all files automatically to the "srv" module execution root?
My current workflow:
- Make changes to CDS files locally with VS Code
- Build project, so it generates csn.json
- Commit changes and push to Git repo
- Pull changes in WebIDE
- CDS Build, so I can deploy changes to database
- Before running "srv" module, copy content from csn.json generated locally, paste it in WebIDE' csn.json, and replace the paths with the one given in CDS build console output.
I appreciate any help to solve this problem. :)
Related questions 22 How to build SCons projects with Eclipse CDT? 2 How to add a directory with source files in PVCS 1 SAP HANA Javascript deployment Related questions 22 How to build SCons projects with Eclipse CDT? 2 How to add a directory with source files in PVCS 1 SAP HANA Javascript deployment 1 Web Application using JavaCV and deployed on SAP HANA Cloud Platform error 0 SAP HANA - Error when trying to import data via Eclipse 0 STRING_AGG is not a recognized built-in function name when using SAP HANA CDS file 3 Connect to another SAP HANA database with CDS 2 SAP Hybris Assisted Service Module (ASM) - can't generate component 0 Error while building maven project s4hana cloud sdk 3 'Unable to build destination for service binding' with SAP Cloud SDK JS app Load 7 more related questions Show fewer related questions
Reset to default