cap-js-community / odata-v2-adapter

OData V2 adapter for CDS. Exposes a full-fledged OData V2 service, converting OData V2 requests to CDS OData V4 service calls and responses back.
https://www.npmjs.com/package/@cap-js-community/odata-v2-adapter
Apache License 2.0
25 stars 10 forks source link

multitenant streamlined MTX side-car setup - reading isExtended from undefined #28

Closed geert-janklaps closed 11 months ago

geert-janklaps commented 11 months ago

Hi,

We've added the OData V2 adapter to our multitenant application, which is using the out-of-the box setup for multitenancy using a side-car.

We're using the default profile with-mtx-sidecar and the cds.xt.ModelProviderService is configured as "from-sidecar". (full standard setup)

When deploying the application to Cloud Foundry, accessing any metadata document fails. This is because the cds.xt.ModelProviderService is not running in the local project, but is configured as a remote service.

It looks like the current framework is expecting the MPS service to be running locally, since this is not the case, the request fails. (mps = undefined)

image

{
   "level":"error",
   "logger":"cov2ap",
   "component_type":"application",
   "correlation_id":"20547aad-668c-4231-745a-d53a51fe3fa4",
   "tenant_id":"ae6cb8c9-bcc9-4471-8672-57ece9769589",
   "msg":"MetadataRequest: TypeError: Cannot read properties of undefined (reading 'isExtended')\n at /home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:950:18\n at callCached (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:1044:22)\n at getTenantMetadataStreamlined (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:949:30)\n at getMetadata (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:884:26)\n at /home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:387:29\n at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)\n at next (/home/vcap/app/node_modules/express/lib/router/route.js:144:13)\n at Route.dispatch (/home/vcap/app/node_modules/express/lib/router/route.js:114:3)\n at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)\n at /home/vcap/app/node_modules/express/lib/router/index.js:284:15",
   "layer":"cds",
}

We're using the latest versions of the libraries involved:

Result of "cds env get requires --profile production":

{
   "middlewares":true,
   "auth":{
      "strategy":"xsuaa",
      "kind":"xsuaa",
      "vcap":{
         "label":"xsuaa"
      }
   },
   "db":{
      "impl":"@sap/cds/libx/_runtime/hana/Service.js",
      "kind":"hana",
      "deploy-format":"hdbtable",
      "vcap":{
         "label":"service-manager"
      },
      "credentials":{
         "database":"db.sqlite"
      }
   },
   "cds.xt.SaasProvisioningService":false,
   "cds.xt.DeploymentService":false,
   "cds.xt.ExtensibilityService":false,
   "c4c":{
      "impl":"srv/C4cRemoteService",
      "external":true,
      "kind":"odata-v2",
      "model":"srv/external/c4c",
      "credentials":{
         "destination":"c4codataapi",
         "forwardAuthToken":true
      }
   },
   "approuter":{
      "kind":"cloudfoundry"
   },
   "multitenancy":{
      "model":[
         "@sap/cds-mtxs/srv/bootstrap"
      ],
      "kind":"saas-registry",
      "t0":"t0"
   },
   "extensibility":{
      "model":[
         "@sap/cds-mtxs/srv/bootstrap",
         "@sap/cds-mtxs/db/extensions"
      ],
      "tenantCheckInterval":10000
   },
   "toggles":{
      "model":[
         "@sap/cds-mtxs/srv/bootstrap"
      ]
   },
   "cds.xt.ModelProviderService":{
      "impl":"@sap/cds/libx/_runtime/remote/Service.js",
      "external":true,
      "kind":"rest",
      "model":"@sap/cds-mtxs/srv/model-provider"
   }
}

Is this a bug or am I missing some configuration? Looking into the documentation I didn't seem to find any specifics for a side-car setup for the streamlined mtx library. (only for a remote setup for the old MTX library)

Best regards, Geert-Jan

oklemenz2 commented 11 months ago

Thanks for reporting this issue. Yes, this seems to be a limitation currently. It's only working when cds.xt.ModelProviderService is running locally.

So your scenario is not supported out-of-the-box currently.

I check, how this can be supported in near future. Stay tuned...

geert-janklaps commented 11 months ago

Great, to see this is going to be added in the near future! Do you by any chance have an idea of an availability date that you're aiming for?

To give some context, we're in the process of going live with this partner solution we're creating and the OData V2 adapter is one of the crucial parts for one of the apps. (using a hierarchy tree in SAPUI5, which currently only supports OData V2) Just to keep this in mind for our go-live plan (maybe postpone the delivery of the impacted app).

oklemenz2 commented 11 months ago

Thanks for letting me know. I have an alignment meeting with MTX colleagues for this topic today. Depending on that I can give more information. But I hope, that I can provide a solution within the next weeks. Stay tuned.

oklemenz2 commented 11 months ago

We discuss the problem, and need further information about your configuration of CDS requires in package.json. Is there an explicit configuration of ModelProviderService? Because in your effective env we see this:

 "cds.xt.ModelProviderService":{
      "impl":"@sap/cds/libx/_runtime/remote/Service.js",
      "external":true,
      "kind":"rest",
      "model":"@sap/cds-mtxs/srv/model-provider"
   }

In general the following configuration should be enough in package.json cds section:

"cds": {
  "profile": "with-mtx-sidecar"
  "requires": {
    "multitenancy": true
  }
}

Especially cds.xt.ModelProviderService: "from-sidecar" is not required. "from-sidecar" is deprecated anyways and should not be used anymore.

oklemenz2 commented 11 months ago

In any case, I will fix, that mps is checked before access, so that the request will not crash...

geert-janklaps commented 11 months ago

I think the from-side car part is the reason why there is an explicit configuration for the cds.xt.ModelProviderService. When removing it, there's no explicit configuration anymore.

The good news seems to be that removing the 'from-sidecar' preset seems to fix the OData V2 adapter issue. I'm now perfectly able to get a metadata document without the previous error.

I must have missed the deprecation of 'from-sidecar' or is not communicated yet? Looking at the CAP documentation, it's still mentioned in the CAP documentation without any deprecation warning so it seems. (https://cap.cloud.sap/docs/guides/extensibility/feature-toggles#add-remote-service-link-to-sidecar)

oklemenz2 commented 11 months ago

Good to hear that it works for you now. You're right, it's officially documented. I talked to the colleagues, and they said the usage is discouraged and that from-sidecar is planned to be deprecated in future. I was mistaken here. But in principle the same result: "from-sidecar" should not be used. Thanks.