VMware {code} Community
sam2000
Contributor
Contributor

Task object related problem

Hi,

I am using VI SDK 2.5 with C#.net. I have three operations executing in sequence:

PowerOffVM_Task

PowerOnVM_Task

SuspendVM_Task

They operate on the same VM whose initial power state is Enabled (PoweredOn). For Vmware, they are asynchronous operations. But for my code, I have blocked (synch operations) them so that they will execute one after other. For blocking each task, I am checking the task object's "info.state"

property. Unless it gets completed, I loop over it after 1 sec sleep.

The 1st operation executes successfully showing me the progress in percentage (I get percentage using Task ManagedObjectReference). The 2nd operation, using Task MOR, shows me that the task has completed. The 3rd operation shows me error "Another task in progress". So for 1st task, I didn't face any issue. Lets come to 2nd and 3rd task.

I debugged and was quick enough to see in Vmware Infrastructure Client window that even though the 2nd task was in progress, Vmware SDK returned me it as completed. Due to this, my 3rd task began and clashed with 2nd task, which is already running. Hence, it gave me error on 3rd task "Another task in progress".

Is anyone aware of such unexpected behaviour of Vmware SDK or am I missing something?

Any clue appreciated.

Regards,

Sam

Reply
0 Kudos
10 Replies
Steve_Jin
Expert
Expert

That is interesting, becuase VI Client should rely on the same Task object to track the progress. Do you want to share your code snippet? Also your target(VC/ESX) and version. Thanks!

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
sam2000
Contributor
Contributor

It is difficult for me to share the code as it is shared over multiple files and multiple functions. We are using ESXi server update-2.

Reply
0 Kudos
Steve_Jin
Expert
Expert

Understand. How about a small test code? As you described, it shouldn't take much time.

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
sam2000
Contributor
Contributor

Thanks for the quick reply. Give me some time to prepare the code. I will post the code in some time.

Regards,

Sam

Reply
0 Kudos
sam2000
Contributor
Contributor

I have created this snippet of code for you reference. Please check it and let me know the problem. Please ignore minute mistakes as I have written it in hurry.

Regards,

Sam

Reply
0 Kudos
Steve_Jin
Expert
Expert

You are quick coder! From browsing the code, it seems OK to me. I don't have VS on my home computer so it's hard to try it out.

To find out whether it's an issue of the server, I think I can write several lines of code in Java and you can run it again your ESXi target. Do you want to do that?

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
Reply
0 Kudos
sam2000
Contributor
Contributor

Yes, sure please send me the equivalent java code to run all 3 operations one after the other. I'll run it here.

Thanks,

Sam

Reply
0 Kudos
Steve_Jin
Expert
Expert

import java.net.URL;

import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.Task;
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.util.MorUtil;

public class TestVmOps 
{
 public static void main(String[] args) throws Exception
 {

  String url = args[0];
  String username = args[1];
  String password = args[2];

  ServiceInstance si = new ServiceInstance(new URL(url), username, password, true);

  ManagedObjectReference vmMor = new ManagedObjectReference();
  vmMor.setType("VirtualMachine");
  vmMor.set_value("576"); //change to a valid mor value in your environment

  VirtualMachine vm = (VirtualMachine)MorUtil.createExactManagedEntity(si.getServerConnection(), vmMor);

  Task task = vm.powerOffVM_Task();
  task.waitForMe();

  task = vm.powerOnVM_Task(null);
  task.waitForMe();

  task = vm.suspendVM_Task();
  task.waitForMe();
 }
}

To run the code, you need to download the VI Java API 2.0 runtime from the link below. Please let me know how it goes. Also here is a tutorial on setting up VI Java API with Eclipse:

Steve JIN, VMware Engineering

Creator of VMware Infrastructure Java API. VI Java API 2.0 --- 15 times faster than AXIS in loading, 4+ faster in deserialization; only 1/4 of the size required by AXIS. More importantly, the freedom to redistribute your applications. (Download, Samples, DocWiki, RSS Feed)

Get Connected with Other Developers in the Community?

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
sam2000
Contributor
Contributor

Hi Steve,

Thanks for the code. As I have some other tasks queued up, I will try to run this code after those tasks. I will post a reply as soon as I am able to get it run.

Regards,

Sam

Reply
0 Kudos
sam2000
Contributor
Contributor

Hi Steve,

I am trying to download from URL:

http://sourceforge.net/project/showfiles.php?group_id=228007&package_id=308982&release_id=666495

Unfortunately, my company has blocked this website (it has blocked download of freewares/sharewares). So I am trying to compile java axis samples that come with vmware. But as I am newbie in java, I am getting too many framework related errors. Trying to solve that.

After solving those, I will modify the VmPowerOps.java file to run 3 operations in sequence and test that.

Thanks,

Sam

Reply
0 Kudos