@Override public StaticRoute getStaticRoute(final long routeId) { return _staticRouteDao.findById(routeId); }
for (final StaticRoute route : routes) { if (route.getState() == StaticRoute.State.Revoke) { _staticRouteDao.remove(route.getId()); s_logger.debug("Removed route " + route + " from the DB"); } else if (route.getState() == StaticRoute.State.Add) { final StaticRouteVO ruleVO = _staticRouteDao.findById(route.getId()); ruleVO.setState(StaticRoute.State.Active); _staticRouteDao.update(ruleVO.getId(), ruleVO); s_logger.debug("Marked route " + route + " with state " + StaticRoute.State.Active);
protected void markStaticRouteForRevoke(final StaticRouteVO route, final Account caller) { s_logger.debug("Revoking static route " + route); if (caller != null) { _accountMgr.checkAccess(caller, null, false, route); } if (route.getState() == StaticRoute.State.Staged) { if (s_logger.isDebugEnabled()) { s_logger.debug("Found a static route that is still in stage state so just removing it: " + route); } _staticRouteDao.remove(route.getId()); } else if (route.getState() == StaticRoute.State.Add || route.getState() == StaticRoute.State.Active) { route.setState(StaticRoute.State.Revoke); _staticRouteDao.update(route.getId(), route); s_logger.debug("Marked static route " + route + " with state " + StaticRoute.State.Revoke); } }
@Override public StaticRouteVO doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException { StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId()); s_logger.debug("Adding static route " + newRoute); newRoute = _staticRouteDao.persist(newRoute); detectRoutesConflict(newRoute); if (!_staticRouteDao.setStateToAdd(newRoute)) { throw new CloudRuntimeException("Unable to update the state to add for " + newRoute); } CallContext.current().setEventDetails("Static route Id: " + newRoute.getId()); return newRoute; } });
final Filter searchFilter = new Filter(StaticRouteVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal()); final SearchBuilder<StaticRouteVO> sb = _staticRouteDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); final Pair<List<StaticRouteVO>, Integer> result = _staticRouteDao.searchAndCount(sc, searchFilter); return new Pair<List<? extends StaticRoute>, Integer>(result.first(), result.second());
@DB protected boolean revokeStaticRoutesForVpc(final long vpcId, final Account caller) throws ResourceUnavailableException { // get all static routes for the vpc final List<StaticRouteVO> routes = _staticRouteDao.listByVpcId(vpcId); s_logger.debug("Found " + routes.size() + " to revoke for the vpc " + vpcId); if (!routes.isEmpty()) { // mark all of them as revoke Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { for (final StaticRouteVO route : routes) { markStaticRouteForRevoke(route, caller); } } }); return applyStaticRoutesForVpc(vpcId); } return true; }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { // don't allow to remove gateway when there are static // routes associated with it final long routeCount = _staticRouteDao.countRoutesByGateway(gatewayVO.getId()); if (routeCount > 0) { throw new CloudRuntimeException("Can't delete private gateway " + gatewayVO + " as it has " + routeCount + " static routes applied. Remove the routes first"); } gatewayVO.setState(VpcGateway.State.Deleting); _vpcGatewayDao.update(gatewayVO.getId(), gatewayVO); s_logger.debug("Marked gateway " + gatewayVO + " with state " + VpcGateway.State.Deleting); } });
protected void detectRoutesConflict(final StaticRoute newRoute) throws NetworkRuleConflictException { // Multiple private gateways can exist within Vpc. Check for conflicts // for all static routes in Vpc // and not just the gateway final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcIdAndNotRevoked(newRoute.getVpcId()); assert routes.size() >= 1 : "For static routes, we now always first persist the route and then check for " + "network conflicts so we should at least have one rule at this point."; for (final StaticRoute route : routes) { if (route.getId() == newRoute.getId()) { continue; // Skips my own route. } if (NetUtils.isNetworksOverlap(route.getCidr(), newRoute.getCidr())) { throw new NetworkRuleConflictException("New static route cidr conflicts with existing route " + route); } } }
@Override public boolean applyStaticRoutesForVpc(final long vpcId) throws ResourceUnavailableException { final Account caller = CallContext.current().getCallingAccount(); final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(vpcId); return applyStaticRoutes(routes, caller, true); }
public static StaticRouteVO findStaticRouteById(long routeId) { return s_staticRouteDao.findById(routeId); }
final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(domainRouterVO.getVpcId()); final List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size()); final Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
@Override @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_CREATE, eventDescription = "Applying static route", async = true) public boolean applyStaticRoute(final long routeId) throws ResourceUnavailableException { final StaticRoute route = _staticRouteDao.findById(routeId); return applyStaticRoutesForVpc(route.getVpcId()); }
@Override @ActionEvent(eventType = EventTypes.EVENT_STATIC_ROUTE_DELETE, eventDescription = "deleting static route") public boolean revokeStaticRoute(final long routeId) throws ResourceUnavailableException { final Account caller = CallContext.current().getCallingAccount(); final StaticRouteVO route = _staticRouteDao.findById(routeId); if (route == null) { throw new InvalidParameterValueException("Unable to find static route by id"); } _accountMgr.checkAccess(caller, null, false, route); markStaticRouteForRevoke(route, caller); return applyStaticRoutesForVpc(route.getVpcId()); }