SEARCH-56: Switching to use external properties for solr.host,port,baseurl

This commit is contained in:
Gethin James
2016-06-08 12:20:21 +02:00
parent 58a6d0acd3
commit c1c20bf356
2 changed files with 10 additions and 47 deletions

View File

@@ -128,6 +128,7 @@ import org.alfresco.solr.client.SOLRAPIClient;
import org.alfresco.solr.client.SOLRAPIClient.GetTextContentResponse;
import org.alfresco.solr.client.StringPropertyValue;
import org.alfresco.solr.client.Transaction;
import org.alfresco.solr.config.ConfigUtil;
import org.alfresco.solr.content.SolrContentStore;
import org.alfresco.solr.content.SolrContentUrlBuilder;
import org.alfresco.solr.tracker.IndexHealthReport;
@@ -309,21 +310,12 @@ public class SolrInformationServer implements InformationServer
contentStreamLimit = Integer.parseInt(p.getProperty("alfresco.contentStreamLimit", "10000000"));
// build base URL - host and port have to come from configuration.
Properties props = AlfrescoSolrDataModel.getCommonConfig();
port = Integer.parseInt(props.getProperty("solr.port", getHttpPort("8080")));
String defaultHost;
try
{
defaultHost = InetAddress.getLocalHost().getHostName();
}
catch (UnknownHostException e)
{
defaultHost = "localhost";
}
hostName = props.getProperty("solr.host", defaultHost);
baseUrl = props.getProperty("solr.baseUrl", "/solr4");
hostName = ConfigUtil.locateProperty("solr.host", props.getProperty("solr.host"));
String portNumber = ConfigUtil.locateProperty("solr.port", props.getProperty("solr.port"));
port = Integer.parseInt(portNumber);
baseUrl = ConfigUtil.locateProperty("solr.baseurl", props.getProperty("solr.baseurl"));
baseUrl = (baseUrl.startsWith("/") ? "" : "/") + baseUrl + "/" + core.getName() + "/";
}
@@ -3858,39 +3850,6 @@ public class SolrInformationServer implements InformationServer
return hostName;
}
private String getHttpPort(String defaultPort)
{
try
{
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
QueryExp query = Query.and(Query.eq(Query.attr("scheme"), Query.value("http")), Query.eq(Query.attr("protocol"), Query.value("HTTP/1.1")));
Set<ObjectName> objectNames = mBeanServer.queryNames(null, query);
if (objectNames != null && objectNames.size() > 0) {
for (ObjectName objectName : objectNames) {
String name = objectName.toString();
if (name.indexOf("port=") > -1) {
String[] parts = name.split("port=");
String port = parts[1];
try {
Integer.parseInt(port);
return port;
} catch (NumberFormatException e) {
log.error("Error parsing http port:" + port);
return defaultPort;
}
}
}
}
}
catch(Throwable t)
{
log.error("Error getting https port:", t);
}
return defaultPort;
}
public void setCleanContentTxnFloor(long cleanContentTxnFloor)
{
this.cleanContentTxnFloor = cleanContentTxnFloor;

View File

@@ -1,5 +1,9 @@
# Shared Properties file
#Host details an external client would use to connect to Solr
solr.host=localhost
solr.port=8983
solr.baseurl=/solr
# Properties treated as identifiers when indexed