Changeset 31490


Ignore:
Timestamp:
03/10/17 22:03:47 (4 years ago)
Author:
ak19
Message:
  1. Fix to issue of a tomcat host/port change not propagating to solr host/port change when rebuilding a solr collection after tomcat host/port change. The change to tomcat server props need to be made after gs3-setup.sh was already run in the terminal earlier, to encouner the problem upon solr build. The bug was reproduced on Linux, and the fix for it also tested on Linux. Still need to test fix out on Windows. 2. Simultaneously made http protocol used in solr more robust to whether it's http or https.
Location:
gs3-extensions/solr/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl

    r29288 r31490  
    6767
    6868  # Now start up the solr-post command
    69   &solrutil::open_post_pipe($core);
     69  &solrutil::open_post_pipe($core, $solr_server->get_solr_base_url());
    7070}
    7171
  • gs3-extensions/solr/trunk/src/perllib/solrserver.pm

    r30534 r31490  
    4343    $self->{'server_explicitly_started'} = undef;
    4444
    45     my $server_port = $ENV{'SOLR_PORT'};
    46     my $server_host = $ENV{'SOLR_HOST'};
    47     my $base_url = "http://$server_host:$server_port/solr/";
    48     my $admin_url = "http://$server_host:$server_port/solr/admin/cores";
    49    
    50     $self->{'base-url'} = $base_url;
    51     $self->{'admin-url'} = $admin_url;
     45    # set SOLR_HOST and SOLR_PORT env vars (tomcat host and port, if not using jetty)
     46    # by calling ant get-default-solr-servlet if possible. Else fallback on whatever the existing env vars are.
     47    # tomcat host and port would have been set up in the env as SOLR_HOST and SOLR_PORT
     48    # In case someone changed the tomcat host/port, we want to update the solr server variables too
     49    my $solr_url = &solrutil::get_solr_servlet_url();   
     50    # get the url parts, though we won't be using most of them
     51    my ($protocol, $server_host, $server_port, $servlet_name) = &solrutil::get_solr_url_parts($solr_url);
     52   
     53    # set the solr server env vars to what was discovered, so that any other old perl code
     54    # dependent on these env vars will have any changes propagated.
     55    # (All perl code referencing these env vars should already be updated, but still...)
     56    $ENV{'SOLR_HOST'} = $server_host;
     57    $ENV{'SOLR_PORT'} = $server_port;
     58   
     59    $self->{'base-url'} = $solr_url; # e.g. of the form http://localhost:8383/solr
     60    $self->{'admin-url'} = "$solr_url/admin/cores";
    5261
    5362    return bless $self, $class;
     63}
     64
     65sub get_solr_base_url {
     66    my $self = shift (@_);
     67    return $self->{'base-url'};
    5468}
    5569
  • gs3-extensions/solr/trunk/src/perllib/solrutil.pm

    r31168 r31490  
    5959}
    6060
     61# The get-solr-servlet-url ant target can be run from anywhere by specifying the
     62# location of GS3's ant build.xml buildfile.
     63# GSDL3SRCHOME will be set for GS3 by gs3-setup.sh.
     64# Based on servercontrol::get_library_URL.
     65sub get_solr_servlet_url {
     66    # Set up fall backs, incl. old way of using solr host and port values that's already in the environment
     67    my $solr_url = "http://".$ENV{'SOLR_HOST'}.$ENV{'SOLR_PORT'}."/solr"; # fallback to default
     68
     69    my $perl_command = "ant -buildfile \"$ENV{'GSDL3SRCHOME'}/build.xml\" get-solr-servlet-url";
     70   
     71    if (open(PIN, "$perl_command |")) {
     72    while (defined (my $perl_output_line = <PIN>)) {
     73        if($perl_output_line =~ m@(https?):\/\/(\S*)@) { # grab all the non-whitespace chars
     74        $solr_url="$1://".$2; # preserve the http protocol
     75        }
     76    }
     77    close(PIN);
     78   
     79    #print STDERR "XXXXXXXXXX SOLR URL: $solr_url\n";
     80
     81    } else {
     82    print STDERR "*** ERROR IN solrutil::get_solr_servlet_url:\n";
     83    print STDERR "    Failed to run $perl_command to work out GS3's solr URL\n";
     84    print STDERR "    falling back to using original solr_URL: $solr_url\n";
     85    }
     86
     87    return $solr_url;
     88}
     89
     90# Given the solr base url (e.g. http://localhost:8383/solr by default), this function
     91# returns the url's parts: protocol, host, port, solr servlet
     92sub get_solr_url_parts {
     93    my $solr_url = shift (@_);
     94
     95    # Set up fall backs, incl. old way of using solr host and port values that's already in the environment
     96    my ($protocol, $server_host, $server_port, $servlet_name)
     97    = ("http://", $ENV{'SOLR_HOST'}, $ENV{'SOLR_PORT'}, "solr");
     98
     99   
     100    # http://stackoverflow.com/questions/8206135/storing-regex-result-in-a-new-variable
     101    if($solr_url =~ m@(https?)://([^:]*):([0-9]*)/(.*)$@) { # m@https?://([^:]*):([^/])/(.*)@) {
     102   
     103    ($protocol, $server_host, $server_port, $servlet_name) = ($1, $2, $3, $4);
     104   
     105    #print STDERR "XXXXXXXXXX PROTOCOL: $protocol, SOLR_HOST: $server_host, SOLR_PORT: $server_port, servlet: $servlet_name\n";
     106
     107    } else {
     108    print STDERR "*** WARNING: in solrutil::get_solr_url_parts(): solr servlet URL not in expected format\n";
     109    }
     110
     111    return ($protocol, $server_host, $server_port, $servlet_name);
     112}
    61113
    62114
    63115sub open_post_pipe
    64116{
    65     my ($core) = @_;
     117    my ($core, $solr_base_url) = @_;
    66118
    67119    my $search_path = get_search_path();
     
    72124    my $full_post_jar   = solrutil::locate_file($search_path,$post_jar);
    73125   
    74     my $server_port = $ENV{'SOLR_PORT'}; # tomcat
    75     my $server_host = $ENV{'SOLR_HOST'};
    76    
    77126    # Now run solr-post command
    78     my $post_props = "-Durl=http://$server_host:$server_port/solr/$core/update";
     127    my $post_props = "-Durl=$solr_base_url/$core/update"; # robustness of protocol is taken care of too
     128
    79129    $post_props .= " -Ddata=stdin";
    80130    $post_props .= " -Dcommit=yes";
Note: See TracChangeset for help on using the changeset viewer.