Skip to content

Commit

Permalink
Merge pull request NessComputing#4 from stevenschlansker/nexus-fetcher
Browse files Browse the repository at this point in the history
Nexus fetcher
  • Loading branch information
hgschmie committed Sep 12, 2012
2 parents 2fa5875 + f2088dc commit 5f177ab
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/announcements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def announce(agent)
response.body
end
rescue Exception => e
@log.warn "Client side error: #{e}" if @log
@log.warn "Client side error for #{@uri.host}:#{@uri.port} is: #{e}" if @log
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def user
end

def announcement_url
@announcement_url ||= @config.announcement_url || @config_from_file['galaxy.console.announcement-url'] || "http://#{`hostname`.strip}"
@announcement_url ||= @config.announcement_url || @config_from_file['galaxy.console.announcement-url'] || "http://0.0.0.0"
end

def host
Expand Down
25 changes: 17 additions & 8 deletions lib/galaxy/fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'galaxy/temp'
require 'galaxy/host'
require 'json'
require 'open-uri'

module Galaxy
class Fetcher
Expand All @@ -11,20 +13,25 @@ def initialize base_url, http_user, http_password, log
def fetch build, build_uri=nil, extension="tar.gz"
core_url = build_uri || @base

if !build.group.nil?
group_path=build.group.gsub /\./, '/'
# Maven repo compatible
core_url = "#{core_url}/#{group_path}/#{build.artifact}/#{build.version}"
end
if core_url.start_with? "nexus:"
core_url.slice! "nexus:"
core_url = "#{core_url}/service/local/artifact/maven/redirect?r=public&g=#{build.group}&a=#{build.artifact}&v=#{build.version}&e=#{extension}"
else
if !build.group.nil?
group_path=build.group.gsub /\./, '/'
# Maven repo compatible
core_url = "#{core_url}/#{group_path}/#{build.artifact}/#{build.version}"
end

core_url="#{core_url}/#{build.artifact}-#{build.version}.#{extension}"
core_url="#{core_url}/#{build.artifact}-#{build.version}.#{extension}"
end

tmp = Galaxy::Temp.mk_auto_file "galaxy-download"

@log.info("Fetching #{core_url} into #{tmp}")
if core_url =~ /^https?:/
begin
curl_command = "curl -D - #{core_url} -o #{tmp} -s"
curl_command = "curl -L -D - \"#{core_url}\" -o #{tmp} -s"
if !@http_user.nil? && !@http_password.nil?
curl_command << " -u #{@http_user}:#{@http_password}"
end
Expand All @@ -34,7 +41,9 @@ def fetch build, build_uri=nil, extension="tar.gz"
rescue Galaxy::HostUtils::CommandFailedError => e
raise "Failed to download archive #{core_url}: #{e.message}"
end
status = output.first
# cURL prints out each status code as it gets it, so in the case of a 301 redirect
# we need to make sure to get the last one, which should still be 200.
status = output.select {|l| l.start_with? "HTTP" }.last
(protocol, response_code, response_message) = status.split
unless response_code == '200'
raise "Failed to download archive #{core_url}: #{status}"
Expand Down
1 change: 1 addition & 0 deletions test/property_data/service/local/artifact/maven/redirect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
somedata
6 changes: 6 additions & 0 deletions test/test_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ def test_http_group_fetch_not_found
@server.logger.level = Logger::WARN
end
end

def test_nexus_fetching
fetcher = Galaxy::Fetcher.new("nexus:http://localhost:7777", nil, nil, Logger.new("/dev/null"))
path = fetcher.fetch FetchObj.new "group", "artifact", "version"
assert File.exists?(path)
end
end

0 comments on commit 5f177ab

Please sign in to comment.