Commit cc2fd3c7 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Use `Replication` namespace on downloaders, transfers and uploaders

Git doesn't track file moves correctly so we have to split the operation
 in two different commits.
parent 79a1bdec
......@@ -33,9 +33,9 @@ module Geo
private
def downloader_klass
return Gitlab::Geo::FileDownloader if user_upload?
return Gitlab::Geo::JobArtifactDownloader if job_artifact?
return Gitlab::Geo::LfsDownloader if lfs?
return Gitlab::Geo::Replication::FileDownloader if user_upload?
return Gitlab::Geo::Replication::JobArtifactDownloader if job_artifact?
return Gitlab::Geo::Replication::LfsDownloader if lfs?
error_message = "Cannot find a Gitlab::Geo Downloader for object_type = '#{object_type}'"
......
......@@ -20,6 +20,10 @@ module Geo
uploader.execute
end
def uploader
uploader_klass.new(object_db_id, decoded_authorization)
end
private
def jwt_scope_valid?
......@@ -32,14 +36,10 @@ module Geo
end
end
def uploader
uploader_klass.new(object_db_id, decoded_authorization)
end
def uploader_klass
return Gitlab::Geo::FileUploader if user_upload?
return Gitlab::Geo::JobArtifactUploader if job_artifact?
return Gitlab::Geo::LfsUploader if lfs?
return Gitlab::Geo::Replication::FileUploader if user_upload?
return Gitlab::Geo::Replication::JobArtifactUploader if job_artifact?
return Gitlab::Geo::Replication::LfsUploader if lfs?
error_message = "Cannot find a Gitlab::Geo Uploader for object_type = '#{object_type}'"
......
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding an Upload record
# * Requesting and downloading the Upload's file from the primary
......@@ -61,4 +62,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Requesting an Upload file from the primary
# * Saving it in the right place on successful download
......@@ -32,4 +33,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding an Upload record
# * Returning the necessary response data to send the file back
......@@ -69,4 +70,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding a ::Ci::JobArtifact record
# * Requesting and downloading the JobArtifact's file from the primary
......@@ -14,10 +15,11 @@ module Gitlab
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
return fail_before_transfer unless job_artifact.present?
transfer = ::Gitlab::Geo::JobArtifactTransfer.new(job_artifact)
transfer = ::Gitlab::Geo::Replication::JobArtifactTransfer.new(job_artifact)
Result.from_transfer_result(transfer.download_from_primary)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Requesting an ::Ci::JobArtifact file from the primary
# * Saving it in the right place on successful download
......@@ -28,4 +29,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding an ::Ci::JobArtifact record
# * Returning the necessary response data to send the file back
......@@ -27,4 +28,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding a LfsObject record
# * Requesting and downloading the LfsObject's file from the primary
......@@ -20,4 +21,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Requesting an LfsObject file from the primary
# * Saving it in the right place on successful download
......@@ -28,4 +29,5 @@ module Gitlab
end
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
# This class is responsible for:
# * Finding an LfsObject record
# * Returning the necessary response data to send the file back
......@@ -26,4 +27,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Geo
module Replication
class Transfer
include LogHelpers
......@@ -162,4 +163,5 @@ module Gitlab
end
end
end
end
end
......@@ -9,7 +9,7 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do
downloader = described_class.new(:job_artifact, job_artifact.id)
result = Gitlab::Geo::Replication::Transfer::Result.new(success: true, bytes_downloaded: 1)
allow_any_instance_of(Gitlab::Geo::JobArtifactTransfer)
allow_any_instance_of(Gitlab::Geo::Replication::JobArtifactTransfer)
.to receive(:download_from_primary).and_return(result)
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
......
require 'spec_helper'
describe Gitlab::Geo::JobArtifactTransfer, :geo do
describe Gitlab::Geo::Replication::JobArtifactTransfer, :geo do
include ::EE::GeoHelpers
set(:primary_node) { create(:geo_node, :primary) }
......
......@@ -435,7 +435,7 @@ describe Geo::FileDownloadService do
context 'bad object type' do
it 'raises an error' do
expect { described_class.new(:bad, 1).execute }.to raise_error(NameError)
expect { described_class.new(:bad, 1).execute }.to raise_error(NotImplementedError)
end
end
end
......@@ -445,7 +445,7 @@ describe Geo::FileDownloadService do
bytes_downloaded: bytes_downloaded,
success: success,
primary_missing_file: primary_missing_file)
instance = double("(instance of Gitlab::Geo::Transfer)", download_from_primary: result)
instance = double("(instance of Gitlab::Geo::Replication::Transfer)", download_from_primary: result)
allow(Gitlab::Geo::Replication::Transfer).to receive(:new).and_return(instance)
end
end
......@@ -200,7 +200,7 @@ describe Geo::FileUploadService do
context 'job artifact' do
let(:job_artifact) { create(:ci_job_artifact, :with_file) }
let(:params) { { id: job_artifact.id, type: 'job_artifact' } }
let(:request_data) { Gitlab::Geo::JobArtifactTransfer.new(job_artifact).request_data }
let(:request_data) { Gitlab::Geo::Replication::JobArtifactTransfer.new(job_artifact).request_data }
it 'sends job artifact file' do
service = described_class.new(params, req_header)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment