mirror of https://github.com/apache/lucene.git
SOLR-2458: post.jar fails on non-XML updateHandlers
Fixed by doing the COMMIT through HTTP GET instead of posting XML "<commit/>" Other improvements: * Get help with -h and -help in addition to --help * Support -Doptimize=yes * More explicit error handling git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1139759 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
68dc477537
commit
b7c5e42675
|
@ -249,7 +249,25 @@ Documentation
|
||||||
|
|
||||||
======================= 3.x (not yet released) ================
|
======================= 3.x (not yet released) ================
|
||||||
|
|
||||||
(No changes)
|
New Features
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
* SOLR-2458: post.jar enhanced to handle JSON, CSV and <optimize> (janhoy)
|
||||||
|
|
||||||
|
Optimizations
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Other Changes
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Build
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
----------------------
|
||||||
|
|
||||||
================== 3.3.0 ==================
|
================== 3.3.0 ==================
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.solr.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
@ -39,10 +38,10 @@ import java.net.URL;
|
||||||
*/
|
*/
|
||||||
public class SimplePostTool {
|
public class SimplePostTool {
|
||||||
public static final String DEFAULT_POST_URL = "http://localhost:8983/solr/update";
|
public static final String DEFAULT_POST_URL = "http://localhost:8983/solr/update";
|
||||||
public static final String VERSION_OF_THIS_TOOL = "1.3";
|
public static final String VERSION_OF_THIS_TOOL = "1.4";
|
||||||
private static final String SOLR_OK_RESPONSE_EXCERPT = "<int name=\"status\">0</int>";
|
|
||||||
|
|
||||||
private static final String DEFAULT_COMMIT = "yes";
|
private static final String DEFAULT_COMMIT = "yes";
|
||||||
|
private static final String DEFAULT_OPTIMIZE = "no";
|
||||||
private static final String DEFAULT_OUT = "no";
|
private static final String DEFAULT_OUT = "no";
|
||||||
|
|
||||||
private static final String DEFAULT_DATA_TYPE = "application/xml";
|
private static final String DEFAULT_DATA_TYPE = "application/xml";
|
||||||
|
@ -64,23 +63,27 @@ public class SimplePostTool {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
info("version " + VERSION_OF_THIS_TOOL);
|
info("version " + VERSION_OF_THIS_TOOL);
|
||||||
|
|
||||||
if (0 < args.length && "-help".equals(args[0])) {
|
if (0 < args.length && ("-help".equals(args[0]) || "--help".equals(args[0]) || "-h".equals(args[0]))) {
|
||||||
System.out.println
|
System.out.println
|
||||||
("This is a simple command line tool for POSTing raw data to a Solr\n"+
|
("This is a simple command line tool for POSTing raw data to a Solr\n"+
|
||||||
"port. Data can be read from files specified as commandline args,\n"+
|
"port. Data can be read from files specified as commandline args,\n"+
|
||||||
"as raw commandline arg strings, or via STDIN.\n"+
|
"as raw commandline arg strings, or via STDIN.\n"+
|
||||||
"Examples:\n"+
|
"Examples:\n"+
|
||||||
" java -Ddata=files -jar post.jar *.xml\n"+
|
" java -jar post.jar *.xml\n"+
|
||||||
" java -Ddata=args -jar post.jar '<delete><id>42</id></delete>'\n"+
|
" java -Ddata=args -jar post.jar '<delete><id>42</id></delete>'\n"+
|
||||||
" java -Ddata=stdin -jar post.jar < hd.xml\n"+
|
" java -Ddata=stdin -jar post.jar < hd.xml\n"+
|
||||||
|
" java -Durl=http://localhost:8983/solr/update/csv -Dtype=text/csv -jar post.jar *.csv\n"+
|
||||||
|
" java -Durl=http://localhost:8983/solr/update/json -Dtype=application/json -jar post.jar *.json\n"+
|
||||||
|
" java -Durl=http://localhost:8983/solr/update/extract?literal.id=a -Dtype=application/pdf -jar post.jar a.pdf\n"+
|
||||||
"Other options controlled by System Properties include the Solr\n"+
|
"Other options controlled by System Properties include the Solr\n"+
|
||||||
"URL to POST to, the Content-Type of the data, whether a commit\n"+
|
"URL to POST to, the Content-Type of the data, whether a commit\n"+
|
||||||
"should be executed, and whether the response should be written\n"+
|
"or optimize should be executed, and whether the response should\n"+
|
||||||
"to STDOUT. These are the defaults for all System Properties...\n"+
|
"be written to STDOUT. These are the defaults for all System Properties:\n"+
|
||||||
" -Ddata=" + DEFAULT_DATA_MODE + "\n"+
|
" -Ddata=" + DEFAULT_DATA_MODE + "\n"+
|
||||||
" -Dtype=" + DEFAULT_DATA_TYPE + "\n"+
|
" -Dtype=" + DEFAULT_DATA_TYPE + "\n"+
|
||||||
" -Durl=" + DEFAULT_POST_URL + "\n"+
|
" -Durl=" + DEFAULT_POST_URL + "\n"+
|
||||||
" -Dcommit=" + DEFAULT_COMMIT + "\n"+
|
" -Dcommit=" + DEFAULT_COMMIT + "\n"+
|
||||||
|
" -Doptimize=" + DEFAULT_OPTIMIZE + "\n"+
|
||||||
" -Dout=" + DEFAULT_OUT + "\n");
|
" -Dout=" + DEFAULT_OUT + "\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +103,6 @@ public class SimplePostTool {
|
||||||
fatal("System Property 'data' is not valid for this tool: " + mode);
|
fatal("System Property 'data' is not valid for this tool: " + mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String doOut = System.getProperty("out", DEFAULT_OUT);
|
|
||||||
if ("yes".equals(System.getProperty("out", DEFAULT_OUT))) {
|
if ("yes".equals(System.getProperty("out", DEFAULT_OUT))) {
|
||||||
out = System.out;
|
out = System.out;
|
||||||
}
|
}
|
||||||
|
@ -109,14 +111,16 @@ public class SimplePostTool {
|
||||||
if (DATA_MODE_FILES.equals(mode)) {
|
if (DATA_MODE_FILES.equals(mode)) {
|
||||||
if (0 < args.length) {
|
if (0 < args.length) {
|
||||||
info("POSTing files to " + u + "..");
|
info("POSTing files to " + u + "..");
|
||||||
final int posted = t.postFiles(args, 0, out);
|
t.postFiles(args, 0, out);
|
||||||
|
} else {
|
||||||
|
info("No files specified. (Use -h for help)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (DATA_MODE_ARGS.equals(mode)) {
|
} else if (DATA_MODE_ARGS.equals(mode)) {
|
||||||
if (0 < args.length) {
|
if (0 < args.length) {
|
||||||
info("POSTing args to " + u + "..");
|
info("POSTing args to " + u + "..");
|
||||||
for (String a : args) {
|
for (String a : args) {
|
||||||
t.postData(t.stringToStream(a), null, out);
|
t.postData(SimplePostTool.stringToStream(a), null, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,10 +130,15 @@ public class SimplePostTool {
|
||||||
}
|
}
|
||||||
if ("yes".equals(System.getProperty("commit",DEFAULT_COMMIT))) {
|
if ("yes".equals(System.getProperty("commit",DEFAULT_COMMIT))) {
|
||||||
info("COMMITting Solr index changes..");
|
info("COMMITting Solr index changes..");
|
||||||
t.commit(out);
|
t.commit();
|
||||||
|
}
|
||||||
|
if ("yes".equals(System.getProperty("optimize",DEFAULT_OPTIMIZE))) {
|
||||||
|
info("Performing an OPTIMIZE..");
|
||||||
|
t.optimize();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(RuntimeException e) {
|
} catch(RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
fatal("RuntimeException " + e);
|
fatal("RuntimeException " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,8 +183,19 @@ public class SimplePostTool {
|
||||||
/**
|
/**
|
||||||
* Does a simple commit operation
|
* Does a simple commit operation
|
||||||
*/
|
*/
|
||||||
public void commit(OutputStream output) {
|
public void commit() {
|
||||||
postData(stringToStream("<commit/>"), null, output);
|
doGet(appendParam(solrUrl.toString(), "commit=true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a simple optimize operation
|
||||||
|
*/
|
||||||
|
public void optimize() {
|
||||||
|
doGet(appendParam(solrUrl.toString(), "optimize=true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String appendParam(String url, String param) {
|
||||||
|
return url + (url.indexOf('?')>0 ? "&" : "?") + param;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,6 +220,34 @@ public class SimplePostTool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a simple get on the given URL
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public void doGet(String url) {
|
||||||
|
try {
|
||||||
|
doGet(new URL(url));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
fatal("The specified URL "+url+" is not a valid URL. Please check");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a simple get on the given URL
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
public void doGet(URL url) {
|
||||||
|
try {
|
||||||
|
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
|
||||||
|
if (HttpURLConnection.HTTP_OK != urlc.getResponseCode()) {
|
||||||
|
fatal("Solr returned an error #" + urlc.getResponseCode() +
|
||||||
|
" " + urlc.getResponseMessage());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
fatal("An error occured posting data to "+url+". Please check that Solr is running.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads data from the data stream and posts it to solr,
|
* Reads data from the data stream and posts it to solr,
|
||||||
* writes to the response to output
|
* writes to the response to output
|
||||||
|
|
Loading…
Reference in New Issue