Tal Nisan has uploaded a new change for review.

Change subject: core: Allow force re-election of a specific host as SPM
......................................................................

core: Allow force re-election of a specific host as SPM

Allow the user to select a non SPM host and force elect it as SPM and
resigning the previous elected SPM

Change-Id: Iab31fc7918b10448b923821547a583f3d6c3fcba
Bug-Url: https://bugzilla.redhat.com/629034
Signed-off-by: Tal Nisan <[email protected]>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ReinitializeSPMCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveStoragePoolCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandAssertUtils.java
A 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ReinitializeSPMCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/ReinitializeSPMParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/ResetIrsVDSCommandParameters.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/ResetIrsVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommand.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommandParameters.java
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostListModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabHostView.java
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
23 files changed, 451 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/16105/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ReinitializeSPMCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ReinitializeSPMCommand.java
new file mode 100644
index 0000000..af4ad80
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ReinitializeSPMCommand.java
@@ -0,0 +1,103 @@
+package org.ovirt.engine.core.bll;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.action.ReinitializeSPMParameters;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
+import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
+import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
+import org.ovirt.engine.core.compat.Guid;
+import 
org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters;
+
+@NonTransactiveCommandAttribute
+public class ReinitializeSPMCommand<T extends ReinitializeSPMParameters> 
extends CommandBase<T> {
+
+    public ReinitializeSPMCommand(T parameters) {
+        super(parameters);
+        setVdsId(getParameters().getPreferredSPMId());
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        if (getVds() == null) {
+            return failCanDoAction(VdcBllMessages.VDS_NOT_EXIST);
+        }
+
+        if (getVds().getStatus() != VDSStatus.Up) {
+            return failCanDo(VdcBllMessages.CANNOT_REINIT_SPM_VDS_NOT_UP);
+        }
+
+        if (getParameters().getStoragePoolId() == null
+                || 
!getParameters().getStoragePoolId().equals(getVds().getStoragePoolId())) {
+            return failCanDo(VdcBllMessages.CANNOT_REINIT_SPM_VDS_NOT_IN_POOL);
+        }
+
+        if (getVds().getSpmStatus() != VdsSpmStatus.None) {
+            return failCanDo(VdcBllMessages.CANNOT_REINIT_SPM_VDS_ALREADY_SPM);
+        }
+
+        if (getVds().getVdsSpmPriority() == 
BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
+            return 
failCanDo(VdcBllMessages.CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM);
+        }
+
+        if (isAsyncTasksRunningOnPool(getParameters().getStoragePoolId())) {
+            return 
failCanDo(VdcBllMessages.CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS);
+        }
+
+        return true;
+    }
+
+    private boolean failCanDo(VdcBllMessages message) {
+        addCanDoActionMessage(String.format("$%1$s %2$s", "VdsName", 
getVds().getName()));
+        return failCanDoAction(message);
+    }
+
+    @Override
+    protected void executeCommand() {
+        SpmStopOnIrsVDSCommandParameters params =
+                new 
SpmStopOnIrsVDSCommandParameters(getParameters().getStoragePoolId(),
+                        getParameters().getPreferredSPMId());
+        runVdsCommand(VDSCommandType.SpmStopOnIrs, params);
+        setSucceeded(true);
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REINITIALIZE);
+        addCanDoActionMessage(VdcBllMessages.VAR__TYPE__SPM);
+    }
+
+    private boolean isAsyncTasksRunningOnPool(Guid storagePoolId) {
+        List<Guid> tasks = 
getAsyncTaskDao().getAsyncTaskIdsByStoragePoolId(storagePoolId);
+        return !tasks.isEmpty();
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        switch (getActionState()) {
+        case EXECUTE:
+            return AuditLogType.USER_REINITIALIZED_SPM;
+        default:
+            return AuditLogType.UNASSIGNED;
+        }
+    }
+
+    @Override
+    public List<PermissionSubject> getPermissionCheckSubjects() {
+        List<PermissionSubject> permissions = new 
ArrayList<PermissionSubject>();
+        permissions.add(new 
PermissionSubject(getParameters().getStoragePoolId(),
+                VdcObjectType.StoragePool,
+                ActionGroup.MANIPUTLATE_HOST));
+        permissions.add(new 
PermissionSubject(getParameters().getPreferredSPMId(),
+                VdcObjectType.VDS,
+                ActionGroup.MANIPUTLATE_HOST));
+        return permissions;
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
index 590ac9b..62fda17 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DeactivateStorageDomainCommand.java
@@ -22,7 +22,6 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import 
org.ovirt.engine.core.common.vdscommands.DeactivateStorageDomainVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
@@ -32,6 +31,7 @@
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.linq.Predicate;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
+import 
org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters;
 
 @LockIdNameAttribute
 @NonTransactiveCommandAttribute(forceCompensation = true)
@@ -203,7 +203,7 @@
         }
         if (_isLastMaster && spm != null) {
             final VDSReturnValue stopSpmReturnValue = 
runVdsCommand(VDSCommandType.SpmStopOnIrs,
-                    new IrsBaseVDSCommandParameters(getStoragePool().getId()));
+                    new 
SpmStopOnIrsVDSCommandParameters(getStoragePool().getId()));
             if (!stopSpmReturnValue.getSucceeded()) {
                 // no need to continue because DisconnectStoragePool will
                 // fail if host is SPM
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveStoragePoolCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveStoragePoolCommand.java
index 849632c..aec9771 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveStoragePoolCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveStoragePoolCommand.java
@@ -17,15 +17,15 @@
 import org.ovirt.engine.core.common.action.RemoveStorageDomainParameters;
 import org.ovirt.engine.core.common.action.StoragePoolParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
-import org.ovirt.engine.core.common.businessentities.StorageDomain;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
@@ -42,6 +42,7 @@
 import org.ovirt.engine.core.utils.linq.Predicate;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
+import 
org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters;
 
 @NonTransactiveCommandAttribute(forceCompensation = true)
 public class RemoveStoragePoolCommand<T extends StoragePoolParametersBase> 
extends StorageHandlingCommandBase<T> {
@@ -227,7 +228,7 @@
                         Backend.getInstance()
                                 .getResourceManager()
                                 .RunVdsCommand(VDSCommandType.SpmStopOnIrs,
-                                        new 
IrsBaseVDSCommandParameters(getStoragePool().getId()));
+                                        new 
SpmStopOnIrsVDSCommandParameters(getStoragePool().getId()));
                         return null;
                     }
                 });
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandAssertUtils.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandAssertUtils.java
index 2297254..5199e37 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandAssertUtils.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommandAssertUtils.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.bll;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
@@ -24,4 +25,17 @@
         }
     }
 
