Class: CPEE::Instantiation::InstantiateUrl

Inherits:
Riddl::Implementation
  • Object
show all
Includes:
Helpers
Defined in:
lib/cpee-instantiation/instantiation.rb

Overview

}}}

Instance Method Summary collapse

Methods included from Helpers

#add_to_testset, #augment_testset, #handle_attributes, #handle_data, #handle_endpoints

Instance Method Details

#responseObject



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/cpee-instantiation/instantiation.rb', line 253

def response
  cpee    = @h['X_CPEE'] || @a[0]
  selfurl = @a[1]
  cblist  = @a[2]
  name    = @a[3] ? @p.shift.value : nil

  status, res = Riddl::Client.new(@p[1].value.gsub(/ /,'%20')).get
  tdoc = if status >= 200 && status < 300
    res[0].value.read
  else
    (@status = 500) && return
  end
  customization = @p.find{ |e| e.name == 'customization' }&.value

  tdoc = augment_testset(tdoc,@p)
  if (instance, uuid = load_testset(tdoc,cpee,name,customization)).first == -1
    @status = 500
  else
    EM.defer do
      handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
      handle_starting cpee, instance, @p[0].value
    end

    send = {
      'CPEE-INSTANCE' => instance,
      'CPEE-INSTANCE-URL' => File.join(cpee,instance),
      'CPEE-INSTANCE-UUID' => uuid,
      'CPEE-BEHAVIOR' => @p[0].value
    }
    if @p[0].value =~ /^wait/
      @headers << Riddl::Header.new('CPEE-CALLBACK','true')
    end
    @headers << Riddl::Header.new('CPEE-INSTANTIATION',JSON::generate(send))
    Riddl::Parameter::Complex.new('instance','application/json',JSON::generate(send))
  end
end