Class: Application

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

Direct Known Subclasses

JvmApp, RailsZipApp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, project_name, platform_type, options, url_segment = nil) ⇒ Application

Returns a new instance of Application.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/conan/application.rb', line 7

def initialize(id, project_name, platform_type, options, url_segment=nil)
  @id = id
  @platform_type = platform_type
  @url_segment = url_segment || id
  mvn_id = project_name.split(':')
  @options = options
  @org = options[:'deploy-shipcloud'].split('-')[0]
  @infra = options[:'deploy-shipcloud'].split('-')[1]
  @environment = options[:environment]
  @group_id = mvn_id[0]
  @artifact_id = mvn_id[1]
  @smoke_test_path = 'status/healthcheck'
end

Instance Attribute Details

#additional_mappingsObject

Returns the value of attribute additional_mappings.



4
5
6
# File 'lib/conan/application.rb', line 4

def additional_mappings
  @additional_mappings
end

#artifact_idObject

Returns the value of attribute artifact_id.



4
5
6
# File 'lib/conan/application.rb', line 4

def artifact_id
  @artifact_id
end

#artifact_meta_dataObject

Returns the value of attribute artifact_meta_data.



4
5
6
# File 'lib/conan/application.rb', line 4

def 
  
end

#existing_mappingsObject

Returns the value of attribute existing_mappings.



4
5
6
# File 'lib/conan/application.rb', line 4

def existing_mappings
  @existing_mappings
end

#extensionObject

Returns the value of attribute extension.



4
5
6
# File 'lib/conan/application.rb', line 4

def extension
  @extension
end

#group_idObject

Returns the value of attribute group_id.



4
5
6
# File 'lib/conan/application.rb', line 4

def group_id
  @group_id
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/conan/application.rb', line 4

def id
  @id
end

#infraObject

Returns the value of attribute infra.



4
5
6
# File 'lib/conan/application.rb', line 4

def infra
  @infra
end

#orgObject

Returns the value of attribute org.



4
5
6
# File 'lib/conan/application.rb', line 4

def org
  @org
end

#platform_typeObject

Returns the value of attribute platform_type.



4
5
6
# File 'lib/conan/application.rb', line 4

def platform_type
  @platform_type
end

#sha1Object

Returns the value of attribute sha1.



4
5
6
# File 'lib/conan/application.rb', line 4

def sha1
  @sha1
end

#smoke_test_pathObject

Returns the value of attribute smoke_test_path.



4
5
6
# File 'lib/conan/application.rb', line 4

def smoke_test_path
  @smoke_test_path
end

#unique_nameObject

Returns the value of attribute unique_name.



4
5
6
# File 'lib/conan/application.rb', line 4

def unique_name
  @unique_name
end

#url_segmentObject

Returns the value of attribute url_segment.



4
5
6
# File 'lib/conan/application.rb', line 4

def url_segment
  @url_segment
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/conan/application.rb', line 4

def version
  @version
end

Instance Method Details

#active_domainsObject



147
148
149
# File 'lib/conan/application.rb', line 147

def active_domains
  @existing_mappings || [full_backchannel_domain, infra_agnostic_backchannel_domain, alternative_agnostic_backchannel_domain] + Array(@additional_mappings)
end

#active_healthcheck_urlObject



39
40
41
# File 'lib/conan/application.rb', line 39

def active_healthcheck_url
  "http://#{full_backchannel_domain}/#{@smoke_test_path}"
end

#compareVersion(target_version, deployed_version) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/conan/application.rb', line 131

def compareVersion(target_version, deployed_version)
  target = Gem::Version.new(target_version)
  begin
    found = Gem::Version.new(deployed_version)
    target > found
  rescue => e
    puts "Error parsing version number: #{e}"
    false
  end
end

#download(location) ⇒ Object



85
86
87
88
# File 'lib/conan/application.rb', line 85

