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



##########
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 
   the last commit seems to be not needed.

##########
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()));

Review comment:
       ```suggestion
                   throw new CloudRuntimeException(String.format("The number of 
jobs to add network %s to vm %s are %d", network.getUuid(), 
vm.getInstanceName(), pendingWorkJobs.size()));
   ```

##########
File path: engine/schema/src/main/resources/META-INF/db/schema-41600to41610.sql
##########
@@ -17,4 +17,7 @@
 
 --;
 -- Schema upgrade from 4.16.0.0 to 4.16.1.0
---;
\ No newline at end of file
+--;
+
+ALTER TABLE `cloud`.`vm_work_job` ADD COLUMN `secondary_object` char(100) 
COMMENT 'any additional item that must be checked during queueing' AFTER 
`vm_instance_id`;
+ALTER TABLE `cloud`.`vm_work_job` ADD CONSTRAINT 
`vm_work_job_step_and_objects` UNIQUE KEY 
(`step`,`vm_instance_id`,`secondary_object`);

Review comment:
       ```suggestion
   ```




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