Citrix Cloud Platform created virtual machines cannot be deleted

Citrix Cloud Platform created virtual machines cannot be deleted

book

Article ID: CTX217560

calendar_today

Updated On:

Description

While attempting to delete virtual machines from ccp we run into the following error:
 

​Unable to schedule async job for command com.cloud.vm.VMWorkStop, 

unexpected exception

Resolution

To resolve the problem perform the following steps. 

 

1) Take a db dump just for precaution using mysqldump 

2) Reproduce the issue while running the following command on the command line of management server 

      #tailf /var/log/cloudstack/management/management-server.log | grep -i duplicate 

 

You will see entries similar to following in output. 

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '8810' for key 'PRIMARY'
 

Note down the number. In the above example it is 8810. We will use this in next step 

3) Now run the below command from mysql prompt. 

delete from vm_work_job where id >= number noted in step 2; 

example in above case 

delete from vm_work_job where id >= 8810; 

Now try to remove or delete the VM


Problem Cause

Looking at the Error code, 1062 it says Duplicate entry 'PRIMARY' 

catch (final SQLException e) { 

if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) { 

throw new EntityExistsException("Entity already exists ", e); 

}
 

It seems its trying to insert a primary key which already exists in database. 

Looking into the DB, I could see there exists an entry in vm_work_job table with the same ID and then it errors out saying. (sample snippet) 

Duplicate entry '121374' for key 'PRIMARY'