my $depends = 0; #depends subcommand to put reverse dependency
my $reverse_off = 0; #disable reverse dependency
my $reverse_on = 1; #enable reverse dependency
+my $enable_cluster = 0; # enable cluster building
+my $max_partitions = 3; # specify max partitions, which is more than or equal to workers
+my %packages_level = (); # save the level of packages, which are calculated by get_top_order() algorithm
GetOptions (
"repository=s" => \@repos,
"arch=s" => \$arch,
"vm-swap=s" => \$vmswapsize,
"disable-debuginfo" => \$disable_debuginfo,
"depends" => \$depends,
+ "enable-cluster" => \$enable_cluster,
+ "max-partitions" => \$max_partitions,
);
if ( $help ) {
--disable-debuginfo
Disable debug info package to be created
+ --enable-cluster
+ enable packages level distributed building, defalt cluster need 3 workers
+
+ --max-partitions
+ specify max partitions, which means you can build max-partitions parallelly,
+ it must more than or equal to workers number.
+
";
exit(0);
}
#---------------------------------------------------------------------
# according to BFS to solve topological sorting issue
#---------------------------------------------------------------------
+sub print_level_packages {
+ my $cur_level = 0;
+ while(defined $packages_level{$cur_level}) {
+ print "level: $cur_level: ";
+ for(@{$packages_level{$cur_level}}) {
+ print " $_";
+ }
+ print "\n";
+ $cur_level++;
+ }
+}
sub get_top_order {
+ my $level = 0;
my @queue = ();
my @top_order = ();
my %ref_build_complete = ();
}
if ($pack_in_degree == 0) {
push @queue, $pack;
+ #push $packages_level{$level}, $pack;
}
}
+ push @queue, "xxx";
while(@queue) {
my $cur_pack = shift @queue;
+ if ($cur_pack eq "xxx") {
+ if (@queue == 0) {
+ last; #there is no package need to check
+ }
+ $level = $level + 1;
+ push @queue, "xxx";
+ next;
+ }
push @top_order, $cur_pack;
+ push @{$packages_level{$level}}, $cur_pack;
#print "write $cur_pack\n";
for (@{$pkgrddeps{$cur_pack}}) {
$ref_build_complete{$_} += 1;
$prune = 1;
}
}
-
+# use kafka to send message to other workers
+use Kafka::Producer;
+my $connection = Kafka::Connection->new( host => '109.123.100.144' );
+my $producer = Kafka::Producer->new( Connection => $connection );
+sub writeToKafka {
+ my $cur_level = shift;
+ my $partition = 0;
+ my @fail_packages;
+ foreach my $package (@{$packages_level{$cur_level}}) {
+ $producer->send('tizen-unified',$partition,"$package");
+ $partition = ($partition+1)%($max_partitions);
+ }
+ return @fail_packages;
+}
# MAIN
if ($depends) {
info("start generate packages depends from: " . $package_path . " ($style)");
$srpmpaths{$na} = [$pkg];
}
}
+# if build with cluster, not build local
+if ($enable_cluster == 1) {
+ my $cur_level = 0;
+ my $ret = 0;
+ while(defined $packages_level{$cur_level}) {
+ my @fail_packages = writeToKafka($cur_level);
+ if(@fail_packages > 0) {
+ while(@fail_packages) {
+ print "$_ ";
+ }
+ print "\n";
+ error("these @fail_packages packages build failed");
+ }
+ $cur_level++;
+ }
+ exit $ret;
+}
# only one package need to be built, do it directly
if ($noinit == 1 || $incremental == 1) {