Class: VMC::KNIFE::ApplicationManifestApplier

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, client, old_name = nil) ⇒ ApplicationManifestApplier

or the JSON for it.

Parameters:

  • application

    The application object as defined in the SaaS manifest

  • client

    the vmc client object. assumed that it is logged in.



664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/vmc_knife/vmc_knife.rb', line 664

def initialize(application, client, old_name=nil)
  @client = client
  if application.kind_of? Hash
    @application_json = application
  elsif application.kind_of? Application
    @application_json = application.wrapped
  else
    raise "Unexpected type of object to describe the application #{application}"
  end
  raise "Can't find the name of the application" if @application_json['name'].nil?
  @current_name = old_name
  @current_name ||= @application_json['old_name']
  @current_name ||= @application_json['name']
end

Instance Attribute Details

#application_jsonObject

Returns the value of attribute application_json.



660
661
662
# File 'lib/vmc_knife/vmc_knife.rb', line 660

def application_json
  @application_json
end

#clientObject

Returns the value of attribute client.



660
661
662
# File 'lib/vmc_knife/vmc_knife.rb', line 660

def client
  @client
end

#current_nameObject

Returns the value of attribute current_name.



660
661
662
# File 'lib/vmc_knife/vmc_knife.rb', line 660

def current_name
  @current_name
end

Instance Method Details

#__set_current(current) ⇒ Object

Only for testing: inject json



696
697
698
# File 'lib/vmc_knife/vmc_knife.rb', line 696

def __set_current(current)
  @current = current
end

#app_download_dir_pathObject



903
904
905
# File 'lib/vmc_knife/vmc_knife.rb', line 903

def app_download_dir_path()
  "#{ENV['HOME']}/vmc_knife_downloads/#{@application_json['name']}"
end

#ccdb_app_hash(hash_type = 'staged_package_hash') ⇒ Object

hash_type: ‘staged_package_hash’ or ‘package_hash’



754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/vmc_knife/vmc_knife.rb', line 754

def ccdb_app_hash(hash_type='staged_package_hash')
  db=KNIFE::get_ccdb_credentials()
  # todo: add the id of the current vcap user. not a problem unless we have multiple vcap users.
  app_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from apps where name='#{@current_name}'\" #{PSQL_RAW_RES_ARGS}`.strip
  unless app_id
    raise "Can't find the app #{@current_name} amongst the deployed apps in the cloud_controller."
  end
  staged_hash=`psql --username #{db['username']} --dbname #{db['database']} -c \"select #{hash_type} from apps where id='#{app_id}'\" #{PSQL_RAW_RES_ARGS}`.strip
  unless app_id
    raise "The app #{@current_name} is not staged yet."
  end
  staged_hash.strip! if staged_hash
  staged_hash
end

#ccdb_app_idObject

returns the internal id of the app in the cloud_controller database



741
742
743
# File 'lib/vmc_knife/vmc_knife.rb', line 741

def ccdb_app_id()
  KNIFE::get_app_id(@current_name)
end

#ccdb_package_hashObject

The sha1 of the package; not staged



749
750
751
# File 'lib/vmc_knife/vmc_knife.rb', line 749

def ccdb_package_hash()
  ccdb_app_hash('package_hash')
end

#ccdb_staged_hashObject

the sha1 of the staged package



745
746
747
# File 'lib/vmc_knife/vmc_knife.rb', line 745

def ccdb_staged_hash()
  ccdb_app_hash('staged_package_hash')
end

#cmd_read_version_installedObject



794
795
796
797
798
# File 'lib/vmc_knife/vmc_knife.rb', line 794

def cmd_read_version_installed()
  cmd=@application_json['repository']['version_installed']['cmd'] if @application_json['repository']['version_installed']
  cmd||=@application_json['repository']['version_available']['cmd'] if @application_json['repository']['version_available']
  cmd
end

#currentObject



688
689
690
691
692
693
# File 'lib/vmc_knife/vmc_knife.rb', line 688

def current()
  return @current unless @current.nil?
  @current = safe_app_info(@current_name)
  @current ||= safe_app_info(@application_json['name']) # in case the rename occurred already.
  @current ||= Hash.new # that would be a new app.
end

#deleteObject



1058
1059
1060
1061
1062
1063
1064
# File 'lib/vmc_knife/vmc_knife.rb', line 1058

