mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Add SolrStatisticsCore and MockSolrStatisticsCore beans
This commit is contained in:
@@ -20,12 +20,9 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -146,6 +143,8 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
private ConfigurationService configurationService;
|
||||
@Autowired(required = true)
|
||||
private ClientInfoService clientInfoService;
|
||||
@Autowired
|
||||
private SolrStatisticsCore solrStatisticsCore;
|
||||
|
||||
/** URL to the current-year statistics core. Prior-year shards will have a year suffixed. */
|
||||
private String statisticsCoreURL;
|
||||
@@ -177,31 +176,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
statisticsCoreURL = configurationService.getProperty("solr-statistics.server");
|
||||
|
||||
if (null != statisticsCoreURL) {
|
||||
Path statisticsPath = Paths.get(new URI(statisticsCoreURL).getPath());
|
||||
statisticsCoreBase = statisticsPath
|
||||
.getName(statisticsPath.getNameCount() - 1)
|
||||
.toString();
|
||||
} else {
|
||||
statisticsCoreBase = null;
|
||||
}
|
||||
|
||||
log.info("solr-statistics.server: {}", statisticsCoreURL);
|
||||
log.info("usage-statistics.dbfile: {}",
|
||||
configurationService.getProperty("usage-statistics.dbfile"));
|
||||
|
||||
HttpSolrClient server = null;
|
||||
|
||||
if (statisticsCoreURL != null) {
|
||||
try {
|
||||
server = new HttpSolrClient.Builder(statisticsCoreURL).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error accessing Solr server configured in 'solr-statistics.server'", e);
|
||||
}
|
||||
}
|
||||
solr = server;
|
||||
solr = solrStatisticsCore.getSolr();
|
||||
|
||||
// Read in the file so we don't have to do it all the time
|
||||
//spiderIps = SpiderDetector.getSpiderIpAddresses();
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.statistics;
|
||||
|
||||
import static org.apache.logging.log4j.LogManager.getLogger;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.solr.client.solrj.SolrClient;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Bean containing the {@link SolrClient} for the statistics core
|
||||
*/
|
||||
public class SolrStatisticsCore {
|
||||
|
||||
private static Logger log = getLogger(SolrStatisticsCore.class);
|
||||
|
||||
protected SolrClient solr = null;
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
/**
|
||||
* Returns the {@link SolrClient} for the Statistics core.
|
||||
* Initializes it if needed.
|
||||
* @return The {@link SolrClient} for the Statistics core
|
||||
*/
|
||||
public SolrClient getSolr() {
|
||||
if (solr == null) {
|
||||
initSolr();
|
||||
}
|
||||
return solr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the statistics {@link SolrClient}.
|
||||
*/
|
||||
protected void initSolr() {
|
||||
|
||||
String solrService = configurationService.getProperty("solr-statistics.server");
|
||||
|
||||
log.info("solr-statistics.server: {}", solrService);
|
||||
log.info("usage-statistics.dbfile: {}", configurationService.getProperty("usage-statistics.dbfile"));
|
||||
|
||||
try {
|
||||
solr = new HttpSolrClient.Builder(solrService).build();
|
||||
} catch (Exception e) {
|
||||
log.error("Error accessing Solr server configured in 'solr-statistics.server'", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,4 +44,6 @@
|
||||
class="org.dspace.statistics.MockSolrLoggerServiceImpl"
|
||||
lazy-init="true"/>
|
||||
|
||||
<bean class="org.dspace.statistics.solr.MockSolrStatisticsCore" autowire-candidate="true"/>
|
||||
|
||||
</beans>
|
||||
|
@@ -63,9 +63,8 @@ public class MockSolrServer {
|
||||
* Wrap an instance of embedded Solr.
|
||||
*
|
||||
* @param coreName name of the core to serve.
|
||||
* @throws Exception passed through.
|
||||
*/
|
||||
public MockSolrServer(final String coreName) throws Exception {
|
||||
public MockSolrServer(final String coreName) {
|
||||
this.coreName = coreName;
|
||||
initSolrServer();
|
||||
}
|
||||
@@ -79,9 +78,8 @@ public class MockSolrServer {
|
||||
|
||||
/**
|
||||
* Ensure that this instance's core is loaded. Create it if necessary.
|
||||
* @throws Exception passed through.
|
||||
*/
|
||||
protected void initSolrServer() throws Exception {
|
||||
protected void initSolrServer() {
|
||||
solrServer = loadedCores.get(coreName);
|
||||
if (solrServer == null) {
|
||||
solrServer = initSolrServerForCore(coreName);
|
||||
|
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.statistics.solr;
|
||||
|
||||
import org.dspace.solr.MockSolrServer;
|
||||
import org.dspace.statistics.SolrStatisticsCore;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MockSolrStatisticsCore extends SolrStatisticsCore implements DisposableBean {
|
||||
|
||||
private MockSolrServer mockSolrServer = new MockSolrServer("statistics");
|
||||
|
||||
@Override
|
||||
public void initSolr() {
|
||||
if (solr == null) {
|
||||
solr = mockSolrServer.getSolrServer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
mockSolrServer.destroy();
|
||||
}
|
||||
}
|
@@ -37,4 +37,7 @@
|
||||
class="org.dspace.statistics.MockSolrLoggerServiceImpl"
|
||||
lazy-init="true"/>
|
||||
|
||||
<bean id="org.dspace.statistics.solr.SolrStatisticsCore"
|
||||
class="org.dspace.statistics.solr.MockSolrStatisticsCore" autowire-candidate="true"/>
|
||||
|
||||
</beans>
|
||||
|
@@ -30,4 +30,6 @@
|
||||
<!-- Statistics services are both lazy loaded (by name), as you are likely just using ONE of them and not both -->
|
||||
<bean id="solrLoggerService" class="org.dspace.statistics.SolrLoggerServiceImpl" lazy-init="true"/>
|
||||
|
||||
<bean class="org.dspace.statistics.SolrStatisticsCore" autowire-candidate="true"/>
|
||||
|
||||
</beans>
|
||||
|
Reference in New Issue
Block a user