VMs / stacks described in a template created and deployed in parallel or serially?

Asked by Lakshminarayanan Renganarayana

Hi,

I am interested in understanding how Heat deploys a template that specifies multiple VMs. For example, consider a template that creates 1 apache vm, 1 tomcat vm, and 1 mysql vm. Will Heat start creating and deploying these three VMs in parallel (i.e., concurrently) or will do it serially (in some order)?

I am also interested in Heat's VM creation scheme, when the template has multiple VMs and there are dependencies between them. For example, consider a dependency between the tomcat vm and the mysql vm, in the above scenario. With such dependencies, will Heat create the VMs in parallel or serially?

I would greatly appreciate any info / pointers (even to the right section of Heat code :-) )

Thanks for your time,
LN

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Heat Edit question
Assignee:
No assignee Edit question
Solved by:
Zane Bitter
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Best Zane Bitter (zaneb) said :
#1

Excellent question.

In the Grizzly (2013.1) version of Heat, VMs will be created serially (in dependency order if dependencies exist). In the current development version of Heat (and in the eventual Havana release) the VMs will be created in parallel provided that they do not have any dependencies on each other.

Dependencies are mostly created automatically. If you use the "Ref" or "Fn::GetAtt" functions within a resource to refer to another resource, then that creates a dependency between them. This generally just works how you would want - e.g. if your Tomcat VM configuration uses {"Fn::GetAtt": ["MySqlVM", "PrivateIp"]} to get the IP address of your MySQL VM, then the Tomcat one will not be created until after the MySQL one has been (and hence it's IP address is known).

You can also add dependency manually, by adding e.g. "DependsOn": "MySqlVM" to the resource definition.

Note, however, that a VM is considered created as soon as Nova has started it. If you want to wait for the guest OS to actually boot and/or for applications to be installed/started then you need to add a WaitCondition resource to your template. In the Instance's UserData script, you post a notification to the URL of the corresponding WaitConditionHandle when everything is ready. The WaitCondition will wait until this notification is received. (The WaitCondition usually "DependsOn" the Instance that is expected to notify it, so that it's timeout period starts only once the VM is created.) You can then mark that another resource "DependsOn" the WaitCondition.

Revision history for this message
Lakshminarayanan Renganarayana (lakshminarayanan-r) said :
#2

Thanks Zane Bitter, that solved my question.

Revision history for this message
Lakshminarayanan Renganarayana (lakshminarayanan-r) said :
#3

Hi Zane,

Thanks very much for the detailed reply.

I have a follow up question regarding when and how Heat determines a dependence is satisfied and hence starts the creation of the dependent resource.

Consider a template that creates two VMs, say vmA and vmB, with the following properties:

-- vmA needs the IP address of vmB and uses a Ref to get that

-- vmB has UserData that installs a lot of applications, after the VM is created.

Now, I assume that Heat will first create vmB and then create vmA. When does the creation of vmA start? After vmB (the base vm) is created, i.e, Nova has started vmB? or After Nova has started vmB AND all its UserData scripts are executed?

I am also interested in looking at the

1. code that analyzes the template for Ref, Fn::GetAtt and builds the dependence graph (I am assuming an explicit dependence graph is built)

2. code that uses the dependence graph to enforce the order of VM creation.

Can you please point me to these parts of the code?

Once again, thanks very much for your time and I greatly appreciate the help.

LN

Revision history for this message
Zane Bitter (zaneb) said :
#4

Sure, no problem :)

vmA will start as soon as Nova has finished building vmB. (And we may modify it in the future to start even sooner - as soon as the call to Nova has completed.) It will not wait for the UserData scripts on vmB to run, or even for vmB to boot.

If you did want to wait for the UserData script to complete, you would use a WaitCondition and signal it at the end of the UserData script, then add a manual dependency on the WaitCondition resource, as described above.

Dependencies for each resource are calculated in the Resource.add_dependencies() method in heat/engine/resource.py. The Stack object gets each of its resources to add its dependencies to the Stack's dependency list in Stack._get_dependencies() in heat/engine/parser.py. The code for the dependency graph itself is in heat/engine/dependencies.py.

The stack creation is called from Stack.create_task(), and the order is enforced by the DependencyTaskGroup in heat/engine/scheduler.py.

https://github.com/openstack/heat/blob/master/heat/engine/parser.py
https://github.com/openstack/heat/blob/master/heat/engine/resource.py
https://github.com/openstack/heat/blob/master/heat/engine/dependencies.py
https://github.com/openstack/heat/blob/master/heat/engine/scheduler.py

Revision history for this message
Lakshminarayanan Renganarayana (lakshminarayanan-r) said :
#5

Hi Zane,

Thank you very much for the clarification and pointers to the code!

Thanks,
LN

Revision history for this message
Lakshminarayanan Renganarayana (lakshminarayanan-r) said :
#6

Thanks Zane Bitter, that solved my question.