You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/09/30 14:52:28 UTC

[GitHub] [cloudstack] weizhouapache commented on a change in pull request #5541: parallel nic adding

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



##########
File path: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -5618,35 +5631,76 @@ 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;
-            workJob = pendingWorkJobs.get(0);
+            if (pendingWorkJobs.size() > 0) {
+                s_logger.warn(String.format("number of jobs to add net %s to vm %s are %d", network.getUuid(), vm.getInstanceName(), pendingWorkJobs.size()));
+            }
+            workJob = fetchOrCreateVmWorkJobToAddNetwork(vm, network, requested, context, user, account, pendingWorkJobs);
         } 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());
+        return new VmJobVirtualMachineOutcome(workJob, vm.getId());
+    }
 
-            workJob.setAccountId(account.getId());
-            workJob.setUserId(user.getId());
-            workJob.setVmType(VirtualMachine.Type.Instance);
-            workJob.setVmInstanceId(vm.getId());
-            workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
+    private VmWorkJobVO fetchOrCreateVmWorkJobToAddNetwork(
+            VirtualMachine vm,
+            Network network,
+            NicProfile requested,
+            CallContext context,
+            User user,
+            Account account,
+            List<VmWorkJobVO> pendingWorkJobs) {
+        VmWorkJobVO workJob = null;
+        for (VmWorkJobVO job : pendingWorkJobs) {
+            if (network.getUuid().equals(job.getSecondaryObjectIdentifier())) {

Review comment:
       @DaanHoogland 
   do it need to check network uuid here ?
   you have already list vm work jobs by vmid and network uuid.
   ```
           final List<VmWorkJobVO> pendingWorkJobs = _workJobDao.listPendingWorkJobs(
                   VirtualMachine.Type.Instance, vm.getId(),
                   VmWorkAddVmToNetwork.class.getName(), network.getUuid());
   ```




-- 
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-unsubscribe@cloudstack.apache.org

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