Internal Lb: added 2 boolean fields - internal_lb and public_lb - to the network offering. Define if internal or public LB service is supported. In the current release it's either one or another; in the future releases we might support both on the same network

This commit is contained in:
Alena Prokharchyk 2013-04-16 11:04:22 -07:00
parent 014689e45e
commit b7709b89ff
10 changed files with 106 additions and 43 deletions

View File

@ -124,6 +124,8 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
boolean getIsPersistent();
Map getDetails();
boolean getInternalLb();
boolean getPublicLb();
}

View File

@ -229,6 +229,7 @@ import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcOffering;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Detail;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.org.Cluster;
@ -2227,7 +2228,10 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setServices(serviceResponses);
//set network offering details
response.setDetails(_ntwkModel.getNtwkOffDetails(offering.getId()));
Map<Detail, String> details = _ntwkModel.getNtwkOffDetails(offering.getId());
if (details != null && !details.isEmpty()) {
response.setDetails(details);
}
response.setObjectName("networkoffering");
return response;

View File

@ -3371,18 +3371,20 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
Map<NetworkOffering.Detail, String> details = new HashMap<NetworkOffering.Detail, String>();
for (String detailStr : detailsStr.keySet()) {
NetworkOffering.Detail offDetail = null;
for (NetworkOffering.Detail supportedDetail: NetworkOffering.Detail.values()) {
if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
offDetail = supportedDetail;
break;
if (detailsStr != null) {
for (String detailStr : detailsStr.keySet()) {
NetworkOffering.Detail offDetail = null;
for (NetworkOffering.Detail supportedDetail: NetworkOffering.Detail.values()) {
if (detailStr.equalsIgnoreCase(supportedDetail.toString())) {
offDetail = supportedDetail;
break;
}
}
if (offDetail == null) {
throw new InvalidParameterValueException("Unsupported detail " + detailStr);
}
details.put(offDetail, detailsStr.get(detailStr));
}
if (offDetail == null) {
throw new InvalidParameterValueException("Unsupported detail " + detailStr);
}
details.put(offDetail, detailsStr.get(detailStr));
}
return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false,
@ -3415,8 +3417,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
if (!enabled && !disabled) {
throw new InvalidParameterValueException("Unknown specified value for " + Capability.InlineMode.getName());
}
} else if (cap == Capability.LbSchemes) {
boolean internalLb = value.contains("internal");
boolean publicLb = value.contains("public");
if (!internalLb && !publicLb) {
throw new InvalidParameterValueException("Unknown specified value for " + Capability.LbSchemes.getName());
}
} else {
throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() + ", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName() + " capabilities can be sepcified for LB service");
throw new InvalidParameterValueException("Only " + Capability.SupportedLBIsolation.getName() +
", " + Capability.ElasticLb.getName() + ", " + Capability.InlineMode.getName()
+ ", " + Capability.LbSchemes.getName() + " capabilities can be sepcified for LB service");
}
}
}
@ -3542,6 +3552,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
boolean elasticIp = false;
boolean associatePublicIp = false;
boolean inline = false;
boolean publicLb = false;
boolean internalLb = false;
if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) {
Map<Capability, String> lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb);
@ -3566,6 +3578,18 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
} else {
inline = false;
}
String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes);
if (serviceProviderMap.containsKey(Service.Lb)) {
if (publicLbStr != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr);
internalLb = publicLbStr.contains("internal");
publicLb = publicLbStr.contains("public");
} else {
//if not specified, default public lb to true
publicLb = true;
}
}
}
Map<Capability, String> sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat);
@ -3600,7 +3624,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan,
networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb,
sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp);
sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, internalLb);
if (serviceOfferingId != null) {
offering.setServiceOfferingId(serviceOfferingId);

View File

@ -56,4 +56,6 @@ public interface LoadBalancingRulesManager extends LoadBalancingRulesService {
boolean validateLbRule(LoadBalancingRule lbRule);
void removeLBRule(LoadBalancer rule);
void isLbServiceSupportedInNetwork(long networkId, Scheme scheme);
}

View File

@ -2068,7 +2068,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
return dstList;
}
protected void isLbServiceSupportedInNetwork(long networkId, Scheme scheme) {
@Override
public void isLbServiceSupportedInNetwork(long networkId, Scheme scheme) {
Network network = _networkDao.findById(networkId);
//1) Check if the LB service is supported
@ -2079,7 +2080,19 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
throw ex;
}
//2) Check if the provider supports the scheme
//2) Check if the Scheme is supported\
NetworkOffering off = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
if (scheme == Scheme.Public) {
if (!off.getPublicLb()) {
throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
}
} else {
if (!off.getInternalLb()) {
throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
}
}
//3) Check if the provider supports the scheme
LoadBalancingServiceProvider lbProvider = _networkMgr.getLoadBalancingProviderForNetwork(network, scheme);
if (lbProvider == null) {
throw new InvalidParameterValueException("Lb rule with scheme " + scheme.toString() + " is not supported by lb providers in network " + network);

View File

@ -17,7 +17,6 @@
package com.cloud.offerings;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import javax.persistence.Column;
@ -28,7 +27,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.cloud.network.Network;
import com.cloud.network.Networks.TrafficType;
@ -137,8 +135,11 @@ public class NetworkOfferingVO implements NetworkOffering {
return displayText;
}
@Transient
Map details;
@Column(name = "internal_lb")
boolean internalLb;
@Column(name = "public_lb")
boolean publicLb;
@Override
public long getId() {
@ -275,7 +276,7 @@ public class NetworkOfferingVO implements NetworkOffering {
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent) {
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean specifyIpRanges, boolean isPersistent, boolean internalLb, boolean publicLb) {
this.name = name;
this.displayText = displayText;
this.rateMbps = rateMbps;
@ -299,12 +300,14 @@ public class NetworkOfferingVO implements NetworkOffering {
this.inline = false;
this.specifyIpRanges = specifyIpRanges;
this.isPersistent=isPersistent;
this.publicLb = publicLb;
this.internalLb = internalLb;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, boolean isDefault,
Availability availability, String tags, Network.GuestType guestType, boolean conserveMode, boolean dedicatedLb, boolean sharedSourceNat, boolean redundantRouter, boolean elasticIp, boolean elasticLb,
boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent);
boolean specifyIpRanges, boolean inline, boolean isPersistent, boolean associatePublicIP, boolean publicLb, boolean internalLb) {
this(name, displayText, trafficType, systemOnly, specifyVlan, rateMbps, multicastRateMbps, isDefault, availability, tags, guestType, conserveMode, specifyIpRanges, isPersistent, internalLb, publicLb);
this.dedicatedLB = dedicatedLb;
this.sharedSourceNat = sharedSourceNat;
this.redundantRouter = redundantRouter;
@ -326,13 +329,13 @@ public class NetworkOfferingVO implements NetworkOffering {
* TODO
*/
public NetworkOfferingVO(String name, TrafficType trafficType, boolean specifyIpRanges) {
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false);
this(name, "System Offering for " + name, trafficType, true, false, 0, 0, true, Availability.Required, null, null, true, specifyIpRanges, false, false, false);
this.state = State.Enabled;
}
public NetworkOfferingVO(String name, Network.GuestType guestType) {
this(name, "System Offering for " + name, TrafficType.Guest, true, true, 0, 0, true, Availability.Optional,
null, Network.GuestType.Isolated, true, false, false);
null, Network.GuestType.Isolated, true, false, false, false, false);
this.state = State.Enabled;
}
@ -400,9 +403,15 @@ public class NetworkOfferingVO implements NetworkOffering {
public boolean getIsPersistent() {
return isPersistent;
}
public Map getDetails() {
return this.details;
@Override
public boolean getInternalLb() {
return internalLb;
}
@Override
public boolean getPublicLb() {
return publicLb;
}
}

View File

@ -939,7 +939,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Shared Security group enabled networks",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true, true, false);
null, Network.GuestType.Shared, true, true, false, false, false);
defaultSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedSGNetworkOffering);
@ -956,7 +956,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Shared networks",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true, true, false);
null, Network.GuestType.Shared, true, true, false, false, false);
defaultSharedNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultSharedNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultSharedNetworkOffering);
@ -973,7 +973,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Isolated networks with Source Nat service enabled",
TrafficType.Guest,
false, false, null, null, true, Availability.Required,
null, Network.GuestType.Isolated, true, false, false);
null, Network.GuestType.Isolated, true, false, false, false, true);
defaultIsolatedSourceNatEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultIsolatedSourceNatEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedSourceNatEnabledNetworkOffering);
@ -991,7 +991,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Isolated networks with no Source Nat service",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Isolated, true, true, false);
null, Network.GuestType.Isolated, true, true, false, false, false);
defaultIsolatedEnabledNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultIsolatedEnabledNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultIsolatedEnabledNetworkOffering);
@ -1008,7 +1008,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Shared networks with Elastic IP and Elastic LB capabilities",
TrafficType.Guest,
false, true, null, null, true, Availability.Optional,
null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true);
null, Network.GuestType.Shared, true, false, false, false, true, true, true, false, false, true, true, false);
defaultNetscalerNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultNetscalerNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetscalerNetworkOffering);
@ -1025,7 +1025,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Isolated Vpc networks with Source Nat service enabled",
TrafficType.Guest,
false, false, null, null, true, Availability.Optional,
null, Network.GuestType.Isolated, false, false, false);
null, Network.GuestType.Isolated, false, false, false, false, true);
defaultNetworkOfferingForVpcNetworks.setState(NetworkOffering.State.Enabled);
defaultNetworkOfferingForVpcNetworks = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworks);
@ -1055,7 +1055,7 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
"Offering for Isolated Vpc networks with Source Nat service enabled and LB service Disabled",
TrafficType.Guest,
false, false, null, null, true, Availability.Optional,
null, Network.GuestType.Isolated, false, false, false);
null, Network.GuestType.Isolated, false, false, false, false, false);
defaultNetworkOfferingForVpcNetworksNoLB.setState(NetworkOffering.State.Enabled);
defaultNetworkOfferingForVpcNetworksNoLB = _networkOfferingDao.persistDefaultNetworkOffering(defaultNetworkOfferingForVpcNetworksNoLB);