def delete()
  if current().empty?
    puts "The application #{@application_json['name']} does not exist yet" if VMC::Cli::Config.trace
  else
    client.delete_app(@application_json['name']) unless current().empty?
  end
end

#diff_lists(old_services, new_services) ⇒ Object



1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/vmc_knife/vmc_knife.rb', line 1185

def diff_lists(old_services,new_services)
  new_services ||= Array.new
  old_services ||= Array.new
  add = Array.new
  remove = Array.new
  new_services.each do |item|
    add << item unless old_services.include? item
  end
  old_services.each do |item|
    remove << item unless new_services.include? item
  end
  return if add.empty? && remove.empty?
  return { "add" => add } if remove.empty?
  return { "remove" => remove } if add.empty?
  return { "add" => add, "remove" => remove }
end

#droplet_file_pathObject



811
812
813
814
815
816
817
818
819
820
# File 'lib/vmc_knife/vmc_knife.rb', line 811

def droplet_file_path()
  return unless @application_json['repository']
  return unless ccdb_app_id()
  # go into the cloud_controller db, find out the staged_hash
  staged_hash=ccdb_staged_hash()
  return unless staged_hash && !staged_hash.empty?
  droplet="/var/vcap/shared/droplets/#{staged_hash}"
  raise "Can't find the staged droplet file #{droplet}." unless File.exist?(droplet)
  return droplet
end

#executeObject



700
701
702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/vmc_knife/vmc_knife.rb', line 700

def execute()
  diff = updates_pending()
  if diff && diff.size > 0
    if @current['name'].nil? && @current[:name].nil?
      puts "Creating #{@application_json['name']} with #{updated_manifest.inspect}"
      @client.create_app(@application_json['name'], updated_manifest)
    elsif @current['name'] != @application_json['name']
      # This works for renaming the application too.
      puts "Updating #{@application_json['name']} with #{updated_manifest.inspect}"
      @client.update_app(@application_json['name'], updated_manifest)
    end

  end
end

#extract_deployed(force = false) ⇒ Object



906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'lib/vmc_knife/vmc_knife.rb', line 906

def extract_deployed(force=false)
  installed_v=version_installed()
  unless installed_v
    puts "No deployed app #{@application_json['name']}. Not extracting it"
    return
  end
  do_extract=false
  app_download_dir=app_download_dir_path()
  if force
    FileUtils.rm_rf app_download_dir if File.exists?(app_download_dir)
    do_extract=true
  elsif File.exists?(app_download_dir)
    version_file_in_download = File.join(app_download_dir,  version_available_file_path(false))
    p "Reading the version of the downloaded app folder in file #{version_file_in_download}"
    cmd_to_read=cmd_read_version_installed()
    version_downloaded=read_version(version_file_in_download,cmd_to_read)
	  if installed_v != version_downloaded
	    p "The version installed is #{installed_v} and the version ready to be deployed is #{version_downloaded}"
	    p "Would you like to replace the app to deploy by the one already deployed?"
	    ans = STDIN.gets.chomp
      if ans && ans.capitalize.start_with?('Y')
        FileUtils.rm_rf app_download_dir if File.exists?(app_download_dir)
        do_extract=true
      end
	  else
	    p "The version installed and the version ready to deploy are identical: #{installed_v}"
    end
  else
    do_extract = true
  end
  if do_extract
    FileUtils.mkdir_p app_download_dir
    drop_f_p=droplet_file_path()
    p "tar -xzvf #{drop_f_p}"
    `cd /tmp; [ -d drop_app ] && rm -rf drop_app; mkdir drop_app; cd drop_app; tar -xzvf #{drop_f_p}; [ -d app ] && mv app/* #{app_download_dir} || mv tomcat/webapps/ROOT/* #{app_download_dir}`
    p "Done. ls -la #{app_download_dir}"
    `ls -la #{app_download_dir}`
  end
  do_extract
end

#infoObject



853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
# File 'lib/vmc_knife/vmc_knife.rb', line 853

def info()
  app_id=ccdb_app_id()
  if app_id
    staged_hash=ccdb_staged_hash()||"deployed; not staged"
    installed_v=version_installed()||"deployed; can't read installed version"
  else
    installed_v="not uploaded"
    staged_hash="not staged"
  end
  available_v=version_available()||"none"
  puts "Application #{@application_json['name']}"
  puts "  Version installed: #{installed_v}; Staged hash: #{staged_hash}"
  puts "  Version available: #{available_v}"
  return installed_v == available_v if installed_v && available_v
  return false
