Juan Hernandez has uploaded a new change for review.

Change subject: packaging: Add /etc/sysconfig/ovirt-engine.d
......................................................................

packaging: Add /etc/sysconfig/ovirt-engine.d

This is an optional directory where additional configuration files
(anything ending in .conf) can be placed. The engine will load them
after the defaults and the main configuration file, so they can override
the default configuration.

Change-Id: I8742b8e056d1122ee4350eccb77bcba0b0d0657b
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M Makefile
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/LocalConfig.java
M packaging/fedora/engine-service.py
M packaging/fedora/setup/basedefs.py
M packaging/fedora/spec/ovirt-engine.spec.in
5 files changed, 99 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/8789/1

diff --git a/Makefile b/Makefile
index 075933b..9fe3f89 100644
--- a/Makefile
+++ b/Makefile
@@ -206,7 +206,6 @@
        @install -dm 755 $(DESTDIR)$(PYTHON_DIR)/sos/plugins
        @install -dm 755 $(DESTDIR)$(PKG_SYSCONF_DIR)/engine-config
        @install -dm 755 $(DESTDIR)$(PKG_SYSCONF_DIR)/engine-manage-domains
-       @install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/sysconfig
        @install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/cron.daily
        @install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/security/limits.d
        @install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/rc.d/init.d
@@ -382,6 +381,8 @@
 
        # Install the files:
        install -dm 755 $(DESTDIR)$(DATA_DIR)/service
+       install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/sysconfig
+       install -dm 755 $(DESTDIR)$(SYSCONF_DIR)/sysconfig/ovirt-engine.d
        install -m 644 packaging/fedora/engine-service.xml.in 
$(DESTDIR)$(DATA_DIR)/service
        install -m 644 packaging/fedora/engine-service-logging.properties 
$(DESTDIR)$(DATA_DIR)/service
        install -m 755 packaging/fedora/engine-service.py 
$(DESTDIR)$(DATA_DIR)/service
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/LocalConfig.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/LocalConfig.java
index 710a517..8259b47 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/LocalConfig.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/LocalConfig.java
@@ -2,12 +2,16 @@
 
 import java.io.File;
 import java.io.FileReader;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.Enumeration;
+import java.util.List;
 import java.util.Properties;
 
 import org.apache.log4j.Logger;
@@ -23,8 +27,8 @@
     private static final Logger log = Logger.getLogger(LocalConfig.class);
 
     // Default files for defaults and overriden values:
-    private static final File DEFAULTS_FILE = new 
File("/usr/share/ovirt-engine/conf/engine.conf.defaults");
-    private static final File VARS_FILE = new 
File("/etc/sysconfig/ovirt-engine");
+    private static final String DEFAULTS_PATH = 
"/usr/share/ovirt-engine/conf/engine.conf.defaults";
+    private static final String VARS_PATH = "/etc/sysconfig/ovirt-engine";
 
     // This is a singleton and this is the instance:
     private static final LocalConfig instance = new LocalConfig();
@@ -34,30 +38,69 @@
     }
 
     // The properties object storing the current values of the parameters:
