Commit 7add0464 authored by Fabio Pitino's avatar Fabio Pitino Committed by Shinya Maeda

Port Ci::Bridge to Core

Move most of the model and specs
parent dd5500f1
...@@ -25,6 +25,14 @@ module Ci ...@@ -25,6 +25,14 @@ module Ci
# rubocop:enable Cop/ActiveRecordSerialize # rubocop:enable Cop/ActiveRecordSerialize
state_machine :status do state_machine :status do
after_transition created: :pending do |bridge|
next unless bridge.downstream_project
bridge.run_after_commit do
bridge.schedule_downstream_pipeline!
end
end
event :manual do event :manual do
transition all => :manual transition all => :manual
end end
...@@ -38,6 +46,12 @@ module Ci ...@@ -38,6 +46,12 @@ module Ci
raise NotImplementedError raise NotImplementedError
end end
def schedule_downstream_pipeline!
raise InvalidBridgeTypeError unless downstream_project
::Ci::CreateCrossProjectPipelineWorker.perform_async(self.id)
end
def inherit_status_from_downstream!(pipeline) def inherit_status_from_downstream!(pipeline)
case pipeline.status case pipeline.status
when 'success' when 'success'
......
...@@ -17,7 +17,12 @@ module CommitStatusEnums ...@@ -17,7 +17,12 @@ module CommitStatusEnums
archived_failure: 9, archived_failure: 9,
unmet_prerequisites: 10, unmet_prerequisites: 10,
scheduler_failure: 11, scheduler_failure: 11,
data_integrity_failure: 12 data_integrity_failure: 12,
insufficient_bridge_permissions: 1_001,
downstream_bridge_project_not_found: 1_002,
invalid_bridge_trigger: 1_003,
bridge_pipeline_is_child_pipeline: 1_006,
downstream_pipeline_creation_failed: 1_007
} }
end end
end end
......
...@@ -13,7 +13,12 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated ...@@ -13,7 +13,12 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
archived_failure: 'The job is archived and cannot be run', archived_failure: 'The job is archived and cannot be run',
unmet_prerequisites: 'The job failed to complete prerequisite tasks', unmet_prerequisites: 'The job failed to complete prerequisite tasks',
scheduler_failure: 'The scheduler failed to assign job to the runner, please try again or contact system administrator', scheduler_failure: 'The scheduler failed to assign job to the runner, please try again or contact system administrator',
data_integrity_failure: 'There has been a structural integrity problem detected, please contact system administrator' data_integrity_failure: 'There has been a structural integrity problem detected, please contact system administrator',
invalid_bridge_trigger: 'This job could not be executed because downstream pipeline trigger definition is invalid',
downstream_bridge_project_not_found: 'This job could not be executed because downstream bridge project could not be found',
insufficient_bridge_permissions: 'This job could not be executed because of insufficient permissions to create a downstream pipeline',
bridge_pipeline_is_child_pipeline: 'This job belongs to a child pipeline and cannot create further child pipelines',
downstream_pipeline_creation_failed: 'The downstream pipeline could not be created'
}.freeze }.freeze
private_constant :CALLOUT_FAILURE_MESSAGES private_constant :CALLOUT_FAILURE_MESSAGES
......
...@@ -531,6 +531,12 @@ ...@@ -531,6 +531,12 @@
:latency_sensitive: :latency_sensitive:
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 3 :weight: 3
- :name: pipeline_default:ci_create_cross_project_pipeline
:feature_category: :continuous_integration
:has_external_dependencies:
:latency_sensitive:
:resource_boundary: :cpu
:weight: 3
- :name: pipeline_default:ci_pipeline_bridge_status - :name: pipeline_default:ci_pipeline_bridge_status
:feature_category: :continuous_integration :feature_category: :continuous_integration
:has_external_dependencies: :has_external_dependencies:
......
...@@ -9,14 +9,6 @@ module EE ...@@ -9,14 +9,6 @@ module EE
belongs_to :upstream_pipeline, class_name: "::Ci::Pipeline" belongs_to :upstream_pipeline, class_name: "::Ci::Pipeline"
state_machine :status do state_machine :status do
after_transition created: :pending do |bridge|
next unless bridge.downstream_project
bridge.run_after_commit do
bridge.schedule_downstream_pipeline!
end
end
after_transition any => :pending do |bridge| after_transition any => :pending do |bridge|
next unless bridge.upstream_project next unless bridge.upstream_project
...@@ -27,12 +19,6 @@ module EE ...@@ -27,12 +19,6 @@ module EE
end end
end end
def schedule_downstream_pipeline!
raise InvalidBridgeTypeError unless downstream_project
::Ci::CreateCrossProjectPipelineWorker.perform_async(self.id)
end
def subscribe_to_upstream! def subscribe_to_upstream!
raise InvalidBridgeTypeError unless upstream_project raise InvalidBridgeTypeError unless upstream_project
......
...@@ -10,13 +10,8 @@ module EE ...@@ -10,13 +10,8 @@ module EE
override :failure_reasons override :failure_reasons
def failure_reasons def failure_reasons
super.merge(protected_environment_failure: 1_000, super.merge(protected_environment_failure: 1_000,
insufficient_bridge_permissions: 1_001,
downstream_bridge_project_not_found: 1_002,
invalid_bridge_trigger: 1_003,
upstream_bridge_project_not_found: 1_004, upstream_bridge_project_not_found: 1_004,
insufficient_upstream_permissions: 1_005, insufficient_upstream_permissions: 1_005)
bridge_pipeline_is_child_pipeline: 1_006,
downstream_pipeline_creation_failed: 1_007)
end end
end end
end end
......
...@@ -6,13 +6,8 @@ module EE ...@@ -6,13 +6,8 @@ module EE
prepended do prepended do
EE_CALLOUT_FAILURE_MESSAGES = const_get(:CALLOUT_FAILURE_MESSAGES, false).merge( EE_CALLOUT_FAILURE_MESSAGES = const_get(:CALLOUT_FAILURE_MESSAGES, false).merge(
protected_environment_failure: 'The environment this job is deploying to is protected. Only users with permission may successfully run this job.', protected_environment_failure: 'The environment this job is deploying to is protected. Only users with permission may successfully run this job.',
insufficient_bridge_permissions: 'This job could not be executed because of insufficient permissions to create a downstream pipeline.',
insufficient_upstream_permissions: 'This job could not be executed because of insufficient permissions to track the upstream project.', insufficient_upstream_permissions: 'This job could not be executed because of insufficient permissions to track the upstream project.',
downstream_bridge_project_not_found: 'This job could not be executed because downstream bridge project could not be found.', upstream_bridge_project_not_found: 'This job could not be executed because upstream bridge project could not be found.'
upstream_bridge_project_not_found: 'This job could not be executed because upstream bridge project could not be found.',
invalid_bridge_trigger: 'This job could not be executed because downstream pipeline trigger definition is invalid.',
bridge_pipeline_is_child_pipeline: 'This job belongs to a child pipeline and cannot create further child pipelines.',
downstream_pipeline_creation_failed: 'The downstream pipeline could not be created.'
).freeze ).freeze
EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES
......
...@@ -339,12 +339,6 @@ ...@@ -339,12 +339,6 @@
:latency_sensitive: :latency_sensitive:
:resource_boundary: :unknown :resource_boundary: :unknown
:weight: 1 :weight: 1
- :name: pipeline_default:ci_create_cross_project_pipeline
:feature_category: :continuous_integration
:has_external_dependencies:
:latency_sensitive:
:resource_boundary: :cpu
:weight: 3
- :name: pipeline_default:store_security_reports - :name: pipeline_default:store_security_reports
:feature_category: :continuous_integration :feature_category: :continuous_integration
:has_external_dependencies: :has_external_dependencies:
......
...@@ -11,13 +11,8 @@ module EE ...@@ -11,13 +11,8 @@ module EE
prepended do prepended do
EE_REASONS = const_get(:REASONS, false).merge( EE_REASONS = const_get(:REASONS, false).merge(
protected_environment_failure: 'protected environment failure', protected_environment_failure: 'protected environment failure',
invalid_bridge_trigger: 'downstream pipeline trigger definition is invalid',
downstream_bridge_project_not_found: 'downstream project could not be found',
upstream_bridge_project_not_found: 'upstream project could not be found', upstream_bridge_project_not_found: 'upstream project could not be found',
insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline', insufficient_upstream_permissions: 'no permissions to read upstream project'
insufficient_upstream_permissions: 'no permissions to read upstream project',
bridge_pipeline_is_child_pipeline: 'creation of child pipeline not allowed from another child pipeline',
downstream_pipeline_creation_failed: 'downstream pipeline can not be created'
).freeze ).freeze
EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS
end end
......
...@@ -18,7 +18,12 @@ module Gitlab ...@@ -18,7 +18,12 @@ module Gitlab
archived_failure: 'archived failure', archived_failure: 'archived failure',
unmet_prerequisites: 'unmet prerequisites', unmet_prerequisites: 'unmet prerequisites',
scheduler_failure: 'scheduler failure', scheduler_failure: 'scheduler failure',
data_integrity_failure: 'data integrity failure' data_integrity_failure: 'data integrity failure',
invalid_bridge_trigger: 'downstream pipeline trigger definition is invalid',
downstream_bridge_project_not_found: 'downstream project could not be found',
insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline',
bridge_pipeline_is_child_pipeline: 'creation of child pipeline not allowed from another child pipeline',
downstream_pipeline_creation_failed: 'downstream pipeline can not be created'
}.freeze }.freeze
private_constant :REASONS private_constant :REASONS
......
...@@ -53,6 +53,16 @@ describe Ci::Bridge do ...@@ -53,6 +53,16 @@ describe Ci::Bridge do
end end
end end
describe 'state machine transitions' do
context 'when bridge points towards downstream' do
it 'schedules downstream pipeline creation' do
expect(bridge).to receive(:schedule_downstream_pipeline!)
bridge.enqueue!
end
end
end
describe '#inherit_status_from_downstream!' do describe '#inherit_status_from_downstream!' do
let(:downstream_pipeline) { build(:ci_pipeline, status: downstream_status) } let(:downstream_pipeline) { build(:ci_pipeline, status: downstream_status) }
......
...@@ -342,7 +342,9 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -342,7 +342,9 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
let(:service) { described_class.new(upstream_project, upstream_project.owner) } let(:service) { described_class.new(upstream_project, upstream_project.owner) }
context 'that include the bridge job' do context 'that include the bridge job' do
it 'creates the downstream pipeline' do # TODO: this is skipped because `trigger` keyword does not exist yet.
# enabling it in the next MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24393
xit 'creates the downstream pipeline' do
expect { service.execute(bridge) } expect { service.execute(bridge) }
.to change(downstream_project.ci_pipelines, :count).by(1) .to change(downstream_project.ci_pipelines, :count).by(1)
end end
......
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