bug 11204: when search for domR/dhcp, include Role to the corresponding search to eliminate getting "LB" network element in the response

status 11204: resolved fixed

Conflicts:

	server/src/com/cloud/network/element/VirtualRouterElement.java
	server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java
This commit is contained in:
alena 2011-08-23 12:05:53 -07:00
parent 40d348ff8b
commit d3eb9db7fa
8 changed files with 131 additions and 89 deletions

View File

@ -37,4 +37,5 @@ public interface VirtualRouter extends VirtualMachine {
FAULT
}
RedundantState getRedundantState();
String getGuestIpAddress();
}

View File

@ -139,6 +139,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
return publicMacAddress;
}
@Override
public String getGuestIpAddress() {
return guestIpAddress;
}

View File

@ -44,6 +44,7 @@ import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.StaticNat;
import com.cloud.network.vpn.PasswordResetElement;
@ -129,7 +130,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
DataCenter dc = dest.getDataCenter();
boolean isPodBased = (dc.getNetworkType() == NetworkType.Basic || network.isSecurityGroupEnabled()) && network.getTrafficType() == TrafficType.Guest;
if (isPodBased && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running);
List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.DHCP_USERDATA);
routers.addAll(allRunningRoutersOutsideThePod);
}
@ -147,7 +148,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
@Override
public boolean shutdown(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
@ -160,7 +161,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
@Override
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.findByNetwork(config.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
@ -216,7 +217,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
return false;
}
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.trace("Can't find dhcp element in network " + network.getId());
return true;
@ -241,11 +242,17 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password
@Override
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.trace("Can't find dhcp element in network " + network.getId());
return true;
}
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
return _routerMgr.savePasswordToRouter(network, nic, uservm);
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
}
@Override

View File

@ -47,6 +47,7 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VirtualRouter.Role;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.StaticNat;
@ -147,7 +148,7 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
NetworkOffering networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
// We need to re-implement the network since the redundancy capability may changed
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.trace("Can't find virtual router element in network " + network.getId());
return true;
@ -182,15 +183,14 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
DataCenter dc = _configMgr.getZone(config.getDataCenterId());
if (canHandle(config.getGuestType(),dc)) {
long networkId = config.getId();
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual router doesn't exist in the network " + config.getId());
return true;
}
if(!_routerMgr.applyFirewallRules(config, rules)){
throw new CloudRuntimeException("Failed to apply firewall rules in network "+config.getId());
if(!_routerMgr.applyFirewallRules(config, rules, routers)){
throw new CloudRuntimeException("Failed to apply firewall rules in network " + config.getId());
} else {
return true;
}
@ -204,8 +204,15 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
public String[] applyVpnUsers(RemoteAccessVpn vpn, List<? extends VpnUser> users) throws ResourceUnavailableException{
Network network = _networksDao.findById(vpn.getNetworkId());
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router doesn't exist in the network " + network.getId());
return null;
}
if (canHandle(network.getGuestType(),dc)) {
return _routerMgr.applyVpnUsers(network, users);
return _routerMgr.applyVpnUsers(network, users, routers);
} else {
s_logger.debug("Element " + this.getName() + " doesn't handle applyVpnUsers command");
return null;
@ -215,8 +222,15 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
@Override
public boolean startVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't exist in the network " + network.getId());
return true;
}
if (canHandle(network.getGuestType(),dc)) {
return _routerMgr.startRemoteAccessVpn(network, vpn);
return _routerMgr.startRemoteAccessVpn(network, vpn, routers);
} else {
s_logger.debug("Element " + this.getName() + " doesn't handle createVpn command");
return false;
@ -226,27 +240,33 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
@Override
public boolean stopVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't exist in the network " + network.getId());
return true;
}
if (canHandle(network.getGuestType(),dc)) {
return _routerMgr.deleteRemoteAccessVpn(network, vpn);
return _routerMgr.deleteRemoteAccessVpn(network, vpn, routers);
} else {
s_logger.debug("Element " + this.getName() + " doesn't handle removeVpn command");
return false;
}
}
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
if (canHandle(network.getGuestType(),dc)) {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual router doesn't exist in the network " + network.getId());
return true;
}
return _routerMgr.associateIP(network, ipAddress);
return _routerMgr.associateIP(network, ipAddress, routers);
} else {
return false;
}
@ -306,16 +326,56 @@ public class VirtualRouterElement extends DhcpElement implements NetworkElement,
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
DataCenter dc = _configMgr.getZone(config.getDataCenterId());
if (canHandle(config.getGuestType(),dc)) {
long networkId = config.getId();
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual router doesn't exist in the network " + config.getId());
return true;
}
return _routerMgr.applyStaticNats(config, rules);
return _routerMgr.applyStaticNats(config, rules, routers);
} else {
return true;
}
}
@Override
public boolean shutdown(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
boolean result = true;
for (DomainRouterVO router : routers) {
result = result && _routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null;
}
return result;
}
@Override
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
return true;
}
boolean result = true;
for (DomainRouterVO router : routers) {
result = result && _routerMgr.destroyRouter(router.getId());
}
return result;
}
@Override
public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws ResourceUnavailableException{
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
if (routers == null || routers.isEmpty()) {
s_logger.trace("Can't find dhcp element in network " + network.getId());
return true;
}
@SuppressWarnings("unchecked")
VirtualMachineProfile<UserVm> uservm = (VirtualMachineProfile<UserVm>)vm;
return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
}
}