-    private Properties values;
+    private Properties values = new Properties();
 
     private LocalConfig() {
-        // Load the defaults:
-        Properties defaults = null;
-        try {
-            defaults = loadProperties("ENGINE_DEFAULTS", DEFAULTS_FILE, null);
+        // This is the list of configuration files that will be loaded and
+        // merged (the initial size is 2 because usually we will have only two
+        // configuration files to merge, the defaults and the variables):
+        List<File> configFiles = new ArrayList<File>(2);
+
+        // Locate the defaults file and add it to the list:
+        String defaultsPath = System.getenv("ENGINE_DEFAULTS");
+        if (defaultsPath == null) {
+            defaultsPath = DEFAULTS_PATH;
         }
-        catch (IOException exception) {
-            String message = "Can't load defaults file.";
-            log.error(message, exception);
-            throw new IllegalStateException(message, exception);
+        File defaultsFile = new File(defaultsPath);
+        configFiles.add(defaultsFile);
+
+        // Locate the overriden values file and add it to the list:
+        String varsPath = System.getenv("ENGINE_VARS");
+        if (varsPath == null) {
+            varsPath = VARS_PATH;
+        }
+        File varsFile = new File(varsPath);
+        configFiles.add(varsFile);
+
+        // Locate the override values directory and add the .conf files inside
+        // to the list, sorted alphabetically:
+        File varsDir = new File(varsPath + ".d");
+        if (varsDir.isDirectory()) {
+            File[] varsFiles = varsDir.listFiles(
+                new FilenameFilter() {
+                    @Override
+                    public boolean accept(File parent, String name) {
+                        return name.endsWith(".conf");
+                    }
+                }
+            );
+            Arrays.sort(
+                varsFiles,
+                new Comparator<File>() {
+                    @Override
+                    public int compare (File leftFile, File rightFile) {
+                        String leftName = leftFile.getName();
+                        String rightName = rightFile.getName();
+                        return leftName.compareTo(rightName);
+                    }
+                }
+            );
+            for (File file : varsFiles) {
+                configFiles.add(file);
+            }
         }
 
-        // Load the overriden values:
-        try {
-            values = loadProperties("ENGINE_VARS", VARS_FILE, defaults);
+        // Load the configuration files in the order they are in the list:
+        for (File configFile : configFiles) {
+            try {
+                loadProperties(configFile);
+            }
+            catch (IOException exception) {
+                String message = "Can't load configuration file.";
+                log.error(message, exception);
+                throw new IllegalStateException(message, exception);
+            }
         }
-        catch (IOException exception) {
-            String message = "Can't load configuration file.";
-            log.error(message, exception);
-            throw new IllegalStateException(message, exception);
-        }
-
 
         // Dump the properties to the log (this should probably be DEBUG, but 
as
         // it will usually happen only once, during the startup, is not that a
@@ -75,37 +118,21 @@
      * Load the contents of the properties file located by the given 
environment
      * variable or file.
      *
-     * @param variable the name of the environment variable that contains the 
name of
-     *    the file containing the properties
      * @param file the file that will be used to load the properties if the 
given
      *    environment variable doesn't have a value
-     * @param properties the previously created properties object
-     * @param defaults if not <code>null</code> this will be used as the 
defaults
-     *    for the created properties object
      */
-    private Properties loadProperties(String variable, File file, Properties 
defaults) throws IOException {
-        // Locate the file (the given file is just ignored if the environment
-        // variable has a value):
-        String path = System.getenv(variable);
-        if (path != null) {
-            log.info("Environment variable \"" + variable + "\" contains \"" + 
path + "\". Will load that file instead of \"" + file.getAbsolutePath() + 
"\".");
-            file = new File(path);
-        }
-
-        // Create an empty properties object:
-        Properties properties = new Properties(defaults);
-
+    private void loadProperties(File file) throws IOException {
         // Do nothing if the file doesn't exist or isn't readable:
         if (!file.canRead()) {
             log.warn("The file \"" + file.getAbsolutePath() + "\" doesn't 
exist or isn't readable. Will return an empty set of properties.");
-            return properties;
+            return;
         }
 
         // Load the file:
         Reader reader = null;
         try {
             reader = new FileReader(file);
-            properties.load(reader);
+            values.load(reader);
             log.info("Loaded file \"" + file.getAbsolutePath() + "\".");
         }
         catch (IOException exception) {
@@ -122,9 +149,6 @@
                 }
             }
         }
-
-        // Done:
-        return properties;
     }
 
     /**
diff --git a/packaging/fedora/engine-service.py 
b/packaging/fedora/engine-service.py
index 3f37856..d1cda6f 100644
--- a/packaging/fedora/engine-service.py
+++ b/packaging/fedora/engine-service.py
@@ -129,12 +129,25 @@
     if not os.path.exists(engineConfigFile):
         raise Exception("The engine configuration file \"%s\" doesn't exist." 
% engineConfigFile)
 
-    # Merge all the configuration files:
-    global engineConfig
-    engineConfig = Config([
+    # This will be the list of configuration files to load and merge, later
+    # files override earlier ones:
+    engineConfigFiles = [
         engineDefaultsFile,
         engineConfigFile,
-    ])
+    ]
+
+    # Find additional configuration files in the optional configuration
+    # directory, sorted alphabetically so that numeric prefixes can be used to
+    # force the order:
+    engineConfigDir = engineConfigFile + ".d"
+    if os.path.isdir(engineConfigDir): 
+        additionalEngineConfigFiles = glob.glob(engineConfigDir + "/*.conf")
+        additionalEngineConfigFiles.sort()
+        engineConfigFiles.extend(additionalEngineConfigFiles)
+        
+    # Merge all the configuration files:
+    global engineConfig
+    engineConfig = Config(engineConfigFiles)
 
     # Get the id of the engine user:
     global engineUser
diff --git a/packaging/fedora/setup/basedefs.py 
b/packaging/fedora/setup/basedefs.py
index f635c6b..611d9e4 100644
--- a/packaging/fedora/setup/basedefs.py
+++ b/packaging/fedora/setup/basedefs.py
@@ -71,7 +71,6 @@
 FILE_ENGINE_CERT="%s/certs/engine.cer"%(DIR_OVIRT_PKI)
 FILE_APACHE_CERT="%s/certs/apache.cer"%(DIR_OVIRT_PKI)
 FILE_JBOSSAS_CONF="/etc/%s/%s.conf" % (ENGINE_SERVICE_NAME, 
ENGINE_SERVICE_NAME)
-FILE_ENGINE_SYSCONFIG="/etc/sysconfig/ovirt-engine"
 FILE_DB_INSTALL_SCRIPT="engine-db-install.sh"
 FILE_DB_UPGRADE_SCRIPT="upgrade.sh"
 FILE_RHEVM_CONFIG_BIN="/usr/bin/engine-config"
@@ -100,6 +99,18 @@
 FILE_HTTPD_CONF="/etc/httpd/conf/httpd.conf"
 FILE_IMAGE_UPLOADER_CONF="/etc/ovirt-engine/imageuploader.conf"
 
+# File containing the local configuration of the engine:
+FILE_ENGINE_SYSCONFIG="/etc/sysconfig/ovirt-engine"
+
+# This directory can also contain local configuration files for the
+# engine that will be loaded in alphabetial order:
+DIR_ENGINE_SYSCONFIG="%s.d" % FILE_ENGINE_SYSCONFIG
+
+# This file will be automatically created when the engine goes into
+# maintenance mode during upgrades and automatically removed when the
+# engine goes back into normal mode once the upgrade is finished:
+FILE_ENGINE_SYSCONFIG_MAINTENANCE="%s/99-maintenance.conf" % 
DIR_ENGINE_SYSCONFIG
+
 # ISO FILES
 FILE_VIRTIO_WIN_VFD="/usr/share/virtio-win/virtio-win.vfd"
 FILE_VIRTIO_WIN_ISO="/usr/share/virtio-win/virtio-win.iso"
diff --git a/packaging/fedora/spec/ovirt-engine.spec.in 
b/packaging/fedora/spec/ovirt-engine.spec.in
index c2d1a59..cb34fa6 100644
--- a/packaging/fedora/spec/ovirt-engine.spec.in
+++ b/packaging/fedora/spec/ovirt-engine.spec.in
@@ -627,8 +627,9 @@
 %config(noreplace) %attr(-, %{engine_user}, %{engine_group}) 
%{engine_etc}/engine.conf
 
 # Files needed by the service:
-%config(noreplace) %{_sysconfdir}/sysconfig/%{engine_name}
 %config(noreplace) %{_sysconfdir}/security/limits.d/10-ovirt-engine.conf
+%config(noreplace) %{_sysconfdir}/sysconfig/%{engine_name}
+%dir %{_sysconfdir}/sysconfig/%{engine_name}.d
 %{engine_data}/service
 %{_bindir}/engine-service
 %{_unitdir}/%{engine_name}.service


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8742b8e056d1122ee4350eccb77bcba0b0d0657b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to