Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@sap/instance-manager
Advanced tools
Node.js package for creating and deleting service instances per tenant within an application at runtime.
Node.js package for creating and deleting service instances per tenant within an application at runtime.
This package provides a client for Instance Manager and Service Manager - components that create and delete service instances (via REST API) for a specified key. These components can be used in the context of multitenant applications where the tenant id is the key an instance is associated with.
Multitenancy is a concept for sharing resources between several different and unrelated to each other groups of users called tenants. Example: subscriptions to a commercial cloud application can be sold to two different companies each of which should use the application in isolation from the other one. Customizations are also applied (e.g. different branding, identity providers, database schemas etc.).
A typical application has access to external resources (e.g. a database or messaging) via services. If an application is used by different tenants, then using a separate service instance for each one will improve isolation since service binding provides access to a resource.
With this package a Node.js application can dynamically create and delete service instances per tenant at runtime.
To consume Instance Manager, an instance of a managed service of the desired type is created first and is then bound to the application. Taking HANA database as an example, the managed service is called 'managed-hana'. Its credentials contain HTTP endpoints and credentials only which can later be used by the application for creating and deleting service instances of the desired type for each tenant. All managed instances are of the same plan - the one used during the managed service instance creation (e.g. creating a managed-hana service of plan hdi-shared would mean managing service instances of this plan only).
To consume Service Manager, an instance of the service-manager service, container plan should be created. Its credentials contain parameters that are used at runtime to manage service instances. Instances of any available service and plan can be managed with a single instance of Service Manager. The application specifies which service and plan to be used by the library.
var createInstanceManager = require('@sap/instance-manager').create;
var options = { /* properties from service binding */ };
createInstanceManager(options, function (err, instanceManager) {
if (err) {
return console.log('Create instance manager error:', err.message);
}
var optionalParameters = {
/* Optional JSON object containing service-specific configuration parameters */
"provisioning_parameters": { "<key>" : "<key>" },
"binding_parameters": {"<key>" : "<value>"}
};
instanceManager.create('my-tenant', optionalParameters, function (err, instance) {
if (err) {
return console.log('Create error:', err.message);
}
// consume instance.credentials
console.log(instance);
instanceManager.get('my-tenant', function (err, instance) {
if (err) {
return console.log('Get error:', err.message);
}
// same instance
console.log(instance);
instanceManager.delete('my-tenant', function (err) {
if (err) {
return console.log('Delete error:', err.message);
}
console.log('Instance deleted');
});
});
});
});
The following properties are provided in the credentials of the Instance Manager service binding.
Property | Mandatory | Details |
---|---|---|
user | x | User for authentication. |
password | x | Password for the user. |
post_managed_instance_url | x | REST endpoint used for creating a new service instance for a tenant. |
get_managed_instance_url | x | REST endpoint used for getting the details about a specific tenant service instance. |
get_all_managed_instances_url | x | REST endpoint used for getting the details about all instances (for all tenants). |
delete_managed_instance_url | x | REST endpoint used for deletion of a service instance. |
Note: A managed service binding contains all the mandatory properties mentioned above.
Property | Mandatory | Details |
---|---|---|
sm_url | x | URL of Service Manager. |
url | x | URL of UAA server from which to fetch tokens which will be send to Service Manager. |
clientid | x | Used when retrieving a token. |
clientsecret | x | Used when retrieving a token. |
service | Defaults to 'hana'. Name of the service of which to manage instances. | |
plan | Defaults to 'hdi-shared'. Name of a plan from the selected service of which to manage instances. |
Note: A service-manager binding contains all the mandatory properties mentioned above.
The create and delete operations are executed asynchronously on server side. To provide an easier interface, this library also implements polling until an operation is finished. Developers can tune polling via some optional properties.
Since operations involve network activity (thus, can be considered relatively slow) the package also caches the created instances. Cache options can also be provided by developers.
Property | Details |
---|---|
polling_interval_millis | Defaults to 300. States how many milliseconds to wait between requests in the polling phase. |
polling_timeout_seconds | Defaults to 120. Sets a limit for time (in seconds) that can be spent in polling. |
cache_max_items | Defaults to 500. States the capacity of the cache. |
cache_item_expire_seconds | Defaults to 600 (10 minutes). Number of seconds after which a cache entry expires. |
Note: It is recommended to have a single instance manager JavaScript object per managed service bound to the application.
Note: Due to details in regard to consuming Service Manager (more communication with the service is required), applications currently using Instance Manager may need to increase the value of the polling_timeout_seconds setting.
create(tenant, optionalParameters, callback)
- creates a service instance for the provided tenant.
The method polls until the instance is successfully created and then invokes the callback.
Reports an error having a statusCode
property with value of 409
if an instance for this tenant already exists.
create-service
and bind-service
for unmanaged services. E.g.{
"provisioning_parameters": { "database_id" : "<HANA Tenant DB Guid or Name>" },
"binding_parameters": {"<key>" : "<value>"}
}
Note: With Service Manager the properties provided on the managed instance are a subset (label
, plan
, tags
, credentials
, tenant_id
and status
) of the properties provided on it when using Instance Manager.
get(tenant, callback)
- gets the corresponding instance for the provided tenant either from cache or from server.
Value of null
means that a service instance for this tenant does not exist.
Note: In Instance Manager case this method only polls if the instance is in status CREATION_IN_PROGRESS
.
In all other cases it returns the service instance as it is on server.
Thus, having the credentials
property on the instance
object in the callback is not guaranteed.
In Service Manager case if the managed instance is not ready to be used, the method returns an error.
getAll(callback)
- gets the instances for all tenants as an array of objects. This method updates the cache.
Note: In Instance Manager case filtering of the instances according to their status (e.g. CREATION_SUCCEEDED
, CREATION_IN_PROGRESS
) does not take place. Thus, having the credentials
property on each of the instances provided in the callback is not guaranteed. In Service Manager case only ready to be used managed instances are returned.
delete(tenant, callback)
- deletes service instance for the provided tenant.
The method polls until the instance is successfully deleted and then invokes the callback.
Reports an error having a statusCode
property with value of 404
if an instance for this tenant does not exist.
When the callback of a method is invoked with an error which is caused by an unexpected HTTP response code
received from the server, then this error object will have a statusCode
property with the value of the HTTP status code.
One can enable debug logs of this package via adding instance-manager to the DEBUG
environment variable.
FAQs
Node.js package for creating and deleting service instances per tenant within an application at runtime.
The npm package @sap/instance-manager receives a total of 3,077 weekly downloads. As such, @sap/instance-manager popularity was classified as popular.
We found that @sap/instance-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.