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 ...@@ -33,9 +33,9 @@ module Geo
private private
def downloader_klass def downloader_klass
return Gitlab::Geo::FileDownloader if user_upload? return Gitlab::Geo::Replication::FileDownloader if user_upload?
return Gitlab::Geo::JobArtifactDownloader if job_artifact? return Gitlab::Geo::Replication::JobArtifactDownloader if job_artifact?
return Gitlab::Geo::LfsDownloader if lfs? return Gitlab::Geo::Replication::LfsDownloader if lfs?
error_message = "Cannot find a Gitlab::Geo Downloader for object_type = '#{object_type}'" error_message = "Cannot find a Gitlab::Geo Downloader for object_type = '#{object_type}'"
......
...@@ -20,6 +20,10 @@ module Geo ...@@ -20,6 +20,10 @@ module Geo
uploader.execute uploader.execute
end end
def uploader
uploader_klass.new(object_db_id, decoded_authorization)
end
private private
def jwt_scope_valid? def jwt_scope_valid?
...@@ -32,14 +36,10 @@ module Geo ...@@ -32,14 +36,10 @@ module Geo
end end
end end
def uploader
uploader_klass.new(object_db_id, decoded_authorization)
end
def uploader_klass def uploader_klass
return Gitlab::Geo::FileUploader if user_upload? return Gitlab::Geo::Replication::FileUploader if user_upload?
return Gitlab::Geo::JobArtifactUploader if job_artifact? return Gitlab::Geo::Replication::JobArtifactUploader if job_artifact?
return Gitlab::Geo::LfsUploader if lfs? return Gitlab::Geo::Replication::LfsUploader if lfs?
error_message = "Cannot find a Gitlab::Geo Uploader for object_type = '#{object_type}'" error_message = "Cannot find a Gitlab::Geo Uploader for object_type = '#{object_type}'"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding an Upload record # * Finding an Upload record
# * Requesting and downloading the Upload's file from the primary # * Requesting and downloading the Upload's file from the primary
...@@ -61,4 +62,5 @@ module Gitlab ...@@ -61,4 +62,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Requesting an Upload file from the primary # * Requesting an Upload file from the primary
# * Saving it in the right place on successful download # * Saving it in the right place on successful download
...@@ -32,4 +33,5 @@ module Gitlab ...@@ -32,4 +33,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding an Upload record # * Finding an Upload record
# * Returning the necessary response data to send the file back # * Returning the necessary response data to send the file back
...@@ -69,4 +70,5 @@ module Gitlab ...@@ -69,4 +70,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding a ::Ci::JobArtifact record # * Finding a ::Ci::JobArtifact record
# * Requesting and downloading the JobArtifact's file from the primary # * Requesting and downloading the JobArtifact's file from the primary
...@@ -14,10 +15,11 @@ module Gitlab ...@@ -14,10 +15,11 @@ module Gitlab
job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id) job_artifact = ::Ci::JobArtifact.find_by(id: object_db_id)
return fail_before_transfer unless job_artifact.present? 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) Result.from_transfer_result(transfer.download_from_primary)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Requesting an ::Ci::JobArtifact file from the primary # * Requesting an ::Ci::JobArtifact file from the primary
# * Saving it in the right place on successful download # * Saving it in the right place on successful download
...@@ -28,4 +29,5 @@ module Gitlab ...@@ -28,4 +29,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding an ::Ci::JobArtifact record # * Finding an ::Ci::JobArtifact record
# * Returning the necessary response data to send the file back # * Returning the necessary response data to send the file back
...@@ -27,4 +28,5 @@ module Gitlab ...@@ -27,4 +28,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding a LfsObject record # * Finding a LfsObject record
# * Requesting and downloading the LfsObject's file from the primary # * Requesting and downloading the LfsObject's file from the primary
...@@ -20,4 +21,5 @@ module Gitlab ...@@ -20,4 +21,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Requesting an LfsObject file from the primary # * Requesting an LfsObject file from the primary
# * Saving it in the right place on successful download # * Saving it in the right place on successful download
...@@ -28,4 +29,5 @@ module Gitlab ...@@ -28,4 +29,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
# This class is responsible for: # This class is responsible for:
# * Finding an LfsObject record # * Finding an LfsObject record
# * Returning the necessary response data to send the file back # * Returning the necessary response data to send the file back
...@@ -26,4 +27,5 @@ module Gitlab ...@@ -26,4 +27,5 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
end end
end end
end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication
class Transfer class Transfer
include LogHelpers include LogHelpers
...@@ -162,4 +163,5 @@ module Gitlab ...@@ -162,4 +163,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -9,7 +9,7 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do ...@@ -9,7 +9,7 @@ describe Gitlab::Geo::Replication::JobArtifactDownloader, :geo do
downloader = described_class.new(:job_artifact, job_artifact.id) downloader = described_class.new(:job_artifact, job_artifact.id)
result = Gitlab::Geo::Replication::Transfer::Result.new(success: true, bytes_downloaded: 1) 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) .to receive(:download_from_primary).and_return(result)
expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result) expect(downloader.execute).to be_a(Gitlab::Geo::Replication::FileDownloader::Result)
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Geo::JobArtifactTransfer, :geo do describe Gitlab::Geo::Replication::JobArtifactTransfer, :geo do
include ::EE::GeoHelpers include ::EE::GeoHelpers
set(:primary_node) { create(:geo_node, :primary) } set(:primary_node) { create(:geo_node, :primary) }
......
...@@ -435,7 +435,7 @@ describe Geo::FileDownloadService do ...@@ -435,7 +435,7 @@ describe Geo::FileDownloadService do
context 'bad object type' do context 'bad object type' do
it 'raises an error' 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 end
end end
...@@ -445,7 +445,7 @@ describe Geo::FileDownloadService do ...@@ -445,7 +445,7 @@ describe Geo::FileDownloadService do
bytes_downloaded: bytes_downloaded, bytes_downloaded: bytes_downloaded,
success: success, success: success,
primary_missing_file: primary_missing_file) 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) allow(Gitlab::Geo::Replication::Transfer).to receive(:new).and_return(instance)
end end
end end
...@@ -200,7 +200,7 @@ describe Geo::FileUploadService do ...@@ -200,7 +200,7 @@ describe Geo::FileUploadService do
context 'job artifact' do context 'job artifact' do
let(:job_artifact) { create(:ci_job_artifact, :with_file) } let(:job_artifact) { create(:ci_job_artifact, :with_file) }
let(:params) { { id: job_artifact.id, type: 'job_artifact' } } 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 it 'sends job artifact file' do
service = described_class.new(params, req_header) 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