Host capacity calculation: use VM creation time if update time is null.#9662
Conversation
…n capacity calculation. VM update time is nullable in DB and can cause NullPointerException if record in vm_instance has defined last_host_id and undefined update_time.
|
@blueorangutan package |
|
@mprokopchuk a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✖️ debian ✔️ suse15. SL-JID 11063 |
|
@blueorangutan test |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9662 +/- ##
============================================
- Coverage 15.77% 15.77% -0.01%
Complexity 12538 12538
============================================
Files 5621 5621
Lines 491556 491557 +1
Branches 60227 62130 +1903
============================================
Hits 77562 77562
- Misses 405537 405538 +1
Partials 8457 8457
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✖️ debian ✔️ suse15. SL-JID 11066 |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 11070 |
|
@JoaoJandre since this is a bugfix, causing NPE exception can we consider it? |
|
@blueorangutan test |
|
@kiranchavala a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
kiranchavala
left a comment
There was a problem hiding this comment.
LGTM, Steps to reproduce the issue
Before fix
-
Stop a running vm
-
Manually update the database with the following sql query
mysql>update vm_instance set update_time=NULL where id=20;
- Execute the list capacity api call with fetchlatest=true
https://cloudstack.apache.org/api/apidocs-4.19/apis/listCapacity.html
- Null pointer exception in the logs
2024-09-11 09:38:53,428 DEBUG [c.c.a.ApiServlet] (qtp660017404-18:ctx-031e6e67) (logid:4fab4036) ===START=== 10.0.3.251 -- GET apiKey=l1_SR4uC25TftqakF--jG9Su3VhMIeR6nvTZairizwO-ZEx_du9PRQsg8efhUP5THn_4vPM1IfzABYMmfkwYig&command=listCapacity&fetchlatest=true&response=json&signature=T8%2FBKjc9uZmnGlCkiAn21RCy6qU%3D
2024-09-11 09:38:53,456 ERROR [c.c.a.AlertManagerImpl] (qtp660017404-18:ctx-031e6e67 ctx-60961f1a) (logid:4fab4036) Caught exception in recalculating capacity
java.lang.NullPointerException
at com.cloud.capacity.CapacityManagerImpl.updateCapacityForHost(CapacityManagerImpl.java:714)
at com.cloud.alert.AlertManagerImpl.recalculateCapacity(AlertManagerImpl.java:286)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
After fix
- No Null pointer exceptinon observed
Logs
2024-09-11 10:27:01,862 DEBUG [c.c.a.ApiServlet] (qtp253011924-22:[ctx-8d67dfb3]) (logid:91763e20) ===START=== 10.0.3.251 -- GET apiKey=l1_SR4uC25TftqakF--jG9Su3VhMIeR6nvTZairizwO-ZEx_du9PRQsg8efhUP5THn_4vPM1IfzABYMmfkwYi&command=listCapacity&fetchlatest=true&response=json&signature=p5x0bMfDYCzQyGsSHP4v2PSouGc%3D
2024-09-11 10:27:01,932 INFO [c.c.a.ApiServlet] (qtp253011924-22:[ctx-8d67dfb3, ctx-ca9e43a9]) (logid:91763e20) (userId=2 accountId=2 sessionId=node01wqd73ie98jsaho1i4b0xibv4) 10.0.3.251 -- GET apiKey=l1_SR4uC25TftqakF--jG9Su3VhMIeR6nvTZairizwO-ZEx_du9PRQsg8efhUP5THn_4vPM1IfzABYMmfkwYi&command=listCapacity&fetchlatest=true&response=json&signature=p5x0bMfDYCzQyGsSHP4v2PSouGc%3D 200 {"listcapacityresponse":{"count":10,"capacity":[{"type":0,"name":"MEMORY","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityallocated":2684354560,"capacityused":2684354560,"capacitytotal":7228305408,"percentused":"37.14"},{"type":1,"name":"CPU","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityallocated":2000,"capacityused":2000,"capacitytotal":12600,"percentused":"15.87"},{"type":2,"name":"STORAGE","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":1250223456256,"capacitytotal":2197949513728,"percentused":"56.88"},{"type":3,"name":"STORAGE_ALLOCATED","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":24318968016,"capacitytotal":4395899027456,"percentused":"0.55"},{"type":4,"name":"VIRTUAL_NETWORK_PUBLIC_IP","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":3,"capacitytotal":20,"percentused":"15"},{"type":5,"name":"PRIVATE_IP","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":2,"capacitytotal":20,"percentused":"10"},{"type":6,"name":"SECONDARY_STORAGE","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":1250222407680,"capacitytotal":2197949513728,"percentused":"56.88"},{"type":7,"name":"VLAN","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":1,"capacitytotal":20,"percentused":"5"},{"type":19,"name":"GPU","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityused":0,"capacitytotal":0,"percentused":"0"},{"type":90,"name":"CPU_CORE","zoneid":"3d129b60-79b8-43aa-bf87-f06d2341b9aa","zonename":"ref-trl-7311-k-Mol8-kiran-chavala","capacityallocated":4,"capacityused":4,"capacitytotal":3,"percentused":"133.33"}]}}
2024-09-11 10:27:01,932 DEBUG [c.c.a.ApiServlet] (qtp253011924-22:[ctx-8d67dfb3, ctx-ca9e43a9]) (logid:91763e20) ===END=== 10.0.3.251 -- GET apiKey=l1_SR4uC25TftqakF--jG9Su3VhMIeR6nvTZairizwO-ZEx_du9PRQsg8efhUP5THn_4vPM1IfzABYMmfkwYi&command=listCapacity&fetchlatest=true&response=json&signature=p5x0bMfDYCzQyGsSHP4v2PSouGc%3D
|
[SF] Trillian test result (tid-11454)
|
…n capacity calculation. (apache#9662) VM update time is nullable in DB and can cause NullPointerException if record in vm_instance has defined last_host_id and undefined update_time.
CapacityManagementImpl.updateCapacityForHost(..) use VM update time in capacity calculation.
VM update time is nullable in DB and can cause NullPointerException if record in vm_instance has defined last_host_id and undefined update_time.
Added logic to check whether update_time is null and use created time instead (which is not null).
Description
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Tested manually.