Tomas Jelinek has uploaded a new change for review.

Change subject: core: enable migration to a different cluster
......................................................................

core: enable migration to a different cluster

WIP

Change-Id: I9eb4fd7f10d3b0e63455a81f0b5c1389586a43f4
Bug-Url: https://bugzilla.redhat.com/
Signed-off-by: Tomas Jelinek <tjeli...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmToServerParameters.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
M packaging/dbscripts/vms_sp.sql
7 files changed, 59 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/34316/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
index 3e7354b..6aba5ed 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java
@@ -54,6 +54,12 @@
 
     public MigrateVmCommand(T migrateVmParameters, CommandContext cmdContext) {
         super(migrateVmParameters, cmdContext);
+
+        if (migrateVmParameters.getTargetVdsGroupId() != null) {
+            setVdsGroupId(migrateVmParameters.getTargetVdsGroupId());
+            // force reload
+            setVdsGroup(null);
+        }
     }
 
     @Override
@@ -173,9 +179,17 @@
     public void runningSucceded() {
         try {
             getVmDynamicDao().clearMigratingToVds(getVmId());
+            adjustDestinationVdsGroupId();
         }
         finally {
             super.runningSucceded();
+        }
+    }
+
+    private void adjustDestinationVdsGroupId() {
+        if 
(!getVm().getVdsGroupId().equals(getParameters().getTargetVdsGroupId())) {
+            getVmStaticDAO().updateVdsGroupId(getVm().getId(), 
getParameters().getTargetVdsGroupId());
+
         }
     }
 
@@ -207,6 +221,7 @@
         Network migrationNetwork = null;
 
         // Find migrationNetworkCluster
+        // TODO is this valid if the VM is going to be migrated to a different 
cluster?
         List<Network> allNetworksInCluster = 
getNetworkDAO().getAllForCluster(getVm().getVdsGroupId());
 
         for (Network tempNetwork : allNetworksInCluster) {
@@ -271,6 +286,7 @@
                 : _isRerun ?
                         AuditLogType.VM_MIGRATION_TRYING_RERUN
                         : getAuditLogForMigrationFailure();
+
     }
 
     private AuditLogType getAuditLogForMigrationStarted() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java
index e252ca7..34098a1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java
@@ -48,10 +48,6 @@
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_MIGRATION_TO_SAME_HOST);
         }
 
-        if (!vm.getVdsGroupId().equals(getDestinationVds().getVdsGroupId())) {
-            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_MIGRATE_BETWEEN_TWO_CLUSTERS);
-        }
-
         return true;
     }
 
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmParameters.java
index 5cf0d01..6b4d2e6 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmParameters.java
@@ -14,13 +14,19 @@
     protected boolean forceMigrationForNonMigratableVm;
     ArrayList<Guid> initialHosts;
     protected Date startTime;
+    private Guid targetVdsGroupId;
 
     public MigrateVmParameters() {
     }
 
     public MigrateVmParameters(boolean forceMigrationForNonMigratableVM, Guid 
vmId) {
+        this(forceMigrationForNonMigratableVM, vmId, null);
+    }
+
+    public MigrateVmParameters(boolean forceMigrationForNonMigratableVM, Guid 
vmId, Guid targetVdsGroupId) {
         super(vmId);
 
+        this.targetVdsGroupId = targetVdsGroupId;
         setForceMigrationForNonMigratableVm(forceMigrationForNonMigratableVM);
     }
 
@@ -56,4 +62,7 @@
         this.startTime = startTime;
     }
 
+    public Guid getTargetVdsGroupId() {
+        return targetVdsGroupId;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmToServerParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmToServerParameters.java
index 7dd576c..b2a9382 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmToServerParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MigrateVmToServerParameters.java
@@ -6,11 +6,15 @@
     private static final long serialVersionUID = 2378358850714143232L;
     private Guid vdsId;
 
-    public MigrateVmToServerParameters(boolean forceMigration, Guid vmId, Guid 
serverId) {
-        super(forceMigration, vmId);
+    public MigrateVmToServerParameters(boolean forceMigration, Guid vmId, Guid 
serverId, Guid targetVdsGroupId) {
+        super(forceMigration, vmId, targetVdsGroupId);
         vdsId = serverId;
     }
 
+    public MigrateVmToServerParameters(boolean forceMigration, Guid vmId, Guid 
serverId) {
+        this(forceMigration, vmId, serverId, null);
+    }
+
     public Guid getVdsId() {
         return vdsId;
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java
index b2726ed..caefe31 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java
@@ -100,4 +100,12 @@
      * @param cpuProfileId
      */
     void updateVmCpuProfileIdForClusterId(Guid clusterId, Guid cpuProfileId);
+
+    /**
+     * Updates the given VM's vdsGroupId
+     *
+     * @param id Vm id
+     * @param vdsGroupId vds group id
+     */
+    void updateVdsGroupId(Guid id, Guid vdsGroupId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
index 375217b..3122034 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java
@@ -155,6 +155,14 @@
                         .addValue("cpu_profile_id", cpuProfileId));
     }
 
+    @Override
+    public void updateVdsGroupId(Guid id, Guid vdsGroupId) {
+        getCallsHandler().executeModification("UpdateVdsGroupId",
+                getCustomMapSqlParameterSource()
+                        .addValue("vm_id", id)
+                        .addValue("cluster_id", vdsGroupId));
+    }
+
     /**
      * JDBC row mapper for VM static
      */
diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql
index 9892e54..0dbffcf 100644
--- a/packaging/dbscripts/vms_sp.sql
+++ b/packaging/dbscripts/vms_sp.sql
@@ -1399,3 +1399,15 @@
    WHERE vds_group_id = v_cluster_id;
 END; $procedure$
 LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateVdsGroupId(v_vm_id UUID, v_cluster_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+UPDATE vm_static
+   SET vds_group_id = v_cluster_id
+   WHERE vm_guid = v_vm_id;
+END; $procedure$
+LANGUAGE plpgsql;
+


-- 
To view, visit http://gerrit.ovirt.org/34316
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9eb4fd7f10d3b0e63455a81f0b5c1389586a43f4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tomas Jelinek <tjeli...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to