Class SimCloudManager
- java.lang.Object
-
- org.apache.solr.cloud.autoscaling.sim.SimCloudManager
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,SolrCloudManager
,SolrCloseable
public class SimCloudManager extends Object implements SolrCloudManager
SimulatedSolrCloudManager
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_FREE_DISK
static long
DEFAULT_IDX_SIZE_BYTES
static int
DEFAULT_TOTAL_DISK
-
Constructor Summary
Constructors Constructor Description SimCloudManager(TimeSource timeSource)
Create a simulated cluster.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static SimCloudManager
createCluster(int numNodes, TimeSource timeSource)
Create a cluster with the specified number of nodes.static SimCloudManager
createCluster(SolrCloudManager other, AutoScalingConfig config, TimeSource timeSource)
static SimCloudManager
createCluster(ClusterState initialState, TimeSource timeSource)
Create a cluster initialized from the provided cluster state.static Map<String,Object>
createNodeValues(String nodeName)
Create simulated node values (metrics) for a node.void
disableMetricsHistory()
String
dumpClusterState(boolean withCollections)
long
getBackgroundTaskFailureCount()
Returns a total count of the number of tasks submitted tosubmit(java.util.concurrent.Callable<T>)
that have failed with any throwable other thenInteruptedException
ClusterStateProvider
getClusterStateProvider()
DistribStateManager
getDistribStateManager()
DistributedQueueFactory
getDistributedQueueFactory()
LiveNodesSet
getLiveNodesSet()
SolrResourceLoader
getLoader()
Get the instance ofSolrResourceLoader
that is used by the cluster components.SolrMetricManager
getMetricManager()
NodeStateProvider
getNodeStateProvider()
ObjectCache
getObjectCache()
OverseerTriggerThread
getOverseerTriggerThread()
Direct access to the currentOverseerTriggerThread
Random
getRandom()
Get the source of randomness (usually initialized by the test suite).SimClusterStateProvider
getSimClusterStateProvider()
SimDistribStateManager
getSimDistribStateManager()
SimNodeStateProvider
getSimNodeStateProvider()
TimeSource
getTimeSource()
byte[]
httpRequest(String url, SolrRequest.METHOD method, Map<String,String> headers, String payload, int timeout, boolean followRedirects)
HTTP requests are not supported by this implementation.SolrResponse
request(SolrRequest req)
String
simAddNode()
Add a new node and initialize its node values (metrics).void
simClearSystemCollection()
Clear the (simulated) .system collection.Map<String,Map<String,AtomicInteger>>
simGetEventCounts()
long
simGetOpCount(String op)
Get the number of processed operations of a specified type.Map<String,AtomicLong>
simGetOpCounts()
Get the number and type of operations processed by this cluster.SolrClient
simGetSolrClient()
Get aSolrClient
implementation where calls are forwarded to this instance of the cluster.List<SolrInputDocument>
simGetSystemCollection()
Get the content of (simulated) .system collection.SolrResponse
simHandleSolrRequest(SolrRequest req)
Handler method for autoscaling requests.void
simRemoveNode(String nodeId, boolean withValues)
Remove a node from the cluster.void
simRemoveRandomNodes(int number, boolean withValues, Random random)
Remove a number of randomly selected nodesvoid
simResetOpCounts()
void
simRestartOverseer(String killNodeId)
Simulate the effect of restarting Overseer leader - in this case this means closing the currentOverseerTriggerThread
(and optionally killing a node) then starting a newOverseerTriggerThread
.void
simSetUseSystemCollection(boolean useSystemCollection)
<T> Future<T>
submit(Callable<T> callable)
Submit a task to execute in a thread pool.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.solr.common.SolrCloseable
isClosed
-
-
-
-
Constructor Detail
-
SimCloudManager
public SimCloudManager(TimeSource timeSource) throws Exception
Create a simulated cluster. This cluster uses the following components:SimDistribStateManager
with non-shared root node.SimClusterStateProvider
SimNodeStateProvider
, where node values are automatically initialized when usingsimAddNode()
method.GenericDistributedQueueFactory
that usesSimDistribStateManager
as its storage.- an instance of
AutoScalingHandler
for managing AutoScalingConfig. - an instance of
OverseerTriggerThread
for managing triggers and processing events.
- Parameters:
timeSource
- time source to use.- Throws:
Exception
-
-
Method Detail
-
createCluster
public static SimCloudManager createCluster(int numNodes, TimeSource timeSource) throws Exception
Create a cluster with the specified number of nodes. Node metrics are pre-populated.- Parameters:
numNodes
- number of nodes to createtimeSource
- time source- Returns:
- instance of simulated cluster
- Throws:
Exception
-
createCluster
public static SimCloudManager createCluster(ClusterState initialState, TimeSource timeSource) throws Exception
Create a cluster initialized from the provided cluster state.- Parameters:
initialState
- existing cluster statetimeSource
- time source- Returns:
- instance of simulated cluster with the same layout as the provided cluster state.
- Throws:
Exception
-
createCluster
public static SimCloudManager createCluster(SolrCloudManager other, AutoScalingConfig config, TimeSource timeSource) throws Exception
- Throws:
Exception
-
createNodeValues
public static Map<String,Object> createNodeValues(String nodeName)
Create simulated node values (metrics) for a node.- Parameters:
nodeName
- node name (eg. '127.0.0.1:10000_solr'). If null then a new node name will be created using sequentially increasing port number.- Returns:
- node values
-
disableMetricsHistory
public void disableMetricsHistory()
-
dumpClusterState
public String dumpClusterState(boolean withCollections) throws Exception
- Throws:
Exception
-
getLoader
public SolrResourceLoader getLoader()
Get the instance ofSolrResourceLoader
that is used by the cluster components.
-
getRandom
public Random getRandom()
Get the source of randomness (usually initialized by the test suite).
-
simAddNode
public String simAddNode() throws Exception
Add a new node and initialize its node values (metrics). The /live_nodes list is updated with the new node id.- Returns:
- new node id
- Throws:
Exception
-
simRemoveNode
public void simRemoveNode(String nodeId, boolean withValues) throws Exception
Remove a node from the cluster. This simulates a node lost scenario. Node id is removed from the /live_nodes list.- Parameters:
nodeId
- node idwithValues
- when true, remove also simulated node values. If false then node values are retained to later simulate a node that comes back up- Throws:
Exception
-
simRemoveRandomNodes
public void simRemoveRandomNodes(int number, boolean withValues, Random random) throws Exception
Remove a number of randomly selected nodes- Parameters:
number
- number of nodes to removewithValues
- when true, remove also simulated node values. If false then node values are retained to later simulate a node that comes back uprandom
- random- Throws:
Exception
-
simSetUseSystemCollection
public void simSetUseSystemCollection(boolean useSystemCollection)
-
simClearSystemCollection
public void simClearSystemCollection()
Clear the (simulated) .system collection.
-
simGetSystemCollection
public List<SolrInputDocument> simGetSystemCollection()
Get the content of (simulated) .system collection.- Returns:
- documents in the collection, in chronological order starting from the oldest.
-
simGetEventCounts
public Map<String,Map<String,AtomicInteger>> simGetEventCounts()
-
simGetSolrClient
public SolrClient simGetSolrClient()
Get aSolrClient
implementation where calls are forwarded to this instance of the cluster.- Returns:
- simulated SolrClient.
-
simRestartOverseer
public void simRestartOverseer(String killNodeId) throws Exception
Simulate the effect of restarting Overseer leader - in this case this means closing the currentOverseerTriggerThread
(and optionally killing a node) then starting a newOverseerTriggerThread
. All background tasks currently in progress will be interrupted.- Parameters:
killNodeId
- optional nodeId to kill. If null then don't kill any node, just restart the thread- Throws:
Exception
- See Also:
getOverseerTriggerThread()
-
submit
public <T> Future<T> submit(Callable<T> callable)
Submit a task to execute in a thread pool. Every callable submitted will be wrapped such that errors not handled w/in the callable will be logged and counted for later assertions.- Parameters:
callable
- task to execute- Returns:
- future to obtain results
- See Also:
getBackgroundTaskFailureCount()
-
getBackgroundTaskFailureCount
public long getBackgroundTaskFailureCount()
Returns a total count of the number of tasks submitted tosubmit(java.util.concurrent.Callable<T>)
that have failed with any throwable other thenInteruptedException
- See Also:
submit(java.util.concurrent.Callable<T>)
-
getSimClusterStateProvider
public SimClusterStateProvider getSimClusterStateProvider()
-
getSimNodeStateProvider
public SimNodeStateProvider getSimNodeStateProvider()
-
getSimDistribStateManager
public SimDistribStateManager getSimDistribStateManager()
-
getLiveNodesSet
public LiveNodesSet getLiveNodesSet()
-
simGetOpCounts
public Map<String,AtomicLong> simGetOpCounts()
Get the number and type of operations processed by this cluster.
-
simResetOpCounts
public void simResetOpCounts()
-
simGetOpCount
public long simGetOpCount(String op)
Get the number of processed operations of a specified type.- Parameters:
op
- operation name, eg. MOVEREPLICA- Returns:
- number of operations
-
getMetricManager
public SolrMetricManager getMetricManager()
-
getObjectCache
public ObjectCache getObjectCache()
- Specified by:
getObjectCache
in interfaceSolrCloudManager
-
getTimeSource
public TimeSource getTimeSource()
- Specified by:
getTimeSource
in interfaceSolrCloudManager
-
getClusterStateProvider
public ClusterStateProvider getClusterStateProvider()
- Specified by:
getClusterStateProvider
in interfaceSolrCloudManager
-
getNodeStateProvider
public NodeStateProvider getNodeStateProvider()
- Specified by:
getNodeStateProvider
in interfaceSolrCloudManager
-
getDistribStateManager
public DistribStateManager getDistribStateManager()
- Specified by:
getDistribStateManager
in interfaceSolrCloudManager
-
getDistributedQueueFactory
public DistributedQueueFactory getDistributedQueueFactory()
- Specified by:
getDistributedQueueFactory
in interfaceSolrCloudManager
-
request
public SolrResponse request(SolrRequest req) throws IOException
- Specified by:
request
in interfaceSolrCloudManager
- Throws:
IOException
-
simHandleSolrRequest
public SolrResponse simHandleSolrRequest(SolrRequest req) throws IOException, InterruptedException
Handler method for autoscaling requests. NOTE: only a specific subset of autoscaling requests is supported!- Parameters:
req
- autoscaling request- Returns:
- results
- Throws:
IOException
InterruptedException
-
httpRequest
public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String,String> headers, String payload, int timeout, boolean followRedirects) throws IOException
HTTP requests are not supported by this implementation.- Specified by:
httpRequest
in interfaceSolrCloudManager
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getOverseerTriggerThread
public OverseerTriggerThread getOverseerTriggerThread()
Direct access to the currentOverseerTriggerThread
- See Also:
simRestartOverseer(java.lang.String)
-
-