Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/bulk_imports/export.rb10
-rw-r--r--app/models/bulk_imports/export_status.rb47
-rw-r--r--app/models/bulk_imports/file_transfer/base_config.rb12
3 files changed, 66 insertions, 3 deletions
diff --git a/app/models/bulk_imports/export.rb b/app/models/bulk_imports/export.rb
index 59ca4dbfec6..371b58dea03 100644
--- a/app/models/bulk_imports/export.rb
+++ b/app/models/bulk_imports/export.rb
@@ -4,6 +4,10 @@ module BulkImports
class Export < ApplicationRecord
include Gitlab::Utils::StrongMemoize
+ STARTED = 0
+ FINISHED = 1
+ FAILED = -1
+
self.table_name = 'bulk_import_exports'
belongs_to :project, optional: true
@@ -18,9 +22,9 @@ module BulkImports
validate :portable_relation?
state_machine :status, initial: :started do
- state :started, value: 0
- state :finished, value: 1
- state :failed, value: -1
+ state :started, value: STARTED
+ state :finished, value: FINISHED
+ state :failed, value: FAILED
event :start do
transition any => :started
diff --git a/app/models/bulk_imports/export_status.rb b/app/models/bulk_imports/export_status.rb
new file mode 100644
index 00000000000..72ece4e8fc0
--- /dev/null
+++ b/app/models/bulk_imports/export_status.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+module BulkImports
+ class ExportStatus
+ include Gitlab::Utils::StrongMemoize
+
+ def initialize(pipeline_tracker, relation)
+ @pipeline_tracker = pipeline_tracker
+ @relation = relation
+ @entity = @pipeline_tracker.entity
+ @configuration = @entity.bulk_import.configuration
+ @client = Clients::Http.new(uri: @configuration.url, token: @configuration.access_token)
+ end
+
+ def started?
+ export_status['status'] == Export::STARTED
+ end
+
+ def failed?
+ export_status['status'] == Export::FAILED
+ end
+
+ def error
+ export_status['error']
+ end
+
+ private
+
+ attr_reader :client, :entity, :relation
+
+ def export_status
+ strong_memoize(:export_status) do
+ fetch_export_status.find { |item| item['relation'] == relation }
+ end
+ rescue StandardError => e
+ { 'status' => Export::FAILED, 'error' => e.message }
+ end
+
+ def fetch_export_status
+ client.get(status_endpoint).parsed_response
+ end
+
+ def status_endpoint
+ "/groups/#{entity.encoded_source_full_path}/export_relations/status"
+ end
+ end
+end
diff --git a/app/models/bulk_imports/file_transfer/base_config.rb b/app/models/bulk_imports/file_transfer/base_config.rb
index bb04e84ad72..7396f9d3655 100644
--- a/app/models/bulk_imports/file_transfer/base_config.rb
+++ b/app/models/bulk_imports/file_transfer/base_config.rb
@@ -13,6 +13,14 @@ module BulkImports
attributes_finder.find_root(portable_class_sym)
end
+ def top_relation_tree(relation)
+ portable_relations_tree[relation.to_s]
+ end
+
+ def relation_excluded_keys(relation)
+ attributes_finder.find_excluded_keys(relation)
+ end
+
def export_path
strong_memoize(:export_path) do
relative_path = File.join(base_export_path, SecureRandom.hex)
@@ -47,6 +55,10 @@ module BulkImports
@portable_class_sym ||= portable_class.to_s.demodulize.underscore.to_sym
end
+ def portable_relations_tree
+ @portable_relations_tree ||= attributes_finder.find_relations_tree(portable_class_sym).deep_stringify_keys
+ end
+
def import_export_yaml
raise NotImplementedError
end