end

#meta_pendingObject

only look for debug and restage_on_service_change



1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/vmc_knife/vmc_knife.rb', line 1167

def meta_pending()
  old_meta = current[:meta] || current['meta'] || {}
  new_meta = @application_json['meta'] || {}
  old_debug = old_meta[:debug] || old_meta['debug']
  new_debug = new_meta['debug']
  debug_change = "#{old_debug} => #{new_debug}" if old_debug != new_debug

  old_restage_on_service_change = old_meta[:restage_on_service_change]
  old_restage_on_service_change = old_meta['restage_on_service_change'] unless old_restage_on_service_change == false
  old_restage_on_service_change = old_restage_on_service_change.to_s unless old_restage_on_service_change.nil?
  new_restage_on_service_change = new_meta['restage_on_service_change']
  restage_on_service_change_change = "#{old_restage_on_service_change} => #{new_restage_on_service_change}" if old_restage_on_service_change != new_restage_on_service_change

  return if debug_change.nil? && restage_on_service_change_change.nil?
  return { "debug" => debug_change } if restage_on_service_change_change.nil?
  return { "restage_on_service_change" => restage_on_service_change_change } if debug_change.nil?
  return { "debug" => debug_change, "restage_on_service_change" => restage_on_service_change_change }
end

#patch(force = false) ⇒ Object



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
# File 'lib/vmc_knife/vmc_knife.rb', line 1032

def patch(force=false)
  app_download_dir=app_download_dir_path()
  app_was_extracted = extract_deployed(force)
  p "Application ready to be patched in #{app_download_dir}"
  if VMC::Cli::Config.trace || app_was_extracted
    p "Type y when ready to update. Anything else will stop."
    ans = STDIN.gets.chomp
    return unless ans && ans.capitalize.start_with?('Y')
  end
  upload_app_bits()
end

#read_version(droplet_dot_version, cmd) ⇒ Object



800
801
802
803
804
805
806
807
808
809
# File 'lib/vmc_knife/vmc_knife.rb', line 800

