https://fedorahosted.org/freeipa/ticket/1688

The serial associator is used to execute a command multiple times with different parameters. This is used for adding/removing a user into/from multiple groups. It has some issues:

Each command is executed one-by-one, so it could be slow.
  * If there's a failure the rest of the commands will not be executed.
* This can be fixed by putting the commands into a batch and execute them at once.
--
Petr Vobornik
From cfa78cfbef6130739f4dd161a33d4f535bd0fc02 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <[email protected]>
Date: Thu, 25 Aug 2011 14:57:44 +0200
Subject: [PATCH] Modify serial associator to use batch

https://fedorahosted.org/freeipa/ticket/1688

The serial associator is used to execute a command multiple times with different parameters. This is used for adding/removing a user into/from multiple groups. It has some issues:

Each command is executed one-by-one, so it could be slow.
  * If there's a failure the rest of the commands will not be executed.
  * This can be fixed by putting the commands into a batch and execute them at once.
---
 install/ui/association.js            |   36 ++++++++++++++-------------
 install/ui/test/association_tests.js |   45 +++++++++++++++++++---------------
 2 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index b79a18f061229e51cc9534aadea38b8e2636a984..1c9776b0e6c596be4dd07665b141891d2e7d4ba0 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -64,28 +64,30 @@ IPA.serial_associator = function(spec) {
             return;
         }
 
-        var value = that.values.shift();
-        if (!value) {
-            that.on_success();
-            return;
-        }
-
-        var args = [value];
-        var options = {};
-        options[that.entity.name] = that.pkey;
-
-        var command = IPA.command({
-            entity: that.other_entity,
-            method: that.method,
-            args: args,
-            options: options,
-            on_success: that.execute,
+        var batch = IPA.batch_command({
+            on_success: that.on_success,
             on_error: that.on_error
         });
 
+        var args, options, command;
+
+        for(var i=0; i < that.values.length; i++) {
+            args = [that.values[i]];
+            options = {};
+            options[that.entity.name] = that.pkey;
+
+            command = IPA.command({
+                entity: that.other_entity,
+                method: that.method,
+                args: args,
+                options: options
+            });
+
+            batch.add_command(command);
+        }
         //alert(JSON.stringify(command.to_json()));
 
-        command.execute();
+        batch.execute();
     };
 
     return that;
diff --git a/install/ui/test/association_tests.js b/install/ui/test/association_tests.js
index 1cdc17ccb954832fa85d82dfa50fac57b12342b5..db01343307f27e142dafef98ab1479159bc83ee7 100644
--- a/install/ui/test/association_tests.js
+++ b/install/ui/test/association_tests.js
@@ -23,11 +23,9 @@ module('association');
 
 test("Testing serial_associator().", function() {
 
-    expect(10);
+    expect(11);
 
-    var orig_ipa_command = IPA.command;
-
-    var counter = 0;
+    var orig_ipa_batch_command = IPA.batch_command;
 
     var params = {
         method: 'add_member',
@@ -38,27 +36,34 @@ test("Testing serial_associator().", function() {
 
     params.values = ['user1', 'user2', 'user3'];
 
-    IPA.command = function(spec) {
+    IPA.batch_command = function(spec) {
 
-        var that = orig_ipa_command(spec);
+        var that = orig_ipa_batch_command(spec);
 
         that.execute = function() {
-            counter++;
+            equals(that.commands.length, params.values.length,
+                   'Checking IPA.batch_command command count');
 
-            equals(
-                that.entity, params.other_entity,
-                'Checking IPA.command() parameter: entity'
-            );
+            var i, command;
 
-            equals(
-                that.method, params.method,
-                'Checking IPA.command() parameter: method'
-            );
+            for(i=0; i < params.values.length; i++) {
+                command = that.commands[i];
 
-            equals(
-                that.args[0], 'user'+counter,
-                'Checking IPA.command() parameter: primary key'
-            );
+                equals(
+                    command.entity, params.other_entity,
+                    'Checking IPA.command() parameter: entity'
+                );
+
+                equals(
+                    command.method, params.method,
+                    'Checking IPA.command() parameter: method'
+                );
+
+                equals(
+                    command.args[0], 'user'+(i+1),
+                    'Checking IPA.command() parameter: primary key'
+                );
+            }
 
             that.on_success({});
         };
@@ -73,7 +78,7 @@ test("Testing serial_associator().", function() {
     var associator = IPA.serial_associator(params);
     associator.execute();
 
-    IPA.command = orig_ipa_command;
+    IPA.batch_command = orig_ipa_batch_command;
 });
 
 test("Testing bulk_associator().", function() {
-- 
1.7.6

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to