Module: Nucleus::Adapters::V1::Heroku::Application

Included in:
Nucleus::Adapters::V1::Heroku
Defined in:
lib/nucleus/adapters/v1/heroku/application.rb

Instance Method Summary collapse

Instance Method Details

#application(application_id) ⇒ Object

See Also:



17
18
19
20
# File 'lib/nucleus/adapters/v1/heroku/application.rb', line 17

def application(application_id)
  response = get("/apps/#{application_id}")
  to_nucleus_app response.body
end

#applicationsObject

See Also:



7
8
9
10
11
12
13
14
# File 'lib/nucleus/adapters/v1/heroku/application.rb', line 7

def applications
  response = get('/apps')
  apps = []
  response.body.each do |application|
    apps << to_nucleus_app(application)
  end
  apps
end

#create_application(application) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nucleus/adapters/v1/heroku/application.rb', line 29

def create_application(application)
  # updates the application with a valid region identity
  retrieve_region(application)

  # Heroku does not support autoscale
  fail_with(:no_autoscale) if application[:autoscaled]
  application.delete :autoscaled

  # can fail if runtime URLs are invalid or names do not exist on this platform
  runtimes = runtimes_to_install(application)

  # create the actual application
  created_app = post('/apps', body: application).body

  # when application has been created, process runtime information if applicable
  unless runtimes.nil? || runtimes.empty?
    begin
      install_runtimes(created_app[:id], runtimes)
    rescue
      # if buildpack fails, make sure app gets deleted (!)
      log.debug 'Runtime installation failed, rollback...'
      delete_application(created_app[:id])
      log.debug '...application successfully rolled back'
      raise Errors::AdapterRequestError,
            'Heroku requires a buildpack URL when the runtime shall be specified manually.'
    end
  end
  to_nucleus_app(created_app)
end

#delete_application(application_id) ⇒ Object



23
24
25
26
# File 'lib/nucleus/adapters/v1/heroku/application.rb', line 23

def delete_application(application_id)
  # returns the application, but we do not want any output
  delete("/apps/#{application_id}")
end

#update_application(application_id, application) ⇒ Object

TODO: make update transactional in case sub-task (app, buildpacks) fails



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/nucleus/adapters/v1/heroku/application.rb', line 61

def update_application(application_id, application)
  # start updating the buildpacks
  if application.key? :runtimes
    # can fail if runtime URLs are invalid or names do not exist on this platform
    runtimes = runtimes_to_install(application)
    install_runtimes(application_id, runtimes)
  end

  # now change the app name and all other direct properties, which are in the body
  response = patch("/apps/#{application_id}", body: application)
  to_nucleus_app(response.body)
end