def read_version(droplet_dot_version,cmd)
  if File.exists? droplet_dot_version
    installed_version=`version_built_download=#{droplet_dot_version};#{cmd}`.strip
    raise "could not read the installed version in \
        #{File.expand_path(version_available_file)} with version_built_download=#{droplet_dot_version};#{cmd}" unless installed_version
    installed_version.gsub!(/^["']|["']$/, '')
    puts "#{@current_name} is staged with version installed_version #{installed_version}" if VMC::Cli::Config.trace
    return installed_version
  end
end

#safe_app_info(name) ⇒ Object



679
680
681
682
683
684
685
686
# File 'lib/vmc_knife/vmc_knife.rb', line 679

def safe_app_info(name)
  begin
    return @client.app_info(name)
  rescue VMC::Client::NotFound
    #expected
    return
  end
end

#startObject



1044
1045
1046
1047
1048
1049
# File 'lib/vmc_knife/vmc_knife.rb', line 1044

def start()
  #raise "The application #{@application_json['name']} does not exist yet" if current().empty?
  return if current().empty? || current[:state] == 'STARTED'
  current[:state] = 'STARTED'
  client.update_app(@application_json['name'], current())
end

#stopObject



1051
1052
1053
1054
1055
1056
# File 'lib/vmc_knife/vmc_knife.rb', line 1051

def stop()
  #raise "The application #{@application_json['name']} does not exist yet" if current().empty?
  return if current().empty? || current[:state] == 'STOPPED'
  current[:state] = 'STOPPED'
  client.update_app(@application_json['name'], current())
end

#update(force = false) ⇒ Object



882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/vmc_knife/vmc_knife.rb', line 882

def update(force=false)
  raise "The application #{@application_json['name']} does not exist yet" if current().empty?
  do_delete_download=false
  begin
    installed_version=version_installed()
    p "#{@current_name} installed_version #{installed_version}"
    available_version=version_available()
    p "#{@current_name} available_version #{available_version}"
    if installed_version == available_version
      puts "The staged version of #{@current_name} is the same as the one on the remote repository"
      return unless force
      puts "Forced download"
    end
    do_delete_download=true
  rescue => e
    p "Trying to read the installed and available version crashed. #{e}"
    p e.backtrace.join("\n") if VMC::Cli::Config.trace
  end
  upload(force,do_delete_download)
end

#update_env_pendingObject



1156
1157
1158
1159
1160
# File 'lib/vmc_knife/vmc_knife.rb', line 1156

def update_env_pending()
  old_services = current[:env] || current['env']
  new_services = @application_json['env']
  diff_lists(old_services,new_services)
end

#update_memory_pendingObject



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/vmc_knife/vmc_knife.rb', line 1120

def update_memory_pending()
  old_mem = current[:resources][:memory] if current[:resources]
  old_mem ||= current['resources']['memory'] if current['resources']
  old_mem = old_mem.to_i if old_mem && old_mem.kind_of?(String)
  new_mem = @application_json['resources']['memory'] unless @application_json['resources'].nil?
  new_mem = new_mem.to_i if new_mem && new_mem.kind_of?(String)
  if old_mem != new_mem
    return "#{old_mem} => #{new_mem}"
  end
end

#update_name_pendingObject



1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/vmc_knife/vmc_knife.rb', line 1111

def update_name_pending()
  curr_name=current[:name] || current['name']
  if curr_name.nil?
    return "Create #{@application_json['name']}"
  end
  if @application_json['name'] != curr_name
    return "#{curr_name} => #{@application_json['name']}"
  end
end

#update_services_pendingObject



1151
1152
1153
1154
1155
# File 'lib/vmc_knife/vmc_knife.rb', line 1151

def update_services_pending()
  old_services = current[:services] || current['services']
  new_services = @application_json['services']
  diff_lists(old_services,new_services)
end

#update_staging_pendingObject



1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
# File 'lib/vmc_knife/vmc_knife.rb', line 1130

def update_staging_pending()
  if current[:staging] # sym style: real vmc.
    old_model = current[:staging][:model]
    old_stack = current[:staging][:stack]
  elsif current['staging'] # string style: testing.
    old_model = current['staging']['model']
    old_stack = current['staging']['stack']
  end
  new_model = @application_json['staging']['model'] unless @application_json['staging'].nil?
  new_stack = @application_json['staging']['stack'] unless @application_json['staging'].nil?
  if old_model != new_model
    model_change "#{old_model} => #{new_model}"
  end
  if old_stack != new_stack
    stack_change "#{old_stack} => #{new_stack}"
  end
  return if model_change.nil? && stack_change.nil?
  return { "stack" => stack_change } if model_change.nil?
  return { "model" => model_change } if stack_change.nil?
  return { "stack" => stack_change, "model" => model_change }
end

#update_uris_pendingObject



1161
1162
1163
1164
1165
# File 'lib/vmc_knife/vmc_knife.rb', line 1161

def update_uris_pending()
  old_services = current[:uris] || current['uris']
  new_services = @application_json['uris']
  diff_lists(old_services,new_services)
end

#updated_manifestObject

Generate the updated application manifest: take the manifest defined in the saas recipe merge it with the current manifest of the application.



1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/vmc_knife/vmc_knife.rb', line 1069

def updated_manifest()
  new_app_manifest = JSON.parse(current.to_json) # a deep clone.
  #now let's update everything.
  new_mem = @application_json['resources']['memory'] unless @application_json['resources'].nil?
  new_app_manifest[:name] = @application_json['name']
  new_app_manifest['resources'] = Hash.new if new_app_manifest['resources'].nil?
  new_app_manifest['resources']['memory'] = new_mem unless new_mem.nil?
  unless @application_json['staging'].nil?
    new_app_manifest['staging'] = Hash.new if new_app_manifest['staging'].nil?
    new_app_manifest['staging']['model'] = @application_json['staging']['model'] unless @application_json['staging']['model'].nil?
    #new_app_manifest['staging']['framework'] = new_app_manifest['staging']['model']
    new_app_manifest['staging']['stack'] = @application_json['staging']['stack'] unless @application_json['staging']['stack'].nil?
  end
  new_app_manifest['uris'] = @application_json['uris'] unless @application_json['uris'].nil?
  new_app_manifest['services'] = @application_json['services'] unless @application_json['services'].nil?
  new_app_manifest['env'] = @application_json['env'] unless @application_json['env'].nil?
  if @application_json['meta']
    new_app_manifest['meta'] = Hash.new if new_app_manifest['meta'].nil?
    new_app_manifest['meta']['debug'] = @application_json['meta']['debug'] if @application_json['meta']['debug']
    new_app_manifest['meta']['restage_on_service_change'] = @application_json['meta']['restage_on_service_change'] if @application_json['meta']['restage_on_service_change']
  end
  new_app_manifest
end

#updates_pendingObject

Returns a json object where we see the differences.



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'lib/vmc_knife/vmc_knife.rb', line 1094

def updates_pending()
  name = update_name_pending()
  services = update_services_pending()
  env = update_env_pending()
  memory = update_memory_pending()
  meta = meta_pending()
  uris = update_uris_pending()
  updates = Hash.new
  updates['name'] = name if name
  updates['services'] = services if services
  updates['env'] = env if env
  updates['uris'] = uris if uris
  updates['memory'] = memory if memory
  updates['meta'] = meta if meta
  updates unless updates.empty?
end

#upload(force = false, do_delete_download = false) ⇒ Object



946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'lib/vmc_knife/vmc_knife.rb', line 946

def upload(force=false,do_delete_download=false)
  raise "The application #{@application_json['name']} does not exist yet" if current().empty?
  return unless @application_json['repository']
  url = @application_json['repository']['url']

  Dir.chdir(ENV['HOME']) do
    tmp_download_filename="_download_.zip"
    app_download_dir=app_download_dir_path()
    `rm -rf #{app_download_dir}` if File.exist?("#{app_download_dir}") && do_delete_download
    `rm -rf #{app_download_dir}` if File.exist? "#{app_download_dir}/#{tmp_download_filename}"

    FileUtils.mkdir_p app_download_dir
    Dir.chdir(app_download_dir) do
      if Dir.entries(Dir.pwd).size == 2 #empty directory ?
        if /\.git$/ =~ url
          `git clone #{url} --depth 1`
          branch = @application_json['repository']['branch']
          if branch
            `git checkout #{branch}`
          else
            branch='master'
          end
          `git pull origin #{branch}`
        else
          begin
            wget_args_str = wget_args()
            #`wget #{wget_args_str} --output-document=#{tmp_download_filename} #{url}`
            #TODO: find the same file in the installed apps.
`touch /tmp/wget_#{@application_json['name']};\
 wget #{wget_args_str} --output-document=#{tmp_download_filename} #{url} --output-file=/tmp/wget_#{@application_json['name']}`
            raise "Unable to download #{url}" unless $? == 0
            if /\.tgz$/ =~ url || /\.tar\.gz$/ =~ url
              `tar zxvf #{tmp_download_filename} --strip 1`
            elsif /\.tar$/ =~ url
              `tar xvf #{tmp_download_filename}`
            else
              `unzip #{tmp_download_filename}`
            end

            # also download the version file
            `wget -N #{File.dirname(url)}/version_built.properties`
          ensure
            `[ -f #{tmp_download_filename} ] && rm #{tmp_download_filename}`
          end
=begin            else
        if /\.git$/ =~ url
          branch = @application_json['repository']['branch']||"master"
          `git checkout #{branch}`
          `git pull origin #{branch}`
=end
        end
      end
      post_download_script = @application_json['repository']['post_download_script']
      if post_download_script
        post_download_script = post_download_script.join("\n") if post_download_script.kind_of?(Array)
        p "Executing the post_download script : #{post_download_script}"
        success = system(post_download_script)
        p "Done executing the post_download script succcess #{success}"
        #exit unless success
      end
      upload_app_bits()
    end
  end
end

#upload_app_bitsObject



1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
# File 'lib/vmc_knife/vmc_knife.rb', line 1011

def upload_app_bits()
  Dir.chdir(app_download_dir_path()) do
    puts "upload_app_bits in #{app_download_dir_path()}"
    Dir.chdir(@application_json['repository']['sub_dir']) if @application_json['repository']['sub_dir']
    tmp_git = "/tmp/#{@application_json['name']}.git"
    if File.exists? ".git"
      # don't deploy the .git repo
      FileUtils.rm_rf(tmp_git) if File.exists?(tmp_git)
      FileUtils.mv(".git", tmp_git)
    end
    ori_trace = VMC::Cli::Config.trace
    begin
      VMC::KNIFE::HELPER.static_upload_app_bits(@client,@application_json['name'],Dir.pwd)
    rescue
      FileUtils.mv(tmp_git, ".git") if File.exists?(tmp_git)
    ensure
      VMC::Cli::Config.trace = ori_trace
    end
  end
end

#version_availableObject



715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
# File 'lib/vmc_knife/vmc_knife.rb', line 715

def version_available()
  return unless @application_json['repository']
  if @application_json['repository']['version_available'] && @application_json['repository']['version_available']['url']
    version_available_url=@application_json['repository']['version_available']['url']
    url = @application_json['repository']['url']
    cmd=@application_json['repository']['version_available']['cmd']
    if version_available_url.start_with?("./")
      version_available_url.slice!(0)
      version_available_url.slice!(0)
    end
    unless /:\/\// =~ version_available_url || version_available_url.start_with?("/")
      rel_url=File.dirname(url)
      version_available_file||=version_available_file
      version_available_url="#{rel_url}/#{version_available_url}"
      p "version_available_url: #{version_available_url}" if VMC::Cli::Config.trace
      p "extract with #{cmd}" if VMC::Cli::Config.trace
    end
    ## This will find out the available version.
`version_built_download=/tmp/version_built_download
wget #{wget_args()} --output-document=$version_built_download #{version_available_url} --output-file=/tmp/wget_#{@application_json['name']}_available`
    available_version=`version_built_download=/tmp/version_built_download;#{cmd}`.strip
    available_version.gsub(/^["']|["']$/, '')
  end
end

#version_available_file_path(prefix_app_by_default = true) ⇒ Object



769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/vmc_knife/vmc_knife.rb', line 769

def version_available_file_path(prefix_app_by_default=true)
  # extract the file that contains the version from that tar.gz
  version_available_file=@application_json['repository']['version_installed']['staged_entry'] if @application_json['repository']['version_installed']
  unless version_available_file
    # default on the available url prefixed by the 'app' folder
    if @application_json['repository']['version_available'] && @application_json['repository']['version_available']['url']
      version_available_url=@application_json['repository']['version_available']['url']
      if version_available_url.start_with?("./")
        version_available_url.slice!(0)
        version_available_url.slice!(0)
        version_available_file= prefix_app_by_default ? "app/#{version_available_url}" : version_available_url
      elsif !(/:\/\// =~ version_available_url) && !(version_available_url.start_with?("/"))
        version_available_file= prefix_app_by_default ? "app/#{version_available_url}" : version_available_url
      end
    end
  else
    if version_available_file.start_with?('app/') && !prefix_app_by_default
      version_available_file=version_available_file['app/'.length..-1]
    elsif version_available_file.start_with?('tomcat/webapp/ROOT/') && !prefix_app_by_default
      version_available_file=version_available_file['tomcat/webapp/ROOT/'.length..-1]
    end
  end
  version_available_file
end

#version_installedObject

Reads the version installed



823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/vmc_knife/vmc_knife.rb', line 823

def version_installed()
  droplet=droplet_file_path()
  return unless droplet
  version_available_file = version_available_file_path()
  unless version_available_file
    puts "Don't know what file stores the version installed of #{@current_name}" if VMC::Cli::Config.trace
    return
  end
  cmd = cmd_read_version_installed()
  unless cmd
    puts "Don't know how to read the version installed with a cmd." if VMC::Cli::Config.trace
    return
  end
  puts "Looking for the installed version here #{droplet} // #{version_available_file}" if VMC::Cli::Config.trace
  puts "   with cmd #{cmd}" if VMC::Cli::Config.trace
  droplet_dot_version="#{droplet}.version"
  unless File.exists? droplet_dot_version
    Dir.chdir("/tmp") do
      `[ -f #{version_available_file} ] && rm #{version_available_file}`
      `tar -xzf #{droplet} #{version_available_file}`
      if File.exist?(version_available_file)
        `cp #{version_available_file} #{droplet_dot_version}`
      else
        puts "Could not find the installed version file here: here #{droplet} // #{version_available_file}" if VMC::Cli::Config.trace
      end
    end
  end
  installed_version=read_version(droplet_dot_version,cmd)
end

#wget_argsObject



870
871
872
873
874
875
876
877
878
879
880
# File 'lib/vmc_knife/vmc_knife.rb', line 870

def wget_args()
  _wget_args = @application_json['repository']['wget_args']
  if _wget_args.nil?
    wget_args_str = ""
  elsif _wget_args.kind_of? Array
    wget_args_str = wget_args.join(' ')
  elsif _wget_args.kind_of? String
    wget_args_str = wget_args
  end
  wget_args_str
end