View File

@ -126,19 +126,24 @@ public class ApplicationLoadBalancerManagerImpl extends ManagerBase implements A
//1) Validate LB rule's parameters
validateLbRule(sourcePort, instancePort, algorithm, guestNtwk, scheme);
//2) Get source ip address
//2) verify that lb service is supported by the network
_lbMgr.isLbServiceSupportedInNetwork(guestNtwk.getId(), scheme);
//3) Get source ip address
sourceIp = getSourceIp(scheme, sourceIpNtwk, sourceIp);
ApplicationLoadBalancerRuleVO newRule = new ApplicationLoadBalancerRuleVO(name, description, sourcePort, instancePort, algorithm, guestNtwk.getId(),
lbOwner.getId(), lbOwner.getDomainId(), new Ip(sourceIp), sourceIpNtwk.getId(), scheme);
//3) Validate Load Balancing rule on the providers
//4) Validate Load Balancing rule on the providers
LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(),
new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), new Ip(sourceIp));
if (!_lbMgr.validateLbRule(loadBalancing)) {
throw new InvalidParameterValueException("LB service provider cannot support this rule");
}
//4) Persist Load Balancer rule
return persistLbRule(newRule, sourceIp, guestNtwk);

View File

@ -101,28 +101,28 @@ public class MockNetworkOfferingDaoImpl extends NetworkOfferingDaoImpl implement
if (id.longValue() == 1) {
//network offering valid for vpc
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false, false);
Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
} else if (id.longValue() == 2) {
//invalid offering - source nat is not included
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false, false);
Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
} else if (id.longValue() == 3) {
//network offering invalid for vpc (conserve mode off)
vo = new NetworkOfferingVO("non vpc", "non vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, true, false, false);
Availability.Optional, null, Network.GuestType.Isolated, true, false, false, false, false);
} else if (id.longValue() == 4) {
//network offering invalid for vpc (Shared)
vo = new NetworkOfferingVO("non vpc", "non vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Shared, false, false, false);
Availability.Optional, null, Network.GuestType.Shared, false, false, false, false, false);
} else if (id.longValue() == 5) {
//network offering invalid for vpc (has redundant router)
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false, false);
Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
vo.setRedundantRouter(true);
} else if (id.longValue() == 6) {
//network offering invalid for vpc (has lb service)
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false, false);
Availability.Optional, null, Network.GuestType.Isolated, false, false, false, false, false);
}
if (vo != null) {

View File

@ -852,3 +852,7 @@ ALTER TABLE `cloud`.`ntwk_service_map` DROP INDEX `network_id`;
ALTER TABLE `cloud`.`ntwk_service_map` ADD UNIQUE `network_id` (`network_id`,`service`,`provider`);
ALTER TABLE `cloud`.`ntwk_service_map` ADD CONSTRAINT `fk_ntwk_service_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE;
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `internal_lb` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering supports Internal lb service';
ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `public_lb` int(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true if the network offering supports Public lb service';
UPDATE `cloud`.`network_offerings` SET public_lb=1 where id IN (SELECT DISTINCT network_offering_id FROM `cloud`.`ntwk_offering_service_map` WHERE service='Lb');