Updated code to handle sync of storage policies when importVsphereStoragePolicies API is called multiple times

This commit is contained in:
Harikrishna Patnala 2020-06-05 11:58:57 +05:30
parent a951e5f57f
commit 27e5dfa633
4 changed files with 29 additions and 2 deletions

View File

@ -103,11 +103,19 @@ public class VsphereStoragePolicyVO implements VsphereStoragePolicy {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getUpdateTime() {
return updateTime;
}

View File

@ -20,4 +20,7 @@ import com.cloud.dc.VsphereStoragePolicyVO;
import com.cloud.utils.db.GenericDao;
public interface VsphereStoragePolicyDao extends GenericDao<VsphereStoragePolicyVO, Long> {
public VsphereStoragePolicyVO findByPolicyId(Long zoneId, String policyId);
}

View File

@ -39,7 +39,16 @@ public class VsphereStoragePolicyDaoImpl extends GenericDaoBase<VsphereStoragePo
zoneSearch.done();
policySearch = createSearchBuilder();
policySearch.and("zoneId", policySearch.entity().getZoneId(), SearchCriteria.Op.EQ);
policySearch.and("policyId", policySearch.entity().getPolicyId(), SearchCriteria.Op.EQ);
policySearch.done();
}
@Override
public VsphereStoragePolicyVO findByPolicyId(Long zoneId, String policyId) {
SearchCriteria<VsphereStoragePolicyVO> sc = policySearch.create();
sc.setParameters("zoneId", zoneId);
sc.setParameters("policyId", policyId);
return findOneBy(sc);
}
}

View File

@ -1429,8 +1429,15 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
}
for (PbmProfile storageProfile : storageProfiles) {
VsphereStoragePolicyVO StoragePolicyVO = new VsphereStoragePolicyVO(zoneId, storageProfile.getProfileId().getUniqueId(), storageProfile.getName(), storageProfile.getDescription());
vsphereStoragePolicyDao.persist(StoragePolicyVO);
VsphereStoragePolicyVO storagePolicyVO = vsphereStoragePolicyDao.findByPolicyId(zoneId, storageProfile.getProfileId().getUniqueId());
if (storagePolicyVO == null) {
storagePolicyVO = new VsphereStoragePolicyVO(zoneId, storageProfile.getProfileId().getUniqueId(), storageProfile.getName(), storageProfile.getDescription());
vsphereStoragePolicyDao.persist(storagePolicyVO);
} else {
storagePolicyVO.setDescription(storageProfile.getDescription());
storagePolicyVO.setName(storageProfile.getName());
vsphereStoragePolicyDao.update(storagePolicyVO.getId(), storagePolicyVO);
}
}
List<VsphereStoragePolicyVO> storagePolicies = vsphereStoragePolicyDao.listAll();