2. Creating Architecture DAG
Architecture DAG (Directed Acyclic Graph) is an abstract representation of your intended architecture dependency graph. Once you created components and links that represent your architecture DAG there will be no infrastructure provisioned yet. The only thing that will change is the
Installing Torque Packages for Components and Links
Installing packages is a one-time operation that brings desired functionality into the workspace: components, links, and providers that you want to use in creating and evolving your architecture DAG.
In this step, you will install some Torque code packages that contain the definitions for required components and links between components.
Components and links are installed as code that implements certain framework entities. They are abstract types that you can use for constructing an architecture DAG (Directed Acyclic Graph) data structure. You can find more details about these concepts in the Torque Framework Concepts chapter.
Our goal is for you to have a workspace with a load balancer, a backend service, and a PostgreSQL database.
Let’s install the required packages. Currently, you have to manually install all packages that you need since the feature to automatically install all dependent packages is still in the works.
Inside my_workspace directory.
torque package install git+https://github.com/torquetech/torque-basics-pack.git && \
torque package install git+https://github.com/torquetech/torque-hlb-component.git && \
torque package install git+https://github.com/torquetech/torque-postgres-component.git
torque-basics-pack package contains components and links for handling any kind of containerized application services and links between such services. The only requirement for the application code is to have
Again, the added components and links serve the purpose of creating an abstract architecture DAG. We did not install any capability to deploy or run the components and links, just the capability to describe an architecture DAG.
You can easily check which packages we have available inside the workspace:
torque-basics-pack: version: 1, uri: git+https://github.com/torquetech/torque-basics-pack.git
torque-hlb-component: version: 3, uri: git+https://github.com/torquetech/torque-hlb-component.git
torque-postgres-component: version: 3, uri: git+https://github.com/torquetech/torque-postgres-component.git
torque-workspace: version: 2, uri: https://github.com/torquetech/torque-workspace
torque-workspace is a special package that contains the Torque Framework and was installed when the workspace was initialized with
torque init command.
Components are abstract types that you use to create an architecture DAG data structure. They represent application services, where you write your application code, or platform services, like databases, queues, and similar.
Now that you have installed packages, let’s explore what components are available.
torque component list-types
torque.hlb.V1Component: <class 'torque.hlb.V1Component'>
torque.postgres.V1Component: <class 'torque.postgres.V1Component'>
torque.basics.V1Task: <class 'torque.basics.V1Task'>
torque.basics.V1TCPService: <class 'torque.basics.V1TCPService'>
torque.basics.V1HttpService: <class 'torque.basics.V1HttpService'>
You are ready to create components in your Torque workspace. Each component is a node in a DAG that Torque generates based on your design.
torque component create backend_srv torque.basics.V1HttpService -p path=backend_srv -p port=80 && \
torque component create lb torque.hlb.V1Component --no-suffix && \
torque component create db torque.postgres.V1Component --no-suffix
You have created components for a backend service, load balancer, and a PostgreSQL database. The load balancer is necessary if you want to have your services publicly accessible.
These three components are now three nodes in your DAG.
Running these commands created isolated nodes in the architecture DAG. Now you need to create links between them. Here is what we got inside the
Links are also abstract types like components, and are used to create edges that connect nodes in the architecture DAG you are building. Links serve the purpose of active propagation of configuration variables from one component to another.
Here’s how to link the database to the backend service:
torque link create db backend_srv \
--type torque.basics.V1PostgresLink \
-p database=example \
torque link create command tells Torque Framework what instance exposes its services and to where. In the example, framework creates a link between the
db instance and the
backend_srv instance. The additional
--type argument tells the framework to use the
torque.basics.V1PostgresLink link as an intermediary. Links take care of transferring any environment variables and other required information between instances.
To reach these services from the internet, you need to connect them to a load balancer. In this case, you’ll use the
torque link create backend_srv lb \
--type torque.basics.V1IngressLink \
-p path=/backend_srv \
These links instruct the load balancer how to configure the routing table, to define how requests from which URLs or paths should be forwarded to which service.
We can peek into the
.torque/workspace.yaml to see how the links are represented in the DAG:
You created the entire architecture DAG. To do anything with it you’ll need to create a
deployment object, but before that, we need an application code that will actually run the backend service.