mirror of https://github.com/apache/lucene.git
SOLR-6840: Remove support for old-style solr.xml
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1652995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb558014e5
commit
e61cd9654b
|
@ -183,6 +183,10 @@ Upgrading from Solr 4.x
|
||||||
* Due to changes in the underlying commons-codec package, users of the BeiderMorseFilterFactory
|
* Due to changes in the underlying commons-codec package, users of the BeiderMorseFilterFactory
|
||||||
will need to rebuild their indexes after upgrading. See LUCENE-6058 for more details.
|
will need to rebuild their indexes after upgrading. See LUCENE-6058 for more details.
|
||||||
|
|
||||||
|
* The 'old-style' solr.xml format is no longer supported, and cores must be
|
||||||
|
defined using core.properties files. See
|
||||||
|
https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml
|
||||||
|
|
||||||
Detailed Change List
|
Detailed Change List
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
@ -738,6 +742,8 @@ Other Changes
|
||||||
* SOLR-6981: Add a delete action to the bin/solr script to allow deleting of cores /
|
* SOLR-6981: Add a delete action to the bin/solr script to allow deleting of cores /
|
||||||
collections (with delete collection config directory from ZK) (Timothy Potter)
|
collections (with delete collection config directory from ZK) (Timothy Potter)
|
||||||
|
|
||||||
|
* SOLR-6840: Remove support for old-style solr.xml (Erick Erickson, Alan Woodward)
|
||||||
|
|
||||||
================== 4.10.3 ==================
|
================== 4.10.3 ==================
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
|
|
|
@ -20,14 +20,10 @@
|
||||||
solr.xml mimicking the old default solr.xml
|
solr.xml mimicking the old default solr.xml
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<solr persistent="false">
|
<solr>
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1"
|
|
||||||
host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"
|
|
||||||
zkClientTimeout="${zkClientTimeout:15000}">
|
|
||||||
<core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>
|
|
||||||
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
<str name="urlScheme">${urlScheme:}</str>
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
</shardHandlerFactory>
|
</shardHandlerFactory>
|
||||||
</cores>
|
|
||||||
</solr>
|
</solr>
|
||||||
|
|
|
@ -20,13 +20,8 @@
|
||||||
solr.xml mimicking the old default solr.xml
|
solr.xml mimicking the old default solr.xml
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<solr persistent="false">
|
<solr>
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1"
|
|
||||||
host="${host:}" hostPort="${hostPort:}" hostContext="${hostContext:}"
|
|
||||||
zkClientTimeout="${zkClientTimeout:15000}">
|
|
||||||
<core name="collection1" shard="${shard:}" collection="${collection:collection1}" instanceDir="collection1"/>
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
<str name="urlScheme">${urlScheme:}</str>
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
</shardHandlerFactory>
|
</shardHandlerFactory>
|
||||||
</cores>
|
|
||||||
</solr>
|
</solr>
|
|
@ -16,9 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.handler.dataimport;
|
package org.apache.solr.handler.dataimport;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||||
|
@ -32,6 +29,10 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for ContentStreamDataSource
|
* Test for ContentStreamDataSource
|
||||||
*
|
*
|
||||||
|
@ -67,7 +68,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
|
||||||
params.set("command", "full-import");
|
params.set("command", "full-import");
|
||||||
params.set("clean", "false");
|
params.set("clean", "false");
|
||||||
req.setParams(params);
|
req.setParams(params);
|
||||||
HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr"));
|
HttpSolrClient solrClient = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"));
|
||||||
try {
|
try {
|
||||||
solrClient.request(req);
|
solrClient.request(req);
|
||||||
ModifiableSolrParams qparams = new ModifiableSolrParams();
|
ModifiableSolrParams qparams = new ModifiableSolrParams();
|
||||||
|
@ -90,7 +91,7 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
|
||||||
"clean", "false", UpdateParams.COMMIT, "false",
|
"clean", "false", UpdateParams.COMMIT, "false",
|
||||||
UpdateParams.COMMIT_WITHIN, "1000");
|
UpdateParams.COMMIT_WITHIN, "1000");
|
||||||
req.setParams(params);
|
req.setParams(params);
|
||||||
HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr"));
|
HttpSolrClient solrServer = new HttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"));
|
||||||
solrServer.request(req);
|
solrServer.request(req);
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
ModifiableSolrParams queryAll = params("q", "*");
|
ModifiableSolrParams queryAll = params("q", "*");
|
||||||
|
@ -168,6 +169,8 @@ public class TestContentStreamDataSource extends AbstractDataImportHandlerTestCa
|
||||||
FileUtils.copyFile(getFile(getSchemaFile()), f);
|
FileUtils.copyFile(getFile(getSchemaFile()), f);
|
||||||
f = new File(confDir, "data-config.xml");
|
f = new File(confDir, "data-config.xml");
|
||||||
FileUtils.copyFile(getFile(CONF_DIR + "dataconfig-contentstream.xml"), f);
|
FileUtils.copyFile(getFile(CONF_DIR + "dataconfig-contentstream.xml"), f);
|
||||||
|
|
||||||
|
Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,6 @@ package org.apache.solr.handler.dataimport;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
|
@ -38,6 +30,15 @@ import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End-to-end test of SolrEntityProcessor. "Real" test using embedded Solr
|
* End-to-end test of SolrEntityProcessor. "Real" test using embedded Solr
|
||||||
*/
|
*/
|
||||||
|
@ -94,7 +95,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSourceUrl() {
|
private String getSourceUrl() {
|
||||||
return buildUrl(jetty.getLocalPort(), "/solr");
|
return buildUrl(jetty.getLocalPort(), "/solr/collection1");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: fix this test to close its directories
|
//TODO: fix this test to close its directories
|
||||||
|
@ -332,6 +333,8 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
|
||||||
FileUtils.copyFile(getFile(getSchemaFile()), f);
|
FileUtils.copyFile(getFile(getSchemaFile()), f);
|
||||||
f = new File(confDir, "data-config.xml");
|
f = new File(confDir, "data-config.xml");
|
||||||
FileUtils.copyFile(getFile(SOURCE_CONF_DIR + "dataconfig-contentstream.xml"), f);
|
FileUtils.copyFile(getFile(SOURCE_CONF_DIR + "dataconfig-contentstream.xml"), f);
|
||||||
|
|
||||||
|
Files.createFile(confDir.toPath().resolve("../core.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
|
|
@ -16,18 +16,25 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!--
|
<solr>
|
||||||
All (relative) paths are relative to the installation path
|
|
||||||
|
<solrcloud>
|
||||||
persistent: Save changes made via the API to this file
|
<int name="hostPort">${hostPort:8983}</int>
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
<str name="hostContext">${hostContext:solr}</str>
|
||||||
-->
|
<int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>
|
||||||
<solr persistent="${solr.xml.persist:false}">
|
<str name="host">127.0.0.1</str>
|
||||||
|
</solrcloud>
|
||||||
|
|
||||||
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
|
<int name="socketTimeout">${socketTimeout:120000}</int>
|
||||||
|
<int name="connTimeout">${connTimeout:15000}</int>
|
||||||
|
</shardHandlerFactory>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
adminPath: RequestHandler path to manage cores.
|
adminPath: RequestHandler path to manage cores.
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
If 'null' (or absent), cores will not be manageable via request handler
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
||||||
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"
|
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"
|
||||||
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
||||||
|
@ -40,5 +47,6 @@
|
||||||
<int name="connTimeout">${connTimeout:15000}</int>
|
<int name="connTimeout">${connTimeout:15000}</int>
|
||||||
</shardHandlerFactory>
|
</shardHandlerFactory>
|
||||||
</cores>
|
</cores>
|
||||||
|
-->
|
||||||
|
|
||||||
</solr>
|
</solr>
|
||||||
|
|
|
@ -16,25 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import java.io.File;
|
import com.google.common.base.Joiner;
|
||||||
import java.io.IOException;
|
import com.google.common.io.Files;
|
||||||
import java.util.Arrays;
|
import com.typesafe.config.Config;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||||
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
||||||
|
@ -56,10 +45,20 @@ import org.kitesdk.morphline.stdlib.PipeBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import java.io.ByteArrayInputStream;
|
||||||
import com.google.common.base.Joiner;
|
import java.io.File;
|
||||||
import com.google.common.io.Files;
|
import java.io.IOException;
|
||||||
import com.typesafe.config.Config;
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
|
public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
|
||||||
private static Locale savedLocale;
|
private static Locale savedLocale;
|
||||||
|
@ -123,7 +122,7 @@ public class AbstractSolrMorphlineTestBase extends SolrTestCaseJ4 {
|
||||||
((HttpSolrClient) solrClient).setParser(new XMLResponseParser());
|
((HttpSolrClient) solrClient).setParser(new XMLResponseParser());
|
||||||
} else {
|
} else {
|
||||||
if (TEST_WITH_EMBEDDED_SOLR_SERVER) {
|
if (TEST_WITH_EMBEDDED_SOLR_SERVER) {
|
||||||
solrClient = new EmbeddedTestSolrServer(h.getCoreContainer(), "");
|
solrClient = new EmbeddedTestSolrServer(h.getCoreContainer(), DEFAULT_TEST_CORENAME);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Not yet implemented");
|
throw new RuntimeException("Not yet implemented");
|
||||||
//solrServer = new TestSolrServer(getSolrClient());
|
//solrServer = new TestSolrServer(getSolrClient());
|
||||||
|
|
|
@ -17,11 +17,9 @@
|
||||||
|
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.File;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
import java.io.IOException;
|
import com.google.common.collect.ListMultimap;
|
||||||
import java.util.Iterator;
|
import com.typesafe.config.Config;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||||
|
@ -42,9 +40,10 @@ import org.kitesdk.morphline.base.FaultTolerance;
|
||||||
import org.kitesdk.morphline.base.Notifications;
|
import org.kitesdk.morphline.base.Notifications;
|
||||||
import org.kitesdk.morphline.stdlib.PipeBuilder;
|
import org.kitesdk.morphline.stdlib.PipeBuilder;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import java.io.File;
|
||||||
import com.google.common.collect.ListMultimap;
|
import java.io.IOException;
|
||||||
import com.typesafe.config.Config;
|
import java.util.Iterator;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistribZkTestBase {
|
public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistribZkTestBase {
|
||||||
private static File solrHomeDirectory;
|
private static File solrHomeDirectory;
|
||||||
|
@ -155,7 +154,8 @@ public abstract class AbstractSolrMorphlineZkTestBase extends AbstractFullDistri
|
||||||
public JettySolrRunner createJetty(File solrHome, String dataDir,
|
public JettySolrRunner createJetty(File solrHome, String dataDir,
|
||||||
String shardList, String solrConfigOverride, String schemaOverride)
|
String shardList, String solrConfigOverride, String schemaOverride)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
|
writeCoreProperties(solrHome.toPath(), DEFAULT_TEST_CORENAME);
|
||||||
JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(),
|
JettySolrRunner jetty = new JettySolrRunner(solrHome.getAbsolutePath(),
|
||||||
context, 0, solrConfigOverride, schemaOverride, true, null, sslConfig);
|
context, 0, solrConfigOverride, schemaOverride, true, null, sslConfig);
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,15 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.kitesdk.morphline.api.Record;
|
import org.kitesdk.morphline.api.Record;
|
||||||
import org.kitesdk.morphline.base.Fields;
|
import org.kitesdk.morphline.base.Fields;
|
||||||
import org.kitesdk.morphline.base.Notifications;
|
import org.kitesdk.morphline.base.Notifications;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class SolrMorphlineTest extends AbstractSolrMorphlineTestBase {
|
public class SolrMorphlineTest extends AbstractSolrMorphlineTestBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,11 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.File;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||||
import java.io.IOException;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
||||||
import java.util.Iterator;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
||||||
import org.apache.lucene.util.Constants;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
|
@ -35,13 +37,9 @@ import org.kitesdk.morphline.api.Record;
|
||||||
import org.kitesdk.morphline.base.Fields;
|
import org.kitesdk.morphline.base.Fields;
|
||||||
import org.kitesdk.morphline.base.Notifications;
|
import org.kitesdk.morphline.base.Notifications;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
import java.io.File;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
import java.io.IOException;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
import java.util.Iterator;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
|
||||||
|
|
||||||
@ThreadLeakAction({Action.WARN})
|
@ThreadLeakAction({Action.WARN})
|
||||||
@ThreadLeakLingering(linger = 0)
|
@ThreadLeakLingering(linger = 0)
|
||||||
|
|
|
@ -16,28 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.avro.Schema.Field;
|
|
||||||
import org.apache.avro.file.DataFileReader;
|
|
||||||
import org.apache.avro.file.FileReader;
|
|
||||||
import org.apache.avro.generic.GenericData;
|
|
||||||
import org.apache.avro.generic.GenericDatumReader;
|
|
||||||
import org.apache.lucene.util.Constants;
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
|
||||||
import org.apache.solr.common.SolrDocument;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.kitesdk.morphline.api.Record;
|
|
||||||
import org.kitesdk.morphline.base.Fields;
|
|
||||||
import org.kitesdk.morphline.base.Notifications;
|
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
||||||
|
@ -48,6 +26,26 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Conseque
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
import org.apache.avro.Schema.Field;
|
||||||
|
import org.apache.avro.file.DataFileReader;
|
||||||
|
import org.apache.avro.file.FileReader;
|
||||||
|
import org.apache.avro.generic.GenericData;
|
||||||
|
import org.apache.avro.generic.GenericDatumReader;
|
||||||
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
|
import org.apache.solr.common.SolrDocument;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.kitesdk.morphline.api.Record;
|
||||||
|
import org.kitesdk.morphline.base.Fields;
|
||||||
|
import org.kitesdk.morphline.base.Notifications;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@ThreadLeakAction({Action.WARN})
|
@ThreadLeakAction({Action.WARN})
|
||||||
@ThreadLeakLingering(linger = 0)
|
@ThreadLeakLingering(linger = 0)
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.morphlines.solr;
|
package org.apache.solr.morphlines.solr;
|
||||||
|
|
||||||
import java.io.File;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
||||||
import java.util.Iterator;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
||||||
import org.apache.lucene.util.Constants;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
|
@ -29,13 +32,8 @@ import org.kitesdk.morphline.api.Record;
|
||||||
import org.kitesdk.morphline.base.Fields;
|
import org.kitesdk.morphline.base.Fields;
|
||||||
import org.kitesdk.morphline.base.Notifications;
|
import org.kitesdk.morphline.base.Notifications;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
|
import java.io.File;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction.Action;
|
import java.util.Iterator;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies.Consequence;
|
|
||||||
|
|
||||||
@ThreadLeakAction({Action.WARN})
|
@ThreadLeakAction({Action.WARN})
|
||||||
@ThreadLeakLingering(linger = 0)
|
@ThreadLeakLingering(linger = 0)
|
||||||
|
|
|
@ -129,10 +129,8 @@ public class EmbeddedSolrServer extends SolrClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Perhaps the path is to manage the cores
|
// Perhaps the path is to manage the cores
|
||||||
if( handler == null &&
|
if (handler == null) {
|
||||||
coreContainer != null &&
|
handler = coreContainer.getRequestHandler(path);
|
||||||
path.equals( coreContainer.getAdminPath() ) ) {
|
|
||||||
handler = coreContainer.getMultiCoreHandler();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( handler == null ) {
|
if( handler == null ) {
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.eclipse.jetty.servlet.FilterHolder;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.servlets.GzipFilter;
|
import org.eclipse.jetty.servlets.GzipFilter;
|
||||||
import org.eclipse.jetty.servlets.gzip.GzipHandler;
|
|
||||||
import org.eclipse.jetty.util.component.LifeCycle;
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
@ -64,6 +63,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
* @since solr 1.3
|
* @since solr 1.3
|
||||||
*/
|
*/
|
||||||
public class JettySolrRunner {
|
public class JettySolrRunner {
|
||||||
|
|
||||||
|
private static final AtomicLong JETTY_ID_COUNTER = new AtomicLong();
|
||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
|
|
||||||
FilterHolder dispatchFilter;
|
FilterHolder dispatchFilter;
|
||||||
|
@ -73,6 +75,7 @@ public class JettySolrRunner {
|
||||||
|
|
||||||
private String solrConfigFilename;
|
private String solrConfigFilename;
|
||||||
private String schemaFilename;
|
private String schemaFilename;
|
||||||
|
private final String coreRootDirectory;
|
||||||
|
|
||||||
private boolean waitOnSolr = false;
|
private boolean waitOnSolr = false;
|
||||||
|
|
||||||
|
@ -91,6 +94,8 @@ public class JettySolrRunner {
|
||||||
|
|
||||||
private String coreNodeName;
|
private String coreNodeName;
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
/** Maps servlet holders (i.e. factories: class + init params) to path specs */
|
/** Maps servlet holders (i.e. factories: class + init params) to path specs */
|
||||||
private SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
|
private SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
|
||||||
private SortedMap<Class,String> extraRequestFilters;
|
private SortedMap<Class,String> extraRequestFilters;
|
||||||
|
@ -149,12 +154,16 @@ public class JettySolrRunner {
|
||||||
|
|
||||||
public JettySolrRunner(String solrHome, String context, int port) {
|
public JettySolrRunner(String solrHome, String context, int port) {
|
||||||
this.init(solrHome, context, port, true);
|
this.init(solrHome, context, port, true);
|
||||||
|
this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();
|
||||||
|
this.coreRootDirectory = System.getProperty("coreRootDirectory", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettySolrRunner(String solrHome, String context, int port, String solrConfigFilename, String schemaFileName) {
|
public JettySolrRunner(String solrHome, String context, int port, String solrConfigFilename, String schemaFileName) {
|
||||||
this.init(solrHome, context, port, true);
|
this.init(solrHome, context, port, true);
|
||||||
this.solrConfigFilename = solrConfigFilename;
|
this.solrConfigFilename = solrConfigFilename;
|
||||||
this.schemaFilename = schemaFileName;
|
this.schemaFilename = schemaFileName;
|
||||||
|
this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();
|
||||||
|
this.coreRootDirectory = System.getProperty("coreRootDirectory", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettySolrRunner(String solrHome, String context, int port,
|
public JettySolrRunner(String solrHome, String context, int port,
|
||||||
|
@ -162,6 +171,8 @@ public class JettySolrRunner {
|
||||||
this.init(solrHome, context, port, stopAtShutdown);
|
this.init(solrHome, context, port, stopAtShutdown);
|
||||||
this.solrConfigFilename = solrConfigFilename;
|
this.solrConfigFilename = solrConfigFilename;
|
||||||
this.schemaFilename = schemaFileName;
|
this.schemaFilename = schemaFileName;
|
||||||
|
this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();
|
||||||
|
this.coreRootDirectory = System.getProperty("coreRootDirectory", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,6 +210,9 @@ public class JettySolrRunner {
|
||||||
this.schemaFilename = schemaFileName;
|
this.schemaFilename = schemaFileName;
|
||||||
this.sslConfig = sslConfig;
|
this.sslConfig = sslConfig;
|
||||||
|
|
||||||
|
this.name = "jetty-" + JETTY_ID_COUNTER.incrementAndGet();
|
||||||
|
this.coreRootDirectory = System.getProperty("coreRootDirectory", null);
|
||||||
|
|
||||||
this.init(solrHome, context, port, stopAtShutdown);
|
this.init(solrHome, context, port, stopAtShutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +221,7 @@ public class JettySolrRunner {
|
||||||
|
|
||||||
this.solrHome = solrHome;
|
this.solrHome = solrHome;
|
||||||
this.stopAtShutdown = stopAtShutdown;
|
this.stopAtShutdown = stopAtShutdown;
|
||||||
|
|
||||||
System.setProperty("solr.solr.home", solrHome);
|
System.setProperty("solr.solr.home", solrHome);
|
||||||
if (System.getProperty("jetty.testMode") != null) {
|
if (System.getProperty("jetty.testMode") != null) {
|
||||||
// if this property is true, then jetty will be configured to use SSL
|
// if this property is true, then jetty will be configured to use SSL
|
||||||
|
@ -298,6 +313,8 @@ public class JettySolrRunner {
|
||||||
solrConfigFilename);
|
solrConfigFilename);
|
||||||
if (schemaFilename != null) System.setProperty("schema",
|
if (schemaFilename != null) System.setProperty("schema",
|
||||||
schemaFilename);
|
schemaFilename);
|
||||||
|
if (coreRootDirectory != null)
|
||||||
|
System.setProperty("coreRootDirectory", coreRootDirectory);
|
||||||
// SolrDispatchFilter filter = new SolrDispatchFilter();
|
// SolrDispatchFilter filter = new SolrDispatchFilter();
|
||||||
// FilterHolder fh = new FilterHolder(filter);
|
// FilterHolder fh = new FilterHolder(filter);
|
||||||
debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );
|
debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST) );
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import org.apache.solr.common.cloud.Slice;
|
import org.apache.solr.common.cloud.Slice;
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
|
@ -49,10 +50,14 @@ public class CloudDescriptor {
|
||||||
public CloudDescriptor(String coreName, Properties props, CoreDescriptor cd) {
|
public CloudDescriptor(String coreName, Properties props, CoreDescriptor cd) {
|
||||||
this.cd = cd;
|
this.cd = cd;
|
||||||
this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null);
|
this.shardId = props.getProperty(CoreDescriptor.CORE_SHARD, null);
|
||||||
|
if (Strings.isNullOrEmpty(shardId))
|
||||||
|
this.shardId = null;
|
||||||
// If no collection name is specified, we default to the core name
|
// If no collection name is specified, we default to the core name
|
||||||
this.collectionName = props.getProperty(CoreDescriptor.CORE_COLLECTION, coreName);
|
this.collectionName = props.getProperty(CoreDescriptor.CORE_COLLECTION, coreName);
|
||||||
this.roles = props.getProperty(CoreDescriptor.CORE_ROLES, null);
|
this.roles = props.getProperty(CoreDescriptor.CORE_ROLES, null);
|
||||||
this.nodeName = props.getProperty(CoreDescriptor.CORE_NODE_NAME);
|
this.nodeName = props.getProperty(CoreDescriptor.CORE_NODE_NAME);
|
||||||
|
if (Strings.isNullOrEmpty(nodeName))
|
||||||
|
this.nodeName = null;
|
||||||
this.numShards = PropertiesUtil.toInteger(props.getProperty(CloudDescriptor.NUM_SHARDS), null);
|
this.numShards = PropertiesUtil.toInteger(props.getProperty(CloudDescriptor.NUM_SHARDS), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -614,15 +614,13 @@ public final class ZkController {
|
||||||
|
|
||||||
ShardHandler shardHandler;
|
ShardHandler shardHandler;
|
||||||
UpdateShardHandler updateShardHandler;
|
UpdateShardHandler updateShardHandler;
|
||||||
String adminPath;
|
|
||||||
shardHandler = cc.getShardHandlerFactory().getShardHandler();
|
shardHandler = cc.getShardHandlerFactory().getShardHandler();
|
||||||
updateShardHandler = cc.getUpdateShardHandler();
|
updateShardHandler = cc.getUpdateShardHandler();
|
||||||
adminPath = cc.getAdminPath();
|
|
||||||
|
|
||||||
if (!zkRunOnly) {
|
if (!zkRunOnly) {
|
||||||
overseerElector = new LeaderElector(zkClient);
|
overseerElector = new LeaderElector(zkClient);
|
||||||
this.overseer = new Overseer(shardHandler, updateShardHandler,
|
this.overseer = new Overseer(shardHandler, updateShardHandler,
|
||||||
adminPath, zkStateReader, this, cc.getConfig());
|
CoreContainer.CORES_HANDLER_PATH, zkStateReader, this, cc.getConfig());
|
||||||
ElectionContext context = new OverseerElectionContext(zkClient,
|
ElectionContext context = new OverseerElectionContext(zkClient,
|
||||||
overseer, getNodeName());
|
overseer, getNodeName());
|
||||||
overseerElector.setup(context);
|
overseerElector.setup(context);
|
||||||
|
|
|
@ -22,25 +22,15 @@ import org.apache.solr.cloud.CloudConfigSetService;
|
||||||
import org.apache.solr.cloud.ZkController;
|
import org.apache.solr.cloud.ZkController;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.logging.LogWatcherConfig;
|
import org.apache.solr.logging.LogWatcherConfig;
|
||||||
import org.apache.solr.util.DOMUtil;
|
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
import javax.xml.xpath.XPath;
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,10 +64,9 @@ public abstract class ConfigSolr {
|
||||||
public static ConfigSolr fromInputStream(SolrResourceLoader loader, InputStream is) {
|
public static ConfigSolr fromInputStream(SolrResourceLoader loader, InputStream is) {
|
||||||
try {
|
try {
|
||||||
byte[] buf = IOUtils.toByteArray(is);
|
byte[] buf = IOUtils.toByteArray(is);
|
||||||
String originalXml = new String(buf, StandardCharsets.UTF_8);
|
|
||||||
try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) {
|
try (ByteArrayInputStream dup = new ByteArrayInputStream(buf)) {
|
||||||
Config config = new Config(loader, null, new InputSource(dup), null, false);
|
Config config = new Config(loader, null, new InputSource(dup), null, false);
|
||||||
return fromConfig(config, originalXml);
|
return new ConfigSolrXml(config);
|
||||||
}
|
}
|
||||||
} catch (SolrException exc) {
|
} catch (SolrException exc) {
|
||||||
throw exc;
|
throw exc;
|
||||||
|
@ -89,12 +78,6 @@ public abstract class ConfigSolr {
|
||||||
public static ConfigSolr fromSolrHome(SolrResourceLoader loader, String solrHome) {
|
public static ConfigSolr fromSolrHome(SolrResourceLoader loader, String solrHome) {
|
||||||
return fromFile(loader, new File(solrHome, SOLR_XML_FILE));
|
return fromFile(loader, new File(solrHome, SOLR_XML_FILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigSolr fromConfig(Config config, String originalXml) {
|
|
||||||
boolean oldStyle = (config.getNode("solr/cores", false) != null);
|
|
||||||
return oldStyle ? new ConfigSolrXmlOld(config, originalXml)
|
|
||||||
: new ConfigSolrXml(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract CoresLocator getCoresLocator();
|
public abstract CoresLocator getCoresLocator();
|
||||||
|
|
||||||
|
@ -106,32 +89,26 @@ public abstract class ConfigSolr {
|
||||||
* @return core root directory
|
* @return core root directory
|
||||||
*/
|
*/
|
||||||
public String getCoreRootDirectory() {
|
public String getCoreRootDirectory() {
|
||||||
SolrResourceLoader loader = config.getResourceLoader();
|
String relativeDir = getString(CfgProp.SOLR_COREROOTDIRECTORY, null);
|
||||||
String relativeDir = get(CfgProp.SOLR_COREROOTDIRECTORY, null);
|
|
||||||
if (relativeDir != null)
|
if (relativeDir != null)
|
||||||
return loader.resolve(relativeDir);
|
return loader.resolve(relativeDir);
|
||||||
return loader.getInstanceDir();
|
return loader.getInstanceDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
public abstract PluginInfo getShardHandlerFactoryPluginInfo();
|
||||||
Node node = config.getNode(getShardHandlerFactoryConfigPath(), false);
|
|
||||||
return (node == null) ? null : new PluginInfo(node, "shardHandlerFactory", false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract String getShardHandlerFactoryConfigPath();
|
|
||||||
|
|
||||||
public String getZkHost() {
|
public String getZkHost() {
|
||||||
String sysZkHost = System.getProperty("zkHost");
|
String sysZkHost = System.getProperty("zkHost");
|
||||||
if (sysZkHost != null)
|
if (sysZkHost != null)
|
||||||
return sysZkHost;
|
return sysZkHost;
|
||||||
return get(CfgProp.SOLR_ZKHOST, null);
|
return getString(CfgProp.SOLR_ZKHOST, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getZkClientTimeout() {
|
public int getZkClientTimeout() {
|
||||||
String sysProp = System.getProperty("zkClientTimeout");
|
String sysProp = System.getProperty("zkClientTimeout");
|
||||||
if (sysProp != null)
|
if (sysProp != null)
|
||||||
return Integer.parseInt(sysProp);
|
return Integer.parseInt(sysProp);
|
||||||
return get(CfgProp.SOLR_ZKCLIENTTIMEOUT, DEFAULT_ZK_CLIENT_TIMEOUT);
|
return getInt(CfgProp.SOLR_ZKCLIENTTIMEOUT, DEFAULT_ZK_CLIENT_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int DEFAULT_ZK_CLIENT_TIMEOUT = 15000;
|
private static final int DEFAULT_ZK_CLIENT_TIMEOUT = 15000;
|
||||||
|
@ -150,120 +127,110 @@ public abstract class ConfigSolr {
|
||||||
protected static final String DEFAULT_CORE_ADMIN_PATH = "/admin/cores";
|
protected static final String DEFAULT_CORE_ADMIN_PATH = "/admin/cores";
|
||||||
|
|
||||||
public String getSolrHostPort() {
|
public String getSolrHostPort() {
|
||||||
return get(CfgProp.SOLR_HOSTPORT, null);
|
return getString(CfgProp.SOLR_HOSTPORT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZkHostContext() {
|
public String getZkHostContext() {
|
||||||
return get(CfgProp.SOLR_HOSTCONTEXT, null);
|
return getString(CfgProp.SOLR_HOSTCONTEXT, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return get(CfgProp.SOLR_HOST, null);
|
return getString(CfgProp.SOLR_HOST, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeaderVoteWait() {
|
public int getLeaderVoteWait() {
|
||||||
return get(CfgProp.SOLR_LEADERVOTEWAIT, DEFAULT_LEADER_VOTE_WAIT);
|
return getInt(CfgProp.SOLR_LEADERVOTEWAIT, DEFAULT_LEADER_VOTE_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeaderConflictResolveWait() {
|
public int getLeaderConflictResolveWait() {
|
||||||
return get(CfgProp.SOLR_LEADERCONFLICTRESOLVEWAIT, DEFAULT_LEADER_CONFLICT_RESOLVE_WAIT);
|
return getInt(CfgProp.SOLR_LEADERCONFLICTRESOLVEWAIT, DEFAULT_LEADER_CONFLICT_RESOLVE_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAutoReplicaFailoverWaitAfterExpiration() {
|
public int getAutoReplicaFailoverWaitAfterExpiration() {
|
||||||
return get(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_WAIT_AFTER_EXPIRATION);
|
return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_WAIT_AFTER_EXPIRATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAutoReplicaFailoverWorkLoopDelay() {
|
public int getAutoReplicaFailoverWorkLoopDelay() {
|
||||||
return get(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, DEFAULT_AUTO_REPLICA_FAILOVER_WORKLOOP_DELAY);
|
return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, DEFAULT_AUTO_REPLICA_FAILOVER_WORKLOOP_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAutoReplicaFailoverBadNodeExpiration() {
|
public int getAutoReplicaFailoverBadNodeExpiration() {
|
||||||
return get(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_BAD_NODE_EXPIRATION);
|
return getInt(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, DEFAULT_AUTO_REPLICA_FAILOVER_BAD_NODE_EXPIRATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getGenericCoreNodeNames() {
|
public boolean getGenericCoreNodeNames() {
|
||||||
return get(CfgProp.SOLR_GENERICCORENODENAMES, false);
|
return getBoolean(CfgProp.SOLR_GENERICCORENODENAMES, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDistributedConnectionTimeout() {
|
public int getDistributedConnectionTimeout() {
|
||||||
return get(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, DEFAULT_DISTRIBUPDATECONNTIMEOUT);
|
return getInt(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, DEFAULT_DISTRIBUPDATECONNTIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDistributedSocketTimeout() {
|
public int getDistributedSocketTimeout() {
|
||||||
return get(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, DEFAULT_DISTRIBUPDATESOTIMEOUT);
|
return getInt(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, DEFAULT_DISTRIBUPDATESOTIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxUpdateConnections() {
|
public int getMaxUpdateConnections() {
|
||||||
return get(CfgProp.SOLR_MAXUPDATECONNECTIONS, 10000);
|
return getInt(CfgProp.SOLR_MAXUPDATECONNECTIONS, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxUpdateConnectionsPerHost() {
|
public int getMaxUpdateConnectionsPerHost() {
|
||||||
return get(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, 100);
|
return getInt(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCoreLoadThreadCount() {
|
public int getCoreLoadThreadCount() {
|
||||||
return get(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, DEFAULT_CORE_LOAD_THREADS);
|
return getInt(ConfigSolr.CfgProp.SOLR_CORELOADTHREADS, DEFAULT_CORE_LOAD_THREADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSharedLibDirectory() {
|
public String getSharedLibDirectory() {
|
||||||
return get(ConfigSolr.CfgProp.SOLR_SHAREDLIB , null);
|
return getString(ConfigSolr.CfgProp.SOLR_SHAREDLIB, null);
|
||||||
}
|
|
||||||
|
|
||||||
public String getDefaultCoreName() {
|
|
||||||
return get(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean isPersistent();
|
|
||||||
|
|
||||||
public String getAdminPath() {
|
|
||||||
return get(CfgProp.SOLR_ADMINPATH, DEFAULT_CORE_ADMIN_PATH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCoreAdminHandlerClass() {
|
public String getCoreAdminHandlerClass() {
|
||||||
return get(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler");
|
return getString(CfgProp.SOLR_ADMINHANDLER, "org.apache.solr.handler.admin.CoreAdminHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZkCredentialsProviderClass() {
|
public String getZkCredentialsProviderClass() {
|
||||||
return get(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, null);
|
return getString(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZkACLProviderClass() {
|
public String getZkACLProviderClass() {
|
||||||
return get(CfgProp.SOLR_ZKACLPROVIDER, null);
|
return getString(CfgProp.SOLR_ZKACLPROVIDER, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCollectionsHandlerClass() {
|
public String getCollectionsHandlerClass() {
|
||||||
return get(CfgProp.SOLR_COLLECTIONSHANDLER, "org.apache.solr.handler.admin.CollectionsHandler");
|
return getString(CfgProp.SOLR_COLLECTIONSHANDLER, "org.apache.solr.handler.admin.CollectionsHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInfoHandlerClass() {
|
public String getInfoHandlerClass() {
|
||||||
return get(CfgProp.SOLR_INFOHANDLER, "org.apache.solr.handler.admin.InfoHandler");
|
return getString(CfgProp.SOLR_INFOHANDLER, "org.apache.solr.handler.admin.InfoHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSchemaCache() {
|
public boolean hasSchemaCache() {
|
||||||
return get(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false);
|
return getBoolean(ConfigSolr.CfgProp.SOLR_SHARESCHEMA, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getManagementPath() {
|
public String getManagementPath() {
|
||||||
return get(CfgProp.SOLR_MANAGEMENTPATH, null);
|
return getString(CfgProp.SOLR_MANAGEMENTPATH, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConfigSetBaseDirectory() {
|
public String getConfigSetBaseDirectory() {
|
||||||
return get(CfgProp.SOLR_CONFIGSETBASEDIR, "configsets");
|
return getString(CfgProp.SOLR_CONFIGSETBASEDIR, "configsets");
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogWatcherConfig getLogWatcherConfig() {
|
public LogWatcherConfig getLogWatcherConfig() {
|
||||||
String loggingClass = get(CfgProp.SOLR_LOGGING_CLASS, null);
|
String loggingClass = getString(CfgProp.SOLR_LOGGING_CLASS, null);
|
||||||
String loggingWatcherThreshold = get(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
|
String loggingWatcherThreshold = getString(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, null);
|
||||||
return new LogWatcherConfig(
|
return new LogWatcherConfig(
|
||||||
get(CfgProp.SOLR_LOGGING_ENABLED, true),
|
getBoolean(CfgProp.SOLR_LOGGING_ENABLED, true),
|
||||||
loggingClass,
|
loggingClass,
|
||||||
loggingWatcherThreshold,
|
loggingWatcherThreshold,
|
||||||
get(CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50)
|
getInt(CfgProp.SOLR_LOGGING_WATCHER_SIZE, 50)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTransientCacheSize() {
|
public int getTransientCacheSize() {
|
||||||
return get(CfgProp.SOLR_TRANSIENTCACHESIZE, Integer.MAX_VALUE);
|
return getInt(CfgProp.SOLR_TRANSIENTCACHESIZE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigSetService createCoreConfigService(SolrResourceLoader loader, ZkController zkController) {
|
public ConfigSetService createCoreConfigService(SolrResourceLoader loader, ZkController zkController) {
|
||||||
|
@ -275,7 +242,7 @@ public abstract class ConfigSolr {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
|
// Ugly for now, but we'll at least be able to centralize all of the differences between 4x and 5x.
|
||||||
protected static enum CfgProp {
|
public static enum CfgProp {
|
||||||
SOLR_ADMINHANDLER,
|
SOLR_ADMINHANDLER,
|
||||||
SOLR_COLLECTIONSHANDLER,
|
SOLR_COLLECTIONSHANDLER,
|
||||||
SOLR_CORELOADTHREADS,
|
SOLR_CORELOADTHREADS,
|
||||||
|
@ -309,59 +276,44 @@ public abstract class ConfigSolr {
|
||||||
|
|
||||||
SOLR_ZKCREDENTIALSPROVIDER,
|
SOLR_ZKCREDENTIALSPROVIDER,
|
||||||
SOLR_ZKACLPROVIDER,
|
SOLR_ZKACLPROVIDER,
|
||||||
|
|
||||||
//TODO: Remove all of these elements for 5.0
|
|
||||||
SOLR_PERSISTENT,
|
|
||||||
SOLR_CORES_DEFAULT_CORE_NAME,
|
|
||||||
SOLR_ADMINPATH
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Config config;
|
|
||||||
protected Map<CfgProp, Object> propMap = new HashMap<>();
|
|
||||||
|
|
||||||
public ConfigSolr(Config config) {
|
|
||||||
this.config = config;
|
|
||||||
config.substituteProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
// for extension & testing.
|
|
||||||
protected ConfigSolr() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config getConfig() {
|
protected final SolrResourceLoader loader;
|
||||||
return config;
|
protected final Properties solrProperties;
|
||||||
|
|
||||||
|
public ConfigSolr(SolrResourceLoader loader, Properties solrProperties) {
|
||||||
|
this.loader = loader;
|
||||||
|
this.solrProperties = solrProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public ConfigSolr(SolrResourceLoader loader) {
|
||||||
public <T> T get(CfgProp key, T defaultValue) {
|
this(loader, new Properties());
|
||||||
if (propMap.containsKey(key) && propMap.get(key) != null) {
|
|
||||||
return (T) propMap.get(key);
|
|
||||||
}
|
|
||||||
return defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getSolrProperties(String path) {
|
protected abstract String getProperty(CfgProp key);
|
||||||
try {
|
|
||||||
return readProperties(((NodeList) config.evaluate(
|
|
||||||
path, XPathConstants.NODESET)).item(0));
|
|
||||||
} catch (Exception e) {
|
|
||||||
SolrException.log(log, null, e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
|
private String getString(CfgProp key, String defaultValue) {
|
||||||
|
String v = getProperty(key);
|
||||||
|
return v == null ? defaultValue : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Properties readProperties(Node node) throws XPathExpressionException {
|
private int getInt(CfgProp key, int defaultValue) {
|
||||||
XPath xpath = config.getXPath();
|
String v = getProperty(key);
|
||||||
NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);
|
return v == null ? defaultValue : Integer.parseInt(v);
|
||||||
Properties properties = new Properties();
|
}
|
||||||
for (int i = 0; i < props.getLength(); i++) {
|
|
||||||
Node prop = props.item(i);
|
private boolean getBoolean(CfgProp key, boolean defaultValue) {
|
||||||
properties.setProperty(DOMUtil.getAttr(prop, "name"),
|
String v = getProperty(key);
|
||||||
PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));
|
return v == null ? defaultValue : Boolean.parseBoolean(v);
|
||||||
}
|
}
|
||||||
return properties;
|
|
||||||
|
public Properties getSolrProperties() {
|
||||||
|
return solrProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SolrResourceLoader getSolrResourceLoader() {
|
||||||
|
return loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,24 +17,26 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Functions;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.util.DOMUtil;
|
import org.apache.solr.util.DOMUtil;
|
||||||
|
import org.apache.solr.util.PropertiesUtil;
|
||||||
import com.google.common.base.Function;
|
import org.slf4j.Logger;
|
||||||
import com.google.common.base.Functions;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import javax.xml.xpath.XPath;
|
||||||
import org.slf4j.LoggerFactory;
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,51 +47,28 @@ public class ConfigSolrXml extends ConfigSolr {
|
||||||
protected static Logger log = LoggerFactory.getLogger(ConfigSolrXml.class);
|
protected static Logger log = LoggerFactory.getLogger(ConfigSolrXml.class);
|
||||||
|
|
||||||
private final CoresLocator coresLocator;
|
private final CoresLocator coresLocator;
|
||||||
|
private final Config config;
|
||||||
|
private final Map<CfgProp, Object> propMap = new HashMap<>();
|
||||||
|
|
||||||
public ConfigSolrXml(Config config) {
|
public ConfigSolrXml(Config config) {
|
||||||
super(config);
|
super(config.getResourceLoader(), loadProperties(config));
|
||||||
try {
|
this.config = config;
|
||||||
checkForIllegalConfig();
|
this.config.substituteProperties();
|
||||||
fillPropMap();
|
checkForIllegalConfig();
|
||||||
coresLocator = new CorePropertiesLocator(getCoreRootDirectory());
|
fillPropMap();
|
||||||
} catch (IOException e) {
|
coresLocator = new CorePropertiesLocator(getCoreRootDirectory());
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForIllegalConfig() throws IOException {
|
private void checkForIllegalConfig() {
|
||||||
|
|
||||||
// Do sanity checks - we don't want to find old style config
|
|
||||||
failIfFound("solr/@coreLoadThreads");
|
failIfFound("solr/@coreLoadThreads");
|
||||||
failIfFound("solr/@persistent");
|
failIfFound("solr/@persistent");
|
||||||
failIfFound("solr/@sharedLib");
|
failIfFound("solr/@sharedLib");
|
||||||
failIfFound("solr/@zkHost");
|
failIfFound("solr/@zkHost");
|
||||||
|
|
||||||
failIfFound("solr/logging/@class");
|
failIfFound("solr/cores");
|
||||||
failIfFound("solr/logging/@enabled");
|
|
||||||
failIfFound("solr/logging/watcher/@size");
|
|
||||||
failIfFound("solr/logging/watcher/@threshold");
|
|
||||||
|
|
||||||
failIfFound("solr/cores/@adminHandler");
|
|
||||||
failIfFound("solr/cores/@distribUpdateConnTimeout");
|
|
||||||
failIfFound("solr/cores/@distribUpdateSoTimeout");
|
|
||||||
failIfFound("solr/cores/@host");
|
|
||||||
failIfFound("solr/cores/@hostContext");
|
|
||||||
failIfFound("solr/cores/@hostPort");
|
|
||||||
failIfFound("solr/cores/@leaderVoteWait");
|
|
||||||
failIfFound("solr/cores/@leaderConflictResolveWait");
|
|
||||||
failIfFound("solr/cores/@genericCoreNodeNames");
|
|
||||||
failIfFound("solr/cores/@managementPath");
|
|
||||||
failIfFound("solr/cores/@shareSchema");
|
|
||||||
failIfFound("solr/cores/@transientCacheSize");
|
|
||||||
failIfFound("solr/cores/@zkClientTimeout");
|
|
||||||
|
|
||||||
// These have no counterpart in 5.0, asking for any of these in Solr 5.0
|
|
||||||
// will result in an error being
|
|
||||||
// thrown.
|
|
||||||
failIfFound("solr/cores/@defaultCoreName");
|
|
||||||
failIfFound("solr/@persistent");
|
failIfFound("solr/@persistent");
|
||||||
failIfFound("solr/cores/@adminPath");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +76,32 @@ public class ConfigSolrXml extends ConfigSolr {
|
||||||
|
|
||||||
if (config.getVal(xPath, false) != null) {
|
if (config.getVal(xPath, false) != null) {
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Should not have found " + xPath +
|
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Should not have found " + xPath +
|
||||||
" solr.xml may be a mix of old and new style formats.");
|
"\n. Please upgrade your solr.xml: https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getProperty(CfgProp key) {
|
||||||
|
if (!propMap.containsKey(key) || propMap.get(key) == null)
|
||||||
|
return null;
|
||||||
|
return propMap.get(key).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Properties loadProperties(Config config) {
|
||||||
|
try {
|
||||||
|
Node node = ((NodeList) config.evaluate("solr", XPathConstants.NODESET)).item(0);
|
||||||
|
XPath xpath = config.getXPath();
|
||||||
|
NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);
|
||||||
|
Properties properties = new Properties();
|
||||||
|
for (int i = 0; i < props.getLength(); i++) {
|
||||||
|
Node prop = props.item(i);
|
||||||
|
properties.setProperty(DOMUtil.getAttr(prop, "name"),
|
||||||
|
PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
catch (XPathExpressionException e) {
|
||||||
|
log.warn("Error parsing solr.xml: " + e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,24 +251,9 @@ public class ConfigSolrXml extends ConfigSolr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
public String getDefaultCoreName() {
|
Node node = config.getNode("solr/shardHandlerFactory", false);
|
||||||
return "collection1";
|
return (node == null) ? null : new PluginInfo(node, "shardHandlerFactory", false, true);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPersistent() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getShardHandlerFactoryConfigPath() {
|
|
||||||
return "solr/shardHandlerFactory";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAdminPath() {
|
|
||||||
return DEFAULT_CORE_ADMIN_PATH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,284 +0,0 @@
|
||||||
package org.apache.solr.core;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.apache.solr.util.DOMUtil;
|
|
||||||
import org.apache.solr.util.PropertiesUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ConfigSolrXmlOld extends ConfigSolr {
|
|
||||||
|
|
||||||
protected static Logger log = LoggerFactory.getLogger(ConfigSolrXmlOld.class);
|
|
||||||
|
|
||||||
private NodeList coreNodes = null;
|
|
||||||
|
|
||||||
private final CoresLocator persistor;
|
|
||||||
|
|
||||||
public static final String DEFAULT_DEFAULT_CORE_NAME = "collection1";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getShardHandlerFactoryConfigPath() {
|
|
||||||
return "solr/cores/shardHandlerFactory";
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSolrXmlOld(Config config, String originalXML) {
|
|
||||||
super(config);
|
|
||||||
try {
|
|
||||||
checkForIllegalConfig();
|
|
||||||
fillPropMap();
|
|
||||||
initCoreList();
|
|
||||||
this.persistor = isPersistent() ? new SolrXMLCoresLocator(originalXML, this)
|
|
||||||
: new SolrXMLCoresLocator.NonPersistingLocator(originalXML, this);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CoresLocator getCoresLocator() {
|
|
||||||
return this.persistor;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkForIllegalConfig() throws IOException {
|
|
||||||
// Do sanity checks - we don't want to find new style
|
|
||||||
// config
|
|
||||||
failIfFound("solr/str[@name='adminHandler']");
|
|
||||||
failIfFound("solr/int[@name='coreLoadThreads']");
|
|
||||||
failIfFound("solr/str[@name='coreRootDirectory']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='distribUpdateConnTimeout']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='distribUpdateSoTimeout']");
|
|
||||||
failIfFound("solr/solrcloud/str[@name='host']");
|
|
||||||
failIfFound("solr/solrcloud/str[@name='hostContext']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='hostPort']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='leaderVoteWait']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='genericCoreNodeNames']");
|
|
||||||
failIfFound("solr/str[@name='managementPath']");
|
|
||||||
failIfFound("solr/str[@name='sharedLib']");
|
|
||||||
failIfFound("solr/str[@name='shareSchema']");
|
|
||||||
failIfFound("solr/int[@name='transientCacheSize']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='zkClientTimeout']");
|
|
||||||
failIfFound("solr/solrcloud/int[@name='zkHost']");
|
|
||||||
|
|
||||||
failIfFound("solr/logging/str[@name='class']");
|
|
||||||
failIfFound("solr/logging/str[@name='enabled']");
|
|
||||||
|
|
||||||
failIfFound("solr/logging/watcher/int[@name='size']");
|
|
||||||
failIfFound("solr/logging/watcher/int[@name='threshold']");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void failIfFound(String xPath) {
|
|
||||||
|
|
||||||
if (config.getVal(xPath, false) != null) {
|
|
||||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Should not have found " + xPath +
|
|
||||||
" solr.xml may be a mix of old and new style formats.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPersistent() {
|
|
||||||
return config.getBool("solr/@persistent", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultCoreName() {
|
|
||||||
return get(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, DEFAULT_DEFAULT_CORE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillPropMap() {
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_CORELOADTHREADS, "solr/@coreLoadThreads");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_SHAREDLIB, "solr/@sharedLib");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_ZKHOST, "solr/@zkHost");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_LOGGING_CLASS, "solr/logging/@class");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_LOGGING_ENABLED, "solr/logging/@enabled");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_LOGGING_WATCHER_SIZE, "solr/logging/watcher/@size");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_LOGGING_WATCHER_THRESHOLD, "solr/logging/watcher/@threshold");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_ADMINHANDLER, "solr/cores/@adminHandler");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_COLLECTIONSHANDLER, "solr/cores/@collectionsHandler");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_INFOHANDLER, "solr/cores/@infoHandler");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_DISTRIBUPDATECONNTIMEOUT, "solr/cores/@distribUpdateConnTimeout");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_DISTRIBUPDATESOTIMEOUT, "solr/cores/@distribUpdateSoTimeout");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_MAXUPDATECONNECTIONS, "solr/cores/@maxUpdateConnections");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_MAXUPDATECONNECTIONSPERHOST, "solr/cores/@maxUpdateConnectionsPerHost");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_HOST, "solr/cores/@host");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_HOSTCONTEXT, "solr/cores/@hostContext");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_HOSTPORT, "solr/cores/@hostPort");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_LEADERVOTEWAIT, "solr/cores/@leaderVoteWait");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_GENERICCORENODENAMES, "solr/cores/@genericCoreNodeNames");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERBADNODEEXPIRATION, "solr/cores/@autoReplicaFailoverBadNodeExpiration");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERWAITAFTEREXPIRATION, "solr/cores/@autoReplicaFailoverWaitAfterExpiration");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_AUTOREPLICAFAILOVERWORKLOOPDELAY, "solr/cores/@autoReplicaFailoverWorkLoopDelay");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_ZKACLPROVIDER, "solr/cores/@zkACLProvider");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_ZKCREDENTIALSPROVIDER, "solr/cores/@zkCredentialsProvider");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_MANAGEMENTPATH, "solr/cores/@managementPath");
|
|
||||||
storeConfigPropertyAsBoolean(CfgProp.SOLR_SHARESCHEMA, "solr/cores/@shareSchema");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_TRANSIENTCACHESIZE, "solr/cores/@transientCacheSize");
|
|
||||||
storeConfigPropertyAsInt(CfgProp.SOLR_ZKCLIENTTIMEOUT, "solr/cores/@zkClientTimeout");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_CONFIGSETBASEDIR, "solr/cores/@configSetBaseDir");
|
|
||||||
|
|
||||||
// These have no counterpart in 5.0, asking, for any of these in Solr 5.0
|
|
||||||
// will result in an error being
|
|
||||||
// thrown.
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_CORES_DEFAULT_CORE_NAME, "solr/cores/@defaultCoreName");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_PERSISTENT, "solr/@persistent");
|
|
||||||
storeConfigPropertyAsString(CfgProp.SOLR_ADMINPATH, "solr/cores/@adminPath");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeConfigPropertyAsInt(CfgProp key, String xmlPath) {
|
|
||||||
String valueAsString = config.getVal(xmlPath, false);
|
|
||||||
if (StringUtils.isNotBlank(valueAsString)) {
|
|
||||||
propMap.put(key, Integer.parseInt(valueAsString));
|
|
||||||
} else {
|
|
||||||
propMap.put(key, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeConfigPropertyAsBoolean(CfgProp key, String xmlPath) {
|
|
||||||
String valueAsString = config.getVal(xmlPath, false);
|
|
||||||
if (StringUtils.isNotBlank(valueAsString)) {
|
|
||||||
propMap.put(key, Boolean.parseBoolean(valueAsString));
|
|
||||||
} else {
|
|
||||||
propMap.put(key, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeConfigPropertyAsString(CfgProp key, String xmlPath) {
|
|
||||||
propMap.put(key, config.getVal(xmlPath, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCoreList() throws IOException {
|
|
||||||
|
|
||||||
coreNodes = (NodeList) config.evaluate("solr/cores/core",
|
|
||||||
XPathConstants.NODESET);
|
|
||||||
// Check a couple of error conditions
|
|
||||||
Set<String> names = new HashSet<>(); // for duplicate names
|
|
||||||
Map<String,String> dirs = new HashMap<>(); // for duplicate
|
|
||||||
// data dirs.
|
|
||||||
|
|
||||||
for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
|
|
||||||
Node node = coreNodes.item(idx);
|
|
||||||
String name = DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null);
|
|
||||||
|
|
||||||
String dataDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_DATADIR, null);
|
|
||||||
if (name != null) {
|
|
||||||
if (!names.contains(name)) {
|
|
||||||
names.add(name);
|
|
||||||
} else {
|
|
||||||
String msg = String.format(Locale.ROOT,
|
|
||||||
"More than one core defined for core named %s", name);
|
|
||||||
log.error(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String instDir = DOMUtil.getAttr(node, CoreDescriptor.CORE_INSTDIR, null);
|
|
||||||
|
|
||||||
if (dataDir != null) {
|
|
||||||
String absData = null;
|
|
||||||
File dataFile = new File(dataDir);
|
|
||||||
if (dataFile.isAbsolute()) {
|
|
||||||
absData = dataFile.getCanonicalPath();
|
|
||||||
} else if (instDir != null) {
|
|
||||||
File instFile = new File(instDir);
|
|
||||||
absData = new File(instFile, dataDir).getCanonicalPath();
|
|
||||||
}
|
|
||||||
if (absData != null) {
|
|
||||||
if (!dirs.containsKey(absData)) {
|
|
||||||
dirs.put(absData, name);
|
|
||||||
} else {
|
|
||||||
String msg = String
|
|
||||||
.format(
|
|
||||||
Locale.ROOT,
|
|
||||||
"More than one core points to data dir %s. They are in %s and %s",
|
|
||||||
absData, dirs.get(absData), name);
|
|
||||||
log.warn(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAllCoreNames() {
|
|
||||||
List<String> ret = new ArrayList<>();
|
|
||||||
|
|
||||||
synchronized (coreNodes) {
|
|
||||||
for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
|
|
||||||
Node node = coreNodes.item(idx);
|
|
||||||
ret.add(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProperty(String coreName, String property, String defaultVal) {
|
|
||||||
|
|
||||||
synchronized (coreNodes) {
|
|
||||||
for (int idx = 0; idx < coreNodes.getLength(); ++idx) {
|
|
||||||
Node node = coreNodes.item(idx);
|
|
||||||
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME,
|
|
||||||
null))) {
|
|
||||||
String propVal = DOMUtil.getAttr(node, property);
|
|
||||||
if (propVal == null)
|
|
||||||
propVal = defaultVal;
|
|
||||||
return propVal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultVal;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Properties getCoreProperties(String coreName) {
|
|
||||||
synchronized (coreNodes) {
|
|
||||||
for (int idx = 0; idx < coreNodes.getLength(); idx++) {
|
|
||||||
Node node = coreNodes.item(idx);
|
|
||||||
if (coreName.equals(DOMUtil.getAttr(node, CoreDescriptor.CORE_NAME, null))) {
|
|
||||||
try {
|
|
||||||
return readProperties(node);
|
|
||||||
} catch (XPathExpressionException e) {
|
|
||||||
SolrException.log(log, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Properties();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,21 +17,8 @@
|
||||||
|
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import org.apache.solr.cloud.ZkController;
|
import org.apache.solr.cloud.ZkController;
|
||||||
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
import org.apache.solr.cloud.ZkSolrResourceLoader;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
|
@ -51,8 +38,20 @@ import org.apache.zookeeper.KeeperException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import java.io.File;
|
||||||
import com.google.common.collect.Maps;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,9 +101,14 @@ public class CoreContainer {
|
||||||
protected final CoresLocator coresLocator;
|
protected final CoresLocator coresLocator;
|
||||||
|
|
||||||
private String hostName;
|
private String hostName;
|
||||||
|
|
||||||
private final JarRepository jarRepository = new JarRepository(this);
|
private final JarRepository jarRepository = new JarRepository(this);
|
||||||
|
|
||||||
private Map<String ,SolrRequestHandler> containerHandlers = new HashMap<>();
|
public static final String CORES_HANDLER_PATH = "/admin/cores";
|
||||||
|
public static final String COLLECTIONS_HANDLER_PATH = "/admin/collections";
|
||||||
|
public static final String INFO_HANDLER_PATH = "/admin/info";
|
||||||
|
|
||||||
|
private Map<String, SolrRequestHandler> containerHandlers = new HashMap<>();
|
||||||
|
|
||||||
public SolrRequestHandler getRequestHandler(String path) {
|
public SolrRequestHandler getRequestHandler(String path) {
|
||||||
return RequestHandlerBase.getRequestHandler(path, containerHandlers);
|
return RequestHandlerBase.getRequestHandler(path, containerHandlers);
|
||||||
|
@ -112,7 +116,6 @@ public class CoreContainer {
|
||||||
|
|
||||||
public Map<String, SolrRequestHandler> getRequestHandlers(){
|
public Map<String, SolrRequestHandler> getRequestHandlers(){
|
||||||
return this.containerHandlers;
|
return this.containerHandlers;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();
|
// private ClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();
|
||||||
|
@ -137,7 +140,7 @@ public class CoreContainer {
|
||||||
* @see #load()
|
* @see #load()
|
||||||
*/
|
*/
|
||||||
public CoreContainer(SolrResourceLoader loader) {
|
public CoreContainer(SolrResourceLoader loader) {
|
||||||
this(loader, ConfigSolr.fromSolrHome(loader, loader.getInstanceDir()));
|
this(ConfigSolr.fromSolrHome(loader, loader.getInstanceDir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,19 +157,15 @@ public class CoreContainer {
|
||||||
* Create a new CoreContainer using the given SolrResourceLoader,
|
* Create a new CoreContainer using the given SolrResourceLoader,
|
||||||
* configuration and CoresLocator. The container's cores are
|
* configuration and CoresLocator. The container's cores are
|
||||||
* not loaded.
|
* not loaded.
|
||||||
* @param loader the SolrResourceLoader
|
|
||||||
* @param config a ConfigSolr representation of this container's configuration
|
* @param config a ConfigSolr representation of this container's configuration
|
||||||
* @see #load()
|
* @see #load()
|
||||||
*/
|
*/
|
||||||
public CoreContainer(SolrResourceLoader loader, ConfigSolr config) {
|
public CoreContainer(ConfigSolr config) {
|
||||||
this.loader = checkNotNull(loader);
|
this(config, config.getCoresLocator());
|
||||||
this.solrHome = loader.getInstanceDir();
|
|
||||||
this.cfg = checkNotNull(config);
|
|
||||||
this.coresLocator = config.getCoresLocator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoreContainer(SolrResourceLoader loader, ConfigSolr config, CoresLocator locator) {
|
public CoreContainer(ConfigSolr config, CoresLocator locator) {
|
||||||
this.loader = checkNotNull(loader);
|
this.loader = config.getSolrResourceLoader();
|
||||||
this.solrHome = loader.getInstanceDir();
|
this.solrHome = loader.getInstanceDir();
|
||||||
this.cfg = checkNotNull(config);
|
this.cfg = checkNotNull(config);
|
||||||
this.coresLocator = locator;
|
this.coresLocator = locator;
|
||||||
|
@ -194,7 +193,7 @@ public class CoreContainer {
|
||||||
*/
|
*/
|
||||||
public static CoreContainer createAndLoad(String solrHome, File configFile) {
|
public static CoreContainer createAndLoad(String solrHome, File configFile) {
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
SolrResourceLoader loader = new SolrResourceLoader(solrHome);
|
||||||
CoreContainer cc = new CoreContainer(loader, ConfigSolr.fromFile(loader, configFile));
|
CoreContainer cc = new CoreContainer(ConfigSolr.fromFile(loader, configFile));
|
||||||
try {
|
try {
|
||||||
cc.load();
|
cc.load();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -243,15 +242,15 @@ public class CoreContainer {
|
||||||
zkSys.initZooKeeper(this, solrHome, cfg);
|
zkSys.initZooKeeper(this, solrHome, cfg);
|
||||||
|
|
||||||
collectionsHandler = createHandler(cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
|
collectionsHandler = createHandler(cfg.getCollectionsHandlerClass(), CollectionsHandler.class);
|
||||||
containerHandlers.put("/admin/collections" , collectionsHandler);
|
containerHandlers.put(COLLECTIONS_HANDLER_PATH, collectionsHandler);
|
||||||
infoHandler = createHandler(cfg.getInfoHandlerClass(), InfoHandler.class);
|
infoHandler = createHandler(cfg.getInfoHandlerClass(), InfoHandler.class);
|
||||||
containerHandlers.put("/admin/info" , infoHandler);
|
containerHandlers.put(INFO_HANDLER_PATH, infoHandler);
|
||||||
coreAdminHandler = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
|
coreAdminHandler = createHandler(cfg.getCoreAdminHandlerClass(), CoreAdminHandler.class);
|
||||||
containerHandlers.put(cfg.getAdminPath() , coreAdminHandler);
|
containerHandlers.put(CORES_HANDLER_PATH, coreAdminHandler);
|
||||||
|
|
||||||
coreConfigService = cfg.createCoreConfigService(loader, zkSys.getZkController());
|
coreConfigService = cfg.createCoreConfigService(loader, zkSys.getZkController());
|
||||||
|
|
||||||
containerProperties = cfg.getSolrProperties("solr");
|
containerProperties = cfg.getSolrProperties();
|
||||||
|
|
||||||
// setup executor to load cores in parallel
|
// setup executor to load cores in parallel
|
||||||
// do not limit the size of the executor in zk mode since cores may try and wait for each other.
|
// do not limit the size of the executor in zk mode since cores may try and wait for each other.
|
||||||
|
@ -599,8 +598,6 @@ public class CoreContainer {
|
||||||
*/
|
*/
|
||||||
public void reload(String name) {
|
public void reload(String name) {
|
||||||
|
|
||||||
name = checkDefault(name);
|
|
||||||
|
|
||||||
SolrCore core = solrCores.getCoreFromAnyList(name, false);
|
SolrCore core = solrCores.getCoreFromAnyList(name, false);
|
||||||
if (core == null)
|
if (core == null)
|
||||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name );
|
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "No such core: " + name );
|
||||||
|
@ -623,11 +620,6 @@ public class CoreContainer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//5.0 remove all checkDefaults?
|
|
||||||
private String checkDefault(String name) {
|
|
||||||
return (null == name || name.isEmpty()) ? getDefaultCoreName() : name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swaps two SolrCore descriptors.
|
* Swaps two SolrCore descriptors.
|
||||||
*/
|
*/
|
||||||
|
@ -635,8 +627,6 @@ public class CoreContainer {
|
||||||
if( n0 == null || n1 == null ) {
|
if( n0 == null || n1 == null ) {
|
||||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Can not swap unnamed cores." );
|
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Can not swap unnamed cores." );
|
||||||
}
|
}
|
||||||
n0 = checkDefault(n0);
|
|
||||||
n1 = checkDefault(n1);
|
|
||||||
solrCores.swap(n0, n1);
|
solrCores.swap(n0, n1);
|
||||||
|
|
||||||
coresLocator.swap(this, solrCores.getCoreDescriptor(n0), solrCores.getCoreDescriptor(n1));
|
coresLocator.swap(this, solrCores.getCoreDescriptor(n0), solrCores.getCoreDescriptor(n1));
|
||||||
|
@ -662,8 +652,6 @@ public class CoreContainer {
|
||||||
*/
|
*/
|
||||||
public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir) {
|
public void unload(String name, boolean deleteIndexDir, boolean deleteDataDir, boolean deleteInstanceDir) {
|
||||||
|
|
||||||
name = checkDefault(name);
|
|
||||||
|
|
||||||
// check for core-init errors first
|
// check for core-init errors first
|
||||||
CoreLoadFailure loadFailure = coreInitFailures.remove(name);
|
CoreLoadFailure loadFailure = coreInitFailures.remove(name);
|
||||||
if (loadFailure != null) {
|
if (loadFailure != null) {
|
||||||
|
@ -715,7 +703,6 @@ public class CoreContainer {
|
||||||
try (SolrCore core = getCore(name)) {
|
try (SolrCore core = getCore(name)) {
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
registerCore(toName, core, true);
|
registerCore(toName, core, true);
|
||||||
name = checkDefault(name);
|
|
||||||
SolrCore old = solrCores.remove(name);
|
SolrCore old = solrCores.remove(name);
|
||||||
coresLocator.rename(this, old.getCoreDescriptor(), core.getCoreDescriptor());
|
coresLocator.rename(this, old.getCoreDescriptor(), core.getCoreDescriptor());
|
||||||
}
|
}
|
||||||
|
@ -753,8 +740,6 @@ public class CoreContainer {
|
||||||
*/
|
*/
|
||||||
public SolrCore getCore(String name) {
|
public SolrCore getCore(String name) {
|
||||||
|
|
||||||
name = checkDefault(name);
|
|
||||||
|
|
||||||
// Do this in two phases since we don't want to lock access to the cores over a load.
|
// Do this in two phases since we don't want to lock access to the cores over a load.
|
||||||
SolrCore core = solrCores.getCoreFromAnyList(name, true);
|
SolrCore core = solrCores.getCoreFromAnyList(name, true);
|
||||||
|
|
||||||
|
@ -821,26 +806,6 @@ public class CoreContainer {
|
||||||
return infoHandler;
|
return infoHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------- Multicore self related methods ---------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the default core name, or null if there is no default core name
|
|
||||||
*/
|
|
||||||
public String getDefaultCoreName() {
|
|
||||||
return cfg.getDefaultCoreName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// all of the following properties aren't synchronized
|
|
||||||
// but this should be OK since they normally won't be changed rapidly
|
|
||||||
@Deprecated
|
|
||||||
public boolean isPersistent() {
|
|
||||||
return cfg.isPersistent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAdminPath() {
|
|
||||||
return cfg.getAdminPath();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHostName() {
|
public String getHostName() {
|
||||||
return this.hostName;
|
return this.hostName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,240 +0,0 @@
|
||||||
package org.apache.solr.core;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes any changes in core definitions to this instance's solr.xml
|
|
||||||
*/
|
|
||||||
public class SolrXMLCoresLocator implements CoresLocator {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SolrXMLCoresLocator.class);
|
|
||||||
|
|
||||||
private final String solrXmlTemplate;
|
|
||||||
private final ConfigSolrXmlOld cfg;
|
|
||||||
|
|
||||||
/** Core name to use if a core definition has no name */
|
|
||||||
public static final String DEFAULT_CORE_NAME = "collection1";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new SolrXMLCoresLocator
|
|
||||||
* @param originalXML the original content of the solr.xml file
|
|
||||||
* @param cfg the CoreContainer's config object
|
|
||||||
*/
|
|
||||||
public SolrXMLCoresLocator(String originalXML, ConfigSolrXmlOld cfg) {
|
|
||||||
this.solrXmlTemplate = buildTemplate(originalXML);
|
|
||||||
this.cfg = cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Pattern POPULATED_CORES_TAG
|
|
||||||
= Pattern.compile("^(.*<cores[^>]*>)(.*)(</cores>.*)$", Pattern.DOTALL);
|
|
||||||
private static Pattern EMPTY_CORES_TAG
|
|
||||||
= Pattern.compile("^(.*<cores[^>]*)/>(.*)$", Pattern.DOTALL);
|
|
||||||
|
|
||||||
private static Pattern SHARD_HANDLER_TAG
|
|
||||||
= Pattern.compile("(<shardHandlerFactory[^>]*>.*</shardHandlerFactory>)|(<shardHandlerFactory[^>]*/>)",
|
|
||||||
Pattern.DOTALL);
|
|
||||||
|
|
||||||
private static String CORES_PLACEHOLDER = "{{CORES_PLACEHOLDER}}";
|
|
||||||
|
|
||||||
// Package-private for testing
|
|
||||||
// We replace the existing <cores></cores> contents with a template pattern
|
|
||||||
// that we can later replace with the up-to-date core definitions. We also
|
|
||||||
// need to extract the <shardHandlerFactory> section, as, annoyingly, it's
|
|
||||||
// kept inside <cores/>.
|
|
||||||
static String buildTemplate(String originalXML) {
|
|
||||||
|
|
||||||
String shardHandlerConfig = "";
|
|
||||||
Matcher shfMatcher = SHARD_HANDLER_TAG.matcher(originalXML);
|
|
||||||
if (shfMatcher.find()) {
|
|
||||||
shardHandlerConfig = shfMatcher.group(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matcher popMatcher = POPULATED_CORES_TAG.matcher(originalXML);
|
|
||||||
if (popMatcher.matches()) {
|
|
||||||
return new StringBuilder(popMatcher.group(1))
|
|
||||||
.append(CORES_PLACEHOLDER).append(shardHandlerConfig).append(popMatcher.group(3)).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Self-closing <cores/> tag gets expanded to <cores></cores>
|
|
||||||
Matcher emptyMatcher = EMPTY_CORES_TAG.matcher(originalXML);
|
|
||||||
if (emptyMatcher.matches())
|
|
||||||
return new StringBuilder(emptyMatcher.group(1))
|
|
||||||
.append(">").append(CORES_PLACEHOLDER).append("</cores>")
|
|
||||||
.append(emptyMatcher.group(2)).toString();
|
|
||||||
|
|
||||||
// If there's no <cores> tag at all, add one at the end of the file
|
|
||||||
return originalXML.replace("</solr>", "<cores>" + CORES_PLACEHOLDER + "</cores></solr>");
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected access for testing
|
|
||||||
protected String buildSolrXML(List<CoreDescriptor> cds) {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
for (CoreDescriptor cd : cds) {
|
|
||||||
builder.append(buildCoreTag(cd));
|
|
||||||
}
|
|
||||||
return solrXmlTemplate.replace(CORES_PLACEHOLDER, builder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String NEWLINE = System.getProperty("line.separator");
|
|
||||||
public static final String INDENT = " ";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize a coredescriptor as a String containing an XML <core> tag.
|
|
||||||
* @param cd the CoreDescriptor
|
|
||||||
* @return an XML representation of the CoreDescriptor
|
|
||||||
*/
|
|
||||||
protected static String buildCoreTag(CoreDescriptor cd) {
|
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder(NEWLINE).append(INDENT).append("<core");
|
|
||||||
for (Map.Entry<Object, Object> entry : cd.getPersistableStandardProperties().entrySet()) {
|
|
||||||
builder.append(" ").append(entry.getKey()).append("=\"").append(entry.getValue()).append("\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
Properties userProperties = cd.getPersistableUserProperties();
|
|
||||||
if (userProperties.isEmpty()) {
|
|
||||||
return builder.append("/>").append(NEWLINE).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append(">").append(NEWLINE);
|
|
||||||
for (Map.Entry<Object, Object> entry : userProperties.entrySet()) {
|
|
||||||
builder.append(INDENT).append(INDENT)
|
|
||||||
.append("<property name=\"").append(entry.getKey()).append("\" value=\"")
|
|
||||||
.append(entry.getValue()).append("\"/>").append(NEWLINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.append("</core>").append(NEWLINE).toString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized final void persist(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
|
||||||
List<CoreDescriptor> cds = new ArrayList<>(cc.getCoreDescriptors().size() + coreDescriptors.length);
|
|
||||||
|
|
||||||
cds.addAll(cc.getCoreDescriptors());
|
|
||||||
cds.addAll(Arrays.asList(coreDescriptors));
|
|
||||||
|
|
||||||
doPersist(buildSolrXML(cds));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doPersist(String xml) {
|
|
||||||
File file = new File(cfg.config.getResourceLoader().getInstanceDir(), ConfigSolr.SOLR_XML_FILE);
|
|
||||||
Writer writer = null;
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
try {
|
|
||||||
fos = new FileOutputStream(file);
|
|
||||||
writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
|
|
||||||
writer.write(xml);
|
|
||||||
writer.close();
|
|
||||||
logger.info("Persisted core descriptions to {}", file.getAbsolutePath());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("Couldn't persist core descriptions to {} : {}",
|
|
||||||
file.getAbsolutePath(), e);
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(writer);
|
|
||||||
IOUtils.closeQuietly(fos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
|
||||||
this.persist(cc, coreDescriptors);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
|
||||||
// coreDescriptors is kind of a useless param - we persist the current state off cc
|
|
||||||
this.persist(cc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void rename(CoreContainer cc, CoreDescriptor oldCD, CoreDescriptor newCD) {
|
|
||||||
// we don't need those params, we just write out the current cc state
|
|
||||||
this.persist(cc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void swap(CoreContainer cc, CoreDescriptor cd1, CoreDescriptor cd2) {
|
|
||||||
this.persist(cc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<CoreDescriptor> discover(CoreContainer cc) {
|
|
||||||
|
|
||||||
ImmutableList.Builder<CoreDescriptor> listBuilder = ImmutableList.builder();
|
|
||||||
|
|
||||||
for (String coreName : cfg.getAllCoreNames()) {
|
|
||||||
|
|
||||||
String name = cfg.getProperty(coreName, CoreDescriptor.CORE_NAME, DEFAULT_CORE_NAME);
|
|
||||||
String instanceDir = cfg.getProperty(coreName, CoreDescriptor.CORE_INSTDIR, "");
|
|
||||||
|
|
||||||
Properties coreProperties = new Properties();
|
|
||||||
for (String propName : CoreDescriptor.standardPropNames) {
|
|
||||||
String propValue = cfg.getProperty(coreName, propName, "");
|
|
||||||
if (StringUtils.isNotEmpty(propValue))
|
|
||||||
coreProperties.setProperty(propName, propValue);
|
|
||||||
}
|
|
||||||
coreProperties.putAll(cfg.getCoreProperties(coreName));
|
|
||||||
|
|
||||||
listBuilder.add(new CoreDescriptor(cc, name, instanceDir, coreProperties));
|
|
||||||
}
|
|
||||||
|
|
||||||
return listBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
// for testing
|
|
||||||
String getTemplate() {
|
|
||||||
return solrXmlTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NonPersistingLocator extends SolrXMLCoresLocator {
|
|
||||||
|
|
||||||
public NonPersistingLocator(String originalXML, ConfigSolrXmlOld cfg) {
|
|
||||||
super(originalXML, cfg);
|
|
||||||
this.xml = originalXML;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doPersist(String xml) {
|
|
||||||
this.xml = xml;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String xml;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,25 +17,8 @@
|
||||||
|
|
||||||
package org.apache.solr.handler.admin;
|
package org.apache.solr.handler.admin;
|
||||||
|
|
||||||
import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||||
|
@ -67,7 +50,6 @@ import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.DirectoryFactory;
|
import org.apache.solr.core.DirectoryFactory;
|
||||||
import org.apache.solr.core.DirectoryFactory.DirContext;
|
import org.apache.solr.core.DirectoryFactory.DirContext;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrXMLCoresLocator;
|
|
||||||
import org.apache.solr.handler.RequestHandlerBase;
|
import org.apache.solr.handler.RequestHandlerBase;
|
||||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
|
@ -86,8 +68,24 @@ import org.apache.zookeeper.KeeperException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import java.io.File;
|
||||||
import com.google.common.collect.Lists;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -586,12 +584,7 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
||||||
|
|
||||||
// only write out the descriptor if the core is successfully created
|
// only write out the descriptor if the core is successfully created
|
||||||
coreContainer.getCoresLocator().create(coreContainer, dcore);
|
coreContainer.getCoresLocator().create(coreContainer, dcore);
|
||||||
|
|
||||||
if (coreContainer.getCoresLocator() instanceof SolrXMLCoresLocator) {
|
|
||||||
// hack - in this case we persist once more because a core create race might
|
|
||||||
// have dropped entries.
|
|
||||||
coreContainer.getCoresLocator().create(coreContainer);
|
|
||||||
}
|
|
||||||
rsp.add("core", core.getName());
|
rsp.add("core", core.getName());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -694,7 +687,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (cname == null) {
|
if (cname == null) {
|
||||||
rsp.add("defaultCoreName", coreContainer.getDefaultCoreName());
|
|
||||||
for (String name : coreContainer.getAllCoreNames()) {
|
for (String name : coreContainer.getAllCoreNames()) {
|
||||||
status.add(name, getCoreStatus(coreContainer, name, isIndexInfoNeeded));
|
status.add(name, getCoreStatus(coreContainer, name, isIndexInfoNeeded));
|
||||||
}
|
}
|
||||||
|
@ -1111,7 +1103,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
||||||
CoreDescriptor desc = cores.getUnloadedCoreDescriptor(cname);
|
CoreDescriptor desc = cores.getUnloadedCoreDescriptor(cname);
|
||||||
if (desc != null) {
|
if (desc != null) {
|
||||||
info.add("name", desc.getName());
|
info.add("name", desc.getName());
|
||||||
info.add("isDefaultCore", desc.getName().equals(cores.getDefaultCoreName()));
|
|
||||||
info.add("instanceDir", desc.getInstanceDir());
|
info.add("instanceDir", desc.getInstanceDir());
|
||||||
// None of the following are guaranteed to be present in a not-yet-loaded core.
|
// None of the following are guaranteed to be present in a not-yet-loaded core.
|
||||||
String tmp = desc.getDataDir();
|
String tmp = desc.getDataDir();
|
||||||
|
@ -1126,7 +1117,6 @@ public class CoreAdminHandler extends RequestHandlerBase {
|
||||||
try (SolrCore core = cores.getCore(cname)) {
|
try (SolrCore core = cores.getCore(cname)) {
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
info.add("name", core.getName());
|
info.add("name", core.getName());
|
||||||
info.add("isDefaultCore", core.getName().equals(cores.getDefaultCoreName()));
|
|
||||||
info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir()));
|
info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir()));
|
||||||
info.add("dataDir", normalizePath(core.getDataDir()));
|
info.add("dataDir", normalizePath(core.getDataDir()));
|
||||||
info.add("config", core.getConfigResource());
|
info.add("config", core.getConfigResource());
|
||||||
|
|
|
@ -17,20 +17,19 @@
|
||||||
|
|
||||||
package org.apache.solr.servlet;
|
package org.apache.solr.servlet;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import org.apache.commons.io.IOUtils;
|
||||||
import java.io.IOException;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import java.io.OutputStreamWriter;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import java.io.Writer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import org.apache.commons.io.IOUtils;
|
import java.io.InputStream;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import java.io.OutputStreamWriter;
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import java.io.Writer;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import java.nio.charset.StandardCharsets;
|
||||||
import org.apache.solr.core.SolrCore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple servlet to load the Solr Admin UI
|
* A simple servlet to load the Solr Admin UI
|
||||||
|
@ -63,7 +62,7 @@ public final class LoadAdminUiServlet extends BaseSolrServlet {
|
||||||
};
|
};
|
||||||
String[] replace = new String[] {
|
String[] replace = new String[] {
|
||||||
StringEscapeUtils.escapeJavaScript(request.getContextPath()),
|
StringEscapeUtils.escapeJavaScript(request.getContextPath()),
|
||||||
StringEscapeUtils.escapeJavaScript(cores.getAdminPath()),
|
StringEscapeUtils.escapeJavaScript(CoreContainer.CORES_HANDLER_PATH),
|
||||||
StringEscapeUtils.escapeJavaScript(pack.getSpecificationVersion())
|
StringEscapeUtils.escapeJavaScript(pack.getSpecificationVersion())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||||
protected CoreContainer createCoreContainer() {
|
protected CoreContainer createCoreContainer() {
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
|
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
|
||||||
ConfigSolr config = loadConfigSolr(loader);
|
ConfigSolr config = loadConfigSolr(loader);
|
||||||
CoreContainer cores = new CoreContainer(loader, config);
|
CoreContainer cores = new CoreContainer(config);
|
||||||
cores.load();
|
cores.load();
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
|
@ -250,22 +250,18 @@ public class SolrDispatchFilter extends BaseSolrFilter {
|
||||||
path = path.substring( 0, idx );
|
path = path.substring( 0, idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for the core admin page
|
|
||||||
if( path.equals( cores.getAdminPath() ) ) {
|
boolean usingAliases = false;
|
||||||
handler = cores.getMultiCoreHandler();
|
List<String> collectionsList = null;
|
||||||
solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);
|
|
||||||
|
// Check for container handlers
|
||||||
|
handler = cores.getRequestHandler(path);
|
||||||
|
if (handler != null) {
|
||||||
|
solrReq = SolrRequestParsers.DEFAULT.parse(null, path, req);
|
||||||
handleAdminRequest(req, response, handler, solrReq);
|
handleAdminRequest(req, response, handler, solrReq);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean usingAliases = false;
|
else {
|
||||||
List<String> collectionsList = null;
|
|
||||||
// Check for the core admin collections url
|
|
||||||
handler = cores.getRequestHandler(path);
|
|
||||||
if( handler!= null ) {
|
|
||||||
solrReq = SolrRequestParsers.DEFAULT.parse(null,path, req);
|
|
||||||
handleAdminRequest(req, response, handler, solrReq);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
//otherwise, we should find a core from the path
|
//otherwise, we should find a core from the path
|
||||||
idx = path.indexOf( "/", 1 );
|
idx = path.indexOf( "/", 1 );
|
||||||
if( idx > 1 ) {
|
if( idx > 1 ) {
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
<requestHandler name="/replication" class="solr.ReplicationHandler">
|
<requestHandler name="/replication" class="solr.ReplicationHandler">
|
||||||
<lst name="slave">
|
<lst name="slave">
|
||||||
<str name="masterUrl">http://127.0.0.1:TEST_PORT/solr</str>
|
<str name="masterUrl">http://127.0.0.1:TEST_PORT/solr/collection1</str>
|
||||||
<str name="pollInterval">00:00:01</str>
|
<str name="pollInterval">00:00:01</str>
|
||||||
<str name="compression">COMPRESSION</str>
|
<str name="compression">COMPRESSION</str>
|
||||||
</lst>
|
</lst>
|
||||||
|
|
|
@ -15,15 +15,11 @@
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
<schema name="minimal" version="1.1">
|
||||||
<!--
|
<types>
|
||||||
old-style solr.xml specifying a custom shardHandlerFactory
|
<fieldType name="string" class="solr.StrField"/>
|
||||||
-->
|
</types>
|
||||||
<solr>
|
<fields>
|
||||||
<cores>
|
<dynamicField name="*" type="string" indexed="true" stored="true" />
|
||||||
<shardHandlerFactory name="shardHandlerFactory"
|
</fields>
|
||||||
class="org.apache.solr.core.MockShardHandlerFactory">
|
</schema>
|
||||||
<str name="myMagicRequiredParameter">myMagicRequiredValue</str>
|
|
||||||
</shardHandlerFactory>
|
|
||||||
</cores>
|
|
||||||
</solr>
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?xml version="1.0" ?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<config>
|
||||||
|
|
||||||
|
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
|
||||||
|
|
||||||
|
<luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
|
||||||
|
|
||||||
|
<indexConfig>
|
||||||
|
<mergePolicy class="org.apache.solr.update.DummyMergePolicy"/>
|
||||||
|
<mergeFactor>8</mergeFactor>
|
||||||
|
</indexConfig>
|
||||||
|
|
||||||
|
<updateHandler class="solr.DirectUpdateHandler2"/>
|
||||||
|
<requestHandler name="standard" class="solr.StandardRequestHandler"></requestHandler>
|
||||||
|
|
||||||
|
</config>
|
|
@ -1,41 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!--
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
All (relative) paths are relative to the installation path
|
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
|
||||||
-->
|
|
||||||
<solr persistent="${solr.xml.persist:true}">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
adminPath: RequestHandler path to manage cores.
|
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
|
||||||
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" numShards="${numShards:3}" shareSchema="${shareSchema:false}"
|
|
||||||
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
|
||||||
distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:3400000}">
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
|
||||||
<int name="socketTimeout">${socketTimeout:120000}</int>
|
|
||||||
<int name="connTimeout">${connTimeout:15000}</int>
|
|
||||||
</shardHandlerFactory>
|
|
||||||
</cores>
|
|
||||||
|
|
||||||
</solr>
|
|
|
@ -19,6 +19,8 @@
|
||||||
<solr>
|
<solr>
|
||||||
|
|
||||||
<str name="shareSchema">${shareSchema:false}</str>
|
<str name="shareSchema">${shareSchema:false}</str>
|
||||||
|
<str name="configSetBaseDir">${configSetBaseDir:configsets}</str>
|
||||||
|
<str name="coreRootDirectory">${coreRootDirectory:.}</str>
|
||||||
|
|
||||||
<solrcloud>
|
<solrcloud>
|
||||||
<str name="host">127.0.0.1</str>
|
<str name="host">127.0.0.1</str>
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!--
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!--
|
|
||||||
All (relative) paths are relative to the installation path
|
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
|
||||||
-->
|
|
||||||
<solr persistent="${solr.xml.persist:true}">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
adminPath: RequestHandler path to manage cores.
|
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
|
||||||
hostContext="${hostContext:solr}">
|
|
||||||
<core name="00000_core" instanceDir="00000_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="false" loadOnStartup="true" />
|
|
||||||
<core name="00001_core" instanceDir="00001_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00002_core" instanceDir="00002_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00003_core" instanceDir="00003_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00004_core" instanceDir="00004_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00005_core" instanceDir="00005_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00006_core" instanceDir="00006_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00007_core" instanceDir="00007_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00008_core" instanceDir="00008_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00009_core" instanceDir="00009_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00010_core" instanceDir="00010_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00011_core" instanceDir="00011_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00012_core" instanceDir="00012_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00013_core" instanceDir="00013_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00014_core" instanceDir="00014_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00015_core" instanceDir="00015_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00016_core" instanceDir="00016_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00017_core" instanceDir="00017_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00018_core" instanceDir="00018_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<core name="00019_core" instanceDir="00019_core" schema="schema-tiny.xml" config="solrconfig-minimal.xml" transient="true" loadOnStartup="false" />
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
|
||||||
<int name="socketTimeout">${socketTimeout:90000}</int>
|
|
||||||
<int name="connTimeout">${connTimeout:15000}</int>
|
|
||||||
</shardHandlerFactory>
|
|
||||||
</cores>
|
|
||||||
|
|
||||||
</solr>
|
|
|
@ -18,27 +18,28 @@
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
All (relative) paths are relative to the installation path
|
All (relative) paths are relative to the installation path
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
|
||||||
-->
|
-->
|
||||||
<solr persistent="${solr.xml.persist:false}">
|
<solr>
|
||||||
|
|
||||||
<!--
|
<str name="shareSchema">${shareSchema:false}</str>
|
||||||
adminPath: RequestHandler path to manage cores.
|
<str name="configSetBaseDir">${configSetBaseDir:configsets}</str>
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
<str name="coreRootDirectory">${coreRootDirectory:.}</str>
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" shareSchema="${shareSchema:false}"
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
<int name="socketTimeout">${socketTimeout:90000}</int>
|
||||||
distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:340000}">
|
<int name="connTimeout">${connTimeout:15000}</int>
|
||||||
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
|
</shardHandlerFactory>
|
||||||
coreNodeName="${coreNodeName:}"/>
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
<solrcloud>
|
||||||
<str name="urlScheme">${urlScheme:}</str>
|
<str name="host">127.0.0.1</str>
|
||||||
<int name="socketTimeout">${socketTimeout:90000}</int>
|
<int name="hostPort">${hostPort:8983}</int>
|
||||||
<int name="connTimeout">${connTimeout:15000}</int>
|
<str name="hostContext">${hostContext:solr}</str>
|
||||||
</shardHandlerFactory>
|
<int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>
|
||||||
</cores>
|
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
|
||||||
|
<int name="leaderVoteWait">0</int>
|
||||||
|
<int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>
|
||||||
|
<int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>
|
||||||
|
</solrcloud>
|
||||||
|
|
||||||
</solr>
|
</solr>
|
||||||
|
|
|
@ -16,20 +16,21 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr;
|
package org.apache.solr;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p> Test for Loading core properties from a properties file </p>
|
* <p> Test for Loading core properties from a properties file </p>
|
||||||
|
@ -39,6 +40,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
*/
|
*/
|
||||||
public class TestSolrCoreProperties extends SolrJettyTestBase {
|
public class TestSolrCoreProperties extends SolrJettyTestBase {
|
||||||
|
|
||||||
|
// TODO these properties files don't work with configsets
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeTest() throws Exception {
|
public static void beforeTest() throws Exception {
|
||||||
File homeDir = createTempDir().toFile();
|
File homeDir = createTempDir().toFile();
|
||||||
|
@ -68,7 +71,19 @@ public class TestSolrCoreProperties extends SolrJettyTestBase {
|
||||||
p.store(fos, null);
|
p.store(fos, null);
|
||||||
IOUtils.close(fos);
|
IOUtils.close(fos);
|
||||||
|
|
||||||
createJetty(homeDir.getAbsolutePath(), null, null);
|
Files.createFile(collDir.toPath().resolve("core.properties"));
|
||||||
|
|
||||||
|
jetty = new JettySolrRunner(homeDir.getAbsolutePath(), "/solr", 0, null, null, true, null, sslConfig);
|
||||||
|
|
||||||
|
// this sets the property for jetty starting SolrDispatchFilter
|
||||||
|
if (System.getProperty("solr.data.dir") == null && System.getProperty("solr.hdfs.home") == null) {
|
||||||
|
jetty.setDataDir(createTempDir().toFile().getCanonicalPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
jetty.start();
|
||||||
|
port = jetty.getLocalPort();
|
||||||
|
|
||||||
|
//createJetty(homeDir.getAbsolutePath(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package org.apache.solr;
|
package org.apache.solr;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||||
|
@ -21,6 +17,10 @@ import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -60,7 +60,7 @@ public class TestTolerantSearch extends SolrJettyTestBase {
|
||||||
solrHome = createSolrHome();
|
solrHome = createSolrHome();
|
||||||
createJetty(solrHome.getAbsolutePath(), null, null);
|
createJetty(solrHome.getAbsolutePath(), null, null);
|
||||||
String url = jetty.getBaseUrl().toString();
|
String url = jetty.getBaseUrl().toString();
|
||||||
collection1 = new HttpSolrClient(url);
|
collection1 = new HttpSolrClient(url + "/collection1");
|
||||||
collection2 = new HttpSolrClient(url + "/collection2");
|
collection2 = new HttpSolrClient(url + "/collection2");
|
||||||
|
|
||||||
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
|
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
|
||||||
|
@ -69,9 +69,16 @@ public class TestTolerantSearch extends SolrJettyTestBase {
|
||||||
shard2 = urlCollection2.replaceAll("https?://", "");
|
shard2 = urlCollection2.replaceAll("https?://", "");
|
||||||
|
|
||||||
//create second core
|
//create second core
|
||||||
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
|
HttpSolrClient nodeClient = new HttpSolrClient(url);
|
||||||
req.setCoreName("collection2");
|
try {
|
||||||
collection1.request(req);
|
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
|
||||||
|
req.setCoreName("collection2");
|
||||||
|
req.setConfigSet("collection1");
|
||||||
|
nodeClient.request(req);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
nodeClient.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
SolrInputDocument doc = new SolrInputDocument();
|
SolrInputDocument doc = new SolrInputDocument();
|
||||||
doc.setField("id", "1");
|
doc.setField("id", "1");
|
||||||
|
|
|
@ -41,6 +41,8 @@ import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test sync phase that occurs when Leader goes down and a new Leader is
|
* Test sync phase that occurs when Leader goes down and a new Leader is
|
||||||
|
@ -48,6 +50,8 @@ import org.junit.BeforeClass;
|
||||||
*/
|
*/
|
||||||
@Slow
|
@Slow
|
||||||
public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
|
public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AliasIntegrationTest.class);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeSuperClass() throws Exception {
|
public static void beforeSuperClass() throws Exception {
|
||||||
|
@ -80,12 +84,14 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doTest() throws Exception {
|
public void doTest() throws Exception {
|
||||||
|
|
||||||
handle.clear();
|
handle.clear();
|
||||||
handle.put("timestamp", SKIPVAL);
|
handle.put("timestamp", SKIPVAL);
|
||||||
|
|
||||||
waitForThingsToLevelOut(30);
|
waitForThingsToLevelOut(30);
|
||||||
|
|
||||||
|
logger.info("### STARTING ACTUAL TEST");
|
||||||
|
|
||||||
del("*:*");
|
del("*:*");
|
||||||
|
|
||||||
createCollection("collection2", 2, 1, 10);
|
createCollection("collection2", 2, 1, 10);
|
||||||
|
@ -258,6 +264,8 @@ public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
|
||||||
sawException = true;
|
sawException = true;
|
||||||
}
|
}
|
||||||
assertTrue(sawException);
|
assertTrue(sawException);
|
||||||
|
|
||||||
|
logger.info("### FINISHED ACTUAL TEST");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAlias(String alias, String collections)
|
private void createAlias(String alias, String collections)
|
||||||
|
|
|
@ -54,7 +54,6 @@ import org.apache.solr.common.util.StrUtils;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrInfoMBean.Category;
|
import org.apache.solr.core.SolrInfoMBean.Category;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
|
||||||
import org.apache.solr.servlet.SolrDispatchFilter;
|
import org.apache.solr.servlet.SolrDispatchFilter;
|
||||||
import org.apache.solr.update.DirectUpdateHandler2;
|
import org.apache.solr.update.DirectUpdateHandler2;
|
||||||
import org.apache.solr.util.DefaultSolrThreadFactory;
|
import org.apache.solr.util.DefaultSolrThreadFactory;
|
||||||
|
@ -64,10 +63,12 @@ import org.junit.BeforeClass;
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerFactory;
|
import javax.management.MBeanServerFactory;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -110,7 +111,6 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
||||||
|
|
||||||
// we randomly use a second config set rather than just one
|
// we randomly use a second config set rather than just one
|
||||||
private boolean secondConfigSet = random().nextBoolean();
|
private boolean secondConfigSet = random().nextBoolean();
|
||||||
private boolean oldStyleSolrXml = false;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeThisClass2() throws Exception {
|
public static void beforeThisClass2() throws Exception {
|
||||||
|
@ -123,13 +123,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
useJettyDataDir = false;
|
useJettyDataDir = false;
|
||||||
|
|
||||||
oldStyleSolrXml = random().nextBoolean();
|
|
||||||
if (oldStyleSolrXml) {
|
|
||||||
System.err.println("Using old style solr.xml");
|
|
||||||
} else {
|
|
||||||
System.err.println("Using new style solr.xml");
|
|
||||||
}
|
|
||||||
if (secondConfigSet ) {
|
if (secondConfigSet ) {
|
||||||
String zkHost = zkServer.getZkHost();
|
String zkHost = zkServer.getZkHost();
|
||||||
String zkAddress = zkServer.getZkAddress();
|
String zkAddress = zkServer.getZkAddress();
|
||||||
|
@ -158,12 +152,11 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
||||||
}
|
}
|
||||||
|
|
||||||
System.setProperty("numShards", Integer.toString(sliceCount));
|
System.setProperty("numShards", Integer.toString(sliceCount));
|
||||||
System.setProperty("solr.xml.persist", "true");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getSolrXml() {
|
protected String getSolrXml() {
|
||||||
// test old style and new style solr.xml
|
return "solr-no-core.xml";
|
||||||
return oldStyleSolrXml ? "solr-no-core-old-style.xml" : "solr-no-core.xml";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -953,28 +946,22 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInstanceDirs(JettySolrRunner jetty) {
|
private void checkInstanceDirs(JettySolrRunner jetty) throws IOException {
|
||||||
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
|
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
|
||||||
.getFilter()).getCores();
|
.getFilter()).getCores();
|
||||||
Collection<SolrCore> theCores = cores.getCores();
|
Collection<SolrCore> theCores = cores.getCores();
|
||||||
for (SolrCore core : theCores) {
|
for (SolrCore core : theCores) {
|
||||||
if (!oldStyleSolrXml) {
|
|
||||||
// look for core props file
|
|
||||||
assertTrue("Could not find expected core.properties file",
|
|
||||||
new File((String) core.getStatistics().get("instanceDir"),
|
|
||||||
"core.properties").exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
// look for core props file
|
||||||
assertEquals(
|
assertTrue("Could not find expected core.properties file",
|
||||||
new File(SolrResourceLoader.normalizeDir(jetty.getSolrHome() + File.separator
|
new File((String) core.getStatistics().get("instanceDir"),
|
||||||
+ core.getName())).getCanonicalPath(),
|
"core.properties").exists());
|
||||||
new File(SolrResourceLoader.normalizeDir((String) core.getStatistics().get(
|
|
||||||
"instanceDir"))).getCanonicalPath());
|
Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve("cores").resolve(core.getName());
|
||||||
} catch (IOException e) {
|
Path reported = Paths.get((String) core.getStatistics().get("instanceDir"));
|
||||||
log.error("Failed to get canonical path", e);
|
|
||||||
fail("Failed to get canonical path");
|
assertTrue("Expected: " + expected + "\nFrom core stats: " + reported, Files.isSameFile(expected, reported));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
import org.apache.solr.common.cloud.ZkStateReader;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -146,8 +147,7 @@ public class LeaderElectionIntegrationTest extends SolrTestCaseJ4 {
|
||||||
ports.add(port);
|
ports.add(port);
|
||||||
CoreContainer container = new CoreContainer();
|
CoreContainer container = new CoreContainer();
|
||||||
container.load();
|
container.load();
|
||||||
assertTrue("Container " + port + " has no cores!", container.getCores()
|
container.create(new CoreDescriptor(container, "collection1", "collection1", "collection", "collection1"));
|
||||||
.size() > 0);
|
|
||||||
containerMap.put(port, container);
|
containerMap.put(port, container);
|
||||||
System.clearProperty("solr.solr.home");
|
System.clearProperty("solr.solr.home");
|
||||||
System.clearProperty("hostPort");
|
System.clearProperty("hostPort");
|
||||||
|
|
|
@ -17,14 +17,6 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.io.filefilter.RegexFileFilter;
|
import org.apache.commons.io.filefilter.RegexFileFilter;
|
||||||
|
@ -44,6 +36,14 @@ import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
// TODO: This test would be a lot faster if it used a solrhome with fewer config
|
// TODO: This test would be a lot faster if it used a solrhome with fewer config
|
||||||
// files - there are a lot of them to upload
|
// files - there are a lot of them to upload
|
||||||
public class ZkCLITest extends SolrTestCaseJ4 {
|
public class ZkCLITest extends SolrTestCaseJ4 {
|
||||||
|
@ -78,19 +78,10 @@ public class ZkCLITest extends SolrTestCaseJ4 {
|
||||||
log.info("####SETUP_START " + getTestName());
|
log.info("####SETUP_START " + getTestName());
|
||||||
|
|
||||||
String exampleHome = SolrJettyTestBase.legacyExampleCollection1SolrHome();
|
String exampleHome = SolrJettyTestBase.legacyExampleCollection1SolrHome();
|
||||||
|
|
||||||
boolean useNewSolrXml = random().nextBoolean();
|
|
||||||
File tmpDir = createTempDir().toFile();
|
File tmpDir = createTempDir().toFile();
|
||||||
if (useNewSolrXml) {
|
solrHome = exampleHome;
|
||||||
solrHome = exampleHome;
|
|
||||||
} else {
|
|
||||||
File tmpSolrHome = new File(tmpDir, "tmp-solr-home");
|
|
||||||
FileUtils.copyDirectory(new File(exampleHome), tmpSolrHome);
|
|
||||||
FileUtils.copyFile(getFile("old-solr-example/solr.xml"), new File(tmpSolrHome, "solr.xml"));
|
|
||||||
solrHome = tmpSolrHome.getAbsolutePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
zkDir = tmpDir.getAbsolutePath() + File.separator
|
zkDir = tmpDir.getAbsolutePath() + File.separator
|
||||||
+ "zookeeper/server1/data";
|
+ "zookeeper/server1/data";
|
||||||
log.info("ZooKeeper dataDir:" + zkDir);
|
log.info("ZooKeeper dataDir:" + zkDir);
|
||||||
|
|
|
@ -17,12 +17,6 @@ package org.apache.solr.cloud;
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||||
import org.apache.solr.SolrJettyTestBase;
|
import org.apache.solr.SolrJettyTestBase;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
@ -33,6 +27,7 @@ import org.apache.solr.core.ConfigSolr;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.CoresLocator;
|
import org.apache.solr.core.CoresLocator;
|
||||||
|
import org.apache.solr.core.PluginInfo;
|
||||||
import org.apache.solr.handler.admin.CoreAdminHandler;
|
import org.apache.solr.handler.admin.CoreAdminHandler;
|
||||||
import org.apache.solr.handler.component.HttpShardHandlerFactory;
|
import org.apache.solr.handler.component.HttpShardHandlerFactory;
|
||||||
import org.apache.solr.update.UpdateShardHandler;
|
import org.apache.solr.update.UpdateShardHandler;
|
||||||
|
@ -41,6 +36,12 @@ import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slow
|
@Slow
|
||||||
public class ZkControllerTest extends SolrTestCaseJ4 {
|
public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
@ -321,7 +322,7 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigSolr getConfig() {
|
public ConfigSolr getConfig() {
|
||||||
return new ConfigSolr() {
|
return new ConfigSolr(null, null) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoresLocator getCoresLocator() {
|
public CoresLocator getCoresLocator() {
|
||||||
|
@ -329,25 +330,22 @@ public class ZkControllerTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getShardHandlerFactoryConfigPath() {
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
throw new UnsupportedOperationException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPersistent() {
|
protected String getProperty(CfgProp key) {
|
||||||
throw new UnsupportedOperationException();
|
return null;
|
||||||
}};
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateShardHandler getUpdateShardHandler() {
|
public UpdateShardHandler getUpdateShardHandler() {
|
||||||
return new UpdateShardHandler(null);
|
return new UpdateShardHandler(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAdminPath() {
|
|
||||||
return "/admin/cores";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,436 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.solr.core;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.lucene.util.IOUtils;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.apache.solr.common.SolrException;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.xml.sax.SAXParseException;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class CoreContainerCoreInitFailuresTest extends SolrTestCaseJ4 {
|
|
||||||
|
|
||||||
File solrHome = null;
|
|
||||||
CoreContainer cc = null;
|
|
||||||
|
|
||||||
private void init(final String dirSuffix) {
|
|
||||||
solrHome = createTempDir(dirSuffix).toFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void cleanUp() throws Exception {
|
|
||||||
if (cc != null) {
|
|
||||||
cc.shutdown();
|
|
||||||
cc = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
solrHome = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFlowWithEmpty() throws Exception {
|
|
||||||
// reused state
|
|
||||||
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
|
||||||
Collection<String> cores = null;
|
|
||||||
Exception fail = null;
|
|
||||||
|
|
||||||
init("empty_flow");
|
|
||||||
|
|
||||||
// solr.xml
|
|
||||||
File solrXml = new File(solrHome, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, EMPTY_SOLR_XML, IOUtils.UTF_8);
|
|
||||||
|
|
||||||
// ----
|
|
||||||
// init the CoreContainer
|
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 0, cores.size());
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 0, failures.size());
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// try to add a collection with a path that doesn't exist
|
|
||||||
final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
|
|
||||||
try {
|
|
||||||
ignoreException(Pattern.quote("bogus_path"));
|
|
||||||
cc.create(bogus);
|
|
||||||
fail("bogus inst dir failed to trigger exception from create");
|
|
||||||
} catch (SolrException e) {
|
|
||||||
assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
|
|
||||||
0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 0, cores.size());
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
fail = failures.get("bogus").exception;
|
|
||||||
assertNotNull("null failure for test core", fail);
|
|
||||||
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
|
||||||
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
|
||||||
|
|
||||||
// check that we get null accessing a non-existent core
|
|
||||||
assertNull(cc.getCore("does_not_exist"));
|
|
||||||
// check that we get a 500 accessing the core with an init failure
|
|
||||||
try {
|
|
||||||
SolrCore c = cc.getCore("bogus");
|
|
||||||
fail("Failed to get Exception on accessing core with init failure");
|
|
||||||
} catch (SolrException ex) {
|
|
||||||
assertEquals(500, ex.code());
|
|
||||||
// double wrapped
|
|
||||||
String cause = ex.getCause().getCause().getMessage();
|
|
||||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
|
||||||
0 < cause.indexOf("bogus_path"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// let the test end here, with some recorded failures, and let cleanUp()
|
|
||||||
// verify that there is no problem shuting down CoreContainer with known
|
|
||||||
// SolrCore failures
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFlowBadFromStart() throws Exception {
|
|
||||||
|
|
||||||
// reused state
|
|
||||||
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
|
||||||
Collection<String> cores = null;
|
|
||||||
Exception fail = null;
|
|
||||||
|
|
||||||
init("bad_flow");
|
|
||||||
|
|
||||||
// start with two collections: one valid, and one broken
|
|
||||||
File solrXml = new File(solrHome, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);
|
|
||||||
|
|
||||||
// our "ok" collection
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
// our "bad" collection
|
|
||||||
ignoreException(Pattern.quote("DummyMergePolicy"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/bad-mp-solrconfig.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// init the CoreContainer with the mix of ok/bad cores
|
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 1, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
fail = failures.get("col_bad").exception;
|
|
||||||
assertNotNull("null failure for test core", fail);
|
|
||||||
assertTrue("init failure doesn't mention problem: " + fail.getMessage(),
|
|
||||||
0 < fail.getMessage().indexOf("DummyMergePolicy"));
|
|
||||||
|
|
||||||
// check that we get null accessing a non-existent core
|
|
||||||
assertNull(cc.getCore("does_not_exist"));
|
|
||||||
// check that we get a 500 accessing the core with an init failure
|
|
||||||
try {
|
|
||||||
SolrCore c = cc.getCore("col_bad");
|
|
||||||
fail("Failed to get Exception on accessing core with init failure");
|
|
||||||
} catch (SolrException ex) {
|
|
||||||
assertEquals(500, ex.code());
|
|
||||||
// double wrapped
|
|
||||||
String cause = ex.getCause().getCause().getMessage();
|
|
||||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
|
||||||
0 < cause.indexOf("DummyMergePolicy"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// "fix" the bad collection
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
|
||||||
final CoreDescriptor fixed = new CoreDescriptor(cc, "col_bad", "col_bad");
|
|
||||||
cc.create(fixed);
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 2, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
assertTrue("col_bad not found", cores.contains("col_bad"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 0, failures.size());
|
|
||||||
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// try to add a collection with a path that doesn't exist
|
|
||||||
final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
|
|
||||||
try {
|
|
||||||
ignoreException(Pattern.quote("bogus_path"));
|
|
||||||
cc.create(bogus);
|
|
||||||
fail("bogus inst dir failed to trigger exception from create");
|
|
||||||
} catch (SolrException e) {
|
|
||||||
assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
|
|
||||||
0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 2, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
assertTrue("col_bad not found", cores.contains("col_bad"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
fail = failures.get("bogus").exception;
|
|
||||||
assertNotNull("null failure for test core", fail);
|
|
||||||
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
|
||||||
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
|
||||||
|
|
||||||
// check that we get null accessing a non-existent core
|
|
||||||
assertNull(cc.getCore("does_not_exist"));
|
|
||||||
// check that we get a 500 accessing the core with an init failure
|
|
||||||
try {
|
|
||||||
SolrCore c = cc.getCore("bogus");
|
|
||||||
fail("Failed to get Exception on accessing core with init failure");
|
|
||||||
} catch (SolrException ex) {
|
|
||||||
assertEquals(500, ex.code());
|
|
||||||
// double wrapped
|
|
||||||
String cause = ex.getCause().getCause().getMessage();
|
|
||||||
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
|
||||||
0 < cause.indexOf("bogus_path"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// break col_bad's config and try to RELOAD to add failure
|
|
||||||
|
|
||||||
final long col_bad_old_start = getCoreStartTime(cc, "col_bad");
|
|
||||||
|
|
||||||
FileUtils.write
|
|
||||||
(FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"),
|
|
||||||
"This is giberish, not valid XML <",
|
|
||||||
IOUtils.UTF_8);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ignoreException(Pattern.quote("SAX"));
|
|
||||||
cc.reload("col_bad");
|
|
||||||
fail("corrupt solrconfig.xml failed to trigger exception from reload");
|
|
||||||
} catch (SolrException e) {
|
|
||||||
Throwable rootException = getWrappedException(e);
|
|
||||||
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
|
|
||||||
rootException instanceof SAXParseException);
|
|
||||||
SAXParseException se = (SAXParseException) rootException;
|
|
||||||
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
|
|
||||||
0 < se.getSystemId().indexOf("solrconfig.xml"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("Failed core reload should not have changed start time",
|
|
||||||
col_bad_old_start, getCoreStartTime(cc, "col_bad"));
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 2, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
assertTrue("col_bad not found", cores.contains("col_bad"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 2, failures.size());
|
|
||||||
Throwable ex = getWrappedException(failures.get("col_bad").exception);
|
|
||||||
assertNotNull("null failure for test core", ex);
|
|
||||||
assertTrue("init failure isn't SAXParseException",
|
|
||||||
ex instanceof SAXParseException);
|
|
||||||
SAXParseException saxEx = (SAXParseException) ex;
|
|
||||||
assertTrue("init failure doesn't mention problem: " + saxEx.toString(), saxEx.getSystemId().contains("solrconfig.xml"));
|
|
||||||
|
|
||||||
// ----
|
|
||||||
// fix col_bad's config (again) and RELOAD to fix failure
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
|
||||||
cc.reload("col_bad");
|
|
||||||
|
|
||||||
assertTrue("Core reload should have changed start time",
|
|
||||||
col_bad_old_start < getCoreStartTime(cc, "col_bad"));
|
|
||||||
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 2, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
assertTrue("col_bad not found", cores.contains("col_bad"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testJavaLangErrorFromHandlerOnStartup() throws Exception {
|
|
||||||
|
|
||||||
// reused state
|
|
||||||
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
|
||||||
Collection<String> cores = null;
|
|
||||||
Exception fail = null;
|
|
||||||
|
|
||||||
init("java_lang_error_handler");
|
|
||||||
|
|
||||||
// start with two collections: 1 ok, and 1 that throws java.lang.Error on startup
|
|
||||||
File solrXml = new File(solrHome, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);
|
|
||||||
|
|
||||||
// our "ok" collection
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
// our "bad" collection
|
|
||||||
ignoreException(Pattern.quote("my_error_handler"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/bad-error-solrconfig.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// init the CoreContainer with the mix of ok/bad cores
|
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 1, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
fail = failures.get("col_bad").exception;
|
|
||||||
assertNotNull("null failure for test core", fail);
|
|
||||||
assertTrue("init failure doesn't mention root problem: " + fail.getMessage(),
|
|
||||||
0 < fail.getMessage().indexOf("throwing a java.lang.Error"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testJavaLangErrorFromSchemaOnStartup() throws Exception {
|
|
||||||
|
|
||||||
// reused state
|
|
||||||
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
|
||||||
Collection<String> cores = null;
|
|
||||||
Exception fail = null;
|
|
||||||
|
|
||||||
init("java_lang_error_schema");
|
|
||||||
|
|
||||||
// start with two collections: 1 ok, and 1 that throws java.lang.Error on startup
|
|
||||||
File solrXml = new File(solrHome, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, BAD_SOLR_XML, IOUtils.UTF_8);
|
|
||||||
|
|
||||||
// our "ok" collection
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_ok", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
// our "bad" collection
|
|
||||||
ignoreException(Pattern.quote("error_ft"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "solrconfig.xml"));
|
|
||||||
FileUtils.copyFile(getFile("solr/collection1/conf/bad-schema-init-error.xml"),
|
|
||||||
FileUtils.getFile(solrHome, "col_bad", "conf", "schema.xml"));
|
|
||||||
|
|
||||||
|
|
||||||
// -----
|
|
||||||
// init the CoreContainer with the mix of ok/bad cores
|
|
||||||
cc = new CoreContainer(solrHome.getAbsolutePath());
|
|
||||||
cc.load();
|
|
||||||
|
|
||||||
// check that we have the cores we expect
|
|
||||||
cores = cc.getCoreNames();
|
|
||||||
assertNotNull("core names is null", cores);
|
|
||||||
assertEquals("wrong number of cores", 1, cores.size());
|
|
||||||
assertTrue("col_ok not found", cores.contains("col_ok"));
|
|
||||||
|
|
||||||
// check that we have the failures we expect
|
|
||||||
failures = cc.getCoreInitFailures();
|
|
||||||
assertNotNull("core failures is a null map", failures);
|
|
||||||
assertEquals("wrong number of core failures", 1, failures.size());
|
|
||||||
fail = failures.get("col_bad").exception;
|
|
||||||
assertNotNull("null failure for test core", fail);
|
|
||||||
assertTrue("init failure doesn't mention root problem: " + fail.getMessage(),
|
|
||||||
0 < fail.getMessage().indexOf("throwing java.lang.Error"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getCoreStartTime(final CoreContainer cc, final String name) {
|
|
||||||
try (SolrCore tmp = cc.getCore(name)) {
|
|
||||||
return tmp.getStartTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
|
||||||
"<solr persistent=\"false\">\n" +
|
|
||||||
" <cores adminPath=\"/admin/cores\">\n" +
|
|
||||||
" </cores>\n" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
private static final String BAD_SOLR_XML =
|
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
|
||||||
"<solr persistent=\"false\">\n" +
|
|
||||||
" <cores adminPath=\"/admin/cores\">\n" +
|
|
||||||
" <core name=\"col_ok\" instanceDir=\"col_ok\" />\n" +
|
|
||||||
" <core name=\"col_bad\" instanceDir=\"col_bad\" />\n" +
|
|
||||||
" </cores>\n" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
}
|
|
|
@ -105,47 +105,41 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test5Seconds() throws Exception {
|
public void test5Seconds() throws Exception {
|
||||||
doStress(5, random().nextBoolean());
|
doStress(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Nightly
|
@Nightly
|
||||||
public void test15SecondsOld() throws Exception {
|
public void test15SecondsOld() throws Exception {
|
||||||
doStress(15, true);
|
doStress(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Nightly
|
@Nightly
|
||||||
public void test15SecondsNew() throws Exception {
|
public void test15SecondsNew() throws Exception {
|
||||||
doStress(15, false);
|
doStress(15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Nightly
|
@Nightly
|
||||||
public void test10MinutesOld() throws Exception {
|
public void test10MinutesOld() throws Exception {
|
||||||
doStress(300, true);
|
doStress(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Nightly
|
@Nightly
|
||||||
public void test10MinutesNew() throws Exception {
|
public void test10MinutesNew() throws Exception {
|
||||||
doStress(300, false);
|
doStress(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Weekly
|
@Weekly
|
||||||
public void test1HourOld() throws Exception {
|
public void test1Hour() throws Exception {
|
||||||
doStress(1800, true);
|
doStress(1800);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Weekly
|
|
||||||
public void test1HourNew() throws Exception {
|
|
||||||
doStress(1800, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void buildClients() throws Exception {
|
private void buildClients() throws Exception {
|
||||||
|
|
||||||
jetty.start();
|
jetty.start();
|
||||||
url = buildUrl(jetty.getLocalPort(), "/solr/");
|
url = buildUrl(jetty.getLocalPort(), "/solr/");
|
||||||
|
|
||||||
|
@ -169,8 +163,8 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unless things go _really_ well, stop after you have the directories set up.
|
// Unless things go _really_ well, stop after you have the directories set up.
|
||||||
private void doStress(int secondsToRun, boolean oldStyle) throws Exception {
|
private void doStress(int secondsToRun) throws Exception {
|
||||||
makeCores(solrHomeDirectory, oldStyle);
|
makeCores(solrHomeDirectory);
|
||||||
|
|
||||||
//MUST start the server after the cores are made.
|
//MUST start the server after the cores are made.
|
||||||
buildClients();
|
buildClients();
|
||||||
|
@ -213,25 +207,22 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeCores(File home, boolean oldStyle) throws Exception {
|
private void makeCores(File home) throws Exception {
|
||||||
File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME());
|
File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME());
|
||||||
String srcSolrXml = "solr-stress-new.xml";
|
String srcSolrXml = "solr-stress-new.xml";
|
||||||
|
|
||||||
if (oldStyle) {
|
|
||||||
srcSolrXml = "solr-stress-old.xml";
|
|
||||||
}
|
|
||||||
FileUtils.copyFile(new File(testSrcRoot, srcSolrXml), new File(home, "solr.xml"));
|
FileUtils.copyFile(new File(testSrcRoot, srcSolrXml), new File(home, "solr.xml"));
|
||||||
|
|
||||||
// create directories in groups of 100 until you have enough.
|
// create directories in groups of 100 until you have enough.
|
||||||
for (int idx = 0; idx < numCores; ++idx) {
|
for (int idx = 0; idx < numCores; ++idx) {
|
||||||
String coreName = String.format(Locale.ROOT, "%05d_core", idx);
|
String coreName = String.format(Locale.ROOT, "%05d_core", idx);
|
||||||
makeCore(new File(home, coreName), testSrcRoot, oldStyle);
|
makeCore(new File(home, coreName), testSrcRoot);
|
||||||
coreCounts.put(coreName, 0L);
|
coreCounts.put(coreName, 0L);
|
||||||
coreNames.add(coreName);
|
coreNames.add(coreName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeCore(File coreDir, File testSrcRoot, boolean oldStyle) throws IOException {
|
private void makeCore(File coreDir, File testSrcRoot) throws IOException {
|
||||||
File conf = new File(coreDir, "conf");
|
File conf = new File(coreDir, "conf");
|
||||||
|
|
||||||
if (!conf.mkdirs()) log.warn("mkdirs returned false in makeCore... ignoring");
|
if (!conf.mkdirs()) log.warn("mkdirs returned false in makeCore... ignoring");
|
||||||
|
@ -244,9 +235,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
|
||||||
FileUtils.copyFile(new File(testConf, "solrconfig.snippet.randomindexconfig.xml"),
|
FileUtils.copyFile(new File(testConf, "solrconfig.snippet.randomindexconfig.xml"),
|
||||||
new File(conf, "solrconfig.snippet.randomindexconfig.xml"));
|
new File(conf, "solrconfig.snippet.randomindexconfig.xml"));
|
||||||
|
|
||||||
if (!oldStyle) {
|
FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));
|
||||||
FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,35 +51,6 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
|
||||||
deleteCore();
|
deleteCore();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRemoveThenAddDefaultCore() throws Exception {
|
|
||||||
final CoreContainer cores = h.getCoreContainer();
|
|
||||||
SolrCore core = cores.getCore("");
|
|
||||||
|
|
||||||
assertEquals(COLLECTION1, cores.getDefaultCoreName());
|
|
||||||
|
|
||||||
cores.unload("");
|
|
||||||
core.close();
|
|
||||||
|
|
||||||
CoreDescriptor cd = new CoreDescriptor(cores, COLLECTION1, "collection1",
|
|
||||||
CoreDescriptor.CORE_DATADIR, createTempDir("dataDir2").toFile().getAbsolutePath());
|
|
||||||
|
|
||||||
cores.create(cd);
|
|
||||||
|
|
||||||
assertEquals(COLLECTION1, cores.getDefaultCoreName());
|
|
||||||
|
|
||||||
// so we should be able to get a core with collection1
|
|
||||||
core = cores.getCore(COLLECTION1);
|
|
||||||
assertNotNull(core);
|
|
||||||
core.close();
|
|
||||||
|
|
||||||
// and with ""
|
|
||||||
core = cores.getCore("");
|
|
||||||
assertNotNull(core);
|
|
||||||
|
|
||||||
core.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRequestHandlerRegistry() {
|
public void testRequestHandlerRegistry() {
|
||||||
|
@ -100,7 +71,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testClose() throws Exception {
|
public void testClose() throws Exception {
|
||||||
final CoreContainer cores = h.getCoreContainer();
|
final CoreContainer cores = h.getCoreContainer();
|
||||||
SolrCore core = cores.getCore("");
|
SolrCore core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
|
||||||
|
|
||||||
ClosingRequestHandler handler1 = new ClosingRequestHandler();
|
ClosingRequestHandler handler1 = new ClosingRequestHandler();
|
||||||
handler1.inform( core );
|
handler1.inform( core );
|
||||||
|
@ -120,7 +91,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
|
||||||
assertTrue("Refcount != 1", core.getOpenCount() == 1);
|
assertTrue("Refcount != 1", core.getOpenCount() == 1);
|
||||||
|
|
||||||
final CoreContainer cores = h.getCoreContainer();
|
final CoreContainer cores = h.getCoreContainer();
|
||||||
SolrCore c1 = cores.getCore("");
|
SolrCore c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
|
||||||
assertTrue("Refcount != 2", core.getOpenCount() == 2);
|
assertTrue("Refcount != 2", core.getOpenCount() == 2);
|
||||||
|
|
||||||
ClosingRequestHandler handler1 = new ClosingRequestHandler();
|
ClosingRequestHandler handler1 = new ClosingRequestHandler();
|
||||||
|
@ -131,12 +102,12 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
|
||||||
assertNull( old ); // should not be anything...
|
assertNull( old ); // should not be anything...
|
||||||
assertEquals( core.getRequestHandlers().get( path ), handler1 );
|
assertEquals( core.getRequestHandlers().get( path ), handler1 );
|
||||||
|
|
||||||
SolrCore c2 = cores.getCore("");
|
SolrCore c2 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
|
||||||
c1.close();
|
c1.close();
|
||||||
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
|
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
|
||||||
assertTrue("Handler is closed", handler1.closed == false);
|
assertTrue("Handler is closed", handler1.closed == false);
|
||||||
|
|
||||||
c1 = cores.getCore("");
|
c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
|
||||||
assertTrue("Refcount < 2", core.getOpenCount() >= 2);
|
assertTrue("Refcount < 2", core.getOpenCount() >= 2);
|
||||||
assertTrue("Handler is closed", handler1.closed == false);
|
assertTrue("Handler is closed", handler1.closed == false);
|
||||||
|
|
||||||
|
@ -184,7 +155,7 @@ public class SolrCoreTest extends SolrTestCaseJ4 {
|
||||||
try {
|
try {
|
||||||
for (int l = 0; l < LOOP; ++l) {
|
for (int l = 0; l < LOOP; ++l) {
|
||||||
r += 1;
|
r += 1;
|
||||||
core = cores.getCore("");
|
core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
|
||||||
// sprinkle concurrency hinting...
|
// sprinkle concurrency hinting...
|
||||||
yield(l);
|
yield(l);
|
||||||
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
|
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
|
||||||
System.setProperty("configsets", configSetsBaseDir);
|
System.setProperty("configsets", configSetsBaseDir);
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
|
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
|
||||||
CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));
|
CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));
|
||||||
container.load();
|
container.load();
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
|
@ -115,12 +115,12 @@ public class TestConfigSets extends SolrTestCaseJ4 {
|
||||||
System.setProperty("configsets", csd);
|
System.setProperty("configsets", csd);
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
|
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
|
||||||
CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));
|
CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));
|
||||||
container.load();
|
container.load();
|
||||||
|
|
||||||
// We initially don't have a /get handler defined
|
// We initially don't have a /get handler defined
|
||||||
SolrCore core = container.create(new CoreDescriptor(container, "core1", testDirectory + "/core", "configSet", "configset-2"));
|
SolrCore core = container.create(new CoreDescriptor(container, "core1", testDirectory + "/core", "configSet", "configset-2"));
|
||||||
assertThat("No /get handler should be defined in the initial configuration",
|
assertThat("No /dump handler should be defined in the initial configuration",
|
||||||
core.getRequestHandler("/dump"), is(nullValue()));
|
core.getRequestHandler("/dump"), is(nullValue()));
|
||||||
|
|
||||||
// Now copy in a config with a /get handler and reload
|
// Now copy in a config with a /get handler and reload
|
||||||
|
@ -129,7 +129,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
|
||||||
container.reload("core1");
|
container.reload("core1");
|
||||||
|
|
||||||
core = container.getCore("core1");
|
core = container.getCore("core1");
|
||||||
assertThat("A /get handler should be defined in the reloaded configuration",
|
assertThat("A /dump handler should be defined in the reloaded configuration",
|
||||||
core.getRequestHandler("/dump"), is(notNullValue()));
|
core.getRequestHandler("/dump"), is(notNullValue()));
|
||||||
core.close();
|
core.close();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.handler.admin.CollectionsHandler;
|
import org.apache.solr.handler.admin.CollectionsHandler;
|
||||||
|
@ -26,19 +27,18 @@ import org.apache.solr.handler.admin.InfoHandler;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.nio.file.Path;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarOutputStream;
|
import java.util.jar.JarOutputStream;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
|
@ -55,7 +55,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
oldSolrHome = System.getProperty(SOLR_HOME_PROP);
|
oldSolrHome = System.getProperty(SOLR_HOME_PROP);
|
||||||
initCore("solrconfig.xml", "schema.xml");
|
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
|
@ -67,16 +67,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File solrHomeDirectory;
|
private CoreContainer init(String xml) throws Exception {
|
||||||
|
Path solrHomeDirectory = createTempDir();
|
||||||
|
return init(solrHomeDirectory, xml);
|
||||||
|
}
|
||||||
|
|
||||||
private CoreContainer init(String dirName) throws Exception {
|
private CoreContainer init(Path homeDirectory, String xml) throws Exception {
|
||||||
|
SolrResourceLoader loader = new SolrResourceLoader(homeDirectory.toString());
|
||||||
solrHomeDirectory = createTempDir(dirName).toFile();
|
CoreContainer ret = new CoreContainer(ConfigSolr.fromString(loader, xml));
|
||||||
|
|
||||||
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
|
|
||||||
System.out.println("Using solrconfig from " + new File(SolrTestCaseJ4.TEST_HOME()).getAbsolutePath());
|
|
||||||
|
|
||||||
CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
|
||||||
ret.load();
|
ret.load();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -84,12 +82,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testShareSchema() throws Exception {
|
public void testShareSchema() throws Exception {
|
||||||
System.setProperty("shareSchema", "true");
|
System.setProperty("shareSchema", "true");
|
||||||
final CoreContainer cores = init("_shareSchema");
|
|
||||||
|
CoreContainer cores = init(CONFIGSETS_SOLR_XML);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1");
|
CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1", "configSet", "minimal");
|
||||||
SolrCore core1 = cores.create(descriptor1);
|
SolrCore core1 = cores.create(descriptor1);
|
||||||
|
|
||||||
CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1");
|
CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1", "configSet", "minimal");
|
||||||
SolrCore core2 = cores.create(descriptor2);
|
SolrCore core2 = cores.create(descriptor2);
|
||||||
|
|
||||||
assertSame(core1.getLatestSchema(), core2.getLatestSchema());
|
assertSame(core1.getLatestSchema(), core2.getLatestSchema());
|
||||||
|
@ -102,12 +102,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReloadSequential() throws Exception {
|
public void testReloadSequential() throws Exception {
|
||||||
final CoreContainer cc = init("_reloadSequential");
|
final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
|
||||||
|
CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
|
||||||
|
cc.create(descriptor1);
|
||||||
try {
|
try {
|
||||||
cc.reload("collection1");
|
cc.reload("core1");
|
||||||
cc.reload("collection1");
|
cc.reload("core1");
|
||||||
cc.reload("collection1");
|
cc.reload("core1");
|
||||||
cc.reload("collection1");
|
cc.reload("core1");
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
cc.shutdown();
|
cc.shutdown();
|
||||||
|
@ -116,63 +118,52 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReloadThreaded() throws Exception {
|
public void testReloadThreaded() throws Exception {
|
||||||
final CoreContainer cc = init("_reloadThreaded");
|
final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
|
||||||
|
CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
|
||||||
|
cc.create(descriptor1);
|
||||||
|
|
||||||
class TestThread extends Thread {
|
class TestThread extends Thread {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
cc.reload("collection1");
|
cc.reload("core1");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Thread> threads = new ArrayList<>();
|
List<Thread> threads = new ArrayList<>();
|
||||||
int numThreads = 4;
|
int numThreads = 4;
|
||||||
for (int i = 0; i < numThreads; i++) {
|
for (int i = 0; i < numThreads; i++) {
|
||||||
threads.add(new TestThread());
|
threads.add(new TestThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Thread thread : threads) {
|
for (Thread thread : threads) {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Thread thread : threads) {
|
for (Thread thread : threads) {
|
||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
cc.shutdown();
|
cc.shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoCores() throws IOException, ParserConfigurationException, SAXException {
|
public void testNoCores() throws Exception {
|
||||||
//create solrHome
|
|
||||||
File solrHomeDirectory = createTempDir().toFile();
|
CoreContainer cores = init(CONFIGSETS_SOLR_XML);
|
||||||
|
|
||||||
boolean oldSolrXml = random().nextBoolean();
|
|
||||||
|
|
||||||
SetUpHome(solrHomeDirectory, oldSolrXml ? EMPTY_SOLR_XML : EMPTY_SOLR_XML2);
|
|
||||||
CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
|
||||||
cores.load();
|
|
||||||
try {
|
try {
|
||||||
//assert zero cores
|
//assert zero cores
|
||||||
assertEquals("There should not be cores", 0, cores.getCores().size());
|
assertEquals("There should not be cores", 0, cores.getCores().size());
|
||||||
|
|
||||||
FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME(), "collection1"), solrHomeDirectory);
|
|
||||||
//add a new core
|
//add a new core
|
||||||
CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", solrHomeDirectory.getAbsolutePath());
|
CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", "collection1", CoreDescriptor.CORE_CONFIGSET, "minimal");
|
||||||
SolrCore newCore = cores.create(coreDescriptor);
|
SolrCore newCore = cores.create(coreDescriptor);
|
||||||
|
|
||||||
//assert one registered core
|
//assert one registered core
|
||||||
|
|
||||||
assertEquals("There core registered", 1, cores.getCores().size());
|
assertEquals("There core registered", 1, cores.getCores().size());
|
||||||
|
|
||||||
if (oldSolrXml) {
|
|
||||||
assertXmlFile(new File(solrHomeDirectory, "solr.xml"),
|
|
||||||
"/solr/cores[@transientCacheSize='32']");
|
|
||||||
}
|
|
||||||
|
|
||||||
cores.unload("core1");
|
cores.unload("core1");
|
||||||
//assert cero cores
|
//assert cero cores
|
||||||
assertEquals("There should not be cores", 0, cores.getCores().size());
|
assertEquals("There should not be cores", 0, cores.getCores().size());
|
||||||
|
@ -193,27 +184,14 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLogWatcherEnabledByDefault() {
|
public void testLogWatcherEnabledByDefault() throws Exception {
|
||||||
assertNotNull(h.getCoreContainer().getLogging());
|
CoreContainer cc = init("<solr></solr>");
|
||||||
}
|
|
||||||
|
|
||||||
private void SetUpHome(File solrHomeDirectory, String xmlFile) throws IOException {
|
|
||||||
if (solrHomeDirectory.exists()) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
}
|
|
||||||
assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
|
|
||||||
try {
|
try {
|
||||||
File solrXmlFile = new File(solrHomeDirectory, "solr.xml");
|
assertNotNull(cc.getLogging());
|
||||||
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), StandardCharsets.UTF_8));
|
}
|
||||||
out.write(xmlFile);
|
finally {
|
||||||
out.close();
|
cc.shutdown();
|
||||||
} catch (IOException e) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//init
|
|
||||||
System.setProperty(SOLR_HOME_PROP, solrHomeDirectory.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -221,13 +199,12 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
MockCoresLocator cl = new MockCoresLocator();
|
MockCoresLocator cl = new MockCoresLocator();
|
||||||
|
|
||||||
solrHomeDirectory = createTempDir("_deleteBadCores").toFile();
|
SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());
|
||||||
SolrResourceLoader resourceLoader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
|
||||||
File instanceDir = new File(solrHomeDirectory, "_deleteBadCores");
|
|
||||||
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
|
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
|
||||||
|
|
||||||
final CoreContainer cc = new CoreContainer(resourceLoader, ConfigSolr.fromString(resourceLoader, EMPTY_SOLR_XML2), cl);
|
final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);
|
||||||
CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "nosuchconfigset");
|
CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", "badcore", "configSet", "nosuchconfigset");
|
||||||
cl.add(badcore);
|
cl.add(badcore);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -238,7 +215,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
assertThat(cc.getCoreInitFailures().size(), is(0));
|
assertThat(cc.getCoreInitFailures().size(), is(0));
|
||||||
|
|
||||||
// can we create the core now with a good config?
|
// can we create the core now with a good config?
|
||||||
SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "minimal"));
|
SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", "badcore", "configSet", "minimal"));
|
||||||
assertThat(core, not(nullValue()));
|
assertThat(core, not(nullValue()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,13 +226,13 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassLoaderHierarchy() throws Exception {
|
public void testClassLoaderHierarchy() throws Exception {
|
||||||
final CoreContainer cc = init("_classLoaderHierarchy");
|
final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
|
||||||
try {
|
try {
|
||||||
ClassLoader sharedLoader = cc.loader.getClassLoader();
|
ClassLoader sharedLoader = cc.loader.getClassLoader();
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assertSame(contextLoader, sharedLoader.getParent());
|
assertSame(contextLoader, sharedLoader.getParent());
|
||||||
|
|
||||||
CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1");
|
CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
|
||||||
SolrCore core1 = cc.create(descriptor1);
|
SolrCore core1 = cc.create(descriptor1);
|
||||||
ClassLoader coreLoader = core1.getResourceLoader().getClassLoader();
|
ClassLoader coreLoader = core1.getResourceLoader().getClassLoader();
|
||||||
assertSame(sharedLoader, coreLoader.getParent());
|
assertSame(sharedLoader, coreLoader.getParent());
|
||||||
|
@ -267,9 +244,9 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSharedLib() throws Exception {
|
public void testSharedLib() throws Exception {
|
||||||
File tmpRoot = createTempDir("testSharedLib").toFile();
|
Path tmpRoot = createTempDir("testSharedLib");
|
||||||
|
|
||||||
File lib = new File(tmpRoot, "lib");
|
File lib = new File(tmpRoot.toFile(), "lib");
|
||||||
lib.mkdirs();
|
lib.mkdirs();
|
||||||
|
|
||||||
JarOutputStream jar1 = new JarOutputStream(new FileOutputStream(new File(lib, "jar1.jar")));
|
JarOutputStream jar1 = new JarOutputStream(new FileOutputStream(new File(lib, "jar1.jar")));
|
||||||
|
@ -277,7 +254,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
jar1.closeEntry();
|
jar1.closeEntry();
|
||||||
jar1.close();
|
jar1.close();
|
||||||
|
|
||||||
File customLib = new File(tmpRoot, "customLib");
|
File customLib = new File(tmpRoot.toFile(), "customLib");
|
||||||
customLib.mkdirs();
|
customLib.mkdirs();
|
||||||
|
|
||||||
JarOutputStream jar2 = new JarOutputStream(new FileOutputStream(new File(customLib, "jar2.jar")));
|
JarOutputStream jar2 = new JarOutputStream(new FileOutputStream(new File(customLib, "jar2.jar")));
|
||||||
|
@ -285,41 +262,32 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
jar2.closeEntry();
|
jar2.closeEntry();
|
||||||
jar2.close();
|
jar2.close();
|
||||||
|
|
||||||
FileUtils.writeStringToFile(new File(tmpRoot, "default-lib-solr.xml"), "<solr><cores/></solr>", "UTF-8");
|
final CoreContainer cc1 = init(tmpRoot, "<solr></solr>");
|
||||||
FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><cores/></solr>", "UTF-8");
|
|
||||||
FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
|
|
||||||
|
|
||||||
final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
|
|
||||||
try {
|
try {
|
||||||
cc1.loader.openResource("defaultSharedLibFile").close();
|
cc1.loader.openResource("defaultSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
cc1.shutdown();
|
cc1.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
|
final CoreContainer cc2 = init(tmpRoot, "<solr><str name=\"sharedLib\">lib</str></solr>");
|
||||||
try {
|
try {
|
||||||
cc2.loader.openResource("defaultSharedLibFile").close();
|
cc2.loader.openResource("defaultSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
cc2.shutdown();
|
cc2.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
|
final CoreContainer cc3 = init(tmpRoot, "<solr><str name=\"sharedLib\">customLib</str></solr>");
|
||||||
try {
|
try {
|
||||||
cc3.loader.openResource("customSharedLibFile").close();
|
cc3.loader.openResource("customSharedLibFile").close();
|
||||||
} finally {
|
} finally {
|
||||||
cc3.shutdown();
|
cc3.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
private static final String CONFIGSETS_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
||||||
"<solr persistent=\"false\">\n" +
|
|
||||||
" <cores adminPath=\"/admin/cores\" transientCacheSize=\"32\" >\n" +
|
|
||||||
" </cores>\n" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
|
||||||
"<solr>\n" +
|
"<solr>\n" +
|
||||||
"<str name=\"configSetBaseDir\">${configsets:configsets}</str>" +
|
"<str name=\"configSetBaseDir\">${configsets:configsets}</str>\n" +
|
||||||
|
"<str name=\"shareSchema\">${shareSchema:false}</str>\n" +
|
||||||
"</solr>";
|
"</solr>";
|
||||||
|
|
||||||
private static final String CUSTOM_HANDLERS_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
private static final String CUSTOM_HANDLERS_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
||||||
|
@ -350,12 +318,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
@Test
|
@Test
|
||||||
public void testCustomHandlers() throws Exception {
|
public void testCustomHandlers() throws Exception {
|
||||||
|
|
||||||
solrHomeDirectory = createTempDir("_customHandlers").toFile();
|
CoreContainer cc = init(CUSTOM_HANDLERS_SOLR_XML);
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
|
||||||
|
|
||||||
ConfigSolr config = ConfigSolr.fromString(loader, CUSTOM_HANDLERS_SOLR_XML);
|
|
||||||
|
|
||||||
CoreContainer cc = new CoreContainer(loader, config);
|
|
||||||
try {
|
try {
|
||||||
cc.load();
|
cc.load();
|
||||||
assertThat(cc.getCollectionsHandler(), is(instanceOf(CustomCollectionsHandler.class)));
|
assertThat(cc.getCollectionsHandler(), is(instanceOf(CustomCollectionsHandler.class)));
|
||||||
|
@ -406,4 +369,262 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
|
||||||
return cores;
|
return cores;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoreInitFailuresFromEmptyContainer() throws Exception {
|
||||||
|
// reused state
|
||||||
|
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
||||||
|
Collection<String> cores = null;
|
||||||
|
Exception fail = null;
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// init the CoreContainer
|
||||||
|
CoreContainer cc = init(CONFIGSETS_SOLR_XML);
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 0, cores.size());
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 0, failures.size());
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// try to add a collection with a path that doesn't exist
|
||||||
|
final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
|
||||||
|
try {
|
||||||
|
ignoreException(Pattern.quote("bogus_path"));
|
||||||
|
cc.create(bogus);
|
||||||
|
fail("bogus inst dir failed to trigger exception from create");
|
||||||
|
} catch (SolrException e) {
|
||||||
|
assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
|
||||||
|
0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 0, cores.size());
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 1, failures.size());
|
||||||
|
fail = failures.get("bogus").exception;
|
||||||
|
assertNotNull("null failure for test core", fail);
|
||||||
|
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
||||||
|
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
||||||
|
|
||||||
|
// check that we get null accessing a non-existent core
|
||||||
|
assertNull(cc.getCore("does_not_exist"));
|
||||||
|
// check that we get a 500 accessing the core with an init failure
|
||||||
|
try {
|
||||||
|
SolrCore c = cc.getCore("bogus");
|
||||||
|
fail("Failed to get Exception on accessing core with init failure");
|
||||||
|
} catch (SolrException ex) {
|
||||||
|
assertEquals(500, ex.code());
|
||||||
|
// double wrapped
|
||||||
|
String cause = ex.getCause().getCause().getMessage();
|
||||||
|
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||||
|
0 < cause.indexOf("bogus_path"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
cc.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoreInitFailuresOnReload() throws Exception {
|
||||||
|
|
||||||
|
// reused state
|
||||||
|
Map<String,CoreContainer.CoreLoadFailure> failures = null;
|
||||||
|
Collection<String> cores = null;
|
||||||
|
Exception fail = null;
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// init the CoreContainer with the mix of ok/bad cores
|
||||||
|
MockCoresLocator cl = new MockCoresLocator();
|
||||||
|
|
||||||
|
SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());
|
||||||
|
|
||||||
|
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
|
||||||
|
|
||||||
|
final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);
|
||||||
|
cl.add(new CoreDescriptor(cc, "col_ok", "col_ok", "configSet", "minimal"));
|
||||||
|
cl.add(new CoreDescriptor(cc, "col_bad", "col_bad", "configSet", "bad-mergepolicy"));
|
||||||
|
cc.load();
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 1, cores.size());
|
||||||
|
assertTrue("col_ok not found", cores.contains("col_ok"));
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 1, failures.size());
|
||||||
|
fail = failures.get("col_bad").exception;
|
||||||
|
assertNotNull("null failure for test core", fail);
|
||||||
|
assertTrue("init failure doesn't mention problem: " + fail.getMessage(),
|
||||||
|
0 < fail.getMessage().indexOf("DummyMergePolicy"));
|
||||||
|
|
||||||
|
// check that we get null accessing a non-existent core
|
||||||
|
assertNull(cc.getCore("does_not_exist"));
|
||||||
|
// check that we get a 500 accessing the core with an init failure
|
||||||
|
try {
|
||||||
|
SolrCore c = cc.getCore("col_bad");
|
||||||
|
fail("Failed to get Exception on accessing core with init failure");
|
||||||
|
} catch (SolrException ex) {
|
||||||
|
assertEquals(500, ex.code());
|
||||||
|
// double wrapped
|
||||||
|
String cause = ex.getCause().getCause().getMessage();
|
||||||
|
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||||
|
0 < cause.indexOf("DummyMergePolicy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// "fix" the bad collection
|
||||||
|
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
||||||
|
FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));
|
||||||
|
FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
|
||||||
|
FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "schema.xml"));
|
||||||
|
final CoreDescriptor fixed = new CoreDescriptor(cc, "col_bad", "col_bad");
|
||||||
|
cc.create(fixed);
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 2, cores.size());
|
||||||
|
assertTrue("col_ok not found", cores.contains("col_ok"));
|
||||||
|
assertTrue("col_bad not found", cores.contains("col_bad"));
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 0, failures.size());
|
||||||
|
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// try to add a collection with a path that doesn't exist
|
||||||
|
final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
|
||||||
|
try {
|
||||||
|
ignoreException(Pattern.quote("bogus_path"));
|
||||||
|
cc.create(bogus);
|
||||||
|
fail("bogus inst dir failed to trigger exception from create");
|
||||||
|
} catch (SolrException e) {
|
||||||
|
assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
|
||||||
|
0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 2, cores.size());
|
||||||
|
assertTrue("col_ok not found", cores.contains("col_ok"));
|
||||||
|
assertTrue("col_bad not found", cores.contains("col_bad"));
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 1, failures.size());
|
||||||
|
fail = failures.get("bogus").exception;
|
||||||
|
assertNotNull("null failure for test core", fail);
|
||||||
|
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
|
||||||
|
0 < fail.getCause().getMessage().indexOf("bogus_path"));
|
||||||
|
|
||||||
|
// check that we get null accessing a non-existent core
|
||||||
|
assertNull(cc.getCore("does_not_exist"));
|
||||||
|
// check that we get a 500 accessing the core with an init failure
|
||||||
|
try {
|
||||||
|
SolrCore c = cc.getCore("bogus");
|
||||||
|
fail("Failed to get Exception on accessing core with init failure");
|
||||||
|
} catch (SolrException ex) {
|
||||||
|
assertEquals(500, ex.code());
|
||||||
|
// double wrapped
|
||||||
|
String cause = ex.getCause().getCause().getMessage();
|
||||||
|
assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
|
||||||
|
0 < cause.indexOf("bogus_path"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// break col_bad's config and try to RELOAD to add failure
|
||||||
|
|
||||||
|
final long col_bad_old_start = getCoreStartTime(cc, "col_bad");
|
||||||
|
|
||||||
|
FileUtils.write
|
||||||
|
(FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"),
|
||||||
|
"This is giberish, not valid XML <",
|
||||||
|
IOUtils.UTF_8);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ignoreException(Pattern.quote("SAX"));
|
||||||
|
cc.reload("col_bad");
|
||||||
|
fail("corrupt solrconfig.xml failed to trigger exception from reload");
|
||||||
|
} catch (SolrException e) {
|
||||||
|
Throwable rootException = getWrappedException(e);
|
||||||
|
assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
|
||||||
|
rootException instanceof SAXParseException);
|
||||||
|
SAXParseException se = (SAXParseException) rootException;
|
||||||
|
assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
|
||||||
|
0 < se.getSystemId().indexOf("solrconfig.xml"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("Failed core reload should not have changed start time",
|
||||||
|
col_bad_old_start, getCoreStartTime(cc, "col_bad"));
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 2, cores.size());
|
||||||
|
assertTrue("col_ok not found", cores.contains("col_ok"));
|
||||||
|
assertTrue("col_bad not found", cores.contains("col_bad"));
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 2, failures.size());
|
||||||
|
Throwable ex = getWrappedException(failures.get("col_bad").exception);
|
||||||
|
assertNotNull("null failure for test core", ex);
|
||||||
|
assertTrue("init failure isn't SAXParseException",
|
||||||
|
ex instanceof SAXParseException);
|
||||||
|
SAXParseException saxEx = (SAXParseException) ex;
|
||||||
|
assertTrue("init failure doesn't mention problem: " + saxEx.toString(), saxEx.getSystemId().contains("solrconfig.xml"));
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// fix col_bad's config (again) and RELOAD to fix failure
|
||||||
|
FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
|
||||||
|
FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));
|
||||||
|
cc.reload("col_bad");
|
||||||
|
|
||||||
|
assertTrue("Core reload should have changed start time",
|
||||||
|
col_bad_old_start < getCoreStartTime(cc, "col_bad"));
|
||||||
|
|
||||||
|
|
||||||
|
// check that we have the cores we expect
|
||||||
|
cores = cc.getCoreNames();
|
||||||
|
assertNotNull("core names is null", cores);
|
||||||
|
assertEquals("wrong number of cores", 2, cores.size());
|
||||||
|
assertTrue("col_ok not found", cores.contains("col_ok"));
|
||||||
|
assertTrue("col_bad not found", cores.contains("col_bad"));
|
||||||
|
|
||||||
|
// check that we have the failures we expect
|
||||||
|
failures = cc.getCoreInitFailures();
|
||||||
|
assertNotNull("core failures is a null map", failures);
|
||||||
|
assertEquals("wrong number of core failures", 1, failures.size());
|
||||||
|
|
||||||
|
cc.shutdown();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getCoreStartTime(final CoreContainer cc, final String name) {
|
||||||
|
try (SolrCore tmp = cc.getCore(name)) {
|
||||||
|
return tmp.getStartTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,8 +140,6 @@ public class TestCoreDiscovery extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
CoreContainer cc = init();
|
CoreContainer cc = init();
|
||||||
try {
|
try {
|
||||||
assertEquals(ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME,
|
|
||||||
cc.getDefaultCoreName());
|
|
||||||
|
|
||||||
TestLazyCores.checkInCores(cc, "core1");
|
TestLazyCores.checkInCores(cc, "core1");
|
||||||
TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");
|
TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.apache.solr.core;
|
package org.apache.solr.core;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import java.io.File;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -22,17 +21,16 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class TestImplicitCoreProperties extends SolrTestCaseJ4 {
|
public class TestImplicitCoreProperties extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
public static final String SOLRXML =
|
|
||||||
"<solr><cores><core name=\"collection1\" instanceDir=\"collection1\" config=\"solrconfig-implicitproperties.xml\"/></cores></solr>";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImplicitPropertiesAreSubstitutedInSolrConfig() {
|
public void testImplicitPropertiesAreSubstitutedInSolrConfig() {
|
||||||
|
|
||||||
CoreContainer cc = createCoreContainer(TEST_HOME(), SOLRXML);
|
CoreContainer cc
|
||||||
|
= createCoreContainer("collection1", "data", "solrconfig-implicitproperties.xml", "schema.xml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertQ(req("q", "*:*")
|
assertQ(req("q", "*:*")
|
||||||
, "//str[@name='dummy1'][.='collection1']"
|
, "//str[@name='dummy1'][.='collection1']"
|
||||||
, "//str[@name='dummy2'][.='data"+File.separator+"']"
|
, "//str[@name='dummy2'][.='data']"
|
||||||
, "//str[@name='dummy3'][.='solrconfig-implicitproperties.xml']"
|
, "//str[@name='dummy3'][.='solrconfig-implicitproperties.xml']"
|
||||||
, "//str[@name='dummy4'][.='schema.xml']"
|
, "//str[@name='dummy4'][.='schema.xml']"
|
||||||
, "//str[@name='dummy5'][.='false']"
|
, "//str[@name='dummy5'][.='false']"
|
||||||
|
|
|
@ -17,9 +17,10 @@ package org.apache.solr.core;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.apache.commons.codec.Charsets;
|
import org.apache.commons.codec.Charsets;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CoreAdminParams;
|
import org.apache.solr.common.params.CoreAdminParams;
|
||||||
|
@ -31,9 +32,7 @@ import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.solr.update.AddUpdateCommand;
|
import org.apache.solr.update.AddUpdateCommand;
|
||||||
import org.apache.solr.update.CommitUpdateCommand;
|
import org.apache.solr.update.CommitUpdateCommand;
|
||||||
import org.apache.solr.update.UpdateHandler;
|
import org.apache.solr.update.UpdateHandler;
|
||||||
import org.apache.solr.util.TestHarness;
|
import org.apache.solr.util.ReadOnlyCoresLocator;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -48,18 +47,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TestLazyCores extends SolrTestCaseJ4 {
|
public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void beforeClass() throws Exception {
|
|
||||||
initCore("solrconfig-minimal.xml", "schema-tiny.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
private File solrHomeDirectory;
|
private File solrHomeDirectory;
|
||||||
|
|
||||||
@Before
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CoreContainer init() throws Exception {
|
private CoreContainer init() throws Exception {
|
||||||
solrHomeDirectory = createTempDir().toFile();
|
solrHomeDirectory = createTempDir().toFile();
|
||||||
|
@ -69,17 +57,7 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
||||||
|
return createCoreContainer(new LazyCoreTestConfig(loader));
|
||||||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, LOTS_SOLR_XML, Charsets.UTF_8.toString());
|
|
||||||
ConfigSolrXmlOld config = (ConfigSolrXmlOld) ConfigSolr.fromFile(loader, solrXml);
|
|
||||||
|
|
||||||
CoresLocator locator = new SolrXMLCoresLocator.NonPersistingLocator(LOTS_SOLR_XML, config);
|
|
||||||
|
|
||||||
|
|
||||||
final CoreContainer cores = new CoreContainer(loader, config, locator);
|
|
||||||
cores.load();
|
|
||||||
return cores;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -172,14 +150,16 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
// Now just insure that the normal searching on "collection1" finds _0_ on the same query that found _2_ above.
|
// Now just insure that the normal searching on "collection1" finds _0_ on the same query that found _2_ above.
|
||||||
// Use of makeReq above and req below is tricky, very tricky.
|
// Use of makeReq above and req below is tricky, very tricky.
|
||||||
|
SolrCore collection1 = cc.getCore("collection1");
|
||||||
assertQ("test raw query",
|
assertQ("test raw query",
|
||||||
req("q", "{!raw f=v_t}hello", "wt", "xml")
|
makeReq(collection1, "q", "{!raw f=v_t}hello", "wt", "xml")
|
||||||
, "//result[@numFound='0']"
|
, "//result[@numFound='0']"
|
||||||
);
|
);
|
||||||
|
|
||||||
checkInCores(cc, "collectionLazy4");
|
checkInCores(cc, "collectionLazy4");
|
||||||
|
|
||||||
core4.close();
|
core4.close();
|
||||||
|
collection1.close();
|
||||||
} finally {
|
} finally {
|
||||||
cc.shutdown();
|
cc.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -411,72 +391,6 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Make sure persisting not-loaded lazy cores is done. See SOLR-4347
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPersistence() throws Exception {
|
|
||||||
final CoreContainer cc = init();
|
|
||||||
try {
|
|
||||||
copyMinConf(new File(solrHomeDirectory, "core1"));
|
|
||||||
copyMinConf(new File(solrHomeDirectory, "core2"));
|
|
||||||
copyMinConf(new File(solrHomeDirectory, "core3"));
|
|
||||||
copyMinConf(new File(solrHomeDirectory, "core4"));
|
|
||||||
|
|
||||||
final CoreDescriptor cd1 = buildCoreDescriptor(cc, "core1", "./core1")
|
|
||||||
.isTransient(true).loadOnStartup(true).build();
|
|
||||||
final CoreDescriptor cd2 = buildCoreDescriptor(cc, "core2", "./core2")
|
|
||||||
.isTransient(true).loadOnStartup(false).build();
|
|
||||||
final CoreDescriptor cd3 = buildCoreDescriptor(cc, "core3", "./core3")
|
|
||||||
.isTransient(false).loadOnStartup(true).build();
|
|
||||||
final CoreDescriptor cd4 = buildCoreDescriptor(cc, "core4", "./core4")
|
|
||||||
.isTransient(false).loadOnStartup(false).build();
|
|
||||||
|
|
||||||
|
|
||||||
SolrCore core1 = cc.create(cd1);
|
|
||||||
SolrCore core2 = cc.create(cd2);
|
|
||||||
SolrCore core3 = cc.create(cd3);
|
|
||||||
SolrCore core4 = cc.create(cd4);
|
|
||||||
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator =
|
|
||||||
(SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr/cores/core[@name='collection1']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy2']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy3']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy4']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy5']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy6']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy7']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy8']",
|
|
||||||
"/solr/cores/core[@name='collectionLazy9']",
|
|
||||||
"/solr/cores/core[@name='core1']",
|
|
||||||
"/solr/cores/core[@name='core2']",
|
|
||||||
"/solr/cores/core[@name='core3']",
|
|
||||||
"/solr/cores/core[@name='core4']",
|
|
||||||
"13=count(/solr/cores/core)");
|
|
||||||
|
|
||||||
removeOne(cc, "collectionLazy2");
|
|
||||||
removeOne(cc, "collectionLazy3");
|
|
||||||
removeOne(cc, "collectionLazy4");
|
|
||||||
removeOne(cc, "collectionLazy5");
|
|
||||||
removeOne(cc, "collectionLazy6");
|
|
||||||
removeOne(cc, "collectionLazy7");
|
|
||||||
removeOne(cc, "core1");
|
|
||||||
removeOne(cc, "core2");
|
|
||||||
removeOne(cc, "core3");
|
|
||||||
removeOne(cc, "core4");
|
|
||||||
|
|
||||||
// now test that unloading a core means the core is not persisted
|
|
||||||
TestHarness.validateXPath(locator.xml, "3=count(/solr/cores/core)");
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test that transient cores
|
// Test that transient cores
|
||||||
// 1> produce errors as appropriate when the config or schema files are foo'd
|
// 1> produce errors as appropriate when the config or schema files are foo'd
|
||||||
// 2> "self heal". That is, if the problem is corrected can the core be reloaded and used?
|
// 2> "self heal". That is, if the problem is corrected can the core be reloaded and used?
|
||||||
|
@ -627,12 +541,8 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
|
||||||
ConfigSolrXml config = (ConfigSolrXml) ConfigSolr.fromFile(loader, solrXml);
|
ConfigSolrXml config = (ConfigSolrXml) ConfigSolr.fromFile(loader, solrXml);
|
||||||
|
|
||||||
CoresLocator locator = new CorePropertiesLocator(solrHomeDirectory.getAbsolutePath());
|
|
||||||
|
|
||||||
// OK this should succeed, but at the end we should have recorded a series of errors.
|
// OK this should succeed, but at the end we should have recorded a series of errors.
|
||||||
final CoreContainer cores = new CoreContainer(loader, config, locator);
|
return createCoreContainer(config);
|
||||||
cores.load();
|
|
||||||
return cores;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to see that the core "heals itself" if an un-corrupted file is written to the directory.
|
// We want to see that the core "heals itself" if an un-corrupted file is written to the directory.
|
||||||
|
@ -669,9 +579,6 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeOne(CoreContainer cc, String coreName) {
|
|
||||||
cc.unload(coreName);
|
|
||||||
}
|
|
||||||
public static void checkNotInCores(CoreContainer cc, String... nameCheck) {
|
public static void checkNotInCores(CoreContainer cc, String... nameCheck) {
|
||||||
Collection<String> names = cc.getCoreNames();
|
Collection<String> names = cc.getCoreNames();
|
||||||
for (String name : nameCheck) {
|
for (String name : nameCheck) {
|
||||||
|
@ -712,26 +619,51 @@ public class TestLazyCores extends SolrTestCaseJ4 {
|
||||||
return StringUtils.join(args, File.separator);
|
return StringUtils.join(args, File.separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String LOTS_SOLR_XML = " <solr persistent=\"false\"> " +
|
public static class LazyCoreTestConfig extends ConfigSolr {
|
||||||
"<cores adminPath=\"/admin/cores\" defaultCoreName=\"collectionLazy2\" transientCacheSize=\"4\"> " +
|
|
||||||
"<core name=\"collection1\" instanceDir=\"collection1\" /> " +
|
|
||||||
|
|
||||||
"<core name=\"collectionLazy2\" instanceDir=\"collection2\" transient=\"true\" loadOnStartup=\"true\" /> " +
|
public LazyCoreTestConfig(SolrResourceLoader loader) {
|
||||||
|
super(loader, null);
|
||||||
|
}
|
||||||
|
|
||||||
"<core name=\"collectionLazy3\" instanceDir=\"collection3\" transient=\"on\" loadOnStartup=\"false\" /> " +
|
static CoreDescriptor makeCoreDescriptor(CoreContainer cc, String coreName, String instanceDir, String isTransient, String loadOnStartup) {
|
||||||
|
return new CoreDescriptor(cc, coreName, instanceDir,
|
||||||
|
CoreDescriptor.CORE_TRANSIENT, isTransient,
|
||||||
|
CoreDescriptor.CORE_LOADONSTARTUP, loadOnStartup);
|
||||||
|
}
|
||||||
|
|
||||||
"<core name=\"collectionLazy4\" instanceDir=\"collection4\" transient=\"false\" loadOnStartup=\"false\" /> " +
|
@Override
|
||||||
|
public CoresLocator getCoresLocator() {
|
||||||
|
return new ReadOnlyCoresLocator() {
|
||||||
|
@Override
|
||||||
|
public List<CoreDescriptor> discover(CoreContainer cc) {
|
||||||
|
return ImmutableList.of(
|
||||||
|
new CoreDescriptor(cc, "collection1", "collection1"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy2", "collection2", "true", "true"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy3", "collection3", "on", "false"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy4", "collection4", "false", "false"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy5", "collection5", "false", "true"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy6", "collection6", "true", "false"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy7", "collection7", "true", "false"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy8", "collection8", "true", "false"),
|
||||||
|
makeCoreDescriptor(cc, "collectionLazy9", "collection9", "true", "false")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
"<core name=\"collectionLazy5\" instanceDir=\"collection5\" transient=\"false\" loadOnStartup=\"true\" /> " +
|
@Override
|
||||||
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
"<core name=\"collectionLazy6\" instanceDir=\"collection6\" transient=\"true\" loadOnStartup=\"false\" /> " +
|
@Override
|
||||||
|
protected String getProperty(CfgProp key) {
|
||||||
|
switch (key) {
|
||||||
|
case SOLR_TRANSIENTCACHESIZE:
|
||||||
|
return "4";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"<core name=\"collectionLazy7\" instanceDir=\"collection7\" transient=\"true\" loadOnStartup=\"false\" /> " +
|
|
||||||
|
|
||||||
"<core name=\"collectionLazy8\" instanceDir=\"collection8\" transient=\"true\" loadOnStartup=\"false\" /> " +
|
|
||||||
|
|
||||||
"<core name=\"collectionLazy9\" instanceDir=\"collection9\" transient=\"true\" loadOnStartup=\"false\" /> " +
|
|
||||||
|
|
||||||
"</cores> " +
|
|
||||||
"</solr>";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,13 +38,4 @@ public class TestShardHandlerFactory extends SolrTestCaseJ4 {
|
||||||
cc.shutdown();
|
cc.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOldXML() throws Exception {
|
|
||||||
CoreContainer cc = CoreContainer.createAndLoad(TEST_HOME(), new File(TEST_HOME(), "solr-shardhandler-old.xml"));
|
|
||||||
ShardHandlerFactory factory = cc.getShardHandlerFactory();
|
|
||||||
assertTrue(factory instanceof MockShardHandlerFactory);
|
|
||||||
NamedList args = ((MockShardHandlerFactory)factory).args;
|
|
||||||
assertEquals("myMagicRequiredValue", args.get("myMagicRequiredParameter"));
|
|
||||||
factory.close();
|
|
||||||
cc.shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,30 +18,10 @@ package org.apache.solr.core;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
||||||
import org.apache.solr.common.cloud.DocCollection;
|
|
||||||
import org.apache.solr.common.cloud.Replica;
|
|
||||||
import org.apache.solr.common.cloud.Slice;
|
|
||||||
import org.apache.solr.common.cloud.ZkStateReader;
|
|
||||||
import org.apache.solr.handler.TestBlobHandler;
|
|
||||||
import org.apache.solr.handler.TestSolrConfigHandlerConcurrent;
|
import org.apache.solr.handler.TestSolrConfigHandlerConcurrent;
|
||||||
import org.apache.solr.util.RestTestBase;
|
import org.apache.solr.util.RestTestBase;
|
||||||
import org.apache.solr.util.RestTestHarness;
|
import org.apache.solr.util.RestTestHarness;
|
||||||
|
@ -54,6 +34,19 @@ import org.restlet.ext.servlet.ServerServlet;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.solr.core.ConfigOverlay.getObjectByPath;
|
import static org.apache.solr.core.ConfigOverlay.getObjectByPath;
|
||||||
import static org.apache.solr.handler.TestBlobHandler.getAsString;
|
import static org.apache.solr.handler.TestBlobHandler.getAsString;
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,6 @@ public class TestSolrXml extends SolrTestCaseJ4 {
|
||||||
assertEquals("trans cache size", 66, cfg.getTransientCacheSize());
|
assertEquals("trans cache size", 66, cfg.getTransientCacheSize());
|
||||||
assertEquals("zk client timeout", 77, cfg.getZkClientTimeout());
|
assertEquals("zk client timeout", 77, cfg.getZkClientTimeout());
|
||||||
assertEquals("zk host", "testZkHost", cfg.getZkHost());
|
assertEquals("zk host", "testZkHost", cfg.getZkHost());
|
||||||
assertEquals("persistent", true, cfg.isPersistent());
|
|
||||||
assertEquals("core admin path", ConfigSolr.DEFAULT_CORE_ADMIN_PATH, cfg.getAdminPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test a few property substitutions that happen to be in solr-50-all.xml.
|
// Test a few property substitutions that happen to be in solr-50-all.xml.
|
||||||
|
|
|
@ -1,613 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.solr.core;
|
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.lucene.util.IOUtils;
|
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.apache.solr.common.params.CoreAdminParams;
|
|
||||||
import org.apache.solr.handler.admin.CoreAdminHandler;
|
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
|
||||||
import org.apache.solr.util.TestHarness;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.RuleChain;
|
|
||||||
import org.junit.rules.TestRule;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.NamedNodeMap;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
|
|
||||||
public class TestSolrXmlPersistence extends SolrTestCaseJ4 {
|
|
||||||
|
|
||||||
private File solrHomeDirectory = createTempDir().toFile();
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public TestRule solrTestRules =
|
|
||||||
RuleChain.outerRule(new SystemPropertiesRestoreRule());
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setupTest() {
|
|
||||||
solrHomeDirectory = createTempDir(LuceneTestCase.getTestClass().getSimpleName()).toFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private CoreContainer init(String solrXmlString, String... subDirs) throws Exception {
|
|
||||||
|
|
||||||
for (String s : subDirs) {
|
|
||||||
copyMinConf(new File(solrHomeDirectory, s));
|
|
||||||
}
|
|
||||||
|
|
||||||
File solrXml = new File(solrHomeDirectory, "solr.xml");
|
|
||||||
FileUtils.write(solrXml, solrXmlString, IOUtils.UTF_8);
|
|
||||||
|
|
||||||
final CoreContainer cores = createCoreContainer(solrHomeDirectory.getAbsolutePath(), solrXmlString);
|
|
||||||
return cores;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// take a solr.xml with system vars in <solr>, <cores> and <core> and <core/properties> tags that have system
|
|
||||||
// variables defined. Insure that after persisting solr.xml, they're all still there as ${} syntax.
|
|
||||||
// Also insure that nothing extra crept in.
|
|
||||||
@Test
|
|
||||||
public void testSystemVars() throws Exception {
|
|
||||||
//Set these system props in order to insure that we don't write out the values rather than the ${} syntax.
|
|
||||||
System.setProperty("solr.zkclienttimeout", "93");
|
|
||||||
System.setProperty("solrconfig", "solrconfig.xml");
|
|
||||||
System.setProperty("schema", "schema.xml");
|
|
||||||
System.setProperty("zkHostSet", "localhost:9983");
|
|
||||||
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
|
|
||||||
try {
|
|
||||||
origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReload() throws Exception {
|
|
||||||
// Whether the core is transient or not can make a difference.
|
|
||||||
doReloadTest("SystemVars2");
|
|
||||||
doReloadTest("SystemVars1");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doReloadTest(String which) throws Exception {
|
|
||||||
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
|
|
||||||
try {
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
|
||||||
SolrQueryResponse resp = new SolrQueryResponse();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.RELOAD.toString(),
|
|
||||||
CoreAdminParams.CORE, which),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on reload", resp.getException());
|
|
||||||
|
|
||||||
origMatchesPersist(cc, SOLR_XML_LOTS_SYSVARS);
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
if (solrHomeDirectory.exists()) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRename() throws Exception {
|
|
||||||
doTestRename("SystemVars1");
|
|
||||||
doTestRename("SystemVars2");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTestRename(String which) throws Exception {
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
|
||||||
SolrQueryResponse resp = new SolrQueryResponse();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.RENAME.toString(),
|
|
||||||
CoreAdminParams.CORE, which,
|
|
||||||
CoreAdminParams.OTHER, "RenamedCore"),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on rename", resp.getException());
|
|
||||||
|
|
||||||
// OK, Assure that if I change everything that has been renamed with the original value for the core, it matches
|
|
||||||
// the old list
|
|
||||||
String[] persistList = getAllNodes();
|
|
||||||
String[] expressions = new String[persistList.length];
|
|
||||||
|
|
||||||
for (int idx = 0; idx < persistList.length; ++idx) {
|
|
||||||
expressions[idx] = persistList[idx].replaceAll("RenamedCore", which);
|
|
||||||
}
|
|
||||||
|
|
||||||
//assertXmlFile(origXml, expressions);
|
|
||||||
TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);
|
|
||||||
|
|
||||||
// Now the other way, If I replace the original name in the original XML file with "RenamedCore", does it match
|
|
||||||
// what was persisted?
|
|
||||||
persistList = getAllNodes(SOLR_XML_LOTS_SYSVARS);
|
|
||||||
expressions = new String[persistList.length];
|
|
||||||
for (int idx = 0; idx < persistList.length; ++idx) {
|
|
||||||
// /solr/cores/core[@name='SystemVars1' and @collection='${collection:collection1}']
|
|
||||||
expressions[idx] = persistList[idx].replace("@name='" + which + "'", "@name='RenamedCore'");
|
|
||||||
}
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml, expressions);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
if (solrHomeDirectory.exists()) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSwap() throws Exception {
|
|
||||||
doTestSwap("SystemVars1", "SystemVars2");
|
|
||||||
doTestSwap("SystemVars2", "SystemVars1");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Count the number of times substring appears in target
|
|
||||||
*/
|
|
||||||
private int countOccurrences(String target, String substring) {
|
|
||||||
int pos = -1, count = 0;
|
|
||||||
while ((pos = target.indexOf(substring, pos + 1)) != -1) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTestSwap(String from, String to) throws Exception {
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();
|
|
||||||
|
|
||||||
int coreCount = countOccurrences(locator.xml, "<core ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
|
||||||
SolrQueryResponse resp = new SolrQueryResponse();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.SWAP.toString(),
|
|
||||||
CoreAdminParams.CORE, from,
|
|
||||||
CoreAdminParams.OTHER, to),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on swap", resp.getException());
|
|
||||||
|
|
||||||
assertThat("Swapping cores should leave the same number of cores as before",
|
|
||||||
countOccurrences(locator.xml, "<core "), is(coreCount));
|
|
||||||
|
|
||||||
String[] persistList = getAllNodes();
|
|
||||||
String[] expressions = new String[persistList.length];
|
|
||||||
|
|
||||||
// Now manually change the names back and it should match exactly to the original XML.
|
|
||||||
for (int idx = 0; idx < persistList.length; ++idx) {
|
|
||||||
String fromName = "@name='" + from + "'";
|
|
||||||
String toName = "@name='" + to + "'";
|
|
||||||
if (persistList[idx].contains(fromName)) {
|
|
||||||
expressions[idx] = persistList[idx].replace(fromName, toName);
|
|
||||||
} else {
|
|
||||||
expressions[idx] = persistList[idx].replace(toName, fromName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//assertXmlFile(origXml, expressions);
|
|
||||||
TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
if (solrHomeDirectory.exists()) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMinimalXml() throws Exception {
|
|
||||||
CoreContainer cc = init(SOLR_XML_MINIMAL, "SystemVars1");
|
|
||||||
try {
|
|
||||||
cc.shutdown();
|
|
||||||
origMatchesPersist(cc, SOLR_XML_MINIMAL);
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void origMatchesPersist(CoreContainer cc, String originalSolrXML) throws Exception {
|
|
||||||
String[] expressions = getAllNodes(originalSolrXML);
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml, expressions);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUnloadCreate() throws Exception {
|
|
||||||
doTestUnloadCreate("SystemVars1");
|
|
||||||
doTestUnloadCreate("SystemVars2");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTestUnloadCreate(String which) throws Exception {
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2");
|
|
||||||
try {
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
|
||||||
|
|
||||||
SolrQueryResponse resp = new SolrQueryResponse();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.UNLOAD.toString(),
|
|
||||||
CoreAdminParams.CORE, which),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on unload", resp.getException());
|
|
||||||
|
|
||||||
//origMatchesPersist(cc, new File(solrHomeDirectory, "unloadcreate1.solr.xml"));
|
|
||||||
|
|
||||||
String instPath = new File(solrHomeDirectory, which).getAbsolutePath();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.CREATE.toString(),
|
|
||||||
CoreAdminParams.INSTANCE_DIR, instPath,
|
|
||||||
CoreAdminParams.NAME, which),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on create", resp.getException());
|
|
||||||
|
|
||||||
String[] persistList = getAllNodes();
|
|
||||||
String[] expressions = new String[persistList.length];
|
|
||||||
|
|
||||||
// Now manually change the names back and it should match exactly to the original XML.
|
|
||||||
for (int idx = 0; idx < persistList.length; ++idx) {
|
|
||||||
String name = "@name='" + which + "'";
|
|
||||||
|
|
||||||
if (persistList[idx].contains(name)) {
|
|
||||||
if (persistList[idx].contains("@schema='schema.xml'")) {
|
|
||||||
expressions[idx] = persistList[idx].replace("schema.xml", "${schema:schema.xml}");
|
|
||||||
} else if (persistList[idx].contains("@config='solrconfig.xml'")) {
|
|
||||||
expressions[idx] = persistList[idx].replace("solrconfig.xml", "${solrconfig:solrconfig.xml}");
|
|
||||||
} else if (persistList[idx].contains("@instanceDir=")) {
|
|
||||||
expressions[idx] = persistList[idx].replaceFirst("instanceDir\\='.*?'", "instanceDir='" + which + "/'");
|
|
||||||
} else {
|
|
||||||
expressions[idx] = persistList[idx];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
expressions[idx] = persistList[idx];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//assertXmlFile(origXml, expressions);
|
|
||||||
TestHarness.validateXPath(SOLR_XML_LOTS_SYSVARS, expressions);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
if (solrHomeDirectory.exists()) {
|
|
||||||
FileUtils.deleteDirectory(solrHomeDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatePersistCore() throws Exception {
|
|
||||||
// Template for creating a core.
|
|
||||||
CoreContainer cc = init(SOLR_XML_LOTS_SYSVARS, "SystemVars1", "SystemVars2", "props1", "props2");
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cc.getCoresLocator();
|
|
||||||
|
|
||||||
try {
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cc);
|
|
||||||
// create a new core (using CoreAdminHandler) w/ properties
|
|
||||||
|
|
||||||
SolrQueryResponse resp = new SolrQueryResponse();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.CREATE.toString(),
|
|
||||||
CoreAdminParams.NAME, "props1",
|
|
||||||
CoreAdminParams.TRANSIENT, "true",
|
|
||||||
CoreAdminParams.LOAD_ON_STARTUP, "true",
|
|
||||||
CoreAdminParams.PROPERTY_PREFIX + "prefix1", "valuep1",
|
|
||||||
CoreAdminParams.PROPERTY_PREFIX + "prefix2", "valueP2",
|
|
||||||
"wt", "json", // need to insure that extra parameters are _not_ preserved (actually happened).
|
|
||||||
"qt", "admin/cores"),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on create", resp.getException());
|
|
||||||
|
|
||||||
String instPath2 = new File(solrHomeDirectory, "props2").getAbsolutePath();
|
|
||||||
admin.handleRequestBody
|
|
||||||
(req(CoreAdminParams.ACTION,
|
|
||||||
CoreAdminParams.CoreAdminAction.CREATE.toString(),
|
|
||||||
CoreAdminParams.INSTANCE_DIR, instPath2,
|
|
||||||
CoreAdminParams.NAME, "props2",
|
|
||||||
CoreAdminParams.PROPERTY_PREFIX + "prefix2_1", "valuep2_1",
|
|
||||||
CoreAdminParams.PROPERTY_PREFIX + "prefix2_2", "valueP2_2",
|
|
||||||
CoreAdminParams.CONFIG, "solrconfig.xml",
|
|
||||||
CoreAdminParams.DATA_DIR, "./dataDirTest",
|
|
||||||
CoreAdminParams.SCHEMA, "schema.xml"),
|
|
||||||
resp);
|
|
||||||
assertNull("Exception on create", resp.getException());
|
|
||||||
|
|
||||||
// Everything that was in the original XML file should be in the persisted one.
|
|
||||||
TestHarness.validateXPath(locator.xml, getAllNodes(SOLR_XML_LOTS_SYSVARS));
|
|
||||||
|
|
||||||
// And the params for the new core should be in the persisted file.
|
|
||||||
TestHarness.validateXPath
|
|
||||||
(
|
|
||||||
locator.xml,
|
|
||||||
"/solr/cores/core[@name='props1']/property[@name='prefix1' and @value='valuep1']"
|
|
||||||
, "/solr/cores/core[@name='props1']/property[@name='prefix2' and @value='valueP2']"
|
|
||||||
, "/solr/cores/core[@name='props1' and @transient='true']"
|
|
||||||
, "/solr/cores/core[@name='props1' and @loadOnStartup='true']"
|
|
||||||
, "/solr/cores/core[@name='props1' and @instanceDir='props1" + File.separator + "']"
|
|
||||||
, "/solr/cores/core[@name='props2']/property[@name='prefix2_1' and @value='valuep2_1']"
|
|
||||||
, "/solr/cores/core[@name='props2']/property[@name='prefix2_2' and @value='valueP2_2']"
|
|
||||||
, "/solr/cores/core[@name='props2' and @config='solrconfig.xml']"
|
|
||||||
, "/solr/cores/core[@name='props2' and @schema='schema.xml']"
|
|
||||||
, "/solr/cores/core[@name='props2' and not(@loadOnStartup)]"
|
|
||||||
, "/solr/cores/core[@name='props2' and not(@transient)]"
|
|
||||||
, "/solr/cores/core[@name='props2' and @instanceDir='" + instPath2 + "']"
|
|
||||||
, "/solr/cores/core[@name='props2' and @dataDir='./dataDirTest']"
|
|
||||||
);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cc.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPersist() throws Exception {
|
|
||||||
|
|
||||||
String defXml = FileUtils.readFileToString(
|
|
||||||
new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
|
|
||||||
StandardCharsets.UTF_8.name());
|
|
||||||
final CoreContainer cores = init(defXml, "collection1");
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();
|
|
||||||
|
|
||||||
String instDir;
|
|
||||||
try (SolrCore template = cores.getCore("collection1")) {
|
|
||||||
assertNotNull(template);
|
|
||||||
instDir = template.getCoreDescriptor().getRawInstanceDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
final File instDirFile = new File(cores.getSolrHome(), instDir);
|
|
||||||
assertTrue("instDir doesn't exist: " + instDir, instDirFile.exists());
|
|
||||||
|
|
||||||
// sanity check the basic persistence of the default init
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr[@persistent='true']",
|
|
||||||
"/solr/cores[@defaultCoreName='collection1' and not(@transientCacheSize)]",
|
|
||||||
"/solr/cores/core[@name='collection1' and @instanceDir='" + instDir +
|
|
||||||
"' and @transient='false' and @loadOnStartup='true' ]",
|
|
||||||
"1=count(/solr/cores/core)");
|
|
||||||
|
|
||||||
// create some new cores and sanity check the persistence
|
|
||||||
|
|
||||||
final File dataXfile = new File(solrHomeDirectory, "dataX");
|
|
||||||
final String dataX = dataXfile.getAbsolutePath();
|
|
||||||
assertTrue("dataXfile mkdirs failed: " + dataX, dataXfile.mkdirs());
|
|
||||||
|
|
||||||
final File instYfile = new File(solrHomeDirectory, "instY");
|
|
||||||
FileUtils.copyDirectory(instDirFile, instYfile);
|
|
||||||
|
|
||||||
// :HACK: dataDir leaves off trailing "/", but instanceDir uses it
|
|
||||||
final String instY = instYfile.getAbsolutePath() + "/";
|
|
||||||
|
|
||||||
final CoreDescriptor xd = buildCoreDescriptor(cores, "X", instDir)
|
|
||||||
.withDataDir(dataX).build();
|
|
||||||
|
|
||||||
final CoreDescriptor yd = new CoreDescriptor(cores, "Y", instY);
|
|
||||||
|
|
||||||
SolrCore x = null;
|
|
||||||
SolrCore y = null;
|
|
||||||
try {
|
|
||||||
x = cores.create(xd);
|
|
||||||
y = cores.create(yd);
|
|
||||||
|
|
||||||
assertEquals("cores not added?", 3, cores.getCoreNames().size());
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr[@persistent='true']",
|
|
||||||
"/solr/cores[@defaultCoreName='collection1']",
|
|
||||||
"/solr/cores/core[@name='collection1' and @instanceDir='" + instDir
|
|
||||||
+ "']", "/solr/cores/core[@name='X' and @instanceDir='" + instDir
|
|
||||||
+ "' and @dataDir='" + dataX + "']",
|
|
||||||
"/solr/cores/core[@name='Y' and @instanceDir='" + instY + "']",
|
|
||||||
"3=count(/solr/cores/core)");
|
|
||||||
|
|
||||||
// Test for saving implicit properties, we should not do this.
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr/cores/core[@name='X' and not(@solr.core.instanceDir) and not (@solr.core.configName)]");
|
|
||||||
|
|
||||||
cores.unload("X");
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml, "/solr[@persistent='true']",
|
|
||||||
"/solr/cores[@defaultCoreName='collection1']",
|
|
||||||
"/solr/cores/core[@name='collection1' and @instanceDir='" + instDir + "']",
|
|
||||||
"/solr/cores/core[@name='Y' and @instanceDir='" + instY + "']",
|
|
||||||
"2=count(/solr/cores/core)");
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
cores.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private String[] getAllNodes(InputStream is) throws ParserConfigurationException, IOException, SAXException {
|
|
||||||
List<String> expressions = new ArrayList<>(); // XPATH and value for all elements in the indicated XML
|
|
||||||
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
|
|
||||||
.newInstance();
|
|
||||||
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
|
|
||||||
Document document = docBuilder.parse(is);
|
|
||||||
|
|
||||||
Node root = document.getDocumentElement();
|
|
||||||
gatherNodes(root, expressions, "");
|
|
||||||
return expressions.toArray(new String[expressions.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getAllNodes() throws ParserConfigurationException, IOException, SAXException {
|
|
||||||
return getAllNodes(new FileInputStream(new File(solrHomeDirectory, "solr.xml")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getAllNodes(String xmlString) throws ParserConfigurationException, IOException, SAXException {
|
|
||||||
return getAllNodes(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
private void assertSolrXmlFile(String... xpathExpressions) throws IOException, SAXException {
|
|
||||||
assertXmlFile(new File(solrHomeDirectory, "solr.xml"), xpathExpressions);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Note this is pretty specialized for a solr.xml file because working with the DOM is such a pain.
|
|
||||||
|
|
||||||
private static List<String> qualified = new ArrayList<String>() {{
|
|
||||||
add("core");
|
|
||||||
add("property");
|
|
||||||
add("int");
|
|
||||||
add("str");
|
|
||||||
add("long");
|
|
||||||
add("property");
|
|
||||||
}};
|
|
||||||
|
|
||||||
private static List<String> addText = new ArrayList<String>() {{
|
|
||||||
add("int");
|
|
||||||
add("str");
|
|
||||||
add("long");
|
|
||||||
}};
|
|
||||||
|
|
||||||
// path is the path to parent node
|
|
||||||
|
|
||||||
private void gatherNodes(Node node, List<String> expressions, String path) {
|
|
||||||
|
|
||||||
String nodeName = node.getNodeName();
|
|
||||||
String thisPath = path + "/" + nodeName;
|
|
||||||
//Parent[@id='1']/Children/child[@name]
|
|
||||||
// Add in the xpaths for verification of any attributes.
|
|
||||||
NamedNodeMap attrs = node.getAttributes();
|
|
||||||
String qualifier = "";
|
|
||||||
if (attrs.getLength() > 0) {
|
|
||||||
// Assemble the prefix for qualifying all of the attributes with the same name
|
|
||||||
if (qualified.contains(nodeName)) {
|
|
||||||
qualifier = "@name='" + node.getAttributes().getNamedItem("name").getTextContent() + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int idx = 0; idx < attrs.getLength(); ++idx) {
|
|
||||||
|
|
||||||
Node attr = attrs.item(idx);
|
|
||||||
if (StringUtils.isNotBlank(qualifier) && "name".equals(attr.getNodeName())) {
|
|
||||||
continue; // Already added "name" attribute in qualifier string.
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(qualifier)) {
|
|
||||||
// Create [@name="stuff" and @attrib="value"] fragment
|
|
||||||
expressions.add(thisPath +
|
|
||||||
"[" + qualifier + " and @" + attr.getNodeName() + "='" + attr.getTextContent() + "']");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Create [@attrib="value"] fragment
|
|
||||||
expressions.add(thisPath +
|
|
||||||
"[" + qualifier + " @" + attr.getNodeName() + "='" + attr.getTextContent() + "']");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Now add the text for special nodes
|
|
||||||
// a[normalize-space(text())='somesite']
|
|
||||||
if (addText.contains(nodeName)) {
|
|
||||||
expressions.add(thisPath + "[" + qualifier + " and text()='" + node.getTextContent() + "']");
|
|
||||||
}
|
|
||||||
// Now collect all the child element nodes.
|
|
||||||
NodeList nodeList = node.getChildNodes();
|
|
||||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
|
||||||
|
|
||||||
Node currentNode = nodeList.item(i);
|
|
||||||
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
|
|
||||||
if (StringUtils.isNotBlank(qualifier)) {
|
|
||||||
gatherNodes(currentNode, expressions, thisPath + "[" + qualifier + "]");
|
|
||||||
} else {
|
|
||||||
gatherNodes(currentNode, expressions, thisPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String SOLR_XML_LOTS_SYSVARS =
|
|
||||||
"<solr persistent=\"${solr.xml.persist:false}\" coreLoadThreads=\"12\" sharedLib=\"${something:.}\" >\n" +
|
|
||||||
" <logging class=\"${logclass:log4j.class}\" enabled=\"{logenable:true}\">\n" +
|
|
||||||
" <watcher size=\"${watchSize:13}\" threshold=\"${logThresh:54}\" />\n" +
|
|
||||||
" </logging>\n" +
|
|
||||||
" <cores adminPath=\"/admin/cores\" defaultCoreName=\"SystemVars1\" host=\"127.0.0.1\" \n" +
|
|
||||||
" hostPort=\"${hostPort:8983}\" hostContext=\"${hostContext:solr}\" \n" +
|
|
||||||
" zkClientTimeout=\"${solr.zkclienttimeout:30000}\" \n" +
|
|
||||||
" shareSchema=\"${shareSchema:false}\" distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\" \n" +
|
|
||||||
" distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\" \n" +
|
|
||||||
" leaderVoteWait=\"${leadVoteWait:32}\" managementPath=\"${manpath:/var/lib/path}\" transientCacheSize=\"${tranSize:128}\"> \n" +
|
|
||||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" shard=\"${shard:32}\" \n" +
|
|
||||||
" collection=\"${collection:collection1}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
|
||||||
" schema=\"${schema:schema.xml}\" ulogDir=\"${ulog:./}\" roles=\"${myrole:boss}\" \n" +
|
|
||||||
" dataDir=\"${data:./}\" loadOnStartup=\"${onStart:true}\" transient=\"${tran:true}\" \n" +
|
|
||||||
" coreNodeName=\"${coreNode:utterlyridiculous}\" \n" +
|
|
||||||
" >\n" +
|
|
||||||
" </core>\n" +
|
|
||||||
" <core name=\"SystemVars2\" instanceDir=\"SystemVars2/\" shard=\"${shard:32}\" \n" +
|
|
||||||
" collection=\"${collection:collection2}\" config=\"${solrconfig:solrconfig.xml}\" \n" +
|
|
||||||
" coreNodeName=\"${coreNodeName:}\" schema=\"${schema:schema.xml}\">\n" +
|
|
||||||
" <property name=\"collection\" value=\"{collection:collection2}\"/>\n" +
|
|
||||||
" <property name=\"schema\" value=\"${schema:schema.xml}\"/>\n" +
|
|
||||||
" <property name=\"coreNodeName\" value=\"EricksCore\"/>\n" +
|
|
||||||
" </core>\n" +
|
|
||||||
" <shardHandlerFactory name=\"${shhandler:shardHandlerFactory}\" class=\"${handlefac:HttpShardHandlerFactory}\">\n" +
|
|
||||||
" <int name=\"socketTimeout\">${socketTimeout:120000}</int> \n" +
|
|
||||||
" <int name=\"connTimeout\">${connTimeout:15000}</int> \n" +
|
|
||||||
" <str name=\"arbitraryName\">${arbitrarySysValue:foobar}</str>\n" +
|
|
||||||
" </shardHandlerFactory> \n" +
|
|
||||||
" </cores>\n" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
|
|
||||||
private static String SOLR_XML_MINIMAL =
|
|
||||||
"<solr >\n" +
|
|
||||||
" <cores> \n" +
|
|
||||||
" <core name=\"SystemVars1\" instanceDir=\"SystemVars1/\" />\n" +
|
|
||||||
" </cores>\n" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,127 +0,0 @@
|
||||||
package org.apache.solr.core;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
public class TestSolrXmlPersistor extends SolrTestCaseJ4 {
|
|
||||||
|
|
||||||
private static final List<CoreDescriptor> EMPTY_CD_LIST = ImmutableList.<CoreDescriptor>builder().build();
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void selfClosingCoresTagIsPersisted() {
|
|
||||||
|
|
||||||
final String solrxml = "<solr><cores adminHandler=\"/admin\"/></solr>";
|
|
||||||
|
|
||||||
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
assertEquals("<solr><cores adminHandler=\"/admin\"></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void emptyCoresTagIsPersisted() {
|
|
||||||
final String solrxml = "<solr><cores adminHandler=\"/admin\"></cores></solr>";
|
|
||||||
|
|
||||||
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
assertEquals("<solr><cores adminHandler=\"/admin\"></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void emptySolrXmlIsPersisted() {
|
|
||||||
final String solrxml = "<solr></solr>";
|
|
||||||
|
|
||||||
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
assertEquals("<solr><cores></cores></solr>", persistor.buildSolrXML(EMPTY_CD_LIST));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void simpleCoreDescriptorIsPersisted() throws IOException {
|
|
||||||
|
|
||||||
final String solrxml = "<solr><cores></cores></solr>";
|
|
||||||
|
|
||||||
final File solrHomeDirectory = createTempDir().toFile();
|
|
||||||
|
|
||||||
copyMinFullSetup(solrHomeDirectory);
|
|
||||||
|
|
||||||
CoreContainer cc = new CoreContainer(solrHomeDirectory.getAbsolutePath());
|
|
||||||
|
|
||||||
final CoreDescriptor cd = new CoreDescriptor(cc, "testcore",
|
|
||||||
"instance/dir/");
|
|
||||||
List<CoreDescriptor> cds = ImmutableList.of(cd);
|
|
||||||
|
|
||||||
SolrXMLCoresLocator persistor = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
String xml = persistor.buildSolrXML(cds);
|
|
||||||
|
|
||||||
assertTrue(xml.contains("<solr><cores>"));
|
|
||||||
assertTrue(xml.contains("name=\"testcore\""));
|
|
||||||
assertTrue(xml.contains("instanceDir=\"instance/dir/\""));
|
|
||||||
assertTrue(xml.contains("</cores></solr>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shardHandlerInfoIsPersisted() {
|
|
||||||
|
|
||||||
final String solrxml =
|
|
||||||
"<solr>" +
|
|
||||||
"<cores adminHandler=\"whatever\">" +
|
|
||||||
"<core name=\"testcore\" instanceDir=\"instance/dir/\"/>" +
|
|
||||||
"<shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\">" +
|
|
||||||
"<int name=\"socketTimeout\">${socketTimeout:500}</int>" +
|
|
||||||
"<str name=\"arbitrary\">arbitraryValue</str>" +
|
|
||||||
"</shardHandlerFactory>" +
|
|
||||||
"</cores>" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
SolrXMLCoresLocator locator = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));
|
|
||||||
assertTrue(locator.getTemplate().contains("<shardHandlerFactory "));
|
|
||||||
assertTrue(locator.getTemplate().contains("${socketTimeout:500}"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void simpleShardHandlerInfoIsPersisted() {
|
|
||||||
|
|
||||||
final String solrxml =
|
|
||||||
"<solr>" +
|
|
||||||
"<cores adminHandler=\"whatever\">" +
|
|
||||||
"<core name=\"testcore\" instanceDir=\"instance/dir/\"/>" +
|
|
||||||
"<shardHandlerFactory name=\"shardHandlerFactory\" class=\"HttpShardHandlerFactory\"/>" +
|
|
||||||
"</cores>" +
|
|
||||||
"</solr>";
|
|
||||||
|
|
||||||
SolrXMLCoresLocator locator = new SolrXMLCoresLocator(solrxml, null);
|
|
||||||
assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));
|
|
||||||
assertTrue(locator.getTemplate().contains("<shardHandlerFactory "));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void complexXmlIsParsed() {
|
|
||||||
SolrXMLCoresLocator locator = new SolrXMLCoresLocator(TestSolrXmlPersistence.SOLR_XML_LOTS_SYSVARS, null);
|
|
||||||
assertTrue(locator.getTemplate().contains("{{CORES_PLACEHOLDER}}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -68,6 +68,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -153,7 +154,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
private static SolrClient createNewSolrClient(int port) {
|
private static SolrClient createNewSolrClient(int port) {
|
||||||
try {
|
try {
|
||||||
// setup the client...
|
// setup the client...
|
||||||
HttpSolrClient client = new HttpSolrClient(buildUrl(port));
|
HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);
|
||||||
client.setConnectionTimeout(15000);
|
client.setConnectionTimeout(15000);
|
||||||
client.setSoTimeout(60000);
|
client.setSoTimeout(60000);
|
||||||
client.setDefaultMaxConnectionsPerHost(100);
|
client.setDefaultMaxConnectionsPerHost(100);
|
||||||
|
@ -261,18 +262,27 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private NamedList<Object> reloadCore(SolrClient s, String core) throws Exception {
|
private NamedList<Object> reloadCore(SolrClient s, String core) throws Exception {
|
||||||
|
|
||||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||||
params.set("action","reload");
|
params.set("action","reload");
|
||||||
params.set("core", core);
|
params.set("core", core);
|
||||||
params.set("qt","/admin/cores");
|
params.set("qt","/admin/cores");
|
||||||
QueryRequest req = new QueryRequest(params);
|
QueryRequest req = new QueryRequest(params);
|
||||||
|
|
||||||
NamedList<Object> res = s.request(req);
|
HttpSolrClient adminClient = adminClient(s);
|
||||||
|
try {
|
||||||
|
NamedList<Object> res = adminClient.request(req);
|
||||||
|
assertNotNull("null response from server", res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
adminClient.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assertNotNull("null response from server", res);
|
private HttpSolrClient adminClient(SolrClient client) {
|
||||||
|
String adminUrl = ((HttpSolrClient)client).getBaseURL().replace("/collection1", "");
|
||||||
return res;
|
return new HttpSolrClient(adminUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -449,7 +459,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) + "/replication?command=" + pCommand;
|
String masterUrl = buildUrl(pJettyPort) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + pCommand;
|
||||||
URL u = new URL(masterUrl);
|
URL u = new URL(masterUrl);
|
||||||
InputStream stream = u.openStream();
|
InputStream stream = u.openStream();
|
||||||
stream.close();
|
stream.close();
|
||||||
|
@ -608,8 +618,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
assertEquals(nDocs, masterQueryResult.getNumFound());
|
assertEquals(nDocs, masterQueryResult.getNumFound());
|
||||||
|
|
||||||
// snappull
|
// snappull
|
||||||
String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/replication?command=fetchindex&masterUrl=";
|
String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=fetchindex&masterUrl=";
|
||||||
masterUrl += buildUrl(masterJetty.getLocalPort()) + "/replication";
|
masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + "/replication";
|
||||||
URL url = new URL(masterUrl);
|
URL url = new URL(masterUrl);
|
||||||
InputStream stream = url.openStream();
|
InputStream stream = url.openStream();
|
||||||
stream.close();
|
stream.close();
|
||||||
|
@ -962,8 +972,10 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
URL url;
|
URL url;
|
||||||
InputStream stream;
|
InputStream stream;
|
||||||
masterUrl = buildUrl(to.getLocalPort())
|
masterUrl = buildUrl(to.getLocalPort())
|
||||||
|
+ "/" + DEFAULT_TEST_CORENAME
|
||||||
+ "/replication?wait=true&command=fetchindex&masterUrl="
|
+ "/replication?wait=true&command=fetchindex&masterUrl="
|
||||||
+ buildUrl(from.getLocalPort()) + "/replication";
|
+ buildUrl(from.getLocalPort())
|
||||||
|
+ "/" + DEFAULT_TEST_CORENAME + "/replication";
|
||||||
url = new URL(masterUrl);
|
url = new URL(masterUrl);
|
||||||
stream = url.openStream();
|
stream = url.openStream();
|
||||||
stream.close();
|
stream.close();
|
||||||
|
@ -1391,34 +1403,40 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
final long sleepInterval = 200;
|
final long sleepInterval = 200;
|
||||||
long timeSlept = 0;
|
long timeSlept = 0;
|
||||||
|
|
||||||
SolrParams p = params("action","status", "core", "collection1");
|
HttpSolrClient adminClient = adminClient(client);
|
||||||
while (timeSlept < timeout) {
|
try {
|
||||||
QueryRequest req = new QueryRequest(p);
|
SolrParams p = params("action", "status", "core", "collection1");
|
||||||
req.setPath("/admin/cores");
|
while (timeSlept < timeout) {
|
||||||
try {
|
QueryRequest req = new QueryRequest(p);
|
||||||
NamedList data = client.request(req);
|
req.setPath("/admin/cores");
|
||||||
for (String k : new String[] {"status","collection1"}) {
|
try {
|
||||||
Object o = data.get(k);
|
NamedList data = adminClient.request(req);
|
||||||
assertNotNull("core status rsp missing key: " + k, o);
|
for (String k : new String[]{"status", "collection1"}) {
|
||||||
data = (NamedList) o;
|
Object o = data.get(k);
|
||||||
|
assertNotNull("core status rsp missing key: " + k, o);
|
||||||
|
data = (NamedList) o;
|
||||||
|
}
|
||||||
|
Date startTime = (Date) data.get("startTime");
|
||||||
|
assertNotNull("core has null startTime", startTime);
|
||||||
|
if (null == min || startTime.after(min)) {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
} catch (SolrException e) {
|
||||||
|
// workarround for SOLR-4668
|
||||||
|
if (500 != e.code()) {
|
||||||
|
throw e;
|
||||||
|
} // else server possibly from the core reload in progress...
|
||||||
}
|
}
|
||||||
Date startTime = (Date) data.get("startTime");
|
|
||||||
assertNotNull("core has null startTime", startTime);
|
|
||||||
if (null == min || startTime.after(min)) {
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
} catch (SolrException e) {
|
|
||||||
// workarround for SOLR-4668
|
|
||||||
if (500 != e.code()) {
|
|
||||||
throw e;
|
|
||||||
} // else server possibly from the core reload in progress...
|
|
||||||
}
|
|
||||||
|
|
||||||
timeSlept += sleepInterval;
|
timeSlept += sleepInterval;
|
||||||
Thread.sleep(sleepInterval);
|
Thread.sleep(sleepInterval);
|
||||||
|
}
|
||||||
|
fail("timed out waiting for collection1 startAt time to exceed: " + min);
|
||||||
|
return min; // compilation neccessity
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
adminClient.shutdown();
|
||||||
}
|
}
|
||||||
fail("timed out waiting for collection1 startAt time to exceed: " + min);
|
|
||||||
return min; // compilation neccessity
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String buildUrl(int port) {
|
private static String buildUrl(int port) {
|
||||||
|
@ -1476,6 +1494,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
||||||
System.setProperty("solr.test.sys.prop1", "propone");
|
System.setProperty("solr.test.sys.prop1", "propone");
|
||||||
System.setProperty("solr.test.sys.prop2", "proptwo");
|
System.setProperty("solr.test.sys.prop2", "proptwo");
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("name", "collection1");
|
||||||
|
|
||||||
|
writeCoreProperties(homeDir.toPath().resolve("collection1"), props, "TestReplicationHandler");
|
||||||
|
|
||||||
dataDir = new File(homeDir + "/collection1", "data");
|
dataDir = new File(homeDir + "/collection1", "data");
|
||||||
confDir = new File(homeDir + "/collection1", "conf");
|
confDir = new File(homeDir + "/collection1", "conf");
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
private static SolrClient createNewSolrClient(int port) {
|
private static SolrClient createNewSolrClient(int port) {
|
||||||
try {
|
try {
|
||||||
// setup the client...
|
// setup the client...
|
||||||
HttpSolrClient client = new HttpSolrClient(buildUrl(port, context));
|
HttpSolrClient client = new HttpSolrClient(buildUrl(port, context) + "/" + DEFAULT_TEST_CORENAME);
|
||||||
client.setConnectionTimeout(15000);
|
client.setConnectionTimeout(15000);
|
||||||
client.setSoTimeout(60000);
|
client.setSoTimeout(60000);
|
||||||
client.setDefaultMaxConnectionsPerHost(100);
|
client.setDefaultMaxConnectionsPerHost(100);
|
||||||
|
@ -260,7 +260,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchStatus() throws IOException {
|
public void fetchStatus() throws IOException {
|
||||||
String masterUrl = buildUrl(masterJetty.getLocalPort(), "/solr") + "/replication?command=" + ReplicationHandler.CMD_DETAILS;
|
String masterUrl = buildUrl(masterJetty.getLocalPort(), "/solr") + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS;
|
||||||
URL url;
|
URL url;
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
try {
|
try {
|
||||||
|
@ -309,10 +309,10 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
public void runCommand() {
|
public void runCommand() {
|
||||||
String masterUrl = null;
|
String masterUrl = null;
|
||||||
if(backupName != null) {
|
if(backupName != null) {
|
||||||
masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + cmd +
|
masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + cmd +
|
||||||
"&name=" + backupName;
|
"&name=" + backupName;
|
||||||
} else {
|
} else {
|
||||||
masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + cmd +
|
masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + cmd +
|
||||||
(addNumberToKeepInRequest ? "&" + backupKeepParamName + "=1" : "");
|
(addNumberToKeepInRequest ? "&" + backupKeepParamName + "=1" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +343,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fetchStatus() throws IOException {
|
public boolean fetchStatus() throws IOException {
|
||||||
String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + ReplicationHandler.CMD_DETAILS;
|
String masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/" + DEFAULT_TEST_CORENAME + "/replication?command=" + ReplicationHandler.CMD_DETAILS;
|
||||||
URL url;
|
URL url;
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrXMLCoresLocator;
|
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@ -73,8 +72,6 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
|
||||||
new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));
|
new File(subHome, "solrconfig.snippet.randomindexconfig.xml"));
|
||||||
|
|
||||||
final CoreContainer cores = h.getCoreContainer();
|
final CoreContainer cores = h.getCoreContainer();
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();
|
|
||||||
|
|
||||||
final CoreAdminHandler admin = new CoreAdminHandler(cores);
|
final CoreAdminHandler admin = new CoreAdminHandler(cores);
|
||||||
|
|
||||||
|
@ -98,15 +95,6 @@ public class CoreAdminHandlerTest extends SolrTestCaseJ4 {
|
||||||
resp);
|
resp);
|
||||||
assertNull("Exception on create", resp.getException());
|
assertNull("Exception on create", resp.getException());
|
||||||
|
|
||||||
// First assert that these values are persisted.
|
|
||||||
h.validateXPath
|
|
||||||
(locator.xml
|
|
||||||
,"/solr/cores/core[@name='" + getCoreName() + "' and @instanceDir='${INSTDIR_TEST}']"
|
|
||||||
,"/solr/cores/core[@name='" + getCoreName() + "' and @dataDir='${DATA_TEST}']"
|
|
||||||
,"/solr/cores/core[@name='" + getCoreName() + "' and @schema='${SCHEMA_TEST}']"
|
|
||||||
,"/solr/cores/core[@name='" + getCoreName() + "' and @config='${CONFIG_TEST}']"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Now assert that certain values are properly dereferenced in the process of creating the core, see
|
// Now assert that certain values are properly dereferenced in the process of creating the core, see
|
||||||
// SOLR-4982.
|
// SOLR-4982.
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,8 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
|
||||||
solrHome = createSolrHome();
|
solrHome = createSolrHome();
|
||||||
createJetty(solrHome.getAbsolutePath(), null, null);
|
createJetty(solrHome.getAbsolutePath(), null, null);
|
||||||
String url = jetty.getBaseUrl().toString();
|
String url = jetty.getBaseUrl().toString();
|
||||||
collection1 = new HttpSolrClient(url);
|
|
||||||
|
collection1 = new HttpSolrClient(url + "/collection1");
|
||||||
collection2 = new HttpSolrClient(url + "/collection2");
|
collection2 = new HttpSolrClient(url + "/collection2");
|
||||||
|
|
||||||
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
|
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
|
||||||
|
@ -74,9 +75,16 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
|
||||||
shard2 = urlCollection2.replaceAll("https?://", "");
|
shard2 = urlCollection2.replaceAll("https?://", "");
|
||||||
|
|
||||||
//create second core
|
//create second core
|
||||||
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
|
HttpSolrClient nodeClient = new HttpSolrClient(url);
|
||||||
req.setCoreName("collection2");
|
try {
|
||||||
collection1.request(req);
|
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
|
||||||
|
req.setCoreName("collection2");
|
||||||
|
req.setConfigSet("collection1");
|
||||||
|
nodeClient.request(req);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
nodeClient.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
SolrInputDocument doc = new SolrInputDocument();
|
SolrInputDocument doc = new SolrInputDocument();
|
||||||
doc.setField("id", "1");
|
doc.setField("id", "1");
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.restlet.ext.servlet.ServerServlet;
|
import org.restlet.ext.servlet.ServerServlet;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
@ -42,11 +44,25 @@ abstract public class SolrRestletTestBase extends RestTestBase {
|
||||||
*/
|
*/
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
|
|
||||||
|
Path tempDir = createTempDir();
|
||||||
|
Path coresDir = tempDir.resolve("cores");
|
||||||
|
|
||||||
|
System.setProperty("coreRootDirectory", coresDir.toString());
|
||||||
|
System.setProperty("configSetBaseDir", TEST_HOME());
|
||||||
|
|
||||||
final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
|
final SortedMap<ServletHolder,String> extraServlets = new TreeMap<>();
|
||||||
final ServletHolder solrSchemaRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
|
final ServletHolder solrSchemaRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
|
||||||
solrSchemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
|
solrSchemaRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
|
||||||
extraServlets.put(solrSchemaRestApi, "/schema/*"); // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'
|
extraServlets.put(solrSchemaRestApi, "/schema/*"); // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("name", DEFAULT_TEST_CORENAME);
|
||||||
|
props.setProperty("config", "solrconfig.xml");
|
||||||
|
props.setProperty("schema", "schema-rest.xml");
|
||||||
|
props.setProperty("configSet", "collection1");
|
||||||
|
|
||||||
|
writeCoreProperties(coresDir.resolve("core"), props, "SolrRestletTestBase");
|
||||||
createJettyAndHarness(TEST_HOME(), "solrconfig.xml", "schema-rest.xml", "/solr", true, extraServlets);
|
createJettyAndHarness(TEST_HOME(), "solrconfig.xml", "schema-rest.xml", "/solr", true, extraServlets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,6 @@ package org.apache.solr.rest.schema;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.util.RestTestBase;
|
import org.apache.solr.util.RestTestBase;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
@ -29,6 +24,11 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.restlet.ext.servlet.ServerServlet;
|
import org.restlet.ext.servlet.ServerServlet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TestManagedSchemaDynamicFieldResource extends RestTestBase {
|
public class TestManagedSchemaDynamicFieldResource extends RestTestBase {
|
||||||
|
|
||||||
private static File tmpSolrHome;
|
private static File tmpSolrHome;
|
||||||
|
|
|
@ -16,11 +16,6 @@ package org.apache.solr.rest.schema;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.util.RestTestBase;
|
import org.apache.solr.util.RestTestBase;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
@ -29,6 +24,11 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.restlet.ext.servlet.ServerServlet;
|
import org.restlet.ext.servlet.ServerServlet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class TestManagedSchemaFieldResource extends RestTestBase {
|
public class TestManagedSchemaFieldResource extends RestTestBase {
|
||||||
|
|
||||||
private static File tmpSolrHome;
|
private static File tmpSolrHome;
|
||||||
|
|
|
@ -17,10 +17,7 @@
|
||||||
|
|
||||||
package org.apache.solr.schema;
|
package org.apache.solr.schema;
|
||||||
|
|
||||||
import java.io.File;
|
import com.google.common.base.Charsets;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.solr.SolrJettyTestBase;
|
import org.apache.solr.SolrJettyTestBase;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
|
@ -34,6 +31,14 @@ import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
|
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
|
||||||
public class TestBinaryField extends SolrJettyTestBase {
|
public class TestBinaryField extends SolrJettyTestBase {
|
||||||
|
|
||||||
|
@ -60,6 +65,12 @@ public class TestBinaryField extends SolrJettyTestBase {
|
||||||
FileUtils.copyFile(new File(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
|
FileUtils.copyFile(new File(src_dir, "solrconfig.snippet.randomindexconfig.xml"),
|
||||||
new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
|
new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
|
||||||
|
|
||||||
|
try (Writer w = new OutputStreamWriter(Files.newOutputStream(collDir.toPath().resolve("core.properties")), Charsets.UTF_8)) {
|
||||||
|
Properties coreProps = new Properties();
|
||||||
|
coreProps.put("name", "collection1");
|
||||||
|
coreProps.store(w, "");
|
||||||
|
}
|
||||||
|
|
||||||
createJetty(homeDir.getAbsolutePath(), null, null);
|
createJetty(homeDir.getAbsolutePath(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,8 @@ package org.apache.solr.update;
|
||||||
|
|
||||||
import org.apache.lucene.index.LogDocMergePolicy;
|
import org.apache.lucene.index.LogDocMergePolicy;
|
||||||
import org.apache.solr.BaseDistributedSearchTestCase;
|
import org.apache.solr.BaseDistributedSearchTestCase;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||||
|
@ -36,6 +36,7 @@ import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolr;
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.CoresLocator;
|
import org.apache.solr.core.CoresLocator;
|
||||||
|
import org.apache.solr.core.PluginInfo;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrEventListener;
|
import org.apache.solr.core.SolrEventListener;
|
||||||
import org.apache.solr.search.SolrIndexSearcher;
|
import org.apache.solr.search.SolrIndexSearcher;
|
||||||
|
@ -52,6 +53,7 @@ import org.xml.sax.SAXException;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -70,7 +72,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
||||||
private UpdateShardHandler updateShardHandler;
|
private UpdateShardHandler updateShardHandler;
|
||||||
|
|
||||||
public SolrCmdDistributorTest() throws ParserConfigurationException, IOException, SAXException {
|
public SolrCmdDistributorTest() throws ParserConfigurationException, IOException, SAXException {
|
||||||
updateShardHandler = new UpdateShardHandler(new ConfigSolr() {
|
updateShardHandler = new UpdateShardHandler(new ConfigSolr(null, null) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoresLocator getCoresLocator() {
|
public CoresLocator getCoresLocator() {
|
||||||
|
@ -78,14 +80,15 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getShardHandlerFactoryConfigPath() {
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPersistent() {
|
protected String getProperty(CfgProp key) {
|
||||||
return false;
|
return null;
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
fixShardCount = true;
|
fixShardCount = true;
|
||||||
shardCount = 4;
|
shardCount = 4;
|
||||||
|
@ -105,6 +108,10 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
||||||
// we don't get helpful override behavior due to the method being static
|
// we don't get helpful override behavior due to the method being static
|
||||||
@Override
|
@Override
|
||||||
protected void createServers(int numShards) throws Exception {
|
protected void createServers(int numShards) throws Exception {
|
||||||
|
|
||||||
|
System.setProperty("configSetBaseDir", TEST_HOME());
|
||||||
|
System.setProperty("coreRootDirectory", testDir.toPath().resolve("control").toString());
|
||||||
|
writeCoreProperties(testDir.toPath().resolve("control/cores"), DEFAULT_TEST_CORENAME);
|
||||||
controlJetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());
|
controlJetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());
|
||||||
|
|
||||||
controlClient = createNewSolrClient(controlJetty.getLocalPort());
|
controlClient = createNewSolrClient(controlJetty.getLocalPort());
|
||||||
|
@ -113,6 +120,10 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < numShards; i++) {
|
for (int i = 0; i < numShards; i++) {
|
||||||
if (sb.length() > 0) sb.append(',');
|
if (sb.length() > 0) sb.append(',');
|
||||||
|
String shardname = "shard" + i;
|
||||||
|
Path coresPath = testDir.toPath().resolve(shardname).resolve("cores");
|
||||||
|
writeCoreProperties(coresPath, DEFAULT_TEST_CORENAME);
|
||||||
|
System.setProperty("coreRootDirectory", testDir.toPath().resolve(shardname).toString());
|
||||||
JettySolrRunner j = createJetty(new File(getSolrHome()),
|
JettySolrRunner j = createJetty(new File(getSolrHome()),
|
||||||
testDir + "/shard" + i + "/data", null, getSolrConfigFile(),
|
testDir + "/shard" + i + "/data", null, getSolrConfigFile(),
|
||||||
getSchemaFile());
|
getSchemaFile());
|
||||||
|
|
|
@ -19,25 +19,30 @@ package org.apache.solr.util;
|
||||||
|
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolr;
|
||||||
import org.apache.solr.core.CoresLocator;
|
import org.apache.solr.core.CoresLocator;
|
||||||
|
import org.apache.solr.core.PluginInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MockConfigSolr extends ConfigSolr {
|
public class MockConfigSolr extends ConfigSolr {
|
||||||
|
|
||||||
|
public MockConfigSolr() {
|
||||||
|
super(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoresLocator getCoresLocator() {
|
public CoresLocator getCoresLocator() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getShardHandlerFactoryConfigPath() {
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPersistent() {
|
protected String getProperty(CfgProp key) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,2 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<solr sharedLib="lib" persistent="true">
|
<solr></solr>
|
||||||
<cores adminPath="/admin/cores" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
|
|
||||||
<core default="true" instanceDir="db" name="db"/>
|
|
||||||
<core default="false" instanceDir="rss" name="rss"/>
|
|
||||||
<core default="false" instanceDir="mail" name="mail"/>
|
|
||||||
<core default="false" instanceDir="tika" name="tika"/>
|
|
||||||
<core default="false" instanceDir="solr" name="solr"/>
|
|
||||||
</cores>
|
|
||||||
</solr>
|
|
||||||
|
|
|
@ -16,25 +16,7 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!--
|
<solr>
|
||||||
All (relative) paths are relative to the installation path
|
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
|
||||||
-->
|
|
||||||
<solr persistent="false">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
adminPath: RequestHandler path to manage cores.
|
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
|
|
||||||
<core name="core0" instanceDir="core0" />
|
|
||||||
<core name="core1" instanceDir="core1" />
|
|
||||||
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
|
||||||
<str name="urlScheme">${urlScheme:}</str>
|
|
||||||
</shardHandlerFactory>
|
|
||||||
</cores>
|
|
||||||
|
|
||||||
</solr>
|
</solr>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
configSet=shared
|
|
@ -0,0 +1,8 @@
|
||||||
|
name=core0
|
||||||
|
dataDir=${dataDir1}
|
||||||
|
collection=${collection:acollection}
|
||||||
|
version=3.5
|
||||||
|
l10n=EN
|
||||||
|
ctlField=core0
|
||||||
|
comment=This is a sample with a sys prop ${sysprop:default}
|
||||||
|
configSet=shared
|
|
@ -0,0 +1,6 @@
|
||||||
|
dataDir=${dataDir2}
|
||||||
|
version=2.4
|
||||||
|
l10n=FR
|
||||||
|
ctlField=core1
|
||||||
|
comment=Ceci est un exemple
|
||||||
|
configSet=shared
|
|
@ -16,20 +16,45 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<solr>
|
||||||
|
|
||||||
|
<str name="shareSchema">${shareSchema:false}</str>
|
||||||
|
<str name="configSetBaseDir">${configSetBaseDir:../configsets}</str>
|
||||||
|
<str name="coreRootDirectory">${coreRootDirectory:.}</str>
|
||||||
|
|
||||||
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
|
<int name="socketTimeout">${socketTimeout:90000}</int>
|
||||||
|
<int name="connTimeout">${connTimeout:15000}</int>
|
||||||
|
</shardHandlerFactory>
|
||||||
|
|
||||||
|
<solrcloud>
|
||||||
|
<str name="host">127.0.0.1</str>
|
||||||
|
<int name="hostPort">${hostPort:8983}</int>
|
||||||
|
<str name="hostContext">${hostContext:solr}</str>
|
||||||
|
<int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>
|
||||||
|
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
|
||||||
|
<int name="leaderVoteWait">0</int>
|
||||||
|
<int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>
|
||||||
|
<int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>
|
||||||
|
</solrcloud>
|
||||||
|
|
||||||
|
</solr>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
All (relative) paths are relative to the installation path
|
All (relative) paths are relative to the installation path
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
persistent: Save changes made via the API to this file
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
sharedLib: path to a lib directory that will be shared across all cores
|
||||||
-->
|
|
||||||
<solr persistent="false">
|
<solr persistent="false">
|
||||||
<property name="version" value="1.3"/>
|
<property name="version" value="1.3"/>
|
||||||
<property name="lang" value="english, french"/>
|
<property name="lang" value="english, french"/>
|
||||||
|
|
||||||
<!--
|
|
||||||
adminPath: RequestHandler path to manage cores.
|
adminPath: RequestHandler path to manage cores.
|
||||||
If 'null' (or absent), cores will not be manageable via REST
|
If 'null' (or absent), cores will not be manageable via REST
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="core0" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="${hostContext:solr}" zkClientTimeout="8000" genericCoreNodeNames="${genericCoreNodeNames:true}" configSetBaseDir="${configSetBase:configsets}">
|
<cores adminPath="/admin/cores" defaultCoreName="core0" host="127.0.0.1" hostPort="${hostPort:8983}" hostContext="${hostContext:solr}" zkClientTimeout="8000" genericCoreNodeNames="${genericCoreNodeNames:true}" configSetBaseDir="${configSetBase:configsets}">
|
||||||
<core name="collection1" instanceDir="." />
|
<core name="collection1" instanceDir="." />
|
||||||
<core name="core0" instanceDir="${theInstanceDir:./}" dataDir="${dataDir1}" collection="${collection:acollection}">
|
<core name="core0" instanceDir="${theInstanceDir:./}" dataDir="${dataDir1}" collection="${collection:acollection}">
|
||||||
|
@ -46,3 +71,4 @@
|
||||||
</core>
|
</core>
|
||||||
</cores>
|
</cores>
|
||||||
</solr>
|
</solr>
|
||||||
|
-->
|
||||||
|
|
|
@ -16,24 +16,52 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
All (relative) paths are relative to the installation path
|
All (relative) paths are relative to the installation path
|
||||||
|
|
||||||
persistent: Save changes made via the API to this file
|
|
||||||
sharedLib: path to a lib directory that will be shared across all cores
|
|
||||||
-->
|
-->
|
||||||
|
<solr>
|
||||||
|
|
||||||
|
<str name="shareSchema">${shareSchema:false}</str>
|
||||||
|
<str name="configSetBaseDir">${configSetBaseDir:configsets}</str>
|
||||||
|
<str name="coreRootDirectory">${coreRootDirectory:.}</str>
|
||||||
|
|
||||||
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
|
<int name="socketTimeout">${socketTimeout:90000}</int>
|
||||||
|
<int name="connTimeout">${connTimeout:15000}</int>
|
||||||
|
</shardHandlerFactory>
|
||||||
|
|
||||||
|
<solrcloud>
|
||||||
|
<str name="host">127.0.0.1</str>
|
||||||
|
<int name="hostPort">${hostPort:8983}</int>
|
||||||
|
<str name="hostContext">${hostContext:solr}</str>
|
||||||
|
<int name="zkClientTimeout">${solr.zkclienttimeout:30000}</int>
|
||||||
|
<bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
|
||||||
|
<int name="leaderVoteWait">0</int>
|
||||||
|
<int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:45000}</int>
|
||||||
|
<int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:340000}</int>
|
||||||
|
</solrcloud>
|
||||||
|
|
||||||
|
</solr>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
All (relative) paths are relative to the installation path
|
||||||
|
|
||||||
|
persistent: Save changes made via the API to this file
|
||||||
|
sharedLib: path to a lib directory that will be shared across all cores
|
||||||
|
|
||||||
<solr persistent="false">
|
<solr persistent="false">
|
||||||
|
|
||||||
<!--
|
|
||||||
adminPath: RequestHandler path to manage cores.
|
|
||||||
If 'null' (or absent), cores will not be manageable via request handler
|
|
||||||
-->
|
|
||||||
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
<cores adminPath="/admin/cores" defaultCoreName="collection1" host="127.0.0.1" hostPort="${hostPort:8983}"
|
||||||
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" shareSchema="${shareSchema:false}"
|
hostContext="${hostContext:solr}" zkClientTimeout="${solr.zkclienttimeout:30000}" shareSchema="${shareSchema:false}"
|
||||||
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
genericCoreNodeNames="${genericCoreNodeNames:true}" leaderVoteWait="0"
|
||||||
distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:340000}">
|
distribUpdateConnTimeout="${distribUpdateConnTimeout:45000}" distribUpdateSoTimeout="${distribUpdateSoTimeout:340000}">
|
||||||
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" />
|
<core name="collection1" instanceDir="collection1" shard="${shard:}" collection="${collection:collection1}" />
|
||||||
<!--config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"/-->
|
|
||||||
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
<shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">
|
||||||
<str name="urlScheme">${urlScheme:}</str>
|
<str name="urlScheme">${urlScheme:}</str>
|
||||||
<int name="socketTimeout">${socketTimeout:90000}</int>
|
<int name="socketTimeout">${socketTimeout:90000}</int>
|
||||||
|
@ -41,3 +69,4 @@
|
||||||
</shardHandlerFactory>
|
</shardHandlerFactory>
|
||||||
</cores>
|
</cores>
|
||||||
</solr>
|
</solr>
|
||||||
|
-->
|
|
@ -17,15 +17,8 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj;
|
package org.apache.solr.client.solrj;
|
||||||
|
|
||||||
import java.io.File;
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
@ -46,7 +39,13 @@ import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for LBHttpSolrClient
|
* Test for LBHttpSolrClient
|
||||||
|
@ -268,7 +267,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return buildUrl(port, "/solr");
|
return buildUrl(port, "/solr/collection1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSchemaFile() {
|
public String getSchemaFile() {
|
||||||
|
@ -303,6 +302,7 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
|
||||||
FileUtils.copyFile(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);
|
FileUtils.copyFile(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);
|
||||||
f = new File(confDir, "schema.xml");
|
f = new File(confDir, "schema.xml");
|
||||||
FileUtils.copyFile(SolrTestCaseJ4.getFile(getSchemaFile()), f);
|
FileUtils.copyFile(SolrTestCaseJ4.getFile(getSchemaFile()), f);
|
||||||
|
Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
|
|
|
@ -19,16 +19,14 @@ package org.apache.solr.client.solrj.embedded;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
|
||||||
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
import org.apache.solr.client.solrj.request.CoreAdminRequest;
|
||||||
import org.apache.solr.client.solrj.request.QueryRequest;
|
import org.apache.solr.client.solrj.request.QueryRequest;
|
||||||
import org.apache.solr.client.solrj.request.UpdateRequest;
|
import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||||
import org.apache.solr.client.solrj.response.CoreAdminResponse;
|
import org.apache.solr.client.solrj.response.CoreAdminResponse;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.apache.solr.core.SolrXMLCoresLocator;
|
|
||||||
import org.apache.solr.util.TestHarness;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.RuleChain;
|
import org.junit.rules.RuleChain;
|
||||||
|
@ -67,9 +65,6 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
|
|
||||||
SolrXMLCoresLocator.NonPersistingLocator locator
|
|
||||||
= (SolrXMLCoresLocator.NonPersistingLocator) cores.getCoresLocator();
|
|
||||||
|
|
||||||
UpdateRequest up = new UpdateRequest();
|
UpdateRequest up = new UpdateRequest();
|
||||||
up.setAction(ACTION.COMMIT, true, true);
|
up.setAction(ACTION.COMMIT, true, true);
|
||||||
up.deleteByQuery("*:*");
|
up.deleteByQuery("*:*");
|
||||||
|
@ -139,33 +134,6 @@ public class TestSolrProperties extends AbstractEmbeddedSolrServerTestCase {
|
||||||
long after = mcr.getStartTime(name).getTime();
|
long after = mcr.getStartTime(name).getTime();
|
||||||
assertTrue("should have more recent time: " + after + "," + before, after > before);
|
assertTrue("should have more recent time: " + after + "," + before, after > before);
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr/cores[@defaultCoreName='core0']",
|
|
||||||
"/solr/cores[@host='127.0.0.1']",
|
|
||||||
"/solr/cores[@hostPort='${hostPort:8983}']",
|
|
||||||
"/solr/cores[@zkClientTimeout='8000']",
|
|
||||||
"/solr/cores[@hostContext='${hostContext:solr}']",
|
|
||||||
"/solr/cores[@genericCoreNodeNames='${genericCoreNodeNames:true}']"
|
|
||||||
);
|
|
||||||
|
|
||||||
CoreAdminRequest.renameCore(name, "renamed_core", coreadmin);
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml,
|
|
||||||
"/solr/cores/core[@name='renamed_core']",
|
|
||||||
"/solr/cores/core[@instanceDir='${theInstanceDir:./}']",
|
|
||||||
"/solr/cores/core[@collection='${collection:acollection}']"
|
|
||||||
);
|
|
||||||
|
|
||||||
coreadmin = getRenamedSolrAdmin();
|
|
||||||
File dataDir = new File(tempDir,"data3");
|
|
||||||
File tlogDir = new File(tempDir,"tlog3");
|
|
||||||
|
|
||||||
CoreAdminRequest.createCore("newCore", SOLR_HOME.getAbsolutePath(),
|
|
||||||
coreadmin, null, null, dataDir.getAbsolutePath(),
|
|
||||||
tlogDir.getAbsolutePath());
|
|
||||||
|
|
||||||
TestHarness.validateXPath(locator.xml, "/solr/cores/core[@name='collection1' and @instanceDir='.']");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
|
||||||
req.setInstanceDir(newCoreInstanceDir.getAbsolutePath() + File.separator + "newcore");
|
req.setInstanceDir(newCoreInstanceDir.getAbsolutePath() + File.separator + "newcore");
|
||||||
req.setDataDir(dataDir.getAbsolutePath());
|
req.setDataDir(dataDir.getAbsolutePath());
|
||||||
req.setUlogDir(new File(dataDir, "ulog").getAbsolutePath());
|
req.setUlogDir(new File(dataDir, "ulog").getAbsolutePath());
|
||||||
|
req.setConfigSet("shared");
|
||||||
|
|
||||||
// These should be the inverse of defaults.
|
// These should be the inverse of defaults.
|
||||||
req.setIsLoadOnStartup(false);
|
req.setIsLoadOnStartup(false);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -53,6 +54,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
@ -285,25 +287,33 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JettySolrRunner createControlJetty() throws Exception {
|
protected JettySolrRunner createControlJetty() throws Exception {
|
||||||
|
writeCoreProperties(testDir.toPath().resolve("control/cores"), DEFAULT_TEST_CORENAME);
|
||||||
|
System.setProperty("coreRootDirectory", testDir.toPath().resolve("control").toString());
|
||||||
JettySolrRunner jetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());
|
JettySolrRunner jetty = createJetty(new File(getSolrHome()), testDir + "/control/data", null, getSolrConfigFile(), getSchemaFile());
|
||||||
return jetty;
|
return jetty;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createServers(int numShards) throws Exception {
|
|
||||||
controlJetty = createControlJetty();
|
|
||||||
|
|
||||||
|
protected void createServers(int numShards) throws Exception {
|
||||||
|
|
||||||
|
System.setProperty("configSetBaseDir", getSolrHome());
|
||||||
|
|
||||||
|
controlJetty = createControlJetty();
|
||||||
controlClient = createNewSolrClient(controlJetty.getLocalPort());
|
controlClient = createNewSolrClient(controlJetty.getLocalPort());
|
||||||
|
|
||||||
shardsArr = new String[numShards];
|
shardsArr = new String[numShards];
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < numShards; i++) {
|
for (int i = 0; i < numShards; i++) {
|
||||||
if (sb.length() > 0) sb.append(',');
|
if (sb.length() > 0) sb.append(',');
|
||||||
|
String shardname = "shard" + i;
|
||||||
|
Path coresPath = testDir.toPath().resolve(shardname).resolve("cores");
|
||||||
|
writeCoreProperties(coresPath, DEFAULT_TEST_CORENAME);
|
||||||
|
System.setProperty("coreRootDirectory", testDir.toPath().resolve(shardname).toString());
|
||||||
JettySolrRunner j = createJetty(new File(getSolrHome()),
|
JettySolrRunner j = createJetty(new File(getSolrHome()),
|
||||||
testDir + "/shard" + i + "/data", null, getSolrConfigFile(),
|
testDir + "/shard" + i + "/data", null, getSolrConfigFile(),
|
||||||
getSchemaFile());
|
getSchemaFile());
|
||||||
jettys.add(j);
|
jettys.add(j);
|
||||||
clients.add(createNewSolrClient(j.getLocalPort()));
|
clients.add(createNewSolrClient(j.getLocalPort()));
|
||||||
String shardStr = buildUrl(j.getLocalPort());
|
String shardStr = buildUrl(j.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME;
|
||||||
shardsArr[i] = shardStr;
|
shardsArr[i] = shardStr;
|
||||||
sb.append(shardStr);
|
sb.append(shardStr);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +399,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
|
||||||
protected SolrClient createNewSolrClient(int port) {
|
protected SolrClient createNewSolrClient(int port) {
|
||||||
try {
|
try {
|
||||||
// setup the client...
|
// setup the client...
|
||||||
HttpSolrClient client = new HttpSolrClient(buildUrl(port));
|
HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/" + DEFAULT_TEST_CORENAME);
|
||||||
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
||||||
client.setSoTimeout(90000);
|
client.setSoTimeout(90000);
|
||||||
client.setDefaultMaxConnectionsPerHost(100);
|
client.setDefaultMaxConnectionsPerHost(100);
|
||||||
|
@ -931,6 +941,20 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
|
||||||
if (solrxml != null) {
|
if (solrxml != null) {
|
||||||
FileUtils.copyFile(new File(getSolrHome(), solrxml), new File(jettyHome, "solr.xml"));
|
FileUtils.copyFile(new File(getSolrHome(), solrxml), new File(jettyHome, "solr.xml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Properties coreProperties = new Properties();
|
||||||
|
coreProperties.setProperty("name", "collection1");
|
||||||
|
coreProperties.setProperty("shard", "${shard:}");
|
||||||
|
coreProperties.setProperty("collection", "${collection:collection1}");
|
||||||
|
coreProperties.setProperty("config", "${solrconfig:solrconfig.xml}");
|
||||||
|
coreProperties.setProperty("schema", "${schema:schema.xml}");
|
||||||
|
coreProperties.setProperty("coreNodeName", "${coreNodeName:}");
|
||||||
|
|
||||||
|
writeCoreProperties(jettyHome.toPath().resolve("cores/collection1"), coreProperties, "collection1");
|
||||||
|
|
||||||
|
// <core name="collection1" instanceDir="collection1" shard="${shard:}"
|
||||||
|
// collection="${collection:collection1}" config="${solrconfig:solrconfig.xml}" schema="${schema:schema.xml}"
|
||||||
|
//coreNodeName="${coreNodeName:}"/>
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,6 @@ package org.apache.solr;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
|
@ -35,6 +30,12 @@ import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
|
||||||
|
|
||||||
abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,19 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
||||||
// creates the data dir
|
// creates the data dir
|
||||||
initCore(null, null, solrHome);
|
initCore(null, null, solrHome);
|
||||||
|
|
||||||
|
Path coresDir = createTempDir().resolve("cores");
|
||||||
|
|
||||||
|
System.setProperty("coreRootDirectory", coresDir.toString());
|
||||||
|
System.setProperty("configSetBaseDir", solrHome);
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("name", DEFAULT_TEST_CORENAME);
|
||||||
|
props.setProperty("configSet", "collection1");
|
||||||
|
props.setProperty("config", "${solrconfig:solrconfig.xml}");
|
||||||
|
props.setProperty("schema", "${schema:schema.xml}");
|
||||||
|
|
||||||
|
writeCoreProperties(coresDir.resolve("core"), props, "RestTestBase");
|
||||||
|
|
||||||
ignoreException("maxWarmingSearchers");
|
ignoreException("maxWarmingSearchers");
|
||||||
|
|
||||||
context = context==null ? "/solr" : context;
|
context = context==null ? "/solr" : context;
|
||||||
|
@ -120,7 +134,7 @@ abstract public class SolrJettyTestBase extends SolrTestCaseJ4
|
||||||
throw new RuntimeException( ex );
|
throw new RuntimeException( ex );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new EmbeddedSolrServer( h.getCoreContainer(), "" );
|
return new EmbeddedSolrServer( h.getCoreContainer(), "collection1" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,40 +17,9 @@
|
||||||
|
|
||||||
package org.apache.solr;
|
package org.apache.solr;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
||||||
|
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
||||||
import java.io.File;
|
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.logging.ConsoleHandler;
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.Charsets;
|
import org.apache.commons.codec.Charsets;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.lucene.analysis.MockAnalyzer;
|
import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
|
@ -77,7 +46,6 @@ import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.ObjectReleaseTracker;
|
import org.apache.solr.common.util.ObjectReleaseTracker;
|
||||||
import org.apache.solr.common.util.XML;
|
import org.apache.solr.common.util.XML;
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolr;
|
||||||
import org.apache.solr.core.ConfigSolrXmlOld;
|
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
import org.apache.solr.core.CoreDescriptor;
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
import org.apache.solr.core.SolrConfig;
|
import org.apache.solr.core.SolrConfig;
|
||||||
|
@ -109,9 +77,42 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.RandomizedContext;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
|
import java.io.File;
|
||||||
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Inherited;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.Handler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
|
* A junit4 Solr test harness that extends LuceneTestCaseJ4. To change which core is used when loading the schema and solrconfig.xml, simply
|
||||||
|
@ -125,9 +126,32 @@ import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
|
||||||
})
|
})
|
||||||
@SuppressSysoutChecks(bugUrl = "Solr dumps tons of logs to console.")
|
@SuppressSysoutChecks(bugUrl = "Solr dumps tons of logs to console.")
|
||||||
public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
private static String coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
|
|
||||||
|
public static final String DEFAULT_TEST_CORENAME = "collection1";
|
||||||
|
|
||||||
|
private static String coreName = DEFAULT_TEST_CORENAME;
|
||||||
|
|
||||||
public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
|
public static int DEFAULT_CONNECTION_TIMEOUT = 60000; // default socket connection timeout in ms
|
||||||
|
|
||||||
|
protected void writeCoreProperties(Path coreDirectory, String corename) throws IOException {
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("name", corename);
|
||||||
|
props.setProperty("configSet", "collection1");
|
||||||
|
props.setProperty("config", "${solrconfig:solrconfig.xml}");
|
||||||
|
props.setProperty("schema", "${schema:schema.xml}");
|
||||||
|
|
||||||
|
writeCoreProperties(coreDirectory, props, this.getTestName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeCoreProperties(Path coreDirectory, Properties properties, String testname) throws IOException {
|
||||||
|
log.info("Writing core.properties file to {}", coreDirectory);
|
||||||
|
Files.createDirectories(coreDirectory);
|
||||||
|
try (Writer writer =
|
||||||
|
new OutputStreamWriter(Files.newOutputStream(coreDirectory.resolve("core.properties")), Charset.forName("UTF-8"))) {
|
||||||
|
properties.store(writer, testname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation for test classes that want to disable SSL
|
* Annotation for test classes that want to disable SSL
|
||||||
*/
|
*/
|
||||||
|
@ -188,7 +212,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
endTrackingSearchers();
|
endTrackingSearchers();
|
||||||
assertTrue("Some resources were not closed, shutdown, or released.", ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
assertTrue("Some resources were not closed, shutdown, or released.", ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||||
resetFactory();
|
resetFactory();
|
||||||
coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
|
coreName = DEFAULT_TEST_CORENAME;
|
||||||
} finally {
|
} finally {
|
||||||
initCoreDataDir = null;
|
initCoreDataDir = null;
|
||||||
System.clearProperty("zookeeper.forceSync");
|
System.clearProperty("zookeeper.forceSync");
|
||||||
|
@ -290,7 +314,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
FileUtils.write(tmpFile, xmlStr, IOUtils.UTF_8);
|
FileUtils.write(tmpFile, xmlStr, IOUtils.UTF_8);
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(solrHome.getAbsolutePath());
|
SolrResourceLoader loader = new SolrResourceLoader(solrHome.getAbsolutePath());
|
||||||
h = new TestHarness(loader, ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));
|
h = new TestHarness(ConfigSolr.fromFile(loader, new File(solrHome, "solr.xml")));
|
||||||
lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
|
lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,6 +596,19 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
return h.getCoreContainer();
|
return h.getCoreContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CoreContainer createCoreContainer(ConfigSolr config) {
|
||||||
|
testSolrHome = config.getSolrResourceLoader().getInstanceDir();
|
||||||
|
h = new TestHarness(config);
|
||||||
|
lrf = h.getRequestFactory("standard", 0, 20, CommonParams.VERSION, "2.2");
|
||||||
|
return h.getCoreContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) {
|
||||||
|
CoreContainer cc = createCoreContainer(new TestHarness.TestConfigSolr(coreName, dataDir, solrConfig, schema));
|
||||||
|
h.coreName = coreName;
|
||||||
|
return cc;
|
||||||
|
}
|
||||||
|
|
||||||
public static CoreContainer createDefaultCoreContainer(String solrHome) {
|
public static CoreContainer createDefaultCoreContainer(String solrHome) {
|
||||||
testSolrHome = checkNotNull(solrHome);
|
testSolrHome = checkNotNull(solrHome);
|
||||||
h = new TestHarness("collection1", initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml");
|
h = new TestHarness("collection1", initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml");
|
||||||
|
@ -1780,7 +1817,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
copyMinConf(dstRoot, null);
|
copyMinConf(dstRoot, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a minimal conf dir. Optionally adding in a core.properties file from the string passed in
|
// Creates a minimal conf dir, adding in a core.properties file from the string passed in
|
||||||
// the string to write to the core.properties file may be null in which case nothing is done with it.
|
// the string to write to the core.properties file may be null in which case nothing is done with it.
|
||||||
// propertiesContent may be an empty string, which will actually work.
|
// propertiesContent may be an empty string, which will actually work.
|
||||||
public static void copyMinConf(File dstRoot, String propertiesContent) throws IOException {
|
public static void copyMinConf(File dstRoot, String propertiesContent) throws IOException {
|
||||||
|
@ -1789,6 +1826,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
||||||
if (! dstRoot.exists()) {
|
if (! dstRoot.exists()) {
|
||||||
assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());
|
assertTrue("Failed to make subdirectory ", dstRoot.mkdirs());
|
||||||
}
|
}
|
||||||
|
Files.createFile(dstRoot.toPath().resolve("core.properties"));
|
||||||
if (propertiesContent != null) {
|
if (propertiesContent != null) {
|
||||||
FileUtils.writeStringToFile(new File(dstRoot, "core.properties"), propertiesContent, Charsets.UTF_8.toString());
|
FileUtils.writeStringToFile(new File(dstRoot, "core.properties"), propertiesContent, Charsets.UTF_8.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,9 +281,10 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
File controlJettyDir = createTempDir().toFile();
|
File controlJettyDir = createTempDir("control").toFile();
|
||||||
setupJettySolrHome(controlJettyDir);
|
setupJettySolrHome(controlJettyDir);
|
||||||
|
|
||||||
|
System.setProperty("coreRootDirectory", controlJettyDir.toPath().resolve("cores").toString());
|
||||||
controlJetty = createJetty(controlJettyDir, useJettyDataDir ? getDataDir(testDir
|
controlJetty = createJetty(controlJettyDir, useJettyDataDir ? getDataDir(testDir
|
||||||
+ "/control/data") : null); // don't pass shard name... let it default to
|
+ "/control/data") : null); // don't pass shard name... let it default to
|
||||||
// "shard1"
|
// "shard1"
|
||||||
|
@ -393,11 +394,12 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
|
||||||
if (sb.length() > 0) sb.append(',');
|
if (sb.length() > 0) sb.append(',');
|
||||||
int cnt = this.jettyIntCntr.incrementAndGet();
|
int cnt = this.jettyIntCntr.incrementAndGet();
|
||||||
|
|
||||||
File jettyDir = createTempDir().toFile();
|
File jettyDir = createTempDir("shard-" + i).toFile();
|
||||||
|
|
||||||
jettyDir.mkdirs();
|
jettyDir.mkdirs();
|
||||||
setupJettySolrHome(jettyDir);
|
setupJettySolrHome(jettyDir);
|
||||||
log.info("create jetty " + i);
|
log.info("create jetty " + i);
|
||||||
|
System.setProperty("coreRootDirectory", jettyDir.toPath().resolve("cores").toString());
|
||||||
JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"
|
JettySolrRunner j = createJetty(jettyDir, useJettyDataDir ? getDataDir(testDir + "/jetty"
|
||||||
+ cnt) : null, null, "solrconfig.xml", null);
|
+ cnt) : null, null, "solrconfig.xml", null);
|
||||||
jettys.add(j);
|
jettys.add(j);
|
||||||
|
|
|
@ -17,10 +17,6 @@ package org.apache.solr.cloud;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.cloud.SolrZkClient;
|
import org.apache.solr.common.cloud.SolrZkClient;
|
||||||
import org.apache.solr.common.cloud.ZkNodeProps;
|
import org.apache.solr.common.cloud.ZkNodeProps;
|
||||||
|
@ -31,6 +27,10 @@ import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base test class for ZooKeeper tests.
|
* Base test class for ZooKeeper tests.
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +74,7 @@ public abstract class AbstractZkTestCase extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), SOLRHOME,
|
buildZooKeeper(zkServer.getZkHost(), zkServer.getZkAddress(), SOLRHOME,
|
||||||
"solrconfig.xml", "schema.xml");
|
"solrconfig.xml", "schema.xml");
|
||||||
|
|
||||||
initCore("solrconfig.xml", "schema.xml");
|
initCore("solrconfig.xml", "schema.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.apache.solr.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
|
import org.apache.solr.core.CoresLocator;
|
||||||
|
|
||||||
|
public abstract class ReadOnlyCoresLocator implements CoresLocator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void persist(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(CoreContainer cc, CoreDescriptor... coreDescriptors) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rename(CoreContainer cc, CoreDescriptor oldCD, CoreDescriptor newCD) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void swap(CoreContainer cc, CoreDescriptor cd1, CoreDescriptor cd2) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,12 +16,6 @@ package org.apache.solr.util;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
|
|
||||||
import org.apache.solr.JSONTestUtil;
|
import org.apache.solr.JSONTestUtil;
|
||||||
import org.apache.solr.SolrJettyTestBase;
|
import org.apache.solr.SolrJettyTestBase;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
|
@ -29,11 +23,15 @@ import org.apache.solr.common.params.MultiMapSolrParams;
|
||||||
import org.apache.solr.common.util.StrUtils;
|
import org.apache.solr.common.util.StrUtils;
|
||||||
import org.apache.solr.servlet.SolrRequestParsers;
|
import org.apache.solr.servlet.SolrRequestParsers;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
|
||||||
abstract public class RestTestBase extends SolrJettyTestBase {
|
abstract public class RestTestBase extends SolrJettyTestBase {
|
||||||
private static final Logger log = LoggerFactory.getLogger(RestTestBase.class);
|
private static final Logger log = LoggerFactory.getLogger(RestTestBase.class);
|
||||||
|
@ -56,7 +54,7 @@ abstract public class RestTestBase extends SolrJettyTestBase {
|
||||||
restTestHarness = new RestTestHarness(new RESTfulServerProvider() {
|
restTestHarness = new RestTestHarness(new RESTfulServerProvider() {
|
||||||
@Override
|
@Override
|
||||||
public String getBaseURL() {
|
public String getBaseURL() {
|
||||||
return jetty.getBaseUrl().toString();
|
return jetty.getBaseUrl().toString() + "/" + DEFAULT_TEST_CORENAME;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,6 @@ package org.apache.solr.util;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.Closeable;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.methods.HttpDelete;
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
@ -37,6 +29,13 @@ import org.apache.http.util.EntityUtils;
|
||||||
import org.apache.solr.client.solrj.impl.HttpClientUtil;
|
import org.apache.solr.client.solrj.impl.HttpClientUtil;
|
||||||
import org.apache.solr.common.params.ModifiableSolrParams;
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
||||||
|
|
||||||
|
import javax.xml.xpath.XPathConstants;
|
||||||
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Facilitates testing Solr's REST API via a provided embedded Jetty
|
* Facilitates testing Solr's REST API via a provided embedded Jetty
|
||||||
*/
|
*/
|
||||||
|
@ -52,6 +51,10 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
|
||||||
public String getBaseURL() {
|
public String getBaseURL() {
|
||||||
return serverProvider.getBaseURL();
|
return serverProvider.getBaseURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAdminURL() {
|
||||||
|
return getBaseURL().replace("/collection1", "");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates an XML "query" response against an array of XPath test strings
|
* Validates an XML "query" response against an array of XPath test strings
|
||||||
|
@ -97,6 +100,10 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
|
||||||
return getResponse(new HttpGet(getBaseURL() + request));
|
return getResponse(new HttpGet(getBaseURL() + request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String adminQuery(String request) throws Exception {
|
||||||
|
return getResponse(new HttpGet(getAdminURL() + request));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a PUT request using a URL path (with no context path) + optional query params,
|
* Processes a PUT request using a URL path (with no context path) + optional query params,
|
||||||
* e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
|
* e.g. "/schema/fields/newfield", PUTs the given content, and returns the response content.
|
||||||
|
@ -152,17 +159,25 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String checkAdminResponseStatus(String xml, String code) throws Exception {
|
||||||
|
try {
|
||||||
|
String response = adminQuery(xml);
|
||||||
|
String valid = validateXPath(response, "//int[@name='status']="+code );
|
||||||
|
return (null == valid) ? null : response;
|
||||||
|
} catch (XPathExpressionException e) {
|
||||||
|
throw new RuntimeException("?!? static xpath has bug?", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Reloads the first core listed in the response to the core admin handler STATUS command
|
* Reloads the first core listed in the response to the core admin handler STATUS command
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void reload() throws Exception {
|
public void reload() throws Exception {
|
||||||
String coreName = (String)evaluateXPath
|
String coreName = (String)evaluateXPath
|
||||||
(query("/admin/cores?action=STATUS"),
|
(adminQuery("/admin/cores?action=STATUS"),
|
||||||
"//lst[@name='status']/lst[1]/str[@name='name']",
|
"//lst[@name='status']/lst[1]/str[@name='name']",
|
||||||
XPathConstants.STRING);
|
XPathConstants.STRING);
|
||||||
String xml = checkResponseStatus("/admin/cores?action=RELOAD&core=" + coreName, "0");
|
String xml = checkAdminResponseStatus("/admin/cores?action=RELOAD&core=" + coreName, "0");
|
||||||
if (null != xml) {
|
if (null != xml) {
|
||||||
throw new RuntimeException("RELOAD failed:\n" + xml);
|
throw new RuntimeException("RELOAD failed:\n" + xml);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,17 @@
|
||||||
|
|
||||||
package org.apache.solr.util;
|
package org.apache.solr.util;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
import org.apache.solr.common.util.NamedList.NamedListEntry;
|
||||||
import org.apache.solr.core.ConfigSolr;
|
import org.apache.solr.core.ConfigSolr;
|
||||||
import org.apache.solr.core.ConfigSolrXmlOld;
|
|
||||||
import org.apache.solr.core.CoreContainer;
|
import org.apache.solr.core.CoreContainer;
|
||||||
|
import org.apache.solr.core.CoreDescriptor;
|
||||||
|
import org.apache.solr.core.CoresLocator;
|
||||||
|
import org.apache.solr.core.PluginInfo;
|
||||||
import org.apache.solr.core.SolrConfig;
|
import org.apache.solr.core.SolrConfig;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrResourceLoader;
|
import org.apache.solr.core.SolrResourceLoader;
|
||||||
|
@ -42,6 +46,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +62,7 @@ import java.util.Map;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TestHarness extends BaseTestHarness {
|
public class TestHarness extends BaseTestHarness {
|
||||||
String coreName;
|
public String coreName;
|
||||||
protected volatile CoreContainer container;
|
protected volatile CoreContainer container;
|
||||||
public UpdateRequestHandler updater;
|
public UpdateRequestHandler updater;
|
||||||
|
|
||||||
|
@ -78,11 +83,10 @@ public class TestHarness extends BaseTestHarness {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SolrConfig object for the
|
* Creates a SolrConfig object for the default test core using {@link #createConfig(String,String,String)}
|
||||||
* {@link ConfigSolrXmlOld#DEFAULT_DEFAULT_CORE_NAME} core using {@link #createConfig(String,String,String)}
|
|
||||||
*/
|
*/
|
||||||
public static SolrConfig createConfig(String solrHome, String confFile) {
|
public static SolrConfig createConfig(String solrHome, String confFile) {
|
||||||
return createConfig(solrHome, ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME, confFile);
|
return createConfig(solrHome, SolrTestCaseJ4.DEFAULT_TEST_CORENAME, confFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +120,7 @@ public class TestHarness extends BaseTestHarness {
|
||||||
public TestHarness( String dataDirectory,
|
public TestHarness( String dataDirectory,
|
||||||
SolrConfig solrConfig,
|
SolrConfig solrConfig,
|
||||||
IndexSchema indexSchema) {
|
IndexSchema indexSchema) {
|
||||||
this(ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME, dataDirectory, solrConfig, indexSchema);
|
this(SolrTestCaseJ4.DEFAULT_TEST_CORENAME, dataDirectory, solrConfig, indexSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,21 +130,9 @@ public class TestHarness extends BaseTestHarness {
|
||||||
* @param indexSchema schema resource name
|
* @param indexSchema schema resource name
|
||||||
*/
|
*/
|
||||||
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
|
public TestHarness(String coreName, String dataDir, String solrConfig, String indexSchema) {
|
||||||
try {
|
this(new TestConfigSolr(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()),
|
||||||
if (coreName == null)
|
coreName, dataDir, solrConfig, indexSchema));
|
||||||
coreName = ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME;
|
this.coreName = (coreName == null) ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
|
||||||
this.coreName = coreName;
|
|
||||||
|
|
||||||
SolrResourceLoader loader = new SolrResourceLoader(SolrResourceLoader.locateSolrHome());
|
|
||||||
ConfigSolr config = getTestHarnessConfig(loader, coreName, dataDir, solrConfig, indexSchema);
|
|
||||||
container = new CoreContainer(loader, config);
|
|
||||||
container.load();
|
|
||||||
|
|
||||||
updater = new UpdateRequestHandler();
|
|
||||||
updater.init( null );
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
|
public TestHarness(String coreName, String dataDir, SolrConfig solrConfig, IndexSchema indexSchema) {
|
||||||
|
@ -162,38 +154,81 @@ public class TestHarness extends BaseTestHarness {
|
||||||
* @param solrXml the text of a solrxml
|
* @param solrXml the text of a solrxml
|
||||||
*/
|
*/
|
||||||
public TestHarness(SolrResourceLoader loader, String solrXml) {
|
public TestHarness(SolrResourceLoader loader, String solrXml) {
|
||||||
this(loader, ConfigSolr.fromString(loader, solrXml));
|
this(ConfigSolr.fromString(loader, solrXml));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a TestHarness using a specific resource loader and config
|
* Create a TestHarness using a specific config
|
||||||
* @param loader the SolrResourceLoader to use
|
|
||||||
* @param config the ConfigSolr to use
|
* @param config the ConfigSolr to use
|
||||||
*/
|
*/
|
||||||
public TestHarness(SolrResourceLoader loader, ConfigSolr config) {
|
public TestHarness(ConfigSolr config) {
|
||||||
container = new CoreContainer(loader, config);
|
container = new CoreContainer(config);
|
||||||
container.load();
|
container.load();
|
||||||
updater = new UpdateRequestHandler();
|
updater = new UpdateRequestHandler();
|
||||||
updater.init(null);
|
updater.init(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigSolr getTestHarnessConfig(SolrResourceLoader loader, String coreName, String dataDir,
|
public static class TestConfigSolr extends ConfigSolr {
|
||||||
String solrConfig, String schema) {
|
|
||||||
String solrxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
final CoresLocator locator;
|
||||||
+ "<solr persistent=\"false\">\n"
|
|
||||||
+ " <cores adminPath=\"/admin/cores\" defaultCoreName=\""
|
public TestConfigSolr(String coreName, String dataDir, String solrConfig, String schema) {
|
||||||
+ ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME
|
this(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()), coreName, dataDir, solrConfig, schema);
|
||||||
+ "\""
|
}
|
||||||
+ " host=\"${host:}\" hostPort=\"${hostPort:}\" hostContext=\"${hostContext:}\""
|
|
||||||
+ " distribUpdateSoTimeout=\"30000\""
|
public TestConfigSolr(SolrResourceLoader loader, String coreName, String dataDir, String solrConfig, String schema) {
|
||||||
+ " zkClientTimeout=\"${zkClientTimeout:30000}\" distribUpdateConnTimeout=\"30000\""
|
super(loader);
|
||||||
+ ">\n"
|
locator = new TestCoresLocator(coreName, dataDir, solrConfig, schema);
|
||||||
+ " <core name=\"" + coreName + "\" config=\"" + solrConfig
|
}
|
||||||
+ "\" schema=\"" + schema + "\" dataDir=\"" + dataDir
|
|
||||||
+ "\" transient=\"false\" loadOnStartup=\"true\""
|
@Override
|
||||||
+ " shard=\"${shard:shard1}\" collection=\"${collection:collection1}\" instanceDir=\"" + coreName + "/\" />\n"
|
public CoresLocator getCoresLocator() {
|
||||||
+ " </cores>\n" + "</solr>";
|
return locator;
|
||||||
return ConfigSolr.fromString(loader, solrxml);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluginInfo getShardHandlerFactoryPluginInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getProperty(CfgProp key) {
|
||||||
|
switch (key) {
|
||||||
|
case SOLR_HOST: return System.getProperty("host");
|
||||||
|
case SOLR_HOSTPORT: return System.getProperty("hostPort", "");
|
||||||
|
case SOLR_HOSTCONTEXT: return System.getProperty("hostContext", "");
|
||||||
|
case SOLR_DISTRIBUPDATESOTIMEOUT: return "30000";
|
||||||
|
case SOLR_ZKCLIENTTIMEOUT: return System.getProperty("zkClientTimeout", "30000");
|
||||||
|
case SOLR_DISTRIBUPDATECONNTIMEOUT: return "30000";
|
||||||
|
case SOLR_SHARESCHEMA: return System.getProperty("shareSchema", "false");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestCoresLocator extends ReadOnlyCoresLocator {
|
||||||
|
|
||||||
|
final String coreName;
|
||||||
|
final String dataDir;
|
||||||
|
final String solrConfig;
|
||||||
|
final String schema;
|
||||||
|
|
||||||
|
public TestCoresLocator(String coreName, String dataDir, String solrConfig, String schema) {
|
||||||
|
this.coreName = coreName == null ? SolrTestCaseJ4.DEFAULT_TEST_CORENAME : coreName;
|
||||||
|
this.dataDir = dataDir;
|
||||||
|
this.schema = schema;
|
||||||
|
this.solrConfig = solrConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CoreDescriptor> discover(CoreContainer cc) {
|
||||||
|
return ImmutableList.of(new CoreDescriptor(cc, coreName, coreName,
|
||||||
|
CoreDescriptor.CORE_DATADIR, dataDir,
|
||||||
|
CoreDescriptor.CORE_CONFIG, solrConfig,
|
||||||
|
CoreDescriptor.CORE_SCHEMA, schema,
|
||||||
|
CoreDescriptor.CORE_COLLECTION, System.getProperty("collection", "collection1"),
|
||||||
|
CoreDescriptor.CORE_SHARD, System.getProperty("shard", "shard1")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoreContainer getCoreContainer() {
|
public CoreContainer getCoreContainer() {
|
||||||
|
@ -289,7 +324,8 @@ public class TestHarness extends BaseTestHarness {
|
||||||
* @see LocalSolrQueryRequest
|
* @see LocalSolrQueryRequest
|
||||||
*/
|
*/
|
||||||
public String query(String handler, SolrQueryRequest req) throws Exception {
|
public String query(String handler, SolrQueryRequest req) throws Exception {
|
||||||
try (SolrCore core = getCoreInc()) {
|
try {
|
||||||
|
SolrCore core = req.getCore();
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||||
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
|
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
|
||||||
core.execute(core.getRequestHandler(handler),req,rsp);
|
core.execute(core.getRequestHandler(handler),req,rsp);
|
||||||
|
|
Loading…
Reference in New Issue