const createInstanceManager = require('@sap/instance-manager');
const xsenv = require('@sap/xsenv');
const hanaClient = require('@sap/hana-client');
const smCredentials = xsenv.getServices({
sm: {name: 'es-sm'},
});
let options = smCredentials.sm;
// to search for HDI-Containers created under service manager
options = Object.assign(options, {service: 'hana', plan: 'hdi-shared'});
/**
* Returns HDI connection Object
* @param {string} tenantId - tenant id
* @param {object} logger - logger object
* @returns {Object} - HDI connection Object
*/
const getHDICredentials = async (tenantId, logger) => {
console.log(tenantId);
return new Promise((resolve, reject) => {
try {
createInstanceManager.create(options, (err, instanceManager) => {
if (err) {
logger.error('Error in getting Connection Manager', err);
reject(err);
} else {
instanceManager.get(tenantId, (err1, credentials) => {
try {
if (err1) {
logger.error('Error in getting Connection Credentials', err1);
reject(err1);
} else {
if (credentials) {
const conn = hanaClient.createConnection();
conn.connect(credentials.credentials, (err2) => {
if (err2) {
logger.error('Error in connecting to HDI container', err2);
reject(err2);
} else {
logger.info(`HDI connection established for tenant ${tenantId}`);
console.timeEnd('connectionpool');
conn.exec(`SET SCHEMA ${credentials.credentials.schema}`, (err3, result)=>{
if (err3) {
logger.error('Error in setting schema', err3);
reject(err3);
} else {
resolve(conn);
}
});
}
});
} else {
reject(new Error(`No credentials found for tenant:: ${tenantId}`));
}
}
} catch (e) {
reject(e);
}
});
}
});
} catch (error) {
logger.error('Error in getting Connection Manager', error);
reject(error);
}
});
};
Here we will see how to use SAP Cloud SDK to access S/4HANA System from the subscriber subaccount. The connection uses a connectivity service and destination service to fetch data from the on-premise system and destination service in case it is a Cloud System.
const {businessPartnerService} = require('@sap/cloud-sdk-op-vdm-business-partner-service');
const {businessPartnerApi} = businessPartnerService();
/**
* Get Business Partner
* @param {string} token JWT TOKEN with tenant ID to isolate tenant specific Destinations
* @return {Promise<any>}
*/
const getBusinessPartner = async (token) => {
// TODO: filter for identifying new business partners
const resultPromise = await businessPartnerApi.requestBuilder().getAll().filter(businessPartnerApi.schema.SEARCH_TERM_1.equals(`${process.env.searchTerm}`))
.execute({destinationName: 'bupa', jwt: token}, {useCache: true});
return resultPromise;
};
execute()
and getDestination()
methods of the SAP Cloud SDK. The destination caching is disabled by default and you switch it on by the useCache
flag:.execute({ destinationName: 'myDestination', jwt: 'yourJWT', useCache: true })
Tenant
: The destination is cached for a tenant and different users will hit the same cache entry.TenantUser
: The destination is cached separately for each user of a tenant.Tenant
and the value for the tenant is the provider account.user_id
: Isolation is set to Tenant
and the value for the tenant is the zid
of the JWT.user_id
: Isolation is set to TenantUser
and values are taken from zid
and user_id
.Develop a multitenant Software as a Service application in SAP BTP using CAP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
11 | |
11 | |
10 | |
10 | |
9 | |
8 | |
7 | |
7 | |
6 |