Class: RestApplication

Inherits:
OpenShift::Model
  • Object
show all
Includes:
LegacyBrokerHelper
Defined in:
app/models/rest_application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LegacyBrokerHelper

#get_cached

Constructor Details

#initialize(app, url, nolinks = false) ⇒ RestApplication

Returns a new instance of RestApplication.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/rest_application.rb', line 7

def initialize(app, url, nolinks=false)
  self.framework = app.framework
  self.name = app.name
  self.creation_time = app.creation_time
  self.uuid = app.uuid
  self.aliases = app.aliases || Array.new
  self.gear_count = (app.gears.nil?) ? 0 : app.gears.length
  self.embedded = app.embedded
  self.domain_id = app.domain.namespace
  self.gear_profile = app.node_profile
  self.scalable = app.scalable
  self.git_url = "ssh://#{@uuid}@#{@name}-#{@domain_id}.#{Rails.configuration.openshift[:domain_suffix]}/~/git/#{@name}.git/"
  self.app_url = "http://#{@name}-#{@domain_id}.#{Rails.configuration.openshift[:domain_suffix]}/"
  self.ssh_url = "ssh://#{@uuid}@#{@name}-#{@domain_id}.#{Rails.configuration.openshift[:domain_suffix]}"
  self.health_check_path = app.health_check_path
  self.building_with = nil
  self.building_app = nil
  self.build_job_url = nil
  self.initial_git_url = app.init_git_url
  
  app.embedded.each { |cname, cinfo|
    cart = CartridgeCache::find_cartridge(cname)
    if cart.categories.include? "ci_builder"
      self.building_with = cart.name
      self.build_job_url = cinfo["job_url"]
      break
    end
  }
  app.user.applications.each { |user_app|
    cart = CartridgeCache::find_cartridge(user_app.framework)
    if cart.categories.include? "ci"
      self.building_app = user_app.name
      break
    end
  }

  cart_type = "embedded"
  cache_key = "cart_list_#{cart_type}"
  unless nolinks
    carts = nil
    if app.scalable
      carts = Application::SCALABLE_EMBEDDED_CARTS
    else
      carts = get_cached(cache_key, :expires_in => 21600.seconds) do
        Application.get_available_cartridges("embedded")
      end
    end
    # Update carts list
    # - remove already embedded carts
    # - remove conflicting carts
    app.embedded.keys.each do |cname|
      carts -= [cname]
      cinfo = CartridgeCache.find_cartridge(cname)
      carts -= cinfo.conflicts_feature if defined?(cinfo.conflicts_feature)
    end if !app.embedded.empty?

    self.links = {
      "GET" => Link.new("Get application", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}")),
      "GET_DESCRIPTOR" => Link.new("Get application descriptor", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/descriptor")),
      "GET_GEARS" => Link.new("Get application gears", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/gears")),
      "GET_GEAR_GROUPS" => Link.new("Get application gear groups", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/gear_groups")),
      "START" => Link.new("Start application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "start")
      ]),
      "STOP" => Link.new("Stop application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "stop")
      ]),
      "RESTART" => Link.new("Restart application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "restart")
      ]),
      "FORCE_STOP" => Link.new("Force stop application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "force-stop")
      ]),
      "EXPOSE_PORT" => Link.new("Expose port", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "expose-port")
      ]),
      "CONCEAL_PORT" => Link.new("Conceal port", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "conceal-port")
      ]),
      "SHOW_PORT" => Link.new("Show port", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "show-port")
      ]),
      "ADD_ALIAS" => Link.new("Add application alias", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "add-alias"),
        Param.new("alias", "string", "The server alias for the application")
      ]),
      "REMOVE_ALIAS" => Link.new("Remove application alias", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "remove-alias"),
        Param.new("alias", "string", "The application alias to be removed")
      ]),
      "SCALE_UP" => Link.new("Scale up application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "scale-up")
      ]),
      "SCALE_DOWN" => Link.new("Scale down application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "scale-down")
      ]),
      "TIDY" => Link.new("Tidy the application framework", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "tidy")
      ]),
      "RELOAD" => Link.new("Reload the application", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "reload")
      ]),
      "THREAD_DUMP" => Link.new("Trigger thread dump", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/events"), [
        Param.new("event", "string", "event", "thread-dump")
      ]),
      "DELETE" => Link.new("Delete application", "DELETE", URI::join(url, "domains/#{@domain_id}/applications/#{@name}")),
      "ADD_CARTRIDGE" => Link.new("Add embedded cartridge", "POST", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/cartridges"),[
        Param.new("cartridge", "string", "framework-type, e.g.: mongodb-2.2", carts)
      ]),
      "LIST_CARTRIDGES" => Link.new("List embedded cartridges", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/cartridges")),
      "DNS_RESOLVABLE" => Link.new("Resolve DNS", "GET", URI::join(url, "domains/#{@domain_id}/applications/#{@name}/dns_resolvable"))
    }
  end
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



