Class: CPEE::NewInstanceFull

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/implementation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/cpee/implementation.rb', line 313

def response
  opts  = @a[0]
  redis = opts[:redis]

  doc   = XML::Smart::string(@p[0].value.read)
  doc.register_namespace 'p', 'http://cpee.org/ns/properties/2.0'
  doc.register_namespace 'np', 'http://riddl.org/ns/common-patterns/notifications-producer/2.0'

  name = doc.find('string(/*/p:attributes/p:info)')

  subs = (doc.find('/*/np:subscriptions/np:subscription') rescue []).to_a
  id, uuid = NewInstance::create(opts,redis,name,subs,doc)

  content = {
    :state => 'ready',
    :attributes => CPEE::Persistence::extract_list(id,opts,'attributes').to_h
  }
  CPEE::Message::send(:event,'state/change',File.join(opts[:url],'/'),id,uuid,name,content,redis)

  CPEE::Properties::Put::change_first(id,opts,doc) # change again, for proper event sending
  CPEE::Properties::PutState::run(id,opts,'running') if doc.find('string(/*/p:state)') == 'running'

  @headers << Riddl::Header.new("CPEE-INSTANCE", id.to_s)
  @headers << Riddl::Header.new("CPEE-INSTANCE-URL", File.join(opts[:url].to_s,id.to_s,'/'))
  @headers << Riddl::Header.new("CPEE-INSTANCE-UUID", uuid)

  Riddl::Parameter::Simple.new("id", id.to_s)
end