This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
/
rest_application13.rb
141 lines (129 loc) · 7.34 KB
/
rest_application13.rb
1
2
3
4
5
6
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class RestApplication13 < OpenShift::Model
attr_accessor :framework, :creation_time, :uuid, :embedded, :aliases, :name, :gear_count, :links, :domain_id, :git_url, :app_url, :ssh_url,
:gear_profile, :scalable, :health_check_path, :building_with, :building_app, :build_job_url, :cartridges, :initial_git_url
def initialize(app, domain, url, nolinks=false, applications=nil)
self.embedded = {}
app.requires(true).each do |feature|
cart = CartridgeCache.find_cartridge(feature)
if cart.categories.include? "web_framework"
self.framework = cart.name
else
self.embedded[cart.name] = {info: ""}
end
end
self.name = app.name
self.creation_time = app.created_at
self.uuid = app.uuid
self.aliases = []
app.aliases.each do |a|
self.aliases << a.fqdn
end
self.gear_count = app.num_gears
self.domain_id = domain.namespace
self.gear_profile = app.default_gear_size
self.scalable = app.scalable
self.git_url = "ssh://#{app.ssh_uri(domain)}/~/git/#{@name}.git/"
self.app_url = "http://#{app.fqdn(domain)}/"
self.ssh_url = "ssh://#{app.ssh_uri(domain)}"
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.component_instances.each do |component_instance|
cart = CartridgeCache::find_cartridge(component_instance.cartridge_name)
# add the builder properties if this is a builder component
if cart.categories.include?("ci_builder")
self.building_with = cart.name
self.build_job_url = component_instance.component_properties["job_url"]
# adding the job_url and "info" property for backward compatibility
self.embedded[cart.name] = component_instance.component_properties
self.embedded[cart.name]["info"] = "Job URL: #{component_instance.component_properties['job_url']}"
else
unless cart.categories.include? "web_framework"
self.embedded[cart.name] = component_instance.component_properties
# if the component has a connection_url property, add it as "info" for backward compatibility
if component_instance.component_properties.has_key?("connection_url")
self.embedded[cart.name]["info"] = "Connection URL: #{component_instance.component_properties['connection_url']}"
end
end
end
end
#TODO this is way too inefficient. Adding a bit of a hack to not have to call this all the time.
domain.env_vars.each do |env_var|
if env_var['key'] == 'JENKINS_URL'
apps = applications || domain.applications
apps.each do |domain_app|
domain_app.component_instances.each do |component_instance|
cart = CartridgeCache::find_cartridge(component_instance.cartridge_name)
if cart.categories.include?("ci")
self.building_app = domain_app.name
break
end
end
end
break
end
end
unless nolinks
carts = CartridgeCache.find_cartridge_by_category("embedded").map{ |c| c.name }
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")
]),
"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", @aliases)
]),
"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("name", "string", "framework-type, e.g.: mongodb-2.0", carts)
],[
OptionalParam.new("colocate_with", "string", "The component to colocate with", app.component_instances.map{|c| c.cartridge_name}),
OptionalParam.new("scales_from", "integer", "Minumimum number of gears to run the component on."),
OptionalParam.new("scales_to", "integer", "Maximum number of gears to run the component on."),
OptionalParam.new("additional_storage", "integer", "Additional GB of space to request on all gears running this component."),
]
),
"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
def to_xml(options={})
options[:tag_name] = "application"
super(options)
end
end