Class: Archsight::Import::Handlers::GoDepResolver

Inherits:
Archsight::Import::Handler show all
Includes:
GoModuleParser
Defined in:
lib/archsight/import/handlers/go_dep_resolver.rb

Overview

GoDepResolver handler - second-pass resolver that patches dependsOn relations onto ApplicationComponents generated by GoGrapher.

Runs after all GoGraphers complete (iteration 2 of the executor loop) so the database contains the full set of freshly-generated ApplicationComponents. Output goes to a single shared generated/relationships.yaml file (all repos combined), loaded after modules.yaml alphabetically so its version of each component — with dependsOn — takes precedence.

One Import:GoDepResolver:* resource is emitted by each GoGrapher run; this handler is registered as a child of GoGrapher via the generates relation so the executor knows to wait until GoGrapher has completed.

Configuration:

import/config/path - Path to the Go repository root (same as GoGrapher)

Instance Attribute Summary

Attributes inherited from Archsight::Import::Handler

#database, #import_resource, #progress, #resources_dir, #shared_writer

Instance Method Summary collapse

Methods included from GoModuleParser

#component_name, #discover_modules, #go_mod_requires, #read_module_name, #same_origin_prefix

Methods inherited from Archsight::Import::Handler

#compute_config_hash, #config, #config_all, #import_yaml, #initialize, #resource_yaml, #resources_to_yaml, #self_marker, #write_generates_meta, #write_yaml

Constructor Details

This class inherits a constructor from Archsight::Import::Handler

Instance Method Details

#executeObject



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
60
61
62
63
64
65
66
67
68
69
# File 'lib/archsight/import/handlers/go_dep_resolver.rb', line 26

def execute
  @path = config("path")
  raise "Missing required config: path" unless @path
  raise "Directory not found: #{@path}" unless File.directory?(@path)

  import_resource.annotations["import/outputPath"] ||= "generated/relationships.yaml"

  modules = discover_modules(@path)
  return write_yaml(YAML.dump(self_marker)) if modules.empty?

  existing_components = database&.instances_by_kind("ApplicationComponent") || {}
  output = +""

  modules.each do |rel_dir, mod_name|
    mod_dir = rel_dir == "." ? @path : File.join(@path, rel_dir)
    dep_names = compute_deps(mod_dir, mod_name, existing_components)
    next if dep_names.empty?

    comp_name = component_name(mod_name)
    existing = existing_components[comp_name]
    next unless existing

    # Rebuild the full ApplicationComponent merging dependsOn into the existing
    # spec (which carries realizedThrough, exposes, etc. from GoGrapher).
    spec = existing.raw.fetch("spec", {}).dup
    spec["dependsOn"] = { "applicationComponents" => dep_names }

    component = {
      "apiVersion" => "architecture/v1alpha1",
      "kind" => "ApplicationComponent",
      "metadata" => {
        "name" => comp_name,
        "annotations" => existing.annotations.merge(
          "generated/script" => import_resource.name,
          "generated/at" => Time.now.utc.iso8601
        )
      },
      "spec" => spec
    }
    output << YAML.dump(component)
  end

  write_yaml(output + YAML.dump(self_marker))
end