archsight 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/docs/archimate.md +4 -3
  3. data/docs/diagram.md +107 -6
  4. data/docs/icons.md +1 -0
  5. data/docs/index.md.erb +1 -0
  6. data/docs/modeling.md +71 -2
  7. data/lib/archsight/diagram/graph/attributes.rb +66 -11
  8. data/lib/archsight/diagram/graph/builder.rb +101 -3
  9. data/lib/archsight/diagram/graph/edge.rb +7 -1
  10. data/lib/archsight/diagram/graph/node.rb +29 -1
  11. data/lib/archsight/diagram/graph/port.rb +28 -0
  12. data/lib/archsight/diagram/graph.rb +18 -1
  13. data/lib/archsight/diagram/includes.rb +22 -4
  14. data/lib/archsight/diagram/layout/alignment.rb +138 -0
  15. data/lib/archsight/diagram/layout/expander.rb +13 -0
  16. data/lib/archsight/diagram/layout/ports.rb +182 -0
  17. data/lib/archsight/diagram/layout/rank_arranger.rb +27 -1
  18. data/lib/archsight/diagram/layout/stacker.rb +3 -2
  19. data/lib/archsight/diagram/layout.rb +15 -5
  20. data/lib/archsight/diagram/legend/inventory.rb +52 -4
  21. data/lib/archsight/diagram/legend/row.rb +44 -0
  22. data/lib/archsight/diagram/parser/ast.rb +9 -0
  23. data/lib/archsight/diagram/parser.rb +56 -5
  24. data/lib/archsight/diagram/renderer/dataflow_renderer.rb +2 -1
  25. data/lib/archsight/diagram/renderer/edge_renderer.rb +5 -2
  26. data/lib/archsight/diagram/renderer/label_placer.rb +98 -22
  27. data/lib/archsight/diagram/renderer/node_renderer.rb +49 -1
  28. data/lib/archsight/diagram/renderer/path_renderer.rb +2 -2
  29. data/lib/archsight/diagram/renderer/stylesheet.rb +10 -1
  30. data/lib/archsight/diagram/renderer/text_renderer.rb +1 -0
  31. data/lib/archsight/diagram/renderer.rb +21 -5
  32. data/lib/archsight/diagram/resource_links.rb +18 -12
  33. data/lib/archsight/diagram/routing/edge_routing.rb +106 -5
  34. data/lib/archsight/diagram/support/markdown_text.rb +2 -2
  35. data/lib/archsight/diagram/support/text_metrics.rb +7 -3
  36. data/lib/archsight/export/confluence/analysis_output.rb +12 -5
  37. data/lib/archsight/linter/structure.rb +17 -3
  38. data/lib/archsight/linter.rb +30 -4
  39. data/lib/archsight/pdf/embeds.rb +3 -2
  40. data/lib/archsight/pdf/typst/archsight.typ +4 -0
  41. data/lib/archsight/resources/base.rb +5 -0
  42. data/lib/archsight/resources/grouping.rb +80 -0
  43. data/lib/archsight/resources/technology_node.rb +17 -2
  44. data/lib/archsight/resources/technology_service.rb +6 -0
  45. data/lib/archsight/resources/technology_system_software.rb +5 -0
  46. data/lib/archsight/resources.rb +28 -0
  47. data/lib/archsight/summary/lens.rb +10 -0
  48. data/lib/archsight/template.rb +2 -2
  49. data/lib/archsight/version.rb +1 -1
  50. metadata +5 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Archsight
4
4
  module Diagram
5
- # Turns `resource "Archsight:Web"` node attributes into links, using a
5
+ # Turns `resource "Archsight:Web"` node and port attributes into links, using a
6
6
  # resolver the caller supplies -- the diagram renderer itself knows
7
7
  # nothing about the resource database.
8
8
  #
@@ -22,19 +22,25 @@ module Archsight
22
22
  return unless resolver
23
23
 
24
24
  graph.nodes_by_id.each_value do |node|
25
- reference = node.attrs["resource"]
26
- next unless reference
25
+ resolve(node.attrs, node.id, node.line, resolver, unresolved)
26
+ node.ports.each { |port| resolve(port.attrs, port.ref, port.line, resolver, unresolved) }
27
+ end
28
+ end
29
+
30
+ # `attrs` of a node or a port; `id` is how `unresolved` names it (`leaf.port` for a port).
31
+ def resolve(attrs, id, line, resolver, unresolved)
32
+ reference = attrs["resource"]
33
+ return unless reference
27
34
 
28
- outcome = resolver.call(reference)
29
- next if outcome.nil?
35
+ outcome = resolver.call(reference)
36
+ return if outcome.nil?
30
37
 
