SOLR-8259: Add getCoreContainer() method to JettySolrRunner

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1713601 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alan Woodward 2015-11-10 10:06:49 +00:00
parent f43daa0163
commit 9cbae39ab8
17 changed files with 191 additions and 232 deletions

View File

@ -477,6 +477,9 @@ Other Changes
* SOLR-8260: Use NIO2 APIs in core discovery (Alan Woodward)
* SOLR-8259: Deprecate JettySolrRunner.getDispatchFilter(), add
.getSolrDispatchFilter() and .getCoreContainer() (Alan Woodward)
================== 5.3.1 ==================
Bug Fixes

View File

@ -17,6 +17,28 @@
package org.apache.solr.client.solrj.embedded;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.eclipse.jetty.server.Connector;
@ -40,28 +62,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* Run solr using jetty
*
@ -353,10 +353,26 @@ public class JettySolrRunner {
}
/**
* @deprecated Use {@link #getSolrDispatchFilter()} or {@link #getCoreContainer()}
*/
@Deprecated
public FilterHolder getDispatchFilter() {
return dispatchFilter;
}
/**
* @return the {@link SolrDispatchFilter} for this node
*/
public SolrDispatchFilter getSolrDispatchFilter() { return (SolrDispatchFilter) dispatchFilter.getFilter(); }
/**
* @return the {@link CoreContainer} for this node
*/
public CoreContainer getCoreContainer() {
return getSolrDispatchFilter().getCores();
}
public boolean isRunning() {
return server.isRunning();
}

View File

