making sure the instance variable _router in the Rules is being used instead of the parameter
Conflicts: server/src/com/cloud/network/router/NetworkHelperImpl.java Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/dc5fefc0 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/dc5fefc0 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/dc5fefc0 Branch: refs/heads/master Commit: dc5fefc018add85d0c45c9f178e315a48d8b4373 Parents: 64eed6c Author: Wilder Rodrigues <wrodrig...@schubergphilis.com> Authored: Tue Sep 2 11:05:23 2014 +0200 Committer: wilderrodrigues <wrodrig...@schubergphilis.com> Committed: Tue Oct 14 15:08:11 2014 +0200 ---------------------------------------------------------------------- .../network/router/CommandSetupHelper.java | 41 +-- .../com/cloud/network/router/NetworkHelper.java | 20 +- .../cloud/network/router/NetworkHelperImpl.java | 281 ++++++++++--------- 3 files changed, 170 insertions(+), 172 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc5fefc0/server/src/com/cloud/network/router/CommandSetupHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/router/CommandSetupHelper.java b/server/src/com/cloud/network/router/CommandSetupHelper.java index 798bcfb..92a3bb1 100644 --- a/server/src/com/cloud/network/router/CommandSetupHelper.java +++ b/server/src/com/cloud/network/router/CommandSetupHelper.java @@ -176,6 +176,7 @@ public class CommandSetupHelper { @Inject private RouterControlHelper _routerControlHelper; + @Autowired @Qualifier("networkHelper") protected NetworkHelper _networkHelper; @@ -195,7 +196,7 @@ public class CommandSetupHelper { final List<VpnUser> addUsers = new ArrayList<VpnUser>(); final List<VpnUser> removeUsers = new ArrayList<VpnUser>(); for (final VpnUser user : users) { - if ((user.getState() == VpnUser.State.Add) || (user.getState() == VpnUser.State.Active)) { + if (user.getState() == VpnUser.State.Add || user.getState() == VpnUser.State.Active) { addUsers.add(user); } else if (user.getState() == VpnUser.State.Revoke) { removeUsers.add(user); @@ -218,7 +219,7 @@ public class CommandSetupHelper { final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); final Nic defaultNic = findGatewayIp(vm.getId()); String gatewayIp = defaultNic.getGateway(); - if ((gatewayIp != null) && !gatewayIp.equals(nic.getGateway())) { + if (gatewayIp != null && !gatewayIp.equals(nic.getGateway())) { gatewayIp = "0.0.0.0"; } dhcpCommand.setDefaultRouter(gatewayIp); @@ -290,7 +291,7 @@ public class CommandSetupHelper { // We don't support VR to be inline currently final boolean inline = false; for (final LoadBalancingRule rule : rules) { - final boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke)); + final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke); final String protocol = rule.getProtocol(); final String algorithm = rule.getAlgorithm(); final String uuid = rule.getUuid(); @@ -392,7 +393,7 @@ public class CommandSetupHelper { Boolean defaultEgressPolicy = false; if (rules != null) { if (rules.size() > 0) { - if ((rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress) && (rules.get(0).getType() == FirewallRule.FirewallRuleType.System)) { + if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System) { systemRule = String.valueOf(FirewallRule.FirewallRuleType.System); } } @@ -407,7 +408,7 @@ public class CommandSetupHelper { final NetworkVO network = _networkDao.findById(guestNetworkId); final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); defaultEgressPolicy = offering.getEgressDefaultPolicy(); - assert (rule.getSourceIpAddressId() == null) : "ipAddressId should be null for egress firewall rule. "; + assert rule.getSourceIpAddressId() == null : "ipAddressId should be null for egress firewall rule. "; final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, "", Purpose.Firewall, traffictype, defaultEgressPolicy); rulesTO.add(ruleTO); } @@ -435,7 +436,7 @@ public class CommandSetupHelper { Boolean defaultEgressPolicy = false; if (rules != null) { if (rules.size() > 0) { - if ((rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress) && (rules.get(0).getType() == FirewallRule.FirewallRuleType.System)) { + if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System) { systemRule = String.valueOf(FirewallRule.FirewallRuleType.System); } } @@ -450,7 +451,7 @@ public class CommandSetupHelper { final NetworkVO network = _networkDao.findById(guestNetworkId); final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); defaultEgressPolicy = offering.getEgressDefaultPolicy(); - assert (rule.getSourceIpAddressId() == null) : "ipAddressId should be null for egress firewall rule. "; + assert rule.getSourceIpAddressId() == null : "ipAddressId should be null for egress firewall rule. "; final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, "", Purpose.Firewall, traffictype, defaultEgressPolicy); rulesTO.add(ruleTO); } @@ -485,7 +486,7 @@ public class CommandSetupHelper { } // domR doesn't support release for sourceNat IP address; so reset // the state - if (ipAddress.isSourceNat() && (ipAddress.getState() == IpAddress.State.Releasing)) { + if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) { ipAddress.setState(IpAddress.State.Allocated); } ipList.add(ipAddress); @@ -510,7 +511,7 @@ public class CommandSetupHelper { public int compare(final PublicIpAddress o1, final PublicIpAddress o2) { final boolean s1 = o1.isSourceNat(); final boolean s2 = o2.isSourceNat(); - return (s1 ^ s2) ? ((s1 ^ true) ? 1 : -1) : 0; + return s1 ^ s2 ? s1 ^ true ? 1 : -1 : 0; } }); @@ -524,7 +525,7 @@ public class CommandSetupHelper { for (final PublicIpAddress ipAddr : ipAddrList) { - final boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true); + final boolean add = ipAddr.getState() == IpAddress.State.Releasing ? false : true; boolean sourceNat = ipAddr.isSourceNat(); /* enable sourceNAT for the first ip of the public interface */ if (firstIP) { @@ -538,7 +539,7 @@ public class CommandSetupHelper { // first public nic's MAC // We cannot depends on first ip because we need to deal with // first ip of other nics - if (!ipAddr.isSourceNat() && (ipAddr.getVlanId() != 0)) { + if (!ipAddr.isSourceNat() && ipAddr.getVlanId() != 0) { vifMacAddress = NetUtils.generateMacOnIncrease(baseMac, ipAddr.getVlanId()); } else { vifMacAddress = ipAddr.getMacAddress(); @@ -605,7 +606,7 @@ public class CommandSetupHelper { final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); // password should be set only on default network element - if ((password != null) && nic.isDefaultNic()) { + if (password != null && nic.isDefaultNic()) { final String encodedPassword = PasswordGenerator.rot13(password); final SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd()); @@ -641,8 +642,8 @@ public class CommandSetupHelper { } public void createStaticRouteCommands(final List<StaticRouteProfile> staticRoutes, final VirtualRouter router, final Commands cmds) { - final SetStaticRouteCommand cmd = new SetStaticRouteCommand(staticRoutes); - cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _networkHelper.getRouterControlIp(router.getId())); + SetStaticRouteCommand cmd = new SetStaticRouteCommand(staticRoutes); + cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); @@ -660,7 +661,7 @@ public class CommandSetupHelper { final String cidr = network.getCidr(); final RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(isCreate, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), - vpn.getIpsecPresharedKey(), (vpn.getVpcId() != null)); + vpn.getIpsecPresharedKey(), vpn.getVpcId() != null); startVpnCmd.setLocalCidr(cidr); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); @@ -675,7 +676,7 @@ public class CommandSetupHelper { final DataCenterVO dc = _dcDao.findById(router.getDataCenterId()); for (final UserVmVO vm : vms) { boolean createVmData = true; - if ((dc.getNetworkType() == NetworkType.Basic) && (router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue())) { + if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue()) { createVmData = false; } @@ -694,7 +695,7 @@ public class CommandSetupHelper { final DataCenterVO dc = _dcDao.findById(router.getDataCenterId()); for (final UserVmVO vm : vms) { boolean createDhcp = true; - if ((dc.getNetworkType() == NetworkType.Basic) && (router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue()) + if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue() && _dnsBasicZoneUpdates.equalsIgnoreCase("pod")) { createDhcp = false; } @@ -737,7 +738,7 @@ public class CommandSetupHelper { } // VR doesn't support release for sourceNat IP address; so reset the // state - if (ipAddress.isSourceNat() && (ipAddress.getState() == IpAddress.State.Releasing)) { + if (ipAddress.isSourceNat() && ipAddress.getState() == IpAddress.State.Releasing) { ipAddress.setState(IpAddress.State.Allocated); } ipList.add(ipAddress); @@ -755,7 +756,7 @@ public class CommandSetupHelper { int i = 0; for (final PublicIpAddress ipAddr : ipAddrList) { - final boolean add = (ipAddr.getState() == IpAddress.State.Releasing ? false : true); + final boolean add = ipAddr.getState() == IpAddress.State.Releasing ? false : true; final String macAddress = vlanMacAddress.get(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag()))); @@ -978,7 +979,7 @@ public class CommandSetupHelper { } final DataCenter dc = _dcDao.findById(_networkModel.getNetwork(defaultNic.getNetworkId()).getDataCenterId()); - final boolean isZoneBasic = (dc.getNetworkType() == NetworkType.Basic); + final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic; // find domR's nic in the network NicVO domrDefaultNic; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc5fefc0/server/src/com/cloud/network/router/NetworkHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/router/NetworkHelper.java b/server/src/com/cloud/network/router/NetworkHelper.java index 635e56c..59338f7 100644 --- a/server/src/com/cloud/network/router/NetworkHelper.java +++ b/server/src/com/cloud/network/router/NetworkHelper.java @@ -37,17 +37,13 @@ import com.cloud.vm.VirtualMachineProfile.Param; public interface NetworkHelper { - public abstract String getRouterControlIp(long routerId); - - public abstract String getRouterIpInNetwork(long networkId, long instanceId); - public abstract boolean sendCommandsToRouter(VirtualRouter router, Commands cmds) throws AgentUnavailableException; public abstract void handleSingleWorkingRedundantRouter( List<? extends VirtualRouter> connectedRouters, List<? extends VirtualRouter> disconnectedRouters, String reason) - throws ResourceUnavailableException; + throws ResourceUnavailableException; public abstract int getRealPriority(DomainRouterVO router); @@ -68,19 +64,19 @@ public interface NetworkHelper { public abstract List<DomainRouterVO> startRouters( RouterDeploymentDefinition routerDeploymentDefinition) - throws StorageUnavailableException, InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException; + throws StorageUnavailableException, InsufficientCapacityException, + ConcurrentOperationException, ResourceUnavailableException; public abstract DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map<Param, Object> params) - throws StorageUnavailableException, InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException; + throws StorageUnavailableException, InsufficientCapacityException, + ConcurrentOperationException, ResourceUnavailableException; public abstract DomainRouterVO deployRouter( RouterDeploymentDefinition routerDeploymentDefinition, boolean startRouter) - throws InsufficientAddressCapacityException, - InsufficientServerCapacityException, InsufficientCapacityException, - StorageUnavailableException, ResourceUnavailableException; + throws InsufficientAddressCapacityException, + InsufficientServerCapacityException, InsufficientCapacityException, + StorageUnavailableException, ResourceUnavailableException; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc5fefc0/server/src/com/cloud/network/router/NetworkHelperImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/router/NetworkHelperImpl.java b/server/src/com/cloud/network/router/NetworkHelperImpl.java index fd1fc17..6c695d5 100644 --- a/server/src/com/cloud/network/router/NetworkHelperImpl.java +++ b/server/src/com/cloud/network/router/NetworkHelperImpl.java @@ -30,6 +30,7 @@ import javax.inject.Inject; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.log4j.Logger; import org.cloud.network.router.deployment.RouterDeploymentDefinition; @@ -40,6 +41,7 @@ import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.manager.Commands; import com.cloud.alert.AlertManager; +import com.cloud.configuration.Config; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; @@ -66,12 +68,10 @@ import com.cloud.network.Network; import com.cloud.network.NetworkModel; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; -import com.cloud.network.Networks.TrafficType; import com.cloud.network.VirtualNetworkApplianceService; import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.NetworkDao; -import com.cloud.network.dao.NetworkVO; import com.cloud.network.dao.UserIpv6AddressDao; import com.cloud.network.router.VirtualRouter.RedundantState; import com.cloud.network.router.VirtualRouter.Role; @@ -101,7 +101,7 @@ import com.cloud.vm.VirtualMachineProfile.Param; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; -@Local(value = {NetworkHelper.class}) +@Local(value = { NetworkHelper.class }) public class NetworkHelperImpl implements NetworkHelper { private static final Logger s_logger = Logger.getLogger(NetworkHelperImpl.class); @@ -143,6 +143,10 @@ public class NetworkHelperImpl implements NetworkHelper { @Inject private UserIpv6AddressDao _ipv6Dao; @Inject + private RouterControlHelper _routerControlHelper; + @Inject + private ConfigurationDao _configDao; + @Inject protected NetworkOrchestrationService _networkMgr; protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>(); @@ -157,43 +161,8 @@ public class NetworkHelperImpl implements NetworkHelper { } @Override - public String getRouterControlIp(final long routerId) { - String routerControlIpAddress = null; - final List<NicVO> nics = _nicDao.listByVmId(routerId); - for (final NicVO n : nics) { - final NetworkVO nc = _networkDao.findById(n.getNetworkId()); - if (nc != null && nc.getTrafficType() == TrafficType.Control) { - routerControlIpAddress = n.getIp4Address(); - // router will have only one control ip - break; - } - } - - if (routerControlIpAddress == null) { - s_logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId); - final DomainRouterVO router = _routerDao.findById(routerId); - return router.getPrivateIpAddress(); - } - - return routerControlIpAddress; - } - - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#getRouterIpInNetwork(long, long) - */ - @Override - public String getRouterIpInNetwork(final long networkId, final long instanceId) { - return _nicDao.getIpAddress(networkId, instanceId); - } - - - // @Override - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#sendCommandsToRouter(com.cloud.network.router.VirtualRouter, com.cloud.agent.manager.Commands) - */ - @Override public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException { - if(!checkRouterVersion(router)){ + if (!checkRouterVersion(router)) { s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + VirtualNetworkApplianceService.MinVRVersion); throw new CloudRuntimeException("Unable to send command. Upgrade in progress. Please contact administrator."); @@ -222,8 +191,8 @@ public class NetworkHelperImpl implements NetworkHelper { } @Override - public void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason) - throws ResourceUnavailableException { + public void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, + final String reason) throws ResourceUnavailableException { if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) { return; } @@ -240,28 +209,26 @@ public class NetworkHelperImpl implements NetworkHelper { .getDataCenterId()); } - final DomainRouterVO connectedRouter = (DomainRouterVO)connectedRouters.get(0); - DomainRouterVO disconnectedRouter = (DomainRouterVO)disconnectedRouters.get(0); + final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0); + DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0); if (s_logger.isDebugEnabled()) { s_logger.debug("About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason); } final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason; - final String context = - "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + - ") would be stopped after connecting back, due to: " + reason; - _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, - context); + final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + + ") would be stopped after connecting back, due to: " + reason; + _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context); disconnectedRouter.setStopPending(true); disconnectedRouter = _routerDao.persist(disconnectedRouter); final int connRouterPR = getRealPriority(connectedRouter); final int disconnRouterPR = getRealPriority(disconnectedRouter); if (connRouterPR < disconnRouterPR) { - //connRouterPR < disconnRouterPR, they won't equal at any time + // connRouterPR < disconnRouterPR, they won't equal at any time if (!connectedRouter.getIsPriorityBumpUp()) { final BumpUpPriorityCommand command = new BumpUpPriorityCommand(); - command.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(connectedRouter.getId())); + command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(connectedRouter.getId())); command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, connectedRouter.getInstanceName()); final Answer answer = _agentMgr.easySend(connectedRouter.getHostId(), command); if (!answer.getResult()) { @@ -274,8 +241,11 @@ public class NetworkHelperImpl implements NetworkHelper { } } - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#getRealPriority(com.cloud.vm.DomainRouterVO) + /* + * (non-Javadoc) + * + * @see com.cloud.network.router.NetworkHelper#getRealPriority(com.cloud.vm. + * DomainRouterVO) */ @Override public int getRealPriority(final DomainRouterVO router) { @@ -286,9 +256,13 @@ public class NetworkHelperImpl implements NetworkHelper { return priority; } - // @Override - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#getNicTO(com.cloud.network.router.VirtualRouter, java.lang.Long, java.lang.String) + // @Override + /* + * (non-Javadoc) + * + * @see + * com.cloud.network.router.NetworkHelper#getNicTO(com.cloud.network.router + * .VirtualRouter, java.lang.Long, java.lang.String) */ @Override public NicTO getNicTO(final VirtualRouter router, final Long networkId, final String broadcastUri) { @@ -297,9 +271,12 @@ public class NetworkHelperImpl implements NetworkHelper { return _itMgr.toNicTO(nicProfile, router.getHypervisorType()); } - // @Override - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#destroyRouter(long, com.cloud.user.Account, java.lang.Long) + // @Override + /* + * (non-Javadoc) + * + * @see com.cloud.network.router.NetworkHelper#destroyRouter(long, + * com.cloud.user.Account, java.lang.Long) */ @Override public VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { @@ -320,24 +297,27 @@ public class NetworkHelperImpl implements NetworkHelper { return router; } - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#checkRouterVersion(com.cloud.network.router.VirtualRouter) + /* + * (non-Javadoc) + * + * @see + * com.cloud.network.router.NetworkHelper#checkRouterVersion(com.cloud.network + * .router.VirtualRouter) */ - // @Override + // @Override @Override public boolean checkRouterVersion(final VirtualRouter router) { - if(!VirtualNetworkApplianceManagerImpl.routerVersionCheckEnabled.value()){ - //Router version check is disabled. + if (!VirtualNetworkApplianceManagerImpl.routerVersionCheckEnabled.value()) { + // Router version check is disabled. return true; } - if(router.getTemplateVersion() == null){ + if (router.getTemplateVersion() == null) { return false; } final String trimmedVersion = Version.trimRouterVersion(router.getTemplateVersion()); return Version.compare(trimmedVersion, VirtualNetworkApplianceService.MinVRVersion) >= 0; } - protected DomainRouterVO start(DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting router " + router); @@ -351,7 +331,8 @@ public class NetworkHelperImpl implements NetworkHelper { router.setStopPending(false); router = _routerDao.persist(router); } - // We don't want the failure of VPN Connection affect the status of router, so we try to make connection + // We don't want the failure of VPN Connection affect the status of + // router, so we try to make connection // only after router start successfully final Long vpcId = router.getVpcId(); if (vpcId != null) { @@ -388,14 +369,16 @@ public class NetworkHelperImpl implements NetworkHelper { return null; } - - // @Override - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#startRouters(org.cloud.network.router.deployment.RouterDeploymentDefinition) + // @Override + /* + * (non-Javadoc) + * + * @see + * com.cloud.network.router.NetworkHelper#startRouters(org.cloud.network + * .router.deployment.RouterDeploymentDefinition) */ @Override - public List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition) - throws StorageUnavailableException, InsufficientCapacityException, + public List<DomainRouterVO> startRouters(final RouterDeploymentDefinition routerDeploymentDefinition) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { List<DomainRouterVO> runningRouters = new ArrayList<DomainRouterVO>(); @@ -411,8 +394,7 @@ public class NetworkHelperImpl implements NetworkHelper { } if (!skip) { if (state != State.Running) { - router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), - routerDeploymentDefinition.getParams()); + router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), routerDeploymentDefinition.getParams()); } if (router != null) { runningRouters.add(router); @@ -422,14 +404,18 @@ public class NetworkHelperImpl implements NetworkHelper { return runningRouters; } - // @Override - /* (non-Javadoc) - * @see com.cloud.network.router.NetworkHelper#startVirtualRouter(com.cloud.vm.DomainRouterVO, com.cloud.user.User, com.cloud.user.Account, java.util.Map) + // @Override + /* + * (non-Javadoc) + * + * @see + * com.cloud.network.router.NetworkHelper#startVirtualRouter(com.cloud.vm + * .DomainRouterVO, com.cloud.user.User, com.cloud.user.Account, + * java.util.Map) */ @Override public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) - throws StorageUnavailableException, InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { + throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) { return start(router, user, caller, params, null); @@ -441,7 +427,8 @@ public class NetworkHelperImpl implements NetworkHelper { } // - // If another thread has already requested a VR start, there is a transition period for VR to transit from + // If another thread has already requested a VR start, there is a + // transition period for VR to transit from // Starting to Running, there exist a race conditioning window here // We will wait until VR is up or fail if (router.getState() == State.Starting) { @@ -452,7 +439,7 @@ public class NetworkHelperImpl implements NetworkHelper { DomainRouterVO result = null; assert router.getIsRedundantRouter(); final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId()); - //Not support VPC now + // Not support VPC now if (networkIds.size() > 1) { throw new ResourceUnavailableException("Unable to support more than one guest network for redundant router now!", DataCenter.class, router.getDataCenterId()); } @@ -462,9 +449,9 @@ public class NetworkHelperImpl implements NetworkHelper { for (final DomainRouterVO rrouter : routerList) { if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) { if (routerToBeAvoid != null) { - throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + - ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + - rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, + throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + + ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + + rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, rrouter.getDataCenterId()); } routerToBeAvoid = rrouter; @@ -508,18 +495,34 @@ public class NetworkHelperImpl implements NetworkHelper { return result; } + protected String retrieveTemplateName(HypervisorType hType, final long datacenterId) { + if (hType == HypervisorType.BareMetal) { + String peerHvType = _configDao.getValue(Config.BaremetalPeerHypervisorType.key()); + if (peerHvType == null) { + throw new CloudRuntimeException(String.format("To use baremetal in advanced networking, you must set %s to type of hypervisor(e.g XenServer)" + + " that exists in the same zone with baremetal host. That hyperivsor is used to spring up virtual router for baremetal instance", + Config.BaremetalPeerHypervisorType.key())); + } + + hType = HypervisorType.getType(peerHvType); + if (HypervisorType.XenServer != hType && HypervisorType.KVM != hType && HypervisorType.VMware != hType) { + throw new CloudRuntimeException(String.format("Baremetal only supports peer hypervisor(XenServer/KVM/VMWare) right now, you specified %s", peerHvType)); + } + } + + return hypervisorsMap.get(hType).valueIn(datacenterId); + } + @Override - public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, - final boolean startRouter) - throws InsufficientAddressCapacityException, - InsufficientServerCapacityException, InsufficientCapacityException, - StorageUnavailableException, ResourceUnavailableException { + public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter) throws InsufficientAddressCapacityException, + InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getOfferingId()); final Account owner = routerDeploymentDefinition.getOwner(); // Router is the network element, we don't know the hypervisor type yet. - // Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up + // Try to allocate the domR twice using diff hypervisors, and when + // failed both times, throw the exception up final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition); int allocateRetry = 0; @@ -530,13 +533,11 @@ public class NetworkHelperImpl implements NetworkHelper { try { final long id = _routerDao.getNextInSequence(Long.class, "id"); if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format( - "Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", - id, routerDeploymentDefinition.getDest().getDataCenter(), hType)); + s_logger.debug(String.format("Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", id, routerDeploymentDefinition.getDest() + .getDataCenter(), hType)); } - String templateName = hypervisorsMap.get(hType) - .valueIn(routerDeploymentDefinition.getDest().getDataCenter().getId()); + String templateName = retrieveTemplateName(hType, routerDeploymentDefinition.getDest().getDataCenter().getId()); final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName); if (template == null) { @@ -545,18 +546,21 @@ public class NetworkHelperImpl implements NetworkHelper { } boolean offerHA = routerOffering.getOfferHA(); - /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ + /* + * We don't provide HA to redundant router VMs, admin should own + * it all, and redundant router themselves are HA + */ if (routerDeploymentDefinition.isRedundant()) { offerHA = false; } - // routerDeploymentDefinition.getVpc().getId() ==> do not use VPC because it is not a VPC offering. + // routerDeploymentDefinition.getVpc().getId() ==> do not use + // VPC because it is not a VPC offering. Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null; - router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), - VirtualMachineName.getRouterName(id, VirtualNetworkStatus.instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), routerDeploymentDefinition.isRedundant(), 0, - false, RedundantState.UNKNOWN, offerHA, false, vpcId); + router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, + VirtualNetworkStatus.instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), + routerDeploymentDefinition.isRedundant(), 0, false, RedundantState.UNKNOWN, offerHA, false, vpcId); router.setDynamicallyScalable(template.isDynamicallyScalable()); router.setRole(Role.VIRTUAL_ROUTER); @@ -592,7 +596,7 @@ public class NetworkHelperImpl implements NetworkHelper { startRetry++; } } else { - //return stopped router + // return stopped router return router; } } @@ -601,15 +605,15 @@ public class NetworkHelperImpl implements NetworkHelper { } protected void filterSupportedHypervisors(final List<HypervisorType> hypervisors) { - // For non vpc we keep them all assuming all types in the list are supported + // For non vpc we keep them all assuming all types in the list are + // supported } protected String getNoHypervisorsErrMsgDetails() { return ""; } - protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) - throws InsufficientServerCapacityException { + protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition routerDeploymentDefinition) throws InsufficientServerCapacityException { final DeployDestination dest = routerDeploymentDefinition.getDest(); List<HypervisorType> hypervisors = new ArrayList<HypervisorType>(); @@ -624,7 +628,7 @@ public class NetworkHelperImpl implements NetworkHelper { if (defaults != HypervisorType.None) { hypervisors.add(defaults); } else { - //if there is no default hypervisor, get it from the cluster + // if there is no default hypervisor, get it from the cluster hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, routerDeploymentDefinition.getPlan().getPodId()); } } @@ -633,19 +637,18 @@ public class NetworkHelperImpl implements NetworkHelper { if (hypervisors.isEmpty()) { if (routerDeploymentDefinition.getPodId() != null) { - throw new InsufficientServerCapacityException( - "Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), - Pod.class, routerDeploymentDefinition.getPodId()); + throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the pod." + getNoHypervisorsErrMsgDetails(), Pod.class, + routerDeploymentDefinition.getPodId()); } - throw new InsufficientServerCapacityException( - "Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), + throw new InsufficientServerCapacityException("Unable to create virtual router, there are no clusters in the zone." + getNoHypervisorsErrMsgDetails(), DataCenter.class, dest.getDataCenter().getId()); } return hypervisors; } /* - * Ovm won't support any system. So we have to choose a partner cluster in the same pod to start domain router for us + * Ovm won't support any system. So we have to choose a partner cluster in + * the same pod to start domain router for us */ protected HypervisorType getClusterToStartDomainRouterForOvm(final long podId) { final List<ClusterVO> clusters = _clusterDao.listByPodId(podId); @@ -667,24 +670,19 @@ public class NetworkHelperImpl implements NetworkHelper { } } - final String errMsg = - new StringBuilder("Cannot find an available cluster in Pod ") - .append(podId) - .append(" to start domain router for Ovm. \n Ovm won't support any system vm including domain router, ") - .append("please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod") - .append(" with Ovm cluster. And there is at least one host in UP status in that cluster.") - .toString(); + final String errMsg = new StringBuilder("Cannot find an available cluster in Pod ").append(podId) + .append(" to start domain router for Ovm. \n Ovm won't support any system vm including domain router, ") + .append("please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod") + .append(" with Ovm cluster. And there is at least one host in UP status in that cluster.").toString(); throw new CloudRuntimeException(errMsg); } + public LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition) + throws ConcurrentOperationException, InsufficientAddressCapacityException { - public LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks( - final RouterDeploymentDefinition routerDeploymentDefinition) - throws ConcurrentOperationException, InsufficientAddressCapacityException { - - //Form networks + // Form networks LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3); - //1) Guest network + // 1) Guest network boolean hasGuestNetwork = false; if (routerDeploymentDefinition.getGuestNetwork() != null) { s_logger.debug("Adding nic for Virtual Router in Guest network " + routerDeploymentDefinition.getGuestNetwork()); @@ -693,30 +691,32 @@ public class NetworkHelperImpl implements NetworkHelper { final Nic placeholder = _networkModel.getPlaceholderNicForRouter(routerDeploymentDefinition.getGuestNetwork(), routerDeploymentDefinition.getPodId()); if (routerDeploymentDefinition.getGuestNetwork().getCidr() != null) { if (placeholder != null && placeholder.getIp4Address() != null) { - s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + routerDeploymentDefinition.getGuestNetwork()); + s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + + routerDeploymentDefinition.getGuestNetwork()); defaultNetworkStartIp = placeholder.getIp4Address(); } else { final String startIp = _networkModel.getStartIpAddress(routerDeploymentDefinition.getGuestNetwork().getId()); if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(routerDeploymentDefinition.getGuestNetwork().getId(), startIp).getAllocatedTime() == null) { defaultNetworkStartIp = startIp; } else if (s_logger.isDebugEnabled()) { - s_logger.debug("First ipv4 " + startIp + " in network id=" + routerDeploymentDefinition.getGuestNetwork().getId() + - " is already allocated, can't use it for domain router; will get random ip address from the range"); + s_logger.debug("First ipv4 " + startIp + " in network id=" + routerDeploymentDefinition.getGuestNetwork().getId() + + " is already allocated, can't use it for domain router; will get random ip address from the range"); } } } if (routerDeploymentDefinition.getGuestNetwork().getIp6Cidr() != null) { if (placeholder != null && placeholder.getIp6Address() != null) { - s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + routerDeploymentDefinition.getGuestNetwork()); + s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + + routerDeploymentDefinition.getGuestNetwork()); defaultNetworkStartIpv6 = placeholder.getIp6Address(); } else { final String startIpv6 = _networkModel.getStartIpv6Address(routerDeploymentDefinition.getGuestNetwork().getId()); if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(routerDeploymentDefinition.getGuestNetwork().getId(), startIpv6) == null) { defaultNetworkStartIpv6 = startIpv6; } else if (s_logger.isDebugEnabled()) { - s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + routerDeploymentDefinition.getGuestNetwork().getId() + - " is already allocated, can't use it for domain router; will get random ipv6 address from the range"); + s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + routerDeploymentDefinition.getGuestNetwork().getId() + + " is already allocated, can't use it for domain router; will get random ipv6 address from the range"); } } } @@ -743,17 +743,17 @@ public class NetworkHelperImpl implements NetworkHelper { hasGuestNetwork = true; } - //2) Control network + // 2) Control network s_logger.debug("Adding nic for Virtual Router in Control network "); List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork); NetworkOffering controlOffering = offerings.get(0); - Network controlConfig = _networkMgr.setupNetwork(VirtualNetworkStatus.account, controlOffering, routerDeploymentDefinition.getPlan(), - null, null, false).get(0); + Network controlConfig = _networkMgr.setupNetwork(VirtualNetworkStatus.account, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0); networks.put(controlConfig, new ArrayList<NicProfile>()); - //3) Public network + // 3) Public network if (routerDeploymentDefinition.isPublicNetwork()) { s_logger.debug("Adding nic for Virtual Router in Public network "); - //if source nat service is supported by the network, get the source nat ip address + // if source nat service is supported by the network, get the source + // nat ip address final NicProfile defaultNic = new NicProfile(); defaultNic.setDefaultNic(true); final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP(); @@ -776,10 +776,11 @@ public class NetworkHelperImpl implements NetworkHelper { defaultNic.setDeviceId(2); } final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0); - final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(VirtualNetworkStatus.account, publicOffering, - routerDeploymentDefinition.getPlan(), null, null, false); + final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(VirtualNetworkStatus.account, publicOffering, routerDeploymentDefinition.getPlan(), null, + null, false); final String publicIp = defaultNic.getIp4Address(); - // We want to use the identical MAC address for RvR on public interface if possible + // We want to use the identical MAC address for RvR on public + // interface if possible final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId()); if (peerNic != null) { s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress()); @@ -790,4 +791,4 @@ public class NetworkHelperImpl implements NetworkHelper { return networks; } -} \ No newline at end of file +}