Class: MOSAIK::Commands::Evaluate

Inherits:
MOSAIK::Command::Graph show all
Defined in:
lib/mosaik/commands/evaluate.rb

Overview

Evaluate microservice candidates

Instance Method Summary collapse

Instance Method Details

#callObject



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
70
71
72
# File 'lib/mosaik/commands/evaluate.rb', line 29

def call
  info "Evaluating microservice candidates (#{options.map { |k, v| "#{k}: #{v}" }.join(', ')})"

  # Remove clusters with cardinality less than 2
  graph.clusters.delete_if { |_, cluster| cluster.vertices.size < 2 }

  # Evaluate metrics
  options[:metrics].each do |metric|
    Metrics
      .const_get(metric.to_s.camelize)
      .new(options, graph)
      .evaluate
  end

  # Print the clusters
  graph.clusters.each_value do |cluster|
    info "Cluster #{cluster.id} (#{options[:metrics].map { |m| "#{m}: #{cluster.attributes[m].round(2)}" }.join(', ')})"

    next unless options[:debug]

    debug "Cluster #{cluster.id}: #{cluster.vertices.map(&:id).join(', ')}"
  end

  # Print the graph
  info "Graph (#{options[:metrics].map { |m| "#{m}: #{graph.attributes[m].round(2)}" }.join(', ')})"

  # Write graph to file
  write_graph

  # Render graph visualization
  visualize_graph

  return unless options[:statistics]

  # Compute statistics
  statistics = Graph::Statistics
    .new(options, graph)
    .call

  # Write statistics to file
  File.write(options[:statistics], statistics.to_yaml)

  info "Statistics written to #{options[:statistics]}"
end

#validateObject

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/mosaik/commands/evaluate.rb', line 19

def validate
  super

  raise OptionError, "input file not found: #{options[:input]}" unless File.exist? options[:input]

  metrics = options[:metrics] - self.class.defaults[:metrics]

  raise OptionError, "unknown metrics: #{metrics.join(', ')}" unless metrics.empty?
end