Class: CPEE::Instantiation::InstantiateUrl

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

Overview

}}}

Instance Method Summary collapse

Methods included from Helpers

#handle_data, #handle_endpoints

Instance Method Details

#responseObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cpee/instantiation.rb', line 189

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

  if (instance, uuid = load_testset(tdoc,cpee,name)).first == -1
    @status = 500
  else
    handle_data cpee, instance, @p[2]&.value if @p[2]&.name == 'init'
    handle_endpoints cpee, instance, @p[2]&.value if @p[2]&.name == 'endpoints'
    handle_endpoints cpee, instance, @p[3]&.value if @p[3]&.name == 'endpoints'

    handle_waiting cpee, instance, uuid, @p[0].value, selfurl, cblist
    handle_starting cpee, instance, @p[0].value

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