Skip to content

Commit

Permalink
Merge pull request #334 from europeana/EA-4023-page-rank-zookeeper
Browse files Browse the repository at this point in the history
updated page-rank solr to use the zookeeper
  • Loading branch information
gsergiu authored Dec 16, 2024
2 parents 8ddc125 + c5c311a commit 4e33e59
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ public class EntityManagementConfiguration implements InitializingBean {

@Value("${entitymanagement.solr.pr.url}")
private String prSolrUrl;

@Value("${entitymanagement.solr.pr.zookeeper.url:}")
private String prSolrZookeeperUrl;

@Value("${entitymanagement.solr.pr.collection}")
private String prSolrCollection;

@Value("${europeana.searchapi.urlPrefix}")
private String searchApiUrlPrefix;

Expand Down Expand Up @@ -500,5 +506,13 @@ public int getZohoSyncDeleteOffsetDays() {
public String getSlackWebHook() {
return slackWebHook;
}

public String getPrSolrZookeeperUrl() {
return prSolrZookeeperUrl;
}

public String getPrSolrCollection() {
return prSolrCollection;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package eu.europeana.entitymanagement.config;

import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration;
import eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -14,6 +12,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import eu.europeana.entitymanagement.common.config.EntityManagementConfiguration;
import eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants;

@Configuration
public class SolrConfig {
Expand All @@ -28,52 +28,57 @@ public SolrConfig(EntityManagementConfiguration emConfiguration) {

@Bean(AppConfigConstants.BEAN_PR_SOLR_CLIENT)
public SolrClient pageRankSolrClient() {
logger.info("Configuring pageRank solr client at the url: {}", emConfiguration.getPrSolrUrl());
return new HttpSolrClient.Builder(emConfiguration.getPrSolrUrl()).build();
if (StringUtils.isNotBlank(emConfiguration.getPrSolrZookeeperUrl())) {
return initSolrCloudClient(emConfiguration.getPrSolrZookeeperUrl(), emConfiguration.getIndexingSolrTimeoutMillis(),
emConfiguration.getPrSolrCollection());
} else {
return initSolrClient(emConfiguration.getPrSolrUrl(), emConfiguration.getIndexingSolrTimeoutMillis());
}
}

@Bean(AppConfigConstants.BEAN_INDEXING_SOLR_CLIENT)
public SolrClient indexingSolrClient() {
if (StringUtils.isNotBlank(emConfiguration.getIndexingSolrZookeeperUrl())) {
return initSolrCloudClient();
return initSolrCloudClient(emConfiguration.getIndexingSolrZookeeperUrl(), emConfiguration.getIndexingSolrTimeoutMillis(),
emConfiguration.getIndexingSolrCollection());
} else {
return initSolrClient();
return initSolrClient(emConfiguration.getIndexingSolrUrl(), emConfiguration.getIndexingSolrTimeoutMillis());
}
}

private SolrClient initSolrClient() {
private SolrClient initSolrClient(String solrUrl, int timeoutMillis) {
logger.info(
"Configuring indexing solr client at the url: {}", emConfiguration.getIndexingSolrUrl());
"Configuring solr client at the url: {}", solrUrl);

if (emConfiguration.getIndexingSolrUrl().contains(",")) {
if (solrUrl.contains(",")) {
LBHttpSolrClient.Builder builder = new LBHttpSolrClient.Builder();
return builder
.withBaseSolrUrls(emConfiguration.getIndexingSolrUrl().split(","))
.withConnectionTimeout(emConfiguration.getIndexingSolrTimeoutMillis())
.withBaseSolrUrls(solrUrl.split(","))
.withConnectionTimeout(timeoutMillis)
.build();
} else {
HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
return builder
.withBaseSolrUrl(emConfiguration.getIndexingSolrUrl())
.withConnectionTimeout(emConfiguration.getIndexingSolrTimeoutMillis())
.withBaseSolrUrl(solrUrl)
.withConnectionTimeout(timeoutMillis)
.build();
}
}

private SolrClient initSolrCloudClient() {
private SolrClient initSolrCloudClient(String solrZookeeperUrl, int timeout, String solrCollection) {
logger.info(
"Configuring indexing solr client with the zookeperurls: {} and collection: {}",
emConfiguration.getIndexingSolrUrl(),
emConfiguration.getIndexingSolrCollection());
"Configuring solr client with the zookeperurls: {} and collection: {}",
solrZookeeperUrl,
solrCollection);

String[] solrZookeeperUrls = emConfiguration.getIndexingSolrZookeeperUrl().trim().split(",");
String[] solrZookeeperUrlsList = solrZookeeperUrl.trim().split(",");

CloudSolrClient client =
new CloudSolrClient.Builder(Arrays.asList(solrZookeeperUrls), Optional.empty())
.withConnectionTimeout(emConfiguration.getIndexingSolrTimeoutMillis())
new CloudSolrClient.Builder(Arrays.asList(solrZookeeperUrlsList), Optional.empty())
.withConnectionTimeout(timeout)
.build();

client.setDefaultCollection(emConfiguration.getIndexingSolrCollection());
client.setDefaultCollection(solrCollection);
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ datasources.config=/datasources.xml
#string value representing the key used for JWT signature verification
europeana.apikey.jwttoken.signaturekey=

#zookeeper url for the page-rank solr (if not present, normal is used)
#entitymanagement.solr.pr.zookeeper.url=localhost:9983

#the name of the page-rank solr collection (mandatory when using zookeeper url)
entitymanagement.solr.pr.collection=pagerank1

#url for the page rank solr
#entitymanagement.solr.pr.url=
entitymanagement.solr.pr.url=http://annotation-entity-test.eanadev.org:9393/solr/pagerank1
Expand Down

0 comments on commit 4e33e59

Please sign in to comment.