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/08/16 16:30:19 UTC

[GitHub] [cloudstack] GutoVeronezi commented on a change in pull request #5227: Store Vm migration details in db

GutoVeronezi commented on a change in pull request #5227:
URL: https://github.com/apache/cloudstack/pull/5227#discussion_r689684461



##########
File path: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -2580,15 +2585,51 @@ private void removeStaleVmFromSource(VMInstanceVO vm, HostVO srcHost) {
         }
     }
 
+    private void createRecord(VMInstanceVO vmInstance,
+                              Account caller,
+                              String srcHost,
+                              String dstHost,
+                              VmMigrationEvent.State state,
+                              String description) {
+        VmMigrationVO vmMigrationVO = new VmMigrationVO(state,
+                vmInstance.getInstanceName(),
+                vmInstance.getId(),
+                description,
+                vmInstance.getType().toString(),
+                srcHost,
+                dstHost,
+                new Date(),
+                caller.getAccountName(),
+                caller.getAccountId(),
+                caller.getDomainId());
+
+        _vmMigrationDao.persist(vmMigrationVO);
+    }
+
+    private void initVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Starting migration of vm " + vmInstance.instanceName;

Review comment:
       We could use String.format here.

##########
File path: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -2636,7 +2682,8 @@ private void orchestrateMigrate(final String vmUuid, final long srcHostId, final
     }
 
     protected void migrate(final VMInstanceVO vm, final long srcHostId, final DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException {
-        s_logger.info("Migrating " + vm + " to " + dest);
+        s_logger.info("Migrating " + vm + " to " + dest + " from source host id : " + srcHostId);

Review comment:
       We could use String.format here.

##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java
##########
@@ -120,13 +120,22 @@ public String getEventType() {
     @Override
     public String getEventDescription() {
         String eventDescription;
+        Long sourceHostId = 0L;
+
+        UserVm userVm = _entityMgr.findById(UserVm.class, getVirtualMachineId());
+        if (userVm != null) {
+            sourceHostId = userVm.getHostId();
+        }
         if (getHostId() != null) {
             eventDescription = String.format("Attempting to migrate VM id: %s to host Id: %s", getVirtualMachineId(), getHostId());
         } else if (getStoragePoolId() != null) {
             eventDescription = String.format("Attempting to migrate VM id: %s to storage pool Id: %s", getVirtualMachineId(), getStoragePoolId());
         } else {
             eventDescription = String.format("Attempting to migrate VM id: %s", getVirtualMachineId());
         }
+        if (sourceHostId != 0L) {
+            eventDescription = eventDescription + " from host id: " + sourceHostId;

Review comment:
       We could use `String.format` here.

##########
File path: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -2580,15 +2585,51 @@ private void removeStaleVmFromSource(VMInstanceVO vm, HostVO srcHost) {
         }
     }
 
+    private void createRecord(VMInstanceVO vmInstance,
+                              Account caller,
+                              String srcHost,
+                              String dstHost,
+                              VmMigrationEvent.State state,
+                              String description) {
+        VmMigrationVO vmMigrationVO = new VmMigrationVO(state,
+                vmInstance.getInstanceName(),
+                vmInstance.getId(),
+                description,
+                vmInstance.getType().toString(),
+                srcHost,
+                dstHost,
+                new Date(),
+                caller.getAccountName(),
+                caller.getAccountId(),
+                caller.getDomainId());
+
+        _vmMigrationDao.persist(vmMigrationVO);
+    }
+
+    private void initVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Starting migration of vm " + vmInstance.instanceName;
+        createRecord(vmInstance, caller, srcHost, dstHost, VmMigrationEvent.State.Started, description);
+    }
+
+    private void completeVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Completed migration of vm " + vmInstance.instanceName;
+        createRecord(vmInstance, caller, srcHost, dstHost, VmMigrationEvent.State.Completed, description);
+    }
+
+    private void failedVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Unable to migrate the vm " + vmInstance.instanceName;

Review comment:
       We could use String.format here.

##########
File path: engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -2580,15 +2585,51 @@ private void removeStaleVmFromSource(VMInstanceVO vm, HostVO srcHost) {
         }
     }
 
+    private void createRecord(VMInstanceVO vmInstance,
+                              Account caller,
+                              String srcHost,
+                              String dstHost,
+                              VmMigrationEvent.State state,
+                              String description) {
+        VmMigrationVO vmMigrationVO = new VmMigrationVO(state,
+                vmInstance.getInstanceName(),
+                vmInstance.getId(),
+                description,
+                vmInstance.getType().toString(),
+                srcHost,
+                dstHost,
+                new Date(),
+                caller.getAccountName(),
+                caller.getAccountId(),
+                caller.getDomainId());
+
+        _vmMigrationDao.persist(vmMigrationVO);
+    }
+
+    private void initVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Starting migration of vm " + vmInstance.instanceName;
+        createRecord(vmInstance, caller, srcHost, dstHost, VmMigrationEvent.State.Started, description);
+    }
+
+    private void completeVmMigrateRecord(VMInstanceVO vmInstance, Account caller, String srcHost, String dstHost) {
+        String description = "Completed migration of vm " + vmInstance.instanceName;

Review comment:
       We could use String.format here.




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