Browse Source

Resolving conflict with merge

prieto 8 years ago
parent
commit
a67a362aa9

+ 1
- 1
Makefile.am View File

@@ -27,7 +27,7 @@ doc_graphviz:
27 27
 
28 28
 do_subst = sed -e 's,\[@\]INSTALLMODEL_DIR\[@\],$(install_model_dir),g' 
29 29
 
30
-runtest: runtest.sh
30
+runtest: ./runtest.sh
31 31
 	$(do_subst) < $(srcdir)/runtest.sh > runtest
32 32
 	chmod +x runtest
33 33
 

+ 2
- 0
lodel/context.py View File

@@ -123,6 +123,7 @@ site_id set to None when we are in MULTISITE beahavior")
123 123
                 self.__class__._current = self.__class__._contexts = self
124 124
                 self.__pkg_name = 'lodel'
125 125
                 self.__package = lodel
126
+                self.__instance_path = os.getcwd()
126 127
                 return
127 128
         else:
128 129
             #Multisite instanciation
@@ -145,6 +146,7 @@ instance path")
145 146
                 """
146 147
                 warnings.warn("It can be a really BAD idea to create a \
147 148
 a context without a path......")
149
+                self.__instance_path = None
148 150
             else:
149 151
                 self.__instance_path = os.path.realpath(instance_path)
150 152
             #Importing the site package to trigger its creation

+ 0
- 64
lodel/leapi/datahandlers/base_classes.py View File

@@ -410,70 +410,6 @@ class MultipleRef(Reference):
410 410
             raise FieldValidationError("MultipleRef have for invalid values [%s]  :" % (",".join(error_list)))
411 411
         return new_val
412 412
 
413
-    ##@brief Construct a multiple ref data
414
-    def construct_data(self, emcomponent, fname, datas, cur_value):
415
-        cur_value = super().construct_data(emcomponent, fname, datas, cur_value)
416
-        if cur_value is not None:
417
-            if self.back_reference is not None:
418
-                br_class = self.back_reference[0]
419
-                for br_id in cur_value:
420
-                    query_filters = list()
421
-                    query_filters.append((br_class.uid_fieldname()[0], '=', br_id))
422
-                    br_obj = br_class.get(query_filters)
423
-                    if len(br_obj) != 0:
424
-                        br_list = br_obj[0].data(self.back_reference[1])
425
-                        if br_list is None:
426
-                            br_list = list()
427
-                        if br_id not in br_list:
428
-                            br_list.append(br_id)
429
-        return cur_value
430
-
431
-    ## @brief Checks the backreference, updates it if it is not complete
432
-    # @param emcomponent EmComponent : An EmComponent child class instance
433
-    # @param fname : the field name
434
-    # @param datas dict : dict storing fields values
435
-    # @note Not done in case of delete
436
-    def make_consistency(self, emcomponent, fname, datas, type_query):
437
-        dh = emcomponent.field(fname)
438
-        logger.info('Warning : multiple uid capabilities are broken here')
439
-        uid = datas[emcomponent.uid_fieldname()[0]]
440
-        if self.back_reference is not None:
441
-            target_class = self.back_reference[0]
442
-            target_field = self.back_reference[1]
443
-            target_uidfield = target_class.uid_fieldname()[0]
444
-            l_value = datas[fname]
445
-
446
-            if l_value is not None:
447
-                for value in l_value:
448
-                    query_filters = list()
449
-                    query_filters.append((target_uidfield, '=', value))
450
-                    obj = target_class.get(query_filters)
451
-                    if len(obj) == 0:
452
-                        logger.warning('Object referenced does not exist')
453
-                        return False
454
-                    l_uids_ref = obj[0].data(target_field)
455
-                    if l_uids_ref is None:
456
-                        l_uids_ref = list()
457
-                    if uid not in l_uids_ref:
458
-                        l_uids_ref.append(uid)
459
-                        obj[0].set_data(target_field, l_uids_ref)
460
-                        obj[0].update()
461
-
462
-            if type_query == 'update':
463
-                query_filters = list()
464
-                query_filters.append((uid, ' in ', target_field))
465
-                objects = target_class.get(query_filters)
466
-                if l_value is None:
467
-                    l_value = list()
468
-                if len(objects) != len(l_value):
469
-                    for obj in objects:
470
-                        l_uids_ref = obj.data(target_field)
471
-                        if obj.data(target_uidfield) not in l_value:
472
-                            l_uids_ref.remove(uid)
473
-                            obj.set_data(target_field, l_uids_ref)
474
-                            obj.update()
475
-
476
-
477 413
 
478 414
 ## @brief Class designed to handle datas access will fieldtypes are constructing datas
479 415
 #@ingroup lodel2_datahandlers

+ 23
- 7
lodel/plugins/multisite/main.py View File

@@ -75,16 +75,23 @@ class LodelWSGIHandler(wsgiref.simple_server.WSGIRequestHandler):
75 75
         self.request.close()
76 76
         super().close()
77 77
 
78
-##@brief WSGIServer implementing ForkingTCPServer.
79
-#
80
-#Same features than wsgiref.simple_server.WSGIServer but process each requests
81
-#in a child process
82
-class ForkingWSGIServer(
83
-        wsgiref.simple_server.WSGIServer, socketserver.ForkingTCPServer):
84
-    
78
+   
79
+class CustomForkingTCPServer(socketserver.ForkingTCPServer):
85 80
     ##@brief static property indicating the max number of childs allowed
86 81
     max_children = 40
87 82
 
83
+    def __init__(self, *args, **kwargs):
84
+        super().__init__(*args, **kwargs)
85
+        if self.__class__.active_children is None:
86
+            self.__class__.active_childer = set()
87
+    
88
+    ##@brief Implements max_children limitations
89
+    def process_request(self, request, client_address):
90
+        while self.active_children is not None and \
91
+                len(self.active_children) > self.__class__.max_children:
92
+            self.collect_children()
93
+        super().process_request(request, client_address)
94
+        
88 95
     ##@brief Custom reimplementation of shutdown method in order to ensure
89 96
     #that we close all listening sockets
90 97
     #
@@ -107,6 +114,15 @@ class ForkingWSGIServer(
107 114
                     self.active_children.discard(pid)
108 115
         self.server_close()
109 116
 
117
+##@brief WSGIServer implementing ForkingTCPServer.
118
+#
119
+#Same features than wsgiref.simple_server.WSGIServer but process each requests
120
+#in a child process
121
+class ForkingWSGIServer(
122
+        wsgiref.simple_server.WSGIServer, CustomForkingTCPServer):
123
+    pass
124
+ 
125
+
110 126
 ##@brief utility function to extract site id from an url
111 127
 def site_id_from_url(url):
112 128
     res = ''

+ 10
- 3
lodel/plugins/webui/interface/controllers/admin.py View File

@@ -45,9 +45,16 @@ def admin_update(request):
45 45
             raise HttpException(400)
46 46
         target_leo = dyncode.Object.name2class(datas['classname'])
47 47
         leo = target_leo.get_from_uid(datas['lodel_id'])
48
-        for in_value in datas:
49
-            if datas[in_value] == '':
50
-                datas[in_value] = None
48
+
49
+        #for in_value in datas:
50
+        #    if datas[in_value] == '':
51
+        #        datas[in_value] = None
52
+
53
+        if leo is None:
54
+            raise HttpException(404,
55
+                custom = 'No %s with id %s' % (
56
+                    target_leo.__name__, datas['lodel_id']))
57
+
51 58
         try:
52 59
             leo.update(
53 60
                 { f:datas[f] for f in datas if f not in ('classname', 'lodel_id')})

+ 1
- 0
plugins View File

@@ -0,0 +1 @@
1
+lodel/plugins/

+ 13
- 12
progs/mass_deploy.sh View File

@@ -37,6 +37,7 @@ test -f $conffile || badconf
37 37
 . $conffile
38 38
 test -z "$MONGODB_ADMIN_USER" && badconf
39 39
 test -z "$MONGODB_ADMIN_PASSWORD" && badconf
40
+$MONGODB_HOST=${MONGODB_HOST:="127.0.0.1"}
40 41
 
41 42
 
42 43
 if [ -z "$fixed_name" ]
@@ -65,17 +66,17 @@ fi
65 66
 
66 67
 if [ -f "/etc/mongodb.conf" ]
67 68
 then
68
-	if cat /etc/mongodb.conf  |grep -E '^ *auth *= *true *$' >/dev/null
69
-	then
70
-		echo "OK, auth enabled"
71
-	else
72
-		echo "WARNING : auth seems disabled on mongod !" >&2
73
-	fi
69
+        if cat /etc/mongodb.conf  |grep -E '^ *auth *= *true *$' >/dev/null
70
+        then
71
+                echo "OK, auth enabled"
72
+        else
73
+                echo "WARNING : auth seems disabled on mongod !" >&2
74
+        fi
74 75
 else
75
-	echo "/etc/mongodb.conf not found. Unable to check if auth is on"
76
+        echo "/etc/mongodb.conf not found. Unable to check if auth is on"
76 77
 fi
77 78
 
78
-echo "exit" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" admin &>/dev/null || mongodb_connfail
79
+echo "exit" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin &>/dev/null || mongodb_connfail
79 80
 
80 81
 if [ "$1" == 'purgedb' ]
81 82
 then
@@ -88,9 +89,9 @@ then
88 89
 	read rep
89 90
 	if [ "$rep" = "Y" ]
90 91
 	then
91
-		for dbname in $(echo "show dbs" | mongo -u admin -p pass admin  |grep "^$MONGODB_DB_PREFIX"|cut -f1)
92
+		for dbname in $(echo "show dbs" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin |grep "^$MONGODB_DB_PREFIX"|cut -f1)
92 93
 		do 
93
-			echo -e "use $dname\ndb.dropDatabase()\nexit\n" | mongo -u $MONGODB_ADMIN_USER -p $MONGODB_ADMIN_PASSWORD --quiet --authenticationDatabase admin $dbname && echo "$dbname succesfully deleted" || echo "$dbname deletion fails" >&2
94
+			echo -e "use $dname\ndb.dropDatabase()\nexit\n" | mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --quiet --authenticationDatabase admin && echo "$dbname succesfully deleted" || echo "$dbname deletion fails" >&2
94 95
 		done
95 96
 		echo "Done."
96 97
 	else
@@ -139,13 +140,13 @@ do
139 140
 	dbname="${MONGODB_DB_PREFIX}_$iname"
140 141
 	dbuser="lodel2_$iname"
141 142
 	dbpass=$($rnd_pass_cmd)
142
-	mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" admin <<EOF
143
+	mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin <<EOF
143 144
 use $dbname
144 145
 db.addUser({user:"$dbuser", pwd:"$dbpass", roles:["readWrite", "dbAdmin"]})
145 146
 exit
146 147
 EOF
147 148
 	#Append created db to instance conf
148
-	slim -n $iname -s --datasource_connectors mongodb --host localhost --user $dbuser --password $dbpass --db_name $dbname || slim_fails "configuring the instance's datasource"
149
+	slim -n $iname -s --datasource_connectors mongodb --host $MONGODB_HOST --user $dbuser --password $dbpass --db_name $dbname || slim_fails "configuring the instance's datasource"
149 150
 
150 151
 done
151 152
 

+ 108
- 26
scripts/cbl.sh View File

@@ -2,7 +2,7 @@
2 2
 #
3 3
 # CBL : Curl Benchmark on Lodel
4 4
 #
5
-# Usage : $0 [HOSTNAME] [INSTANCE_LIST_FILE]
5
+# Usage : $0 [HOSTNAME] [INSTANCE_LIST_FILE] [N_CREATE] [N_EDIT] [N_DELETE]
6 6
 #
7 7
 # Instance_list_file is expected to be a file containing instances name (1 per
8 8
 # line). Uses by default /tmp/lodel2_instance_list.txt
@@ -81,20 +81,11 @@ n_delete=${n_delete:=10}
81 81
 
82 82
 for i in $(seq $#)
83 83
 do
84
-	echo $1 |grep -E "^-?-h" &>/dev/null && usage
84
+	echo $1 |grep -E "^-?-h" &>/dev/null
85 85
 	shift
86 86
 done
87 87
 
88 88
 
89
-logdir="/tmp/lodel2_cbl_logs"
90
-if [ -d "$logdir" ]
91
-then
92
-	echo "WARNING : $logdir allready exists. It's a better idea to delete it before running this script again"
93
-	echo "waiting 3s"
94
-	sleep 3
95
-fi
96
-mkdir -p $logdir
97
-
98 89
 #curl_options='--silent -o /dev/null -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}\n'
99 90
 curl_options='--silent -o /dev/null -s -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
100 91
 curl_debug_opt='-v -w %{url_effective};%{http_code};%{time_connect};%{time_starttransfer};%{time_total}\n'
@@ -128,9 +119,14 @@ mass_creation() {
128 119
 	instance_name=$1
129 120
 	iteration_count=$2
130 121
 	base_uri=$(_base_uri $1)
131
-	logfile="$logdir/mass_creation_${instance_name}.log"
132 122
 	cls_list_file=$(fetch_all_classes $1)
133 123
 
124
+	if [ -z "$(cat $cls_list_file)" ]
125
+	then
126
+		echo "Failed to fetch class list for instance $1. Abording..." >&2
127
+		exit
128
+	fi
129
+
134 130
 	if [ "$iteration_count" -le "0" ]
135 131
 	then
136 132
 		return
@@ -139,10 +135,9 @@ mass_creation() {
139 135
 	for i in $(seq $iteration_count)
140 136
 	do
141 137
 		cls=$(shuf -n1 $cls_list_file)
142
-		$curcurl -d "$(curl_opt_create_$cls)" "${base_uri}$(uri_create $cls)" | tee -a $logfile
138
+		echo "${base_uri}$(uri_create $cls) POST $(curl_opt_create_$cls)"
143 139
 	done
144
-
145
-	rm -v $cls_list_file
140
+	rm -v $cls_list_file >&2
146 141
 }
147 142
 
148 143
 mass_link_edit() {
@@ -152,7 +147,6 @@ mass_link_edit() {
152 147
 	instance_name=$1
153 148
 	iteration_count=$2
154 149
 	base_uri=$(_base_uri $1)
155
-	logfile="$logdir/mass_link_edit_${instance_name}.log"
156 150
 	cls_list_file=$(fetch_all_classes $1)
157 151
 
158 152
 	for cls in $(cat $cls_list_file)
@@ -171,17 +165,79 @@ mass_link_edit() {
171 165
 					ltext_count=$(shuf -i1-5 -n1)
172 166
 					alias_param=$(head -n $(expr $alias_count \* $i) $person_ids| tail -n$alias_count|tr -s "\n" "," | sed 's/,$//')
173 167
 					txt_param=$(head -n $(expr $ltext_count \* $i) $text_ids | tail -n$ltext_count|tr -s "\n" "," | sed 's/,$//')
174
-					$curcurl -d "$(curl_opt_create_$cls $alias_param $txt_param)&uid=$cur_id" "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id" | tee -a $logfile
168
+					echo "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id POST $(curl_opt_create_$cls $alias_param $txt_param)&uid=$cur_id"
175 169
 				done
176 170
 				rm -v $text_ids $person_ids $section_ids $subsection_ids
177 171
 				;;
178
-
172
+            
173
+            Collection)
174
+                collections_ids=$(fetch_all_ids $1 Collection)
175
+                publication_ids=$(fetch_all_ids $1 Publication)
176
+                for i in $(seq $iteration_count)
177
+                do
178
+                    cur_id=$(shuf -n1 $collections_ids)
179
+                    publications_count=$(shuf -i1-5 -n1)
180
+                    publication_param=$(head -n $(expr $publications_count \* $i) $publication_ids| tail -n$publications_count|tr -s "\n" ",")
181
+		    echo "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id POST $(curl_opt_create_$cls $publication_param)&uid=$cur_id"
182
+                done
183
+                rm -v $collections_ids $publication_ids
184
+                ;;
185
+
186
+            Publication)
187
+                publication_ids=$(fetch_all_ids $1 Publication)
188
+                collection_ids=$(fetch_all_ids $1 Collection)
189
+                for i in $(seq $iteration_count)
190
+                do
191
+                    cur_id=$(shuf -n1 $publication_ids)
192
+                    collections_count=$(shuf -i1-5 -n1)
193
+                    collection_param=$(head -n $(expr $collections_count \* $i) $collection_ids| tail -n$collections_count|tr -s "\n" ",")
194
+		    echo "$base_uri/admin.update?classname=$cls&lodel_id=$cur_id POST $(curl_opt_create_$cls $collection_param)&uid=$cur_id"
195
+                done
196
+                rm -v $publication_ids $collection_ids >&2
197
+                ;;
198
+			
199
+			Section)
200
+                section_ids=$(fetch_all_ids $1 Section)
201
+                child_ids=$(fetch_all_ids $1 Subsection)
202
+                person_ids=$(fetch_all_ids $1 Person)
203
+                for i in $(seq $iteration_count)
204
+                do
205
+                    cur_id=$(shuf -n1 $section_ids)
206
+                    child_count=$(shuf -i1-5 -n1)
207
+                    person_count=$(shuf -i1-5 -n1)
208
+                    child_param=$(head -n $(expr $child_count \* $i) $child_ids| tail -n$child_count|tr -s "\n" ",")
209
+                    person_param=$(head -n $(expr $person_count \* $i) $person_ids| tail -n$person_count|tr -s "\n" ",")
210
+		    echo "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id POST $(curl_opt_create_$cls $child_param $person_param)&uid=$cur_id"
211
+                done
212
+                rm -v $section_ids $child_ids $person_ids >&2
213
+                ;;
214
+                
215
+            Subsection)
216
+                subsection_ids=$(fetch_all_ids $1 Subsection)
217
+                section_ids=$(fetch_all_ids $1 Section)
218
+                persons_ids=$(fetch_all_ids $1 Person)
219
+                parent_ids=$($cmktemp)
220
+                cat $section_ids $subsection_ids | shuf > $parent_ids
221
+                child_ids=$subsection_ids
222
+                for i in $(seq $iteration_count)
223
+                do
224
+                    cur_id=$(shuf -n1 $subsection_ids)
225
+                    child_count=$(shuf -i1-5 -n1)
226
+                    parent_count=$(shuf -i1-5 -n1)
227
+                    person_count=$(shuf -i1-5 -n1)
228
+                    child_param=$(head -n $(expr $child_count \* $i) $child_ids| tail -n$child_count|tr -s "\n" ",")
229
+                    parent_param=$(head -n $(expr $parent_count \* $i) $parent_ids| tail -n$parent_count|tr -s "\n" ",")
230
+                    person_param=$(head -n $(expr $person_count \* $i) $persons_ids| tail -n$person_count|tr -s "\n" ",")
231
+		    echo "$base_uri/admin/update?classname=$cls&lodel_id=$cur_id POST $(curl_opt_create_$cls $child_param $person_param $parent_param)&uid=$cur_id"
232
+                done
233
+                rm -v $subsection_ids $parent_ids $section_ids $persons_ids >&2
234
+                ;;
179 235
 			*)
180 236
 				;;
181 237
 			
182 238
 		esac
183 239
 	done
184
-	rm -v $cls_list_file
240
+	rm -v $cls_list_file >&2
185 241
 }
186 242
 
187 243
 mass_deletion() {
@@ -191,7 +247,6 @@ mass_deletion() {
191 247
 	instance_name=$1
192 248
 	iteration_count=$2
193 249
 	base_uri=$(_base_uri $1)
194
-	logfile="$logdir/mass_deletion_${instance_name}.log"
195 250
 	cls_list_file=$(fetch_all_classes $1)
196 251
 	
197 252
 	for cls in $(cat $cls_list_file)
@@ -207,7 +262,7 @@ mass_deletion() {
207 262
 		for i in $(seq $max_iter)
208 263
 		do
209 264
 			id=$(tail -n $i $id_list_file | head -n1)
210
-			$curcurl "${base_uri}/admin/delete?classname=$cls&lodel_id=$id" | tee -a $logfile
265
+			echo "${base_uri}/admin/delete?classname=$cls&lodel_id=$id"
211 266
 		done
212 267
 		rm -v $id_list_file
213 268
 	done
@@ -219,6 +274,13 @@ fetch_all_classes() {
219 274
 	#$1 is intance name
220 275
 	cls_list_file=$($cmktemp)
221 276
 	$curl_raw "$(_base_uri $1)/list_classes" | grep -v Abstract |sed -nE 's/^ *<li> +<a href="show_class([^"]+)".*$/\1/p'|cut -d"=" -f2 > $cls_list_file
277
+	if [ -z "$(cat $cls_list_file)" ]
278
+	then
279
+		echo "Unable to fetch class list for $1" >&2
280
+		echo "Request was : $curl_raw '$(_base_uri $1)/list_classes'" >&2
281
+		rm $cls_list_file
282
+		exit 1
283
+	fi
222 284
 	echo $cls_list_file
223 285
 }
224 286
 
@@ -291,10 +353,30 @@ run_bg_with_param() {
291 353
 	rm -v $pidlist
292 354
 }
293 355
 
294
-run_bg_with_param "mass_creation" $instance_list $n_create
295
-run_bg_with_param "mass_link_edit" $instance_list $n_edit
296
-run_bg_with_param "mass_deletion" $instance_list $n_delete
356
+get_queries_with_params() {
357
+	#$1 is the function name to run
358
+	#$2 is the instance_list filename
359
+	#other parameters are given to the function
360
+	fun=$1
361
+	instance_list=$2
362
+	shift;shift
363
+	counter=0
364
+	for iname in $(cat $instance_list| sort)
365
+	do
366
+		echo "Running $fun $iname $@" >&2
367
+		beg=$(date "+%s")
368
+		$fun $iname $@
369
+		tsecs=$(expr $(date "+%s") - $beg)
370
+		left=$(expr $(cat $instance_list |wc -l) - $counter)
371
+		counter=$(expr $counter + 1)
372
+		tleft=$(expr $left \* $tsecs)
373
+		percent_done=$(echo "2k ${counter}.0 100.0 * $(cat $instance_list |wc -l).0 2k/ f" | dc)
374
+		echo -e "Done in ${tsecs}s\t$fun ${percent_done}% done ~$tleft secs" >&2
375
+
376
+	done | shuf
377
+}
297 378
 
298
-echo ""
299
-echo "Logs can be found in $logdir"
379
+get_queries_with_params "mass_creation" $instance_list $n_create
380
+get_queries_with_params "mass_link_edit" $instance_list $n_edit
381
+get_queries_with_params "mass_deletion" $instance_list $n_delete
300 382
 

Loading…
Cancel
Save