Ensure the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance by sureshanaparti · Pull Request #13492 · apache/cloudstack · GitHub
Skip to content

Ensure the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance#13492

Open
sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:vnc-detail-update-db-error-fix
Open

Ensure the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance#13492
sureshanaparti wants to merge 1 commit into
apache:4.22from
shapeblue:vnc-detail-update-db-error-fix

Conversation

@sureshanaparti

Copy link
Copy Markdown
Contributor

Description

This PR ensures the detail value is not null when updating the VNC access details of the VMs with failed migrations on Host maintenance. It fixes the Constraint error "Column 'value' cannot be null" while updating the VNC access details.

Failed error log below (noticed with 4.18).

2026-06-24 14:28:55,686 DEBUG [c.c.a.t.Request] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) Seq 2-6593551329447135922: Sending  { Cmd , MgmtId: 32988519727921, via: 2(ref-trl-11982-k-Mol8-vladimir-petrov-kvm2), Ver: v1, Flags: 100011, [{"com.cloud.agent.api.GetVncPortCommand":{"id":"13","name":"i-2-13-VM","wait":"0","bypassHostMaintenance":"false"}}] }
2026-06-24 14:28:55,704 DEBUG [c.c.c.ConsoleProxyManagerImpl] (consoleproxy-1:ctx-790c7a65) (logid:62b6d880) Enabled non-edge zones available for scan: 1
2026-06-24 14:28:55,707 INFO  [c.c.c.ClusterManagerImpl] (Cluster-Heartbeat-1:ctx-539a9269) (logid:a328a129) No inactive management server node found
2026-06-24 14:28:55,707 DEBUG [c.c.c.ClusterManagerImpl] (Cluster-Heartbeat-1:ctx-539a9269) (logid:a328a129) Peer scan is finished. profiler: Done. Duration: 1ms , profilerQueryActiveList: Done. Duration: 0ms, , profilerSyncClusterInfo: Done. Duration: 0ms, profilerInvalidatedNodeList: Done. Duration: 0ms, profilerRemovedList: Done. Duration: 0ms,, profilerNewList: Done. Duration: 0ms, profilerInactiveList: Done. Duration: 0ms
2026-06-24 14:28:55,710 DEBUG [c.c.c.ConsoleProxyManagerImpl] (consoleproxy-1:ctx-790c7a65) (logid:62b6d880) Zone Zone {"id": "1", "name": "ref-trl-11982-k-Mol8-vladimir-petrov", "uuid": "9b5b1c23-e596-41e2-8cc1-7291af9608c0"} is ready to launch console proxy
2026-06-24 14:28:55,847 DEBUG [c.c.a.t.Request] (AgentManager-Handler-17:null) (logid:) Seq 2-6593551329447135922: Processing:  { Ans: , MgmtId: 32988519727921, via: 2, Ver: v1, Flags: 10, [{"com.cloud.agent.api.GetVncPortAnswer":{"port":"0","result":"false","details":"org.libvirt.LibvirtException: Domain not found: no domain with matching name 'i-2-13-VM'","wait":"0","bypassHostMaintenance":"false"}}] }
2026-06-24 14:28:55,848 DEBUG [c.c.a.t.Request] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) Seq 2-6593551329447135922: Received:  { Ans: , MgmtId: 32988519727921, via: 2(ref-trl-11982-k-Mol8-vladimir-petrov-kvm2), Ver: v1, Flags: 10, { GetVncPortAnswer } }
2026-06-24 14:28:55,848 DEBUG [c.c.a.m.AgentManagerImpl] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) Details from executing class com.cloud.agent.api.GetVncPortCommand: org.libvirt.LibvirtException: Domain not found: no domain with matching name 'i-2-13-VM'
2026-06-24 14:28:55,854 ERROR [c.c.u.d.GenericDaoBase] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) DB Exception on: HikariProxyPreparedStatement@1962527570 wrapping com.mysql.cj.jdbc.ServerPreparedStatement[350]: INSERT INTO user_vm_details (user_vm_details.vm_id, user_vm_details.name, user_vm_details.value, user_vm_details.display) VALUES (13, x'6b766d2e766e632e61646472657373', NULL, 1)
java.sql.SQLIntegrityConstraintViolationException: Column 'value' cannot be null
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
        at com.mysql.cj.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:555)
        at com.mysql.cj.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:339)
        at com.mysql.cj.jdbc.ClientPrepa	redStatement.executeUpdateInternal(ClientPreparedStatement.java:1061)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
        at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1602)
        at org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase.addDetail(ResourceDetailsDaoBase.java:179)
        at com.cloud.vm.dao.UserVmDetailsDaoImpl.addDetail(UserVmDetailsDaoImpl.java:31)
        at jdk.internal.reflect.GeneratedMethodAccessor609.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at com.cloud.utils.db.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:34)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy75.addDetail(Unknown Source)
        at com.cloud.resource.ResourceManagerImpl.setKVMVncAccess(ResourceManagerImpl.java:1688)
        at com.cloud.resource.ResourceManagerImpl.configureVncAccessForKVMHostFailedMigrations(ResourceManagerImpl.java:1700)
        at com.cloud.resource.ResourceManagerImpl.setHostIntoErrorInPrepareForMaintenance(ResourceManagerImpl.java:1732)
        at com.cloud.resource.ResourceManagerImpl.attemptMaintain(ResourceManagerImpl.java:1807)
        at com.cloud.resource.ResourceManagerImpl.checkAndMaintain(ResourceManagerImpl.java:1826)
        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)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy208.checkAndMaintain(Unknown Source)
        at com.cloud.resource.ResourceManagerImpl.setKVMVncAccess(ResourceManagerImpl.java:1688)
        at com.cloud.resource.ResourceManagerImpl.configureVncAccessForKVMHostFailedMigrations(ResourceManagerImpl.java:1700)
        at com.cloud.resource.ResourceManagerImpl.setHostIntoErrorInPrepareForMaintenance(ResourceManagerImpl.java:1732)
        at com.cloud.resource.ResourceManagerImpl.attemptMaintain(ResourceManagerImpl.java:1807)
        at com.cloud.resource.ResourceManagerImpl.checkAndMaintain(ResourceManagerImpl.java:1826)
        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)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy208.checkAndMaintain(Unknown Source)
        at com.cloud.agent.manager.AgentManagerImpl$MonitorTask.runInContext(AgentManagerImpl.java:1935)
        at org.apache.cloudstack.managed.context.ManagedContextRunnable$1.run(ManagedContextRunnable.java:48)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:55)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:102)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:52)
        at org.apache.cloudstack.managed.context.ManagedContextRunnable.run(ManagedContextRunnable.java:45)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)
