Giter Club home page Giter Club logo

cloud-cap-multitenancy's Introduction

REUSE status

Cloud CAP Multitenancy

SAP Cloud Application Programming (CAP) Node.JS sample code project with multitenancy using service manager created HANA containers for tenant data isolation.

Description

This repository contains a complete Multi-Target Application (MTA) sample project that is an example of using the SAP Cloud Application Programming (CAP) approach and it's multitenancy support library to provide true enterprise multitenant application.

There are many disparate pieces of information found throughout the SAP documentation as well as the CAP centric documentation, but it is difficult to bring them together as a cohesive whole. This sample code project provides a good starting point for those wanting to build a best-practice multitenant enterprise application on SAP Business Technology Platform.

This project is implemented completely in the Node.JS programming language. A Java programing language multitenant sample code project can be found in the repository cloud-cap-samples-java. See the Demonstrated Features section of the README.

Branches

There are several branches in this repo and a little context is warranted.

This sample utilizes the CAP multitenancy library (cds-mtx) to handle customer subscriptions which result in the ServiceManager creating run-time HANA hdi-shared containers. In the original master branch this was tested where each subscribing customer would have their own distinct container with no need of joining the customer container with any shared data. If this is your use case, then you'll find this version was saved in the single-container branch which will work with versions of the cds-mtx library < 1.0.27. For use cases where joining per subscriber containers with a singluar common container, a bug was discovered in the library that prevented run-time container deployments upon subscriptions. A work-around is provided in the xcontainer branch that will work with cds-mtx library < 1.0.27. This work-around effectively performs a secondary deploy with the proper environment that accomplishes the desired result. Once a fix was provided in cds-mtx >= 1.0.27, the work-around was no longer needed and the code removed and the fix-things branch was created in order to facilitate testing of the fix. Once the fix was confirmed effective the code was merged back into the master branch.

The master branch going forward implements the use-case where each run-time container will be joined with a "common container"(as defined in the db_comm folder). The cds-mtx >= 1.0.27 will accomodate this use-case.

Requirements

Download and Installation

modules:
- name: capmt-srv
  type: nodejs
  path: srv
...
  properties:
     CF_API_USER: [email protected]
     CF_API_PW: xxxxxx
...
  • OR - after deployment,
  1. Create a file called .env with the following.
CF_API_USER=<Your User>
CF_API_PW=<Your Password>
  1. Run this command to set the ENVIRONMENT with your specifics.
set -o allexport; source .env; set +o allexport
  1. Update the environment for the capmt-srv module in the CF_CDEDS.sh script.
cf set-env capmt-srv CF_API_USER $CF_API_USER
cf set-env capmt-srv CF_API_PW $CF_API_PW
cf restage capmt-srv

Project Structure

File / Folder Purpose
README.md this getting started guide
COMMANDS.md commands for building/deploying
app/ content for UI frontends go here
db/ database definitions go here
documentation/ supplemental documentation
srv/ your service module code goes here
mta.yaml project structure and relationships
package.json project metadata and configuration

Instructions

Replace .hana.demand.com with the landscape region variant for your account.

See the COMMANDS file for commands for building and deploying the project.

Known Issues

This example project contains no known issues.

Limitations

The creation and assignment of Roles to Roll Collections and the assignment of Roll Collections is limited to global accounts with "Feature Set B".

How to obtain support

Create an issue in this repository if you find a bug or have questions about the content.

For additional support, ask a question in SAP Community.

Documentation

See the Multitenancy section under Cookbook in the CAP documentation. Multitanancy

Also the broader public CAP Documentation.

Reporting Problems and Contributing Enhancements

An SAP Code Sample such as this is open software but is not quite a typical full-blown open source project. If you come across a problem, we’d encourage you to check the project’s issue tracker and to file a new issue if needed. If you are especially passionate about something you’d like to improve, you are welcome to fork the repository and submit improvements or changes as a pull request.

