Yair Zaslavsky has uploaded a new change for review.

Change subject: [WIP] tools: Introducing ConfigInfo provider (#858769)
......................................................................

[WIP] tools: Introducing ConfigInfo provider (#858769)

https://bugzilla.redhat.com/858769

This patch is first stage in introducing db consistency to
manage-domains -
If one of the updates of options at vdc_options fail, all
updates should rollback.
This patch introduces a facility for decoupling engine-config
logic code from the way it obtains configuration information
(key , value, version ) and introduces the
ConfigInfoParserProvider that will be used for the current
"set" operation

Change-Id: Icaadd9eb23016b4866e5cfa99f919378f09fdf1a
Signed-off-by: Yair Zaslavsky <[email protected]>
---
A 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoParserProvider.java
A 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProvider.java
A 
backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProviderException.java
3 files changed, 117 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/8157/1

diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoParserProvider.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoParserProvider.java
new file mode 100644
index 0000000..01452ea
--- /dev/null
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoParserProvider.java
@@ -0,0 +1,77 @@
+package org.ovirt.engine.core.config;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.ovirt.engine.core.config.db.ConfigDAO;
+import org.ovirt.engine.core.config.entity.ConfigKey;
+
+public class ConfigInfoParserProvider implements ConfigInfoProvider {
+
+    private EngineConfigCLIParser parser;
+    private ConfigDAO configDao;
+
+    public ConfigInfoParserProvider(EngineConfigCLIParser parser, ConfigDAO 
configDao) {
+        this.parser = parser;
+        this.configDao = configDao;
+    }
+
+    @Override
+    public String getKey() throws ConfigInfoProviderException {
+       return parser.getKey();
+    }
+
+    @Override
+    public String getValue() throws ConfigInfoProviderException {
+        return parser.getValue();
+    }
+
+    @Override
+    public String getVersion() throws ConfigInfoProviderException {
+        String version = parser.getVersion();
+        if (version == null) {
+            version = startVersionDialog(getKey());
+        }
+        return version;
+    }
+    
+    private String startVersionDialog(String key) throws 
ConfigInfoProviderException {
+        log.debug("starting version dialog.");
+        String version = null;
+        try {
+            List<ConfigKey> keys = configDao.getKeysForName(key);
+            if (keys.size() == 1) {
+                version = keys.get(0).getVersion();
+            } else if (keys.size() > 1) {
+                BufferedReader br = new BufferedReader(new 
InputStreamReader(System.in));
+                while (true) {
+                    System.out.println("Please select a version:");
+                    for (int i = 0; i < keys.size(); i++) {
+                        System.out.println(i + 1 + ". " + 
keys.get(i).getVersion());
+                    }
+                    int index = 0;
+                    try {
+                        index = Integer.valueOf(br.readLine());
+                    } catch (NumberFormatException e) {
+                        continue;
+                    }
+                    if (index >= 1 && index <= keys.size()) {
+                        version = keys.get(index - 1).getVersion();
+                        break;
+                    }
+                } 
+            } 
+        } catch (Exception ex) {
+            throw new ConfigInfoProviderException(ex);
+        }
+        return version;
+    }
+    
+    
+    private final static Logger log = 
Logger.getLogger(ConfigInfoParserProvider.class);
+
+
+}
+        
\ No newline at end of file
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProvider.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProvider.java
new file mode 100644
index 0000000..6594563
--- /dev/null
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProvider.java
@@ -0,0 +1,31 @@
+package org.ovirt.engine.core.config;
+
+/**
+ * Defines functionality for configuration 
+ * information providers.
+ * An example for a provider is a provider that
+ * gets all information from a stream
+ * @author yzaslavs
+ *
+ */
+public interface ConfigInfoProvider {
+    
+    /**
+     * Returns the key part of the configuration 
+     * @return the key if exists, null if not
+     */
+    String getKey() throws ConfigInfoProviderException;
+    
+    /**
+     * Returns the value part of the configuration 
+     * @return the value if exists, null if not
+     */
+    String getValue() throws ConfigInfoProviderException;
+    
+    /**
+     * Returns the version part of the configuration
+     * @return the value if exists, null if not
+     */
+    String getVersion() throws ConfigInfoProviderException;
+
+}
diff --git 
a/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProviderException.java
 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProviderException.java
new file mode 100644
index 0000000..5d0560f
--- /dev/null
+++ 
b/backend/manager/tools/engine-config/src/main/java/org/ovirt/engine/core/config/ConfigInfoProviderException.java
@@ -0,0 +1,9 @@
+package org.ovirt.engine.core.config;
+
+public class ConfigInfoProviderException extends Exception{
+
+    public ConfigInfoProviderException(Throwable cause) {
+        super(cause);
+    }
+
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icaadd9eb23016b4866e5cfa99f919378f09fdf1a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to