Ravi Nori has uploaded a new change for review.

Change subject: tools : engine-config is over writing the previous values
......................................................................

tools : engine-config is over writing the previous values

'engine-config -s' is over writing the existing values
with the new ones from command line.

A new option to merge the new values provided with the
values in the database has been added.

'engine-config -m' or 'engine-config --merge'

This concatenates the new value with the exisiting value
in the database.

Change-Id: I5c70539f47c509e3b8c23b1aa3de41bead36c1b4
Bug-Url: https://bugzilla.redhat.com/1069768
Signed-off-by: Ravi Nori <[email protected]>
---
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigCLIParser.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/config/validation/ConfigActionType.java
3 files changed, 46 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/62/25762/1

diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigCLIParser.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigCLIParser.java
index 976e426..2f5388a 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigCLIParser.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigCLIParser.java
@@ -90,9 +90,11 @@
      */
     private void parseSecondArgWithoutDash(String arg, boolean passFileExists) 
{
         int delimiterIndex = arg.indexOf("=");
-        if (getConfigAction().equals(ConfigActionType.ACTION_SET) && 
delimiterIndex == -1 &&
-                 !passFileExists) {
-            throw new IllegalArgumentException("Argument for set action must 
be in format of key=value.");
+        if ((getConfigAction().equals(ConfigActionType.ACTION_SET)
+                || getConfigAction().equals(ConfigActionType.ACTION_MERGE))
+                && delimiterIndex == -1
+                && !passFileExists) {
+            throw new IllegalArgumentException("Argument for set/concat action 
must be in format of key=value.");
         }
 
         String key = getStringBeforeEqualChar(arg, delimiterIndex);
@@ -100,7 +102,9 @@
         if (!key.isEmpty()) {
             if (!value.isEmpty()) {
                 parseSecondArgWithKeyValue(arg, key, value);
-            } else if (getConfigAction().equals(ConfigActionType.ACTION_SET) 
&& getKey() == null) {
+            } else if ((getConfigAction().equals(ConfigActionType.ACTION_SET)
+                    || getConfigAction().equals(ConfigActionType.ACTION_MERGE))
+                    && getKey() == null) {
                 engineConfigMap.setKey(key);
                 engineConfigMap.setValue(value);
             } else if ((getConfigAction().equals(ConfigActionType.ACTION_GET) 
|| getConfigAction().equals(ConfigActionType.ACTION_HELP))
@@ -120,7 +124,8 @@
      * @param arg
      */
     private void parseSecondArgWithKeyValue(String arg, String key, String 
value) {
-        if (getConfigAction().equals(ConfigActionType.ACTION_SET)) {
+        if (getConfigAction().equals(ConfigActionType.ACTION_SET)
+                || getConfigAction().equals(ConfigActionType.ACTION_MERGE)) {
             engineConfigMap.setKey(key);
             engineConfigMap.setValue(value);
         } else {
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
index 0705d6c..f3e4817 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/EngineConfigLogic.java
@@ -105,6 +105,9 @@
         case ACTION_SET:
             persistValue();
             break;
+        case ACTION_MERGE:
+            mergeValue();
+            break;
         case ACTION_HELP:
             printHelpForKey();
             break;
@@ -370,6 +373,37 @@
         }
     }
 
+    /**
+     * Concatenates the value of the given key for the given version. Is the 
actual execution of the
+     * 'merge' action ('-m', '--merge')
+     */
+    private void mergeValue() throws Exception {
+        String key = parser.getKey();
+        String value = parser.getValue();
+        String version = parser.getVersion();
+        if (version == null) {
+            version = startVersionDialog(key);
+        }
+        ConfigKey configKey = fetchConfigKey(key, version);
+        if (configKey != null && configKey.getKey() != null) {
+            if (!configKey.isPasswordKey() && 
configKey.getDisplayValue().trim().length() > 0) {
+                String val = configKey.getDisplayValue();
+                if (!val.endsWith(";")) {
+                    val += ";";
+                }
+                val += value;
+                value = val;
+            }
+        }
+        boolean sucessUpdate = persist(key, value, version);
+        if (!sucessUpdate) {
+            log.debug("setValue: error concatenating " + key + "'s value. No 
such entry"
+                    + (version == null ? "" : " with version " + version) + 
".");
+            throw new IllegalArgumentException("Error setting " + key + "'s 
value. No such entry"
+                    + (version == null ? "" : " with version " + version) + 
".");
+        }
+    }
+
     private void printHelpForKey() throws Exception {
         final String keyName = parser.getKey();
         boolean foundKey = iterateAllKeys(this.configKeyFactory, keysConfig, 
new ConfigKeyHandler() {
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/validation/ConfigActionType.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/validation/ConfigActionType.java
index 15efbe3..496b293 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/validation/ConfigActionType.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/config/validation/ConfigActionType.java
@@ -16,7 +16,8 @@
     ACTION_GET(Arrays.asList(new String[] { "-g", "--get" }), new 
ValidatorType[] { ValidatorType.get }),
     ACTION_SET(Arrays.asList(new String[] { "-s", "--set" }), new 
ValidatorType[] { ValidatorType.set }),
     ACTION_HELP(Arrays.asList(new String[] { "-h", "--help" }), new 
ValidatorType[] { ValidatorType.help }),
-    ACTION_RELOAD(Arrays.asList(new String[] { "-r", "--reload" }), null);
+    ACTION_RELOAD(Arrays.asList(new String[] { "-r", "--reload" }), null),
+    ACTION_MERGE(Arrays.asList(new String[] { "-m", "--merge" }), new 
ValidatorType[] { ValidatorType.set });
 
     private List<String> optionalStrings;
     private ValidatorType[] validatorTypes;


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

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

Reply via email to