2026-06-24 14:28:55,856 DEBUG [c.c.u.d.T.Transaction] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) Rolling back the transaction: Time = 5 Name =  AgentMonitor-1; called by -TransactionLegacy.rollback:895-TransactionLegacy.removeUpTo:838-TransactionLegacy.close:662-TransactionContextInterceptor.invoke:36-ReflectiveMethodInvocation.proceed:175-ExposeInvocationInterceptor.invoke:97-ReflectiveMethodInvocation.proceed:186-JdkDynamicAopProxy.invoke:215-$Proxy75.addDetail:-1-ResourceManagerImpl.setKVMVncAccess:1688-ResourceManagerImpl.configureVncAccessForKVMHostFailedMigrations:1700-ResourceManagerImpl.setHostIntoErrorInPrepareForMaintenance:1732
2026-06-24 14:28:55,857 ERROR [c.c.a.m.AgentManagerImpl] (AgentMonitor-1:ctx-f1869124) (logid:98e99c06) Caught the following exception:
com.cloud.utils.exception.CloudRuntimeException: Unable to persist on DB, due to: Column 'value' cannot be null
        at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1642)
        at org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase.addDetail(ResourceDetailsDaoBase.java:179)
        at com.cloud.vm.dao.UserVmDetailsDaoImpl.addDetail(UserVmDetailsDaoImpl.java:31)
        at jdk.internal.reflect.GeneratedMethodAccessor609.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at com.cloud.utils.db.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:34)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy75.addDetail(Unknown Source)
        at com.cloud.resource.ResourceManagerImpl.setKVMVncAccess(ResourceManagerImpl.java:1688)
        at com.cloud.resource.ResourceManagerImpl.configureVncAccessForKVMHostFailedMigrations(ResourceManagerImpl.java:1700)
        at com.cloud.resource.ResourceManagerImpl.setHostIntoErrorInPrepareForMaintenance(ResourceManagerImpl.java:1732)
        at com.cloud.resource.ResourceManagerImpl.attemptMaintain(ResourceManagerImpl.java:1807)
        at com.cloud.resource.ResourceManagerImpl.checkAndMaintain(ResourceManagerImpl.java:1826)
        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)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
        at com.sun.proxy.$Proxy208.checkAndMaintain(Unknown Source)
        at com.cloud.agent.manager.AgentManagerImpl$MonitorTask.runInContext(AgentManagerImpl.java:1935)
        at org.apache.cloudstack.managed.context.ManagedContextRunnable$1.run(ManagedContextRunnable.java:48)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:55)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:102)
        at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:52)
        at org.apache.cloudstack.managed.context.ManagedContextRunnable.run(ManagedContextRunnable.java:45)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

