mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
bug 10538: avoid duplicated config values insertion when multiple management servers start at the same time
status 10538: resolved fixed
This commit is contained in:
parent
da179d7f46
commit
9b54b8761a
@ -69,4 +69,6 @@ public interface ConfigurationDao extends GenericDao<ConfigurationVO, String> {
|
||||
boolean isPremium();
|
||||
|
||||
ConfigurationVO findByName(String name);
|
||||
|
||||
ConfigurationVO persistConfigValue(ConfigurationVO config);
|
||||
}
|
||||
|
||||
@ -26,10 +26,12 @@ import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import javax.persistence.EntityExistsException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
@ -194,5 +196,18 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
SearchCriteria<ConfigurationVO> sc = NameSearch.create();
|
||||
sc.setParameters("name", name);
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationVO persistConfigValue(ConfigurationVO config) {
|
||||
ConfigurationVO vo = findByName(config.getName());
|
||||
if (vo != null) {
|
||||
return vo;
|
||||
}
|
||||
try {
|
||||
return persist(config);
|
||||
} catch (EntityExistsException e) {
|
||||
return findByName(config.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,8 +27,6 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -169,9 +167,9 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
createServiceOffering(User.UID_SYSTEM, "Small Instance", 1, 512, 500, "Small Instance, $0.05 per hour", false, false, null);
|
||||
createServiceOffering(User.UID_SYSTEM, "Medium Instance", 1, 1024, 1000, "Medium Instance, $0.10 per hour", false, false, null);
|
||||
// Save default disk offerings
|
||||
createDiskOffering(null, "Small", "Small Disk, 5 GB", 5, null);
|
||||
createDiskOffering(null, "Medium", "Medium Disk, 20 GB", 20, null);
|
||||
createDiskOffering(null, "Large", "Large Disk, 100 GB", 100, null);
|
||||
createdefaultDiskOffering(null, "Small", "Small Disk, 5 GB", 5, null);
|
||||
createdefaultDiskOffering(null, "Medium", "Medium Disk, 20 GB", 20, null);
|
||||
createdefaultDiskOffering(null, "Large", "Large Disk, 100 GB", 100, null);
|
||||
|
||||
// Save the mount parent to the configuration table
|
||||
String mountParent = getMountParent();
|
||||
@ -757,24 +755,23 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
return pod;
|
||||
}
|
||||
|
||||
private DiskOfferingVO createDiskOffering(Long domainId, String name, String description, int numGibibytes, String tags) {
|
||||
private DiskOfferingVO createdefaultDiskOffering(Long domainId, String name, String description, int numGibibytes, String tags) {
|
||||
long diskSize = numGibibytes;
|
||||
diskSize = diskSize * 1024 * 1024 * 1024;
|
||||
tags = cleanupTags(tags);
|
||||
|
||||
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags,false);
|
||||
return _diskOfferingDao.persist(newDiskOffering);
|
||||
newDiskOffering.setUniqueName("Cloud.Com-" + name);
|
||||
newDiskOffering = _diskOfferingDao.persistDeafultDiskOffering(newDiskOffering);
|
||||
return newDiskOffering;
|
||||
}
|
||||
|
||||
private ServiceOfferingVO createServiceOffering(long userId, String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, String tags) {
|
||||
tags = cleanupTags(tags);
|
||||
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, offerHA, displayText, localStorageRequired, false, tags, false, null, false);
|
||||
|
||||
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
|
||||
return offering;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
offering.setUniqueName("Cloud.Com-" + name);
|
||||
offering = _serviceOfferingDao.persistSystemServiceOffering(offering);
|
||||
return offering;
|
||||
}
|
||||
|
||||
private String cleanupTags(String tags) {
|
||||
|
||||
@ -31,5 +31,6 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
|
||||
ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
|
||||
List<ServiceOfferingVO> findPublicServiceOfferings();
|
||||
List<ServiceOfferingVO> findServiceOfferingByDomainId(Long domainId);
|
||||
List<ServiceOfferingVO> findSystemOffering(Long domainId, Boolean isSystem, String vm_type);
|
||||
List<ServiceOfferingVO> findSystemOffering(Long domainId, Boolean isSystem, String vm_type);
|
||||
ServiceOfferingVO persistDeafultServiceOffering(ServiceOfferingVO offering);
|
||||
}
|
||||
|
||||
@ -126,5 +126,20 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
|
||||
SearchCriteria<ServiceOfferingVO> sc = PublicServiceOfferingSearch.create();
|
||||
sc.setParameters("system", false);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public ServiceOfferingVO persistDeafultServiceOffering(ServiceOfferingVO offering) {
|
||||
assert offering.getUniqueName() != null : "unique name should be set for the service offering";
|
||||
ServiceOfferingVO vo = findByName(offering.getUniqueName());
|
||||
if (vo != null) {
|
||||
return vo;
|
||||
}
|
||||
try {
|
||||
return persist(offering);
|
||||
} catch (EntityExistsException e) {
|
||||
// Assume it's conflict on unique name
|
||||
return findByName(offering.getUniqueName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,5 +27,7 @@ public interface DiskOfferingDao extends GenericDao<DiskOfferingVO, Long> {
|
||||
List<DiskOfferingVO> listByDomainId(long domainId);
|
||||
List<DiskOfferingVO> findPrivateDiskOffering();
|
||||
List<DiskOfferingVO> findPublicDiskOfferings();
|
||||
DiskOfferingVO findByUniqueName(String uniqueName);
|
||||
DiskOfferingVO persistDeafultDiskOffering(DiskOfferingVO offering);
|
||||
|
||||
}
|
||||
|
||||
@ -21,10 +21,10 @@ package com.cloud.storage.dao;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.persistence.EntityExistsException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.DiskOfferingVO.Type;
|
||||
import com.cloud.utils.db.Attribute;
|
||||
@ -41,6 +41,7 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
||||
private final SearchBuilder<DiskOfferingVO> DomainIdSearch;
|
||||
private final SearchBuilder<DiskOfferingVO> PrivateDiskOfferingSearch;
|
||||
private final SearchBuilder<DiskOfferingVO> PublicDiskOfferingSearch;
|
||||
protected final SearchBuilder<DiskOfferingVO> UniqueNameSearch;
|
||||
private final Attribute _typeAttr;
|
||||
|
||||
protected DiskOfferingDaoImpl() {
|
||||
@ -57,6 +58,10 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
||||
PublicDiskOfferingSearch.and("system", PublicDiskOfferingSearch.entity().getSystemUse(), SearchCriteria.Op.EQ);
|
||||
PublicDiskOfferingSearch.done();
|
||||
|
||||
UniqueNameSearch = createSearchBuilder();
|
||||
UniqueNameSearch.and("name", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
|
||||
UniqueNameSearch.done();
|
||||
|
||||
_typeAttr = _allAttributes.get("type");
|
||||
}
|
||||
|
||||
@ -105,5 +110,32 @@ public class DiskOfferingDaoImpl extends GenericDaoBase<DiskOfferingVO, Long> im
|
||||
SearchCriteria<DiskOfferingVO> sc = PublicDiskOfferingSearch.create();
|
||||
sc.setParameters("system", false);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO findByUniqueName(String uniqueName) {
|
||||
SearchCriteria<DiskOfferingVO> sc = UniqueNameSearch.create();
|
||||
sc.setParameters("name", uniqueName);
|
||||
List<DiskOfferingVO> vos = search(sc, null, null, false);
|
||||
if (vos.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return vos.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO persistDeafultDiskOffering(DiskOfferingVO offering) {
|
||||
assert offering.getUniqueName() != null : "unique name shouldn't be null for the disk offering";
|
||||
DiskOfferingVO vo = findByUniqueName(offering.getUniqueName());
|
||||
if (vo != null) {
|
||||
return vo;
|
||||
}
|
||||
try {
|
||||
return persist(offering);
|
||||
} catch (EntityExistsException e) {
|
||||
// Assume it's conflict on unique name
|
||||
return findByUniqueName(offering.getUniqueName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user