View File

@ -59,9 +59,10 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
/**
* save a vm password on the router.
* @param routers TODO
*
*/
boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile) throws ResourceUnavailableException;
boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
boolean destroyRouter(long routerId) throws ResourceUnavailableException, ConcurrentOperationException;
@ -72,25 +73,25 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA
List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params, boolean isRedundant) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
List<DomainRouterVO> deployDhcp(Network guestNetwork, DeployDestination dest, Account owner, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException;
boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
List<VirtualRouter> addVirtualMachineIntoNetwork(Network config, NicProfile nic, VirtualMachineProfile<UserVm> vm, DeployDestination dest, ReservationContext context, List<DomainRouterVO> routers) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException;
boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
boolean associateIP (Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException;
boolean associateIP (Network network, List<? extends PublicIpAddress> ipAddress, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException;
boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
List<VirtualRouter> getRoutersForNetwork(long networkId);
String[] applyVpnUsers(Network network, List<? extends VpnUser> users) throws ResourceUnavailableException;
String[] applyVpnUsers(Network network, List<? extends VpnUser> users, List<DomainRouterVO> routers) throws ResourceUnavailableException;
VirtualRouter stop(VirtualRouter router, boolean forced, User callingUser, Account callingAccount) throws ConcurrentOperationException, ResourceUnavailableException;
String getDnsBasicZoneUpdate();
boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException;
boolean applyStaticNats(Network network, List<? extends StaticNat> rules, List<? extends VirtualRouter> routers) throws ResourceUnavailableException;
}

View File

@ -411,8 +411,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
@Override
public boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Unable save password, router doesn't exist in network " + network.getId());
throw new CloudRuntimeException("Unable to save password to router");
@ -424,7 +423,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
DataCenter dc = _dcDao.findById(userVm.getDataCenterIdToDeployIn());
boolean result = true;
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
boolean sendPassword = true;
if (dc.getNetworkType() == NetworkType.Basic && userVm.getPodIdToDeployIn().longValue() != router.getPodIdToDeployIn().longValue()) {
sendPassword = false;
@ -877,7 +876,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
long dcId = dest.getDataCenter().getId();
DataCenterDeployment plan = new DataCenterDeployment(dcId);
List<DomainRouterVO> routers = _routerDao.findByNetwork(guestNetwork.getId());
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.DHCP_FIREWALL_LB_PASSWD_USERDATA);
try {
int routerCount = 1;
@ -1096,10 +1095,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
// In Basic zone and Guest network we have to start domR per pod, not per network
if (isPodBased) {
routers = _routerDao.findByNetworkAndPod(guestNetwork.getId(), podId);
routers = _routerDao.listByNetworkAndPodAndRole(guestNetwork.getId(), podId, Role.DHCP_USERDATA);
plan = new DataCenterDeployment(dcId, podId, null, null, null);
} else {
routers = _routerDao.findByNetwork(guestNetwork.getId());
routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.DHCP_USERDATA);
plan = new DataCenterDeployment(dcId);
}
@ -1533,15 +1532,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
@Override
public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean startRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId());
}
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
if (router.getState() != State.Running) {
s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
@ -1577,16 +1574,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
@Override
public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean deleteRemoteAccessVpn(Network network, RemoteAccessVpn vpn, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to delete remote access VPN: no router found for account and zone");
throw new ResourceUnavailableException("Failed to delete remote access VPN", DataCenter.class, network.getDataCenterId());
}
boolean result = true;
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
if (router.getState() != State.Running) {
s_logger.warn("Failed to delete remote access VPN: domR is not in right state " + router.getState());
throw new ResourceUnavailableException("Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
@ -1770,8 +1765,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
@Override
public String[] applyVpnUsers(Network network, List<? extends VpnUser> users) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public String[] applyVpnUsers(Network network, List<? extends VpnUser> users, List<DomainRouterVO> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Failed to add/remove VPN users: no router found for account and zone");
throw new ResourceUnavailableException("Unable to assign ip addresses, domR doesn't exist for network " + network.getId(), DataCenter.class, network.getDataCenterId());
@ -1888,7 +1882,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return startVirtualRouter(router, user, account, params);
}
private void createAssociateIPCommands(final DomainRouterVO router, final List<? extends PublicIpAddress> ips, Commands cmds, long vmId) {
private void createAssociateIPCommands(final VirtualRouter router, final List<? extends PublicIpAddress> ips, Commands cmds, long vmId) {
// Ensure that in multiple vlans case we first send all ip addresses of vlan1, then all ip addresses of vlan2, etc..
Map<String, ArrayList<PublicIpAddress>> vlanIpMap = new HashMap<String, ArrayList<PublicIpAddress>>();
@ -1950,7 +1944,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
}
private void createApplyPortForwardingRulesCommands(List<? extends PortForwardingRule> rules, DomainRouterVO router, Commands cmds) {
private void createApplyPortForwardingRulesCommands(List<? extends PortForwardingRule> rules, VirtualRouter router, Commands cmds) {
List<PortForwardingRuleTO> rulesTO = null;
if (rules != null) {
rulesTO = new ArrayList<PortForwardingRuleTO>();
@ -1971,7 +1965,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
cmds.addCommand(cmd);
}
private void createApplyStaticNatRulesCommands(List<? extends StaticNatRule> rules, DomainRouterVO router, Commands cmds) {
private void createApplyStaticNatRulesCommands(List<? extends StaticNatRule> rules, VirtualRouter router, Commands cmds) {
List<StaticNatRuleTO> rulesTO = null;
if (rules != null) {
rulesTO = new ArrayList<StaticNatRuleTO>();
@ -1991,7 +1985,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
cmds.addCommand(cmd);
}
private void createApplyLoadBalancingRulesCommands(List<LoadBalancingRule> rules, DomainRouterVO router, Commands cmds) {
private void createApplyLoadBalancingRulesCommands(List<LoadBalancingRule> rules, VirtualRouter router, Commands cmds) {
LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
int i = 0;
@ -2023,7 +2017,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
private void createApplyVpnCommands(RemoteAccessVpn vpn, DomainRouterVO router, Commands cmds) {
private void createApplyVpnCommands(RemoteAccessVpn vpn, VirtualRouter router, Commands cmds) {
List<VpnUserVO> vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId());
List<VpnUser> addUsers = new ArrayList<VpnUser>();
List<VpnUser> removeUsers = new ArrayList<VpnUser>();
@ -2102,7 +2096,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
}
private boolean sendCommandsToRouter(final DomainRouterVO router, Commands cmds) throws AgentUnavailableException {
private boolean sendCommandsToRouter(final VirtualRouter router, Commands cmds) throws AgentUnavailableException {
Answer[] answers = null;
try {
answers = _agentMgr.send(router.getHostId(), cmds);
@ -2128,15 +2122,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
@Override
public boolean associateIP(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean associateIP(Network network, List<? extends PublicIpAddress> ipAddress, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Unable to associate ip addresses, virtual router doesn't exist in the network " + network.getId());
throw new ResourceUnavailableException("Unable to assign ip addresses", DataCenter.class, network.getDataCenterId());
}
boolean result = true;
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
Commands cmds = new Commands(OnError.Continue);
// Have to resend all already associated ip addresses
@ -2157,15 +2150,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
@Override
public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Unable to apply firewall rules, virtual router doesn't exist in the network " + network.getId());
throw new ResourceUnavailableException("Unable to apply firewall rules", DataCenter.class, network.getDataCenterId());
}
boolean result = true;
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
if (rules != null && !rules.isEmpty()) {
if (rules.get(0).getPurpose() == Purpose.LoadBalancing) {
@ -2204,21 +2196,21 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return result;
}
protected boolean applyLBRules(DomainRouterVO router, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
protected boolean applyLBRules(VirtualRouter router, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createApplyLoadBalancingRulesCommands(rules, router, cmds);
// Send commands to router
return sendCommandsToRouter(router, cmds);
}
protected boolean applyPortForwardingRules(DomainRouterVO router, List<PortForwardingRule> rules) throws ResourceUnavailableException {
protected boolean applyPortForwardingRules(VirtualRouter router, List<PortForwardingRule> rules) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createApplyPortForwardingRulesCommands(rules, router, cmds);
// Send commands to router
return sendCommandsToRouter(router, cmds);
}
protected boolean applyStaticNatRules(DomainRouterVO router, List<StaticNatRule> rules) throws ResourceUnavailableException {
protected boolean applyStaticNatRules(VirtualRouter router, List<StaticNatRule> rules) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createApplyStaticNatRulesCommands(rules, router, cmds);
// Send commands to router
@ -2235,7 +2227,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return vrs;
}
private void createFirewallRulesCommands(List<? extends FirewallRule> rules, DomainRouterVO router, Commands cmds) {
private void createFirewallRulesCommands(List<? extends FirewallRule> rules, VirtualRouter router, Commands cmds) {
List<FirewallRuleTO> rulesTO = null;
if (rules != null) {
rulesTO = new ArrayList<FirewallRuleTO>();
@ -2256,7 +2248,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
protected boolean applyFirewallRules(DomainRouterVO router, List<FirewallRule> rules) throws ResourceUnavailableException {
protected boolean applyFirewallRules(VirtualRouter router, List<FirewallRule> rules) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createFirewallRulesCommands(rules, router, cmds);
// Send commands to router
@ -2270,15 +2262,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules, List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
if (routers == null || routers.isEmpty()) {
s_logger.warn("Unable to create static nat, virtual router doesn't exist in the network " + network.getId());
throw new ResourceUnavailableException("Unable to create static nat", DataCenter.class, network.getDataCenterId());
}
boolean result = true;
for (DomainRouterVO router : routers) {
for (VirtualRouter router : routers) {
if (router.getState() == State.Running) {
s_logger.debug("Applying " + rules.size() + " static nat in network " + network);
result = applyStaticNat(router, rules);
@ -2300,14 +2291,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
protected boolean applyStaticNat(DomainRouterVO router, List<? extends StaticNat> rules) throws ResourceUnavailableException {
protected boolean applyStaticNat(VirtualRouter router, List<? extends StaticNat> rules) throws ResourceUnavailableException {
Commands cmds = new Commands(OnError.Continue);
createApplyStaticNatCommands(rules, router, cmds);
// Send commands to router
return sendCommandsToRouter(router, cmds);
}
private void createApplyStaticNatCommands(List<? extends StaticNat> rules, DomainRouterVO router, Commands cmds) {
private void createApplyStaticNatCommands(List<? extends StaticNat> rules, VirtualRouter router, Commands cmds) {
List<StaticNatRuleTO> rulesTO = null;
if (rules != null) {
rulesTO = new ArrayList<StaticNatRuleTO>();

View File

@ -91,8 +91,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
List<DomainRouterVO> findByNetwork(long networkId);
List<DomainRouterVO> findByNetworkAndPod(long networkId, long podId);
List<DomainRouterVO> listActive(long networkId);
/**
@ -101,8 +99,7 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
*/
List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType);
List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state);
List<DomainRouterVO> listByNetworkAndState(long networkId, State state);
List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state, Role role);
List<DomainRouterVO> listByNetworkAndPodAndRole(long networkId, long podId, Role role);

View File

@ -87,6 +87,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
OutsidePodSearch.and("network", OutsidePodSearch.entity().getNetworkId(), Op.EQ);
OutsidePodSearch.and("podId", OutsidePodSearch.entity().getPodIdToDeployIn(), Op.NEQ);
OutsidePodSearch.and("state", OutsidePodSearch.entity().getState(), Op.EQ);
OutsidePodSearch.and("role", OutsidePodSearch.entity().getRole(), Op.EQ);
OutsidePodSearch.done();
}
@ -188,14 +189,6 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
return listBy(sc);
}
@Override
public List<DomainRouterVO> findByNetworkAndPod(long networkId, long podId) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("podId", podId);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listActive(long networkId) {
SearchCriteria<DomainRouterVO> sc = IdNetworkIdStatesSearch.create();
@ -213,21 +206,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
}
@Override
public List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state) {
public List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state, Role role) {
SearchCriteria<DomainRouterVO> sc = OutsidePodSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("podId", podId);
sc.setParameters("state", state);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listByNetworkAndState(long networkId, State state) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);
if (state != null) {
sc.setParameters("state", state);
}
sc.setParameters("role", role);
return listBy(sc);
}