def download(location)
  puts "- Provision #{group_id}:#{artifact_id}:#{extension}:#{version}"
  @artifact_repo.downloadArtifact(location, group_id, artifact_id, extension, version, sha1)
end

#findRequestedVersion(requested_version = 'LATEST') ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/conan/application.rb', line 51

def findRequestedVersion(requested_version='LATEST')
  puts("Finding requested version: #{requested_version}")
  extension = case platform_type
    when :jvm
      "jar"
    when :rails_zip
      "tar.gz"
    else
      raise "Unsupported platform type: #{platform_type}"
    end
  (@artifact_repo.resolveArtifact(group_id, artifact_id, extension, requested_version))
  puts "- Found version #{version} #{@id} artifact\n"+
    "  Artifact: #{self}\n" +
    "  Checksum: #{@sha1}"
end

#inactive_domainsObject



151
152
153
# File 'lib/conan/application.rb', line 151

def inactive_domains
  active_domains.map{|domain| "x.#{domain}"}
end

#inactive_healthcheck_urlObject



35
36
37
# File 'lib/conan/application.rb', line 35

def inactive_healthcheck_url
  "http://x.#{full_backchannel_domain}/#{@smoke_test_path}"
end

#is_active_node_operational?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/conan/application.rb', line 28

def is_active_node_operational?
  puts "Checking active app at #{inactive_healthcheck_url}"
  !!(RestClient.get(active_healthcheck_url))
rescue
  false
end

#is_inactive_node_operational?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/conan/application.rb', line 21

def is_inactive_node_operational?
  puts "Checking inactive app at #{inactive_healthcheck_url}"
  !!(RestClient.get(inactive_healthcheck_url))
rescue
  false
end

#isDeployedAt(url) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/conan/application.rb', line 90

def isDeployedAt(url)
  # only deploy if an older version is found, or no app found
  res = false
  begin
    response = RestClient::Request.new(
      :method => :get,
      :url => url,
      :headers => {
        'accept' => :json,
        'content_type' => :json
      },
      :timeout => 5,
      :open_timeout => 5
    ).execute
    if (response.code == 200)
       = JSON.parse(response.to_str)
      puts ''
      puts "+- Currently at #{url}:"
      printM = ->(s) {
        puts " | #{s}: #{build_metadata[s]}"
      }
      printM.call 'Implementation-Title'
      printM.call 'Build-Version'
      printM.call 'Build-Url'
      printM.call 'Git-Commit'
      current_ver = ["Build-Version"]
    end
    #TODO make sure the artifact id matches too, currently finding  "Implementation-Title": "apollo" in build metadata
    if (compareVersion(@version, current_ver))
      puts "#{@artifact_id} #{@version} is newer than version found at #{url}: #{current_ver}"
    else
      puts "#{@artifact_id} #{@version} found at #{url}. (skipping deployment)"
      res = true
    end
  rescue => e
    puts "#{@artifact_id} not found at #{url}: #{e}"
  end
  res
end

#old_versionsObject



43
44
45
# File 'lib/conan/application.rb', line 43

def old_versions
  @old_apps ||= Stackato.find_old_versions(self)
end

#readArtifactMetadata(xml) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/conan/application.rb', line 67

def (xml)
   = xml
  begin
    doc = REXML::Document.new(xml)
  rescue Exception => e
    puts "Failed to parse meta-data: #{e}"
    puts "--------------------------------"
    puts xml
    puts "--------------------------------"
    raise "Unreadable artifact meta-data for #{self}"
  end

   = doc.elements['/artifact-resolution/data']
  @version = .elements['version'].text
  @sha1 = .elements['sha1'].text
  @extension = .elements['extension'].text
end

#stackato_base_nameObject



47
48
49
# File 'lib/conan/application.rb', line 47

def stackato_base_name
  "#{@id}-#{@environment}-#{@infra}"
end

#to_sObject



142
143
144
# File 'lib/conan/application.rb', line 142

def to_s
  "#{artifact_id}-#{version}.#{extension}"
end