SOLR-9037: replace multiple "/replication" strings with one static constant

This commit is contained in:
Christine Poerschke 2016-04-27 13:09:28 +01:00
parent 71c2c31ee2
commit ec071e2f84
12 changed files with 38 additions and 28 deletions

View File

@ -168,6 +168,8 @@ Other Changes
* SOLR-8929: Add an idea module for solr/server to enable launching start.jar (Scott Blum, Steve Rowe) * SOLR-8929: Add an idea module for solr/server to enable launching start.jar (Scott Blum, Steve Rowe)
* SOLR-9037: Replace multiple "/replication" strings with one static constant. (Christine Poerschke)
================== 6.0.0 ================== ================== 6.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -73,8 +73,6 @@ public class RecoveryStrategy extends Thread implements Closeable {
private static final int MAX_RETRIES = 500; private static final int MAX_RETRIES = 500;
private static final int STARTING_RECOVERY_DELAY = 5000; private static final int STARTING_RECOVERY_DELAY = 5000;
private static final String REPLICATION_HANDLER = "/replication";
public static interface RecoveryListener { public static interface RecoveryListener {
public void recovered(); public void recovered();
public void failed(); public void failed();
@ -143,12 +141,12 @@ public class RecoveryStrategy extends Thread implements Closeable {
commitOnLeader(leaderUrl); commitOnLeader(leaderUrl);
// use rep handler directly, so we can do this sync rather than async // use rep handler directly, so we can do this sync rather than async
SolrRequestHandler handler = core.getRequestHandler(REPLICATION_HANDLER); SolrRequestHandler handler = core.getRequestHandler(ReplicationHandler.PATH);
ReplicationHandler replicationHandler = (ReplicationHandler) handler; ReplicationHandler replicationHandler = (ReplicationHandler) handler;
if (replicationHandler == null) { if (replicationHandler == null) {
throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE,
"Skipping recovery, no " + REPLICATION_HANDLER + " handler found"); "Skipping recovery, no " + ReplicationHandler.PATH + " handler found");
} }
ModifiableSolrParams solrParams = new ModifiableSolrParams(); ModifiableSolrParams solrParams = new ModifiableSolrParams();

View File

@ -189,9 +189,9 @@ public class IndexFetcher {
if (masterUrl == null) if (masterUrl == null)
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"'masterUrl' is required for a slave"); "'masterUrl' is required for a slave");
if (masterUrl.endsWith("/replication")) { if (masterUrl.endsWith(ReplicationHandler.PATH)) {
masterUrl = masterUrl.substring(0, masterUrl.length()-12); masterUrl = masterUrl.substring(0, masterUrl.length()-12);
LOG.warn("'masterUrl' must be specified without the /replication suffix"); LOG.warn("'masterUrl' must be specified without the "+ReplicationHandler.PATH+" suffix");
} }
this.masterUrl = masterUrl; this.masterUrl = masterUrl;
@ -214,7 +214,7 @@ public class IndexFetcher {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set(COMMAND, CMD_INDEX_VERSION); params.set(COMMAND, CMD_INDEX_VERSION);
params.set(CommonParams.WT, JAVABIN); params.set(CommonParams.WT, JAVABIN);
params.set(CommonParams.QT, "/replication"); params.set(CommonParams.QT, ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
// TODO modify to use shardhandler // TODO modify to use shardhandler
@ -236,7 +236,7 @@ public class IndexFetcher {
params.set(COMMAND, CMD_GET_FILE_LIST); params.set(COMMAND, CMD_GET_FILE_LIST);
params.set(GENERATION, String.valueOf(gen)); params.set(GENERATION, String.valueOf(gen));
params.set(CommonParams.WT, JAVABIN); params.set(CommonParams.WT, JAVABIN);
params.set(CommonParams.QT, "/replication"); params.set(CommonParams.QT, ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
// TODO modify to use shardhandler // TODO modify to use shardhandler
@ -1583,7 +1583,7 @@ public class IndexFetcher {
// //the method is command=filecontent // //the method is command=filecontent
params.set(COMMAND, CMD_GET_FILE); params.set(COMMAND, CMD_GET_FILE);
params.set(GENERATION, Long.toString(indexGen)); params.set(GENERATION, Long.toString(indexGen));
params.set(CommonParams.QT, "/replication"); params.set(CommonParams.QT, ReplicationHandler.PATH);
//add the version to download. This is used to reserve the download //add the version to download. This is used to reserve the download
params.set(solrParamOutput, fileName); params.set(solrParamOutput, fileName);
if (useInternalCompression) { if (useInternalCompression) {
@ -1716,7 +1716,7 @@ public class IndexFetcher {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set(COMMAND, CMD_DETAILS); params.set(COMMAND, CMD_DETAILS);
params.set("slave", false); params.set("slave", false);
params.set(CommonParams.QT, "/replication"); params.set(CommonParams.QT, ReplicationHandler.PATH);
// TODO use shardhandler // TODO use shardhandler
try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) { try (HttpSolrClient client = new HttpSolrClient.Builder(masterUrl).withHttpClient(myHttpClient).build()) {

View File

@ -117,6 +117,8 @@ import static org.apache.solr.common.params.CommonParams.NAME;
*/ */
public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAware { public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAware {
public static final String PATH = "/replication";
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
SolrCore core; SolrCore core;

View File

@ -42,6 +42,7 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.handler.CheckBackupStatus; import org.apache.solr.handler.CheckBackupStatus;
import org.apache.solr.handler.ReplicationHandler;
import org.junit.Test; import org.junit.Test;
/** /**
@ -400,7 +401,7 @@ public class BasicDistributedZk2Test extends AbstractFullDistribZkTestBase {
// try a backup command // try a backup command
final HttpSolrClient client = (HttpSolrClient) shardToJetty.get(SHARD2).get(0).client.solrClient; final HttpSolrClient client = (HttpSolrClient) shardToJetty.get(SHARD2).get(0).client.solrClient;
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/replication"); params.set("qt", ReplicationHandler.PATH);
params.set("command", "backup"); params.set("command", "backup");
Path location = createTempDir(); Path location = createTempDir();
location = FilterPath.unwrap(location).toRealPath(); location = FilterPath.unwrap(location).toRealPath();

View File

@ -20,6 +20,7 @@ import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.ReplicationHandler;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
@ -140,7 +141,7 @@ public class DistribDocExpirationUpdateProcessorTest extends AbstractFullDistrib
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command","indexversion"); params.set("command","indexversion");
params.set("_trace","getIndexVersion"); params.set("_trace","getIndexVersion");
params.set("qt","/replication"); params.set("qt",ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
NamedList<Object> res = replicaRunner.client.solrClient.request(req); NamedList<Object> res = replicaRunner.client.solrClient.request(req);

View File

@ -18,6 +18,7 @@ package org.apache.solr.core;
import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.ExecutorUtil; import org.apache.solr.common.util.ExecutorUtil;
import org.apache.solr.handler.ReplicationHandler;
import org.apache.solr.handler.RequestHandlerBase; import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.component.QueryComponent; import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.handler.component.SpellCheckComponent; import org.apache.solr.handler.component.SpellCheckComponent;
@ -96,7 +97,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
++ihCount; assertEquals(pathToClassMap.get("/config"), "solr.SolrConfigHandler"); ++ihCount; assertEquals(pathToClassMap.get("/config"), "solr.SolrConfigHandler");
++ihCount; assertEquals(pathToClassMap.get("/export"), "solr.SearchHandler"); ++ihCount; assertEquals(pathToClassMap.get("/export"), "solr.SearchHandler");
++ihCount; assertEquals(pathToClassMap.get("/get"), "solr.RealTimeGetHandler"); ++ihCount; assertEquals(pathToClassMap.get("/get"), "solr.RealTimeGetHandler");
++ihCount; assertEquals(pathToClassMap.get("/replication"), "solr.ReplicationHandler"); ++ihCount; assertEquals(pathToClassMap.get(ReplicationHandler.PATH), "solr.ReplicationHandler");
++ihCount; assertEquals(pathToClassMap.get("/schema"), "solr.SchemaHandler"); ++ihCount; assertEquals(pathToClassMap.get("/schema"), "solr.SchemaHandler");
++ihCount; assertEquals(pathToClassMap.get("/sql"), "solr.SQLHandler"); ++ihCount; assertEquals(pathToClassMap.get("/sql"), "solr.SQLHandler");
++ihCount; assertEquals(pathToClassMap.get("/stream"), "solr.StreamHandler"); ++ihCount; assertEquals(pathToClassMap.get("/stream"), "solr.StreamHandler");

View File

@ -44,7 +44,7 @@ public class CheckBackupStatus extends SolrTestCaseJ4 {
} }
public void fetchStatus() throws IOException { public void fetchStatus() throws IOException {
String masterUrl = client.getBaseURL() + "/replication?command=" + ReplicationHandler.CMD_DETAILS; String masterUrl = client.getBaseURL() + ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_DETAILS;
response = client.getHttpClient().execute(new HttpGet(masterUrl), new BasicResponseHandler()); response = client.getHttpClient().execute(new HttpGet(masterUrl), new BasicResponseHandler());
if(pException.matcher(response).find()) { if(pException.matcher(response).find()) {
fail("Failed to create backup"); fail("Failed to create backup");

View File

@ -212,7 +212,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command","details"); params.set("command","details");
params.set("_trace","getDetails"); params.set("_trace","getDetails");
params.set("qt","/replication"); params.set("qt",ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
NamedList<Object> res = s.request(req); NamedList<Object> res = s.request(req);
@ -233,7 +233,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command","commits"); params.set("command","commits");
params.set("_trace","getCommits"); params.set("_trace","getCommits");
params.set("qt","/replication"); params.set("qt",ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
NamedList<Object> res = s.request(req); NamedList<Object> res = s.request(req);
@ -249,7 +249,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command","indexversion"); params.set("command","indexversion");
params.set("_trace","getIndexVersion"); params.set("_trace","getIndexVersion");
params.set("qt","/replication"); params.set("qt",ReplicationHandler.PATH);
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
NamedList<Object> res = s.request(req); NamedList<Object> res = s.request(req);
@ -281,6 +281,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
return getHttpSolrClient(adminUrl); return getHttpSolrClient(adminUrl);
} }
@Test
public void doTestHandlerPathUnchanged() throws Exception {
assertEquals("/replication", ReplicationHandler.PATH);
}
@Test @Test
public void doTestDetails() throws Exception { public void doTestDetails() throws Exception {
clearIndexWithReplication(); clearIndexWithReplication();
@ -453,7 +458,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
//jetty servers. //jetty servers.
private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException
{ {
String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + pCommand; String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH+"?command=" + pCommand;
URL u = new URL(masterUrl); URL u = new URL(masterUrl);
InputStream stream = u.openStream(); InputStream stream = u.openStream();
stream.close(); stream.close();
@ -612,8 +617,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
assertEquals(nDocs, masterQueryResult.getNumFound()); assertEquals(nDocs, masterQueryResult.getNumFound());
// index fetch // index fetch
String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=fetchindex&masterUrl="; String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH+"?command=fetchindex&masterUrl=";
masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication"; masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH;
URL url = new URL(masterUrl); URL url = new URL(masterUrl);
InputStream stream = url.openStream(); InputStream stream = url.openStream();
stream.close(); stream.close();
@ -927,7 +932,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
// check vs /replication?command=indexversion call // check vs /replication?command=indexversion call
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/replication"); params.set("qt", ReplicationHandler.PATH);
params.set("_trace", "assertVersions"); params.set("_trace", "assertVersions");
params.set("command", "indexversion"); params.set("command", "indexversion");
QueryRequest req = new QueryRequest(params); QueryRequest req = new QueryRequest(params);
@ -966,9 +971,9 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
InputStream stream; InputStream stream;
masterUrl = buildUrl(to.getLocalPort()) masterUrl = buildUrl(to.getLocalPort())
+ "/" + DEFAULT_TEST_CORENAME + "/" + DEFAULT_TEST_CORENAME
+ "/replication?wait=true&command=fetchindex&masterUrl=" + ReplicationHandler.PATH+"?wait=true&command=fetchindex&masterUrl="
+ buildUrl(from.getLocalPort()) + buildUrl(from.getLocalPort())
+ "/" + DEFAULT_TEST_CORENAME + "/replication"; + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH;
url = new URL(masterUrl); url = new URL(masterUrl);
stream = url.openStream(); stream = url.openStream();
stream.close(); stream.close();

View File

@ -274,7 +274,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
public static void runBackupCommand(JettySolrRunner masterJetty, String cmd, String params) throws IOException { public static void runBackupCommand(JettySolrRunner masterJetty, String cmd, String params) throws IOException {
String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME
+ "/replication?command=" + cmd + params; + ReplicationHandler.PATH+"?command=" + cmd + params;
InputStream stream = null; InputStream stream = null;
try { try {
URL url = new URL(masterUrl); URL url = new URL(masterUrl);
@ -297,7 +297,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
} }
public boolean fetchStatus() throws IOException { public boolean fetchStatus() throws IOException {
String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS; String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_DETAILS;
URL url; URL url;
InputStream stream = null; InputStream stream = null;
try { try {

View File

@ -232,7 +232,7 @@ public class TestRestoreCore extends SolrJettyTestBase {
private boolean fetchRestoreStatus() throws IOException { private boolean fetchRestoreStatus() throws IOException {
String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME +
"/replication?command=" + ReplicationHandler.CMD_RESTORE_STATUS; ReplicationHandler.PATH + "?command=" + ReplicationHandler.CMD_RESTORE_STATUS;
final Pattern pException = Pattern.compile("<str name=\"exception\">(.*?)</str>"); final Pattern pException = Pattern.compile("<str name=\"exception\">(.*?)</str>");
InputStream stream = null; InputStream stream = null;

View File

@ -190,14 +190,14 @@ public class TestRuleBasedAuthorizationPlugin extends SolrTestCaseJ4 {
((Map)rules.get("user-role")).put("cio","su"); ((Map)rules.get("user-role")).put("cio","su");
((List)rules.get("permissions")).add( makeMap("name", "all", "role", "su")); ((List)rules.get("permissions")).add( makeMap("name", "all", "role", "su"));
checkRules(makeMap("resource", "/replication", checkRules(makeMap("resource", ReplicationHandler.PATH,
"httpMethod", "POST", "httpMethod", "POST",
"userPrincipal", "tim", "userPrincipal", "tim",
"handler", new ReplicationHandler(), "handler", new ReplicationHandler(),
"collectionRequests", singletonList(new CollectionRequest("mycoll")) ) "collectionRequests", singletonList(new CollectionRequest("mycoll")) )
, FORBIDDEN, rules); , FORBIDDEN, rules);
checkRules(makeMap("resource", "/replication", checkRules(makeMap("resource", ReplicationHandler.PATH,
"httpMethod", "POST", "httpMethod", "POST",
"userPrincipal", "cio", "userPrincipal", "cio",
"handler", new ReplicationHandler(), "handler", new ReplicationHandler(),