~percona-toolkit-dev/percona-toolkit/pxc-pt-slave-find-tests

« back to all changes in this revision

Viewing changes to bin/pt-kill

Merged OptionParser-remove-optional_value & updated modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
      'default'    => 1,
91
91
      'cumulative' => 1,
92
92
      'negatable'  => 1,
93
 
      'value_is_optional' => 1,
94
93
   );
95
94
 
96
95
   my $self = {
332
331
            $opt->{short} = undef;
333
332
         }
334
333
 
335
 
         $opt->{is_negatable}   = $opt->{spec} =~ m/!/        ? 1 : 0;
336
 
         $opt->{is_cumulative}  = $opt->{spec} =~ m/\+/       ? 1 : 0;
337
 
         $opt->{optional_value} = $opt->{spec} =~ m/:/        ? 1 : 0;
338
 
         $opt->{is_required}    = $opt->{desc} =~ m/required/ ? 1 : 0;
 
334
         $opt->{is_negatable}  = $opt->{spec} =~ m/!/        ? 1 : 0;
 
335
         $opt->{is_cumulative} = $opt->{spec} =~ m/\+/       ? 1 : 0;
 
336
         $opt->{is_required}   = $opt->{desc} =~ m/required/ ? 1 : 0;
339
337
 
340
338
         $opt->{group} ||= 'default';
341
339
         $self->{groups}->{ $opt->{group} }->{$long} = 1;
471
469
   if ( $opt->{is_cumulative} ) {
472
470
      $opt->{value}++;
473
471
   }
