Class: MOSAIK::Commands::Identify

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

Overview

Identify microservice candidates

Instance Method Summary collapse

Instance Method Details

#callObject



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
73
74
75
76
77
78
79
80
81
82
# File 'lib/mosaik/commands/identify.rb', line 38

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

  # Reduce the graph
  Graph::Reducer
    .new(options, graph)
    .call

  RubyProf.start if options[:profile]

  # Track execution time
  time = Time.measure do
    # Identify microservice candidates
    Algorithms
      .const_get(options[:algorithm].camelize)
      .new(options, graph)
      .tap(&:validate)
      .call
  end

  if options[:profile]
    profile = RubyProf.stop

    printer = RubyProf::FlameGraphPrinter.new(profile)
    printer.print(File.open("profile.html", "w+"))

    info "Profiling information written to profile.html"
  end

  info "Executed algorithm in #{time} seconds"

  # Print the clusters
  graph.clusters.each_value do |cluster|
    debug "Cluster #{cluster.id}"
    cluster.vertices.each do |vertex|
      debug "  #{vertex.id}"
    end
  end

  # Write graph to file
  write_graph

  # Render graph visualization
  visualize_graph
end

#validateObject

Raises:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mosaik/commands/identify.rb', line 26

def validate
  super

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

  return unless options[:profile]

  require "ruby-prof"
  require "ruby-prof-flamegraph"
end