31
- if outcome.is_a?(String)
32
- node.attrs["link"] = outcome
33
- else
34
- reason = REASONS.fetch(outcome) { raise ArgumentError, "resolver returned #{outcome.inspect} for #{reference.inspect}" }
35
- node.attrs["broken"] = "Resource #{reference} #{reason}"
36
- unresolved&.push({ node: node.id, reference: reference, reason: reason, line: node.line })
37
- end
38
+ if outcome.is_a?(String)
39
+ attrs["link"] = outcome
40
+ else
41
+ reason = REASONS.fetch(outcome) { raise ArgumentError, "resolver returned #{outcome.inspect} for #{reference.inspect}" }
42
+ attrs["broken"] = "Resource #{reference} #{reason}"
43
+ unresolved&.push({ node: id, reference: reference, reason: reason, line: line })
38
44
  end
39
45
  end
40
46
  end
@@ -76,11 +76,18 @@ module Archsight
76
76
  # instead (see `port_order`).
77
77
  PORT_ORDER_TOLERANCE = PORT_MIN_GAP / 2.0
78
78
 
79
+ # A port end is routed to its tab, a box of its own (always a rectangle).
80
+ PortEnd = Struct.new(:box) do
81
+ def shape = "rectangle"
82
+ end
83
+
79
84
  # `obstacle_map` can be shared with `DataflowRouting` over the same boxes.
80
- def initialize(graph, boxes, obstacle_map: ObstacleMap.new(boxes))
85
+ # `ports` are the port tabs (`Layout::Result#ports`) an edge may attach to instead of its node.
86
+ def initialize(graph, boxes, obstacle_map: ObstacleMap.new(boxes), ports: {})
81
87
  @graph = graph
82
88
  @boxes = boxes
83
89
  @obstacle_map = obstacle_map
90
+ @ports = ports
84
91
  end
85
92
 
86
93
  # Every edge's route, computed up front (rather than immediately
@@ -89,11 +96,13 @@ module Archsight
89
96
  # split into multiple attachment points.
90
97
  def compute_paths(edges)
91
98
  edges.map do |edge|
92
- from = positioned(edge.from)
93
- to = positioned(edge.to)
99
+ from = positioned(edge.from, edge.from_port)
100
+ to = positioned(edge.to, edge.to_port)
94
101
  obstacles = @obstacle_map.excluding(edge.from, edge.to)
95
102
  candidates = EdgeRouter.candidate_paths(from.box, to.box, edge.attrs["style"],
96
103
  from_shape: from.shape, to_shape: to.shape, obstacles: obstacles)
104
+ candidates = tab_free_lanes(edge, from, to) + candidates
105
+ candidates = through_ports(candidates, edge) if edge.from_port || edge.to_port
97
106
  scored = EdgeRouter.score_candidates(candidates, obstacles)
98
107
  points = EdgeRouter.select_best(scored, sibling_paths: [])
99
108
  RoutedEdge.new(edge: edge, points: points, from_box: from.box, to_box: to.box, obstacles: obstacles, scored: scored)
@@ -234,8 +243,100 @@ module Archsight
234
243
  points.map { |point| point.dup.tap { |p| p[index] += delta } }
235
244
  end
236
245
 
