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!(async = false) ⇒ 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!(async = false) ⇒ 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.
- #update!(async = false) ⇒ Object
-
#uri ⇒ Object
(also: #url)
Shortcut for uris.
-
#uri=(x) ⇒ Object
(also: #url=)
Shortcut for uris = [x].
Methods included from UploadHelpers
Methods inherited from Model
#base_object_name, #changed?, #create!, #delete!, #eql?, #exists?, #find_path, #guid_name, #hash, inherited, #initialize, #inspect, #invalidate!, #manifest, #object_name, objects, plural_base_object_name, plural_object_name, #put, #read_manifest, #write_manifest
Methods included from ModelMagic
#attribute, #define_client_methods, #on_base_client, #on_client, #read_locations, #read_only_attributes, #write_locations
Constructor Details
This class inherits a constructor from CFoundry::V1::Model
Instance Method Details
#bind(*instances) ⇒ Object
Bind services to application.
228 229 230 231 |
# File 'lib/cfoundry/v1/app.rb', line 228 def bind(*instances) self.services += instances update! end |
#binds?(instance) ⇒ Boolean
239 240 241 |
# File 'lib/cfoundry/v1/app.rb', line 239 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
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/cfoundry/v1/app.rb', line 196 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
208 209 210 211 212 213 214 |
# File 'lib/cfoundry/v1/app.rb', line 208 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
.
259 260 261 |
# File 'lib/cfoundry/v1/app.rb', line 259 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
.
249 250 251 |
# File 'lib/cfoundry/v1/app.rb', line 249 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.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cfoundry/v1/app.rb', line 140 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.
162 163 164 165 166 |
# File 'lib/cfoundry/v1/app.rb', line 162 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!(async = false) ⇒ Object
Restart the application.
125 126 127 128 |
# File 'lib/cfoundry/v1/app.rb', line 125 def restart!(async = false) 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!(async = false) ⇒ Object
Start the application.
119 120 121 122 |
# File 'lib/cfoundry/v1/app.rb', line 119 def start!(async = false) self.state = "STARTED" update! end |
#started? ⇒ Boolean
Is the application started?
Note that this does not imply that all instances are running. See #healthy?
178 179 180 |
# File 'lib/cfoundry/v1/app.rb', line 178 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?
170 171 172 |
# File 'lib/cfoundry/v1/app.rb', line 170 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.
234 235 236 237 |
# File 'lib/cfoundry/v1/app.rb', line 234 def unbind(*instances) self.services -= instances update! end |
#update!(async = false) ⇒ Object
130 131 132 |
# File 'lib/cfoundry/v1/app.rb', line 130 def update!(async = false) super() end |
#uri ⇒ Object Also known as: url
Shortcut for uris
184 185 186 |
# File 'lib/cfoundry/v1/app.rb', line 184 def uri uris[0] end |
#uri=(x) ⇒ Object Also known as: url=
Shortcut for uris = [x]
189 190 191 |
# File 'lib/cfoundry/v1/app.rb', line 189 def uri=(x) self.uris = [x] end |