Yair Zaslavsky has uploaded a new change for review. Change subject: core: VmPropertiesUtils should be initialized via StartupBean ......................................................................
core: VmPropertiesUtils should be initialized via StartupBean This patch fixes VmPropertiesUtils to be initialized at StartUpBean and makes sure that engine does not crash if cusotm properties are not properly set at vdc_options. This is a first patch in series (the 2nd part will be dealing with validations at engine-config) Change-Id: If25ef37b0d9ff79737e7efe8283372aca70b0dcb Bug-Id: https://bugzilla.redhat.com/878694 Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java A backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/exceptions/InitializationException.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vmproperties/VmPropertiesUtils.java 3 files changed, 75 insertions(+), 27 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/9430/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java index 59cb17d..2f6603e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InitBackendServicesOnStartupBean.java @@ -11,9 +11,11 @@ import org.ovirt.engine.core.bll.storage.StoragePoolStatusHandler; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.utils.exceptions.InitializationException; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil; +import org.ovirt.engine.core.utils.vmproperties.VmPropertiesUtils; import org.ovirt.engine.core.vdsbroker.ResourceManager; /** @@ -55,6 +57,17 @@ StoragePoolStatusHandler.Init(); GlusterManager.getInstance().init(); + //The following initializations should not stop Engine initialization + //Currently - only VmPropertiesUtils initialization is included in this + //try catch block - failure to initialize vm properties should not cause Engine to + //crash on startup, as there might be VMs in the setup that do not use custom properties + try { + log.infoFormat("Init VM Custom Properties utilities: {0}", new Date()); + VmPropertiesUtils.getInstance().init(); + } catch (InitializationException e) { + log.errorFormat("Initialization failed. Exception message is {0} ",e.getMessage()); + log.debug("Initialization failed ",e); + } } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/exceptions/InitializationException.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/exceptions/InitializationException.java new file mode 100644 index 0000000..e04ce92 --- /dev/null +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/exceptions/InitializationException.java @@ -0,0 +1,31 @@ +package org.ovirt.engine.core.utils.exceptions; + +/** + * Exception marking failure in initialization flow + * + */ +public class InitializationException extends Exception { + + public InitializationException() { + } + + public InitializationException(String message) { + super(message); + } + + public InitializationException(Throwable cause) { + super(cause); + } + + public InitializationException(String message, Throwable cause) { + super(message, cause); + } + + public InitializationException(String message, + Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vmproperties/VmPropertiesUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vmproperties/VmPropertiesUtils.java index a3d8f2b..6f326e0 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vmproperties/VmPropertiesUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vmproperties/VmPropertiesUtils.java @@ -18,6 +18,7 @@ import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.utils.MultiValueMapUtils; +import org.ovirt.engine.core.utils.exceptions.InitializationException; /** * Helper methods to help parse and validate predefined and UserDefined(user defined) properties. These methods are used @@ -54,6 +55,11 @@ private Map<Version, Map<String, Pattern>> predefinedProperties; private Map<Version, Map<String, Pattern>> userdefinedProperties; private Map<Version, String> allVmProperties; + + static { + vmPropertiesUtils = new VmPropertiesUtils(); + + } // Defines why validation failed public enum ValidationFailureReason { @@ -106,37 +112,35 @@ } public static VmPropertiesUtils getInstance() { - if (vmPropertiesUtils == null) { - vmPropertiesUtils = new VmPropertiesUtils(); - vmPropertiesUtils.init(); - } return vmPropertiesUtils; } - private void init() { - if (allVmProperties != null) - return; - predefinedProperties = new HashMap<Version, Map<String, Pattern>>(); - userdefinedProperties = new HashMap<Version, Map<String, Pattern>>(); - allVmProperties = new HashMap<Version, String>(); - Set<Version> versions = getSupportedClusterLevels(); - String predefinedVMPropertiesStr, userDefinedVMPropertiesStr; - StringBuilder sb; - for (Version version : versions) { - predefinedVMPropertiesStr = getPredefinedVMProperties(version); - userDefinedVMPropertiesStr = getUserdefinedVMProperties(version); - sb = new StringBuilder(""); - sb.append(predefinedVMPropertiesStr); - if (!predefinedVMPropertiesStr.isEmpty() && !userDefinedVMPropertiesStr.isEmpty()) { - sb.append(";"); - } - sb.append(userDefinedVMPropertiesStr); - allVmProperties.put(version, sb.toString()); + public void init() throws InitializationException { + try { + predefinedProperties = new HashMap<Version, Map<String, Pattern>>(); + userdefinedProperties = new HashMap<Version, Map<String, Pattern>>(); + allVmProperties = new HashMap<Version, String>(); + Set<Version> versions = getSupportedClusterLevels(); + String predefinedVMPropertiesStr, userDefinedVMPropertiesStr; + StringBuilder sb; + for (Version version : versions) { + predefinedVMPropertiesStr = getPredefinedVMProperties(version); + userDefinedVMPropertiesStr = getUserdefinedVMProperties(version); + sb = new StringBuilder(""); + sb.append(predefinedVMPropertiesStr); + if (!predefinedVMPropertiesStr.isEmpty() && !userDefinedVMPropertiesStr.isEmpty()) { + sb.append(";"); + } + sb.append(userDefinedVMPropertiesStr); + allVmProperties.put(version, sb.toString()); - predefinedProperties.put(version, new HashMap<String, Pattern>()); - userdefinedProperties.put(version, new HashMap<String, Pattern>()); - parseVMPropertiesRegex(predefinedVMPropertiesStr, predefinedProperties.get(version)); - parseVMPropertiesRegex(userDefinedVMPropertiesStr, userdefinedProperties.get(version)); + predefinedProperties.put(version, new HashMap<String, Pattern>()); + userdefinedProperties.put(version, new HashMap<String, Pattern>()); + parseVMPropertiesRegex(predefinedVMPropertiesStr, predefinedProperties.get(version)); + parseVMPropertiesRegex(userDefinedVMPropertiesStr, userdefinedProperties.get(version)); + } + } catch (Throwable ex) { + throw new InitializationException(ex); } } -- To view, visit http://gerrit.ovirt.org/9430 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If25ef37b0d9ff79737e7efe8283372aca70b0dcb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches