Ignore:
Timestamp:
2017-03-02T23:28:38+13:00 (7 years ago)
Author:
davidb
Message:

shift to using solr-base-url and a specified solr-collection

Location:
other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/PerVolumeJSON.java

    r31450 r31451  
    3232    protected String _langmap_directory;
    3333   
    34     protected String _solr_url;
     34    protected final ArrayList<String> _solr_endpoints;
     35    protected final int _solr_endpoints_len;
     36   
     37    //protected String _solr_url;
    3538    protected String _output_dir;
    3639   
     
    4447
    4548    public PerVolumeJSON(String input_dir, String whitelist_filename, String langmap_directory,
    46                          String solr_url, String output_dir, int verbosity,
     49                         ArrayList<String> solr_endpoints, String output_dir, int verbosity,
    4750                         boolean icu_tokenize, boolean strict_file_io)
    4851    {
     
    5356        _langmap_directory = langmap_directory;
    5457       
    55         _solr_url   = solr_url;
     58        _solr_endpoints = solr_endpoints;
     59        _solr_endpoints_len = solr_endpoints.size();
     60       
     61        //_solr_url   = solr_url;
    5662        _output_dir = output_dir;
    5763        _verbosity  = verbosity;
     
    7783        int ef_num_pages = 0;
    7884
     85        String solr_url = null;
     86        if (_solr_endpoints_len > 0) {
     87            int random_choice = (int)(_solr_endpoints_len * Math.random());
     88            solr_url = _solr_endpoints.get(random_choice);
     89        }
     90       
    7991        try {
    8092
     
    125137
    126138
    127                         if (_solr_url != null) {
     139                        if (solr_url != null) {
    128140                            if ((_verbosity >=2) && (i==20)) {
    129141                                System.out.println("==================");
    130                                 System.out.println("Posting to: " + _solr_url);
     142                                System.out.println("Posting to: " + solr_url);
    131143                                System.out.println("==================");
    132144                            }
    133                             SolrDocJSON.postSolrDoc(_solr_url, solr_add_doc_json);
     145                            SolrDocJSON.postSolrDoc(solr_url, solr_add_doc_json);
    134146                        }
    135147
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/ProcessForSolrIngest.java

    r31450 r31451  
    2727   
    2828    protected String _input_dir;
    29     //protected String _json_list_filename;
     29    protected String _solr_base_url;
     30    protected String _solr_collection;
     31   
    3032    protected String _whitelist_filename;
    3133    protected String _langmap_directory;
    3234   
    33     protected String _solr_url;
     35    //protected String _solr_url;
    3436    protected String _output_dir;
    3537   
    3638    protected int    _verbosity;
    3739
    38     public ProcessForSolrIngest(String input_dir, /*String json_list_filename,*/
    39                                 String solr_url, String output_dir, int verbosity)
     40    public ProcessForSolrIngest(String input_dir, String solr_collection,
     41                                String solr_base_url, String output_dir, int verbosity)
    4042    {
    4143        _input_dir = input_dir;
    42         //_json_list_filename = (json_list_filename != null) ? json_list_filename : input_dir;
    43 
     44        _solr_collection = solr_collection;
     45       
    4446        boolean use_whitelist = Boolean.getBoolean("wcsa-ef-ingest.use-whitelist");
    4547        _whitelist_filename = (use_whitelist) ?  System.getProperty("wcsa-ef-ingest.whitelist-filename") : null;
     
    4951       
    5052       
    51         _solr_url   = solr_url;
     53        _solr_base_url   = solr_base_url;
    5254        _output_dir = output_dir;
    5355        _verbosity  = verbosity;
     
    5759    {
    5860        String spark_app_name = "[" + exec_mode + "] Extract Features: Process for Solr Ingest";
    59         //spark_app_name += " [" + _json_list_filename + "]";
    60 
    61         if (_solr_url != null) {
    62             spark_app_name += " solr_url=" + _solr_url;
     61        spark_app_name += " [" + _solr_collection + "]";
     62
     63        if (_solr_base_url != null) {
     64            spark_app_name += " solr_base_url=" + _solr_base_url;
    6365        }
    6466       
     
    7072    }
    7173   
    72     public ArrayList<String> extrapolateSolrEndpoints()
     74    public ArrayList<String> extrapolateSolrEndpoints(String solr_collection)
    7375    {
    7476        ArrayList<String> solr_endpoints = new ArrayList<String>();
    7577       
    76         if (_solr_url != null) {
     78        if (_solr_base_url != null) {
     79            String solr_url = _solr_base_url + "/" + solr_collection + "/update";
     80           
    7781            String solr_cloud_nodes = System.getProperty("wcsa-ef-ingest.solr-cloud-nodes",null);
    7882            if (solr_cloud_nodes != null) {
    7983                String [] cloud_nodes = solr_cloud_nodes.split(",");
    8084                for (String cn : cloud_nodes) {
    81                     String solr_endpoint = _solr_url.replaceFirst("//.*?:\\d+/", "//"+cn+"/");
     85                    String solr_endpoint = solr_url.replaceFirst("//.*?:\\d+/", "//"+cn+"/");
    8286                    solr_endpoints.add(solr_endpoint);
    8387                }
    8488            }
    8589            else {
    86                 solr_endpoints.add(_solr_url);
     90                solr_endpoints.add(solr_url);
    8791            }
    8892        }
     
    109113        boolean strict_file_io = Boolean.getBoolean("wcsa-ef-ingest.strict-file-io");
    110114       
     115        ArrayList<String> solr_endpoints = extrapolateSolrEndpoints(_solr_collection);
     116       
    111117        System.out.println("*** away to create PerVolumeJSON class, _langmap_directory = " + _langmap_directory);
    112118        PerVolumeJSON per_vol_json = new PerVolumeJSON(_input_dir,_whitelist_filename, _langmap_directory,
    113                                                        _solr_url,_output_dir,_verbosity,
     119                                                       solr_endpoints,_output_dir,_verbosity,
    114120                                                       icu_tokenize,strict_file_io);
    115121
     
    250256    public static void print_usage(HelpFormatter formatter, Options options)
    251257    {
    252         formatter.printHelp("RUN.bash [options] input-dir json-filelist.txt", options);
     258        formatter.printHelp("RUN.bash [options] input-dir solr-collection", options);
    253259    }
    254260   
     
    271277        options.addOption(output_dir_opt);
    272278       
    273         Option solr_url_opt = new Option("u", "solr-url", true,
    274                 "If specified, the URL to post the Solr JSON data to");
    275         solr_url_opt.setRequired(false);
    276         options.addOption(solr_url_opt);
     279        Option solr_base_url_opt = new Option("u", "solr-base-url", true,
     280                "If specified, the base URL to post the Solr JSON data to");
     281        solr_base_url_opt.setRequired(false);
     282        options.addOption(solr_base_url_opt);
    277283       
    278284        Option read_only_opt = new Option("r", "read-only", false,
     
    304310   
    305311        String output_dir = cmd.getOptionValue("output-dir",null);
    306         String solr_url   = cmd.getOptionValue("solr-url",null);
     312        String solr_base_url   = cmd.getOptionValue("solr-base-url",null);
    307313        boolean read_only   = cmd.hasOption("read-only");
    308314       
    309315        String[] filtered_args = cmd.getArgs();
    310316
    311         if (filtered_args.length != 1) {
     317        if (filtered_args.length != 2) {
    312318            print_usage(formatter,options);
    313319            System.exit(1);
     
    331337        }
    332338       
    333         if (!read_only && ((output_dir == null) && (solr_url==null))) {
    334             System.err.println("Need to specify either --solr-url or --output-dir otherwise generated files are not ingested/saved");
     339        if (!read_only && ((output_dir == null) && (solr_base_url==null))) {
     340            System.err.println("Need to specify either --solr-base-url or --output-dir otherwise generated files are not ingested/saved");
    335341            print_usage(formatter,options);
    336342            System.exit(1);
     
    339345            // For this case, need to ensure solr-url and output-dir are null
    340346            output_dir = null;
    341             solr_url = null;
     347            solr_base_url = null;
    342348        }
    343349       
    344350        String input_dir  = filtered_args[0];
    345         //String json_list_filename = filtered_args[1];
     351        String solr_collection = filtered_args[1];
    346352       
    347353        ProcessForSolrIngest prep_for_ingest
    348             = new ProcessForSolrIngest(input_dir,/*json_list_filename,*/solr_url,output_dir,verbosity);
     354            = new ProcessForSolrIngest(input_dir,solr_collection,solr_base_url,output_dir,verbosity);
    349355           
    350356        prep_for_ingest.execPerVolumeSequenceFile();
Note: See TracChangeset for help on using the changeset viewer.