VPC: don't send staticRoutes in Revoke state to the VPC VR

This commit is contained in:
Alena Prokharchyk 2012-07-11 10:35:43 -07:00
parent dd653618fb
commit b8b7d06f15
2 changed files with 37 additions and 20 deletions

View File

@ -872,12 +872,15 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
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<StaticRouteProfile> 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) {

View File

@ -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<DomainRouterVO, Long> 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<DomainRouterVO> VpcSearch;
protected DomainRouterDaoImpl() {
@ -277,22 +279,24 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> 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();
}
}