Skip to content

Commit

Permalink
Merge pull request #8825 from poikilotherm/7000-mpconfig-solr
Browse files Browse the repository at this point in the history
7000 mpconfig solr
  • Loading branch information
kcondon authored Dec 21, 2022
2 parents 3bdc075 + d4d1a2c commit 18372cd
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 57 deletions.
74 changes: 74 additions & 0 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,61 @@ Defaults to ``5432``, the default PostgreSQL port.

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_DB_PORT``.

.. _dataverse.solr.host:

dataverse.solr.host
+++++++++++++++++++

The hostname of a Solr server to connect to. Remember to restart / redeploy Dataverse after changing the setting
(as with :ref:`:SolrHostColonPort`).

Defaults to ``localhost``.

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SOLR_HOST``.
Defaults to ``solr``, when used with ``mp.config.profile=ct`` (:ref:`see below <:ApplicationServerSettings>`).

dataverse.solr.port
+++++++++++++++++++

The Solr server port to connect to. Remember to restart / redeploy Dataverse after changing the setting
(as with :ref:`:SolrHostColonPort`).

Defaults to ``8983``, the default Solr port.

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SOLR_PORT``.

dataverse.solr.core
+++++++++++++++++++

The name of the Solr core to use for this Dataverse installation. Might be used to switch to a different core quickly.
Remember to restart / redeploy Dataverse after changing the setting (as with :ref:`:SolrHostColonPort`).

Defaults to ``collection1``.

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SOLR_CORE``.

dataverse.solr.protocol
+++++++++++++++++++++++

The Solr server URL protocol for the connection. Remember to restart / redeploy Dataverse after changing the setting
(as with :ref:`:SolrHostColonPort`).

Defaults to ``http``, but might be set to ``https`` for extra secure Solr installations.

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SOLR_PROTOCOL``.

dataverse.solr.path
+++++++++++++++++++

