VMware {code} Community
haiqicun
Contributor
Contributor

vSphere SDK createScheduledTask problems in java

Hi,

I am trying to use vsphere sdk 6 to create scheduled task to unmap datastore, here is the code:

sc: ServiceContent

hostStorageSystem: HostStorageSystem

vmfsUuid: String (the vmfsUuid of a specific datastore)

ManagedObjectReference scheduledTaskManager = sc.getScheduledTaskManager();  // get the scheduledTaskManager

//set methodAction
MethodAction methodAction = new MethodAction();

methodAction.setName("UnmapVmfsVolumeEx_Task");

List<MethodActionArgument> arguments = methodAction.getArgument();

MethodActionArgument arg0 = new MethodActionArgument();

MethodActionArgument arg1 = new MethodActionArgument();

List<String> uuidList = new ArrayList<String>();    

uuidList.add(vmfsUuid);

arg0.setValue(uuidList);

arguments.add(arg0);

//set taskScheduler
OnceTaskScheduler taskScheduler = new OnceTaskScheduler();

//set scheduledTaskSpec

ScheduledTaskSpec taskSpec = new ScheduledTaskInfo();

taskSpec.setName("ScheduledUnmapTask");

taskSpec.setDescription("scheduled task to unmap a datastore");

taskSpec.setEnabled(true);

taskSpec.setAction(methodAction);

taskSpec.setScheduler(taskScheduler);

  _vimPort.createObjectScheduledTask(scheduledTaskManager, hostStorageSystem, taskSpec);

for the unmapVmfsVolumEx_task, I need to pass the a list containing vmfsuuids. But there are problem with arraylist type.

Anyone can help to solve the problem. Not sure whether there are other problems of the above code.

Tags (1)
Reply
0 Kudos
1 Reply
doskiran
Enthusiast
Enthusiast

I didn't see any issue in the above code, try the below steps which i follow and worked for me.

Add all  vmfsUuid into MethodActionArgument[] array and convert the array into vector and then add to the MethodAction arguments list.

MethodAction methodAction = new MethodAction();

MethodActionArgument[] arguments = new MethodActionArgument[3];

for (int i = 0; i < arguments.length; i++) {

            MethodActionArgument argument = new MethodActionArgument();

            argument.setValue(vmfsUuid[i]);

            arguments[i] = argument;

}

methodAction .getArgument().clear();

//conver "arguments" to vector and add to "methodAction " arguments.

methodAction .getArgument().addAll(arrayToVector(arguments))

Reply
0 Kudos