RodrigoDLopez opened a new pull request #4085:
URL: https://github.com/apache/cloudstack/pull/4085


   ## Description
   <!--- Describe your changes in detail -->
   Refactor on `UsageManagerImpl.createVPNUserEvent`. Currently, the present 
method creates and removes a VPN user event. So this PR abstract this method 
into an handle, and creates methods to create and delete VPN user events.
   
   Additionally, the new created method prevents duplicated entries for same 
user, with same userId, domainId and zoneId
   
   <!-- For new features, provide link to FS, dev ML discussion etc. -->
   <!-- In case of bug fix, the expected and actual behaviours, steps to 
reproduce. -->
   <!--
   **Used CMK to identify the bug**
   To find out this bug, i used Cloudmonkey with type=14 and raw usage setted 
to 24 hours.
   And then I saw some entries with a lot more of 24 hours per day.
   
   ```
   cloudmonkey list usagerecords startdate="2020-03-07" enddate="2020-03-07" 
type=14 accountid=**
   count = **
   usagerecord:
   account = **
   accountid = **
   description = **
   domainid = **
   enddate = 2020-03-07'T'23:59:59+00:00
   rawusage = 9504
   startdate = 2020-03-07'T'00:00:00+00:00
   usage = 9504 Hrs
   usageid = **
   usagetype = 14
   ```
   And so I query into BD, and find some duplicate entries into 
`cloud_usage.usage.vpn`
   ```
   select * from (select zone_id, domain_id, account_id, user_id, user_name, 
count(*) as count from cloud_usage.usage_vpn_user group by zone_id, domain_id, 
account_id, user_id, user_name) x where x.count >1;
   ```
   -->
   <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be 
closed when this PR gets merged -->
   <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
   <!-- Fixes: # -->
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Put an `x` in all the 
boxes that apply: -->
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [X] Bug fix (non-breaking change which fixes an issue)
   - [X] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ## Screenshots (if appropriate):
   
   ## How Has This Been Tested?
   <!-- Please describe in detail how you tested your changes. -->
   <!-- Include details of your testing environment, and the tests you ran to 
-->
   <!-- see how your change affects other areas of the code, etc. -->
   **environment**
   **Ubuntu 16.04**
   **ACS 4.11.3.0**
   
   **Manual test**
   To test VPN.USER.ADD event I duplicate a entry on `cloud_usage.usage_event ` 
with: 
   type = 'VPN.USER.ADD' 
   and processed = 0
   
   **Expected:** Do not create a entry on `cloud_usage.usage_vpn_user`
   **Result:**
   2020-04-29 21:35:02,011 DEBUG [cloud.usage.UsageManagerImpl] 
(Usage-Job-1:null) (logid:) We do not need to create the usage VPN user [4] 
assigned to account [4] because it already exists.
   
   To test VPN.USER.REMOVE event I duplicate a entry on 
`cloud_usage.usage_event ` with: 
   type = 'VPN.USER.REMOVE' 
   and processed = 0
   
   **Expected:** If we have more than one entry for this event, we will delete 
then all
   **Result:**
   2020-04-30 12:01:29,481 DEBUG [cloud.usage.UsageManagerImpl] 
(Usage-Job-1:null) (logid:) Deleting vpn user [23] assigned to account [4] 
domain [2] and zone [0] that was created at [Thu Apr 30 11:43:52 AMT 2020].
   
   **Result2:**
   2020-04-30 12:16:06,339 WARN  [cloud.usage.UsageManagerImpl] 
(Usage-Job-1:null) (logid:) No usage entry for vpn user [23] assigned to 
account [4] domain [2] and zone [0] was found.
   
   
   <!-- Please read the 
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/master/CONTRIBUTING.md)
 document -->


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to