package org.ovirt.engine.core.vdsbroker;

import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.common.vdscommands.AddVdsVDSCommandParameters;
import org.ovirt.engine.core.dal.dbbroker.DbFacade;
import org.ovirt.engine.core.utils.ThreadUtils;
import org.ovirt.engine.core.utils.log.Log;
import org.ovirt.engine.core.utils.log.LogFactory;
import org.ovirt.engine.core.utils.transaction.TransactionMethod;
import org.ovirt.engine.core.utils.transaction.TransactionSupport;

public class AddVdsVDSCommand<P extends AddVdsVDSCommandParameters> extends VdsIdVDSCommandBase<P> {
    public AddVdsVDSCommand(P parameters) {
        super(parameters);
    }

    @Override
    protected void ExecuteVdsIdCommand() {
        VDS vds = null;
        log.infoFormat("AddVds - entered , starting logic to add VDS {0}", getVdsId());
        do {
            vds = TransactionSupport.executeInNewTransaction(new TransactionMethod<VDS>() {
                @Override
                public VDS runInTransaction() {
                    return DbFacade.getInstance().getVdsDao().get(getVdsId());
                }
            });

            if (vds == null) {
                log.infoFormat(
                        "AddVds - failed to get VDS by Id {0}, it was not yet added, going to sleep for 1.5 sec",
                        getVdsId());
                ThreadUtils.sleep(1500);
            }
        } while (vds == null);
        log.infoFormat("AddVds - VDS {0} was added, will try to add it to the resource manager",
                getVdsId());
        ResourceManager.getInstance().AddVds(vds, false);
    }

    private static Log log = LogFactory.getLog(AddVdsVDSCommand.class);
}

@@ -225,56 +225,8 @@
 de;%0A
-import org.ovirt.engine.core.utils.ThreadUtils;%0A
 impo
@@ -319,141 +319,8 @@
 ory;
-%0Aimport org.ovirt.engine.core.utils.transaction.TransactionMethod;%0Aimport org.ovirt.engine.core.utils.transaction.TransactionSupport;
 %0A%0Apu
@@ -557,32 +557,8 @@
 ) %7B%0A
-        VDS vds = null;%0A
     
@@ -653,590 +653,67 @@
     
-do %7B%0A            vds = TransactionSupport.executeInNewTransaction(new TransactionMethod%3CVDS%3E() %7B%0A                @Override%0A                public VDS runInTransaction() %7B%0A                    return DbFacade.getInstance().getVdsDao().get(getVdsId());%0A                %7D%0A            %7D);%0A%0A            if (vds == null) %7B%0A                log.infoFormat(%0A                        %22AddVds - failed to get VDS by Id %7B0%7D, it was not yet added, going to sleep for 1.5 sec%22,%0A                        getVdsId());%0A                ThreadUtils.sleep(1500);%0A            %7D%0A        %7D while (vds == null
+VDS vds = DbFacade.getInstance().getVdsDao().get(getVdsId()
 );%0A 

Clean up of AddVdsVDSCommand