Revert "bug 10199: don't allow network offering Name modification."

This reverts commit 97f2b9936a8b9e3a057116d327b058253458b4ef.

Use the following solution instead:

* add unique_name field to the network_offerings table. Use this filed as a unique offering identifier in the code
* Added db upgrade steps to 225to226 sql script
This commit is contained in:
alena 2011-06-09 11:33:30 -07:00
parent 880ea1fe3f
commit 2ae3b4e609
8 changed files with 43 additions and 9 deletions

View File

@ -41,6 +41,9 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the network offering")
private Long id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the network offering")
private String networkOfferingName;
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the network offering")
private String displayText;
@ -52,7 +55,10 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getNetworkOfferingName() {
return networkOfferingName;
}
public String getDisplayText() {
return displayText;
}

View File

@ -97,4 +97,6 @@ public interface NetworkOffering {
boolean isDhcpService();
GuestIpType getGuestType();
String getUniqueName();
}

View File

@ -2771,6 +2771,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
public NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd) {
String displayText = cmd.getDisplayText();
Long id = cmd.getId();
String name = cmd.getNetworkOfferingName();
String availabilityStr = cmd.getAvailability();
Availability availability = null;
@ -2792,6 +2793,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
if (name != null) {
offering.setName(name);
}
if (displayText != null) {
offering.setDisplayText(displayText);
}

View File

@ -45,6 +45,9 @@ public class NetworkOfferingVO implements NetworkOffering {
@Column(name="name")
String name;
@Column(name="unique_name")
private String uniqueName;
@Column(name="display_text")
String displayText;
@ -304,6 +307,15 @@ public class NetworkOfferingVO implements NetworkOffering {
public void setGuestType(GuestIpType guestType) {
this.guestType = guestType;
}
@Override
public String getUniqueName() {
return uniqueName;
}
public void setUniqueName(String uniqueName) {
this.uniqueName = uniqueName;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean dhcpService, boolean dnsService, boolean userDataService, boolean gatewayService, boolean firewallService, boolean lbService, boolean vpnService, GuestIpType guestIpType) {
this.name = name;
@ -324,6 +336,7 @@ public class NetworkOfferingVO implements NetworkOffering {
this.lbService = lbService;
this.vpnService = vpnService;
this.guestType = guestIpType;
this.uniqueName = name;
}
/**

View File

@ -19,10 +19,10 @@ import com.cloud.utils.db.GenericDao;
public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long> {
/**
* Returns the network offering that matches the name.
* @param name name
* @param uniqueName name
* @return NetworkOfferingVO
*/
NetworkOfferingVO findByName(String name);
NetworkOfferingVO findByUniqueName(String uniqueName);
/**
* Persists the system network offering by checking the name. If it

View File

@ -35,6 +35,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.and("uniqueName", NameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
NameSearch.done();
SystemOfferingSearch = createSearchBuilder();
@ -54,10 +55,10 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
}
@Override
public NetworkOfferingVO findByName(String name) {
public NetworkOfferingVO findByUniqueName(String uniqueName) {
SearchCriteria<NetworkOfferingVO> sc = NameSearch.create();
sc.setParameters("name", name);
sc.setParameters("uniqueName", uniqueName);
return findOneBy(sc);
@ -65,8 +66,8 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
@Override
public NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering) {
assert offering.getName() != null : "how are you going to find this later if you don't set it?";
NetworkOfferingVO vo = findByName(offering.getName());
assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
NetworkOfferingVO vo = findByUniqueName(offering.getUniqueName());
if (vo != null) {
return vo;
}
@ -75,7 +76,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
return vo;
} catch (EntityExistsException e) {
// Assume it's conflict on unique name from two different management servers.
return findByName(offering.getName());
return findByUniqueName(offering.getName());
}
}

View File

@ -241,7 +241,8 @@ CREATE TABLE `cloud`.`nics` (
CREATE TABLE `cloud`.`network_offerings` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
`name` varchar(64) NOT NULL unique COMMENT 'network offering',
`name` varchar(64) NOT NULL COMMENT 'name of the network offering',
`unique_name` varchar(64) NOT NULL UNIQUE COMMENT 'unique name of the network offering',
`display_text` varchar(255) NOT NULL COMMENT 'text to display to users',
`nw_rate` smallint unsigned COMMENT 'network rate throttle mbits/s',
`mc_rate` smallint unsigned COMMENT 'mcast rate throttle mbits/s',

View File

@ -4,4 +4,10 @@
ALTER TABLE `cloud`.`storage_pool` MODIFY `host_address` varchar(255) NOT NULL;
ALTER TABLE `cloud`.`network_offerings` MODIFY `name` varchar(64) NOT NULL COMMENT 'name of the network offering';
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `unique_name` varchar(64) NOT NULL COMMENT 'unique name of the network offering';
UPDATE `cloud`.`network_offerings` SET unique_name=name;
ALTER TABLE `cloud`.`network_offerings` MODIFY `unique_name` varchar(64) NOT NULL UNIQUE COMMENT 'unique name of the network offering';