237
- def positioned(node)
238
- Layout::PositionedNode.new(node, @boxes[node.id])
246
+ def positioned(node, port = nil)
247
+ tab = port && @ports[port.ref]
248
+ tab ? PortEnd.new(tab) : Layout::PositionedNode.new(node, @boxes[node.id])
249
+ end
250
+
251
+ # Only lines that leave a tab on its outer side (away from its leaf) and never run through the leaf
252
+ # itself, which is not an obstacle to its own edges. If no candidate does, all of them are kept.
253
+ def through_ports(candidates, edge)
254
+ ends = [[edge.from_port, edge.from, :first], [edge.to_port, edge.to, :last]].select { |port, _, _| port && @ports[port.ref] }
255
+ kept = candidates.select do |points|
256
+ ends.all? do |port, node, at|
257
+ tab = @ports[port.ref]
258
+ outward?(tab, node, points.public_send(at)) && !EdgeRouter::PathMetrics.enters_interior?(points, @boxes[node.id])
259
+ end
260
+ end
261
+ kept.empty? ? candidates : kept
262
+ end
263
+
264
+ # A straight line between two boxes one above the other (or side by side) normally runs at one box's
265
+ # center, which may be where a port tab sits on a side it attaches to (a tab is an obstacle). This
266
+ # offers the same line in the middle of the widest stretch the two boxes share that no tab on the facing
267
+ # sides covers -- only when such a tab is in the way, so other diagrams route as before.
268
+ def tab_free_lanes(edge, from, to)
269
+ a = from.box
270
+ b = to.box
271
+ return [] if [from, to].any? { |e| Representers.for(e.shape).elliptical? }
272
+
273
+ vertical = !a.overlaps_y?(b) && a.overlaps_x?(b)
274
+ horizontal = !a.overlaps_x?(b) && a.overlaps_y?(b)
275
+ return [] unless vertical || horizontal
276
+
277
+ axis = vertical ? %i[left right x] : %i[top bottom y]
278
+ margin = EdgeRouter::StraightPath::ALIGNED_CORNER_MARGIN
279
+ lo = [a.public_send(axis[0]), b.public_send(axis[0])].max + margin
280
+ hi = [a.public_send(axis[1]), b.public_send(axis[1])].min - margin
281
+ blocked = facing_tabs(edge, a, b, vertical).map { |t| [t.public_send(axis[0]) - margin, t.public_send(axis[1]) + margin] }
282
+ return [] if blocked.none? { |l, h| h > lo && l < hi }
283
+
284
+ lane = widest_free(lo, hi, blocked)
285
+ return [] unless lane
286
+
287
+ [lane_line(a, b, (lane[0] + lane[1]) / 2.0, vertical)]
288
+ end
289
+
290
+ # The straight line at `c` between the facing sides of `a` and `b`.
291
+ def lane_line(a, b, c, vertical)
292
+ if vertical
293
+ down = a.y < b.y
294
+ [[c, down ? a.bottom : a.top], [c, down ? b.top : b.bottom]]
295
+ else
296
+ right = a.x < b.x
297
+ [[right ? a.right : a.left, c], [right ? b.left : b.right, c]]
298
+ end
299
+ end
300
+
301
+ # The tabs on the sides of the edge's two leaves that face each other (a port end itself is its own box).
302
+ def facing_tabs(edge, a, b, vertical)
303
+ [[edge.from, edge.from_port, a, b], [edge.to, edge.to_port, b, a]].flat_map do |node, port, own, other|
304
+ next [] if port
305
+
306
+ side = if vertical
307
+ own.y < other.y ? :bottom : :top
308
+ else
309
+ own.x < other.x ? :right : :left
310
+ end
311
+ node.ports.filter_map { |p| @ports[p.ref] }.select { |tab| tab_on_side?(tab, @boxes[node.id], side) }
312
+ end
313
+ end
314
+
315
+ def tab_on_side?(tab, box, side)
316
+ case side
317
+ when :top then EdgeRouter::PathMetrics.close?(tab.y, box.top)
318
+ when :bottom then EdgeRouter::PathMetrics.close?(tab.y, box.bottom)
319
+ when :left then EdgeRouter::PathMetrics.close?(tab.x, box.left)
320
+ else EdgeRouter::PathMetrics.close?(tab.x, box.right)
321
+ end
322
+ end
323
+
324
+ # The widest part of `lo..hi` outside every `blocked` interval, `nil` if none is left.
325
+ def widest_free(lo, hi, blocked)
326
+ cursor = lo
327
+ free = []
328
+ blocked.sort.each do |l, h|
329
+ free << [cursor, l] if l > cursor
330
+ cursor = [cursor, h].max
331
+ end
332
+ free << [cursor, hi] if hi > cursor
333
+ free.map { |l, h| [l, [h, hi].min] }.select { |l, h| h - l >= 1.0 }.max_by { |l, h| h - l }
334
+ end
335
+
336
+ # Whether `point` (an end of a line) is on the side of `tab` that faces away from its leaf.
337
+ def outward?(tab, node, point)
338
+ side = tab.side_of(point)
339
+ !side.nil? && tab_on_side?(tab, @boxes[node.id], side)
239
340
  end
240
341
 
241
342
  # Returns whether any edge's `points` actually changed this round.
@@ -10,8 +10,8 @@ module Archsight
10
10
  # plain run. Anything built from a label has to carry the flag along
11
11
  # (`like`), or its markers render as literal text.
12
12
  class MarkdownText < String
