Class: CFoundry::V1::App
- Includes:
- UploadHelpers
- Defined in:
- lib/cfoundry/v1/app.rb
Defined Under Namespace
Classes: Instance
Constant Summary
Constants included from UploadHelpers
UploadHelpers::RESOURCE_CHECK_LIMIT, UploadHelpers::UPLOAD_EXCLUDE
Instance Attribute Summary
Attributes inherited from Model
Attributes included from ModelMagic
Instance Method Summary collapse
-
#bind(*instances) ⇒ Object
Bind services to application.
- #binds?(instance) ⇒ Boolean
-
#crashes ⇒ Object
Retrieve crashed instances.
- #env ⇒ Object
- #env=(hash) ⇒ Object
- #env_array ⇒ Object
- #env_array= ⇒ Object
-
#file(*path) ⇒ Object
Retrieve file contents for the first instance of the application.
-
#files(*path) ⇒ Object
Retrieve file listing under path for the first instance of the application.
- #framework ⇒ Object
- #framework=(obj) ⇒ Object
- #framework_name ⇒ Object
- #framework_name= ⇒ Object
-
#health ⇒ Object
Determine application health.
-
#healthy? ⇒ Boolean
(also: #running?)
Check that all application instances are running.
-
#instances ⇒ Object
Retrieve all of the instances of the app, as Instance objects.
-
#restart! ⇒ Object
Restart the application.
- #runtime ⇒ Object
- #runtime=(obj) ⇒ Object
- #runtime_name ⇒ Object
- #runtime_name= ⇒ Object
- #service_names ⇒ Object
- #service_names= ⇒ Object
- #services ⇒ Object
- #services=(instances) ⇒ Object
-
#start! ⇒ Object
Start the application.
-
#started? ⇒ Boolean
Is the application started?.
-
#stats ⇒ Object
Retrieve application statistics, e.g.
-
#stop! ⇒ Object
Stop the application.
-
#stopped? ⇒ Boolean
Is the application stopped?.
- #total_instances ⇒ Object
-
#unbind(*instances) ⇒ Object
Unbind services from application.
-
#uri ⇒ Object
(also: #url)
Shortcut for uris.
-
#uri=(x) ⇒ Object
(also: #url=)
Shortcut for uris = [x].
Methods included from UploadHelpers
#check_unreachable_links, #determine_resources, #find_sockets, #make_fingerprints, #prepare_package, #upload
Methods inherited from Model
#base_object_name, #changed?, #create!, #delete!, #eql?, #exists?, #find_path, #guid_name, #hash, #initialize, #inspect, #invalidate!, #manifest, #object_name, plural_base_object_name, plural_object_name, #put, #read_manifest, #update!, #write_manifest
Methods included from ModelMagic
#attribute, #define_client_methods, #read_locations, #write_locations
Constructor Details
This class inherits a constructor from CFoundry::V1::Model
Instance Method Details
#bind(*instances) ⇒ Object
Bind services to application.
224 225 226 227 |
# File 'lib/cfoundry/v1/app.rb', line 224 def bind(*instances) self.services += instances update! end |
#binds?(instance) ⇒ Boolean
235 236 237 |
# File 'lib/cfoundry/v1/app.rb', line 235 def binds?(instance) services.include? instance end |
#crashes ⇒ Object
Retrieve crashed instances
95 96 97 98 99 |
# File 'lib/cfoundry/v1/app.rb', line 95 def crashes @client.base.crashes(@guid).collect do |i| Instance.new(self, i[:instance].to_s, @client, i) end end |
#env ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cfoundry/v1/app.rb', line 192 def env e = env_array || [] env = {} e.each do |pair| name, val = pair.split("=", 2) env[name] = val end CFoundry::ChattyHash.new(method(:env=), env) end |
#env=(hash) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/cfoundry/v1/app.rb', line 204 def env=(hash) unless hash.is_a?(Array) hash = hash.collect { |k, v| "#{k}=#{v}" } end self.env_array = hash end |
#env_array ⇒ Object
59 |
# File 'lib/cfoundry/v1/app.rb', line 59 alias_method :env_array, :env |
#env_array= ⇒ Object
60 |
# File 'lib/cfoundry/v1/app.rb', line 60 alias_method :env_array=, :env= |
#file(*path) ⇒ Object
Retrieve file contents for the first instance of the application.
- path
-
A sequence of strings representing path segments.
For example,
files("foo", "bar")
forfoo/bar
.
255 256 257 |
# File 'lib/cfoundry/v1/app.rb', line 255 def file(*path) Instance.new(self, "0", @client).file(*path) end |
#files(*path) ⇒ Object
Retrieve file listing under path for the first instance of the application.
- path
-
A sequence of strings representing path segments.
For example,
files("foo", "bar")
forfoo/bar
.
245 246 247 |
# File 'lib/cfoundry/v1/app.rb', line 245 def files(*path) Instance.new(self, "0", @client).files(*path) end |
#framework ⇒ Object
62 63 64 |
# File 'lib/cfoundry/v1/app.rb', line 62 def framework @client.framework(framework_name) end |
#framework=(obj) ⇒ Object
66 67 68 |
# File 'lib/cfoundry/v1/app.rb', line 66 def framework=(obj) set_named(:framework, obj) end |
#framework_name ⇒ Object
44 |
# File 'lib/cfoundry/v1/app.rb', line 44 alias_method :framework_name, :framework |
#framework_name= ⇒ Object
45 |
# File 'lib/cfoundry/v1/app.rb', line 45 alias_method :framework_name=, :framework= |
#health ⇒ Object
Determine application health.
If all instances are running, returns “RUNNING”. If only some are started, returns the precentage of them that are healthy.
Otherwise, returns application’s status.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/cfoundry/v1/app.rb', line 136 def health s = state if s == "STARTED" healthy_count = running_instances expected = total_instances if healthy_count && expected > 0 ratio = healthy_count / expected.to_f if ratio == 1.0 "RUNNING" else "#{(ratio * 100).to_i}%" end else "N/A" end else s end end |
#healthy? ⇒ Boolean Also known as: running?
Check that all application instances are running.
158 159 160 161 162 |
# File 'lib/cfoundry/v1/app.rb', line 158 def healthy? # invalidate cache so the check is fresh invalidate! health == "RUNNING" end |
#instances ⇒ Object
Retrieve all of the instances of the app, as Instance objects.
88 89 90 91 92 |
# File 'lib/cfoundry/v1/app.rb', line 88 def instances @client.base.instances(@guid).collect do |m| Instance.new(self, m[:index].to_s, @client, m) end end |
#restart! ⇒ Object
Restart the application.
125 126 127 128 |
# File 'lib/cfoundry/v1/app.rb', line 125 def restart! stop! start! end |
#runtime ⇒ Object
70 71 72 |
# File 'lib/cfoundry/v1/app.rb', line 70 def runtime @client.runtime(runtime_name) end |
#runtime=(obj) ⇒ Object
74 75 76 |
# File 'lib/cfoundry/v1/app.rb', line 74 def runtime=(obj) set_named(:runtime, obj) end |
#runtime_name ⇒ Object
47 |
# File 'lib/cfoundry/v1/app.rb', line 47 alias_method :runtime_name, :runtime |
#runtime_name= ⇒ Object
48 |
# File 'lib/cfoundry/v1/app.rb', line 48 alias_method :runtime_name=, :runtime= |
#service_names ⇒ Object
50 |
# File 'lib/cfoundry/v1/app.rb', line 50 alias_method :service_names, :services |
#service_names= ⇒ Object
51 |
# File 'lib/cfoundry/v1/app.rb', line 51 alias_method :service_names=, :services= |
#services ⇒ Object
78 79 80 |
# File 'lib/cfoundry/v1/app.rb', line 78 def services service_names.collect { |name| @client.service_instance(name) } end |
#services=(instances) ⇒ Object
82 83 84 |
# File 'lib/cfoundry/v1/app.rb', line 82 def services=(objs) set_many_named(:service, objs) end |
#start! ⇒ Object
Start the application.
119 120 121 122 |
# File 'lib/cfoundry/v1/app.rb', line 119 def start! self.state = "STARTED" update! end |
#started? ⇒ Boolean
Is the application started?
Note that this does not imply that all instances are running. See #healthy?
174 175 176 |
# File 'lib/cfoundry/v1/app.rb', line 174 def started? state == "STARTED" end |
#stats ⇒ Object
Retrieve application statistics, e.g. CPU load and memory usage.
102 103 104 105 106 107 108 109 110 |
# File 'lib/cfoundry/v1/app.rb', line 102 def stats stats = {} @client.base.stats(@guid).each do |idx, info| stats[idx.to_s] = info end stats end |
#stop! ⇒ Object
Stop the application.
113 114 115 116 |
# File 'lib/cfoundry/v1/app.rb', line 113 def stop! self.state = "STOPPED" update! end |
#stopped? ⇒ Boolean
Is the application stopped?
166 167 168 |
# File 'lib/cfoundry/v1/app.rb', line 166 def stopped? state == "STOPPED" end |
#total_instances ⇒ Object
38 |
# File 'lib/cfoundry/v1/app.rb', line 38 alias_method :total_instances, :instances |
#unbind(*instances) ⇒ Object
Unbind services from application.
230 231 232 233 |
# File 'lib/cfoundry/v1/app.rb', line 230 def unbind(*instances) self.services -= instances update! end |
#uri ⇒ Object Also known as: url
Shortcut for uris
180 181 182 |
# File 'lib/cfoundry/v1/app.rb', line 180 def uri uris[0] end |
#uri=(x) ⇒ Object Also known as: url=
Shortcut for uris = [x]
185 186 187 |
# File 'lib/cfoundry/v1/app.rb', line 185 def uri=(x) self.uris = [x] end |