diff --git a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java index 9b900ad939c..abd5da22595 100644 --- a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java +++ b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java @@ -34,6 +34,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.naming.ConfigurationException; @@ -1440,6 +1441,13 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw } } + List allStoragePolicies = vsphereStoragePolicyDao.listAll(); + List finalStorageProfiles = storageProfiles; + List needToMarkRemoved = allStoragePolicies.stream() + .filter(existingPolicy -> finalStorageProfiles.stream() + .anyMatch(storageProfile -> !storageProfile.getProfileId().equals(existingPolicy.getPolicyId()))) + .collect(Collectors.toList()); + List storagePolicies = vsphereStoragePolicyDao.listAll(); return storagePolicies; } diff --git a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/PbmProfileManagerMO.java b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/PbmProfileManagerMO.java index 557f350cf8e..fc2d7d131d6 100644 --- a/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/PbmProfileManagerMO.java +++ b/vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/PbmProfileManagerMO.java @@ -19,7 +19,9 @@ package com.cloud.hypervisor.vmware.mo; import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.utils.exception.CloudRuntimeException; +import com.vmware.pbm.PbmCapabilityProfile; import com.vmware.pbm.PbmProfile; +import com.vmware.pbm.PbmProfileCategoryEnum; import com.vmware.pbm.PbmProfileId; import com.vmware.pbm.PbmProfileResourceType; import com.vmware.pbm.PbmProfileResourceTypeEnum; @@ -29,6 +31,7 @@ import org.apache.log4j.Logger; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; public class PbmProfileManagerMO extends BaseMO { @@ -57,20 +60,28 @@ public class PbmProfileManagerMO extends BaseMO { public List getStorageProfiles() throws Exception { List profileIds = getStorageProfileIds(); List profiles = _context.getPbmService().pbmRetrieveContent(_mor, profileIds); - return profiles; + + List requirementCategoryProfiles = profiles.stream() + .filter(x -> ((PbmCapabilityProfile)x).getProfileCategory().equals(PbmProfileCategoryEnum.REQUIREMENT)) + .collect(Collectors.toList()); + return requirementCategoryProfiles; } public PbmProfile getStorageProfile(String storageProfileId) throws Exception { List profileIds = getStorageProfileIds(); - for (PbmProfileId profileId : profileIds) { - if (storageProfileId.equals(profileId.getUniqueId())) { - List profile = _context.getPbmService().pbmRetrieveContent(_mor, Collections.singletonList(profileId)); - return profile.get(0); - } + + PbmProfileId profileId = profileIds.stream() + .filter(x -> x.getUniqueId().equals(storageProfileId)) + .findFirst().orElse(null); + + if (profileId == null) { + String errMsg = String.format("Storage profile with id %s not found", storageProfileId); + s_logger.debug(errMsg); + throw new CloudRuntimeException(errMsg); } - String errMsg = String.format("Storage profile with id %s not found", storageProfileId); - s_logger.debug(errMsg); - throw new CloudRuntimeException(errMsg); + + List profile = _context.getPbmService().pbmRetrieveContent(_mor, Collections.singletonList(profileId)); + return profile.get(0); } private PbmProfileResourceType getStorageResourceType() {