Giter Club home page Giter Club logo

Comments (6)

sebastianesch avatar sebastianesch commented on June 3, 2024 1

Hi @pwasem,

change your .cdsrc.json to add the dialect to the postgres section:

{
  "features": {
    "fiori_preview": true
  },
  "requires": {
    "db": {
      "kind": "postgres"
    },
    "postgres": {
      "dialect": "plain", // << Add the dialect
      "impl": "cds-pg",
      "model": [
        "app"
      ]
    }
  }
}

And change your default-env.json to the tags "plain" and "db":

{
  "PORT": 5005,
  "VCAP_SERVICES": {
    "postgres": [
      {
        "name": "postgres",
        "label": "postgres",
        "tags": ["plain", "db"], // << Change the tags here
        "credentials": {
          "host": "postgres-svc",
          "port": "5432",
          "user": "slonik",
          "password": "topsekret",
          "database": "cap-ratings",
          "schema": "public"
        }
      }
    ]
  },
  "DEBUG": "ratings-service"
}

That should do the trick.

Cheers,
Sebastian

from cds-pg.

pwasem avatar pwasem commented on June 3, 2024

Addition:

I was in doubt if this could be a connection issue, but

  • host postgres-svc is reachable:
node ➜ /workspaces/cap-ratings $ ping postgres-svc
PING postgres-svc (172.18.0.2) 56(84) bytes of data.
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=1 ttl=64 time=0.080 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=2 ttl=64 time=0.089 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=3 ttl=64 time=0.089 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=4 ttl=64 time=0.122 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=5 ttl=64 time=0.128 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=6 ttl=64 time=0.164 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=7 ttl=64 time=0.091 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=8 ttl=64 time=0.170 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=9 ttl=64 time=0.191 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=10 ttl=64 time=0.189 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=11 ttl=64 time=0.250 ms
64 bytes from cap-infra-postgres-svc-1.cap-network (172.18.0.2): icmp_seq=12 ttl=64 time=0.259 ms
^C
--- postgres-svc ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11223ms
rtt min/avg/max/mdev = 0.080/0.151/0.259/0.059 ms
node ➜ /workspaces/cap-ratings $ npm run deploy   

> [email protected] deploy
> npx cds-pg deploy app --to postgres

[cds.connect] - No service definition found for 'postgres', as required by 'cds.requires.postgres': {
  impl: 'cds-pg',
  model: [ 'app' ],
  credentials: {
    host: 'postgres-svc',
    port: '5432',
    user: 'slonik',
    password: 'topsekret',
    database: 'cap-ratings',
    schema: 'public'
  }
}
(node:2384) UnhandledPromiseRejectionWarning: Error: No service definition found for 'postgres'
    at AsyncFunction.connect.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/connect/index.js:42:11)
    at async Object.to (/workspaces/cap-ratings/node_modules/@sap/cds/lib/deploy.js:21:23)
    at async deploy (/workspaces/cap-ratings/node_modules/cds-pg/bin/cds-pg.js:11:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2384) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2384) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
node ➜ /workspaces/cap-ratings $
  • and postgres 14 is also up and running:

Bildschirmfoto 2021-10-15 um 14 44 51

const { Pool } = require('pg')

const testConnection = async () => {
  const pool = new Pool({
    connectionString: 'postgres://slonik:topsekret@postgres-svc:5432/cap-ratings'
  })
  const { rows: [result] } = await pool.query('SELECT 1 as one')
  console.log(result)
  await pool.end()
}

testConnection()
node ➜ /workspaces/cap-ratings $ node test-connection.js 
{ one: 1 }

So it looks like an issue related to cds.

from cds-pg.

gregorwolf avatar gregorwolf commented on June 3, 2024

Hi @pwasem ,

@vobu, @sjvans and I updated cds-pg today to make it compatible with @sap/cds 5.5. I've tested the change in my pg-beershop project. Please check my adjustments to default-env.json and package.json#L82. Right now this is quite a hack as without this configuration no connection to the db is established. and the dialect "plain" must be passed to the _dialect variable in @sap/cds/libx/_runtime/common/utils/quotingStyles.js.

CU
Gregor

from cds-pg.

sebastianesch avatar sebastianesch commented on June 3, 2024

Hi @pwasem,

The problem is in your default-env.json and in your deployment command.

In your default-env.json make sure to have the tags plain and/or db and in your deploy command you need to follow the example in the cds-pg README: npx cds-pg deploy srv --to db.

CAP merges the requires sections "db" and "postgres" in your package.json and actually forgets the "postgres" service and looks for the "db" service. That's why the deploy command has --to db as a parameter. The "kind" information is also stripped during merging of the configuration values and only the "dialect" is left.

CAP then checks if there is a VCAP service whose name matches the service name (db), whose tag matches the context + ':' + service name (cds:db), whose tag match the dialect or kind (plain and undefined) or whose label matches the dialect or kind. See @sap/cds/lib/env/index.js - function _add_vcap_services_to.

Kind regards,
Sebastian

from cds-pg.

sjvans avatar sjvans commented on June 3, 2024

hi @pwasem @gregorwolf @sebastianesch

regarding the original error, please see https://cap.cloud.sap/docs/advanced/troubleshooting#why-does-the-server-crash-with-no-service-definition-found-for-srv-name

deploy to db bypasses this, because the service name lookup isn’t done for the well-known requires property „db“.

best,
sebastian

from cds-pg.

pwasem avatar pwasem commented on June 3, 2024

Hi @pwasem,

The problem is in your default-env.json and in your deployment command.

In your default-env.json make sure to have the tags plain and/or db and in your deploy command you need to follow the example in the cds-pg README: npx cds-pg deploy srv --to db.

CAP merges the requires sections "db" and "postgres" in your package.json and actually forgets the "postgres" service and looks for the "db" service. That's why the deploy command has --to db as a parameter. The "kind" information is also stripped during merging of the configuration values and only the "dialect" is left.

CAP then checks if there is a VCAP service whose name matches the service name (db), whose tag matches the context + ':' + service name (cds:db), whose tag match the dialect or kind (plain and undefined) or whose label matches the dialect or kind. See @sap/cds/lib/env/index.js - function _add_vcap_services_to.

Kind regards, Sebastian

@sebastianesch

How should the actual default-env.json look in this case?

Thx!

from cds-pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.