13
- # Every marker (`**`, `__`, `*`, `[text](url)`) opens with one of these.
14
- MARKER_START = /[*_\[]/
13
+ # Every marker (`**`, `__`, `*`, `` `code` ``, `[text](url)`) opens with one of these.
14
+ MARKER_START = /[*_`\[]/
15
15
 
16
16
  # `text` as a `MarkdownText` if a marker could start in it, else as is.
17
17
  def self.detect(text) = text.match?(MARKER_START) ? new(text) : text
@@ -56,6 +56,8 @@ module Archsight
56
56
  611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584
57
57
  ].freeze
58
58
  FALLBACK_WIDTH = 700
59
+ # Every char of a monospace (`` `code` ``) run: the advance of Menlo, Consolas, DejaVu Sans Mono...
60
+ MONO_WIDTH = 602
59
61
 
60
62
  # The rendered width, in px, of `text`'s widest line at `font_size`
61
63
  # -- markdown-lite markers don't take up room, and `**bold**` runs
@@ -68,6 +70,8 @@ module Archsight
68
70
 
69
71
  def line_units(line)
70
72
  markdown_runs(line).sum do |content, style|
73
+ next content.length * MONO_WIDTH if style[:code]
74
+
71
75
  table = style[:bold] ? HELVETICA_BOLD_WIDTHS : HELVETICA_WIDTHS
72
76
  content.each_char.sum do |char|
73
77
  index = char.ord - 32
@@ -79,7 +83,7 @@ module Archsight
79
83
  # A small, deliberately non-nested markdown-lite: `**bold**`,
80
84
  # `*italic*`, `__underline__` (a separate marker from bold's `**` so
81
85
  # the two never collide, since real Markdown has no underline
82
- # syntax), and `[text](url)` for an inline link. Scans left to
86
+ # syntax), `` `code` `` (monospace) and `[text](url)` for an inline link. Scans left to
83
87
  # right, splitting `text` into `[content, style]` pairs -- `style`
84
88
  # is `{}` for a plain run. Only a `MarkdownText` is scanned (the lexer
85
89
  # flags every string literal a marker could start in); any other
@@ -109,7 +113,7 @@ module Archsight
109
113
  end
110
114
 
111
115
  # Checked in this order, so `**` wins over `*`.
112
- PAIRED_MARKERS = { "**" => :bold, "__" => :underline, "*" => :italic }.freeze
116
+ PAIRED_MARKERS = { "`" => :code, "**" => :bold, "__" => :underline, "*" => :italic }.freeze
113
117
 
114
118
  # The formatted `[content, style]` run starting at `text[i]`, plus the
115
119
  # index just past it -- or nil when no (closed) marker starts there.
@@ -151,7 +155,7 @@ module Archsight
151
155
  lines.empty? ? [line] : lines.map { |l| runs_to_markdown(source, l) }
152
156
  end
153
157
 
154
- MARKERS = { bold: "**", italic: "*", underline: "__" }.freeze
158
+ MARKERS = { bold: "**", italic: "*", underline: "__", code: "`" }.freeze
155
159
 
156
160
  def runs_to_markdown(source, chars)
157
161
  out = chars.chunk_while { |a, b| a[1] == b[1] }.map do |group|
@@ -25,15 +25,22 @@ module Archsight
25
25
 
26
26
  # @return [String] block XML
27
27
  def xml(name, result)
28
- out = %(<p><strong>#{h(name)}</strong> (result of the analysis at the export)</p>\n)
29
- return out << %(<p><em>The analysis failed: #{h(result.error)}</em></p>\n) unless result.success?
30
-
31
- result.sections.each { |section| out << section_xml(section).to_s }
32
- out
28
+ out = +""
29
+ if result.success?
30
+ result.sections.each { |section| out << section_xml(section).to_s }
31
+ else
32
+ out << %(<p><em>The analysis failed: #{h(result.error)}</em></p>\n)
33
+ end
34
+ out << source_note(name)
33
35
  end
34
36
 
35
37
  private
36
38
 
39
+ # Where the content comes from, not a part of it: small, gray, at the right below the result
40
+ def source_note(name)
41
+ %(<p style="text-align: right;"><small><span style="color: rgb(151,160,175);">#{h(name)} (result at the export)</span></small></p>\n)
42
+ end
43
+
37
44
  def section_xml(section)
38
45
  case section[:type]
39
46
  when :heading then heading(section)
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Archsight
4
4
  class Linter
5
- # Structural checks over the declared relations, the rules of "Choosing the Kind" and "Choosing the Kind:
6
- # Infrastructure" in the modeling guide. All findings are warnings: they point at modeling decisions to review and
7
- # have legitimate exceptions (internal services, capabilities that no product carries yet).
5
+ # Structural checks over the declared relations, the rules of "Choosing the Kind", "Choosing the Kind:
6
+ # Infrastructure" and "Virtualization" in the modeling guide. All findings are warnings: they point at modeling
7
+ # decisions to review and have legitimate exceptions (internal services, capabilities that no product carries yet).
8
8
  class Structure
9
9
  # Network types that run over another network and need one that serves them
10
10
  OVERLAY_TYPES = %w[overlay vpn].freeze
@@ -28,6 +28,7 @@ module Archsight
28
28
  generated_component_in_several_repositories,
29
29
  link_not_between_two_facilities,
30
30
  overlay_without_underlay,
31
+ vm_without_platform,
31
32
  facility_without_location,
32
33
  equipment_without_facility,
33
34
  device_without_facility,
@@ -164,6 +165,19 @@ module Archsight
164
165
  end
165
166
  end
166
167
 
168
+ # A virtual machine runs on a platform: it is servedBy a TechnologyService that is suppliedBy the hypervisor, or,
169
+ # virtualized on one machine (an isolated session of a workstation), realizedBy that TechnologyDevice. Fixed
170
+ # hops, no traversal.
171
+ def vm_without_platform
172
+ instances("TechnologyNode").filter_map do |node|
173
+ next unless node.annotations["infrastructure/type"] == "vm"
174
+ next if targets(node, :realizedBy, :technologyDevices).any?
175
+ next if targets(node, :servedBy, :technologyServices).any? { |service| targets(service, :suppliedBy, :technologyComponents).any? }
176
+
177
+ warning(node, "is a vm served by no technology service supplied by system software (its virtualization platform)")
178
+ end
179
+ end
180
+
167
181
  # Only the outermost facility needs a location; nested halls inherit it from their campus
168
182
  def facility_without_location
169
183
  nested = owners_by_target("TechnologyFacility", :composedOf, :technologyFacilities)
@@ -22,6 +22,17 @@ module Archsight
22
22
  # general check above so that a cycle is reported once.
23
23
  HIERARCHY_VERBS = %i[specializes composedOf aggregates refinedBy].freeze
24
24
 
25
+ # Where a virtual machine runs (see "Virtualization" in the modeling guide): the node is served by a service,
26
+ # the service is supplied by the hypervisor, the hypervisor is realized by its hosts. Together with the
27
+ # structure verbs below these may not lead back to where they started, a cycle neither check above sees
28
+ # because each leaves out the other's verbs: a platform would then consist of its own guest.
29
+ VIRTUALIZATION_CHAIN = {
30
+ "TechnologyNode" => %i[servedBy technologyServices],
31
+ "TechnologyService" => %i[suppliedBy technologyComponents],
32
+ "TechnologySystemSoftware" => %i[realizedBy technologyComponents]
33
+ }.freeze
34
+ VIRTUALIZATION_STRUCTURE_VERBS = %i[composedOf aggregates].freeze
35
+
25
36
  def initialize(database)
26
37
  @database = database
27
38
  @errors = []
@@ -40,6 +51,7 @@ module Archsight
40
51
  end
41
52
  validate_relation_cycles
42
53
  validate_hierarchy_cycles
54
+ validate_virtualization_cycles
43
55
  validate_unique_annotations
44
56
 
45
57
  @errors
@@ -200,24 +212,38 @@ module Archsight
200
212
  end
201
213
  end
202
214
 
215
+ # The virtualization chain mixed with composition/aggregation must not lead back to where it started. Only
216
+ # cycles that use both a chain and a structure relation are reported here; the others are reported above.
217
+ def validate_virtualization_cycles
218
+ graph = relation_graph do |verb, key, instance|
219
+ VIRTUALIZATION_STRUCTURE_VERBS.include?(verb) || VIRTUALIZATION_CHAIN[instance.klass] == [verb, key]
220
+ end
221
+ report_cycles(graph, only: ->(cycle) { cycle.map { |step| VIRTUALIZATION_STRUCTURE_VERBS.include?(step[:verb]) }.uniq.length == 2 }) do |start, path|
222
+ "#{start.path_ref}: #{start.klass} '#{start.name}' is part of a cycle of virtualization and composition relations, " \
223
+ "a platform would contain what runs on it (#{path})"
224
+ end
225
+ end
226
+
203
227
  # Adds one error per group of instances that reach each other; the block builds the message from the first
204
- # instance of the group and the path of one concrete cycle
205
- def report_cycles(graph)
228
+ # instance of the group and the path of one concrete cycle; `only` skips groups whose cycle it rejects
229
+ def report_cycles(graph, only: nil)
206
230
  strongly_connected_groups(graph).each do |group|
207
231
  cycle = cycle_through(group.first, group, graph)
232
+ next if only && !only.call(cycle)
233
+
208
234
  start = group.first
209
235
  path = ([start.name] + cycle.map { |step| step[:to].name }).zip(cycle.map { |step| step[:verb] }).flat_map { |name, verb| [name, verb && "-#{verb}->"] }.compact
210
236
  @errors << yield(start, path.join(" "))
211
237
  end
212
238
  end
213
239
 
214
- # { instance => [{ verb:, to: }] } over the declared relations whose verb the block accepts
240
+ # { instance => [{ verb:, to: }] } over the declared relations the block accepts (verb, key, instance)
215
241
  def relation_graph
216
242
  graph = {}
217
243
  @database.instances.each_value do |instances_hash|
218
244
  instances_hash.each_value do |instance|
219
245
  graph[instance] = instance.class.declared_relations.flat_map do |verb, key, _kind|
220
- next [] unless yield(verb)
246
+ next [] unless yield(verb, key, instance)
221
247
 
222
248
  instance.relations(verb, key).map { |target| { verb: verb, to: target } }
223
249
  end
@@ -111,10 +111,11 @@ module Archsight
111
111
  @analyses += 1
112
112
  result = self.class.result(@database, instance)
113
113
  renderer = Archsight::Analysis::TypstRenderer.new([result], full: true)
114
- parts = ["#strong[#{Typst.str(instance.name)}]"]
114
+ parts = []
115
115
  parts << renderer.error(result) if result.failed?
116
116
  parts.concat(result.sections.filter_map { |section| analysis_section(renderer, section) })
117
- parts.join("\n\n")
117
+ # the name is where the content comes from, not a part of it: a small gray note below
118
+ parts.join("\n\n") + "\n#source-note(theme: theme)[#{Typst.str(instance.name)}]"
118
119
  end
119
120
 
120
121
  def analysis_section(renderer, section)
@@ -133,6 +133,10 @@
133
133
  if intro != none { block(above: 8pt, below: 6pt, text(size: 9pt, fill: theme.muted, intro)) }
134
134
  }
135
135
 
136
+ // Where embedded content comes from (e.g. the analysis name below its result): small, gray, at the right, close to the
137
+ // content it belongs to
138
+ #let source-note(theme: none, body) = block(above: 3pt, width: 100%, align(right, text(size: 7pt, fill: theme.muted.lighten(20%), body)))
139
+
136
140
  // A cover page without header and footer: a band with the logo at its bottom left, kind, title and a short rule, the
137
141
  // document meta at the bottom left of the page. The pages after it are numbered from 1.
138
142
  #let cover-page(theme: none, title: "", kind: none, doc-id: none, version: none, date: none, owner: none, classification: none) = {
@@ -25,6 +25,11 @@ module Archsight
25
25
  @declared_relations || []
26
26
  end
27
27
 
28
+ # The relations the template of the kind (`archsight template`, the example of its docs page) shows
29
+ def self.template_relations
30
+ declared_relations
31
+ end
32
+
28
33
  # Every relation a resource of this kind can have: the declared ones and the derived ones (`mentions`,
29
34
  # `depicts`, see Archsight::References). Everything that follows relations (queries, graphs, impact analysis)
30
35
  # uses this; what lets a user write or choose relations uses declared_relations.
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Grouping gathers resources of any kind that belong together by some criterion
4
+ class Archsight::Resources::Grouping < Archsight::Resources::Base
5
+ include_annotations :git, :architecture
6
+
7
+ description <<~MD
8
+ Gathers resources of any kind, other groupings included, that belong together by some criterion.
9
+
10
+ ## ArchiMate Definition
11
+
12
+ **Layer:** Other (ArchiMate: composite element)
13
+ **Aspect:** Composite
14
+
15
+ The grouping element aggregates or composes concepts that belong together based on some common
16
+ characteristic. Unlike a location, the criterion is not a place: a domain, a programme, a product family,
17
+ a migration scope, the subject of a review.
18
+
19
+ ## Usage
20
+
21
+ Use Grouping to represent:
22
+
23
+ - Domains and sub-domains (Payments, Identity)
24
+ - The scope of a programme, a review or an audit
25
+ - A product family that spans business, application and technology resources
26
+
27
+ ## Members
28
+
29
+ A grouping lists its members in `spec`, one key per kind, under one of two verbs:
30
+
31
+ - `aggregates`: the member belongs to the group but also stands on its own; it can be in several groups
32
+ - `composedOf`: the member is a part of this whole and of no other
33
+
34
+ ```yaml
35
+ spec:
36
+ aggregates:
37
+ applicationComponents: [Payment Gateway]
38
+ businessProcesses: [Refund Handling]
39
+ groupings: [Card Payments]
40
+ composedOf:
41
+ dataObjects: [Payment]
42
+ ```
43
+
44
+ A grouping can contain groupings, so groups nest; a grouping that contains itself (directly or through
45
+ others) is reported by `archsight lint`. Members do not name their groups: a member's page lists the groups
46
+ it is in.
47
+
48
+ ## Not this kind
49
+
50
+ - A place is a `Location`
51
+ - The menu of the wiki is a `PageMenu`
52
+ - Resources that only share an attribute (a team, a tag, a risk domain) need no grouping: a query or a view
53
+ finds them
54
+ MD
55
+
56
+ icon "square-dashed"
57
+ layer "other"
58
+
59
+ # The verbs a grouping holds its members with
60
+ MEMBER_VERBS = %i[aggregates composedOf].freeze
61
+
62
+ # The relations shown in the template of the kind; the declared ones cover every kind
63
+ TEMPLATE_KINDS = %w[ApplicationComponent BusinessProcess Grouping].freeze
64
+
65
+ class << self
66
+ # Declares MEMBER_VERBS towards every kind, this one included. Called once all kinds are loaded (see
67
+ # lib/archsight/resources.rb), since a class body only sees the kinds loaded before it.
68
+ def declare_members!
69
+ @declared_relations = []
70
+ @relations = nil
71
+ MEMBER_VERBS.each do |verb|
72
+ Archsight::Resources.each { |kind| relation verb, Archsight::Resources.relation_key(kind).to_sym, kind }
73
+ end
74
+ end
75
+
76
+ def template_relations
77
+ declared_relations.select { |_, _, kind| TEMPLATE_KINDS.include?(kind) }
78
+ end
79
+ end
80
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # TechnologyNode represents physical infrastructure (VMs, servers, Kubernetes nodes)
3
+ # TechnologyNode represents physical and virtual infrastructure (VMs, servers, Kubernetes nodes)
4
4
  class Archsight::Resources::TechnologyNode < Archsight::Resources::Base
5
5
  include_annotations :git, :architecture, :asset, :risk, :capacity
6
6
 
7
7
  description <<~MD
8
- Represents physical infrastructure hosting application components.
8
+ Represents physical or virtual infrastructure hosting application components.
9
9
 
10
10
  ## ArchiMate Definition
11
11
 
@@ -54,6 +54,21 @@ class Archsight::Resources::TechnologyNode < Archsight::Resources::Base
54
54
  A logical node (a host role, "the hypervisors of the platform") is `realizedBy` the `TechnologyDevice`s, the
55
55
  physical machines, that make it up.
56
56
 
57
+ ## Virtualization
58
+
59
+ A virtual machine (`infrastructure/type: vm`) runs on a virtualization platform, reached through the service that
60
+ hands out the VMs. Every step is written on the upper element and points down:
61
+
62
+ - the VM node is `servedBy` the `TechnologyService` that provides it ("virtual machines")
63
+ - the service is `suppliedBy` the hypervisor, a `TechnologySystemSoftware`
64
+ - the hypervisor is `realizedBy` the host nodes (`infrastructure/type: bare-metal`) it runs on
65
+
66
+ The service page lists its guests as incoming "servedBy"; impact analysis on the hosts (incoming, depth 3) reaches
67
+ them. A VM virtualized on one machine (an isolated session of a workstation) is `realizedBy` that
68
+ `TechnologyDevice` instead. Do not use `composedOf` for this: the hosts' cluster consists of its hosts, not of
69
+ the VMs that run on it. `archsight lint` warns about a vm with neither, and reports as an error a platform that
70
+ contains (`composedOf`, `aggregates`) a VM that runs on it. See "Virtualization" in the modeling guide.
71
+
57
72
  ## Spare hosts
58
73
 
59
74
  A host role or pool keeps hosts in reserve (n+1). The reserve is a count, not a machine: any host can take the
@@ -50,6 +50,12 @@ class Archsight::Resources::TechnologyService < Archsight::Resources::Base
50
50
  "servedBy" from ApplicationComponent on its page. An ApplicationService that is `servedBy` the service uses it as a
51
51
  whole; list a cluster there only when the service's own components run in it.
52
52
 
53
+ ## Virtualization
54
+
55
+ A service that hands out virtual machines is `suppliedBy` the hypervisor (`TechnologySystemSoftware`). The VM nodes
56
+ (`infrastructure/type: vm`) are `servedBy` it and listed as incoming "servedBy" from TechnologyNode on its page.
57
+ See `TechnologyNode`.
58
+
53
59
  ## Teams
54
60
 
55
61
  A service is `maintainedBy` the team (`BusinessActor`) that builds and changes it and `operatedBy` the team
@@ -43,6 +43,11 @@ class Archsight::Resources::TechnologySystemSoftware < Archsight::Resources::Bas
43
43
  System software `assignedTo` the artifacts it executes (ArchiMate assignment), written on the system software.
44
44
  The artifact's page shows it as incoming "deployed on".
45
45
 
46
+ ## Virtualization
47
+
48
+ A hypervisor is `realizedBy` the host nodes it runs on and supplies the `TechnologyService` that hands out the
49
+ virtual machines (the service is `suppliedBy` it). See `TechnologyNode`.
50
+
46
51
  ## Concept and implementation
47
52
 
48
53
  System software can `specialize` other system software (ArchiMate specialization): the general one is the
@@ -43,6 +43,31 @@ module Archsight
43
43
  # The derived relations of every class, next to the ones it declares: [verb, key, kind]
44
44
  DERIVED_RELATIONS = DERIVED_VERBS.map { |verb| [verb, DERIVED_KEY, "Resource"] }.freeze
45
45
 
46
+ # Relation keys that do not follow the rule of #relation_key (lowerCamel kind name, made plural): the keys the
47
+ # model has used for these kinds from the start
48
+ IRREGULAR_RELATION_KEYS = {
49
+ "Analysis" => "analyses",
50
+ "MotivationGoal" => "goals",
51
+ "MotivationOutcome" => "outcomes",
52
+ "Page" => "pages",
53
+ "PageMenu" => "menus",
54
+ "TechnologyEquipment" => "technologyEquipment",
55
+ "TechnologySystemSoftware" => "technologySystemSoftware"
56
+ }.freeze
57
+
58
+ # The key under `spec.<verb>` that holds resources of a kind (ApplicationComponent -> applicationComponents),
59
+ # for relations that are declared for many kinds at once (see Grouping)
60
+ def self.relation_key(kind_name)
61
+ name = kind_name.to_s
62
+ IRREGULAR_RELATION_KEYS.fetch(name) do
63
+ key = name[0].downcase + name[1..]
64
+ if key.end_with?("y") && !key.end_with?("ay", "ey", "oy", "uy") then "#{key.chop}ies"
65
+ elsif key.end_with?("s", "x", "ch", "sh") then "#{key}es"
66
+ else "#{key}s"
67
+ end
68
+ end
69
+ end
70
+
46
71
  # The current name of a kind, whichever of its names is given
47
72
  def self.canonical(klass_name)
48
73
  name = klass_name.to_s
@@ -90,3 +115,6 @@ module Archsight::Annotations; end
90
115
  Dir[File.join(__dir__, "annotations", "*.rb")].each { |file| require_relative file }
91
116
  require_relative "resources/base"
92
117
  Dir[File.join(__dir__, "resources", "*.rb")].each { |file| require_relative file }
118
+
119
+ # A Grouping holds resources of every kind, so its relations can only be declared once all kinds are known
120
+ Archsight::Resources::Grouping.declare_members!
@@ -40,6 +40,7 @@ module Archsight
40
40
  in assesses, influences: Assessed and influenced by
41
41
  out evidencedBy: Evidence
42
42
  out ownedBy: Owners
43
+ in aggregates, composedOf: Groups
43
44
  in mentions, depicts: Documented in
44
45
  LENS
45
46
  "strategy" => <<~LENS,
@@ -47,6 +48,7 @@ module Archsight
47
48
  out servedBy: Served by
48
49
  in hasConcern: Stakeholders
49
50
  in realizes: Realized by
51
+ in aggregates, composedOf: Groups
50
52
  in mentions, depicts: Documented in
51
53
  LENS
52
54
  "implementation" => <<~LENS,
@@ -59,6 +61,7 @@ module Archsight
59
61
  out realizes: Realizes
60
62
  in realizes: Realized by
61
63
  out performedBy, ownedBy: People
64
+ in aggregates, composedOf: Groups
62
65
  in mentions, depicts: Documented in
63
66
  LENS
64
67
  "business" => <<~LENS,
@@ -88,6 +91,7 @@ module Archsight
88
91
  out evidencedBy: Evidence
89
92
  in servedBy: Served
90
93
  in exposes: Exposed by
94
+ in aggregates, composedOf: Groups
91
95
  in mentions, depicts: Documented in
92
96
  LENS
93
97
  "technology" => <<~LENS,
@@ -111,6 +115,12 @@ module Archsight
111
115
 
112
116
  # Kinds whose layer lens is too coarse; looked up before the lens of the layer
113
117
  KIND_DEFAULTS = {
118
+ "Grouping" => <<~LENS,
119
+ out aggregates: Members
120
+ out composedOf: Composed of
121
+ in aggregates, composedOf: Part of
122
+ in mentions, depicts: Documented in
123
+ LENS
114
124
  "BusinessActor" => <<~LENS,
115
125
  in performedBy, executedBy: Performs
116
126
  in ownedBy: Owns
@@ -35,10 +35,10 @@ module Archsight
35
35
  end
36
36
 
37
37
  def add_relations(yaml, klass)
38
- return if klass.declared_relations.empty?
38
+ return if klass.template_relations.empty?
39
39
 
40
40
  yaml["spec"] = {} if yaml["spec"].nil?
41
- klass.declared_relations.each do |verb, relation_kind, _relation_klass|
41
+ klass.template_relations.each do |verb, relation_kind, _relation_klass|
42
42
  relation_verb = verb.to_s.delete_prefix(":")
43
43
  yaml["spec"][relation_verb] ||= {}
44
44
  yaml["spec"][relation_verb][relation_kind.to_s] = []