…ils of the vms with failed migrations on host maintenance

- Fixes the Constraint error Column 'value' cannot be null
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a host-maintenance edge case where updating KVM VNC access VM details can attempt to persist a null value, triggering DB constraint failures (e.g., Column 'value' cannot be null). It does so by adding validation around the GetVncPortAnswer before writing kvm.vnc.* details, plus small supporting updates in tests and KVM agent-side logging.

Changes:

  • Refactors VNC detail persistence in ResourceManagerImpl into a helper that validates the GetVncPortAnswer before writing VM details.
  • Updates ResourceManagerImplTest mocks to reflect the new getResult()-gated behavior.
  • Adds an error log in the KVM Libvirt GetVncPort command wrapper when libvirt throws.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
server/src/main/java/com/cloud/resource/ResourceManagerImpl.java Adds guarded VNC detail update logic to avoid persisting null/invalid values from GetVncPortAnswer.
server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java Adjusts test setup to return successful GetVncPortAnswer results under the new logic.
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVncPortCommandWrapper.java Adds logging when libvirt fails to resolve VNC port details for a VM.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1838 to 1851
if (!vmVncPortAnswer.getResult()) {
logger.warn("Failed to get VNC port for VM {} on host {}. Details: {}", vm, hostId, vmVncPortAnswer.getDetails());
return;
}

String vncAddress = vmVncPortAnswer.getAddress();
String vncPort = String.valueOf(vmVncPortAnswer.getPort());
if (org.apache.commons.lang3.StringUtils.isNotBlank(vmVncPortAnswer.getAddress()) && org.apache.commons.lang3.StringUtils.isNotBlank(vncPort)) {
logger.info("Setting VNC access details for VM {} on host {} to address: {}, port: {}", vm, hostId, vncAddress, vncPort);
vmInstanceDetailsDao.addDetail(vm.getId(), VmDetailConstants.KVM_VNC_ADDRESS, vncAddress, true);
vmInstanceDetailsDao.addDetail(vm.getId(), VmDetailConstants.KVM_VNC_PORT, vncPort, true);
} else {
logger.warn("Unable to set VNC access details for VM {} on host {} as the address or port is blank. Address: {}, Port: {}", vm, hostId, vncAddress, vncPort);
}
Comment thread server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
Comment on lines +44 to 45
logger.error("Failed to get vnc port for the vm: {} due to {}", command.getName(), e.getMessage());
return new GetVncPortAnswer(command, e.toString());
@sureshanaparti

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@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.

@blueorangutan

Copy link
Copy Markdown

@weizhouapache weizhouapache added this to the 4.22.2 milestone Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants