use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class SolrDispatchFilter method createCoreContainer.
/**
* Override this to change CoreContainer initialization
* @return a CoreContainer to hold this server's cores
*/
protected CoreContainer createCoreContainer(Path solrHome, Properties extraProperties) {
NodeConfig nodeConfig = loadNodeConfig(solrHome, extraProperties);
final CoreContainer coreContainer = new CoreContainer(nodeConfig, extraProperties, true);
coreContainer.load();
return coreContainer;
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class ClusterStateUpdateTest method testCoreRegistration.
@Test
public void testCoreRegistration() throws Exception {
System.setProperty("solrcloud.update.delay", "1");
Map<String, Object> props2 = new HashMap<>();
props2.put("configName", "conf1");
ZkNodeProps zkProps2 = new ZkNodeProps(props2);
SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(), AbstractZkTestCase.TIMEOUT);
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/testcore", Utils.toJSON(zkProps2), CreateMode.PERSISTENT, true);
zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/testcore/shards", CreateMode.PERSISTENT, true);
zkClient.close();
container1.create("testcore", ImmutableMap.of("dataDir", dataDir4.getAbsolutePath()));
ZkController zkController2 = container2.getZkController();
String host = zkController2.getHostName();
// slight pause - TODO: takes an oddly long amount of time to schedule tasks
// with almost no delay ...
ClusterState clusterState2 = null;
Map<String, Slice> slices = null;
for (int i = 75; i > 0; i--) {
clusterState2 = zkController2.getClusterState();
slices = clusterState2.getSlicesMap("testcore");
if (slices != null && slices.containsKey("shard1") && slices.get("shard1").getReplicasMap().size() > 0) {
break;
}
Thread.sleep(500);
}
assertNotNull(slices);
assertTrue(slices.containsKey("shard1"));
Slice slice = slices.get("shard1");
assertEquals("shard1", slice.getName());
Map<String, Replica> shards = slice.getReplicasMap();
assertEquals(1, shards.size());
Replica zkProps = shards.get(host + ":1661_solr_testcore");
assertNotNull(zkProps);
assertEquals(host + ":1661_solr", zkProps.getStr(ZkStateReader.NODE_NAME_PROP));
assertEquals("http://" + host + ":1661/solr", zkProps.getStr(ZkStateReader.BASE_URL_PROP));
Set<String> liveNodes = clusterState2.getLiveNodes();
assertNotNull(liveNodes);
assertEquals(3, liveNodes.size());
container3.shutdown();
// slight pause (15s timeout) for watch to trigger
for (int i = 0; i < (5 * 15); i++) {
if (zkController2.getClusterState().getLiveNodes().size() == 2) {
break;
}
Thread.sleep(200);
}
assertEquals(2, zkController2.getClusterState().getLiveNodes().size());
// quickly kill / start client
container2.getZkController().getZkClient().getSolrZooKeeper().getConnection().disconnect();
container2.shutdown();
System.setProperty("hostPort", "1662");
System.setProperty("solr.data.dir", ClusterStateUpdateTest.this.dataDir2.getAbsolutePath());
container2 = new CoreContainer(solrHomeDirectory.getAbsolutePath());
container2.load();
System.clearProperty("hostPort");
// pause for watch to trigger
for (int i = 0; i < 200; i++) {
if (container1.getZkController().getClusterState().liveNodesContain(container2.getZkController().getNodeName())) {
break;
}
Thread.sleep(100);
}
assertTrue(container1.getZkController().getClusterState().liveNodesContain(container2.getZkController().getNodeName()));
// core.close(); // don't close - this core is managed by container1 now
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class CoreAdminHandlerTest method testCoreAdminHandler.
@Test
public void testCoreAdminHandler() throws Exception {
final File workDir = createTempDir().toFile();
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
Path instDir;
try (SolrCore template = cores.getCore("collection1")) {
assertNotNull(template);
instDir = template.getCoreDescriptor().getInstanceDir();
}
assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
final File instPropFile = new File(workDir, "instProp");
FileUtils.copyDirectory(instDir.toFile(), instPropFile);
SolrQueryResponse resp = new SolrQueryResponse();
// Sneaking in a test for using a bad core name
try {
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(), CoreAdminParams.NAME, "ugly$core=name"), resp);
} catch (SolrException se) {
assertTrue("Expected error message for bad core name.", se.toString().contains("Invalid core"));
}
CoreDescriptor cd = cores.getCoreDescriptor("ugly$core=name");
assertNull("Should NOT have added this core!", cd);
// create a new core (using CoreAdminHandler) w/ properties
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(), CoreAdminParams.NAME, "props", CoreAdminParams.PROPERTY_PREFIX + "hoss", "man", CoreAdminParams.PROPERTY_PREFIX + "foo", "baz"), resp);
assertNull("Exception on create", resp.getException());
cd = cores.getCoreDescriptor("props");
assertNotNull("Core not added!", cd);
assertEquals(cd.getCoreProperty("hoss", null), "man");
assertEquals(cd.getCoreProperty("foo", null), "baz");
// attempt to create a bogus core and confirm failure
ignoreException("Could not load config");
try {
resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.NAME, "bogus_dir_core", CoreAdminParams.INSTANCE_DIR, "dir_does_not_exist_127896"), resp);
fail("bogus collection created ok");
} catch (SolrException e) {
// :NOOP:
// :TODO: CoreAdminHandler's exception messages are terrible, otherwise we could assert something useful here
}
unIgnoreException("Could not load config");
// check specifically for status of the failed core name
resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.STATUS.toString(), CoreAdminParams.CORE, "bogus_dir_core"), resp);
Map<String, Exception> failures = (Map<String, Exception>) resp.getValues().get("initFailures");
assertNotNull("core failures is null", failures);
NamedList<Object> status = (NamedList<Object>) resp.getValues().get("status");
assertNotNull("core status is null", status);
assertEquals("wrong number of core failures", 1, failures.size());
Exception fail = failures.get("bogus_dir_core");
assertNotNull("null failure for test core", fail);
assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(), 0 < fail.getCause().getMessage().indexOf("dir_does_not_exist"));
assertEquals("bogus_dir_core status isn't empty", 0, ((NamedList) status.get("bogus_dir_core")).size());
//Try renaming the core, we should fail
// First assert that the props core exists
cd = cores.getCoreDescriptor("props");
assertNotNull("Core disappeared!", cd);
// now rename it something else just for kicks since we don't actually test this that I could find.
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.RENAME.toString(), CoreAdminParams.CORE, "props", CoreAdminParams.OTHER, "rename_me"), resp);
cd = cores.getCoreDescriptor("rename_me");
assertNotNull("Core should have been renamed!", cd);
// Rename it something bogus and see if you get an exception, the old core is still there and the bogus one isn't
try {
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.RENAME.toString(), CoreAdminParams.CORE, "rename_me", CoreAdminParams.OTHER, "bad$name"), resp);
} catch (SolrException e) {
// why the heck does create return a SolrException (admittedly wrapping an IAE)
assertTrue("Expected error message for bad core name.", e.getMessage().contains("Invalid core"));
}
cd = cores.getCoreDescriptor("bad$name");
assertNull("Core should NOT exist!", cd);
cd = cores.getCoreDescriptor("rename_me");
assertNotNull("Core should have been renamed!", cd);
// :TODO: because of SOLR-3665 we can't ask for status from all cores
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class CoreMergeIndexesAdminHandlerTest method testMergeIndexesCoreAdminHandler.
@Test
public void testMergeIndexesCoreAdminHandler() throws Exception {
final File workDir = createTempDir().toFile();
final CoreContainer cores = h.getCoreContainer();
final CoreAdminHandler admin = new CoreAdminHandler(cores);
try (SolrCore core = cores.getCore("collection1")) {
DirectoryFactory df = core.getDirectoryFactory();
FailingDirectoryFactory dirFactory = (FailingDirectoryFactory) df;
try {
dirFactory.fail = true;
ignoreException(FAILING_MSG);
SolrQueryResponse resp = new SolrQueryResponse();
admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.MERGEINDEXES.toString(), CoreAdminParams.CORE, "collection1", CoreAdminParams.INDEX_DIR, workDir.getAbsolutePath()), resp);
fail("exception expected");
} catch (FailingDirectoryFactory.FailingDirectoryFactoryException e) {
// expected if error handling properly
} finally {
unIgnoreException(FAILING_MSG);
}
dirFactory.fail = false;
}
}
use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.
the class InfoHandlerTest method testOverriddenHandlers.
@Test
public void testOverriddenHandlers() throws Exception {
final CoreContainer cores = h.getCoreContainer();
final InfoHandler infoHandler = new InfoHandler(cores);
infoHandler.init(null);
CountPropertiesRequestHandler propHandler = new CountPropertiesRequestHandler();
CountThreadDumpHandler threadHandler = new CountThreadDumpHandler();
CountLoggingHandler loggingHandler = new CountLoggingHandler(cores);
CountSystemInfoHandler systemInfoHandler = new CountSystemInfoHandler(cores);
// set the request handlers
infoHandler.setPropertiesHandler(propHandler);
infoHandler.setThreadDumpHandler(threadHandler);
infoHandler.setLoggingHandler(loggingHandler);
infoHandler.setSystemInfoHandler(systemInfoHandler);
// verify that the sets are reflected in the gets
assertEquals(propHandler, infoHandler.getPropertiesHandler());
assertEquals(threadHandler, infoHandler.getThreadDumpHandler());
assertEquals(loggingHandler, infoHandler.getLoggingHandler());
assertEquals(systemInfoHandler, infoHandler.getSystemInfoHandler());
// call each handler and verify it was actually called
handleRequest(infoHandler, "properties");
handleRequest(infoHandler, "threads");
handleRequest(infoHandler, "logging");
handleRequest(infoHandler, "system");
assertEquals(1, propHandler.getRequestCount());
assertEquals(1, threadHandler.getRequestCount());
assertEquals(1, loggingHandler.getRequestCount());
assertEquals(1, systemInfoHandler.getRequestCount());
}
Aggregations