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 intDEFAULT_FREE_DISKstatic longDEFAULT_IDX_SIZE_BYTESstatic intDEFAULT_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 voidclose()static SimCloudManagercreateCluster(int numNodes, TimeSource timeSource)Create a cluster with the specified number of nodes.static SimCloudManagercreateCluster(SolrCloudManager other, AutoScalingConfig config, TimeSource timeSource)static SimCloudManagercreateCluster(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.voiddisableMetricsHistory()StringdumpClusterState(boolean withCollections)longgetBackgroundTaskFailureCount()Returns a total count of the number of tasks submitted tosubmit(java.util.concurrent.Callable<T>)that have failed with any throwable other thenInteruptedExceptionClusterStateProvidergetClusterStateProvider()DistribStateManagergetDistribStateManager()DistributedQueueFactorygetDistributedQueueFactory()LiveNodesSetgetLiveNodesSet()SolrResourceLoadergetLoader()Get the instance ofSolrResourceLoaderthat is used by the cluster components.SolrMetricManagergetMetricManager()NodeStateProvidergetNodeStateProvider()ObjectCachegetObjectCache()OverseerTriggerThreadgetOverseerTriggerThread()Direct access to the currentOverseerTriggerThreadRandomgetRandom()Get the source of randomness (usually initialized by the test suite).SimClusterStateProvidergetSimClusterStateProvider()SimDistribStateManagergetSimDistribStateManager()SimNodeStateProvidergetSimNodeStateProvider()TimeSourcegetTimeSource()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.SolrResponserequest(SolrRequest req)StringsimAddNode()Add a new node and initialize its node values (metrics).voidsimClearSystemCollection()Clear the (simulated) .system collection.Map<String,Map<String,AtomicInteger>>simGetEventCounts()longsimGetOpCount(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.SolrClientsimGetSolrClient()Get aSolrClientimplementation where calls are forwarded to this instance of the cluster.List<SolrInputDocument>simGetSystemCollection()Get the content of (simulated) .system collection.SolrResponsesimHandleSolrRequest(SolrRequest req)Handler method for autoscaling requests.voidsimRemoveNode(String nodeId, boolean withValues)Remove a node from the cluster.voidsimRemoveRandomNodes(int number, boolean withValues, Random random)Remove a number of randomly selected nodesvoidsimResetOpCounts()voidsimRestartOverseer(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.voidsimSetUseSystemCollection(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:SimDistribStateManagerwith non-shared root node.SimClusterStateProviderSimNodeStateProvider, where node values are automatically initialized when usingsimAddNode()method.GenericDistributedQueueFactorythat usesSimDistribStateManageras its storage.- an instance of
AutoScalingHandlerfor managing AutoScalingConfig. - an instance of
OverseerTriggerThreadfor 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 ofSolrResourceLoaderthat 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 ExceptionRemove 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 aSolrClientimplementation 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:
getObjectCachein interfaceSolrCloudManager
-
getTimeSource
public TimeSource getTimeSource()
- Specified by:
getTimeSourcein interfaceSolrCloudManager
-
getClusterStateProvider
public ClusterStateProvider getClusterStateProvider()
- Specified by:
getClusterStateProviderin interfaceSolrCloudManager
-
getNodeStateProvider
public NodeStateProvider getNodeStateProvider()
- Specified by:
getNodeStateProviderin interfaceSolrCloudManager
-
getDistribStateManager
public DistribStateManager getDistribStateManager()
- Specified by:
getDistribStateManagerin interfaceSolrCloudManager
-
getDistributedQueueFactory
public DistributedQueueFactory getDistributedQueueFactory()
- Specified by:
getDistributedQueueFactoryin interfaceSolrCloudManager
-
request
public SolrResponse request(SolrRequest req) throws IOException
- Specified by:
requestin 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:
IOExceptionInterruptedException
-
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:
httpRequestin interfaceSolrCloudManager- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getOverseerTriggerThread
public OverseerTriggerThread getOverseerTriggerThread()
Direct access to the currentOverseerTriggerThread- See Also:
simRestartOverseer(java.lang.String)
-
-