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); } } }
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);
@Override public void create() throws ResourceAllocationException { try { StaticRoute result = _vpcService.createStaticRoute(getGatewayId(), getCidr()); setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { s_logger.info("Network rule conflict: " + ex.getMessage()); s_logger.trace("Network rule conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } }
public StaticRouteProfile(StaticRoute staticRoute, VpcGateway gateway) { id = staticRoute.getId(); uuid = staticRoute.getUuid(); targetCidr = staticRoute.getCidr(); accountId = staticRoute.getAccountId(); domainId = staticRoute.getDomainId(); gatewayId = staticRoute.getVpcGatewayId(); state = staticRoute.getState(); vpcId = staticRoute.getVpcId(); vlanTag = gateway.getBroadcastUri(); this.gateway = gateway.getGateway(); netmask = gateway.getNetmask(); ipAddress = gateway.getIp4Address(); }
@Override public StaticRouteResponse createStaticRouteResponse(StaticRoute result) { StaticRouteResponse response = new StaticRouteResponse(); response.setId(result.getUuid()); if (result.getVpcId() != null) { Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId()); if (vpc != null) { response.setVpcId(vpc.getUuid()); } } response.setCidr(result.getCidr()); StaticRoute.State state = result.getState(); if (state.equals(StaticRoute.State.Revoke)) { state = StaticRoute.State.Deleting; } response.setState(state.toString()); populateAccount(response, result.getAccountId()); populateDomain(response, result.getDomainId()); // set tag information List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId()); List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>(); for (ResourceTag tag : tags) { ResourceTagResponse tagResponse = createResourceTagResponse(tag, true); CollectionUtils.addIgnoreNull(tagResponses,tagResponse); } response.setTags(tagResponses); response.setObjectName("staticroute"); return response; }