diff options
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r-- | app/models/bulk_imports/entity.rb | 30 | ||||
-rw-r--r-- | app/models/bulk_imports/file_transfer/base_config.rb | 23 | ||||
-rw-r--r-- | app/models/bulk_imports/file_transfer/project_config.rb | 6 | ||||
-rw-r--r-- | app/models/bulk_imports/tracker.rb | 13 |
4 files changed, 54 insertions, 18 deletions
diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb index 2368be6196c..38b7da76306 100644 --- a/app/models/bulk_imports/entity.rb +++ b/app/models/bulk_imports/entity.rb @@ -20,8 +20,6 @@ class BulkImports::Entity < ApplicationRecord self.table_name = 'bulk_import_entities' - EXPORT_RELATIONS_URL = '/%{resource}/%{full_path}/export_relations' - belongs_to :bulk_import, optional: false belongs_to :parent, class_name: 'BulkImports::Entity', optional: true @@ -104,18 +102,42 @@ class BulkImports::Entity < ApplicationRecord end end + def entity_type + source_type.gsub('_entity', '') + end + def pluralized_name - source_type.gsub('_entity', '').pluralize + entity_type.pluralize + end + + def base_resource_url_path + "/#{pluralized_name}/#{encoded_source_full_path}" end def export_relations_url_path - @export_relations_url_path ||= EXPORT_RELATIONS_URL % { resource: pluralized_name, full_path: encoded_source_full_path } + "#{base_resource_url_path}/export_relations" end def relation_download_url_path(relation) "#{export_relations_url_path}/download?relation=#{relation}" end + def wikis_url_path + "#{base_resource_url_path}/wikis" + end + + def project? + source_type == 'project_entity' + end + + def group? + source_type == 'group_entity' + end + + def update_service + "::#{pluralized_name.capitalize}::UpdateService".constantize + end + private def validate_parent_is_a_group diff --git a/app/models/bulk_imports/file_transfer/base_config.rb b/app/models/bulk_imports/file_transfer/base_config.rb index 4d370315ad5..036d511bc59 100644 --- a/app/models/bulk_imports/file_transfer/base_config.rb +++ b/app/models/bulk_imports/file_transfer/base_config.rb @@ -5,6 +5,9 @@ module BulkImports class BaseConfig include Gitlab::Utils::StrongMemoize + UPLOADS_RELATION = 'uploads' + SELF_RELATION = 'self' + def initialize(portable) @portable = portable end @@ -26,7 +29,11 @@ module BulkImports end def portable_relations - tree_relations + file_relations - skipped_relations + tree_relations + file_relations + self_relation - skipped_relations + end + + def self_relation?(relation) + relation == SELF_RELATION end def tree_relation?(relation) @@ -43,6 +50,10 @@ module BulkImports portable_tree[:include].find { |include| include[relation.to_sym] } end + def portable_relations_tree + @portable_relations_tree ||= attributes_finder.find_relations_tree(portable_class_sym).deep_stringify_keys + end + private attr_reader :portable @@ -65,10 +76,6 @@ 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 @@ -78,12 +85,16 @@ module BulkImports end def file_relations - [] + [UPLOADS_RELATION] end def skipped_relations [] end + + def self_relation + [SELF_RELATION] + end end end end diff --git a/app/models/bulk_imports/file_transfer/project_config.rb b/app/models/bulk_imports/file_transfer/project_config.rb index 9a0434da08a..fdfb0dd0186 100644 --- a/app/models/bulk_imports/file_transfer/project_config.rb +++ b/app/models/bulk_imports/file_transfer/project_config.rb @@ -3,8 +3,6 @@ module BulkImports module FileTransfer class ProjectConfig < BaseConfig - UPLOADS_RELATION = 'uploads' - SKIPPED_RELATIONS = %w( project_members group_members @@ -14,10 +12,6 @@ module BulkImports ::Gitlab::ImportExport.config_file end - def file_relations - [UPLOADS_RELATION] - end - def skipped_relations SKIPPED_RELATIONS end diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb index 9de3239ee0f..cfe33c013ba 100644 --- a/app/models/bulk_imports/tracker.rb +++ b/app/models/bulk_imports/tracker.rb @@ -29,7 +29,7 @@ class BulkImports::Tracker < ApplicationRecord def self.stage_running?(entity_id, stage) where(stage: stage, bulk_import_entity_id: entity_id) - .with_status(:created, :started) + .with_status(:created, :enqueued, :started) .exists? end @@ -45,15 +45,24 @@ class BulkImports::Tracker < ApplicationRecord state :created, value: 0 state :started, value: 1 state :finished, value: 2 + state :enqueued, value: 3 state :failed, value: -1 state :skipped, value: -2 event :start do - transition created: :started + transition enqueued: :started # To avoid errors when re-starting a pipeline in case of network errors transition started: :started end + event :retry do + transition started: :enqueued + end + + event :enqueue do + transition created: :enqueued + end + event :finish do transition started: :finished transition failed: :failed |