From b8b7d06f15c00a432a811e12486d1a0e501caeef Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 11 Jul 2012 10:35:43 -0700 Subject: [PATCH] VPC: don't send staticRoutes in Revoke state to the VPC VR --- ...VpcVirtualNetworkApplianceManagerImpl.java | 23 ++++++++++--- .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 34 +++++++++++-------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 84e2e20ea07..ed573ce696b 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -872,12 +872,15 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian List staticRouteProfiles = new ArrayList(routes.size()); Map gatewayMap = new HashMap(); for (StaticRoute route : routes) { - VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId()); - if (gateway == null) { - gateway = _vpcMgr.getVpcGateway(route.getVpcGatewayId()); - gatewayMap.put(gateway.getId(), gateway); + if (route.getState() != StaticRoute.State.Revoke) { + //skip static route in revoke state + VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId()); + if (gateway == null) { + gateway = _vpcMgr.getVpcGateway(route.getVpcGatewayId()); + gatewayMap.put(gateway.getId(), gateway); + } + staticRouteProfiles.add(new StaticRouteProfile(route, gateway)); } - staticRouteProfiles.add(new StaticRouteProfile(route, gateway)); } s_logger.debug("Found " + staticRouteProfiles.size() + " static routes to apply as a part of vpc route " @@ -1052,6 +1055,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return true; } + //exclude static route in Revoke state + Iterator it = staticRoutes.iterator(); + while (it.hasNext()) { + StaticRouteProfile profile = it.next(); + if (profile.getState() == StaticRoute.State.Revoke) { + s_logger.debug("Not sending static route " + profile + " because its in " + StaticRoute.State.Revoke + " state"); + it.remove(); + } + } + boolean result = true; for (VirtualRouter router : routers) { if (router.getState() == State.Running) { diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index fc76d221ea5..b79f2258baf 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -24,6 +24,7 @@ import com.cloud.network.RouterNetworkVO; import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.offering.NetworkOffering; +import com.cloud.offerings.dao.NetworkOfferingDaoImpl; import com.cloud.user.UserStatisticsVO; import com.cloud.user.dao.UserStatisticsDaoImpl; import com.cloud.utils.component.ComponentLocator; @@ -49,6 +50,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase im HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class); RouterNetworkDaoImpl _routerNetworkDao = ComponentLocator.inject(RouterNetworkDaoImpl.class); UserStatisticsDaoImpl _userStatsDao = ComponentLocator.inject(UserStatisticsDaoImpl.class); + NetworkOfferingDaoImpl _offDao = ComponentLocator.inject(NetworkOfferingDaoImpl.class); protected final SearchBuilder VpcSearch; protected DomainRouterDaoImpl() { @@ -277,22 +279,24 @@ public class DomainRouterDaoImpl extends GenericDaoBase im @Override @DB public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) { - if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null && - !guestNetwork.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering)) { - Transaction txn = Transaction.currentTxn(); - txn.start(); - //1) add router to network - RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); - _routerNetworkDao.persist(routerNtwkMap); - //2) create user stats entry for the network - UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), - guestNetwork.getId(), null, router.getId(), router.getType().toString()); - if (stats == null) { - stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), - router.getType().toString(), guestNetwork.getId()); - _userStatsDao.persist(stats); + if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null) { + NetworkOffering off = _offDao.findById(guestNetwork.getNetworkOfferingId()); + if (!(off.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering))) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + //1) add router to network + RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType()); + _routerNetworkDao.persist(routerNtwkMap); + //2) create user stats entry for the network + UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), + guestNetwork.getId(), null, router.getId(), router.getType().toString()); + if (stats == null) { + stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(), + router.getType().toString(), guestNetwork.getId()); + _userStatsDao.persist(stats); + } + txn.commit(); } - txn.commit(); } }