148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/marbu/server.rb', line 148
def build_mrm_from_params(params)
name = 'name'
function = 'function'
puts params.inspect
if (uuid = params['uuid'])
mrm = Marbu::Models::Db::MongoDb.find_or_create_by(uuid: uuid)
else
mrm = Marbu::Models::Db::MongoDb.new
end
mrm.name = params['name']
mrf = mrm.map_reduce_finalize
mrf.map = Marbu::Models::Map.new(
:code => {:text => params['map_code']}
)
mrf.reduce = Marbu::Models::Reduce.new(
:code => {:text => params['reduce_code']}
)
mrf.finalize = Marbu::Models::Finalize.new(
:code => {:text => params['finalize_code']}
)
mrf.query = Marbu::Models::Query.new(
condition: params['query_condition'],
force_query: params['query_force_query'],
static: params['query_static']
)
mrf.misc = Marbu::Models::Misc.new(
:database => params['database'],
:input_collection => params['input_collection'],
:output_collection => params['output_collection']
)
['map', 'reduce', 'finalize'].each do |stage|
['key', 'value'].each do |type|
stage_type_name = params["#{stage}_#{type}_#{name}"]
stage_type_function = params["#{stage}_#{type}_#{function}"]
if( stage_type_name.present?)
stage_type_name.each_with_index do |n, i|
case stage
when 'map' then add(mrf.map, type, n, stage_type_function[i])
when 'reduce' then add(mrf.reduce, type, n, stage_type_function[i])
when 'finalize' then add(mrf.finalize, type, n, stage_type_function[i])
else raise Exception.new("#{stage} in #{k} is unknown")
end
end
end
end
end
mrm.map_reduce_finalize = mrf
return mrm
end
|