Martin Peřina has uploaded a new change for review. Change subject: core: Prepare FenceVdsVDSCommand params on caller ......................................................................
core: Prepare FenceVdsVDSCommand params on caller Moves all FenceVdsVDSCommand parameters conversion to caller, where they belongs. Change-Id: Ie17020705e411160f0cceb149d1fe64185d612a5 Bug-Url: https://bugzilla.redhat.com/1182510 Signed-off-by: Martin Perina <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceExecutor.java M 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/vdscommands/FenceVdsVDSCommandParameters.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/FenceVdsVDSCommand.java 4 files changed, 68 insertions(+), 66 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/32/38232/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 index 4d1dd99..c2265bb 100644 --- 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 @@ -1,15 +1,22 @@ 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; @@ -20,6 +27,7 @@ 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; @@ -181,7 +189,7 @@ FenceAgent realAgent = new FenceAgent(agent); realAgent.setType(VdsFenceOptions.getRealAgent(agent.getType())); - realAgent.setOptions(getOptions(agent)); + realAgent.setOptions(getOptions(agent, proxyHost)); return getBackend().getResourceManager() .RunVdsCommand( @@ -191,7 +199,7 @@ _vds.getId(), realAgent, action, - fencingPolicy)); + convertFencingPolicy(proxyHost))); } private void auditFenceAction(FenceActionType action, FenceAgent agent, VDS proxyHost) { @@ -230,12 +238,17 @@ } } - private String getOptions(FenceAgent agent) { + protected String getOptions(FenceAgent agent, VDS proxyHost) { ArchitectureType architectureType = architectureHelper.getArchitecture(_vds.getStaticData()); String managementOptions = - VdsFenceOptions.getDefaultAgentOptions(agent.getType(), - agent.getOptions() == null ? "" : agent.getOptions(), - architectureType); + new VdsFenceOptions( + agent.getType(), + VdsFenceOptions.getDefaultAgentOptions( + agent.getType(), + agent.getOptions() == null ? "" : agent.getOptions(), + architectureType), + proxyHost.getVdsGroupCompatibilityVersion().toString() + ).ToInternalString(); return managementOptions; } @@ -287,4 +300,41 @@ 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 index cda70a4..9a662c6 100644 --- 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 @@ -6,6 +6,7 @@ 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; @@ -103,6 +104,7 @@ 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() { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/FenceVdsVDSCommandParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/FenceVdsVDSCommandParameters.java index ca7587a..a438a00 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/FenceVdsVDSCommandParameters.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/FenceVdsVDSCommandParameters.java @@ -1,15 +1,16 @@ package org.ovirt.engine.core.common.vdscommands; +import java.util.Map; + import org.ovirt.engine.core.common.businessentities.FenceAgent; import org.ovirt.engine.core.common.businessentities.pm.FenceActionType; -import org.ovirt.engine.core.common.businessentities.FencingPolicy; import org.ovirt.engine.core.compat.Guid; public class FenceVdsVDSCommandParameters extends VdsIdVDSCommandParametersBase { private Guid targetVdsId; private FenceAgent fenceAgent; private FenceActionType action; - private FencingPolicy fencingPolicy; + private Map<String, Object> fencingPolicyParams; private FenceVdsVDSCommandParameters() { action = FenceActionType.RESTART; @@ -21,12 +22,12 @@ Guid targetVdsId, FenceAgent fenceAgent, FenceActionType action, - FencingPolicy fencingPolicy) { + Map<String, Object> fencingPolicyParams) { super(proxyVdsId); this.targetVdsId = targetVdsId; this.fenceAgent = fenceAgent; this.action = action; - this.fencingPolicy = fencingPolicy; + this.fencingPolicyParams = fencingPolicyParams; } public Guid getTargetVdsID() { @@ -41,8 +42,8 @@ return action; } - public FencingPolicy getFencingPolicy() { - return fencingPolicy; + public Map<String, Object> getFencingPolicyParams() { + return fencingPolicyParams; } @Override @@ -53,6 +54,6 @@ getTargetVdsID(), getAction(), getFenceAgent(), - getFencingPolicy()); + getFencingPolicyParams()); } } diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/FenceVdsVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/FenceVdsVDSCommand.java index d221772..c9dca60 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/FenceVdsVDSCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/FenceVdsVDSCommand.java @@ -1,22 +1,14 @@ package org.ovirt.engine.core.vdsbroker.vdsbroker; -import java.util.HashMap; -import java.util.Map; - import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue; -import org.ovirt.engine.core.common.businessentities.StorageDomain; -import org.ovirt.engine.core.common.businessentities.StorageDomainType; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.pm.FenceActionType; -import org.ovirt.engine.core.common.businessentities.vds_spm_id_map; -import org.ovirt.engine.core.common.utils.FencingPolicyHelper; import org.ovirt.engine.core.common.vdscommands.FenceVdsVDSCommandParameters; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector; 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; public class FenceVdsVDSCommand<P extends FenceVdsVDSCommandParameters> extends VdsBrokerCommand<P> { private FenceStatusReturnForXmlRpc _result; @@ -129,46 +121,6 @@ return ret; } - protected Map<String, Object> convertFencingPolicy() { - Map<String, Object> map = null; - if (getParameters().getFencingPolicy() != null - && FencingPolicyHelper.isFencingPolicySupported(getProxyVds().getSupportedClusterVersionsSet())) { - // fencing policy is entered and proxy supports passing fencing policy parameters - map = new HashMap<>(); - if (getParameters().getFencingPolicy().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 (getParameters().getFencingPolicy().isSkipFencingIfSDActive()) { - map = new HashMap<>(); - - vds_spm_id_map hostIdRecord = getDbFacade().getVdsSpmIdMapDao().get( - getTargetVds().getId()); - - // create a map SD_GUID -> HOST_ID - for (StorageDomain sd : getDbFacade().getStorageDomainDao().getAllForStoragePool( - getTargetVds().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; - } - - protected String getVdsFenceOptions(String type, String options, String compatibilityVersion) { - return new VdsFenceOptions(type, options, compatibilityVersion).ToInternalString(); - } - protected FenceStatusReturnForXmlRpc fenceNode(FenceActionType actionType, boolean applyFencingPolicy) { return getBroker().fenceNode( getParameters().getFenceAgent().getIp(), @@ -180,11 +132,8 @@ getParameters().getFenceAgent().getPassword(), actionType.getValue(), "", - getVdsFenceOptions( - getParameters().getFenceAgent().getType(), - getParameters().getFenceAgent().getOptions(), - getProxyVds().getVdsGroupCompatibilityVersion().toString()), - applyFencingPolicy ? convertFencingPolicy() : null); + getParameters().getFenceAgent().getOptions(), + applyFencingPolicy ? getParameters().getFencingPolicyParams() : null); } @Override -- To view, visit https://gerrit.ovirt.org/38232 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie17020705e411160f0cceb149d1fe64185d612a5 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
