Skip to content
This repository has been archived by the owner on Oct 9, 2021. It is now read-only.

Commit

Permalink
Update versions and adapt instructions for trial (#11)
Browse files Browse the repository at this point in the history
Updated CDS Services versions to 1.2.0 and performed necessary code changes.
Updated instructions to explain how to use CloudPlatform Trial accounts.
Therefore also removed reference to XXX or other instructor provided details.
  • Loading branch information
beckermarc committed Feb 14, 2020
1 parent 8d13eaa commit 025d5eb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
6 changes: 3 additions & 3 deletions exercises-java/exercise1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Before you can start using SAP Application Studio, you need to create your devel

<img src="images/create_dev_space.png" width="100%" />

3. Choose a name for your dev space. For example **TechEd19_1XX**. **XX** is the number given to you by your instructor.
3. Choose a name for your dev space. For example **TechEd19**.

4. Choose **SAP Cloud Business Application** as the application type.

By selecting **SAP Cloud Business Application**, your space comes with several extensions out of the box that you'll need to develop CAP applications. For example, CDS tools are built in. This saves unnecessary setup time.
By selecting **SAP Cloud Business Application**, your space comes with several extensions out of the box that you'll need to develop CAP applications. For example, CDS tools are built in. This saves unnecessary setup time.

5. Choose **Create Dev Space**.

Expand All @@ -46,7 +46,7 @@ Before you can start using SAP Application Studio, you need to create your devel

```bash
mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds \
-DarchetypeVersion=1.0.1 -DcdsVersion=3.17.4 \
-DarchetypeVersion=1.2.0 -DcdsVersion=3.21.2 \
-DgroupId=com.sap.teched.cap -DartifactId=products-service -Dpackage=com.sap.teched.cap.productsservice
```

Expand Down
2 changes: 1 addition & 1 deletion exercises-java/exercise3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For the bookstore, which you'll develop in this exercise we need to create and i

```bash
mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds \
-DarchetypeVersion=1.0.1 -DcdsVersion=3.17.4 \
-DarchetypeVersion=1.2.0 -DcdsVersion=3.21.2 \
-DgroupId=com.sap.teched.cap -DartifactId=bookstore
```
4. To open the bookstore project in a new workspace:
Expand Down
18 changes: 11 additions & 7 deletions exercises-java/exercise4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ You will now add a method to the `OrdersService` Java class to decrease the stoc
@Before(event = CdsService.EVENT_CREATE, entity = "OrdersService.Orders")
public void validateBookAndDecreaseStockViaOrders(List<Orders> orders) {
for(Orders order : orders) {
validateBookAndDecreaseStock(order.getItems());
if(order.getItems() != null) {
validateBookAndDecreaseStock(order.getItems());
}
}
}
```
Expand All @@ -106,10 +108,10 @@ You will now add a method to the `OrdersService` Java class to decrease the stoc
import com.sap.cds.services.handler.annotations.Before;
import com.sap.cds.services.persistence.PersistenceService;

import ordersservice.OrderItems;
import ordersservice.Orders;
import sap.capire.bookstore.Books;
import sap.capire.bookstore.Books_;
import cds.gen.ordersservice.OrderItems;
import cds.gen.ordersservice.Orders;
import cds.gen.sap.capire.bookstore.Books;
import cds.gen.sap.capire.bookstore.Books_;
```

Let's break down what is happening:
Expand Down Expand Up @@ -247,7 +249,9 @@ Finally, add a method to the `OrdersService` Java class to calculate the `total`
public void calculateTotal(List<Orders> orders) {
for (Orders order : orders) {
// calculate net amount for expanded items
calculateNetAmount(order.getItems());
if(order.getItems() != null) {
calculateNetAmount(order.getItems());
}

// get all items of the order
CqnSelect selItems = Select.from(OrderItems_.class).where(i -> i.parent().ID().eq(order.getId()));
Expand All @@ -269,7 +273,7 @@ Finally, add a method to the `OrdersService` Java class to calculate the `total`
2. Also add the following import statements to the top of the `OrdersService` Java class:

```java
import sap.capire.bookstore.OrderItems_;
import cds.gen.sap.capire.bookstore.OrderItems_;
```

Let's break the code down:
Expand Down
28 changes: 20 additions & 8 deletions exercises-java/exercise5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

In the last exercise you have added custom coding to your bookstore application. In this exercises you will make the application ready to be deployed to the cloud. In order to make our application cloud-ready, we'll switch to SAP HANA as our database.

## Creating a CloudFoundry Trial account

The following two exercises require access to an SAP Cloud Platform account with a Subaccount for the Cloud Foundry environment.
The subaccount needs to have the following entitlements assigned to it:

1. Service: 'SAP HANA Schemas & HDI Containers' or Service 'SAP HANA Schemas & HDI Containers (Trial)'
Plan: 'hdi-shared'
Quota: 1 Unit
2. Service: 'Application Runtime'
Plan: 'MEMORY'
Quota: 1 GiB

You can use a free trial account for this. Please follow [this tutorial](https://developers.sap.com/tutorials/hcp-create-trial-account.html) to create a free trial account.

## Initializing the SAP HANA database

First you need to create and initialize a SAP HANA database schema in the cloud. As you will deploy your application to SAP Cloud Platform Cloud Foundry Environment, you will also create the SAP HANA service there.
Expand All @@ -12,19 +26,17 @@ Login to the Cloud Foundry Environment using the cf CLI:

2. Run `cf api <CF_API>` in the terminal.

The `<CF_API>` endpoint will be provided to you by your instructor.
The `<CF_API>` endpoint can be obtained from the Overview page of your Subaccount in Cloud Cockpit.

3. Run `cf login` and authenticate using the login credentials provided to you by your instructor.
3. Run `cf login` and authenticate using your login credentials.

Initializing the SAP HANA database is now as simple as running these commands in the terminal:

1. Make sure that you are in the root of the bookstore project: `cd ~/projects/bookstore`

2. Run `npm install --save-dev --save-exact @sap/[email protected]`

3. Run `cds deploy --to hana:bookstore-hana-<XXX>`

Replace `<XXX>` with the number given to you by your instructor
3. Run `cds deploy --to hana:bookstore-hana`

With this command, you've created an SAP HANA service instance. In addition, the command initialized the database schemas inside the SAP HANA HDI container.

Expand All @@ -51,11 +63,11 @@ The described features are available as a plugin in CAP Java. Therefore, we'll a

3. Make sure that you are in the root of the bookstore project: `cd ~/projects/bookstore`

4. Let's test the SAP HANA connectivity. Start your application by running `mvn spring-boot:run -Dspring.profiles.active=cloud`
4. Let's test the SAP HANA connectivity. Start your application by running `mvn spring-boot:run -Dspring-boot.run.profiles=cloud`

> Note: The Java system property `-Dspring.profiles.active=cloud` ensures that the default configuration using SQLite as the database, which is still defined in the `application.yaml`, does not get activated.
> Note: The Java system property `-Dspring-boot.run.profiles=cloud` ensures that the default configuration using SQLite as the database, which is still defined in the `application.yaml`, does not get activated.
5. You can observe the log lines `Loaded default-env.json from directory '/home/user/projects/bookstore'` and `Registered 'DataSource' bean definition for connected service 'bookstore-hana-<XXX>'` which indicate that the SAP HANA configuration was picked up.
5. You can observe the log lines `Loaded default-env.json from directory '/home/user/projects/bookstore'` and `Registered primary 'DataSource' bean definition for connected service 'bookstore-hana'` which indicate that the SAP HANA configuration was picked up.

6. Try the following example request, which creates an order together with it's items through a deep insert:

Expand Down
14 changes: 6 additions & 8 deletions exercises-java/exercise6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ When deploying an application to Cloud Foundry, you can use a manifest to descri

1. Go to the `~/projects/bookstore` folder and create a new file called `manifest.yml`.

2. Add the following code to the newly created file. Remember to replace `<XXX>` with the number given to you by your instructor.
2. Add the following code to the newly created file.

```yaml
---
applications:
- name: bookstore-<XXX>
- name: bookstore
path: srv/target/bookstore-1.0-SNAPSHOT.jar
random-route: true
services:
- bookstore-hana-<XXX>
- bookstore-hana
```

The manifest describes the name of the application and the path where the application archive can be found. Spring Boot applications can be deployed from a single JAR archive, which is what you are making use of here.

The route of the application, meaning the HTTP endpoint where it will be available, will be randomized to prevent clashes with other application routes.

The name of SAP HANA service instance you created in [Exercise 5](../exercise5/README.md) is used here under the services section (`bookstore-hana-<XXX>`)
The name of SAP HANA service instance you created in [Exercise 5](../exercise5/README.md) is used here under the services section (`bookstore-hana`)

## Auto configuration of the SAP HANA database connection

Expand All @@ -45,7 +45,7 @@ The described feature is again available as a further plugin in CAP Java. Theref

Even with the Cloud Foundry feature enabled, CAP Java ensures that your application can run still run locally with SQLite or SAP HANA auto-configured based on default-env.json. It provides a seamless developer experience in all environments.

In [Exercise 5](../exercise5/README.md) you added the additional Java system property `-Dspring.profiles.active=cloud` to your application to ensure that the default SQLite configuration from the `application.yaml` does not take effect. When deploying the application to Cloud Foundry this is done automatically for you by the Cloud Foundry Java Buildpack.
In [Exercise 5](../exercise5/README.md) you added the additional Java system property `-Dspring-boot.run.profiles=cloud` to your application to ensure that the default SQLite configuration from the `application.yaml` does not take effect. When deploying the application to Cloud Foundry this is done automatically for you by the Cloud Foundry Java Buildpack.

## Pushing the application

Expand All @@ -59,9 +59,7 @@ You are now ready to push your application to the cloud by running the following

The manifest will be automatically picked up.

4. Run `cf app bookstore-<XXX>` to retrieve the application URL, which can be found under `routes`.

Replace `<XXX>` with the number given to you by your instructor.
4. Run `cf app bookstore` to retrieve the application URL, which can be found under `routes`.

5. Open this URL to test your application running in the cloud.

Expand Down

0 comments on commit 025d5eb

Please sign in to comment.