+    /*
+     * This method checks if the return CDA messages contain the expected 
messages, it is different from checkMessages
+     * by the fact that it does not check by the order the parameters were 
given, the order is irrelevant most of the
+     * time and it does not check that the size of the returned messages 
matches the size of the expected messages, this
+     * comes in handy for example in scenarios where the CDA messages return a 
resolved parameters (e.g. '$VmName MyVM')
+     */
+    public static void checkMessagesContains(CommandBase<?> cmd, 
VdcBllMessages... expected) {
+        List<String> cdaMessages = 
cmd.getReturnValue().getCanDoActionMessages();
+        for (int i = 0; i < expected.length; i++) {
+            assertTrue("CanDoAction message does not contain the message " + 
expected[i],
+                    cdaMessages.contains(expected[i].toString()));
+        }
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ReinitializeSPMCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ReinitializeSPMCommandTest.java
new file mode 100644
index 0000000..5efca1a
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ReinitializeSPMCommandTest.java
@@ -0,0 +1,115 @@
+package org.ovirt.engine.core.bll;
+
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.ovirt.engine.core.bll.CommandAssertUtils.checkMessages;
+import static 
org.ovirt.engine.core.bll.CommandAssertUtils.checkMessagesContains;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.ovirt.engine.core.common.action.ReinitializeSPMParameters;
+import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
+import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.AsyncTaskDAO;
+import org.ovirt.engine.core.dao.StoragePoolDAO;
+import org.ovirt.engine.core.dao.VdsDAO;
+
+
+/** A test case for the {@link ReinitializeSPMCommand} command */
+
+public class ReinitializeSPMCommandTest {
+
+    private Guid vdsId = Guid.NewGuid();
+    private Guid storagePoolId = Guid.NewGuid();
+
+    private ReinitializeSPMCommand<ReinitializeSPMParameters> command;
+    private VDS vds;
+
+    private VdsDAO vdsDAOMock;
+    private StoragePoolDAO storagePoolDAOMock;
+    private AsyncTaskDAO asyncTaskDAOMock;
+
+    @Before
+    public void setup() {
+        createVDS();
+        mockDAOs();
+        mockCommand();
+    }
+
+    @Test
+    public void testCDANonExistingVds() {
+        doReturn(null).when(vdsDAOMock).get(vdsId);
+        assertFalse("canDoAction did not fail for non existing VDS", 
command.canDoAction());
+        checkMessages(command, VdcBllMessages.VDS_NOT_EXIST);
+    }
+
+    @Test
+    public void testCDAVdsNotUp() {
+        vds.setStatus(VDSStatus.Down);
+        assertFalse("canDoAction did not fail for a VDS with a status 
different from UP", command.canDoAction());
+        checkMessagesContains(command, 
VdcBllMessages.CANNOT_REINIT_SPM_VDS_NOT_UP);
+    }
+
+    @Test
+    public void testCDAStoragePoolValid() {
+        vds.setStoragePoolId(Guid.NewGuid());
+        assertFalse("canDoAction did not fail on mismatch Storage Pool", 
command.canDoAction());
+        checkMessagesContains(command, 
VdcBllMessages.CANNOT_REINIT_SPM_VDS_NOT_IN_POOL);
+    }
+
+    @Test
+    public void testCDAVdsIsSPM() {
+        vds.setSpmStatus(VdsSpmStatus.SPM);
+        assertFalse("canDoAction did not fail on a VDS that is already set as 
SPM", command.canDoAction());
+        checkMessagesContains(command, 
VdcBllMessages.CANNOT_REINIT_SPM_VDS_ALREADY_SPM);
+    }
+
+    @Test
+    public void testCDAVdsSPMPrioritySetToNever() {
+        
vds.setVdsSpmPriority(BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY);
+        assertFalse("canDoAction did not fail on a VDS that is set to never be 
elected as SPM", command.canDoAction());
+        checkMessagesContains(command, 
VdcBllMessages.CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM);
+    }
+
+    @Test
+    public void testCDAStoragePoolHasTasks() {
+        List<Guid> tasks = Arrays.asList(Guid.NewGuid());
+        
doReturn(tasks).when(asyncTaskDAOMock).getAsyncTaskIdsByStoragePoolId(storagePoolId);
+        assertFalse("canDoAction did not fail on a Storage Pool with running 
tasks", command.canDoAction());
+        checkMessagesContains(command, 
VdcBllMessages.CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS);
+    }
+
+    private void mockDAOs() {
+        vdsDAOMock = mock(VdsDAO.class);
+        storagePoolDAOMock = mock(StoragePoolDAO.class);
+        asyncTaskDAOMock = mock(AsyncTaskDAO.class);
+    }
+
+    private void createVDS() {
+        vds = new VDS();
+        vds.setId(vdsId);
+        vds.setVdsName("TestVDS");
+        vds.setStoragePoolId(storagePoolId);
+        vds.setStatus(VDSStatus.Up);
+        vds.setSpmStatus(VdsSpmStatus.None);
+        vds.setVdsSpmPriority(10);
+    }
+
+    private void mockCommand() {
+        ReinitializeSPMParameters params = new 
ReinitializeSPMParameters(storagePoolId, vdsId);
+        command = spy(new 
ReinitializeSPMCommand<ReinitializeSPMParameters>(params));
+        doReturn(vdsDAOMock).when(command).getVdsDAO();
+        doReturn(storagePoolDAOMock).when(command).getStoragePoolDAO();
+        doReturn(asyncTaskDAOMock).when(command).getAsyncTaskDao();
+        doReturn(vds).when(vdsDAOMock).get(vdsId);
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
index 4e57c21..a491819 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
@@ -274,6 +274,7 @@
     GLUSTER_SERVICE_RESTARTED(4072),
     GLUSTER_SERVICE_RESTART_FAILED(4073),
 
+    USER_REINITIALIZED_SPM(159),
     USER_VDS_RESTART(41),
     USER_FAILED_VDS_RESTART(107),
     USER_VDS_START(20),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/ReinitializeSPMParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/ReinitializeSPMParameters.java
new file mode 100644
index 0000000..1f9a90a
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/ReinitializeSPMParameters.java
@@ -0,0 +1,30 @@
+package org.ovirt.engine.core.common.action;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class ReinitializeSPMParameters extends VdcActionParametersBase {
+
+    private Guid preferredSPMId;
+    private Guid storagePoolId = Guid.Empty;
+
+    public ReinitializeSPMParameters(Guid storagePoolId, Guid prefferedSPMId) {
+        setStoragePoolId(storagePoolId);
+        setPreferredSPMId(prefferedSPMId);
+    }
+
+    public Guid getPreferredSPMId() {
+        return preferredSPMId;
+    }
+
+    public void setPreferredSPMId(Guid preferredSPMId) {
+        this.preferredSPMId = preferredSPMId;
+    }
+
+    public Guid getStoragePoolId() {
+        return storagePoolId;
+    }
+
+    public void setStoragePoolId(Guid storagePoolId) {
+        this.storagePoolId = storagePoolId;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
index fa97118..bac0e0b 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
@@ -64,6 +64,7 @@
     InitVdsOnUp(115, QuotaDependency.NONE),
     SetNonOperationalVds(117, QuotaDependency.NONE),
     AddVdsSpmId(119, QuotaDependency.NONE),
+    ReinitializeSPM(120, QuotaDependency.NONE),
     // Fencing (including RestartVds above)
     StartVds(121, ActionGroup.MANIPUTLATE_HOST, QuotaDependency.NONE),
     StopVds(122, ActionGroup.MANIPUTLATE_HOST, QuotaDependency.NONE),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 4ceef2d..c18a1d3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -27,6 +27,7 @@
     VAR__TYPE__BOOKMARK,
     VAR__TYPE__VM_TICKET,
     VAR__TYPE__PERMISSION,
+    VAR__TYPE__SPM,
 
     // Gluster types
     VAR__TYPE__GLUSTER_VOLUME,
@@ -79,6 +80,7 @@
     VAR__ACTION__ENABLE,
     VAR__ACTION__DISABLE,
     VAR__ACTION__REFRESH,
+    VAR__ACTION__REINITIALIZE,
 
     // Host statuses replacements
     VAR__HOST_STATUS__UP,
@@ -213,6 +215,12 @@
     VDS_CANNOT_ACTIVATE_VDS_NOT_EXIST(ErrorType.BAD_PARAMETERS),
     VDS_STATUS_NOT_VALID_FOR_STOP(ErrorType.CONFLICT),
     VDS_STATUS_NOT_VALID_FOR_START(ErrorType.CONFLICT),
+    VDS_NOT_EXIST(ErrorType.BAD_PARAMETERS),
+    CANNOT_REINIT_SPM_VDS_NOT_UP(ErrorType.CONFLICT),
+    CANNOT_REINIT_SPM_VDS_ALREADY_SPM(ErrorType.CONFLICT),
+    CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM(ErrorType.CONSTRAINT_VIOLATION),
+    CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS(ErrorType.CONFLICT),
+    CANNOT_REINIT_SPM_VDS_NOT_IN_POOL(ErrorType.CONFLICT),
     VDS_NO_VDS_PROXY_FOUND(ErrorType.CONFLICT),
     VDS_FAILED_FENCE_VIA_PROXY_CONNECTION(ErrorType.CONFLICT),
     VDS_FENCE_DISABLED_AT_SYSTEM_STARTUP_INTERVAL(ErrorType.CONFLICT),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/ResetIrsVDSCommandParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/ResetIrsVDSCommandParameters.java
index 76c8401..78f3d8b 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/ResetIrsVDSCommandParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/ResetIrsVDSCommandParameters.java
@@ -3,12 +3,23 @@
 import org.ovirt.engine.core.compat.Guid;
 
 public class ResetIrsVDSCommandParameters extends IrsBaseVDSCommandParameters {
+
+    private Guid privateVdsId;
+
+    private Guid preferredSPMId;
+
+    public ResetIrsVDSCommandParameters() {
+    }
+
     public ResetIrsVDSCommandParameters(Guid storagePoolId, Guid vdsId) {
         super(storagePoolId);
         setVdsId(vdsId);
     }
 
-    private Guid privateVdsId;
+    public ResetIrsVDSCommandParameters(Guid storagePoolId, Guid vdsId, Guid 
preferredSPMId) {
+        this(storagePoolId, vdsId);
+        setPreferredSPMId(preferredSPMId);
+    }
 
     public Guid getVdsId() {
         return privateVdsId;
@@ -24,11 +35,16 @@
         return privateIgnoreStopFailed;
     }
 
-    public void setIgnoreStopFailed(boolean value) {
-        privateIgnoreStopFailed = value;
+    public Guid getPreferredSPMId() {
+        return preferredSPMId;
     }
 
-    public ResetIrsVDSCommandParameters() {
+    public void setPreferredSPMId(Guid preferredSPMId) {
+        this.preferredSPMId = preferredSPMId;
+    }
+
+    public void setIgnoreStopFailed(boolean value) {
+        privateIgnoreStopFailed = value;
     }
 
     @Override
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
index 0f2c466..bd8f863 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
@@ -293,6 +293,7 @@
         severities.put(AuditLogType.USER_REMOVE_VDS, AuditLogSeverity.NORMAL);
         severities.put(AuditLogType.USER_FAILED_REMOVE_VDS, 
AuditLogSeverity.ERROR);
         severities.put(AuditLogType.USER_VDS_RESTART, AuditLogSeverity.NORMAL);
+        severities.put(AuditLogType.USER_REINITIALIZED_SPM, 
AuditLogSeverity.NORMAL);
         severities.put(AuditLogType.USER_FAILED_VDS_RESTART, 
AuditLogSeverity.ERROR);
         severities.put(AuditLogType.USER_VDS_START, AuditLogSeverity.NORMAL);
         severities.put(AuditLogType.USER_FAILED_VDS_START, 
AuditLogSeverity.ERROR);
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
index 00e193a..9cfe162 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java
@@ -13,11 +13,11 @@
 import org.ovirt.engine.core.common.businessentities.AuditLog;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.interfaces.IVdcUser;
 import org.ovirt.engine.core.compat.Guid;
@@ -614,7 +614,7 @@
         return getDbFacade().getNetworkDao();
     }
 
-    protected AsyncTaskDAO getAsyncTaskDao() {
+    public AsyncTaskDAO getAsyncTaskDao() {
         return getDbFacade().getAsyncTaskDao();
     }
 
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 626b1a7..e5d0030 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -79,6 +79,10 @@
 VDS_CANNOT_REMOVE_VDS_GROUP_VDS_DETECTED=Cannot ${action} ${type}. Host 
Cluster contains one or more Hosts.
 VDS_CANNOT_REMOVE_VDS_STATUS_ILLEGAL=Cannot ${action} ${type}. Host is 
operational. Please switch Host to Maintenance mode first.
 VDS_NOT_EXIST=Cannot ${action} ${type}. Internal Error: Host does not exists 
in DB.
+CANNOT_REINIT_SPM_VDS_NOT_UP=Cannot ${action} ${type}. The Host ${VdsName} is 
not active.
+CANNOT_REINIT_SPM_VDS_ALREADY_SPM=Cannot ${action} ${type}. The Host 
${VdsName} is already SPM or contending.
+CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM=Cannot ${action} ${type}. The SPM 
priority of Host ${VdsName} is set to never. This Host cannot be elected as SPM.
+CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS=Cannot ${action} ${type}. The 
Storage Pool has running tasks.
 VDS_PROTOCOL_ERROR=Internal error: Host protocol error.
 VDS_RESPONSE_ERROR=Internal error: Host response error
 VDS_STATUS_NOT_VALID_FOR_STOP=Cannot perform Stop operation, Host has to be in 
Maintenance mode in order to be stopped.
@@ -235,6 +239,7 @@
 VAR__TYPE__USER_FROM_VM=$type User to VM
 VAR__TYPE__USER=$type User
 VAR__TYPE__PERMISSION=$type Permission
+VAR__TYPE__SPM=$type SPM
 VAR__ACTION__RUN=$action run
 VAR__ACTION__REMOVE=$action remove
 VAR__ACTION__ADD=$action add
@@ -284,6 +289,7 @@
 VAR__ACTION__ENABLE=$action enable
 VAR__ACTION__DISABLE=$action disable
 VAR__ACTION__REFRESH=$action refresh
+VAR__ACTION__REINITIALIZE=$action reinitialize
 VAR__HOST_STATUS__UP=$hostStatus Up
 VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL=$hostStatus Up, 
Maintenance or Non operational
 
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
index a760995..fd539b9 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
@@ -21,6 +21,7 @@
 job.AddDisk=Adding Disk ${DiskAlias}
 job.RemoveDisk=Removing Disk ${DiskAlias}
 job.ImportVm=Importing VM ${VM} to Cluster ${VdsGroups}
+job.ReinitializeSPM=Reinitializing ${VDS} as SPM for Data Center ${StoragePool}
 job.RemoveVmFromImportExport=Removing VM ${VM} image from Storage Domain 
${Storage}
 job.RemoveVmTemplateFromImportExport=Removing VM Template ${VmTemplate} image 
from Storage Domain ${Storage}
 job.ImportVmTemplate=Importing VM Template ${VmTemplate} to Data Center 
${StoragePool}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
index 06edb06..8ea5d4b 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
@@ -24,17 +24,17 @@
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.SpmStatus;
 import org.ovirt.engine.core.common.businessentities.SpmStatusResult;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
+import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap;
 import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSDomainsData;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
-import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
-import org.ovirt.engine.core.common.businessentities.StorageDomain;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
-import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap;
 import org.ovirt.engine.core.common.businessentities.vds_spm_id_map;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
@@ -81,7 +81,6 @@
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException;
 import org.ovirt.engine.core.vdsbroker.xmlrpc.XmlRpcRunTimeException;
 import org.ovirt.engine.core.vdsbroker.xmlrpc.XmlRpcUtils;
-
 @Logged(errorLevel = LogLevel.ERROR)
 public abstract class IrsBrokerCommand<P extends IrsBaseVDSCommandParameters> 
extends BrokerCommandBase<P> {
     public static final long BYTES_TO_GB = 1024 * 1024 * 1024;
@@ -122,19 +121,21 @@
     }
 
     protected static class IrsProxyData {
-        // TODO the syncObj initial purposs was to lock the IrsBroker creation
-        // but eventually because the IRS is singlethreaded and suppose to have
+        // TODO the syncObj initial purpose was to lock the IrsBroker creation
+        // but eventually because the IRS is single threaded and suppose to 
have
         // quite a load of requests,
-        // In order to avoid unexpected behaviour we have used the syncObj to
+        // In order to avoid unexpected behavior we have used the syncObj to
         // lock each request to the IRS
-        // and by that we caused a searialization of requests to the IRS.
+        // and by that we caused a serialization of requests to the IRS.
         // This lock should be removed as soon as the IrsBroker is turned
-        // multithreaded
+        // multi threaded
         public Object syncObj = new Object();
 
         private final String storagePoolRefreshJobId;
         private final java.util.HashSet<Guid> mTriedVdssList = new 
java.util.HashSet<Guid>();
         private Guid mCurrentVdsId;
+
+        private Guid preferredHost;
 
         public Guid getCurrentVdsId() {
             return getIrsProxy() != null ? mCurrentVdsId : Guid.Empty;
@@ -188,7 +189,7 @@
 
                     }
                 }
-            } catch (java.lang.Exception ex) {
+            } catch (Exception ex) {
             }
         }
 
@@ -228,7 +229,7 @@
                     }
                 }
 
-                // if spm status didnt work or not spm and NOT NETWORK
+                // if spm status didn't work or not spm and NOT NETWORK
                 // PROBLEM
                 // then cause failover with attempts
                 if (result != null && !(result.getExceptionObject() instanceof 
VDSNetworkException)) {
@@ -298,6 +299,14 @@
                     }
                 }
             }
+        }
+
+        public Guid getPreferredHost() {
+            return preferredHost;
+        }
+
+        public void setPreferredHost(Guid preferredHost) {
+            this.preferredHost = preferredHost;
         }
 
         private void proceedStorageDomain(StorageDomain data, int 
dataMasterVersion, StoragePool storagePool) {
@@ -694,11 +703,20 @@
             // deal with the case that there are several hosts with the same 
priority.
             List<VDS> allVds = 
DbFacade.getInstance().getVdsDao().getListForSpmSelection(_storagePoolId);
             List<VDS> vdsRelevantForSpmSelection = new ArrayList<VDS>();
+            Guid preferredHost = 
getIrsProxyData(_storagePoolId).getPreferredHost();
+            getIrsProxyData(_storagePoolId).setPreferredHost(null);
+
             for (VDS vds : allVds) {
                 if (!mTriedVdssList.contains(vds.getId()) && 
!vds.getId().equals(curVdsId)) {
-                    vdsRelevantForSpmSelection.add(vds);
+                    if (vds.getId().equals(preferredHost)) {
+                        vdsRelevantForSpmSelection.add(0, vds);
+                    }
+                    else {
+                        vdsRelevantForSpmSelection.add(vds);
+                    }
                 }
             }
+
             return vdsRelevantForSpmSelection;
         }
 
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/ResetIrsVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/ResetIrsVDSCommand.java
index 1fca39b..ee320c1 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/ResetIrsVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/ResetIrsVDSCommand.java
@@ -25,6 +25,9 @@
                 .runVdsCommand(VDSCommandType.SpmStop,
                         new SpmStopVDSCommandParameters(vdsId, 
parameters.getStoragePoolId())).getSucceeded()
                 || parameters.getIgnoreStopFailed()) {
+            if (getParameters().getPreferredSPMId() != null) {
+                
getCurrentIrsProxyData().setPreferredHost(getParameters().getPreferredSPMId());
+            }
             getCurrentIrsProxyData().ResetIrs();
             StoragePool pool = 
DbFacade.getInstance().getStoragePoolDao().get(parameters.getStoragePoolId());
             if (pool != null && (pool.getstatus() == 
StoragePoolStatus.NotOperational)) {
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommand.java
index 204c3c3..ffac889 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommand.java
@@ -1,11 +1,10 @@
 package org.ovirt.engine.core.vdsbroker.irsbroker;
 
-import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.ResetIrsVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.vdsbroker.ResourceManager;
 
-public class SpmStopOnIrsVDSCommand<P extends IrsBaseVDSCommandParameters> 
extends IrsBrokerCommand<P> {
+public class SpmStopOnIrsVDSCommand<P extends 
SpmStopOnIrsVDSCommandParameters> extends IrsBrokerCommand<P> {
     public SpmStopOnIrsVDSCommand(P parameters) {
         super(parameters);
     }
@@ -15,6 +14,6 @@
         ResourceManager.getInstance().runVdsCommand(
                 VDSCommandType.ResetIrs,
                 new 
ResetIrsVDSCommandParameters(getParameters().getStoragePoolId(),
-                        getCurrentIrsProxyData().getCurrentVdsId()));
+                        getCurrentIrsProxyData().getCurrentVdsId(), 
getParameters().getPreferredSPMId()));
     }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommandParameters.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommandParameters.java
new file mode 100644
index 0000000..a347e34
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/SpmStopOnIrsVDSCommandParameters.java
@@ -0,0 +1,26 @@
+package org.ovirt.engine.core.vdsbroker.irsbroker;
+
+import org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters;
+import org.ovirt.engine.core.compat.Guid;
+
+public class SpmStopOnIrsVDSCommandParameters extends 
IrsBaseVDSCommandParameters {
+
+    private Guid preferredSPMId;
+
+    public SpmStopOnIrsVDSCommandParameters(Guid storagePoolId) {
+        super(storagePoolId);
+    }
+
+    public SpmStopOnIrsVDSCommandParameters(Guid storagePoolId, Guid 
preferredSPMId) {
+        super(storagePoolId);
+        setPreferredSPMId(preferredSPMId);
+    }
+
+    public Guid getPreferredSPMId() {
+        return preferredSPMId;
+    }
+
+    public void setPreferredSPMId(Guid preferredSPMId) {
+        this.preferredSPMId = preferredSPMId;
+    }
+}
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index f4ee266..b7af27a 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -184,6 +184,18 @@
     @DefaultStringValue("Cannot ${action} ${type}. Internal Error: Host does 
not exists in DB.")
     String VDS_NOT_EXIST();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The Host ${VdsName} is not 
active.")
+    String CANNOT_REINIT_SPM_VDS_NOT_UP();
+
+    @DefaultStringValue("Cannot ${action} ${type}. The Host ${VdsName} is 
already SPM or contending.")
+    String CANNOT_REINIT_SPM_VDS_ALREADY_SPM();
+
+    @DefaultStringValue("Cannot ${action} ${type}. The SPM priority of Host 
${VdsName} is set to never. This Host cannot be elected as SPM.")
+    String CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM();
+
+    @DefaultStringValue("Cannot ${action} ${type}. The Storage Pool has 
running tasks.")
+    String CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS();
+
     @DefaultStringValue("Internal error: Host protocol error.")
     String VDS_PROTOCOL_ERROR();
 
@@ -634,6 +646,9 @@
     @DefaultStringValue("$type Permission")
     String VAR__TYPE__PERMISSION();
 
+    @DefaultStringValue("$type SPM")
+    String VAR__TYPE__SPM();
+
     @DefaultStringValue("$action run")
     String VAR__ACTION__RUN();
 
@@ -769,6 +784,9 @@
     @DefaultStringValue("$action stop profiling")
     String VAR__ACTION__STOP_PROFILE();
 
+    @DefaultStringValue("$action reinitialize")
+    String VAR__ACTION__REINITIALIZE();
+
     @DefaultStringValue("$action assign")
     String VAR__ACTION__ASSIGN();
 
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostListModel.java
index 15dd798..19d49d8 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostListModel.java
@@ -4,6 +4,7 @@
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -16,12 +17,14 @@
 import org.ovirt.engine.core.common.action.FenceVdsActionParameters;
 import org.ovirt.engine.core.common.action.FenceVdsManualyParameters;
 import org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters;
+import org.ovirt.engine.core.common.action.ReinitializeSPMParameters;
 import org.ovirt.engine.core.common.action.RemoveVdsParameters;
 import org.ovirt.engine.core.common.action.UpdateVdsActionParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.action.VdsActionParameters;
+import 
org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
 import org.ovirt.engine.core.common.businessentities.RoleType;
 import org.ovirt.engine.core.common.businessentities.StoragePool;
@@ -29,6 +32,7 @@
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VDSType;
+import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.common.interfaces.SearchType;
 import org.ovirt.engine.core.common.mode.ApplicationMode;
@@ -129,6 +133,18 @@
     private void setRemoveCommand(UICommand value)
     {
         privateRemoveCommand = value;
+    }
+
+    private UICommand setAsSpmCommand;
+
+    public UICommand getSetAsSpmCommand()
+    {
+        return setAsSpmCommand;
+    }
+
+    private void setSetAsSpmCommand(UICommand value)
+    {
+        setAsSpmCommand = value;
     }
 
     private UICommand privateActivateCommand;
@@ -306,6 +322,7 @@
         setNewCommand(new UICommand("New", this)); //$NON-NLS-1$
         setEditCommand(new UICommand("Edit", this)); //$NON-NLS-1$
         setEditWithPMemphasisCommand(new UICommand("EditWithPMemphasis", 
this)); //$NON-NLS-1$
+        setSetAsSpmCommand(new UICommand("SetAsSpm", this)); //$NON-NLS-1$
         setRemoveCommand(new UICommand("Remove", this)); //$NON-NLS-1$
         setActivateCommand(new UICommand("Activate", this, true)); 
//$NON-NLS-1$
         setMaintenanceCommand(new UICommand("Maintenance", this, true)); 
//$NON-NLS-1$
@@ -1573,6 +1590,8 @@
         getNewCommand().setIsAvailable(isAvailable);
         getRemoveCommand().setIsAvailable(isAvailable);
 
+        
getSetAsSpmCommand().setIsExecutionAllowed(isSetAsSpmCommandAllowed(items));
+
         updateConfigureLocalStorageCommandAvailability();
     }
 
@@ -1658,6 +1677,10 @@
         else if (command == getRemoveCommand())
         {
             remove();
+        }
+        else if (command == getSetAsSpmCommand())
+        {
+            setAsSPM();
         }
         else if (command == getActivateCommand())
         {
@@ -1753,6 +1776,31 @@
         }
     }
 
+    public void setAsSPM() {
+        ReinitializeSPMParameters params =
+                new ReinitializeSPMParameters(((VDS) 
getSelectedItem()).getStoragePoolId(),
+                        ((VDS) getSelectedItem()).getId());
+        Frontend.RunAction(VdcActionType.ReinitializeSPM, params);
+
+    }
+
+    private boolean isSetAsSpmCommandAllowed(List<VDS> selectedItems) {
+        if (selectedItems.size() != 1)
+            return false;
+
+        VDS vds = selectedItems.get(0);
+
+        if (vds.getStatus() != VDSStatus.Up || vds.getSpmStatus() != 
VdsSpmStatus.None) {
+            return false;
+        }
+
+        if (vds.getVdsSpmPriority() == 
BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
+            return false;
+        }
+
+        return true;
+    }
+
     // @Override
     // public void run(TaskContext context)
     // {
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
index dc08cae..565d03b 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationConstants.java
@@ -1118,6 +1118,9 @@
     @DefaultStringValue("Maintenance")
     String maintenanceHost();
 
+    @DefaultStringValue("Set as SPM")
+    String setHostAsSPM();
+
     @DefaultStringValue("Confirm 'Host has been Rebooted'")
     String confirmRebootedHost();
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabHostView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabHostView.java
index ad52288..2f1b649 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabHostView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabHostView.java
@@ -225,6 +225,12 @@
                 return getMainModel().getMaintenanceCommand();
             }
         });
+        getTable().addActionButton(new 
WebAdminButtonDefinition<VDS>(constants.setHostAsSPM()) {
+            @Override
+            protected UICommand resolveCommand() {
+                return getMainModel().getSetAsSpmCommand();
+            }
+        });
         if (ApplicationModeHelper.getUiMode() != ApplicationMode.GlusterOnly) {
             getTable().addActionButton(new 
WebAdminButtonDefinition<VDS>(constants.confirmRebootedHost(),
                     CommandLocation.OnlyFromContext) {
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 458241e..a470ede 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -79,6 +79,10 @@
 VDS_CANNOT_REMOVE_VDS_GROUP_VDS_DETECTED=Cannot ${action} ${type}. Host 
Cluster contains one or more Hosts.
 VDS_CANNOT_REMOVE_VDS_STATUS_ILLEGAL=Cannot ${action} ${type}. Host is 
operational. Please switch Host to Maintenance mode first.
 VDS_NOT_EXIST=Cannot ${action} ${type}. Internal Error: Host does not exists 
in DB.
+CANNOT_REINIT_SPM_VDS_NOT_UP=Cannot ${action} ${type}. The Host ${VdsName} is 
not active.
+CANNOT_REINIT_SPM_VDS_ALREADY_SPM=Cannot ${action} ${type}. The Host 
${VdsName} is already SPM or contending.
+CANNOT_REINIT_SPM_VDS_MARKED_AS_NEVER_SPM=Cannot ${action} ${type}. The SPM 
priority of Host ${VdsName} is set to never. This Host cannot be elected as SPM.
+CANNOT_REINIT_SPM_STORAGE_POOL_HAS_RUNNING_TASKS=Cannot ${action} ${type}. The 
Storage Pool has running tasks.
 VDS_PROTOCOL_ERROR=Internal error: Host protocol error.
 VDS_RESPONSE_ERROR=Internal error: Host response error
 VDS_STATUS_NOT_VALID_FOR_STOP=Cannot perform Stop operation, Host has to be in 
Maintenance mode in order to be stopped.
@@ -238,6 +242,7 @@
 VAR__TYPE__GLUSTER_SERVER=$type Gluster Server
 VAR__TYPE__GLUSTER_HOOK=$type Gluster Hook
 VAR__TYPE__GLUSTER_SERVICE=$type Service
+VAR__TYPE__SPM=$type SPM
 VAR__ACTION__RUN=$action run
 VAR__ACTION__REMOVE=$action remove
 VAR__ACTION__ADD=$action add
@@ -285,6 +290,7 @@
 VAR__ACTION__STOP_PROFILE=$action stop profiling
 VAR__ACTION__ASSIGN=$action assign
 VAR__ACTION__REFRESH=$action refresh
+VAR__ACTION__REINITIALIZE=$action reinitialize
 VAR__HOST_STATUS__UP=$hostStatus Up
 VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL=$hostStatus Up, 
Maintenance or Non operational
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iab31fc7918b10448b923821547a583f3d6c3fcba
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to