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

Conflicts:

	server/src/com/cloud/offerings/NetworkOfferingVO.java
This commit is contained in:
alena 2011-06-09 13:34:50 -07:00
parent b07835c557
commit f06818704b
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

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

View File

@ -2837,6 +2837,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;
@ -2858,6 +2859,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;
@ -319,6 +322,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;
}
@Override
public boolean isRedundantRouterEnabled() {
@ -345,6 +357,7 @@ public class NetworkOfferingVO implements NetworkOffering {
this.vpnService = vpnService;
this.guestType = guestIpType;
this.redundantRouter = isRedundantRouterEnabled;
this.uniqueName = name;
}
/**

View File

@ -37,10 +37,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

@ -53,6 +53,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();
@ -72,10 +73,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);
@ -83,8 +84,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;
}
@ -93,7 +94,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

@ -243,7 +243,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';