How to define a ConnectsTo relationship between service catalogs?
This example shows how to define a relationship for nodecellar (a SOURCE
node) to connect to mongodb (a TARGET
node) as in Figure 1.
- We will define
capabilities
on the mongodb node containing all information for nodecellar node to setup a connection. - We will define the
relationship
interfaces to setup the connection.
Figure 1
Step 1. Define an endpoint capability in the TARGET node (mongodb)
An endpoint capability contains information of a TARGET
node for a SOURCE
node to setup the connection.
In the mongodb component, we define the following capabilities
block:
In this example, we defined a new capability mongo_db
from the TOSCA type tosca.capabilities.Endpoint.Database
. The capability mongo_db
will inherit all default properties from the TOSCA type (e.g., port
, protocol
, url_path
) and show in the editor as in Figure 2.
In the editor, users can specifiy values for the capability mongo_db
. For example, they may set the port
to 27017
.
Figure 2
tip
- The
tosca.capabilities.Endpoint
also has a runtime attributeip_address
(not shown in the Figure). The orchestrator will automatically set the IP address of the hosted compute node to this attribute. ASOURCE
node can use this runtime attribute to setup a connection.
Step 2. Define a requirement in the SOURCE node (nodecellar)
In the nodecellar node, add the following requirements
block:
Step 3: Define the relationship
Define a new relationship otc.relationships.NodejsConnectToMongo
, how nodecellar setups the connection with mongodb:
In the above example, we defined the interface pre_configure_source
by providing a shell script (e.g., set-mongo-url.sh
). The script uses the input parameters DB_IP
, DB_PORT
, NODECELLAR_PORT
to configure nodecellar to connect to mongodb.
note
- Use the function
get_property
to get a SOURCE or TARGET node property. - Use the function
get_attribute
to get a runtime attribute of a SOURCE or TARGET node (e.g., ip_address).
Relationship interfaces:
In addition to the interface pre_configure_source
, we have the following interfaces:
TARGET
node:
Interfaces executed on the pre_configure_target
: executes after theTARGET
node is created.post_configure_target
: executes after theTARGET
node is configured.add_source
: executes onTARGET
node, notifying that theSOURCE
node is up and running.
SOURCE
node:
Interfaces executed on the pre_configure_source
executes after theSOURCE
node is created.post_configure_source
: executes after theSOURCE
node is configured.add_target
: executes after theSOURCE
node is started.remove_target
: executes after theTARGET
node is removed.
note
- The
TARGET
node is always up and running first before theSOURCE
node. - All runtime attributes of the
SOURCE
node are not available until it is up and running (i.e., they are available in theadd_source
interface). Therefore, to configure theTARGET
node with any runtime attributes of theSOURCE
node, you can use theadd_source
interface.
Full example
- See full example