Commit e0f4e9ee authored by Matija Čupić's avatar Matija Čupić

Rename Pipeline <-> Bridge relation

Renames the relation between the Pipeline and Bridge job to be more
descriptive of the intent.

This includes renaming the model relations, database columns as well as
service / worker class names.
parent 68a6f446
...@@ -511,10 +511,9 @@ ActiveRecord::Schema.define(version: 20190426180107) do ...@@ -511,10 +511,9 @@ ActiveRecord::Schema.define(version: 20190426180107) do
t.integer "failure_reason" t.integer "failure_reason"
t.datetime_with_timezone "scheduled_at" t.datetime_with_timezone "scheduled_at"
t.string "token_encrypted" t.string "token_encrypted"
t.integer "bridged_pipeline_id" t.integer "upstream_pipeline_id"
t.index ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree t.index ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
t.index ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree t.index ["auto_canceled_by_id"], name: "index_ci_builds_on_auto_canceled_by_id", using: :btree
t.index ["bridged_pipeline_id"], name: "index_ci_builds_on_bridged_pipeline_id", where: "(bridged_pipeline_id IS NOT NULL)", using: :btree
t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial", where: "(((type)::text = 'Ci::Build'::text) AND ((retried = false) OR (retried IS NULL)) AND ((name)::text = ANY (ARRAY[('sast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('sast:container'::character varying)::text, ('container_scanning'::character varying)::text, ('dast'::character varying)::text])))", using: :btree t.index ["commit_id", "artifacts_expire_at", "id"], name: "index_ci_builds_on_commit_id_and_artifacts_expireatandidpartial", where: "(((type)::text = 'Ci::Build'::text) AND ((retried = false) OR (retried IS NULL)) AND ((name)::text = ANY (ARRAY[('sast'::character varying)::text, ('dependency_scanning'::character varying)::text, ('sast:container'::character varying)::text, ('container_scanning'::character varying)::text, ('dast'::character varying)::text])))", using: :btree
t.index ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree t.index ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree
t.index ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree t.index ["commit_id", "status", "type"], name: "index_ci_builds_on_commit_id_and_status_and_type", using: :btree
...@@ -532,6 +531,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do ...@@ -532,6 +531,7 @@ ActiveRecord::Schema.define(version: 20190426180107) do
t.index ["token"], name: "index_ci_builds_on_token", unique: true, using: :btree t.index ["token"], name: "index_ci_builds_on_token", unique: true, using: :btree
t.index ["token_encrypted"], name: "index_ci_builds_on_token_encrypted", unique: true, where: "(token_encrypted IS NOT NULL)", using: :btree t.index ["token_encrypted"], name: "index_ci_builds_on_token_encrypted", unique: true, where: "(token_encrypted IS NOT NULL)", using: :btree
t.index ["updated_at"], name: "index_ci_builds_on_updated_at", using: :btree t.index ["updated_at"], name: "index_ci_builds_on_updated_at", using: :btree
t.index ["upstream_pipeline_id"], name: "index_ci_builds_on_upstream_pipeline_id", where: "(upstream_pipeline_id IS NOT NULL)", using: :btree
t.index ["user_id"], name: "index_ci_builds_on_user_id", using: :btree t.index ["user_id"], name: "index_ci_builds_on_user_id", using: :btree
end end
...@@ -3474,8 +3474,8 @@ ActiveRecord::Schema.define(version: 20190426180107) do ...@@ -3474,8 +3474,8 @@ ActiveRecord::Schema.define(version: 20190426180107) do
add_foreign_key "ci_build_trace_sections", "ci_builds", column: "build_id", name: "fk_4ebe41f502", on_delete: :cascade add_foreign_key "ci_build_trace_sections", "ci_builds", column: "build_id", name: "fk_4ebe41f502", on_delete: :cascade
add_foreign_key "ci_build_trace_sections", "projects", on_delete: :cascade add_foreign_key "ci_build_trace_sections", "projects", on_delete: :cascade
add_foreign_key "ci_builds", "ci_pipelines", column: "auto_canceled_by_id", name: "fk_a2141b1522", on_delete: :nullify add_foreign_key "ci_builds", "ci_pipelines", column: "auto_canceled_by_id", name: "fk_a2141b1522", on_delete: :nullify
add_foreign_key "ci_builds", "ci_pipelines", column: "bridged_pipeline_id", name: "fk_cb126494a2", on_delete: :cascade
add_foreign_key "ci_builds", "ci_pipelines", column: "commit_id", name: "fk_d3130c9a7f", on_delete: :cascade add_foreign_key "ci_builds", "ci_pipelines", column: "commit_id", name: "fk_d3130c9a7f", on_delete: :cascade
add_foreign_key "ci_builds", "ci_pipelines", column: "upstream_pipeline_id", name: "fk_87f4cefcda", on_delete: :cascade
add_foreign_key "ci_builds", "ci_stages", column: "stage_id", name: "fk_3a9eaa254d", on_delete: :cascade add_foreign_key "ci_builds", "ci_stages", column: "stage_id", name: "fk_3a9eaa254d", on_delete: :cascade
add_foreign_key "ci_builds", "projects", name: "fk_befce0568a", on_delete: :cascade add_foreign_key "ci_builds", "projects", name: "fk_befce0568a", on_delete: :cascade
add_foreign_key "ci_builds_metadata", "ci_builds", column: "build_id", on_delete: :cascade add_foreign_key "ci_builds_metadata", "ci_builds", column: "build_id", on_delete: :cascade
......
...@@ -13,8 +13,8 @@ module EE ...@@ -13,8 +13,8 @@ module EE
serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables
# rubocop:enable Cop/ActiveRecordSerialize # rubocop:enable Cop/ActiveRecordSerialize
belongs_to :source_pipeline, class_name: "::Ci::Pipeline", belongs_to :upstream_pipeline, class_name: "::Ci::Pipeline",
foreign_key: :bridged_pipeline_id foreign_key: :upstream_pipeline_id
has_many :sourced_pipelines, class_name: "::Ci::Sources::Pipeline", has_many :sourced_pipelines, class_name: "::Ci::Sources::Pipeline",
foreign_key: :source_job_id foreign_key: :source_job_id
......
...@@ -28,7 +28,7 @@ module EE ...@@ -28,7 +28,7 @@ module EE
has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id'
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id' has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
has_many :bridged_jobs, class_name: '::Ci::Bridge', foreign_key: :bridged_pipeline_id has_many :downstream_bridges, class_name: '::Ci::Bridge', foreign_key: :upstream_pipeline_id
# Legacy way to fetch security reports based on job name. This has been replaced by the reports feature. # Legacy way to fetch security reports based on job name. This has been replaced by the reports feature.
scope :with_legacy_security_reports, -> do scope :with_legacy_security_reports, -> do
...@@ -97,10 +97,10 @@ module EE ...@@ -97,10 +97,10 @@ module EE
end end
after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline| after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
next unless pipeline.bridged_jobs.any? next unless pipeline.downstream_bridges.any?
pipeline.run_after_commit do pipeline.run_after_commit do
::Ci::PipelineBridgeWorker.perform_async(pipeline.id) ::Ci::PipelineBridgeStatusWorker.perform_async(pipeline.id)
end end
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
class PipelineBridgeService < ::BaseService class PipelineBridgeStatusService < ::BaseService
def execute(pipeline) def execute(pipeline)
pipeline.bridged_jobs.each do |bridged_job| pipeline.downstream_bridges.each do |bridged_job|
process_bridged_job(pipeline.status, bridged_job) process_bridged_job(pipeline.status, bridged_job)
end end
end end
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
- pipeline_default:store_security_reports - pipeline_default:store_security_reports
- pipeline_default:ci_create_cross_project_pipeline - pipeline_default:ci_create_cross_project_pipeline
- pipeline_default:ci_pipeline_bridge - pipeline_default:ci_pipeline_bridge_status
- incident_management:incident_management_process_alert - incident_management:incident_management_process_alert
......
# frozen_string_literal: true # frozen_string_literal: true
module Ci module Ci
class PipelineBridgeWorker class PipelineBridgeStatusWorker
include ::ApplicationWorker include ::ApplicationWorker
include ::PipelineQueue include ::PipelineQueue
def perform(pipeline_id) def perform(pipeline_id)
::Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline| ::Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
::Ci::PipelineBridgeService ::Ci::PipelineBridgeStatusService
.new(pipeline.project, pipeline.user) .new(pipeline.project, pipeline.user)
.execute(pipeline) .execute(pipeline)
end end
......
...@@ -10,6 +10,6 @@ class AddBridgedPipelineIdToBridges < ActiveRecord::Migration[5.0] ...@@ -10,6 +10,6 @@ class AddBridgedPipelineIdToBridges < ActiveRecord::Migration[5.0]
DOWNTIME = false DOWNTIME = false
def change def change
add_column :ci_builds, :bridged_pipeline_id, :integer add_column :ci_builds, :upstream_pipeline_id, :integer
end end
end end
...@@ -12,12 +12,12 @@ class AddBridgedPipelineIdForeignKey < ActiveRecord::Migration[5.0] ...@@ -12,12 +12,12 @@ class AddBridgedPipelineIdForeignKey < ActiveRecord::Migration[5.0]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_concurrent_index :ci_builds, :bridged_pipeline_id, where: 'bridged_pipeline_id IS NOT NULL' add_concurrent_index :ci_builds, :upstream_pipeline_id, where: 'upstream_pipeline_id IS NOT NULL'
add_concurrent_foreign_key :ci_builds, :ci_pipelines, column: :bridged_pipeline_id add_concurrent_foreign_key :ci_builds, :ci_pipelines, column: :upstream_pipeline_id
end end
def down def down
remove_foreign_key :ci_builds, column: :bridged_pipeline_id remove_foreign_key :ci_builds, column: :upstream_pipeline_id
remove_concurrent_index :ci_builds, :bridged_pipeline_id remove_concurrent_index :ci_builds, :upstream_pipeline_id
end end
end end
...@@ -20,7 +20,7 @@ ci_pipelines: ...@@ -20,7 +20,7 @@ ci_pipelines:
- sourced_pipelines - sourced_pipelines
- triggered_by_pipeline - triggered_by_pipeline
- triggered_pipelines - triggered_pipelines
- bridged_jobs - downstream_bridges
- job_artifacts - job_artifacts
- vulnerabilities_occurrence_pipelines - vulnerabilities_occurrence_pipelines
- vulnerabilities - vulnerabilities
......
...@@ -7,4 +7,4 @@ ProjectTracingSetting: ...@@ -7,4 +7,4 @@ ProjectTracingSetting:
Note: Note:
- review_id - review_id
CommitStatus: CommitStatus:
- bridged_pipeline_id - upstream_pipeline_id
...@@ -14,8 +14,8 @@ describe Ci::Bridge do ...@@ -14,8 +14,8 @@ describe Ci::Bridge do
{ trigger: { project: 'my/project', branch: 'master' } } { trigger: { project: 'my/project', branch: 'master' } }
end end
it 'belongs to a source pipeline' do it 'belongs to an upstream pipeline' do
expect(bridge).to belong_to(:source_pipeline) expect(bridge).to belong_to(:upstream_pipeline)
end end
it 'has many sourced pipelines' do it 'has many sourced pipelines' do
......
...@@ -14,7 +14,7 @@ describe Ci::Pipeline do ...@@ -14,7 +14,7 @@ describe Ci::Pipeline do
it { is_expected.to have_many(:sourced_pipelines) } it { is_expected.to have_many(:sourced_pipelines) }
it { is_expected.to have_one(:triggered_by_pipeline) } it { is_expected.to have_one(:triggered_by_pipeline) }
it { is_expected.to have_many(:triggered_pipelines) } it { is_expected.to have_many(:triggered_pipelines) }
it { is_expected.to have_many(:bridged_jobs) } it { is_expected.to have_many(:downstream_bridges) }
it { is_expected.to have_many(:job_artifacts).through(:builds) } it { is_expected.to have_many(:job_artifacts).through(:builds) }
it { is_expected.to have_many(:vulnerabilities).through(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::Occurrence') } it { is_expected.to have_many(:vulnerabilities).through(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::Occurrence') }
it { is_expected.to have_many(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::OccurrencePipeline') } it { is_expected.to have_many(:vulnerabilities_occurrence_pipelines).class_name('Vulnerabilities::OccurrencePipeline') }
...@@ -443,12 +443,13 @@ describe Ci::Pipeline do ...@@ -443,12 +443,13 @@ describe Ci::Pipeline do
context 'when pipeline has bridged jobs' do context 'when pipeline has bridged jobs' do
before do before do
pipeline.bridged_jobs << create(:ci_bridge) pipeline.downstream_bridges << create(:ci_bridge)
end end
context "when transitioning to success" do context "when transitioning to success" do
it 'schedules the pipeline bridge worker' do it 'schedules the pipeline bridge worker' do
expect(::Ci::PipelineBridgeWorker).to receive(:perform_async).with(pipeline.id) expect(::Ci::PipelineBridgeStatusWorker).to receive(:perform_async).with(pipeline.id)
pipeline.succeed! pipeline.succeed!
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Ci::PipelineBridgeService do describe Ci::PipelineBridgeStatusService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) { create(:ci_pipeline, :success, project: project) } let(:pipeline) { create(:ci_pipeline, :success, project: project) }
...@@ -14,7 +14,7 @@ describe Ci::PipelineBridgeService do ...@@ -14,7 +14,7 @@ describe Ci::PipelineBridgeService do
let(:bridge) { create(:ci_bridge, status: :pending) } let(:bridge) { create(:ci_bridge, status: :pending) }
before do before do
pipeline.bridged_jobs << bridge pipeline.downstream_bridges << bridge
end end
it 'updates the bridge status with the pipeline status' do it 'updates the bridge status with the pipeline status' do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Ci::PipelineBridgeWorker do describe Ci::PipelineBridgeStatusWorker do
describe '#perform' do describe '#perform' do
subject { described_class.new.perform(pipeline_id) } subject { described_class.new.perform(pipeline_id) }
...@@ -13,7 +13,7 @@ describe Ci::PipelineBridgeWorker do ...@@ -13,7 +13,7 @@ describe Ci::PipelineBridgeWorker do
it 'calls the service' do it 'calls the service' do
service = double('bridge status service') service = double('bridge status service')
expect(Ci::PipelineBridgeService) expect(Ci::PipelineBridgeStatusService)
.to receive(:new) .to receive(:new)
.with(pipeline.project, pipeline.user) .with(pipeline.project, pipeline.user)
.and_return(service) .and_return(service)
...@@ -28,7 +28,7 @@ describe Ci::PipelineBridgeWorker do ...@@ -28,7 +28,7 @@ describe Ci::PipelineBridgeWorker do
let(:pipeline_id) { 1234 } let(:pipeline_id) { 1234 }
it 'does not call the service' do it 'does not call the service' do
expect(Ci::PipelineBridgeService) expect(Ci::PipelineBridgeStatusService)
.not_to receive(:new) .not_to receive(:new)
subject subject
......
...@@ -38,7 +38,7 @@ describe Ci::RetryBuildService do ...@@ -38,7 +38,7 @@ describe Ci::RetryBuildService do
runner_id tag_taggings taggings tags trigger_request_id runner_id tag_taggings taggings tags trigger_request_id
user_id auto_canceled_by_id retried failure_reason user_id auto_canceled_by_id retried failure_reason
sourced_pipelines artifacts_file_store artifacts_metadata_store sourced_pipelines artifacts_file_store artifacts_metadata_store
metadata runner_session trace_chunks bridged_pipeline_id].freeze metadata runner_session trace_chunks upstream_pipeline_id].freeze
shared_examples 'build duplication' do shared_examples 'build duplication' do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) } let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
......
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