mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Updated code to handle sync of storage policies when importVsphereStoragePolicies API is called multiple times
This commit is contained in:
parent
a951e5f57f
commit
27e5dfa633
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user