Make networkoffering.conserve_mode not a required parameter for API

Also fix some NPEs
This commit is contained in:
Sheng Yang 2012-01-06 10:36:27 -08:00
parent c7d5e29405
commit aa8bf6c135
3 changed files with 19 additions and 6 deletions

View File

@ -71,7 +71,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed")
private Integer networkRate;
@Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, required = true, description="true if the network offering is IP conserve mode enabled")
@Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled")
private Boolean conserveMode;
@IdentityMapper(entityTableName="disk_offering")
@ -139,6 +139,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
}
public Boolean getConserveMode() {
if (conserveMode == null) {
return true;
}
return conserveMode;
}

View File

@ -743,12 +743,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Set<Service> services = ipToServices.get(ip);
Provider provider = null;
for (Service service : services) {
Provider curProvider = (Provider)serviceToProviders.get(service).toArray()[0];
//We don't support multiply providers for one service now
Set<Provider> curProviders = serviceToProviders.get(service);
if (curProviders == null || curProviders.isEmpty()) {
continue;
}
Provider curProvider = (Provider)curProviders.toArray()[0];
if (provider == null) {
provider = curProvider;
continue;
}
//We don't support multiply providers for one service now
if (!provider.equals(curProvider)) {
throw new CloudRuntimeException("There would be multiply providers for IP " + ip.getAddress() + " with the new network offering!");
}
@ -767,8 +771,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return true;
}
//We only support one provider for one service now
Provider oldProvider = (Provider)serviceToProviders.get((Service)services.toArray()[0]).toArray()[0];
Provider newProvider = (Provider)serviceToProviders.get(service).toArray()[0];
Set<Provider> oldProviders = serviceToProviders.get((Service)services.toArray()[0]);
Provider oldProvider = (Provider)oldProviders.toArray()[0];
//Since IP already has service to bind with, the oldProvider can't be null
Set<Provider> newProviders = serviceToProviders.get(service);
if (newProviders == null || newProviders.isEmpty()) {
throw new CloudRuntimeException("There is no new provider for IP " + publicIp.getAddress() + " of service " + service.getName() + "!");
}
Provider newProvider = (Provider)newProviders.toArray()[0];
if (!oldProvider.equals(newProvider)) {
throw new CloudRuntimeException("There would be multiply providers for IP " + publicIp.getAddress() + "!");
}

View File

@ -259,7 +259,7 @@ CREATE TABLE `cloud`.`network_offerings` (
`system_only` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering for system use only',
`specify_vlan` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Should the user specify vlan',
`service_offering_id` bigint unsigned COMMENT 'service offering id that virtual router is tied to',
`conserve_mode` int(1) unsigned NOT NULL DEFAULT 0 COMMENT 'Is this network offering is IP conserve mode enabled',
`conserve_mode` int(1) unsigned NOT NULL DEFAULT 1 COMMENT 'Is this network offering is IP conserve mode enabled',
`created` datetime NOT NULL COMMENT 'time the entry was created',
`removed` datetime DEFAULT NULL COMMENT 'time the entry was removed',
`default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network offering is default',