diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /app/models/bulk_imports | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r-- | app/models/bulk_imports/export.rb | 10 | ||||
-rw-r--r-- | app/models/bulk_imports/export_status.rb | 47 | ||||
-rw-r--r-- | app/models/bulk_imports/file_transfer/base_config.rb | 12 |
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..98804d18f27 --- /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 |