To-Do (upcoming changes)

Tools used throughout the development of this project are evolving and my change over time. This may result in discrepancies in the exact procedures or screen-clips in the accompanying blog posts. All efforts will be made to update the content in order to keep pace with the tooling, but cannot be guaranteed.

Learn more...

Learn more in the CAP documentation at CAPIRE.

A blog post discussing this code sample can be found on SAP Community. See: Getting your head into Cloud Application Programming model multitenancy for a detailed discussion.

License

Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

cloud-cap-multitenancy's People

Contributors

ajinkyapatil8190 avatar andrewlunde avatar btbernard avatar ds10x avatar gregorwolf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloud-cap-multitenancy's Issues

How to configure for multiple microservices

Scenarios:

  1. Different microservices with separate codebase
  2. Each service having different table/JSON Docstore

How can we configure this for multiple microservices and is it supporting JSON Docstore collections?

There is no instance for tenant \

Hi Support,

In my dev account, I have @sap/cds-mtx version 2.2.2. I upgraded from 2.02.2 to 2.2.2. After some DB related issues, I performed unsubscription of tenant but when performing subscription again, I'm getting the error eventType is not passed, whereas it is('CREATE') passed in the body.

BR/KR

Use destination instead of environment variables for Cloud Foundry API credentials

HI @andrewlunde,

ask you know I never liked the way how the the credentials for the Cloud Foundry API where provided in this example. I've found now the better solution: Create a destination in the SAP BTP Subaccount with the following configuration:

Screenshot 2021-07-05 at 08 53 52

The destination details can then be read using the getDestination method from @sap-cloud-sdk/core. Then you can either use cf-http-client (which does not yet support all API Endpoints). Or stick with the axios calls.

CU
Gregor

Service "cis" can not be deployed on trial account

Hi,
When deploying the project into my sap trial account. I receive the following error:
Service operation failed: Controller operation failed: 404 Updating service "CAPMT_CIS" failed: Not Found: Error creating service "CAPMT_CIS" from offering "cis" and plan "central": Service plan central not found
I think this is the "Cloud Identity Service" however, in using this sample. I have created a "provider" subaccount along with two other subaccounts (sub1, sub2) in order to become familiar with the whole mta onboarding, etc.
I am unable to transfer this from "trial" to a different subaccount.

Missing dev dependency on sap/cds-dk

Build CDS fails in SAP Web IDE after cloning project in a fresh workspace.

I believe adding this in package.json would be reasonable:

   "devDependencies": {
+    "@sap/cds-dk": "^3",
     "sqlite3": "^4"
   },

Full log output for the Build CDS failure:

