weizhouapache commented on a change in pull request #5658:
URL: https://github.com/apache/cloudstack/pull/5658#discussion_r778060406



##########
File path: 
engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -5631,35 +5640,72 @@ private void 
checkConcurrentJobsPerDatastoreThreshhold(final StoragePool destPoo
 
         final List<VmWorkJobVO> pendingWorkJobs = 
_workJobDao.listPendingWorkJobs(
                 VirtualMachine.Type.Instance, vm.getId(),
-                VmWorkAddVmToNetwork.class.getName());
+                VmWorkAddVmToNetwork.class.getName(), network.getUuid());
 
         VmWorkJobVO workJob = null;
         if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
-            assert pendingWorkJobs.size() == 1;
+            if (pendingWorkJobs.size() > 1) {
+                s_logger.warn(String.format("The number of jobs to add network 
%s to vm %s are %d", network.getUuid(), vm.getInstanceName(), 
pendingWorkJobs.size()));
+            }
             workJob = pendingWorkJobs.get(0);
         } else {
+            if (s_logger.isTraceEnabled()) {
+                s_logger.trace(String.format("no jobs to add network %s for vm 
%s yet", network, vm));
+            }
 
-            workJob = new VmWorkJobVO(context.getContextId());
+            workJob = createVmWorkJobToAddNetwork(vm, network, requested, 
context, user, account);
+        }
+        
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
 
-            workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
-            workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
+        if (s_logger.isTraceEnabled()) {
+            s_logger.trace(String.format("job %s to add network %s for vm %s 
processed", workJob.toString(), network, vm));
+        }
+        if (workJob.getStep() == VmWorkJobVO.Step.Done ||
+            workJob.getStep() == VmWorkJobVO.Step.Error ||
+            workJob.getStep() == VmWorkJobVO.Step.Release) {
+            _workJobDao.expunge(workJob.getId());
+        }

Review comment:
       @DaanHoogland 
   I suggest you to try to reproduce the issue #5499 without last commit.
   
   ps: I  found that some vm work jobs are in `Filed` step even if job is 
finished.




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

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

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


Reply via email to