Skip to content
This repository was archived by the owner on Nov 13, 2021. It is now read-only.

Commit 45d64b0

Browse files
authored
Merge pull request #1 from IObert/master
Add exercise 10 for Cloud Foundry deployment
2 parents 9a766d8 + c5828cb commit 45d64b0

22 files changed

+295
-215
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Here's an overview of the exercises in this CodeJam.
3333
- [Exercise 07 - Defining a second service](exercises/07/)
3434
- [Exercise 08 - Adding custom logic, and debugging](exercises/08/)
3535
- [Exercise 09 - Introducing an app at the UI layer](exercises/09/)
36-
- [Exercise 10 - (Bonus) Deploy a simple project to the Cloud](exercises/10/)
36+
- [Exercise 10 - Deploy a simple project to the Cloud](exercises/10/)
3737

3838
### Feedback
3939

@@ -60,5 +60,3 @@ Support for the content in this repository is available during CodeJam events, f
6060
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
6161

6262
This file is licensed under the SAP Sample Code License except as noted otherwise in the [LICENSE](LICENSE) file.
63-
64-

exercises/01/readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ When successfully installed, you should see the extension thus:
8181

8282
![CDS Language Support extension installed in VS Code](vscode-extension.png)
8383

84+
### 3. Install the MultiApp Build Tool (mbt)
85+
This tool allows you in package your project into a deployable archieve.
86+
```
87+
npm install -g mbt
88+
```
89+
8490
## Summary
8591

8692
You've now installed the two key tools for developing with CAP locally, and are all set to create your first project.
@@ -94,4 +100,3 @@ You've now installed the two key tools for developing with CAP locally, and are
94100
1. What is the significance of using the `--global` option when installing the `@sap/cds` package?
95101

96102
1. What is the meaning of the `.vsix` file type for the VS Code extension? Can we dig into that to see what's inside?
97-
1.89 KB
Loading
34.7 KB
Loading
3.38 KB
Loading

exercises/02/readme.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,30 @@ user@host:~
6565
=> cds init --help
6666
```
6767
68-
Amongst other things, you should see a `--modules` option to specify a list of modules to be created when the project is initialized, and also a `--verbose` option.
68+
Amongst other things, you should see a `--modules` option to specify a list of modules to be created when the project is initialized, and also a `--verbose` option. The options `--mta`, `--db-technology` and `--insecure` are related to deployment to Cloud Foundry and its access management.
6969
70-
:point_right: Use both of these options to initialize a new project directory thus:
70+
:point_right: Use all of these options to initialize a new project directory thus:
7171
7272
```sh
7373
user@host:~
74-
=> cds init --modules db,srv --verbose bookshop
74+
=> cds init --modules db,srv --mta --insecure --db-technology hana --verbose bookshop
7575
```
7676
7777
You should see output that looks similar to this:
7878
79-
```sh
80-
Creating new project in directory bookshop.
81-
82-
Copying templates for type db to bookshop/db ...
83-
Copying templates for type srv to bookshop/srv ...
84-
Updating npm dependencies in bookshop/package.json ...
79+
```
80+
[Warn] Srv type nodejs only supports odata version v4 and not v2. Will use v4.
81+
Initializing project in folder bookshop.
82+
Copying templates for type db to db ...
83+
Creating mta file /Users/d056949/SoftwareDev/sandbox/bookshop/mta.yaml ...
84+
Copying templates for type srv to {{moduleFolder}} ...
85+
Creating mta file /Users/d056949/SoftwareDev/sandbox/bookshop/mta.yaml ...
86+
Updating npm dependencies in /Users/d056949/SoftwareDev/sandbox/bookshop/package.json ...
8587
Running npm install...
86-
npm WARN bookshop@1.0.0 license should be a valid SPDX license expression
87-
88-
added 76 packages from 109 contributors and audited 166 packages in 3.261s
88+
added 81 packages from 111 contributors and audited 176 packages in 2.976s
8989
found 0 vulnerabilities
9090
91-
92-
Project creation was successful.
91+
Finished successfully.
9392
```
9493
9594
@@ -123,6 +122,7 @@ Briefly, the directories and contents can be described thus:
123122
| `db` | Where the data models (in CDS) are specified. A skeleton CDS project that has been initialized with the `--modules db` option will have a basic data model file in the form of `data-model.cds` with a small sample definition, like here |
124123
| `node_modules` | This is the normal place where NPM packages (modules) are to be found in a Node.js based project |
125124
| `srv` | Where the service definitions (in CDS) are specified. A skeleton CDS project that has been initialized with the `--modules srv` option will have a basic service definition file in the form of `cat-service.cds` with a small service definition, like here |
125+
| `mta.yaml` | This is the central descriptor file for the project. It defines all modules (microservices) and backing services (like databases). This information will be used (a) to build the .mtar archive during design time and to deploy and provision the apps and services during deploy time. |
126126
127127
Besides the directories there are also a number of files, including the project's `package.json` (present in any Node.js based project) and a readme file.
128128

