blob: a2b6ad699484568869d934d39649bdf9032f0100 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
70
71
72
73
74
75
76
|
package MGA::Mirrors::Controller::Graph;
use Moose;
use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller'; }
=head1 NAME
MGA::Mirrors::Controller::Graph - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
=head2 index
=cut
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
my $mirror_list = $c->model('Mirrors')->find_mirrors;
my $graph = GraphViz->new(layout => 'dot', overlap => 'orthoxy', rankdir => 1);
my %node;
my %edge;
foreach (@{$mirror_list || []}) {
$node{$_->{hostname}} = $_;
if ($_->{syncfrom}) {
$edge{$_->{syncfrom}}{$_->{hostname}} = 1;
}
}
my %nodadded;
foreach my $from (keys %edge) {
foreach my $to (keys %{ $edge{$from} ||{}}) {
foreach ($from, $to) {
if (!$nodadded{$_}) {
$graph->add_node($_, shape => 'box', cluster => $node{$_}{country});
}
}
# Minimum bandwidth of both nodes
my $bandwidth = ($node{$from}{bandwidth} < $node{$to}{bandwidth}) ? $node{$from}{bandwidth} : $node{$to}{bandwidth};
$bandwidth = 1 if (!$bandwidth);
my $thickness = log($bandwidth) / log(3) - 16; # Scale line thickness from bandwidth
$thickness = ($thickness < 1) ? 1 : $thickness;
$graph->add_edge($from => $to, penwidth => $thickness);
}
}
$c->stash->{graphviz}->{graph} = $graph;
$c->stash->{graphviz}->{format} = "svg";
}
sub end : Private {
my ($self, $c) = @_;
$c->view('GraphViz')->process($c);
$c->model('Mirrors')->db->rollback;
}
=head1 AUTHOR
Olivier Thauvin
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__PACKAGE__->meta->make_immutable;
1;
|