mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-10-01 14:41:19 +00:00
SEARCH-104: Simplify jetty server creation ready for multi-cores
This commit is contained in:
@@ -378,23 +378,45 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a jetty alfresco solr.
|
* Creates a JettySolrRunner (if one didn't exist already). DOES NOT START IT.
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private JettySolrRunner createJetty(String sourceConfigName, int jettyInstanceId, String coreName, Properties additionalProperties) throws Exception
|
private JettySolrRunner createJetty(String jettyKey) throws Exception
|
||||||
{
|
{
|
||||||
Path jettyTestsHome = testDir.toPath().resolve("jetty"+jettyInstanceId);
|
if (jettyContainers.containsKey(jettyKey))
|
||||||
|
{
|
||||||
|
return jettyContainers.get(jettyKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Path jettySolrHome = testDir.toPath().resolve(jettyKey);
|
||||||
|
seedSolrHome(jettySolrHome);
|
||||||
|
JettySolrRunner jetty = createJetty(jettySolrHome.toFile(), null, null, false, getSchemaFile());
|
||||||
|
return jetty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the core config information to the jetty file system.
|
||||||
|
* Its best to call this before calling start() on Jetty
|
||||||
|
* @param jettyKey
|
||||||
|
* @param sourceConfigName
|
||||||
|
* @param coreName
|
||||||
|
* @param additionalProperties
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private void addCoreToJetty(String jettyKey, String sourceConfigName, String coreName, Properties additionalProperties) throws Exception
|
||||||
|
{
|
||||||
|
Path jettySolrHome = testDir.toPath().resolve(jettyKey);
|
||||||
Path coreSourceConfig = new File(getTestFilesHome() + "/"+sourceConfigName).toPath();
|
Path coreSourceConfig = new File(getTestFilesHome() + "/"+sourceConfigName).toPath();
|
||||||
Path coreHome = jettyTestsHome.resolve(coreName);
|
Path coreHome = jettySolrHome.resolve(coreName);
|
||||||
seedSolrHome(jettyTestsHome);
|
|
||||||
seedCoreDir(coreName, coreSourceConfig, coreHome);
|
seedCoreDir(coreName, coreSourceConfig, coreHome);
|
||||||
updateSolrCoreProperties(coreHome, additionalProperties);
|
updateSolrCoreProperties(coreHome, additionalProperties);
|
||||||
JettySolrRunner jetty = createJetty(jettyTestsHome.toFile(), null, null, false, getSchemaFile());
|
|
||||||
return jetty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateSolrCoreProperties(Path coreHome, Properties additionalProperties) throws IOException
|
private void updateSolrCoreProperties(Path coreHome, Properties additionalProperties) throws IOException
|
||||||
{
|
{
|
||||||
if(additionalProperties != null)
|
if(additionalProperties != null)
|
||||||
@@ -422,25 +444,35 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createServers(JettyInstances jettyStategy, String[] coreNames, int numShards, Properties additionalProperties) throws Exception
|
/**
|
||||||
{
|
* Starts jetty if its not already running
|
||||||
boolean incrementJetty = true;
|
* @param jsr
|
||||||
|
* @throws Exception
|
||||||
switch (jettyStategy)
|
*/
|
||||||
|
private void startJetty(JettySolrRunner jsr) throws Exception {
|
||||||
|
if (!jsr.isRunning())
|
||||||
{
|
{
|
||||||
case SINGLE:
|
jsr.start();
|
||||||
incrementJetty = false;
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
protected void createServers(String jettyKey, String[] coreNames, int numShards, Properties additionalProperties) throws Exception
|
||||||
|
{
|
||||||
|
JettySolrRunner jsr = createJetty(jettyKey);
|
||||||
|
jettyContainers.put(jettyKey, jsr);
|
||||||
|
|
||||||
|
for (int i = 0; i < coreNames.length; i++) {
|
||||||
|
addCoreToJetty(jettyKey, coreNames[i], coreNames[i], additionalProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
int numOfJettys = 0;
|
//Now start jetty
|
||||||
|
startJetty(jsr);
|
||||||
|
|
||||||
|
int jettyPort = jsr.getLocalPort();
|
||||||
for (int i = 0; i < coreNames.length; i++) {
|
for (int i = 0; i < coreNames.length; i++) {
|
||||||
JettySolrRunner jsr = createJetty(coreNames[i], incrementJetty?numOfJettys++:numOfJettys, coreNames[i], additionalProperties);
|
String url = buildUrl(jettyPort) + "/" + coreNames[i];
|
||||||
jettyContainers.put(coreNames[i], jsr);
|
|
||||||
String url = buildUrl(jsr.getLocalPort()) + "/" + coreNames[i];
|
|
||||||
log.info(url);
|
log.info(url);
|
||||||
jettyClients.put(coreNames[i], createNewSolrClient(url));
|
jettyClients.put(coreNames[i], createNewSolrClient(url));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shardsArr = new String[numShards];
|
shardsArr = new String[numShards];
|
||||||
@@ -448,35 +480,21 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
String shardMethod = getShardMethod().toString();
|
String shardMethod = getShardMethod().toString();
|
||||||
log.info("################# shardMethod:"+shardMethod);
|
log.info("################# shardMethod:"+shardMethod);
|
||||||
|
|
||||||
switch (jettyStategy)
|
|
||||||
{
|
|
||||||
case SINGLE:
|
|
||||||
incrementJetty = false;
|
|
||||||
break;
|
|
||||||
case PER_CORE:
|
|
||||||
//We have created them per core but where do we put the shards?
|
|
||||||
if (numShards != 0 && coreNames.length != 1)
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException("What shall we do with multiple cores and multiple shards?");
|
|
||||||
}
|
|
||||||
incrementJetty = false;
|
|
||||||
numOfJettys = 0; //For now, lets put them on the first core.
|
|
||||||
break;
|
|
||||||
case PER_SHARD:
|
|
||||||
incrementJetty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numShards; i++)
|
for (int i = 0; i < numShards; i++)
|
||||||
{
|
{
|
||||||
if (sb.length() > 0)
|
if (sb.length() > 0) sb.append(',');
|
||||||
sb.append(',');
|
|
||||||
final String shardname = "shard" + i;
|
final String shardname = "shard" + i;
|
||||||
if (additionalProperties == null) additionalProperties = new Properties();
|
if (additionalProperties == null) additionalProperties = new Properties();
|
||||||
additionalProperties.put("shard.instance", Integer.toString(i));
|
additionalProperties.put("shard.instance", Integer.toString(i));
|
||||||
additionalProperties.put("shard.method", shardMethod);
|
additionalProperties.put("shard.method", shardMethod);
|
||||||
additionalProperties.put("shard.count", Integer.toString(numShards));
|
additionalProperties.put("shard.count", Integer.toString(numShards));
|
||||||
JettySolrRunner j = createJetty(coreNames[0], incrementJetty?numOfJettys++:numOfJettys, shardname,additionalProperties);
|
|
||||||
|
String shardKey = jettyKey+"_shard_"+i;
|
||||||
|
JettySolrRunner j = createJetty(shardKey);
|
||||||
|
//use the first corename specified as the Share template
|
||||||
|
addCoreToJetty(shardKey, coreNames[0], shardname, additionalProperties);
|
||||||
jettyShards.add(j);
|
jettyShards.add(j);
|
||||||
|
startJetty(j);
|
||||||
String shardStr = buildUrl(j.getLocalPort()) + "/" + shardname;
|
String shardStr = buildUrl(j.getLocalPort()) + "/" + shardname;
|
||||||
log.info(shardStr);
|
log.info(shardStr);
|
||||||
SolrClient clientShard = createNewSolrClient(shardStr);
|
SolrClient clientShard = createNewSolrClient(shardStr);
|
||||||
@@ -485,7 +503,6 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
sb.append(shardStr);
|
sb.append(shardStr);
|
||||||
}
|
}
|
||||||
shards = sb.toString();
|
shards = sb.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ShardMethodEnum getShardMethod() {
|
protected ShardMethodEnum getShardMethod() {
|
||||||
@@ -564,8 +581,7 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
jettyClients.clear();
|
jettyClients.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, boolean sslEnabled,
|
public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, boolean sslEnabled, String schemaOverride) throws Exception
|
||||||
String schemaOverride) throws Exception
|
|
||||||
{
|
{
|
||||||
return createJetty(solrHome, dataDir, shardList, sslEnabled, schemaOverride, useExplicitNodeNames);
|
return createJetty(solrHome, dataDir, shardList, sslEnabled, schemaOverride, useExplicitNodeNames);
|
||||||
}
|
}
|
||||||
@@ -606,8 +622,6 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
// .withServlets(getExtraServlets())
|
// .withServlets(getExtraServlets())
|
||||||
// .withSSLConfig(sslConfig)
|
// .withSSLConfig(sslConfig)
|
||||||
// .build());
|
// .build());
|
||||||
|
|
||||||
jetty.start();
|
|
||||||
return jetty;
|
return jetty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1416,36 +1430,29 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
SOLRAPIQueueClient.transactionQueue.add(transaction);
|
SOLRAPIQueueClient.transactionQueue.add(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum JettyInstances
|
|
||||||
{
|
|
||||||
PER_SHARD,
|
|
||||||
PER_CORE,
|
|
||||||
SINGLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A JUnit Rule to setup Jetty
|
* A JUnit Rule to setup Jetty
|
||||||
*/
|
*/
|
||||||
public class JettyServerRule extends ExternalResource
|
public class JettyServerRule extends ExternalResource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
final String serverName;
|
||||||
final String[] coreNames;
|
final String[] coreNames;
|
||||||
final int numShards;
|
final int numShards;
|
||||||
final JettyInstances jettyStrategy;
|
|
||||||
final Properties solrcoreProperties;
|
final Properties solrcoreProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the jetty servers
|
* Creates the jetty servers
|
||||||
|
* @param serverName The key to use for the Jetty server name
|
||||||
* @param numShards Number of shards required
|
* @param numShards Number of shards required
|
||||||
* @param solrcoreProperties Additional properties to add to the solrcore.properties
|
* @param solrcoreProperties Additional properties to add to the solrcore.properties
|
||||||
* @param jettyStategy How to create the JettyInstances
|
|
||||||
* @param coreNames names of the core config folders
|
* @param coreNames names of the core config folders
|
||||||
*/
|
*/
|
||||||
public JettyServerRule(int numShards, Properties solrcoreProperties, JettyInstances jettyStategy, String ...coreNames)
|
public JettyServerRule(String serverName, int numShards, Properties solrcoreProperties, String ...coreNames)
|
||||||
{
|
{
|
||||||
|
this.serverName = serverName;
|
||||||
this.coreNames = coreNames;
|
this.coreNames = coreNames;
|
||||||
this.numShards = numShards;
|
this.numShards = numShards;
|
||||||
this.jettyStrategy = jettyStategy;
|
|
||||||
this.solrcoreProperties = solrcoreProperties;
|
this.solrcoreProperties = solrcoreProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1455,8 +1462,8 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
*/
|
*/
|
||||||
public JettyServerRule(int numShards)
|
public JettyServerRule(int numShards)
|
||||||
{
|
{
|
||||||
|
this.serverName = DEFAULT_TEST_CORENAME;
|
||||||
coreNames = new String[]{DEFAULT_TEST_CORENAME};
|
coreNames = new String[]{DEFAULT_TEST_CORENAME};
|
||||||
this.jettyStrategy = JettyInstances.PER_SHARD;
|
|
||||||
this.numShards = numShards;
|
this.numShards = numShards;
|
||||||
this.solrcoreProperties = new Properties();
|
this.solrcoreProperties = new Properties();
|
||||||
}
|
}
|
||||||
@@ -1466,7 +1473,7 @@ public abstract class AbstractAlfrescoDistributedTest extends SolrTestCaseJ4
|
|||||||
{
|
{
|
||||||
distribSetUp();
|
distribSetUp();
|
||||||
RandVal.uniqueValues = new HashSet(); // reset random values
|
RandVal.uniqueValues = new HashSet(); // reset random values
|
||||||
createServers(jettyStrategy, coreNames, numShards,solrcoreProperties);
|
createServers(serverName, coreNames, numShards,solrcoreProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user