2
3
4
# File 'app/models/rest_application.rb', line 2

def aliases
  @aliases
end

#app_urlObject

Returns the value of attribute app_url.



2
3
4
# File 'app/models/rest_application.rb', line 2

def app_url
  @app_url
end

#build_job_urlObject

Returns the value of attribute build_job_url.



2
3
4
# File 'app/models/rest_application.rb', line 2

def build_job_url
  @build_job_url
end

#building_appObject

Returns the value of attribute building_app.



2
3
4
# File 'app/models/rest_application.rb', line 2

def building_app
  @building_app
end

#building_withObject

Returns the value of attribute building_with.



2
3
4
# File 'app/models/rest_application.rb', line 2

def building_with
  @building_with
end

#cartridgesObject

Returns the value of attribute cartridges.



2
3
4
# File 'app/models/rest_application.rb', line 2

def cartridges
  @cartridges
end

#creation_timeObject

Returns the value of attribute creation_time.



2
3
4
# File 'app/models/rest_application.rb', line 2

def creation_time
  @creation_time
end

#domain_idObject

Returns the value of attribute domain_id.



2
3
4
# File 'app/models/rest_application.rb', line 2

def domain_id
  @domain_id
end

#embeddedObject

Returns the value of attribute embedded.



2
3
4
# File 'app/models/rest_application.rb', line 2

def embedded
  @embedded
end

#frameworkObject

Returns the value of attribute framework.



2
3
4
# File 'app/models/rest_application.rb', line 2

def framework
  @framework
end

#gear_countObject

Returns the value of attribute gear_count.



2
3
4
# File 'app/models/rest_application.rb', line 2

def gear_count
  @gear_count
end

#gear_profileObject

Returns the value of attribute gear_profile.



2
3
4
# File 'app/models/rest_application.rb', line 2

def gear_profile
  @gear_profile
end

#git_urlObject

Returns the value of attribute git_url.



2
3
4
# File 'app/models/rest_application.rb', line 2

def git_url
  @git_url
end

#health_check_pathObject

Returns the value of attribute health_check_path.



2
3
4
# File 'app/models/rest_application.rb', line 2

def health_check_path
  @health_check_path
end

#initial_git_urlObject

Returns the value of attribute initial_git_url.



2
3
4
# File 'app/models/rest_application.rb', line 2

def initial_git_url
  @initial_git_url
end

Returns the value of attribute links.



2
3
4
# File 'app/models/rest_application.rb', line 2

def links
  @links
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/rest_application.rb', line 2

def name
  @name
end

#scalableObject

Returns the value of attribute scalable.



2
3
4
# File 'app/models/rest_application.rb', line 2

def scalable
  @scalable
end

#ssh_urlObject

Returns the value of attribute ssh_url.



2
3
4
# File 'app/models/rest_application.rb', line 2

def ssh_url
  @ssh_url
end

#uuidObject

Returns the value of attribute uuid.



2
3
4
# File 'app/models/rest_application.rb', line 2

def uuid
  @uuid
end

Instance Method Details

#to_xml(options = {}) ⇒ Object



122
123
124
125
# File 'app/models/rest_application.rb', line 122

def to_xml(options={})
  options[:tag_name] = "application"
  super(options)
end