How to define a ConnectsTo relationship between two software components?

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.

A topology with nodecellar connects to mongodb on a compute node

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:

type: tosca.capabilities.Endpoint.Database

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 portto 27017.

Figure 2

  • The tosca.capabilities.Endpoint also has a runtime attribute ip_address (not shown in the Figure). The orchestrator will automatically set the IP address of the hosted compute node to this attribute. A SOURCE 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:

derived_from: tosca.nodes.WebApplication
- mongo_db:
# nodecellar requires a node that has the capability Endpoint.Database
capability: tosca.capabilities.Endpoint.Database
# nodecellar uses this relationship to setup the connection (see step 3)
relationship: otc.relationships.NodejsConnectToMongo
# (Optional) specifiy relationship instance one-to-one
# it means, one nodecellar has one mongodb
occurrences: [1, 1]

Step 3: Define the relationship

Define a new relationship otc.relationships.NodejsConnectToMongo, how nodecellar setups the connection with mongodb:

derived_from: tosca.relationships.ConnectsTo
# The input DB_IP gets the runtime attribute ip_address of mongodb
DB_IP: { get_attribute: [TARGET, mongo_db, ip_address] }
# The input DB_PORT gets the mongodb port property
DB_PORT: { get_property: [TARGET, port] }
# The input NODECELLAR_PORT gets the nodecellar port property
NODECELLAR_PORT: {get_property: [SOURCE, port]}
implementation: scripts/

In the above example, we defined the interface pre_configure_source by providing a shell script (e.g., The script uses the input parameters DB_IP, DB_PORT, NODECELLAR_PORT to configure nodecellar to connect to mongodb.

  • 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 to control a relationship between two nodes:

Interfaces executed on the SOURCE node:

  • pre_configure_source is executed after the SOURCE node is created, and before it is configured.

  • post_configure_source: executes after the SOURCE node is configured, and before it starts.

  • add_target: executes after the TARGET node is started.

  • remove_target: executes after the TARGET node is removed.

  • target_changed: executes whenever the TARGET node changes.

Interfaces executed on the TARGET node:

  • pre_configure_target: executes after the TARGET node is created, and before it is configured.
  • post_configure_target: executes after the TARGET node is configured, and before it starts.

Full example