Skip to content

Instantly share code, notes, and snippets.

@yanick
Created August 6, 2014 15:00
Show Gist options
  • Save yanick/adec1f50590cf08b0a94 to your computer and use it in GitHub Desktop.
Save yanick/adec1f50590cf08b0a94 to your computer and use it in GitHub Desktop.
command-line Azkaban flow graphing
#!/usr/bin/env perl -s
=head1 SYNOPSIS
$ azkaban_flow -f=<format> path/to/final/job
=head1 DESCRIPTION
The script reads the Azkaban job file, figure out all its dependencies, traverses them,
and generates the resulting graph.
If no format is passed, C<ascii> is assumed.
Caveat: the script assumes that all job files are in the same directory.
=head1 EXAMPLES
To create a svg representation of the graph (C<dot> needs to be installed):
$ azkaban_flow.pl -f=graphviz target/azkaban/final_job.job | dot -Tsvg > pretty.sv
=cut
use 5.18.0;
use Path::Tiny;
use Data::Printer;
use Graph::Easy;
my $job = path(shift);
my %dependencies = create_workflow( $job );
my $graph = Graph::Easy->new;
$graph->timeout(60); # give up after one minute
while( my( $job, $deps ) = each %dependencies ) {
$graph->add_edge( $_ => $job ) for @$deps;
}
my $method = 'as_' . ( $::f || 'ascii' );
print $graph->$method;
sub create_workflow {
my $job = shift;
my $azkaban_dir = $job->parent;
my %dependencies;
my @files = ( $job );
while( my $file = shift @files ) {
my $job = $file->basename =~ s/\.job//r;
next if $dependencies{$job}; # already processed
my @deps = map { split /\s*,\s*/ } grep { s/^dependencies=\s*// } $file->lines( { chomp => 1 } );
$dependencies{$job} = \@deps;
push @files, map { $azkaban_dir->child( $_.'.job' ) } @deps;
}
return %dependencies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment