Class: CPEE::Instantiation::InstantiateGit

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



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/cpee-instantiation/instantiation.rb', line 213

def response
  cpee = @h['X_CPEE'] || @a[0]
  selfurl = @a[1]
  cblist = @a[2]

  status, res = Riddl::Client.new(File.join(@p[1].value,'raw',@p[2].value,@p[3].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,nil,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