Skip to content

Commit ff7294d

Browse files
committed
continue retrieving method added
1 parent 73a2156 commit ff7294d

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,8 @@ public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
16341634
s_logger.error(msg);
16351635
throw new InvalidParameterValueException(msg);
16361636
}
1637-
List<UnmanagedInstanceTO> instances = dcMo.getVmsOnDatacenter(maxObjects, nextPage);
1637+
List<UnmanagedInstanceTO> instances = java.util.Collections.synchronizedList(new ArrayList());
1638+
instances.addAll(dcMo.getVmsOnDatacenter(maxObjects, null).second());
16381639
return StringUtils.isBlank(keyword) ? instances :
16391640
instances.stream().filter(x -> x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
16401641
} catch (Exception e) {
@@ -1697,7 +1698,7 @@ private void startTemplateCleanJobSchedule() {
16971698
}
16981699

16991700
/**
1700-
* This task is to cleanup templates from primary storage that are otherwise not cleaned by the {@link com.cloud.storage.StorageManagerImpl.StorageGarbageCollector}.
1701+
* This task is to clean-up templates from primary storage that are otherwise not cleaned by the {@link com.cloud.storage.StorageManagerImpl.StorageGarbageCollector}.
17011702
* it is called at regular intervals when storage.template.cleanup.enabled == true
17021703
* It collect all templates that
17031704
* - are deleted from cloudstack

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/DatacenterMO.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323

2424
import com.cloud.hypervisor.vmware.util.VmwareHelper;
25+
import com.cloud.utils.StringUtils;
2526
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
2627
import org.apache.commons.collections.CollectionUtils;
2728
import org.apache.log4j.Logger;
@@ -40,6 +41,9 @@
4041
import com.vmware.vim25.TraversalSpec;
4142
import com.vmware.vim25.VirtualEthernetCardDistributedVirtualPortBackingInfo;
4243
import com.vmware.vim25.RetrieveOptions;
44+
import com.vmware.vim25.RetrieveResult;
45+
import com.vmware.vim25.InvalidPropertyFaultMsg;
46+
import com.vmware.vim25.RuntimeFaultFaultMsg;
4347

4448
import com.cloud.hypervisor.vmware.util.VmwareContext;
4549
import com.cloud.utils.Pair;
@@ -162,9 +166,11 @@ public VirtualMachineMO checkIfVmAlreadyExistsInVcenter(String vmNameOnVcenter,
162166
return null;
163167
}
164168

165-
public List<UnmanagedInstanceTO> getVmsOnDatacenter(Integer maxObjects, boolean nextPage) throws Exception {
169+
public Pair<String, List<UnmanagedInstanceTO>> getVmsOnDatacenter(Integer maxObjects, String token) throws Exception {
166170
List<UnmanagedInstanceTO> vms = new ArrayList<>();
167-
List<ObjectContent> ocs = getVmPropertiesOnDatacenterVmFolder(new String[] {"name"}, maxObjects, nextPage);
171+
Pair<String, List<ObjectContent>> objectContents = getVmPropertiesOnDatacenterVmFolder(new String[] {"name"}, maxObjects, token);
172+
Pair<String, List<UnmanagedInstanceTO>> retval = new Pair<>(objectContents.first(), vms);
173+
List<ObjectContent> ocs = objectContents.second();
168174
if (ocs != null) {
169175
for (ObjectContent oc : ocs) {
170176
ManagedObjectReference vmMor = oc.getObj();
@@ -183,7 +189,7 @@ public List<UnmanagedInstanceTO> getVmsOnDatacenter(Integer maxObjects, boolean
183189
}
184190
}
185191

186-
return vms;
192+
return retval;
187193
}
188194

189195
public List<HostMO> getAllHostsOnDatacenter() throws Exception {
@@ -311,19 +317,32 @@ public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyP
311317

312318
}
313319

314-
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws Exception {
315-
return getVmPropertiesOnDatacenterVmFolder(propertyPaths, null, false);
320+
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
321+
return getVmPropertiesOnDatacenterVmFolder(propertyPaths, null, null).second();
316322
}
317323

318324
/**
319325
*
320326
* @param propertyPaths Vmware side property names to query, for instance {"name"}
321327
* @param maxObjects the number of objects to retrieve
322-
* @param nextPage restart the query or continue a previous query
328+
* @param tokenForPriorQuery restart the query or continue a previous query
323329
* @return The propertyPaths requested for the objects of type "VirtualMachine" in a list are found/returned by the DC
324330
* @throws Exception generic {code}Exception{code} as thrown by Vmware.
325331
*/
326-
public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths, Integer maxObjects, boolean nextPage) throws Exception {
332+
public Pair<String, List<ObjectContent>> getVmPropertiesOnDatacenterVmFolder(String[] propertyPaths, Integer maxObjects, String tokenForPriorQuery) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
333+
if(StringUtils.isNotBlank(tokenForPriorQuery)) {
334+
return retrieveNextSetOfPropertiesOnDatacenterVmFolder(tokenForPriorQuery);
335+
} else {
336+
return retrieveNextSetOfPropertiesOnDatacenterVmFolder(propertyPaths, maxObjects);
337+
}
338+
}
339+
340+
private Pair<String, List<ObjectContent>> retrieveNextSetOfPropertiesOnDatacenterVmFolder(String tokenForPriorQuery) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
341+
RetrieveResult result = _context.getService().continueRetrievePropertiesEx(_context.getPropertyCollector(), tokenForPriorQuery);
342+
return createReturnObjectPair(result);
343+
}
344+
345+
private Pair<String, List<ObjectContent>> retrieveNextSetOfPropertiesOnDatacenterVmFolder(String[] propertyPaths, Integer maxObjects) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
327346
PropertySpec pSpec = new PropertySpec();
328347
pSpec.setType("VirtualMachine");
329348
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
@@ -355,11 +374,18 @@ public List<ObjectContent> getVmPropertiesOnDatacenterVmFolder(String[] property
355374
pfSpecArr.add(pfSpec);
356375

357376
RetrieveOptions ro = new RetrieveOptions();
358-
if(maxObjects != null && maxObjects > 0) {
377+
if (maxObjects != null && maxObjects > 0) {
359378
ro.setMaxObjects(maxObjects);
360379
}
361380

362-
return _context.getService().retrievePropertiesEx(_context.getPropertyCollector(), pfSpecArr, ro).getObjects();
381+
RetrieveResult result = _context.getService().retrievePropertiesEx(_context.getPropertyCollector(), pfSpecArr, ro);
382+
return createReturnObjectPair(result);
383+
}
384+
385+
private static Pair<String, List<ObjectContent>> createReturnObjectPair(RetrieveResult result) {
386+
String tokenForRetrievingNewResults = result.getToken();
387+
List<ObjectContent> listOfObjects = result.getObjects();
388+
return new Pair<>(tokenForRetrievingNewResults, listOfObjects);
363389
}
364390

365391
public static Pair<DatacenterMO, String> getOwnerDatacenter(VmwareContext context, ManagedObjectReference morEntity) throws Exception {

0 commit comments

Comments
 (0)