Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 84E5B200BE4 for ; Wed, 21 Dec 2016 19:42:46 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 838A4160B26; Wed, 21 Dec 2016 18:42:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CEAA5160B18 for ; Wed, 21 Dec 2016 19:42:45 +0100 (CET) Received: (qmail 34764 invoked by uid 500); 21 Dec 2016 18:42:45 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 34748 invoked by uid 99); 21 Dec 2016 18:42:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2016 18:42:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7D9BEDFC15; Wed, 21 Dec 2016 18:42:44 +0000 (UTC) From: sudhansu7 To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org Message-ID: Subject: [GitHub] cloudstack pull request #1850: CLOUDSTACK-9694: Unable to limit the Public I... Content-Type: text/plain Date: Wed, 21 Dec 2016 18:42:44 +0000 (UTC) archived-at: Wed, 21 Dec 2016 18:42:46 -0000 GitHub user sudhansu7 opened a pull request: https://github.com/apache/cloudstack/pull/1850 CLOUDSTACK-9694: Unable to limit the Public IPs in VPC Unable to limit the Public IPs in VPC. In VPC network, while acquiring the IP addresses, in the resource_count table, count for the domain is getting increased. However, when the resource count is updated at Domain level, resource count is getting reverted to only non-vpc ip count. Steps to Reproduce: 1. Create a VPC 2. Create a VPC tier. 3. Check resource_count table and note the ip address count. (say 1) 4. Keep acquiring the IP addresses, (say 4 IP addresses). Now new ip address count resource_count table is 5. 5. update the resource count at domain level. 6. the resource_count is updated back 1 Root Cause: Update resource count command recalculates the resource count. While computing public IP we are not considering the ips allocated to VPC. ResourceLimitManagerImpl.java -> calculatePublicIpForAccount() -> IPAddressDaoImpl.countAllocatedIPsForAccount() Currently we have below query builder. Which does not consider vpc_id column. ``` AllocatedIpCountForAccount = createSearchBuilder(Long.class); AllocatedIpCountForAccount.select(null, Func.COUNT, AllocatedIpCountForAccount.entity().getAddress()); AllocatedIpCountForAccount.and("account", AllocatedIpCountForAccount.entity().getAllocatedToAccountId(), Op.EQ); AllocatedIpCountForAccount.and("allocated", AllocatedIpCountForAccount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCountForAccount.and("network", AllocatedIpCountForAccount.entity().getAssociatedWithNetworkId(), Op.NNULL); AllocatedIpCountForAccount.done(); ``` it generates below sql query ``` SELECT COUNT(user_ip_address.public_ip_address) FROM user_ip_address WHERE user_ip_address.account_id = 6 AND user_ip_address.allocated IS NOT NULL AND user_ip_address.network_id IS NOT NULL AND user_ip_address.removed IS NULL ``` Fix: Add vpc_id check in query. ``` AllocatedIpCountForAccount = createSearchBuilder(Long.class); AllocatedIpCountForAccount.select(null, Func.COUNT, AllocatedIpCountForAccount.entity().getAddress()); AllocatedIpCountForAccount.and("account", AllocatedIpCountForAccount.entity().getAllocatedToAccountId(), Op.EQ); AllocatedIpCountForAccount.and("allocated", AllocatedIpCountForAccount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCountForAccount.and().op("network", AllocatedIpCountForAccount.entity().getAssociatedWithNetworkId(), Op.NNULL); AllocatedIpCountForAccount.or("vpc", AllocatedIpCountForAccount.entity().getVpcId(), Op.NNULL); AllocatedIpCountForAccount.cp(); AllocatedIpCountForAccount.done(); ``` SQL: ``` SELECT COUNT(user_ip_address.public_ip_address) FROM user_ip_address WHERE user_ip_address.account_id = 6 AND user_ip_address.allocated IS NOT NULL AND ( user_ip_address.network_id IS NOT NULL or user_ip_address.vpc_id IS NOT NULL) AND user_ip_address.removed IS NULL ``` You can merge this pull request into a Git repository by running: $ git pull https://github.com/sudhansu7/cloudstack CLOUDSTACK-9694 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cloudstack/pull/1850.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1850 ---- commit 24837f655033583388bb608f63039f8e341c16d3 Author: Sudhansu Date: 2016-12-21T18:24:01Z CLOUDSTACK-9694: Unable to limit the Public IPs in VPC Added missing clause to check for vpc_id ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---