7:01:55 PM (git) Project cloud-cap-multitenancy: Git repository cloud-cap-multitenancy: Clone request completed successfully.
7:02:07 PM (CDS build) Start CDS cleanup previous build.
7:02:07 PM (CDS build) Start CDS build execution task.
7:02:07 PM (Executor) The "Building CDS artifacts." process started.
7:02:10 PM (Executor) Starting process: "cd /projects/cloud-cap-multitenancy; export CDS_BUILD_NODEJS_EDMXGENERATION=true; export CDS_BUILD_MODE=inplace; export CDS_BUILD_OUTPUTFILE=.cds_gen.log; export GENERATION_LOG=.cds_gen.log; rm -f copy_back.zip; npm install && npm run build && cat .cds_gen.log | zip -@ copy_back.zip && zip copy_back.zip .cds_gen.log"
7:02:15 PM (Executor) 
7:02:15 PM (Executor) > @sap/[email protected] install /projects/cloud-cap-multitenancy/node_modules/@sap/hana-client
7:02:15 PM (Executor) > node checkbuild.js
7:02:15 PM (Executor) 
7:02:15 PM (Executor) 
7:02:15 PM (Executor) > [email protected] install /projects/cloud-cap-multitenancy/node_modules/sqlite3
7:02:15 PM (Executor) > node-pre-gyp install --fallback-to-build
7:02:15 PM (Executor) 
7:02:15 PM (Executor) node-pre-gyp WARN Using needle for node-pre-gyp https download 
7:02:16 PM (Executor) [sqlite3] Success: "/projects/cloud-cap-multitenancy/node_modules/sqlite3/lib/binding/node-v64-linux-x64/node_sqlite3.node" is installed via remote
7:02:16 PM (Executor) 
7:02:16 PM (Executor) > @sap-cloud-sdk/[email protected] postinstall /projects/cloud-cap-multitenancy/node_modules/@sap-cloud-sdk/core
7:02:16 PM (Executor) > node usage-analytics.js
7:02:16 PM (Executor) 
7:02:16 PM (Executor) added 222 packages from 152 contributors and audited 222 packages in 5.953s
7:02:17 PM (Executor) 
7:02:17 PM (Executor) 4 packages are looking for funding
7:02:17 PM (Executor)   run `npm fund` for details
7:02:17 PM (Executor) 
7:02:17 PM (Executor) found 0 vulnerabilities
7:02:17 PM (Executor) 
7:02:17 PM (Executor) 
7:02:17 PM (Executor) > [email protected] build /projects/cloud-cap-multitenancy
7:02:17 PM (Executor) > cds build/all --clean
7:02:17 PM (Executor) 
7:02:17 PM (Executor) 
7:02:17 PM (Executor)     Unknown command 'build/all'. Install '@sap/cds-dk', then try again:
7:02:17 PM (Executor) 
7:02:17 PM (Executor)       npm i -g @sap/cds-dk
7:02:17 PM (Executor) 
7:02:17 PM (Executor) npm ERR! code ELIFECYCLE
7:02:17 PM (Executor) npm ERR! errno 1
7:02:17 PM (Executor) npm ERR! [email protected] build: `cds build/all --clean`
7:02:17 PM (Executor) npm ERR! Exit status 1
7:02:17 PM (Executor) npm ERR! 
7:02:17 PM (Executor) npm ERR! Failed at the [email protected] build script.
7:02:17 PM (Executor) npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
7:02:17 PM (Executor) 
7:02:17 PM (Executor) npm ERR! A complete log of this run can be found in:
7:02:17 PM (Executor) npm ERR!     /home/user/.npm/_logs/2020-12-02T00_02_18_293Z-debug.log
7:02:17 PM (CDS build) Build of "/cloud-cap-multitenancy" failed.

Instance, but no bindings for tenant

Hi @andrewlunde,

I've followed your instructions in the blogpost but unfortunately as soon as I hit the subscribe button in my consumer subaccount I see the following error messages when running cf logs capmt-srv:

2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR Instance, but no bindings for tenant TENANT-2141b92b-edff-4f81-a778-1f923c369643-META
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR Error: Instance, but no bindings for tenant TENANT-2141b92b-edff-4f81-a778-1f923c369643-META
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap/instance-manager/lib/service-manager/Backend.js:162:10
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap/instance-manager/lib/service-manager/Client.js:92:5
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap/instance-manager/lib/service-manager/Resource.js:147:14
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at /home/vcap/deps/0/node_modules/@sap/instance-manager/lib/service-manager/Resource.js:130:5
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at Request._callback (/home/vcap/deps/0/node_modules/@sap/instance-manager/lib/service-manager/Resource.js:172:7)
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at Request.self.callback (/home/vcap/deps/0/node_modules/request/request.js:185:22)
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at Request.emit (events.js:198:13)
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at Request. (/home/vcap/deps/0/node_modules/request/request.js:1154:10)
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at Request.emit (events.js:198:13)
2020-10-04T17:03:27.75+0200 [APP/PROC/WEB/0] ERR at IncomingMessage. (/home/vcap/deps/0/node_modules/request/request.js:1076:12)

Hope you have a tip for me.

CU
Gregor

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.