Skip to content

Commit 96deec5

Browse files
committed
Add primary runtime conflicts
1 parent 6ef3ab4 commit 96deec5

File tree

15 files changed

+197
-5
lines changed

15 files changed

+197
-5
lines changed

app/grpc/flow_handler.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ class FlowHandler < Tucana::Sagittarius::FlowService::Service
99

1010
def self.update_runtime(runtime)
1111
flows = []
12-
runtime.projects.each do |project|
13-
project.flows.each do |flow|
12+
runtime.project_assignments.compatible.each do |assignment|
13+
assignment.project.flows.each do |flow|
1414
flows << flow.to_grpc
1515
end
1616
end
1717

18-
# TODO: Add check to check for primary runtime conflicts
19-
2018
send_update(
2119
Tucana::Sagittarius::FlowResponse.new(
2220
flows: Tucana::Shared::Flows.new(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
class UpdateRuntimeCompatibilityJob < ApplicationJob
4+
def perform(conditions)
5+
assignments = NamespaceProjectRuntimeAssignment.where(conditions)
6+
7+
assignments.each do |assignment|
8+
res = Runtimes::CheckRuntimeCompatibilityService.new(assignment.runtime, assignment.namespace_project).execute
9+
10+
assignment.compatible = res.success?
11+
assignment.save!
12+
end
13+
end
14+
end

app/models/namespace_project_runtime_assignment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class NamespaceProjectRuntimeAssignment < ApplicationRecord
99
validate :validate_namespaces, if: :runtime_changed?
1010
validate :validate_namespaces, if: :namespace_project_changed?
1111

12+
scope :compatible, -> { where(compatible: true) }
13+
1214
private
1315

1416
def validate_namespaces

app/services/error_code.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def self.error_codes
4040
primary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
4141
secondary_level_not_found: { description: '', deprecation_reason: 'Outdated concept' },
4242
tertiary_level_exceeds_parameters: { description: '', deprecation_reason: 'Outdated concept' },
43+
44+
missing_primary_runtime: { description: 'The project is missing a primary runtime' },
45+
missing_definition: { description: 'The primary runtime has more definitions than this one' },
46+
outdated_definition: { description: 'The primary runtime has a newer definition than this one' },
4347
}
4448
end
4549
end

app/services/namespaces/projects/assign_runtimes_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def execute
3131
)
3232
end
3333

34+
UpdateRuntimeCompatibilityJob.perform_later(namespace_project_id: namespace_project.id)
35+
3436
AuditService.audit(
3537
:project_runtimes_assigned,
3638
author_id: current_authentication.user.id,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
module Runtimes
4+
class CheckRuntimeCompatibilityService
5+
attr_reader :runtime, :namespace_project
6+
7+
def initialize(runtime, namespace_project)
8+
@runtime = runtime
9+
@namespace_project = namespace_project
10+
end
11+
12+
def execute
13+
primary_runtime = namespace_project.primary_runtime
14+
15+
if primary_runtime.nil?
16+
return ServiceResponse.error(message: 'No primary runtime given',
17+
payload: :missing_primary_runtime)
18+
end
19+
20+
{ DataType => :identifier, FlowType => :identifier,
21+
RuntimeFunctionDefinition => :runtime_name }.each do |model, identifier_field|
22+
res = check_versions(model, identifier_field)
23+
return res if res.error?
24+
end
25+
ServiceResponse.success(message: 'Runtime is compatible', payload: runtime)
26+
end
27+
28+
def check_versions(model, identifier_field = :identifier)
29+
to_check_types = model.where(runtime: runtime)
30+
primary_types = model.where(runtime: namespace_project.primary_runtime)
31+
32+
if to_check_types.size < primary_types.size
33+
return ServiceResponse.error(message: "#{model} amount dont match",
34+
payload: :missing_definition)
35+
end
36+
37+
primary_types.each do |curr_type|
38+
to_check = model.find_by(runtime: runtime, identifier_field => curr_type.send(identifier_field))
39+
if to_check.nil?
40+
return ServiceResponse.error(message: "#{model} is not present in new runtime",
41+
payload: :missing_definition)
42+
end
43+
44+
result = compare_version(curr_type.parsed_version, to_check.parsed_version)
45+
46+
unless result
47+
return ServiceResponse.error(message: "#{model} is outdated",
48+
payload: :outdated_definition)
49+
end
50+
end
51+
ServiceResponse.success
52+
end
53+
54+
def compare_version(primary_version, to_check_version)
55+
return false if primary_version.segments[0] != to_check_version.segments[0]
56+
return false if primary_version.segments[1] < to_check_version.segments[1]
57+
58+
true
59+
end
60+
end
61+
end

app/services/runtimes/data_types/update_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def execute
2424
end
2525
end
2626

27+
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
28+
2729
ServiceResponse.success(message: 'Updated data types', payload: data_types)
2830
end
2931
end

app/services/runtimes/flow_types/update_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def execute
2424
end
2525
end
2626

27+
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
28+
2729
ServiceResponse.success(message: 'Updated data types', payload: flow_types)
2830
end
2931
end

app/services/runtimes/runtime_function_definitions/update_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def execute
2525
end
2626
end
2727

28+
UpdateRuntimeCompatibilityJob.perform_later({ runtime_id: current_runtime.id })
29+
2830
ServiceResponse.success(message: 'Updated runtime function definition', payload: runtime_function_definitions)
2931
end
3032
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddIsCompatibleToPrimaryRuntime < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
add_column :namespace_project_runtime_assignments, :compatible, :boolean, null: false, default: false
6+
end
7+
end

0 commit comments

Comments
 (0)