@@ -158,14 +158,15 @@ Note: You can also specify simply `cds serve all` to have `cds` look for appropr
158158
You should see output similar to this:
159159
160160
```
161-
[cds] - server listening at http://localhost:4004
161+
[cds] - connect to datasource - hana:db,srv
162162
[cds] - serving CatalogService at /catalog
163163
[cds] - service definitions loaded from:
164164
165165
srv/cat-service.cds
166166
db/data-model.cds
167167
168-
[cds] - launched in: 448.633ms
168+
[cds] - server listens at http://localhost:4004 ... (terminate with ^C)
169+
[cds] - launched in: 566.451ms
169170
```
170171
171172
The OData service is now running, and available on [http://localhost:4004](http://localhost:4004).
@@ -183,7 +184,7 @@ The [catalog](http://localhost:4004/catalog) link will take you to the service d
183184

184185
:point_right: Explore the metadata document and familiarize yourself with the content. Note the entityset definition and the entity type describing the `Books` entity. Note also the annotations describing particular service capabilities.
185186

186-
:point_right: There is also a link to the [Books](http://localhost:4004/catalog/Books) entityset. Follow this link to see what the service returns.
187+
:point_right: There is also a link to the [Books](http://localhost:4004/catalog/Books) entityset. Follow this link to see what the service returns. Check what happens to the node process when you try to access the entityset.
187188

188189

189190
## Summary
@@ -200,3 +201,5 @@ With a single command, you've initialized a basic OData service project and with
200201
1. What are the annotations in the metadata document describing, and where do they come from?
201202

202203
1. What does the Books entityset resource contain right now?
204+
205+
1. What happened to the node process when you accessed the entityset? Can you think of reasons why this happened?

exercises/03/readme.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,50 @@ Don't forget to save the file.
105105

106106
As it stands, the OData service has no storage. We can actually simulate storage with [service provider](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b9c34890348b4f2184e07a6731bce50b.html) logic in JavaScript but that's not a path we want to explore right now (we'll look at it in [exercise 08](../08/)). Instead, we'll use a real database in the form of [SQLite](https://sqlite.org) and deploy the data model and service definition to it.
107107

108-
_Note: From cds 3.10 onwards, the `sqlite3` package is automatically installed in the project for you as a development dependency so it's all ready for you to start using._
108+
:point_right: Update the database definition in `package.json` to include a SQLite DB for local testing. This will fix the issue you encountered before when the node process crashed. Currently, you'll see a section that describes the persistence layer configuration:
109+
110+
```json
111+
"cds": {
112+
"requires": {
113+
"db": {
114+
"kind": "hana",
115+
"model": [
116+
"db",
117+
"srv"
118+
]
119+
}
120+
},
121+
"odata": {
122+
"version": "v4"
123+
}
124+
}
125+
```
126+
To prepare the app for a multiple databases, change the content to:
127+
```json
128+
"cds": {
129+
"requires": {
130+
"db": {
131+
"kind": "sqlite",
132+
"model": ["db", "srv"],
133+
"credentials": {
134+
"database": "bookshop.db"
135+
},
136+
"[production]": {
137+
"kind": "hana"
138+
}
139+
}
140+
},
141+
"odata": {
142+
"version": "v4"
143+
}
144+
}
145+
```
146+
147+
:point_right: As we want to use a local SQLite database, we need to install a client to communicate with this DB. Install the `sqlite3` package for this job.
148+
```
149+
npm install -D sqlite3
150+
```
151+
109152

110153
:point_right: Explore the `cds deploy` command like this:
111154

@@ -128,34 +171,10 @@ Use this command to deploy the data model and service definition to a new SQLite
128171

129172
```
130173
user@host:~/bookshop
131-
=> cds deploy --to sqlite:bookshop.db
132-
```
133-
134-
This should complete fairly quietly, and give a message like this:
135-
136-
```
137-
- updated package.json
138-
```
139-
140-
Note: If you're wondering what is been updated in `package.json` relating to the use of SQLite, have a look. You'll see a section that describes the persistence layer configuration:
141-
142-
```json
143-
"cds": {
144-
"requires": {
145-
"db": {
146-
"kind": "sqlite",
147-
"model": [
148-
"db",
149-
"srv"
150-
],
151-
"credentials": {
152-
"database": "bookshop.db"
153-
}
154-
}
155-
}
156-
}
174+
=> cds deploy
157175
```
158176

177+
This should complete fairly quietly.
159178

160179
### 5. Explore the new database
161180

exercises/04/csv-files.png

-14.5 KB
Loading

exercises/04/my.bookshop-Authors.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ID,name
1+
ID,NAME
22
42,Douglas Adams
33
101,Emily Brontë
44
107,Charlote Brontë

exercises/04/my.bookshop-Books.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ID,title,author_ID,stock
1+
ID,TITLE,AUTHOR_ID,STOCK
22
421,The Hitch Hiker's Guide To The Galaxy,42,1000
33
427,"Life, The Universe And Everything",42,95
44
201,Wuthering Heights,101,12

0 commit comments

Comments
 (0)