Martin Peřina has uploaded a new change for review. Change subject: core: Remove FenceExecutor and unused fence return value objects ......................................................................
core: Remove FenceExecutor and unused fence return value objects 1. Removes FenceExecutor and its no longer used audit log messages. 2. Removes VDSFenceReturnValue 3. Removes FenceStatusReturnValue Change-Id: If4ded059813f1472d7546e8c7c29a2538c74c945 Bug-Url: https://bugzilla.redhat.com/1182510 Signed-off-by: Martin Perina <[email protected]> --- D backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java D backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java D backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceStatusReturnValue.java D backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSFenceReturnValue.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties 6 files changed, 0 insertions(+), 800 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/38972/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java deleted file mode 100644 index c0399c1..0000000 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java +++ /dev/null @@ -1,340 +0,0 @@ -package org.ovirt.engine.core.bll; - -import java.util.HashMap; -import java.util.Map; - -import org.ovirt.engine.core.bll.interfaces.BackendInternal; -import org.ovirt.engine.core.common.AuditLogType; -import org.ovirt.engine.core.common.businessentities.ArchitectureType; -import org.ovirt.engine.core.common.businessentities.StorageDomain; -import org.ovirt.engine.core.common.businessentities.StorageDomainType; -import org.ovirt.engine.core.common.businessentities.pm.FenceActionType; -import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue; -import org.ovirt.engine.core.common.businessentities.FencingPolicy; -import org.ovirt.engine.core.common.businessentities.FenceAgent; -import org.ovirt.engine.core.common.businessentities.VDS; -import org.ovirt.engine.core.common.businessentities.VdsSpmStatus; -import org.ovirt.engine.core.common.businessentities.vds_spm_id_map; -import org.ovirt.engine.core.common.errors.VdcBLLException; -import org.ovirt.engine.core.common.utils.FencingPolicyHelper; -import org.ovirt.engine.core.common.vdscommands.FenceVdsVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; -import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue; -import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; -import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; -import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; -import org.ovirt.engine.core.utils.pm.VdsFenceOptions; -import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FenceExecutor { - private static final Logger log = LoggerFactory.getLogger(FenceExecutor.class); - - private final VDS _vds; - private FencingPolicy fencingPolicy; - private FenceProxyLocator proxyLocator; - private VdsArchitectureHelper architectureHelper; - - public FenceExecutor(VDS vds) { - this(vds, null); - } - - public FenceExecutor(VDS vds, FencingPolicy fencingPolicy) { - // TODO remove if block after UI patch that should set also cluster & proxy preferences in GetNewVdsFenceStatusParameters - if (! vds.getId().equals(Guid.Empty)) { - VDS dbVds = DbFacade.getInstance().getVdsDao().get(vds.getId()); - if (vds.getVdsGroupId() == null) { - vds.setVdsGroupId(dbVds.getVdsGroupId()); - } - if (vds.getPmProxyPreferences() == null) { - vds.setPmProxyPreferences(dbVds.getPmProxyPreferences()); - } - } - this._vds = vds; - this.fencingPolicy = fencingPolicy; - this.proxyLocator = new FenceProxyLocator(_vds, fencingPolicy); - this.architectureHelper = new VdsArchitectureHelper(); - } - - /** - * Use all fencing agents of this host sequentially. If even one agent returns status "on", the host is up. - * Otherwise, the host is down. - */ - public VDSFenceReturnValue checkHostStatus() { - VDSFenceReturnValue returnValue = null; - VDS proxyHost = proxyLocator.findProxyHost(); - if (proxyHost == null) { - returnValue = proxyNotFound(); - } else { - for (FenceAgent agent : _vds.getFenceAgents()) { - returnValue = checkAgentStatus(agent, proxyHost); - if (returnValue.getSucceeded()) { - returnValue.setProxyHostUsed(proxyHost); - if (isStatusOn(returnValue)) { - returnValue.setFenceAgentUsed(agent); - break; - } - } - } - } - if (returnValue == null) { - returnValue = new VDSFenceReturnValue(); - returnValue.setSucceeded(false); - returnValue.setExceptionString("No fence-agents found for host " + _vds.getName()); - } - return returnValue; - } - - - public VDSFenceReturnValue checkAgentStatus(FenceAgent agent) { - VDS proxyHost = proxyLocator.findProxyHost(); - if (proxyHost == null) { - return proxyNotFound(); - } else { - return checkAgentStatus(agent, proxyHost); - } - } - - - private VDSFenceReturnValue checkAgentStatus(FenceAgent agent, VDS proxyHost) { - VDSFenceReturnValue returnValue = null; - returnValue = fence(FenceActionType.STATUS, agent, proxyHost); - if (returnValue.getSucceeded()) { - returnValue.setProxyHostUsed(proxyHost); - returnValue.setFenceAgentUsed(agent); - // the status itself ("on"/"off") is already set in the result object. - } - return returnValue; - } - - - public VDSFenceReturnValue fence(FenceActionType action, FenceAgent agent) { - boolean withRetries = action != FenceActionType.STATUS; // for status check, no retries on proxy-host selection. - VDS proxyHost = proxyLocator.findProxyHost(withRetries); - if (proxyHost == null) { - return proxyNotFound(); - } else { - return fence(action, agent, proxyHost); - } - } - - private VDSFenceReturnValue proxyNotFound() { - VDSFenceReturnValue returnValue = new VDSFenceReturnValue(); - returnValue.setSucceeded(false); - returnValue.setExceptionString("Failed to run Power Management command on Host " + getNameOrId(_vds) - + " no running proxy Host was found"); - return returnValue; - } - - public VDSFenceReturnValue fence(FenceActionType action, FenceAgent agent, VDS proxyHost) { - VDSReturnValue result = null; - try { - if (action == FenceActionType.RESTART || action == FenceActionType.STOP) { - stopSPM(action); - } - result = runFenceAction(action, agent, proxyHost); - // if fence failed, retry with another proxy. - if (!result.getSucceeded()) { - log.warn("Fence operation failed with proxy host {}, trying another proxy...", - proxyHost.getId()); - boolean withRetries = action != FenceActionType.STATUS; - VDS alternativeProxy = - proxyLocator.findProxyHost(withRetries, proxyHost.getId()); - if (alternativeProxy != null) { - result = runFenceAction(action, agent, alternativeProxy); - } else { - log.warn("Failed to find other proxy to re-run failed fence operation, retrying with the same proxy..."); - new AuditLogDirector().log(getAuditParams(action, agent, proxyHost), - AuditLogType.FENCE_OPERATION_FAILED_USING_PROXY); - result = runFenceAction(action, agent, proxyHost); - } - } - } catch (VdcBLLException e) { - result = new VDSReturnValue(); - result.setReturnValue(new FenceStatusReturnValue("unknown", e.getMessage())); - result.setExceptionString(e.getMessage()); - result.setSucceeded(false); - } - VDSFenceReturnValue returnVal = new VDSFenceReturnValue(result); - returnVal.setFenceAgentUsed(agent); - returnVal.setSucceeded(result.getSucceeded() || returnVal.isSkippedDueToPolicy()); // skipping due to policy - return returnVal; - } - - private void stopSPM(FenceActionType action) { - // skip following code in case of testing a new host status - if (_vds.getId() != null && !_vds.getId().equals(Guid.Empty)) { - // get the host spm status again from the database in order to test it's current state. - VdsSpmStatus spmStatus = DbFacade.getInstance().getVdsDao().get(_vds.getId()).getSpmStatus(); - // try to stop SPM if action is Restart or Stop and the vds is SPM - if (spmStatus != VdsSpmStatus.None) { - getBackend().getResourceManager() - .RunVdsCommand(VDSCommandType.SpmStop, - new SpmStopVDSCommandParameters(_vds.getId(), _vds.getStoragePoolId())); - } - } - } - - /** - * Run the specified fence action. - * @param actionType The action to run. - * @return The result of running the fence command. - */ - private VDSReturnValue runFenceAction(FenceActionType action, FenceAgent agent, VDS proxyHost) { - auditFenceAction(action, agent, proxyHost); - - FenceAgent realAgent = new FenceAgent(agent); - realAgent.setType(VdsFenceOptions.getRealAgent(agent.getType())); - realAgent.setOptions(getOptions(agent, proxyHost)); - - return getBackend().getResourceManager() - .RunVdsCommand( - VDSCommandType.FenceVds, - new FenceVdsVDSCommandParameters( - proxyHost.getId(), - _vds.getId(), - realAgent, - action, - convertFencingPolicy(proxyHost))); - } - - private void auditFenceAction(FenceActionType action, FenceAgent agent, VDS proxyHost) { - log.info("Executing <{}> Power Management command: Proxy Host:{}, Target Host:{}, Agent:{}, Fencing policy:{}", - action, - getNameOrId(proxyHost), - getNameOrId(_vds), - agent, - fencingPolicy); - AuditLogableBase logable = getAuditParams(action, agent, proxyHost); - new AuditLogDirector().log(logable, AuditLogType.FENCE_USING_AGENT_AND_PROXY_HOST); - } - - private AuditLogableBase getAuditParams(FenceActionType action, FenceAgent agent, VDS proxyHost) { - AuditLogableBase logable = new AuditLogableBase(); - logable.addCustomValue("Action", getActionPresentTense(action)); - logable.addCustomValue("Host", getNameOrId(_vds)); - logable.addCustomValue("Agent", agent.getId() == null ? "New Agent (no ID)" : agent.getId().toString()); - logable.addCustomValue("ProxyHost", getNameOrId(proxyHost)); - logable.setVdsId(_vds.getId()); - return logable; - } - - private String getActionPresentTense(FenceActionType action) { - switch (action) { - case START: - return "Starting"; - case RESTART: - return "Restarting"; - case STOP: - return "Stopping"; - case STATUS: - return "Checking status of"; - default: - return "";// should never get here. - } - } - - protected String getOptions(FenceAgent agent, VDS proxyHost) { - ArchitectureType architectureType = architectureHelper.getArchitecture(_vds.getStaticData()); - String managementOptions = - new VdsFenceOptions( - agent.getType(), - VdsFenceOptions.getDefaultAgentOptions( - agent.getType(), - agent.getOptions() == null ? "" : agent.getOptions(), - architectureType), - proxyHost.getVdsGroupCompatibilityVersion().toString() - ).ToInternalString(); - return managementOptions; - } - - /** - * We prefer to log the host name, if it's available, but we won't query the database especially for it. So return - * the host name if it's available, otherwise the host-ID. - */ - private String getNameOrId(VDS host) { - if (host.getName() != null && !host.getName().isEmpty()) { - return host.getName(); - } else { - return host.getId().toString(); - } - } - - public static boolean isStatusOff(VDSFenceReturnValue returnValue) { - return isStatusEqualTo(returnValue, "off"); - } - - public static boolean isStatusOn(VDSFenceReturnValue returnValue) { - return isStatusEqualTo(returnValue, "on"); - } - - private static boolean isStatusEqualTo(VDSFenceReturnValue returnValue, String targetStatus) { - boolean result = false; - if (returnValue != null && returnValue.getSucceeded()) { - FenceStatusReturnValue value = (FenceStatusReturnValue) returnValue.getReturnValue(); - result = value.getStatus().equalsIgnoreCase(targetStatus); - } - return result; - } - - BackendInternal getBackend() { - return Backend.getInstance(); - } - - public VdsArchitectureHelper getArchitectureHelper() { - return architectureHelper; - } - - public void setArchitectureHelper(VdsArchitectureHelper architectureHelper) { - this.architectureHelper = architectureHelper; - } - - public FenceProxyLocator getProxyLocator() { - return proxyLocator; - } - - public void setProxyLocator(FenceProxyLocator proxyLocator) { - this.proxyLocator = proxyLocator; - } - - DbFacade getDbFacade() { - return DbFacade.getInstance(); - } - - protected Map<String, Object> convertFencingPolicy(VDS proxyHost) { - Map<String, Object> map = null; - if (fencingPolicy != null - && FencingPolicyHelper.isFencingPolicySupported(proxyHost.getSupportedClusterVersionsSet())) { - // fencing policy is entered and proxy supports passing fencing policy parameters - map = new HashMap<>(); - if (fencingPolicy.isSkipFencingIfSDActive()) { - // create map STORAGE_DOMAIN_GUID -> HOST_SPM_ID to pass to fence proxy - map.put(VdsProperties.STORAGE_DOMAIN_HOST_ID_MAP, createStorageDomainHostIdMap()); - } - } - return map; - } - - protected Map<Guid, Integer> createStorageDomainHostIdMap() { - Map<Guid, Integer> map = null; - if (fencingPolicy.isSkipFencingIfSDActive()) { - map = new HashMap<>(); - - vds_spm_id_map hostIdRecord = getDbFacade().getVdsSpmIdMapDao().get(_vds.getId()); - - // create a map SD_GUID -> HOST_ID - for (StorageDomain sd : getDbFacade().getStorageDomainDao().getAllForStoragePool(_vds.getStoragePoolId())) { - if (sd.getStorageStaticData().getStorageDomainType() == StorageDomainType.Master || - sd.getStorageStaticData().getStorageDomainType() == StorageDomainType.Data) { - // VDS_SPM_ID identifies the host in sanlock - map.put(sd.getId(), hostIdRecord.getvds_spm_id()); - } - } - } - return map; - } -} diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java deleted file mode 100644 index 9a662c6..0000000 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/FenceExecutorTest.java +++ /dev/null @@ -1,327 +0,0 @@ -package org.ovirt.engine.core.bll; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.stub; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.LinkedList; -import java.util.List; - -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.ovirt.engine.core.bll.interfaces.BackendInternal; -import org.ovirt.engine.core.common.businessentities.ArchitectureType; -import org.ovirt.engine.core.common.businessentities.AuditLog; -import org.ovirt.engine.core.common.businessentities.pm.FenceActionType; -import org.ovirt.engine.core.common.businessentities.FenceAgent; -import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue; -import org.ovirt.engine.core.common.businessentities.VDS; -import org.ovirt.engine.core.common.businessentities.VDSGroup; -import org.ovirt.engine.core.common.businessentities.VdsSpmStatus; -import org.ovirt.engine.core.common.businessentities.VdsStatic; -import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend; -import org.ovirt.engine.core.common.vdscommands.GetDeviceListVDSCommandParameters; -import org.ovirt.engine.core.common.vdscommands.VDSCommandType; -import org.ovirt.engine.core.common.vdscommands.VDSFenceReturnValue; -import org.ovirt.engine.core.common.vdscommands.VDSParametersBase; -import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; -import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.compat.Version; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.dao.AuditLogDAO; -import org.ovirt.engine.core.dao.VdsDAO; -import org.ovirt.engine.core.dao.VdsGroupDAO; -import org.ovirt.engine.core.utils.MockConfigRule; - -@RunWith(MockitoJUnitRunner.class) -public class FenceExecutorTest extends DbDependentTestBase { - - private static final Version CLUSTER_VERSION = Version.v3_0; - private static final ArchitectureType CLUSTER_ARCHITECTURE_TYPE = ArchitectureType.ppc64; - private static Guid FENCECD_HOST_ID = new Guid("11111111-1111-1111-1111-111111111111"); - private static Guid PROXY_HOST_ID = new Guid("44444444-4444-4444-4444-444444444444"); - private static Guid SECOND_PROXY_HOST_ID = new Guid("77777777-7777-7777-7777-777777777777"); - private static Guid FENCECD_HOST_CLUSTER_ID = new Guid("22222222-2222-2222-2222-222222222222"); - private static Guid FENCED_HOST_DATACENTER_ID = new Guid("33333333-3333-3333-3333-333333333333"); - private static Guid FENCE_AGENT_ID = new Guid("55555555-5555-5555-5555-555555555555"); - - @ClassRule - public static MockConfigRule configRule = - new MockConfigRule(MockConfigRule.mockConfig(ConfigValues.FenceAgentMapping, "")); - - @Mock - private VDS vds; - - @Mock - private VdsDAO vdsDao; - - @Mock - private VdsGroupDAO vdsGroupDao; - - @Mock - private AuditLogDAO auditLogDao; - - private VdsStatic vdsStatic = new VdsStatic(); - - @Mock - private VdsArchitectureHelper architectureHelper; - - @Mock - private FenceProxyLocator proxyLocator; - - private FenceExecutor executor; - - @Mock - private VDSBrokerFrontend vdsBrokerFrontend; - - @Mock - private BackendInternal backend; - - @Before - public void setup() { - mockDbFacades(); - mockVds(); - executor = new FenceExecutor(vds); - executor.setArchitectureHelper(architectureHelper); - executor.setProxyLocator(proxyLocator); - executor = spy(executor); - stub(executor.getBackend()).toReturn(backend); - VDSReturnValue retValue = new VDSReturnValue(); - retValue.setSucceeded(true); - when(backend.getResourceManager()).thenReturn(vdsBrokerFrontend); - when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), any(VDSParametersBase.class))).thenReturn(retValue); - when(architectureHelper.getArchitecture(vdsStatic)).thenReturn(CLUSTER_ARCHITECTURE_TYPE); - doReturn("").when(executor).getOptions(any(FenceAgent.class), any(VDS.class)); - } - - private void mockDbFacades() { - when(vdsDao.get(FENCECD_HOST_ID)).thenReturn(vds); - VDSGroup cluster = mockCluster(); - when(vdsGroupDao.get(FENCECD_HOST_CLUSTER_ID)).thenReturn(cluster); - doNothing().when(auditLogDao).save(any(AuditLog.class)); - when(DbFacade.getInstance().getVdsDao()).thenReturn(vdsDao); - when(DbFacade.getInstance().getVdsGroupDao()).thenReturn(vdsGroupDao); - when(DbFacade.getInstance().getAuditLogDao()).thenReturn(auditLogDao); - } - - private VDSGroup mockCluster() { - VDSGroup cluster = new VDSGroup(); - cluster.setId(FENCECD_HOST_CLUSTER_ID); - cluster.setCompatibilityVersion(CLUSTER_VERSION); - cluster.setArchitecture(CLUSTER_ARCHITECTURE_TYPE); - return cluster; - } - - private void mockVds() { - when(vds.getId()).thenReturn(FENCECD_HOST_ID); - when(vds.getVdsGroupId()).thenReturn(FENCECD_HOST_CLUSTER_ID); - when(vds.getStoragePoolId()).thenReturn(FENCED_HOST_DATACENTER_ID); - when(vds.getStaticData()).thenReturn(vdsStatic); - when(vds.getSpmStatus()).thenReturn(VdsSpmStatus.Contending); - List<FenceAgent> agents = new LinkedList<>(); - agents.add(createAgent()); - when(vds.getFenceAgents()).thenReturn(agents); - } - - private void mockProxyHost() { - mockProxyHost(false); - } - - private void mockProxyHost(boolean anotherProxyAvailable) { - VDS proxyHost = new VDS(); - proxyHost.setId(PROXY_HOST_ID); - when(proxyLocator.findProxyHost()).thenReturn(proxyHost); - when(proxyLocator.findProxyHost(true)).thenReturn(proxyHost); - VDS secondProxyHost = new VDS(); - if (anotherProxyAvailable) { - secondProxyHost.setId(SECOND_PROXY_HOST_ID); - when(proxyLocator.findProxyHost(true, PROXY_HOST_ID)).thenReturn(secondProxyHost); - } else { - when(proxyLocator.findProxyHost(true, PROXY_HOST_ID)).thenReturn(null); - } - } - - private void mockFenceSuccess() { - VDSReturnValue returnValue = new VDSReturnValue(); - returnValue.setSucceeded(true); - when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), any(GetDeviceListVDSCommandParameters.class))).thenReturn(returnValue); - } - - private void mockFenceFailure(boolean succeedOnSecondAttempt) { - VDSReturnValue firstReturnValue = new VDSReturnValue(); - firstReturnValue.setSucceeded(false); - VDSReturnValue secondReturnValue = new VDSReturnValue(); - secondReturnValue.setSucceeded(succeedOnSecondAttempt ? true : false); - when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), any(GetDeviceListVDSCommandParameters.class))).thenReturn(firstReturnValue) - .thenReturn(secondReturnValue); - } - - /** - * Test that the correct error-message is conveyed when no proxy host is found. - */ - @Test - public void checkStatus_handleProxyNotFound() { - when(proxyLocator.findProxyHost()).thenReturn(null); - VDSFenceReturnValue result = executor.checkHostStatus(); - assertFalse(result.getSucceeded()); - assertTrue(result.getExceptionString().contains("no running proxy Host was found")); - } - - /** - * Test that the return value is correct when fencing succeeds. The return value should contain succeeded=true and - * the agent used. - */ - @Test - public void successfulFence() { - mockProxyHost(); - mockFenceSuccess(); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.START, agent); - assertTrue(result.getSucceeded()); - assertEquals(result.getFenceAgentUsed(), agent); - } - - /** - * Test that SPM is stopped when Fence.Stop is activated. - */ - @Test - public void successfullSpmFence() { - mockProxyHost(); - mockFenceSuccess(); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.STOP, agent); - verify(vdsBrokerFrontend).RunVdsCommand(eq(VDSCommandType.SpmStop), any(VDSParametersBase.class)); - assertTrue(result.getSucceeded()); - assertEquals(result.getFenceAgentUsed(), agent); - } - - - /** - * Test that when first fence attempt fails, fence is retried with a different proxy. - */ - @Test - public void successfulFenceWithDifferentProxyRetry() { - mockProxyHost(true); - mockFenceFailure(true); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.START, agent); - assertTrue(result.getSucceeded()); - verify(proxyLocator).findProxyHost(true, PROXY_HOST_ID); - } - - /** - * Test that when first fence attempt fails, and no alternative proxy is found, fence is retried with the same - * proxy. - */ - @Test - public void successfulFenceWithSameProxyRetry() { - mockProxyHost(false); - mockFenceFailure(true); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.START, agent); - assertTrue(result.getSucceeded()); - verify(proxyLocator).findProxyHost(true, PROXY_HOST_ID); - } - - /** - * Test that when first fence attempt fails, and also the second attempt, using a different proxy, fails, the return - * value contains succceeded=false. - */ - @Test - public void failedFenceWithDifferentProxyRetry() { - mockProxyHost(true); - mockFenceFailure(false); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.START, agent); - assertFalse(result.getSucceeded()); - verify(proxyLocator).findProxyHost(true, PROXY_HOST_ID); - } - - /** - * Test that when first fence attempt fails, and also the second attempt, using the smae proxy, fails, the return - * value contains succceeded=false. - */ - @Test - public void failedFenceWithSameProxyRetry() { - mockProxyHost(false); - mockFenceFailure(false); - FenceAgent agent = createAgent(); - VDSFenceReturnValue result = executor.fence(FenceActionType.START, agent); - assertFalse(result.getSucceeded()); - verify(proxyLocator).findProxyHost(true, PROXY_HOST_ID); - } - - - /** - * Tests that when at least one agent returns 'on', checkHostStatus() returns 'on'. Mocking makes the first agent - * return 'off'. FenceExecutor then tries the next agent, which is mocked to return true. - */ - @Test - public void checkHostStatusOn() { - mockProxyHost(); - VDSReturnValue returnValueOff = new VDSReturnValue(); - returnValueOff.setSucceeded(true); - FenceStatusReturnValue statusOff = new FenceStatusReturnValue("off", ""); - returnValueOff.setReturnValue(statusOff); - VDSReturnValue returnValueOn = new VDSReturnValue(); - returnValueOn.setSucceeded(true); - FenceStatusReturnValue statusOn = new FenceStatusReturnValue("on", ""); - returnValueOn.setReturnValue(statusOn); - when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), any(GetDeviceListVDSCommandParameters.class))).thenReturn(returnValueOff) - .thenReturn(returnValueOn); - List<FenceAgent> agents = new LinkedList<>(); - agents.add(createAgent()); - agents.add(createAgent()); - when(vds.getFenceAgents()).thenReturn(agents); - VDSFenceReturnValue result = executor.checkHostStatus(); - assertTrue(result.getSucceeded()); - assertTrue(result.getReturnValue() instanceof FenceStatusReturnValue); - FenceStatusReturnValue status = (FenceStatusReturnValue) result.getReturnValue(); - assertEquals(status.getStatus(), "on"); - } - - /** - * Tests that when no even a single agent returns 'on', checkHostStatus() returns 'off'. Two agents are mocked to - * return status 'off'. FenceExecutor tries both of them and returns status=off - */ - @Test - public void checkHostStatusOff() { - mockProxyHost(); - VDSReturnValue returnValueOff = new VDSReturnValue(); - returnValueOff.setSucceeded(true); - FenceStatusReturnValue statusOff = new FenceStatusReturnValue("off", ""); - returnValueOff.setReturnValue(statusOff); - when(vdsBrokerFrontend.RunVdsCommand(eq(VDSCommandType.FenceVds), any(GetDeviceListVDSCommandParameters.class))).thenReturn(returnValueOff) - .thenReturn(returnValueOff); - List<FenceAgent> agents = new LinkedList<>(); - agents.add(createAgent()); - agents.add(createAgent()); - when(vds.getFenceAgents()).thenReturn(agents); - VDSFenceReturnValue result = executor.checkHostStatus(); - assertTrue(result.getSucceeded()); - assertTrue(result.getReturnValue() instanceof FenceStatusReturnValue); - FenceStatusReturnValue status = (FenceStatusReturnValue) result.getReturnValue(); - assertEquals(status.getStatus(), "off"); - } - - - private FenceAgent createAgent() { - FenceAgent agent = new FenceAgent(); - agent.setId(FENCE_AGENT_ID); - return agent; - } - -} 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 a34ef7d..8eabb24 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 @@ -982,8 +982,6 @@ FENCE_OPERATION_STARTED(9017), FENCE_OPERATION_SUCCEEDED(9018), FENCE_OPERATION_FAILED(9019, AuditLogSeverity.ERROR), - FENCE_USING_AGENT_AND_PROXY_HOST(9020), - FENCE_OPERATION_FAILED_USING_PROXY(9021, AuditLogSeverity.WARNING), TASK_STOPPING_ASYNC_TASK(9500, AuditLogTimeInterval.MINUTE.getValue()), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceStatusReturnValue.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceStatusReturnValue.java deleted file mode 100644 index eac8348..0000000 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceStatusReturnValue.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.ovirt.engine.core.common.businessentities; - -import java.io.Serializable; - -import org.ovirt.engine.core.compat.StringHelper; - -public class FenceStatusReturnValue implements Serializable { - private static final long serialVersionUID = 8070963676213797507L; - // indicates that operation was skipped because Host is already in requested state. - public static final String SKIPPED_DUE_TO_STATUS = "skipped_due_to_status"; - public static final String SKIPPED_DUE_TO_POLICY = "skipped"; - public static final String INITIATED = "initiated"; - public FenceStatusReturnValue(String status, String message) { - _status = status; - _message = message; - } - - private String _status; - - public String getStatus() { - return _status; - } - - private String _message; - - public String getMessage() { - return ("done".equalsIgnoreCase(_message)) ? "" : _message; - } - - public boolean getIsSucceeded() { - return (StringHelper.isNullOrEmpty(getMessage())); - } - - public boolean getIsSkippedDueToStatus() { - return SKIPPED_DUE_TO_STATUS.equalsIgnoreCase(_status); - } - - public boolean getIsSkippedDueToPolicy() { - return SKIPPED_DUE_TO_POLICY.equalsIgnoreCase(_status); - } - - public boolean getIsInitiated() { - return INITIATED.equalsIgnoreCase(_status); - } - - @Override - public String toString() { - final String TEST_SUCCEEDED = "Test Succeeded, "; - final String TEST_FAILED = "Test Failed, "; - - return getIsSucceeded() ? TEST_SUCCEEDED + getStatus() : TEST_FAILED + getMessage(); - } - - public FenceStatusReturnValue() { - } -} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSFenceReturnValue.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSFenceReturnValue.java deleted file mode 100644 index 5b6ce85..0000000 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSFenceReturnValue.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.ovirt.engine.core.common.vdscommands; - -import org.ovirt.engine.core.common.businessentities.FenceAgent; -import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue; -import org.ovirt.engine.core.common.businessentities.VDS; - -public class VDSFenceReturnValue extends VDSReturnValue { - - public VDSFenceReturnValue() { - super(); - } - - private VDS proxyHostUsed; - private FenceAgent fenceAgentUsed; - - public VDSFenceReturnValue(VDSReturnValue result) { - super(); - setCreationInfo(result.getCreationInfo()); - setExceptionObject(result.getExceptionObject()); - setExceptionString(result.getExceptionString()); - setReturnValue(result.getReturnValue()); - setSucceeded(result.getSucceeded()); - setVdsError(result.getVdsError()); - } - - public VDS getProxyHostUsed() { - return proxyHostUsed; - } - - public void setProxyHostUsed(VDS proxyHostUsed) { - this.proxyHostUsed = proxyHostUsed; - } - - public FenceAgent getFenceAgentUsed() { - return fenceAgentUsed; - } - - public void setFenceAgentUsed(FenceAgent fenceAgentUsed) { - this.fenceAgentUsed = fenceAgentUsed; - } - - public boolean isProxyHostFound() { - return proxyHostUsed != null; - } - - /** - * Determines according to the return status from fence invocation whether the fence-operation has been skipped - * due to status already reached - */ - public boolean isSkippedDueToStatus() { - if (getReturnValue() != null && getReturnValue() instanceof FenceStatusReturnValue) { - FenceStatusReturnValue fenceStatus = - (FenceStatusReturnValue) getReturnValue(); - return fenceStatus.getIsSkippedDueToStatus(); - } else { - return false; - } - } - - /** - * Determines according to the return status from fence invocation whether the fence-operation has been skipped - * due to fencing policy - */ - public boolean isSkippedDueToPolicy() { - if (getReturnValue() != null && getReturnValue() instanceof FenceStatusReturnValue) { - FenceStatusReturnValue fenceStatus = - (FenceStatusReturnValue) getReturnValue(); - return fenceStatus.getIsSkippedDueToPolicy(); - } else { - return false; - } - } -} diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index f6ec37f..e7f49f1 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -594,8 +594,6 @@ FENCE_OPERATION_STARTED=Power management ${Action} of Host ${VdsName} initiated. FENCE_OPERATION_SUCCEEDED=Power management ${Action} of Host ${VdsName} succeeded. FENCE_OPERATION_FAILED=Power management ${Action} of Host ${VdsName} failed. -FENCE_USING_AGENT_AND_PROXY_HOST=${Action} Host ${Host} using Proxy-Host ${ProxyHost} and fence-agent ${Agent}. -FENCE_OPERATION_FAILED_USING_PROXY=${Action} Host ${Host} using Proxy-Host ${ProxyHost} and fence-agent ${Agent} has failed. RECONSTRUCT_MASTER_FAILED_NO_MASTER=No valid Data Storage Domains are available in Data Center ${StoragePoolName} (please check your storage infrastructure). RECONSTRUCT_MASTER_DONE=Reconstruct Master Domain for Data Center ${StoragePoolName} completed. RECONSTRUCT_MASTER_FAILED=Failed to Reconstruct Master Domain for Data Center ${StoragePoolName}. -- To view, visit https://gerrit.ovirt.org/38972 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If4ded059813f1472d7546e8c7c29a2538c74c945 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Peřina <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