474
 
   elsif ( !($opt->{optional_value} && !$val) ) {
 
472
   else {
475
473
      $opt->{value} = $val;
476
474
   }
477
475
   $opt->{got} = 1;
1012
1010
sub _parse_attribs {
1013
1011
   my ( $self, $option, $attribs ) = @_;
1014
1012
   my $types = $self->{types};
1015
 
   my $eq    = $attribs->{'value_is_optional'} ? ':' : '=';
1016
1013
   return $option
1017
1014
      . ($attribs->{'short form'} ? '|' . $attribs->{'short form'}   : '' )
1018
1015
      . ($attribs->{'negatable'}  ? '!'                              : '' )
1019
1016
      . ($attribs->{'cumulative'} ? '+'                              : '' )
1020
 
      . ($attribs->{'type'}       ? $eq . $types->{$attribs->{type}} : '' );
 
1017
      . ($attribs->{'type'}       ? '=' . $types->{$attribs->{type}} : '' );
1021
1018
}
1022
1019
 
1023
1020
sub _parse_synopsis {
5844
5841
};
5845
5842
 
5846
5843
sub version_check {
5847
 
   my $args        = pop @_;
5848
 
   my (@instances) = @_;
 
5844
   my %args      = @_;
 
5845
   my @instances = $args{instances} ? @{ $args{instances} } : ();
5849
5846
 
5850
5847
   if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
5851
 
      print STDERR '--version-check is disabled by the PERCONA_VERSION_CHECK ',
 
5848
      warn '--version-check is disabled by the PERCONA_VERSION_CHECK ',
5852
5849
                   "environment variable.\n\n";
5853
5850
      return;
5854
5851
   }
 
5852
 
 
5853
   $args{protocol} ||= 'https';
 
5854
   my @protocols = $args{protocol} eq 'auto'
 
5855
                 ? qw(https http)
 
5856
                 : $args{protocol};
5855
5857
   
5856
5858
   my $instances_to_check = [];
5857
5859
   my $time               = int(time());
5866
5868
      ($time_to_check, $instances_to_check)
5867
5869
         = time_to_check($check_time_file, \@instances, $time);
5868
5870
      if ( !$time_to_check ) {
5869
 
         print STDERR 'It is not time to --version-check again; ',
 
5871
         warn 'It is not time to --version-check again; ',
5870
5872
                      "only 1 check per day.\n\n";
5871
5873
         return;
5872
5874
      }
5873
5875
 
5874
 
      my $protocol = $args->{protocol} || 'https';
5875
 
      my $advice = pingback(
5876
 
         url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
5877
 
         instances => $instances_to_check,
5878
 
         protocol  => $args->{protocol},
5879
 
      );
 
5876
      my $advice;
 
5877
      my $e;
 
5878
      for my $protocol ( @protocols ) {
 
5879
         $advice = eval { pingback(
 
5880
            url       => $ENV{PERCONA_VERSION_CHECK_URL} || "$protocol://v.percona.com",
 
5881
            instances => $instances_to_check,
 
5882
            protocol  => $protocol,
 
5883
         ) };
 
5884
         last if !$advice && !$EVAL_ERROR;
 
5885
         $e ||= $EVAL_ERROR;
 
5886
      }
5880
5887
      if ( $advice ) {
5881
5888
         print "# Percona suggests these upgrades:\n";
5882
5889
         print join("\n", map { "#   * $_" } @$advice), "\n\n";
5883
5890
      }
5884
5891
      else {
 
5892
         die $e if $e;
5885
5893
         print "# No suggestions at this time.\n\n";
5886
5894
         ($ENV{PTVCDEBUG} || PTDEBUG )
5887
5895
            && _d('--version-check worked, but there were no suggestions');
5907
5915
 
5908
5916
   my ($instances, $ua, $vc) = @args{qw(instances ua VersionCheck)};
5909
5917
 
5910
 
   $ua ||= HTTPMicro->new( timeout => 2 );
 
5918
   $ua ||= HTTPMicro->new( timeout => 5 );
5911
5919
   $vc ||= VersionCheck->new();
5912
5920
 
5913
5921
   my $response = $ua->request('GET', $url);
6123
6131
   return $client_response;
6124
6132
}
6125
6133
 
 
6134
sub validate_options {
 
6135
   my ($o) = @_;
 
6136
 
 
6137
   return if !$o->got('version-check');
 
6138
 
 
6139
   my $value  = $o->get('version-check');
 
6140
   my @values = split /, /,
 
6141
                $o->read_para_after(__FILE__, qr/MAGIC_version_check/);
 
6142
   chomp(@values);
 
6143
                
 
6144
   return if grep { $value eq $_ } @values;
 
6145
   $o->save_error("--version-check invalid value $value.  Accepted values are "
 
6146
                . join(", ", @values[0..$#values-1]) . " and $values[-1]" );
 
6147
}
 
6148
 
6126
6149
sub _d {
6127
6150
   my ($package, undef, $line) = caller 0;
6128
6151
   @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
6206
6229
      $o->save_error("Invalid value for --victims: $victims");
6207
6230
   }
6208
6231
 
 
6232
   Pingback::validate_options($o);
 
6233
   
6209
6234
   $o->usage_or_errors();
6210
6235
 
6211
6236
   # ########################################################################
6486
6511
   # ########################################################################
6487
6512
   # Do the version-check
6488
6513
   # ########################################################################
6489
 
   if ( $o->got('version-check') && (!$o->has('quiet') || !$o->get('quiet')) ) {
 
6514
   if ( $o->get('version-check') ne 'off' && (!$o->has('quiet') || !$o->get('quiet')) ) {
6490
6515
      Pingback::version_check(
6491
 
         ($dbh ? { dbh => $dbh, dsn => $cxn->dsn() } : ()),
6492
 
         { protocol => $o->get('version-check') },
 
6516
         instances => [ ($dbh ? { dbh => $dbh, dsn => $cxn->dsn() } : ()) ],
 
6517
         protocol  => $o->get('version-check'),
6493
6518
      );
6494
6519
   }
6495
6520
 
7220
7245
 
7221
7246
=item --version-check
7222
7247
 
7223
 
type: string; value_is_optional: yes; default: https
 
7248
type: string; default: off
7224
7249
 
7225
7250
Send program versions to Percona and print suggested upgrades and problems.
7226
 
 
7227
 
If specified without a value, it will use https by default; However, this
7228
 
might fail if C<IO::Socket::SSL> is not installed on your system, in which
7229
 
case you may choose to use C<--version-check http>, which will forgo
7230
 
encryption but should work out of the box.
 
7251
Possible values for --version-check:
 
7252
 
 
7253
=for comment ignore-pt-internal-value
 
7254
MAGIC_version_check
 
7255
 
 
7256
https, http, auto, off
 
7257
 
 
7258
C<auto> first tries using C<https>, and resorts to C<http> if that fails.
 
7259
Keep in mind that C<https> might not be available if
 
7260
C<IO::Socket::SSL> is not installed on your system, although
 
7261
C<--version-check http> should work everywhere.
7231
7262
 
7232
7263
The version check feature causes the tool to send and receive data from
7233
7264
Percona over the web.  The data contains program versions from the local