Class: CFoundry::V2::App
- Includes:
- UploadHelpers
- Defined in:
- lib/cfoundry/v2/app.rb
Overview
Class for representing a user’s application on a given target (via Client).
Does not guarantee that the app exists; used for both app creation and retrieval, as the attributes are all lazily retrieved. Setting attributes does not perform any requests; use #update! to commit your changes.
Constant Summary
Constants included from UploadHelpers
Instance Attribute Summary
Attributes inherited from Model
Instance Method Summary collapse
-
#bind(*instances) ⇒ Object
Bind services to application.
- #binds?(instance) ⇒ Boolean
-
#command ⇒ Object
TODO v2.
-
#console ⇒ Object
TODO v2.
-
#debug_mode ⇒ Object
TODO v2.
- #env ⇒ Object
- #env=(hash) ⇒ Object
-
#health ⇒ Object
Determine application health.
-
#healthy? ⇒ Boolean
(also: #running?)
Check that all application instances are running.
-
#restart! ⇒ Object
Restart the application.
- #services ⇒ Object
-
#start! ⇒ Object
Start the application.
-
#started? ⇒ Boolean
Is the application started?.
-
#stop! ⇒ Object
Stop the application.
-
#stopped? ⇒ Boolean
Is the application stopped?.
-
#unbind(*instances) ⇒ Object
Unbind services from application.
-
#upload(path, check_resources = true) ⇒ Object
Upload application’s code to target.
- #uri ⇒ Object (also: #url)
- #uris ⇒ Object (also: #urls)
- #uris=(x) ⇒ Object (also: #urls=)
Methods included from UploadHelpers
#check_unreachable_links, #find_sockets, #make_fingerprints, #prepare_package
Methods inherited from Model
attribute, #create!, defaults, #delete!, #eql?, #exists?, #hash, #initialize, #inspect, #invalidate!, #manifest, #object_name, to_many, to_one, #update!, validate_type, value_matches?
Constructor Details
This class inherits a constructor from CFoundry::V2::Model
Instance Method Details
#bind(*instances) ⇒ Object
Bind services to application.
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cfoundry/v2/app.rb', line 132 def bind(*instances) instances.each do |i| binding = @client.service_binding binding.app = self binding.service_instance = i binding.create! end self end |
#binds?(instance) ⇒ Boolean
154 155 156 157 158 |
# File 'lib/cfoundry/v2/app.rb', line 154 def binds?(instance) service_bindings.any? { |b| b.service_instance == instance } end |
#command ⇒ Object
TODO v2
55 56 57 |
# File 'lib/cfoundry/v2/app.rb', line 55 def command # TODO v2 nil end |
#console ⇒ Object
TODO v2
63 64 65 |
# File 'lib/cfoundry/v2/app.rb', line 63 def console # TODO v2 nil end |
#debug_mode ⇒ Object
TODO v2
59 60 61 |
# File 'lib/cfoundry/v2/app.rb', line 59 def debug_mode # TODO v2 nil end |
#env ⇒ Object
43 44 45 46 47 |
# File 'lib/cfoundry/v2/app.rb', line 43 def env @env ||= CFoundry::ChattyHash.new( method(:env=), MultiJson.load(environment_json)) end |
#env=(hash) ⇒ Object
49 50 51 52 53 |
# File 'lib/cfoundry/v2/app.rb', line 49 def env=(hash) @env = hash @diff["environment_json"] = hash hash end |
#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.
106 107 108 |
# File 'lib/cfoundry/v2/app.rb', line 106 def health state end |
#healthy? ⇒ Boolean Also known as: running?
Check that all application instances are running.
111 112 113 114 115 |
# File 'lib/cfoundry/v2/app.rb', line 111 def healthy? # invalidate cache so the check is fresh @manifest = nil health == "RUNNING" end |
#restart! ⇒ Object
Restart the application.
95 96 97 98 |
# File 'lib/cfoundry/v2/app.rb', line 95 def restart! stop! start! end |
#services ⇒ Object
39 40 41 |
# File 'lib/cfoundry/v2/app.rb', line 39 def services service_bindings.collect(&:service_instance) end |
#start! ⇒ Object
Start the application.
90 91 92 |
# File 'lib/cfoundry/v2/app.rb', line 90 def start! update! :state => "STARTED" end |
#started? ⇒ Boolean
Is the application started?
Note that this does not imply that all instances are running. See #healthy?
127 128 129 |
# File 'lib/cfoundry/v2/app.rb', line 127 def started? state == "STARTED" end |
#stop! ⇒ Object
Stop the application.
85 86 87 |
# File 'lib/cfoundry/v2/app.rb', line 85 def stop! update! :state => "STOPPED" end |
#stopped? ⇒ Boolean
Is the application stopped?
119 120 121 |
# File 'lib/cfoundry/v2/app.rb', line 119 def stopped? state == "STOPPED" end |
#unbind(*instances) ⇒ Object
Unbind services from application.
144 145 146 147 148 149 150 151 152 |
# File 'lib/cfoundry/v2/app.rb', line 144 def unbind(*instances) service_bindings.each do |b| if instances.include? b.service_instance b.delete! end end self end |
#upload(path, check_resources = true) ⇒ Object
Upload application’s code to target. Do this after #create! and before #start!
- path
-
A path pointing to either a directory, or a .jar, .war, or .zip file.
If a .vmcignore file is detected under the given path, it will be used to exclude paths from the payload, similar to a .gitignore.
- check_resources
-
If set to ‘false`, the entire payload will be uploaded without checking the resource cache.
Only do this if you know what you’re doing.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cfoundry/v2/app.rb', line 175 def upload(path, check_resources = true) unless File.exist? path raise "invalid application path '#{path}'" end zipfile = "#{Dir.tmpdir}/#{@guid}.zip" tmpdir = "#{Dir.tmpdir}/.vmc_#{@guid}_files" FileUtils.rm_f(zipfile) FileUtils.rm_rf(tmpdir) prepare_package(path, tmpdir) resources = determine_resources(tmpdir) if check_resources packed = CFoundry::Zip.pack(tmpdir, zipfile) @client.base.upload_app(@guid, packed && zipfile, resources || []) ensure FileUtils.rm_f(zipfile) if zipfile FileUtils.rm_rf(tmpdir) if tmpdir end |
#uri ⇒ Object Also known as: url
79 80 81 |
# File 'lib/cfoundry/v2/app.rb', line 79 def uri uris[0] end |
#uris ⇒ Object Also known as: urls
67 68 69 70 71 |
# File 'lib/cfoundry/v2/app.rb', line 67 def uris routes.collect do |r| "#{r.host}.#{r.domain.name}" end end |
#uris=(x) ⇒ Object Also known as: urls=
74 75 76 |
# File 'lib/cfoundry/v2/app.rb', line 74 def uris=(x) raise "App#uris= is invalid against V2 APIs. Use add/remove_route." end |