@ -17,6 +17,17 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
@ -28,7 +39,13 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.*;
import org.apache.solr.common.cloud.ClusterState;
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.SolrZkClient;
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -37,15 +54,15 @@ import org.apache.solr.common.util.StrUtils;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.CdcrParams;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.zookeeper.CreateMode;
import org.junit.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import java.io.File;
import java.io.IOException;
import java.util.*;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.*;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.CREATE_NODE_SET;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.SHARDS_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
@ -547,9 +564,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase {
jettys.add(jetty);
}
ZkStateReader zkStateReader = ((SolrDispatchFilter) jettys.get(0)
.getDispatchFilter().getFilter()).getCores().getZkController()
.getZkStateReader();
ZkStateReader zkStateReader = jettys.get(0).getCoreContainer().getZkController().getZkStateReader();
// now wait till we see the leader for each shard
for (int i = 1; i <= shardCount; i++) {
@ -759,8 +774,7 @@ public class BaseCdcrDistributedZkTest extends AbstractDistribZkTestBase {
for (String shard : shardToJetty.get(collection).keySet()) {
List<CloudJettyRunner> jettyRunners = shardToJetty.get(collection).get(shard);
for (CloudJettyRunner jettyRunner : jettyRunners) {
SolrDispatchFilter filter = (SolrDispatchFilter) jettyRunner.jetty.getDispatchFilter().getFilter();
for (SolrCore core : filter.getCores().getCores()) {
for (SolrCore core : jettyRunner.jetty.getCoreContainer().getCores()) {
info.addCore(core, shard, shardToLeaderJetty.get(collection).containsValue(jettyRunner));
}
}

View File

@ -33,7 +33,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.SnapShooter;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -79,8 +78,7 @@ public class CleanupOldIndexTest extends AbstractFullDistribZkTestBase {
// create some "old" index directories
JettySolrRunner jetty = chaosMonkey.getShard("shard1", 1);
SolrDispatchFilter filter = (SolrDispatchFilter)jetty.getDispatchFilter().getFilter();
CoreContainer coreContainer = filter.getCores();
CoreContainer coreContainer = jetty.getCoreContainer();
File dataDir = null;
try (SolrCore solrCore = coreContainer.getCore("collection1")) {
dataDir = new File(solrCore.getDataDir());

View File

@ -26,19 +26,8 @@ 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.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.lucene.util.LuceneTestCase.Slow;
@ -79,15 +68,14 @@ import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean.Category;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.util.TimeOut;
import org.junit.Test;
import static org.apache.solr.cloud.OverseerCollectionMessageHandler.NUM_SLICES;
import static org.apache.solr.common.util.Utils.makeMap;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
import static org.apache.solr.common.cloud.ZkStateReader.MAX_SHARDS_PER_NODE;
import static org.apache.solr.common.cloud.ZkStateReader.REPLICATION_FACTOR;
import static org.apache.solr.common.util.Utils.makeMap;
/**
* Tests the Cloud Collections API.
@ -440,8 +428,8 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
params.set("collection.configName", "conf1");
}
String nn1 = ((SolrDispatchFilter) jettys.get(0).getDispatchFilter().getFilter()).getCores().getZkController().getNodeName();
String nn2 = ((SolrDispatchFilter) jettys.get(1).getDispatchFilter().getFilter()).getCores().getZkController().getNodeName();
String nn1 = jettys.get(0).getCoreContainer().getZkController().getNodeName();
String nn2 = jettys.get(1).getCoreContainer().getZkController().getNodeName();
params.set(OverseerCollectionMessageHandler.CREATE_NODE_SET, nn1 + "," + nn2);
request = new QueryRequest(params);
@ -916,8 +904,7 @@ public class CollectionsAPIDistributedZkTest extends AbstractFullDistribZkTestBa
}
private void checkInstanceDirs(JettySolrRunner jetty) throws IOException {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
.getFilter()).getCores();
CoreContainer cores = jetty.getCoreContainer();
Collection<SolrCore> theCores = cores.getCores();
for (SolrCore core : theCores) {

View File

@ -1,7 +1,5 @@
package org.apache.solr.cloud;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
@ -13,7 +11,6 @@ import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CollectionAdminRequest.ForceLeader;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.SimpleSolrResponse;
import org.apache.solr.cloud.overseer.OverseerAction;
@ -29,7 +26,6 @@ import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.junit.Ignore;
@ -37,6 +33,8 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -87,7 +85,7 @@ public class ForceLeaderTest extends HttpPartitionTest {
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, SHARD1);
JettySolrRunner notLeader0 = getJettyOnPort(getReplicaPort(notLeaders.get(0)));
ZkController zkController = ((SolrDispatchFilter) notLeader0.getDispatchFilter().getFilter()).getCores().getZkController();
ZkController zkController = notLeader0.getCoreContainer().getZkController();
putNonLeadersIntoLIR(testCollectionName, SHARD1, zkController, leader, notLeaders);
@ -181,7 +179,7 @@ public class ForceLeaderTest extends HttpPartitionTest {
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, SHARD1);
JettySolrRunner notLeader0 = getJettyOnPort(getReplicaPort(notLeaders.get(0)));
ZkController zkController = ((SolrDispatchFilter) notLeader0.getDispatchFilter().getFilter()).getCores().getZkController();
ZkController zkController = notLeader0.getCoreContainer().getZkController();
// Mark all replicas down
setReplicaState(testCollectionName, SHARD1, leader, State.DOWN);

View File

@ -51,7 +51,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.UpdateLog;
import org.apache.solr.util.MockCoreContainer.MockCoreDescriptor;
import org.apache.solr.util.RTimer;
@ -137,7 +136,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, shardId);
JettySolrRunner leaderJetty = getJettyOnPort(getReplicaPort(leader));
CoreContainer cores = ((SolrDispatchFilter)leaderJetty.getDispatchFilter().getFilter()).getCores();
CoreContainer cores = leaderJetty.getCoreContainer();
ZkController zkController = cores.getZkController();
assertNotNull("ZkController is null", zkController);
@ -310,8 +309,7 @@ public class HttpPartitionTest extends AbstractFullDistribZkTestBase {
// Get the max version from the replica core to make sure it gets updated after recovery (see SOLR-7625)
JettySolrRunner replicaJetty = getJettyOnPort(getReplicaPort(notLeader));
SolrDispatchFilter filter = (SolrDispatchFilter)replicaJetty.getDispatchFilter().getFilter();
CoreContainer coreContainer = filter.getCores();
CoreContainer coreContainer = replicaJetty.getCoreContainer();
ZkCoreNodeProps replicaCoreNodeProps = new ZkCoreNodeProps(notLeader);
String coreName = replicaCoreNodeProps.getCoreName();
Long maxVersionBefore = null;

View File

@ -1,6 +1,18 @@
package org.apache.solr.cloud;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.util.MockCoreContainer.MockCoreDescriptor;
import org.apache.solr.util.TimeOut;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -19,19 +31,6 @@ import java.util.Properties;
* limitations under the License.
*/
import java.util.concurrent.TimeUnit;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.util.TimeOut;
import org.apache.solr.util.MockCoreContainer.MockCoreDescriptor;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
/**
* Test for {@link LeaderInitiatedRecoveryThread}
*/
@ -48,8 +47,8 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
final String leaderCoreNodeName = shardToLeaderJetty.get(SHARD1).coreNodeName;
final CloudJettyRunner leaderRunner = shardToLeaderJetty.get(SHARD1);
SolrDispatchFilter filter = (SolrDispatchFilter) leaderRunner.jetty.getDispatchFilter().getFilter();
ZkController zkController = filter.getCores().getZkController();
CoreContainer coreContainer = leaderRunner.jetty.getCoreContainer();
ZkController zkController = coreContainer.getZkController();
CloudJettyRunner notLeader = null;
for (CloudJettyRunner cloudJettyRunner : shardToJetty.get(SHARD1)) {
@ -82,7 +81,7 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
*/
try {
LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd);
assertFalse(zkController.isReplicaInRecoveryHandling(replicaCoreNodeProps.getCoreUrl()));
thread.run();
@ -95,7 +94,7 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
/*
2. Test that a non-live replica cannot be put into LIR or down state
*/
LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd);
// kill the replica
int children = cloudClient.getZkStateReader().getZkClient().getChildren("/live_nodes", null, true).size();
@ -126,7 +125,7 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
ChaosMonkey.start(notLeader.jetty);
waitForRecoveriesToFinish(true);
thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
@Override
protected void updateLIRState(String replicaCoreNodeName) {
@ -141,7 +140,7 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
/*
4. Test that if ZK connection loss or session expired then thread should not attempt to publish down state even if forcePublish=true
*/
thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
@Override
protected void updateLIRState(String replicaCoreNodeName) {
@ -156,7 +155,7 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
/*
5. Test that any exception other then ZK connection loss or session expired should publish down state only if forcePublish=true
*/
thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
@Override
protected void updateLIRState(String replicaCoreNodeName) {
@ -191,12 +190,12 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
/*
6. Test that non-leader cannot set LIR nodes
*/
filter = (SolrDispatchFilter) notLeader.jetty.getDispatchFilter().getFilter();
zkController = filter.getCores().getZkController();
thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, filter.getCores().getCores().iterator().next().getCoreDescriptor()) {
coreContainer = notLeader.jetty.getCoreContainer();
zkController = coreContainer.getZkController();
thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, coreContainer.getCores().iterator().next().getCoreDescriptor()) {
@Override
protected void updateLIRState(String replicaCoreNodeName) {
try {
@ -215,10 +214,10 @@ public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTest
7. assert that we can write a LIR state if everything else is fine
*/
// reset the zkcontroller to the one from the leader
filter = (SolrDispatchFilter) leaderRunner.jetty.getDispatchFilter().getFilter();
zkController = filter.getCores().getZkController();
thread = new LeaderInitiatedRecoveryThread(zkController, filter.getCores(),
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, filter.getCores().getCores().iterator().next().getCoreDescriptor());
coreContainer = leaderRunner.jetty.getCoreContainer();
zkController = coreContainer.getZkController();
thread = new LeaderInitiatedRecoveryThread(zkController, coreContainer,
DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, coreContainer.getCores().iterator().next().getCoreDescriptor());
thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false);
timeOut = new TimeOut(30, TimeUnit.SECONDS);
while (!timeOut.hasTimedOut()) {

View File

@ -33,14 +33,12 @@ import org.apache.solr.cloud.overseer.OverseerAction;
import org.apache.solr.common.cloud.ClusterState;
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.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.junit.Test;
@ -104,7 +102,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
Map<String, Integer> shardVsCount = new HashMap<>();
for (JettySolrRunner runner : jettys) {
CoreContainer container = ((SolrDispatchFilter) runner.getDispatchFilter().getFilter()).getCores();
CoreContainer container = runner.getCoreContainer();
for (SolrCore core : container.getCores()) {
SolrRequestHandler select = core.getRequestHandler("");
long c = (long) select.getStatistics().get("requests");
@ -179,7 +177,7 @@ public class TestRandomRequestDistribution extends AbstractFullDistribZkTestBase
//Test to see if the query got forwarded to the active replica or not.
for (JettySolrRunner jetty : jettys) {
CoreContainer container = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
CoreContainer container = jetty.getCoreContainer();
for (SolrCore core : container.getCores()) {
if (core.getName().equals(leader.getStr(ZkStateReader.CORE_NAME_PROP))) {
SolrRequestHandler select = core.getRequestHandler("");

View File

@ -17,8 +17,12 @@
package org.apache.solr.cloud.hdfs;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.NRTCachingDirectory;
@ -33,7 +37,6 @@ import org.apache.solr.cloud.StoppableIndexingThread;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.HdfsDirectoryFactory;
import org.apache.solr.core.SolrCore;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.store.blockcache.BlockCache;
import org.apache.solr.store.blockcache.BlockDirectory;
import org.apache.solr.store.blockcache.BlockDirectoryCache;
@ -44,11 +47,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Slow
@Nightly
@ThreadLeakFilters(defaultFilters = true, filters = {
@ -127,8 +125,7 @@ public class HdfsWriteToMultipleCollectionsTest extends BasicDistributedZkTest {
BlockCache lastBlockCache = null;
// assert that we are using the block directory and that write and read caching are being used
for (JettySolrRunner jetty : jettys) {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
.getFilter()).getCores();
CoreContainer cores = jetty.getCoreContainer();
Collection<SolrCore> solrCores = cores.getCores();
for (SolrCore core : solrCores) {
if (core.getCoreDescriptor().getCloudDescriptor().getCollectionName()

View File

@ -16,6 +16,27 @@
*/
package org.apache.solr.handler;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.LuceneTestCase.Slow;
@ -38,39 +59,16 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.CachingDirectoryFactory;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.StandardDirectoryFactory;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Test for ReplicationHandler
*
@ -802,7 +800,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
}
private void checkForSingleIndex(JettySolrRunner jetty) {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
CoreContainer cores = jetty.getCoreContainer();
Collection<SolrCore> theCores = cores.getCores();
for (SolrCore core : theCores) {
String ddir = core.getDataDir();

View File

@ -29,7 +29,6 @@ import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.junit.Test;
/**
@ -60,7 +59,7 @@ public class TestTrackingShardHandlerFactory extends AbstractFullDistribZkTestBa
TrackingShardHandlerFactory.setTrackingQueue(runners, trackingQueue);
for (JettySolrRunner runner : runners) {
CoreContainer container = ((SolrDispatchFilter) runner.getDispatchFilter().getFilter()).getCores();
CoreContainer container = runner.getCoreContainer();
ShardHandlerFactory factory = container.getShardHandlerFactory();
assert factory instanceof TrackingShardHandlerFactory;
TrackingShardHandlerFactory trackingShardHandlerFactory = (TrackingShardHandlerFactory) factory;
@ -115,7 +114,7 @@ public class TestTrackingShardHandlerFactory extends AbstractFullDistribZkTestBa
TrackingShardHandlerFactory.setTrackingQueue(runners, null);
for (JettySolrRunner runner : runners) {
CoreContainer container = ((SolrDispatchFilter) runner.getDispatchFilter().getFilter()).getCores();
CoreContainer container = runner.getCoreContainer();
ShardHandlerFactory factory = container.getShardHandlerFactory();
assert factory instanceof TrackingShardHandlerFactory;
TrackingShardHandlerFactory trackingShardHandlerFactory = (TrackingShardHandlerFactory) factory;

View File

@ -17,6 +17,15 @@ package org.apache.solr.update;
* limitations under the License.
*/
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.index.LogDocMergePolicy;
import org.apache.solr.BaseDistributedSearchTestCase;
import org.apache.solr.client.solrj.SolrClient;
@ -37,7 +46,6 @@ import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrEventListener;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.MockStreamingSolrClients.Exp;
import org.apache.solr.update.SolrCmdDistributor.Error;
import org.apache.solr.update.SolrCmdDistributor.Node;
@ -48,15 +56,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
private AtomicInteger id = new AtomicInteger();
@ -275,7 +274,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
final AtomicInteger commits = new AtomicInteger();
for(JettySolrRunner jetty : jettys) {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter().getFilter()).getCores();
CoreContainer cores = jetty.getCoreContainer();
try (SolrCore core = cores.getCore("collection1")) {
core.getUpdateHandler().registerCommitCallback(new SolrEventListener() {
@Override

View File

@ -31,7 +31,6 @@ import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.core.Diagnostics;
import org.apache.solr.core.MockDirectoryFactory;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.zookeeper.KeeperException;
import org.junit.BeforeClass;
@ -116,8 +115,7 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTes
// now wait till we see the leader for each shard
for (int i = 1; i <= numShards; i++) {
ZkStateReader zkStateReader = ((SolrDispatchFilter) jettys.get(0)
.getDispatchFilter().getFilter()).getCores().getZkController()
ZkStateReader zkStateReader = jettys.get(0).getCoreContainer().getZkController()
.getZkStateReader();
zkStateReader.getLeaderRetry("collection1", "shard" + (i + 2), 15000);
}

View File

@ -1200,8 +1200,7 @@ public abstract class AbstractFullDistribZkTestBase extends AbstractDistribZkTes
log.info("Turning on auto soft commit: " + time);
for (List<CloudJettyRunner> jettyList : shardToJetty.values()) {
for (CloudJettyRunner jetty : jettyList) {
CoreContainer cores = ((SolrDispatchFilter) jetty.jetty
.getDispatchFilter().getFilter()).getCores();
CoreContainer cores = jetty.jetty.getCoreContainer();
for (SolrCore core : cores.getCores()) {
((DirectUpdateHandler2) core.getUpdateHandler())
.getSoftCommitTracker().setTimeUpperBound(time);

View File

@ -17,6 +17,13 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
@ -32,19 +39,9 @@ import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.util.RTimer;
import org.apache.zookeeper.KeeperException;
import org.eclipse.jetty.servlet.FilterHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Filter;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
/**
* The monkey can stop random or specific jetties used with SolrCloud.
*
@ -120,18 +117,15 @@ public class ChaosMonkey {
// TODO: expire all clients at once?
public void expireSession(final JettySolrRunner jetty) {
monkeyLog("expire session for " + jetty.getLocalPort() + " !");
SolrDispatchFilter solrDispatchFilter = (SolrDispatchFilter) jetty
.getDispatchFilter().getFilter();
if (solrDispatchFilter != null) {
CoreContainer cores = solrDispatchFilter.getCores();
if (cores != null) {
causeConnectionLoss(jetty);
long sessionId = cores.getZkController().getZkClient()
.getSolrZooKeeper().getSessionId();
zkServer.expire(sessionId);
}
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
causeConnectionLoss(jetty);
long sessionId = cores.getZkController().getZkClient()
.getSolrZooKeeper().getSessionId();
zkServer.expire(sessionId);
}
}
public void expireRandomSession() throws KeeperException, InterruptedException {
@ -156,14 +150,10 @@ public class ChaosMonkey {
}
public static void causeConnectionLoss(JettySolrRunner jetty) {
SolrDispatchFilter solrDispatchFilter = (SolrDispatchFilter) jetty
.getDispatchFilter().getFilter();
if (solrDispatchFilter != null) {
CoreContainer cores = solrDispatchFilter.getCores();
if (cores != null) {
SolrZkClient zkClient = cores.getZkController().getZkClient();
zkClient.getSolrZooKeeper().closeCnxn();
}
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
SolrZkClient zkClient = cores.getZkController().getZkClient();
zkClient.getSolrZooKeeper().closeCnxn();
}
}
@ -191,16 +181,11 @@ public class ChaosMonkey {
private static void stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
assert(jetty != null);
monkeyLog("stop shard! " + jetty.getLocalPort());
// get a clean close so that no dirs are left open...
FilterHolder fh = jetty.getDispatchFilter();
if (fh != null) {
SolrDispatchFilter sdf = (SolrDispatchFilter) fh.getFilter();
if (sdf != null) {
sdf.destroy();
}
}
SolrDispatchFilter sdf = jetty.getSolrDispatchFilter();
if (sdf != null)
sdf.destroy();
jetty.stop();
if (!jetty.isStopped()) {
throw new RuntimeException("could not stop jetty");
}
@ -214,18 +199,13 @@ public class ChaosMonkey {
}
public static void kill(JettySolrRunner jetty) throws Exception {
FilterHolder filterHolder = jetty.getDispatchFilter();
if (filterHolder != null) {
Filter filter = filterHolder.getFilter();
if (filter != null) {
CoreContainer cores = ((SolrDispatchFilter) filter).getCores();
if (cores != null) {
if (cores.isZooKeeperAware()) {
int zklocalport = ((InetSocketAddress) cores.getZkController()
.getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
IpTables.blockPort(zklocalport);
}
}
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
if (cores.isZooKeeperAware()) {
int zklocalport = ((InetSocketAddress) cores.getZkController()
.getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
IpTables.blockPort(zklocalport);
}
}
@ -352,26 +332,10 @@ public class ChaosMonkey {
log.error("Could not get leader", t);
return null;
}
FilterHolder fh = cjetty.jetty.getDispatchFilter();
if (fh == null) {
monkeyLog("selected jetty not running correctly - skip");
return null;
}
SolrDispatchFilter df = ((SolrDispatchFilter) fh.getFilter());
if (df == null) {
monkeyLog("selected jetty not running correctly - skip");
return null;
}
CoreContainer cores = df.getCores();
if (cores == null) {
monkeyLog("selected jetty not running correctly - skip");
return null;
}
// cluster state can be stale - also go by our 'near real-time' is leader prop
boolean rtIsLeader;
try (SolrCore core = cores.getCore(leader.getStr(ZkStateReader.CORE_NAME_PROP))) {
try (SolrCore core = cjetty.jetty.getCoreContainer().getCore(leader.getStr(ZkStateReader.CORE_NAME_PROP))) {
if (core == null) {
monkeyLog("selected jetty not running correctly - skip");
return null;
@ -589,20 +553,15 @@ public class ChaosMonkey {
}
}
}
FilterHolder filterHolder = jetty.getDispatchFilter();
if (filterHolder != null) {
Filter filter = filterHolder.getFilter();
if (filter != null) {
CoreContainer cores = ((SolrDispatchFilter) filter).getCores();
if (cores != null) {
if (cores.isZooKeeperAware()) {
int zklocalport = ((InetSocketAddress) cores.getZkController()
.getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
IpTables.unblockPort(zklocalport);
}
}
CoreContainer cores = jetty.getCoreContainer();
if (cores != null) {
if (cores.isZooKeeperAware()) {
int zklocalport = ((InetSocketAddress) cores.getZkController()
.getZkClient().getSolrZooKeeper().getSocketAddress()).getPort();
IpTables.unblockPort(zklocalport);
}
}
return true;
}

View File

@ -35,7 +35,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.servlet.SolrDispatchFilter;
/**
* A ShardHandlerFactory that extends HttpShardHandlerFactory and
@ -153,7 +152,7 @@ public class TrackingShardHandlerFactory extends HttpShardHandlerFactory {
*/
public static void setTrackingQueue(List<JettySolrRunner> runners, Queue<ShardRequestAndParams> queue) {
for (JettySolrRunner runner : runners) {
CoreContainer container = ((SolrDispatchFilter) runner.getDispatchFilter().getFilter()).getCores();
CoreContainer container = runner.getCoreContainer();
ShardHandlerFactory factory = container.getShardHandlerFactory();
assert factory instanceof TrackingShardHandlerFactory : "not a TrackingShardHandlerFactory: " + factory.getClass();
TrackingShardHandlerFactory trackingShardHandlerFactory = (TrackingShardHandlerFactory) factory;