|
22 | 22 | import java.util.Map; |
23 | 23 |
|
24 | 24 | import javax.ejb.Local; |
| 25 | +import javax.naming.ConfigurationException; |
25 | 26 |
|
26 | 27 | import org.apache.log4j.Logger; |
27 | 28 |
|
28 | | -import com.cloud.configuration.ConfigurationManager; |
29 | | -import com.cloud.dc.DataCenter; |
| 29 | +import com.cloud.api.commands.CreateLoadBalancerRuleCmd; |
| 30 | +import com.cloud.configuration.Config; |
| 31 | +import com.cloud.configuration.dao.ConfigurationDao; |
| 32 | +import com.cloud.dc.Vlan.VlanType; |
30 | 33 | import com.cloud.deploy.DeployDestination; |
31 | 34 | import com.cloud.exception.ConcurrentOperationException; |
| 35 | +import com.cloud.exception.InsufficientAddressCapacityException; |
32 | 36 | import com.cloud.exception.InsufficientCapacityException; |
33 | 37 | import com.cloud.exception.ResourceUnavailableException; |
34 | 38 | import com.cloud.network.Network; |
35 | | -import com.cloud.network.NetworkManager; |
| 39 | +import com.cloud.network.NetworkVO; |
36 | 40 | import com.cloud.network.Network.Capability; |
| 41 | +import com.cloud.network.Network.GuestIpType; |
37 | 42 | import com.cloud.network.Network.Provider; |
38 | 43 | import com.cloud.network.Network.Service; |
| 44 | +import com.cloud.network.NetworkManager; |
39 | 45 | import com.cloud.network.Networks.TrafficType; |
40 | 46 | import com.cloud.network.PublicIpAddress; |
| 47 | +import com.cloud.network.addr.PublicIp; |
| 48 | +import com.cloud.network.dao.NetworkDao; |
41 | 49 | import com.cloud.network.lb.ElasticLoadBalancerManager; |
| 50 | +import com.cloud.network.lb.LoadBalancerElement; |
42 | 51 | import com.cloud.network.rules.FirewallRule; |
43 | 52 | import com.cloud.offering.NetworkOffering; |
| 53 | +import com.cloud.offerings.NetworkOfferingVO; |
| 54 | +import com.cloud.offerings.dao.NetworkOfferingDao; |
| 55 | +import com.cloud.user.Account; |
44 | 56 | import com.cloud.utils.component.AdapterBase; |
45 | 57 | import com.cloud.utils.component.Inject; |
46 | 58 | import com.cloud.vm.NicProfile; |
|
53 | 65 | public class ElasticLoadBalancerElement extends AdapterBase implements NetworkElement{ |
54 | 66 | private static final Logger s_logger = Logger.getLogger(ElasticLoadBalancerElement.class); |
55 | 67 | private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); |
56 | | - @Inject ConfigurationManager _configMgr; |
57 | 68 | @Inject NetworkManager _networkManager; |
58 | 69 | @Inject ElasticLoadBalancerManager _lbMgr; |
| 70 | + @Inject ConfigurationDao _configDao; |
| 71 | + @Inject NetworkOfferingDao _networkOfferingDao; |
| 72 | + @Inject NetworkDao _networksDao; |
| 73 | + |
| 74 | + boolean _enabled; |
| 75 | + TrafficType _frontEndTrafficType = TrafficType.Guest; |
59 | 76 |
|
60 | 77 | private boolean canHandle(Network network) { |
61 | | - // DataCenter zone = _configMgr.getZone(network.getDataCenterId()); |
62 | 78 | if (network.getGuestType() != Network.GuestIpType.Direct || network.getTrafficType() != TrafficType.Guest) { |
63 | 79 | s_logger.debug("Not handling network with guest Type " + network.getGuestType() + " and traffic type " + network.getTrafficType()); |
64 | 80 | return false; |
@@ -140,4 +156,23 @@ public boolean applyRules(Network network, List<? extends FirewallRule> rules) t |
140 | 156 |
|
141 | 157 | return _lbMgr.applyLoadBalancerRules(network, rules); |
142 | 158 | } |
| 159 | + |
| 160 | + |
| 161 | + @Override |
| 162 | + public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { |
| 163 | + |
| 164 | + super.configure(name, params); |
| 165 | + String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key()); |
| 166 | + _enabled = (enabled == null) ? false: Boolean.parseBoolean(enabled); |
| 167 | + if (_enabled) { |
| 168 | + String traffType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key()); |
| 169 | + if ("guest".equalsIgnoreCase(traffType)) { |
| 170 | + _frontEndTrafficType = TrafficType.Guest; |
| 171 | + } else if ("public".equalsIgnoreCase(traffType)){ |
| 172 | + _frontEndTrafficType = TrafficType.Public; |
| 173 | + } else |
| 174 | + throw new ConfigurationException("Traffic type for front end of load balancer has to be guest or public; found : " + traffType); |
| 175 | + } |
| 176 | + return true; |
| 177 | + } |
143 | 178 | } |
0 commit comments