cancel
Showing results for 
Search instead for 
Did you mean: 

CAP MTA Java Project - Local Database is used on CF

christoffer_fuss
Participant
0 Kudos

Hello community,

I started a CAP Java project and turned it into a MTA project, you can find it here.

I deployed my db module and my srv module with cf deploy command to my CF account and used cf env to create my default-env.json.

The deployment is running without any errors.

If I start my srv application my service is still running against my local sqllite database:

I attched the compete log file.cockpitcap-srv-2020-05-02-22-10-458430000.txt

What must I do, that my HANA database is used on CF and not my local sqlite database?

Before I turned my project into a MTA project I used cf push and a manifest.yaml for the deployment and it was working fine.

Best Regards,

Chris

Accepted Solutions (0)

Answers (1)

Answers (1)

klaus_kopecz
Participant
0 Kudos

Not sure why you are using default-env.json when you are running the srv module on cf.

Seeing your package.json, Hana will be linked if the production profile is active, which should be the case however on cf. Could you check the environment variable NODE_ENV in your srv app on cf? What is it’s value?

christoffer_fuss
Participant
0 Kudos

Hi Klaus, Thanks for helping.

I thought the default-env.json is needed to deploy the database?

The enviroment variable NODE_ENV is not set for my srv application? How can I set this value to production?

Best regards,

Chris

klaus_kopecz
Participant
0 Kudos

Could you use

cf set-env  APP_NAME  ENV_VAR_NAME  ENV_VAR_VALUE

to set NODE_ENV of your srv application on cloud foundry to 'production' and try again?

christoffer_fuss
Participant
0 Kudos

I set the variable and restarted my application and still get sqllite errors 😞

I checked the application from gregorw and the variable is not set there as well...

Any other suggestions?

klaus_kopecz
Participant
0 Kudos

Not sure what happens. Maybe it helps to use the new best practice of using "kind": "sql".

"requires": {
   "db": {"kind": "sql"}
}

The abstract kind "sql" resolves to sqlite in a development environment and to hana in productive environment.

Regards

christoffer_fuss
Participant
0 Kudos

This is changing nothing.

I just started a new cap project with

cds init

Then I turned it into a MTA project as described here.

If I deploy the project with

cf deploy

I get the same error as in my project.

So what is the correc way to switch a basic cap project to a working MTA project?

chgeo
Advisor
Advisor

klaus.kopecz : this is a Java project, so NODE_ENV, requires.db, etc won't help here as this is Node.js-specfic.

The root cause seems to be an incomplete Java configuration that always activates sqlite. Take a look at a standard configuration and note how the empty `cloud` profile, which gets automatically activated on CF, overwrites the sqlite config with 'nothing', This leads to SAP HANA being used if its bound through a service binding on CF. Learn more on the Java configuration in the docs.

christoffer_fuss
Participant
0 Kudos

This was working 🙂 Thank you so much!!!! Maybe you change your comment to an answer?

christoffer_fuss
Participant
0 Kudos

Hi christian.georgi ,

I was wrong, it is not working yet. If I build my project with

mbt build

the default profile is read from application.yaml and not the cloud profile.

---
spring:
  resources.static-locations: "file:./app"
cds:
  odata-v4.endpoint.path: "/api"
  security.mock.users:
    - name: admin
      password: admin
      roles:
      - admin
    - name: user
      password: user

---
spring:
  profiles: cloud

---
spring:
  profiles: sqlite
  datasource:
    url: "jdbc:sqlite:sqlite.db"
    driver-class-name: org.sqlite.JDBC
    initialization-mode: never
    hikari:
      maximum-pool-size: 1

---
spring:
  profiles: default
  datasource:
    url: "jdbc:sqlite:file::memory:?cache=shared"
    driver-class-name: org.sqlite.JDBC
    initialization-mode: always
    hikari:
      maximum-pool-size: 1

In addition the mbt build is not reading the [production] part of my package.json.

 "db": {
    "kind": "sqlite",
     "model": [
        "db",
        "srv"
      ],
      "[production]": {
        "kind": "hana"
       }
     }

What is needed to configure the MTA build tool to use the production profile?

Best Regards,

Chris

chgeo
Advisor
Advisor
0 Kudos

For the build: to activate the `production` profile, try with `CDS_ENV=production mbt build` (in bash) and check that the HANA files are created in db/gen. Alternatively, change package.json so that it has `kind:hana` as default entry.

For the `cloud` profile: check your startup logs of the Spring Boot app. There it should mention, which profiles got activated. If you really see only `default` being activated, you could add `SPRING_PROFILES_ACTIVE=cloud` environment variable to e.g. mta.yaml in the `properties` section of the `cockpitcap` module.

christoffer_fuss
Participant
0 Kudos

Thanks, this is working. But what is still strange is, that using the command

cds deploy --to hana

is changing my package.json to:

"db": {
    "kind": "sql"
 },

Why is that hapeing? So i have to change it back to "hana" all the time which is quite annoying.

Best Regards,

Chris

klaus_kopecz
Participant

Hi Christoffer,

You should try the --no-save option for the deploy commands:

cds deploy --to hana --no-save
cds deploy --to sqlite --no-save

This prevents that package.json is changed.

Regards

christoffer_fuss
Participant
0 Kudos

Thanks, this is working 🙂

klaus_kopecz
Participant
0 Kudos

In package.json, I'm using:

"requires": { 
     "db": {
        "[production]": {"kind":"hana"},
        "[development]": {"kind": "sqlite"}
    }
}

Then, depending on where I want to deploy to, I'm setting NODE_ENV to "" (or "development"), or to "poduction").

'cds deploy --no-save' is doing the right thing then.

You might want to follow my Github issue on this topic:

https://github.com/sapmentors/cap-community/issues/67