Mike Kolesnik has uploaded a new change for review. Change subject: engine: Add conditional execution to host deploy ......................................................................
engine: Add conditional execution to host deploy Added a way to declaratively determine which customization dialog steps need to be performed. The first usage is with the "IP tables override" step. Change-Id: I98b4fe7d11cdb267664113ac7312a0cd12268f94 Signed-off-by: Mike Kolesnik <mkole...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java 1 file changed, 51 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/49/16849/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java index f5a646e..7d83fc4 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsDeploy.java @@ -6,11 +6,18 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; import java.security.KeyPair; import java.security.KeyStoreException; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.TimeZone; import java.util.concurrent.Callable; @@ -205,6 +212,27 @@ */ /** + * Values to determine when customization should be performed. + */ + private static enum CustomizationCondition { + IPTABLES_OVERRIDE + }; + /** + * Special annotation to specify when the customization is necessary. + */ + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + private @interface CallWhen { + /** + * @return A condition that determines if the customization should run. + */ + CustomizationCondition value(); + } + /** + * A set of conditions under which the conditional customizations should run. + */ + private Set<CustomizationCondition> _customizationConditions = new HashSet<>(); + /** * Customization tick. */ private int _customizationIndex = 0; @@ -275,20 +303,16 @@ new Callable<Object>() { public Object call() throws Exception { _parser.cliEnvironmentSet( NetEnv.IPTABLES_ENABLE, - _iptables.length() > 0 + _customizationConditions.contains(CustomizationCondition.IPTABLES_OVERRIDE) ); return null; }}, - new Callable<Object>() { public Object call() throws Exception { - if (_iptables.length() == 0) { - _parser.cliNoop(); - } - else { - _parser.cliEnvironmentSet( - NetEnv.IPTABLES_RULES, - _iptables.split("\n") - ); - } + new Callable<Object>() {@CallWhen(CustomizationCondition.IPTABLES_OVERRIDE) + public Object call() throws Exception { + _parser.cliEnvironmentSet( + NetEnv.IPTABLES_RULES, + _iptables.split("\n") + ); return null; }}, new Callable<Object>() { public Object call() throws Exception { @@ -347,10 +371,11 @@ } return null; }}, - new Callable<Object>() { public Object call() throws Exception { - String minimal = Config.<String> GetValue(ConfigValues.BootstrapMinimalVdsmVersion); - if (minimal.trim().length() == 0) { - _parser.cliNoop(); + new Callable<Object>() { + public Object call() throws Exception { + String minimal = Config.<String> GetValue(ConfigValues.BootstrapMinimalVdsmVersion); + if (minimal.trim().length() == 0) { + _parser.cliNoop(); } else { _parser.cliEnvironmentSet( @@ -419,7 +444,16 @@ _parser.cliAbort(); } else { - _customizationDialog[_customizationIndex++].call(); + Callable<?> customizationStep = _customizationDialog[_customizationIndex++]; + Method callMethod = customizationStep.getClass().getDeclaredMethod("call"); + if (callMethod != null) { + CallWhen ann = callMethod.getAnnotation(CallWhen.class); + if (ann != null && !_customizationConditions.contains(ann.value())) { + _parser.cliNoop(); + return; + } + } + customizationStep.call(); } } catch (ArrayIndexOutOfBoundsException e) { @@ -819,6 +853,7 @@ public void setFirewall(boolean doFirewall) { if (doFirewall) { _iptables = _getIpTables(); + _customizationConditions.add(CustomizationCondition.IPTABLES_OVERRIDE); } } -- To view, visit http://gerrit.ovirt.org/16849 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I98b4fe7d11cdb267664113ac7312a0cd12268f94 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Mike Kolesnik <mkole...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches