VMware {code} Community
AmirB201110141
Contributor
Contributor

AMQP notifications

Hello,

I connect my vcloud-director to an AMQP server and receive notifications (I'm using RabbitMQ server&sdk)

I receive notifcations about staring and completing of tasks (com/vmware/vcloud/event/task/<create/start/complete>)  and the notifications about the "real" operation - for example com/vmware/vcloud/event/vapp/create (creation of vapp).

When I receive the notification of the "real operation" (com/vmware/vcloud/event/vapp/create) does it mean that the operation already finished? (meaning, the notification of vapp/create is sent after the vapp was already created) does it mean the vapp is being created right now?

if in that point of time I can't know for sure that the vapp was already created - then I guess it means I have to wait for the task completion notification (com/vmware/vcloud/event/task/complete), right? if so, how can I match between the complete notification and "real operation" notification? meaning, how can I know that the complete notification is about the vapp/create notification and not for a different operation that was also done in the vcloud?

Is there some shared identifier to all notifications of the "same operation" that I can use to connect between those notifications?

Thank you very much,

Amir

0 Kudos
9 Replies
TimLawrence
Enthusiast
Enthusiast

Hi,

I think for notification messages you would need to check the status on the resulting object (vApp etc) to determine whether creation was succesful.

If you want to get the creation task for vApps then set up blocking tasks for that specific action. You can always just resume the task immediately. This method is alot quieter. I found that when I enabled notifications the AMQP bus got rather busy!

Thanks

Tim

0 Kudos
AmirB201110141
Contributor
Contributor

Thank you for the reply, but I'm not sure I understood.

Example:

When I create a new Vapp I receive few notifications:

"com/vmware/vcloud/event/task/create"

"com/vmware/vcloud/event/task/start"
"com/vmware/vcloud/event/vapp/create"
"com/vmware/vcloud/event/task/complete"

In which point of time can I be sure that the vapp was already created [meaning I can try to retreive its object using the sdk]?

if this is only after the task complete, then how can I match between the complete notification and the vapp/create notification? (how can I know that the task/complete doesn't refer to a different type of task, for example - vapp/modify). Is there some metadata property that is common between those notifications?

Thank you again

0 Kudos
TimLawrence
Enthusiast
Enthusiast

firstly:

Can you confirm if you have "Enable Notifications" set in System -> Administration -> Blocking Tasks -> Settings

Basically, there are 2 ways to use this.

1. you enable notifications (as above) and this will create AMQP messages for almost all tasks that happen in the system. I wouldnt recommend using these unless you have to. the only reason you would have to is if the event you wish to trigger AMQP messageds for can not be configured using blocking tasks (see below)

2. In System -> Administration -> Blocking Tasks you can select events to create blocking tasks for. A "Blocking Task" Is a special type of object which stops a normal vCloud task from continuing until you take some action externally.

Consider the following example:

You want to send a request to an administrator to authorise vApp creation.

to do this you would:

  • Enable blocking tasks for "vApp Lifecycle->Build New vApp"
  • Subscribe to the AMQP routing key vapp/create (or whatever it is)
  • When a vApp is created you will get a link to the blocking task object
  • Fromt he blocking task object you can retrieve the vCloud task object
  • from the vCloud task object you can get the object the task is working on from the "Owner" field (should contain a href)
  • now whislt the task is paused you can call your approval code and once approved/denied you just update the blocking task either with a "Resume" or "Cancel" which in turn either continues or cancels the vApp create task.

basically,

if you want to use notifications:

get AMQP Message for "com/vmware/vcloud/event/task/create" -> Get the task link -> get the Owner link frmo the task

if you want to use blocking tasks:

get AMQP message for vapp/create - > get blocking task link -> get task link from blocking task link -> get owner link from task -> do something -> resume /cancle blocking task

Sorry if that is a little bit wordy but hopefuly it explains a bit.I'm sure that is at lease 50% accurate anyway 🙂

AmirB201110141
Contributor
Contributor

Thank you again for the help.

1. Yes, I have set "Enable notifications" option in  System -> Administration -> Blocking Tasks -> Settings. and I do receive notifications from the vcloud using the AMQP.

2. I don't want to block tasks - I just want to execute some code when things happen in my vcloud.

3. I now understand that I can get the object the "com/vmware/vcloud/event/vapp/create" is working on from the owner link of the task - but, can I know for sure that the vapp is already created? (or that it is just being created right now). can I do "Vapp.GetVappById(m_client, notification.GetEntityLink().id)" right away when I get the "com/vmware/vcloud/event/vapp/create" notification and be sure that It won't throw? (meaning that the creation was already finished).

or do I have to wait for the /task/complete notification to be sure the operation finished?

0 Kudos
TimLawrence
Enthusiast
Enthusiast

You need to get the task object and then wait until completion.

something like

Task = Task.getTaskById(vcx,taskid);

vApp = vApp.getvAppById(vcx,Task.Owner);

while (Task.status != COMPLETED || Task.status != QUEUED)

{

     sleep(3000);

     Log "Task Running";

}

then do something with vApp

kirilk
VMware Employee
VMware Employee

Hi,

I do not have setup of vCD right now in front of me to test all out. So running on memory:

1. To manipulate the vApp please wait for the task completion notification. Ahead of this the vApp is "busy" and cannot be manipulated. The crerate/vapp notification tell you that vCloud has accepted the vApp creation request i.e. the vApp is visible in the inventory (only part f the properties are accessible through the SDK like "name"). Clonning of VMDKs though happens after this. You may want to try putting the vApp in "maintenance" mode after the create notification - this should prevent concurent access , say if you want to customize the vapp post provisioning.

2. On the ID question - yes there is shared id between all of the notifications. The vApp id that is. I believe ti is sent iwht the task notificaitons as well as the regular event notifications.

I hope this helps. Write again if you need more info.

0 Kudos
AmirB201110141
Contributor
Contributor

Thank you very much - it helps a lot.

So now I understand how to determine when operations on the vapp finish, and how to match between the operation and its completion (the completion of the task with the matching taskOwner). But I´m still confused:

for example - I'm creating a new VM inside a vapp. The notifications I receive (by order) and Task's owner (or entityLink which seems to be the same as the Task's owner):

[notification.GetNotificationEventType().Value()  -   notification.GetTaskOwnerLink().id or notification.GetEntityLink().id]

"com/vmware/vcloud/event/vapp/modify" -  "urn:vcloud:vapp:6bf61002-361a-4429-9d38-2d45d46c032b"

"com/vmware/vcloud/event/task/create" - "urn:vcloud:vapp:6bf61002-361a-4429-9d38-2d45d46c032b"
"com/vmware/vcloud/event/task/start" - "urn:vcloud:vapp:6bf61002-361a-4429-9d38-2d45d46c032b"
"com/vmware/vcloud/event/vm/create" - "urn:vcloud:vm:cd06a522-91a8-4e18-ae4f-0c773cb432bc"
"com/vmware/vcloud/event/task/complete" - "urn:vcloud:vapp:6bf61002-361a-4429-9d38-2d45d46c032b"
but again, I'm still confused here - I want to know when the creation of the vm finished (so I can access it and manipulate it), but when I get the vm/create notification I still don't know the all operation of creating it inside the vapp is done. And I don't know how to match between it and the task/complete notification, cause the vm/creation's task-owner is the vm and the task/complete's owner is the vapp.
The issue is of course that there can be lots of other vm-creations inside vapps in the system and I want to know when each of those creations finish (so the heuristics of waiting until a task/complete is received to a general vapp isn't good for me - I want to make sure this task/complete is indeed regarding the vm/create I'm handling).
Thank you for your help.
0 Kudos
rgerganov
VMware Employee
VMware Employee

You can find the corresponding vApp using the REST API.

Let's say that you received notification for VM with ID cd06a522-91a8-4e18-ae4f-0c773cb432bc (this is from your example) and you want to find which vApp it belongs to. Issue the following request:

GET https://your-vcloud-host/api/vApp/vm-cd06a522-91a8-4e18-ae4f-0c773cb432bc

you will get the VM representation which contains a bunch of Link elements:

<?xml version="1.0" encoding="UTF-8"?>
<Vm>

   ...

   <Link .../>
   <Link .../>
   <Link rel="up" type="application/vnd.vmware.vcloud.vApp+xml" href="https://vcd-host/api/vApp/vapp-53206dda-ba47-4712-ad42-9d9d41a7b65d"/>

   ...

</Vm>

The link with rel="up" points to the vApp container.

In general, notification messages expose small set of information and clients are expected to use REST API when they need more information.

Let me know if you have other questions.

0 Kudos
rgerganov
VMware Employee
VMware Employee

@wamatha Your question is not related to the discussion in this thread. Please start a new thread with your question.

The short answer to your question is that vCD doesn't send email notifications when tasks are blocked but AMQP notifications. The latter are retrieved from the AMQP broker that you have configured in vCD.

0 Kudos