From 4ea3aaeb18142e0e152c05e41d67e037d60c058a Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Wed, 9 Nov 2011 18:58:16 -0800 Subject: [PATCH] NaaS: Add checking for gateway service in update network offering --- .../api/response/NetworkOfferingResponse.java | 7 ++++++ .../src/com/cloud/api/ApiResponseHelper.java | 1 + .../ConfigurationManagerImpl.java | 23 ++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/api/src/com/cloud/api/response/NetworkOfferingResponse.java b/api/src/com/cloud/api/response/NetworkOfferingResponse.java index 1d624e6a1a7..c857701d415 100644 --- a/api/src/com/cloud/api/response/NetworkOfferingResponse.java +++ b/api/src/com/cloud/api/response/NetworkOfferingResponse.java @@ -75,6 +75,9 @@ public class NetworkOfferingResponse extends BaseResponse{ @SerializedName(ApiConstants.IS_SHARED) @Param(description="true if soruce NAT service offered is shared by multiple networks", responseObject = ServiceResponse.class) private Boolean isSourceNatShared; + @SerializedName(ApiConstants.REDUNDANT_ROUTER) @Param(description="true if gateway service offered redundant router", responseObject = ServiceResponse.class) + private Boolean isRedundantRouter; + public void setId(Long id) { this.id = id; } @@ -142,4 +145,8 @@ public class NetworkOfferingResponse extends BaseResponse{ public void setIsSourceNatShared(boolean isSourceNatShared) { this.isSourceNatShared = isSourceNatShared; } + + public void setIsRedundantRouter(Boolean isRedundantRouter) { + this.isRedundantRouter = isRedundantRouter; + } } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index ce5ceb81f2c..d3a855c00ec 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -2117,6 +2117,7 @@ public class ApiResponseHelper implements ResponseGenerator { response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId())); response.setIsLBShared(!offering.getDedicatedLB()); response.setIsSourceNatShared(offering.getSharedSourceNat()); + response.setIsRedundantRouter(offering.getRedundantRouter()); if (offering.getGuestType() != null) { response.setGuestIpType(offering.getGuestType().toString()); } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index c51c0780bdc..f28d2a82979 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -3032,7 +3032,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (gwServiceCapabilityMap.keySet().size() > 1 || !gwServiceCapabilityMap.containsKey(Capability.RedundantRouter)) { throw new InvalidParameterValueException("Only redundant router capability can be sepcified for gateway service"); } - String param = gwServiceCapabilityMap.get(Capability.RedundantRouter.getName()); + String param = gwServiceCapabilityMap.get(Capability.RedundantRouter); boolean enabled = param.contains("true"); boolean disabled = param.contains("false"); if (!enabled && !disabled) { @@ -3068,8 +3068,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Map gwServiceCapabilityMap = serviceCapabilityMap.get(Service.Gateway); boolean redundantRouter = false; if ((gwServiceCapabilityMap != null) && (!gwServiceCapabilityMap.isEmpty())) { - String param = gwServiceCapabilityMap.get(Capability.RedundantRouter.getName()); - redundantRouter = param.contains("true"); + String param = gwServiceCapabilityMap.get(Capability.RedundantRouter); + if (param != null) { + redundantRouter = param.contains("true"); + } } NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, maxConnections, isDefault, availability, tags, type, dedicatedLb, sharedSourceNat, redundantRouter); @@ -3439,6 +3441,21 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura } offering.setSharedSourceNat(sharedSourceNat); + // verify the gateway service capabilities specified in the network offering + Map gatewayServiceCapabilityMap = cmd.getServiceCapabilities(Service.Gateway); + boolean redundantRouter = false; + + if (!cmd.getGatewayService() && gatewayServiceCapabilityMap != null && !gatewayServiceCapabilityMap.isEmpty()) { + throw new InvalidParameterValueException("Capabilities for Gateway service can be specifed only when Gateway service is enabled for network offering."); + } + validateGatewayServiceCapablities(gatewayServiceCapabilityMap); + + if ((gatewayServiceCapabilityMap != null) && (!gatewayServiceCapabilityMap.isEmpty())) { + String param = gatewayServiceCapabilityMap.get(Capability.RedundantRouter.getName()); + redundantRouter = param.contains("true"); + } + offering.setRedundantRouter(redundantRouter); + if (svcPrv != null && !svcPrv.isEmpty()) { if (networksExist) { throw new InvalidParameterValueException("Unable to reset service providers as there are existing networks using this network offering");