package org.ovirt.engine.core.bll;

import org.ovirt.engine.core.common.action.InternalMigrateVmParameters;
import org.ovirt.engine.core.common.action.MigrateVmParameters;
import org.ovirt.engine.core.common.businessentities.MigrationSupport;
import org.ovirt.engine.core.common.errors.VdcBllMessages;

@LockIdNameAttribute(isReleaseAtEndOfExecute = false)
@InternalCommandAttribute
public class InternalMigrateVmCommand<T extends InternalMigrateVmParameters> extends MigrateVmCommand<MigrateVmParameters> {

    public InternalMigrateVmCommand(T parameters) {
        super(new MigrateVmParameters(parameters));
    }

    @Override
    protected void executeCommand() {
        try {
            super.executeCommand();
            setActionReturnValue(true);
            setSucceeded(true);
        } catch (java.lang.Exception e) {
            setActionReturnValue(false);
        }
    }

    /**
     * Internal migrate command is initiated by server.
     * if the VM's migration support is not set to {@link MigrationSupport.MIGRATABLE},
     * the internal migration command should fail
     */
    @Override
    protected boolean canDoAction() {
        if (getVm().getMigrationSupport() == MigrationSupport.MIGRATABLE) {
            return super.canDoAction();
        }

        return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NON_MIGRTABLE);
    }
}

@@ -1145,24 +1145,97 @@
 oAction() %7B%0A
+        if (!super.canDoAction()) %7B%0A            return false;%0A        %7D%0A%0A
         if (
@@ -1264,17 +1264,17 @@
 pport() 
-=
+!
 = Migrat
@@ -1306,55 +1306,8 @@
     
-        return super.canDoAction();%0A        %7D%0A%0A
     
@@ -1389,16 +1389,48 @@
 TABLE);%0A
+        %7D%0A%0A        return true;%0A
     %7D%0A%7D%0A

fix possible NPE in internal migration