diff --git a/dev-tools/scripts/poll-mirrors.pl b/dev-tools/scripts/poll-mirrors.pl index a67b6b1baaa..3084adc46c5 100755 --- a/dev-tools/scripts/poll-mirrors.pl +++ b/dev-tools/scripts/poll-mirrors.pl @@ -1,118 +1,118 @@ -#!/usr/bin/perl -# -# poll-mirrors.pl -# -# This script is designed to poll download sites after posting a release -# and print out notice as each becomes available. The RM can use this -# script to delay the release announcement until the release can be -# downloaded. -# -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -use strict; -use warnings; -use Getopt::Long; -use LWP::Simple; -require LWP::Parallel::UserAgent; - -my $version; -my $interval = 300; -my $quiet = 0; - -my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval); - -my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]"; - -unless ($result) { - print STDERR $usage; - exit(1); -} -unless (defined($version) && $version =~ /\d+(?:\.\d+)+/) { - print STDERR "You must specify the release version.\n$usage"; - exit(1); -} - -my $previously_selected = select STDOUT; -$| = 1; # turn off buffering of STDOUT, so status is printed immediately -select $previously_selected; - -my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc"; -my $apache_mirrors_list_url = "http://www.apache.org/mirrors/"; -my $maven_url = "http://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc"; - -my $maven_available = 0; - -my @apache_mirrors = (); - -my $apache_mirrors_list_page = get($apache_mirrors_list_url); -if (defined($apache_mirrors_list_page)) { - # - # apache.dattatec.com  @ - # - # http - # 8 hours
- # 5 hours
- # ok - # - while ($apache_mirrors_list_page =~ m~(.*?)~gis) { - my $mirror_entry = $1; - next unless ($mirror_entry =~ m~\s*ok\s*\s*$~i); # skip mirrors with problems - if ($mirror_entry =~ m~~i) { - my $mirror_url = $1; - push @apache_mirrors, "$mirror_url/$apache_url_suffix"; - } - } -} else { - print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url"; - exit(1); -} - -my $num_apache_mirrors = $#apache_mirrors; -print "# Apache Mirrors: $num_apache_mirrors\n"; - -while (1) { - unless ($maven_available) { - my $content = get($maven_url); - $maven_available = defined($content); - } - @apache_mirrors = &check_mirrors; - my $num_downloadable_apache_mirrors - = $num_apache_mirrors - $#apache_mirrors; - - print "Available: "; - print "Maven Central; " if ($maven_available); - printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors, - $num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors); - last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors); - sleep($interval); -} - -sub check_mirrors { - my $agent = LWP::Parallel::UserAgent->new(); - $agent->timeout(30); - $agent->redirect(1); # follow redirects - $agent->register($_) for (@apache_mirrors); - my $entries = $agent->wait(); - my @not_yet_downloadable_apache_mirrors; - for my $entry (keys %$entries) { - my $response = $entries->{$entry}->response; - push @not_yet_downloadable_apache_mirrors, $response->request->uri - unless ($response->is_success); - } - return @not_yet_downloadable_apache_mirrors; -} +#!/usr/bin/perl +# +# poll-mirrors.pl +# +# This script is designed to poll download sites after posting a release +# and print out notice as each becomes available. The RM can use this +# script to delay the release announcement until the release can be +# downloaded. +# +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +use strict; +use warnings; +use Getopt::Long; +use LWP::Simple; +require LWP::Parallel::UserAgent; + +my $version; +my $interval = 300; +my $quiet = 0; + +my $result = GetOptions ("version=s" => \$version, "interval=i" => \$interval); + +my $usage = "$0 -v version [ -i interval (seconds; default: 300) ]"; + +unless ($result) { + print STDERR $usage; + exit(1); +} +unless (defined($version) && $version =~ /\d+(?:\.\d+)+/) { + print STDERR "You must specify the release version.\n$usage"; + exit(1); +} + +my $previously_selected = select STDOUT; +$| = 1; # turn off buffering of STDOUT, so status is printed immediately +select $previously_selected; + +my $apache_url_suffix = "lucene/java/$version/lucene-$version.tgz.asc"; +my $apache_mirrors_list_url = "http://www.apache.org/mirrors/"; +my $maven_url = "http://repo2.maven.org/maven2/org/apache/lucene/lucene-core/$version/lucene-core-$version.pom.asc"; + +my $maven_available = 0; + +my @apache_mirrors = (); + +my $apache_mirrors_list_page = get($apache_mirrors_list_url); +if (defined($apache_mirrors_list_page)) { + # + # apache.dattatec.com  @ + # + # http + # 8 hours
+ # 5 hours
+ # ok + # + while ($apache_mirrors_list_page =~ m~(.*?)~gis) { + my $mirror_entry = $1; + next unless ($mirror_entry =~ m~\s*ok\s*\s*$~i); # skip mirrors with problems + if ($mirror_entry =~ m~~i) { + my $mirror_url = $1; + push @apache_mirrors, "$mirror_url/$apache_url_suffix"; + } + } +} else { + print STDERR "Error fetching Apache mirrors list $apache_mirrors_list_url"; + exit(1); +} + +my $num_apache_mirrors = $#apache_mirrors; +print "# Apache Mirrors: $num_apache_mirrors\n"; + +while (1) { + unless ($maven_available) { + my $content = get($maven_url); + $maven_available = defined($content); + } + @apache_mirrors = &check_mirrors; + my $num_downloadable_apache_mirrors + = $num_apache_mirrors - $#apache_mirrors; + + print "Available: "; + print "Maven Central; " if ($maven_available); + printf "%d/%d Apache Mirrors (%0.1f%%)\n", $num_downloadable_apache_mirrors, + $num_apache_mirrors, ($num_downloadable_apache_mirrors*100/$num_apache_mirrors); + last if ($maven_available && $num_downloadable_apache_mirrors == $num_apache_mirrors); + sleep($interval); +} + +sub check_mirrors { + my $agent = LWP::Parallel::UserAgent->new(); + $agent->timeout(30); + $agent->redirect(1); # follow redirects + $agent->register($_) for (@apache_mirrors); + my $entries = $agent->wait(); + my @not_yet_downloadable_apache_mirrors; + for my $entry (keys %$entries) { + my $response = $entries->{$entry}->response; + push @not_yet_downloadable_apache_mirrors, $response->request->uri + unless ($response->is_success); + } + return @not_yet_downloadable_apache_mirrors; +}