mirror of https://github.com/apache/cloudstack.git
Fixed setupNetwork command to use vlan tag instead of vlan dbId.
Changed LoadBalancerConfigCommand to use Array data structrue instead of List as list is not handled well by gson.
This commit is contained in:
parent
a826655740
commit
ca92c28e0e
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
package com.cloud.agent.api.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.agent.api.to.LoadBalancerTO;
|
||||
|
||||
/**
|
||||
|
|
@ -26,13 +24,13 @@ import com.cloud.agent.api.to.LoadBalancerTO;
|
|||
* to the load balancer. Isn't that kinda obvious?
|
||||
*/
|
||||
public class LoadBalancerConfigCommand extends RoutingCommand {
|
||||
List<LoadBalancerTO> loadBalancers;
|
||||
LoadBalancerTO[] loadBalancers;
|
||||
|
||||
public LoadBalancerConfigCommand(List<LoadBalancerTO> loadBalancers) {
|
||||
public LoadBalancerConfigCommand(LoadBalancerTO[] loadBalancers) {
|
||||
this.loadBalancers = loadBalancers;
|
||||
}
|
||||
|
||||
public List<LoadBalancerTO> getLoadBalancers() {
|
||||
public LoadBalancerTO[] getLoadBalancers() {
|
||||
return loadBalancers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,5 +125,5 @@ public interface NetworkManager extends NetworkService {
|
|||
Network getNetwork(long id);
|
||||
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
|
||||
|
||||
boolean applyRules(Ip ip, List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
|
||||
boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,15 +94,20 @@ import com.cloud.network.Networks.TrafficType;
|
|||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.dao.FirewallRulesDao;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.RemoteAccessVpnDao;
|
||||
import com.cloud.network.dao.VpnUserDao;
|
||||
import com.cloud.network.element.NetworkElement;
|
||||
import com.cloud.network.guru.NetworkGuru;
|
||||
import com.cloud.network.lb.LoadBalancingRule;
|
||||
import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
|
||||
import com.cloud.network.router.DomainRouterManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.PortForwardingRuleVO;
|
||||
import com.cloud.network.rules.RulesManager;
|
||||
import com.cloud.network.rules.dao.PortForwardingRulesDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.NetworkOffering.GuestIpType;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
|
|
@ -183,6 +188,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
@Inject RulesManager _rulesMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@Inject FirewallRulesDao _firewallRulesDao;
|
||||
@Inject LoadBalancerDao _lbDao;
|
||||
@Inject PortForwardingRulesDao _pfRulesDao;
|
||||
|
||||
@Inject(adapter=NetworkGuru.class)
|
||||
Adapters<NetworkGuru> _networkGurus;
|
||||
|
|
@ -1992,7 +1999,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean applyRules(Ip ip, List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException {
|
||||
public boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException {
|
||||
if (rules.size() == 0) {
|
||||
s_logger.debug("There are no rules to forward to the network elements");
|
||||
return true;
|
||||
|
|
@ -2003,7 +2010,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
for (NetworkElement ne : _networkElements) {
|
||||
try {
|
||||
boolean handled = ne.applyRules(network, rules);
|
||||
s_logger.debug("Network Rules for " + ip + " were " + (handled ? "" : " not") + " handled by " + ne.getName());
|
||||
s_logger.debug("Network Rules for network " + network.getId() + " were " + (handled ? "" : " not") + " handled by " + ne.getName());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
if (!continueOnError) {
|
||||
throw e;
|
||||
|
|
@ -2060,6 +2067,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
|
||||
@Override
|
||||
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException{
|
||||
//This method reapplies Ip addresses, LoadBalancer and PortForwarding rules
|
||||
String accountName = cmd.getAccountName();
|
||||
long domainId = cmd.getDomainId();
|
||||
Account caller = UserContext.current().getAccount();
|
||||
|
|
@ -2080,12 +2088,41 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||
}
|
||||
}
|
||||
|
||||
//TODO - re-apply port forwarding and load balancing rules in the future
|
||||
boolean success = applyIpAssociations(network, false);
|
||||
if (!success) {
|
||||
s_logger.warn("Failed to reapply the ip addresses for the account " + owner.getId() + " in zone " + network.getDataCenterId() + ", in network " + network.getId());
|
||||
boolean success = true;
|
||||
if (!applyIpAssociations(network, false)) {
|
||||
s_logger.warn("Failed to apply ips as a part of network " + networkId + " restart");
|
||||
success = false;
|
||||
} else {
|
||||
s_logger.debug("Ip addresses are reapplied successfully for the account " + owner.getId() + " in zone " + network.getDataCenterId() + ", in network " + network.getId());
|
||||
s_logger.debug("Ip addresses are reapplied successfully as a part of network " + networkId + " restart");
|
||||
}
|
||||
|
||||
//Reapply lb rules
|
||||
List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
|
||||
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
|
||||
for (LoadBalancerVO lb : lbs) {
|
||||
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
|
||||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
|
||||
lbRules.add(loadBalancing);
|
||||
}
|
||||
|
||||
if (!applyRules(lbRules, true)) {
|
||||
s_logger.warn("Failed to apply load balancing rules as a part of network " + network.getId() + " restart");
|
||||
success = false;
|
||||
} else {
|
||||
s_logger.debug("Load balancing rules are reapplied successfully as a part of network " + networkId + " restart");
|
||||
}
|
||||
|
||||
//Reapply pf rules
|
||||
List<PortForwardingRuleVO> pfRules = _pfRulesDao.listByNetworkId(networkId);
|
||||
if (!applyRules(pfRules, true)) {
|
||||
s_logger.warn("Failed to apply port forwarding rules as a part of network " + network.getId() + " restart");
|
||||
success = false;
|
||||
} else {
|
||||
s_logger.debug("Port forwarding rules are reapplied successfully as a part of network " + networkId + " restart");
|
||||
}
|
||||
|
||||
if (success){
|
||||
s_logger.debug("Network " + networkId + " is restarted successfully.");
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,11 +92,11 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
nic.setIp4Address(ip.getAddress());
|
||||
nic.setGateway(ip.getGateway());
|
||||
nic.setNetmask(ip.getNetmask());
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
nic.setReservationId(String.valueOf(ip.getVlanId()));
|
||||
nic.setReservationId(String.valueOf(ip.getVlanTag()));
|
||||
nic.setMacAddress(ip.getMacAddress());
|
||||
}
|
||||
nic.setDns1(dc.getDns1());
|
||||
|
|
|
|||
|
|
@ -75,11 +75,11 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
nic.setIp4Address(ip.getAddress());
|
||||
nic.setGateway(ip.getGateway());
|
||||
nic.setNetmask(ip.getNetmask());
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setBroadcastType(BroadcastDomainType.Vlan);
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanId()));
|
||||
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
|
||||
nic.setFormat(AddressFormat.Ip4);
|
||||
nic.setReservationId(String.valueOf(ip.getVlanId()));
|
||||
nic.setReservationId(String.valueOf(ip.getVlanTag()));
|
||||
nic.setMacAddress(ip.getMacAddress());
|
||||
}
|
||||
nic.setDns1(dc.getDns1());
|
||||
|
|
|
|||
|
|
@ -343,7 +343,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
|
|||
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
|
||||
rules.add(loadBalancing);
|
||||
|
||||
if (!_networkMgr.applyRules(lb.getSourceIpAddress(), rules, false)) {
|
||||
if (!_networkMgr.applyRules(rules, false)) {
|
||||
s_logger.debug("LB rules are not completely applied");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2077,7 +2077,8 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
if (router.getState() == State.Running || router.getState() == State.Starting) {
|
||||
|
||||
Commands cmds = new Commands(OnError.Continue);
|
||||
List<LoadBalancerTO> lbs = new ArrayList<LoadBalancerTO>();
|
||||
LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
|
||||
int i = 0;
|
||||
for (FirewallRule fwRule : rules) {
|
||||
LoadBalancingRule rule = (LoadBalancingRule) fwRule;
|
||||
boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
|
||||
|
|
@ -2087,7 +2088,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||
int srcPort = rule.getSourcePortStart();
|
||||
List<LbDestination> destinations = rule.getDestinations();
|
||||
LoadBalancerTO lb = new LoadBalancerTO(srcIp, srcPort, protocol, algorithm, revoked, false, destinations);
|
||||
lbs.add(lb);
|
||||
lbs[i++] = lb;
|
||||
}
|
||||
|
||||
LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs);
|
||||
|
|
|
|||
|
|
@ -399,7 +399,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
|||
_accountMgr.checkAccess(caller, rules.toArray(new PortForwardingRuleVO[rules.size()]));
|
||||
}
|
||||
|
||||
if (!_networkMgr.applyRules(ip, rules, continueOnError)) {
|
||||
if (!_networkMgr.applyRules(rules, continueOnError)) {
|
||||
s_logger.debug("Rules are not completely applied");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package com.cloud.network.rules.dao;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
import com.cloud.network.rules.PortForwardingRuleVO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.net.Ip;
|
||||
|
|
@ -37,4 +38,6 @@ public interface PortForwardingRulesDao extends GenericDao<PortForwardingRuleVO,
|
|||
List<PortForwardingRuleVO> searchNatRules(Ip ip, Long startIndex, Long pageSize);
|
||||
|
||||
List<PortForwardingRuleVO> listByVm(Long vmId);
|
||||
|
||||
List<PortForwardingRuleVO> listByNetworkId(long networkId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
|
|||
AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
|
||||
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getSourceIpAddress(), Op.EQ);
|
||||
AllFieldsSearch.and("protocol", AllFieldsSearch.entity().getProtocol(), Op.EQ);
|
||||
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
|
||||
ApplicationSearch = createSearchBuilder();
|
||||
|
|
@ -102,4 +103,11 @@ public class PortForwardingRulesDaoImpl extends GenericDaoBase<PortForwardingRul
|
|||
return listBy(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PortForwardingRuleVO> listByNetworkId(long networkId) {
|
||||
SearchCriteria<PortForwardingRuleVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("networkId", networkId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue