server/executionhandlers/ruby/connection.rb in cpee-2.1.35 vs server/executionhandlers/ruby/connection.rb in cpee-2.1.36
- old
+ new
@@ -83,10 +83,14 @@
:cpee => {
'base' => @controller.base_url,
'instance' => @controller.instance_id,
'instance_url' => @controller.instance_url,
'instance_uuid' => @controller.uuid
+ },
+ :task => {
+ 'label' => @label,
+ 'id' => @handler_position
}
}
end #}}}
def proto_curl(parameters) #{{{
@@ -136,20 +140,20 @@
headers['CPEE_SALVAGE'] = true
c = result[0]&.value
c = c.read if c.respond_to? :read
callback([ Riddl::Parameter::Complex.new('error','application/json',StringIO.new(JSON::generate({ 'status' => status, 'error' => c }))) ], headers)
else
- if headers['CPEE_INSTANTIATION']
- @controller.notify("task/instantiation", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => CPEE::ValueHelper.parse(headers['CPEE_INSTANTIATION']))
- end
- if headers['CPEE_EVENT']
- @controller.notify("task/#{headers['CPEE_EVENT'].gsub(/[^\w_-]/,'')}", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint)
- end
if headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.any?
headers['CPEE_UPDATE'] = true
callback result, headers
elsif headers['CPEE_CALLBACK'] && headers['CPEE_CALLBACK'] == 'true' && result.empty?
+ if headers['CPEE_INSTANTIATION']
+ @controller.notify("task/instantiation", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => CPEE::ValueHelper.parse(headers['CPEE_INSTANTIATION']))
+ end
+ if headers['CPEE_EVENT']
+ @controller.notify("task/#{headers['CPEE_EVENT'].gsub(/[^\w_-]/,'')}", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint)
+ end
# do nothing, later on things will happend
else
callback result, headers
end
end
@@ -157,10 +161,11 @@
def activity_handle(passthrough, parameters) # {{{
raise "Wrong endpoint" if @handler_endpoint.nil? || @handler_endpoint.empty?
@label = parameters[:label]
@anno = parameters.delete(:annotations) rescue nil
+ @controller.notify("status/resource_utilization", :mib => GetProcessMem.new.mb, **Process.times.to_h)
@controller.notify("activity/calling", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters, :annotations => @anno)
if passthrough.to_s.empty?
proto_curl parameters
else
@controller.callback(self,passthrough,:'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position)
@@ -228,10 +233,12 @@
if result[0].is_a? Riddl::Parameter::Simple
result = result[0].value
elsif result[0].is_a? Riddl::Parameter::Complex
if result[0].mimetype == 'application/json'
result = JSON::parse(result[0].value.read) rescue nil
+ elsif result[0].mimetype == 'text/csv'
+ result = result[0].value.read
elsif result[0].mimetype == 'text/yaml'
result = YAML::load(result[0].value.read) rescue nil
elsif result[0].mimetype == 'application/xml' || result[0].mimetype == 'text/xml'
result = XML::Smart::string(result[0].value.read) rescue nil
elsif result[0].mimetype == 'text/plain'
@@ -249,11 +256,16 @@
else
result = result[0]
end
end
end
- result
+ if result.is_a? String
+ enc = detect_encoding(result)
+ enc == 'OTHER' ? result : (result.encode('UTF-8',enc) rescue convert_to_base64(result))
+ else
+ result
+ end
end
def detect_encoding(text)
if text.is_a? String
if text.valid_encoding? && text.encoding.name == 'UTF-8'
@@ -281,26 +293,25 @@
result.map do |r|
if r.is_a? Riddl::Parameter::Simple
{ 'name' => r.name, 'data' => r.value }
elsif r.is_a? Riddl::Parameter::Complex
res = if r.mimetype == 'application/json'
- ttt = JSON::parse(r.value.read) rescue nil
- if ttt.nil?
- ''
- else
- enc = detect_encoding(ttt)
- enc == 'OTHER' ? ttt : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
- end
+ ttt = r.value.read
+ enc = detect_encoding(ttt)
+ enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
+ elsif r.mimetype == 'text/csv'
+ ttt = r.value.read
+ enc = detect_encoding(ttt)
+ enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
elsif r.mimetype == 'text/plain' || r.mimetype == 'text/html'
ttt = r.value.read
ttt = ttt.to_f if ttt == ttt.to_f.to_s
ttt = ttt.to_i if ttt == ttt.to_i.to_s
enc = detect_encoding(ttt)
enc == 'OTHER' ? ttt.inspect : (ttt.encode('UTF-8',enc) rescue convert_to_base64(ttt))
else
convert_to_base64(r.value.read)
- r.value.rewind
end
tmp = {
'name' => r.name == '' ? 'result' : r.name,
'mimetype' => r.mimetype,
@@ -316,10 +327,13 @@
recv = structurize_result(result)
@controller.notify("activity/receiving", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => recv, :annotations => @anno)
@guard_files += result
@handler_returnValue = simplify_result(result)
@handler_returnOptions = options
+ if options['CPEE_INSTANTIATION']
+ @controller.notify("task/instantiation", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => CPEE::ValueHelper.parse(options['CPEE_INSTANTIATION']))
+ end
if options['CPEE_EVENT']
@controller.notify("task/#{options['CPEE_EVENT'].gsub(/[^\w_-]/,'')}", :'activity-uuid' => @handler_activity_uuid, :label => @label, :activity => @handler_position, :endpoint => @handler_endpoint, :received => recv)
end
if options['CPEE_UPDATE']
if options['CPEE_UPDATE_STATUS']
@@ -352,11 +366,9 @@
@controller.notify("condition/eval", :instance_uuid => @controller.uuid, :code => code, :condition => (res ? "true" : "false"))
res
end
def simulate(type,nesting,tid,parent,parameters={}) #{{{
- pp "#{type} - #{nesting} - #{tid} - #{parent} - #{parameters.inspect}"
-
@controller.vote("simulating/step",
:'activity-uuid' => @handler_activity_uuid,
:label => @label,
:activity => tid,
:endpoint => @handler_endpoint,