Class: OpenC3::ConvertToMulti

Inherits:
Migration show all
Defined in:
lib/openc3/migrations/20221210174900_convert_to_multi.rb

Class Method Summary collapse

Class Method Details

.runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/openc3/migrations/20221210174900_convert_to_multi.rb', line 7

def self.run
  # Add parent to preexisting scope microservies and deploy new periodic and multi
  ScopeModel.get_all_models(scope: nil).each do |scope, scope_model|
    parent = "#{scope}__SCOPEMULTI__#{scope}"
    model = MicroserviceModel.get_model(name: "#{scope}__OPENC3__LOG", scope: scope)
    if model
      model.parent = parent
      model.update
      scope_model.children << "#{scope}__OPENC3__LOG"
    end
    model = MicroserviceModel.get_model(name: "#{scope}__NOTIFICATION__LOG", scope: scope)
    if model
      model.parent = parent
      model.update
      scope_model.children << "#{scope}__NOTIFICATION__LOG"
    end
    model = MicroserviceModel.get_model(name: "#{scope}__COMMANDLOG__UNKNOWN", scope: scope)
    if model
      model.parent = parent
      model.update
      scope_model.children << "#{scope}__COMMANDLOG__UNKNOWN"
    end
    model = MicroserviceModel.get_model(name: "#{scope}__PACKETLOG__UNKNOWN", scope: scope)
    if model
      model.parent = parent
      model.update
      scope_model.children << "#{scope}__PACKETLOG__UNKNOWN"
    end
    scope_model.deploy_periodic_microservice("", {}, parent)
    scope_model.deploy_scopemulti_microservice("", {})

    # Add parent to preexisting target microservices and deploy new multi
    TargetModel.get_all_models(scope: scope).each do |target_name, target_model|
      next if target_name == 'UNKNOWN'
      parent = "#{scope}__MULTI__#{target_name}"
      %w(DECOM COMMANDLOG DECOMCMDLOG PACKETLOG DECOMLOG REDUCER CLEANUP).each do |type|
        model = MicroserviceModel.get_model(name: "#{scope}__#{type}__#{target_name}", scope: scope)
        if model
          model.parent = parent
          if %w(COMMANDLOG DECOMCMDLOG).include?(type)
            model.options << ["BUFFER_DEPTH", 5]
          end
          if %w(PACKETLOG DECOMLOG).include?(type)
            model.options << ["BUFFER_DEPTH", 60]
          end
          model.update
          target_model.children << "#{scope}__#{type}__#{target_name}"
        end
      end
      target_model.deploy_multi_microservice("", {}, nil)
    end
  end
end