Class: VMC::KNIFE::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/vmc_knife/vmc_knife.rb

Overview

Read/Write the JSON for an application. Does not map the actual JSON into a new ruby object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, data, role_name) ⇒ Application

Returns a new instance of Application.



146
147
148
149
150
# File 'lib/vmc_knife/vmc_knife.rb', line 146

def initialize(root, data, role_name)
  @root = root
  @wrapped = data
  @role_name = role_name
end

Instance Attribute Details

#role_nameObject

Returns the value of attribute role_name.



145
146
147
# File 'lib/vmc_knife/vmc_knife.rb', line 145

def role_name
  @role_name
end

#rootObject

Returns the value of attribute root.



145
146
147
# File 'lib/vmc_knife/vmc_knife.rb', line 145

def root
  @root
end

#wrappedObject

Returns the value of attribute wrapped.



145
146
147
# File 'lib/vmc_knife/vmc_knife.rb', line 145

def wrapped
  @wrapped
end

Instance Method Details

#envObject



161
162
163
# File 'lib/vmc_knife/vmc_knife.rb', line 161

def env()
  ApplicationEnvironment.new @wrapped['env'], self
end

#log(folder, log_file_glob = nil) ⇒ Object

look for the log folder of the deployed app. making the assumption we are on the same file system. will use the paas APIs later.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/vmc_knife/vmc_knife.rb', line 176

def log(folder,log_file_glob=nil)
  deployed_apps_folder="/home/ubuntu/cloudfoundry/deployed_apps"
  log_file_glob ||= "logs/*"
  if File.exist?(deployed_apps_folder)
    folder_nb=0
    Dir.glob(File.join(deployed_apps_folder, "#{name()}-*")).each do |dir|
      fname="#{File.basename(dir)}"
      app_log_folder=File.join(folder,fname)
      FileUtils.mkdir_p(app_log_folder)
      if File.exist? "#{dir}/logs"
        FileUtils.cp(Dir.glob(File.join("#{dir}", "logs/*")), app_log_folder)
      end
    end
  end
end

#log_shell(shell_cmd = nil, log_file_glob = nil) ⇒ Object

look for the most recent folder where we can find the stdout file. fork to the shell with the ‘less’ command to display the contents of the file.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/vmc_knife/vmc_knife.rb', line 194

def log_shell(shell_cmd=nil,log_file_glob=nil)
  deployed_apps_folder="/home/ubuntu/cloudfoundry/deployed_apps"
  shell_cmd ||= "less"
  log_file_glob ||= File.join("logs","stdout.log")
  if File.exist?(deployed_apps_folder)
    ts_most_recent=0
    most_recent_file=nil
    app_deployed=false
    Dir.glob(File.join(deployed_apps_folder, "#{name()}-*")).each do |dir|
      app_deployed=true
      Dir.glob(File.join("#{dir}", log_file_glob)).each do |logfile|
        ts=File.mtime(logfile).to_i
        if ts > ts_most_recent
          most_recent_file=logfile
          ts_most_recent = ts
        end
      end
    end
    if most_recent_file
      cmd = "#{shell_cmd} #{most_recent_file}"
      puts "#{cmd}" if VMC::Cli::Config.trace
      exec cmd
    elsif app_deployed
      raise "Could not find a log file #{log_file_glob} in the deployed app folder."
    else
      raise "Could not find a deployed application named #{name}"
    end
  else
    raise "Could not find the deployed application folder #{deployed_apps_folder}"
  end
end

#memoryObject



158
159
160
# File 'lib/vmc_knife/vmc_knife.rb', line 158

def memory()
  @wrapped['resources']['memory']
end

#nameObject

Returns the application name (different from the application role name.)



152
153
154
# File 'lib/vmc_knife/vmc_knife.rb', line 152

def name()
  @wrapped['name']
end

#to_vcap_manifestObject

Returns a vcap manifest that can be used to push/update an application to vcap’s cloud_controller.



167
168
169
170
171
# File 'lib/vmc_knife/vmc_knife.rb', line 167

def to_vcap_manifest()
  # This is pretty much identical to the json wrapped here except for the environment variables.
  # if there are differences we will take care of them here.
  @wrapped
end

#urisObject



155
156
157
# File 'lib/vmc_knife/vmc_knife.rb', line 155

def uris()
  @wrapped['uris']
end