The path part of the Solr endpoint URL (e.g. ``/solr/collection1`` of ``http://localhost:8389/solr/collection1``).
Might be used to target a Solr API at non-default places. Remember to restart / redeploy Dataverse after changing the
setting (as with :ref:`:SolrHostColonPort`).

Defaults to ``/solr/${dataverse.solr.core}``, interpolating the core name when used. Make sure to include the variable
when using it to configure your core name!

Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SOLR_PATH``.

dataverse.rserve.host
+++++++++++++++++++++

Expand Down Expand Up @@ -1847,6 +1902,21 @@ To facilitate large file upload and download, the Dataverse Software installer b

and restart Payara to apply your change.

mp.config.profile
+++++++++++++++++

MicroProfile Config 2.0 defines the `concept of "profiles" <https://download.eclipse.org/microprofile/microprofile-config-2.0/microprofile-config-spec-2.0.html#configprofile>`_.
They can be used to change configuration values by context. This is used in Dataverse to change some configuration
defaults when used inside container context rather classic installations.

As per the spec, you will need to set the configuration value ``mp.config.profile`` to ``ct`` as early as possible.
This is best done with a system property:

``./asadmin create-system-properties 'mp.config.profile=ct'``

You might also create your own profiles and use these, please refer to the upstream documentation linked above.


.. _database-settings:

Database Settings
Expand Down Expand Up @@ -2334,13 +2404,17 @@ Limit the number of files in a zip that your Dataverse installation will accept.

``curl -X PUT -d 2048 http://localhost:8080/api/admin/settings/:ZipUploadFilesLimit``

.. _:SolrHostColonPort:

:SolrHostColonPort
++++++++++++++++++

By default your Dataverse installation will attempt to connect to Solr on port 8983 on localhost. Use this setting to change the hostname or port. You must restart Payara after making this change.

``curl -X PUT -d localhost:8983 http://localhost:8080/api/admin/settings/:SolrHostColonPort``

**Note:** instead of using a database setting, you could alternatively use JVM settings like :ref:`dataverse.solr.host`.

:SolrFullTextIndexing
+++++++++++++++++++++

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import edu.harvard.iq.dataverse.datavariable.VariableMetadataUtil;
import edu.harvard.iq.dataverse.datavariable.VariableServiceBean;
import edu.harvard.iq.dataverse.harvest.client.HarvestingClient;
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.FileUtil;
import edu.harvard.iq.dataverse.util.StringUtil;
Expand Down Expand Up @@ -88,13 +89,16 @@
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.BodyContentHandler;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.xml.sax.ContentHandler;

@Stateless
@Named
public class IndexServiceBean {

private static final Logger logger = Logger.getLogger(IndexServiceBean.class.getCanonicalName());
private static final Config config = ConfigProvider.getConfig();

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;
Expand Down Expand Up @@ -155,13 +159,18 @@ public class IndexServiceBean {
public static final String HARVESTED = "Harvested";
private String rootDataverseName;
private Dataverse rootDataverseCached;
private SolrClient solrServer;
SolrClient solrServer;

private VariableMetadataUtil variableMetadataUtil;

@PostConstruct
public void init() {
String urlString = "http://" + systemConfig.getSolrHostColonPort() + "/solr/collection1";
// Get from MPCONFIG. Might be configured by a sysadmin or simply return the default shipped with
// resources/META-INF/microprofile-config.properties.
String protocol = JvmSettings.SOLR_PROT.lookup();
String path = JvmSettings.SOLR_PATH.lookup();

String urlString = protocol + "://" + systemConfig.getSolrHostColonPort() + path;
solrServer = new HttpSolrClient.Builder(urlString).build();

rootDataverseName = findRootDataverseCached().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
*/
package edu.harvard.iq.dataverse.search;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.io.IOException;
import java.util.logging.Logger;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.inject.Named;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import java.io.IOException;
import java.util.logging.Logger;

/**
*
Expand All @@ -38,9 +40,13 @@ public class SolrClientService {

@PostConstruct
public void init() {
String urlString = "http://" + systemConfig.getSolrHostColonPort() + "/solr/collection1";
solrClient = new HttpSolrClient.Builder(urlString).build();
// Get from MPCONFIG. Might be configured by a sysadmin or simply return the default shipped with
// resources/META-INF/microprofile-config.properties.
String protocol = JvmSettings.SOLR_PROT.lookup();
String path = JvmSettings.SOLR_PATH.lookup();

String urlString = protocol + "://" + systemConfig.getSolrHostColonPort() + path;
solrClient = new HttpSolrClient.Builder(urlString).build();
}

@PreDestroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import edu.harvard.iq.dataverse.DvObject;
import edu.harvard.iq.dataverse.DvObjectServiceBean;
import edu.harvard.iq.dataverse.FileMetadata;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -36,9 +34,7 @@
public class SolrIndexServiceBean {

private static final Logger logger = Logger.getLogger(SolrIndexServiceBean.class.getCanonicalName());

@EJB
SystemConfig systemConfig;

@EJB
DvObjectServiceBean dvObjectService;
@EJB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public enum JvmSettings {
FQDN(PREFIX, "fqdn"),
SITE_URL(PREFIX, "siteUrl"),

// SOLR INDEX SETTINGS
SCOPE_SOLR(PREFIX, "solr"),
SOLR_HOST(SCOPE_SOLR, "host"),
SOLR_PORT(SCOPE_SOLR, "port"),
SOLR_PROT(SCOPE_SOLR, "protocol"),
SOLR_CORE(SCOPE_SOLR, "core"),
SOLR_PATH(SCOPE_SOLR, "path"),

// RSERVE CONNECTION
SCOPE_RSERVE(PREFIX, "rserve"),
RSERVE_HOST(SCOPE_RSERVE, "host"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ public enum Key {
*
*/
SearchRespectPermissionRoot,
/** Solr hostname and port, such as "localhost:8983". */
/**
* Solr hostname and port, such as "localhost:8983".
* @deprecated New installations should not use this database setting, but use {@link JvmSettings#SOLR_HOST}
* and {@link JvmSettings#SOLR_PORT}.
*/
@Deprecated(forRemoval = true, since = "2022-12-23")
SolrHostColonPort,
/** Enable full-text indexing in solr up to max file size */
SolrFullTextIndexing, //true or false (default)
Expand Down
60 changes: 33 additions & 27 deletions src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.validation.PasswordValidatorUtil;
import org.passay.CharacterRule;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonString;
import javax.json.JsonValue;
import java.io.StringReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
Expand All @@ -26,18 +37,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.passay.CharacterRule;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonString;
import javax.json.JsonValue;

/**
* System-wide configuration
*/
Expand Down Expand Up @@ -75,12 +74,6 @@ public class SystemConfig {
*/
private static final String PASSWORD_RESET_TIMEOUT_IN_MINUTES = "dataverse.auth.password-reset-timeout-in-minutes";

/**
* A common place to find the String for a sane Solr hostname:port
* combination.
*/
private String saneDefaultForSolrHostColonPort = "localhost:8983";

/**
* The default number of datafiles that we allow to be created through
* zip file upload.
Expand Down Expand Up @@ -143,15 +136,28 @@ public String getVersion(boolean withBuildNumber) {

return appVersion;
}


/**
* Retrieve the Solr endpoint in "host:port" form, to be used with a Solr client.
*
* This will retrieve the setting from either the database ({@link SettingsServiceBean.Key#SolrHostColonPort}) or
* via Microprofile Config API (properties {@link JvmSettings#SOLR_HOST} and {@link JvmSettings#SOLR_PORT}).
*
* A database setting always takes precedence. If not given via other config sources, a default from
* <code>resources/META-INF/microprofile-config.properties</code> is used. (It's possible to use profiles.)
*
* @return Solr endpoint as string "hostname:port"
*/
public String getSolrHostColonPort() {
String SolrHost;
if ( System.getenv("SOLR_SERVICE_HOST") != null && System.getenv("SOLR_SERVICE_HOST") != ""){
SolrHost = System.getenv("SOLR_SERVICE_HOST");
}
else SolrHost = saneDefaultForSolrHostColonPort;
String solrHostColonPort = settingsService.getValueForKey(SettingsServiceBean.Key.SolrHostColonPort, SolrHost);
return solrHostColonPort;
// Get from MPCONFIG. Might be configured by a sysadmin or simply return the default shipped with
// resources/META-INF/microprofile-config.properties.
// NOTE: containers should use system property mp.config.profile=ct to use sane container usage default
String host = JvmSettings.SOLR_HOST.lookup();
String port = JvmSettings.SOLR_PORT.lookup();

// DB setting takes precedence over all. If not present, will return default from above.
return Optional.ofNullable(settingsService.getValueForKey(SettingsServiceBean.Key.SolrHostColonPort))
.orElse(host + ":" + port);
}

public boolean isProvCollectionEnabled() {
Expand Down Expand Up @@ -265,7 +271,7 @@ public static String getDataverseSiteUrlStatic() {
return siteUrl.get();
}

// Other wise try to lookup dataverse.fqdn setting and default to HTTPS
// Otherwise try to lookup dataverse.fqdn setting and default to HTTPS
Optional<String> fqdn = JvmSettings.FQDN.lookupOptional();
if (fqdn.isPresent()) {
return "https://" + fqdn.get();
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/META-INF/microprofile-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ dataverse.build=
%ct.dataverse.fqdn=localhost
%ct.dataverse.siteUrl=http://${dataverse.fqdn}:8080

# SEARCH INDEX
dataverse.solr.host=localhost
# Activating mp config profile -Dmp.config.profile=ct changes default to "solr" as DNS name
%ct.dataverse.solr.host=solr
dataverse.solr.port=8983
dataverse.solr.protocol=http
dataverse.solr.core=collection1
dataverse.solr.path=/solr/${dataverse.solr.core}

# DATABASE
dataverse.db.host=localhost
dataverse.db.port=5432
Expand Down
Loading

0 comments on commit 18372cd

Please sign in to comment.