This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aed2ba
commit 1fac5ef
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module MOSAIK | ||
module Commands | ||
## | ||
# Evaluate microservice candidates | ||
# | ||
class Evaluate < Command | ||
self.description = "Evaluate microservice candidates" | ||
|
||
defaults file: "mosaik-candidates.csv" | ||
|
||
argument "--file FILE", "File for the identified microservice candidates graph (default: #{defaults[:file]})" | ||
|
||
def validate | ||
raise OptionError, "file not found: #{options[:file]}" unless File.exist? options[:file] | ||
end | ||
|
||
def call | ||
info "Evaluating microservice candidates (#{options.map { |k, v| "#{k}: #{v}" }.join(', ')})" | ||
|
||
# Evaluate modularity | ||
Metrics::Modularity | ||
.new(options, graph) | ||
.evaluate | ||
|
||
# Print the clusters | ||
graph.clusters.each_value do |cluster| | ||
info "Cluster #{cluster.id} (modularity: #{cluster.attributes[:modularity]})" | ||
|
||
next unless options[:debug] | ||
|
||
debug "Components: #{cluster.vertices.map(&:id).join(', ')}" | ||
end | ||
|
||
file = "#{File.basename(options[:file], '.*')}-evaluation" | ||
|
||
# Write graph to file | ||
File.write("#{file}.csv", graph.to_csv) | ||
|
||
info "Dependency graph written to #{options[:file]}" | ||
|
||
return unless options[:visualize] | ||
|
||
# Write visualization to file | ||
debug graph.to_dot | ||
graph.to_png(file) | ||
|
||
info "Evaluated microservice candidate graph written to #{file}.dot and rendered to #{file}.png" | ||
end | ||
|
||
private | ||
|
||
def graph | ||
@graph ||= Graph::Graph.from_csv(File.read(options[:file])) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe MOSAIK::Commands::Evaluate do | ||
subject(:command) { build(:evaluate_command, arguments:) } | ||
|
||
let(:arguments) { [] } | ||
|
||
describe "#validate" do | ||
it "does not raise an error" do | ||
FileUtils.touch("mosaik-candidates.csv") | ||
|
||
expect { command.validate }.not_to raise_error | ||
end | ||
|
||
describe "--file" do | ||
let(:arguments) { ["--file", "doesnotexist.csv"] } | ||
|
||
it "raises an error" do | ||
expect { command.validate }.to raise_error MOSAIK::OptionError, "file not found: doesnotexist.csv" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters