Ignore:
Timestamp:
2017-03-10T22:03:47+13:00 (7 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.