Skip to content

Commit

Permalink
Merge pull request #8826 from poikilotherm/7000-mpconfig-fqdn
Browse files Browse the repository at this point in the history
7000 mpconfig fqdn & siteUrl
  • Loading branch information
kcondon authored Dec 20, 2022
2 parents 880ec33 + 5cdca67 commit e6c033b
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 154 deletions.
59 changes: 45 additions & 14 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1435,32 +1435,63 @@ It's also possible to change these values by stopping Payara, editing ``payara5/
dataverse.fqdn
++++++++++++++

If the Dataverse installation has multiple DNS names, this option specifies the one to be used as the "official" hostname. For example, you may want to have ``dataverse.example.edu``, and not the less appealing ``server-123.example.edu`` to appear exclusively in all the registered global identifiers, etc.

The password reset feature requires ``dataverse.fqdn`` to be configured.

Configuring ``dataverse.fqdn`` is not enough. Read on for the importance of also setting ``dataverse.siteUrl``.
If the Dataverse installation has multiple DNS names, this option specifies the one to be used as the "official"
hostname. For example, you may want to have ``dataverse.example.edu``, and not the less appealing
``server-123.example.edu`` to appear exclusively in all the registered global identifiers, etc.

- Email confirmation links
- Password reset links
- Generating a Private URL
- PID minting
- Exporting to Schema.org format (and showing JSON-LD in HTML's <meta/> tag)
- Exporting to DDI format
- Which Dataverse installation an "external tool" should return to
- URLs embedded in SWORD API responses
- ...

Usually it will follow the pattern ``https://<full-qualified-domain-name>/<some-place-to-go-to>``.
*Only* the FQDN part of your Dataverse installation URL can be determined by setting ``dataverse.fqdn``.

**Notes:**

- The URL will default to using ``https://`` and no additional port information. If that does not suit your setup, you
can define an additional option, ``dataverse.siteUrl``, :ref:`explained below <dataverse.siteUrl>`, which always
takes precedence.
- Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_FQDN``.
Defaults to ``localhost`` when used with ``mp.config.profile=ct``

.. _dataverse.siteUrl:

dataverse.siteUrl
+++++++++++++++++

``dataverse.siteUrl`` is used to configure the URL for your Dataverse installation that you plan to advertise to your users. As explained in the :ref:`installation <importance-of-siteUrl>` docs, this setting is critical for the correct operation of your installation.

For example, your site URL could be https://dataverse.example.edu
``dataverse.siteUrl`` is used to configure the URL for your Dataverse installation that you plan to advertise to your
users. As explained in the :ref:`installation <importance-of-siteUrl>` docs, this setting is critical for the correct
operation of your installation. For example, your site URL could be https://dataverse.example.edu . That is, even though
the server might also be available at uglier URLs such as https://server-123.example.edu, the site URL is the
"official" URL.

That is, even though the server might also be available at uglier URLs such as https://server-123.example.edu the site URL is the "official" URL.
That said, some environments may require using a different URL pattern to access your installation. You might need to
use HTTP without "S", a non-standard port and so on. This is especially useful in development or testing environments.

The ``dataverse.siteUrl`` JVM option can be configured by following the procedure under :ref:`jvm-options` or by editing ``domain.xml`` directly. You can specify the protocol, host, and port number. Your ``domain.xml`` file could look like this, for example:
You can provide any custom tailored site URL via ``dataverse.siteUrl``, which always takes precedence.
Example: ``dataverse.siteUrl=http://localhost:8080``

``<jvm-options>-Ddataverse.siteUrl=https://dataverse.example.edu</jvm-options>``
If you wish to change your site URL by changing the domain configuration, you should edit your ``domain.xml`` directly
to avoid problems with colons in commands. Find a line similar to
``<jvm-options>-Ddataverse.siteUrl=https://dataverse.example.edu</jvm-options>`` and change it. You can specify the
protocol, host, and port number and should not include a trailing slash.

Note that it's also possible to use the ``dataverse.fqdn`` as a variable, if you wish. Here's an example of this as well as a custom port (which is usually not necessary):
**Notes:**

``<jvm-options>-Ddataverse.siteUrl=https://${dataverse.fqdn}:444</jvm-options>``
- This setting may be used in combination with variable replacement, referencing :ref:`dataverse.fqdn` with
``./asadmin create-jvm-options "\-Ddataverse.siteUrl=http\://\${dataverse.fqdn}\:8080"``
- Remember to restart Payara after editing ``domain.xml``.
- Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SITEURL``.
Defaults to ``http://${dataverse.fqdn}:8080`` when used with ``mp.config.profile=ct``
- We are absolutely aware that it's confusing to have both ``dataverse.fqdn`` and ``dataverse.siteUrl``.
https://github.com/IQSS/dataverse/issues/6636 is about resolving this confusion.

We are absolutely aware that it's confusing to have both ``dataverse.fqdn`` and ``dataverse.siteUrl``. https://github.com/IQSS/dataverse/issues/6636 is about resolving this confusion.

.. _dataverse.files.directory:

Expand Down
19 changes: 2 additions & 17 deletions src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import java.io.File;
import java.io.FileInputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -34,6 +32,7 @@
import java.security.PrivateKey;

/* Handlenet imports: */
import edu.harvard.iq.dataverse.util.SystemConfig;
import net.handle.hdllib.AbstractMessage;
import net.handle.hdllib.AbstractResponse;
import net.handle.hdllib.AdminRecord;
Expand Down Expand Up @@ -247,21 +246,7 @@ private String getRegistrationUrl(DvObject dvObject) {
}

public String getSiteUrl() {
logger.log(Level.FINE,"getSiteUrl");
String hostUrl = System.getProperty("dataverse.siteUrl");
if (hostUrl != null && !"".equals(hostUrl)) {
return hostUrl;
}
String hostName = System.getProperty("dataverse.fqdn");
if (hostName == null) {
try {
hostName = InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
return null;
}
}
hostUrl = "https://" + hostName;
return hostUrl;
return SystemConfig.getDataverseSiteUrlStatic();
}

private byte[] readKey(final String file) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse.api;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.SystemConfig;
import javax.ejb.EJB;
Expand Down Expand Up @@ -44,7 +45,7 @@ public Response getInfo() {
@GET
@Path("server")
public Response getServer() {
return response( req -> ok(systemConfig.getDataverseServer()));
return response( req -> ok(JvmSettings.FQDN.lookup()));
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@
import edu.harvard.iq.dataverse.export.DDIExporter;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;

import static edu.harvard.iq.dataverse.util.SystemConfig.FQDN;
import static edu.harvard.iq.dataverse.util.SystemConfig.SITE_URL;

import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.FileUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import edu.harvard.iq.dataverse.util.json.JsonUtil;
import edu.harvard.iq.dataverse.util.xml.XmlPrinter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -1292,7 +1289,7 @@ private static void writeNotesElement(XMLStreamWriter xmlw, DatasetVersionDTO da
// harvesting *all* files are encoded as otherMats; even tabular ones.
private static void createOtherMats(XMLStreamWriter xmlw, List<FileDTO> fileDtos) throws XMLStreamException {
// The preferred URL for this dataverse, for cooking up the file access API links:
String dataverseUrl = getDataverseSiteUrl();
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();

for (FileDTO fileDTo : fileDtos) {
// We'll continue using the scheme we've used before, in DVN2-3: non-tabular files are put into otherMat,
Expand Down Expand Up @@ -1339,7 +1336,7 @@ private static void createOtherMats(XMLStreamWriter xmlw, List<FileDTO> fileDtos

private static void createOtherMatsFromFileMetadatas(XMLStreamWriter xmlw, List<FileMetadata> fileMetadatas) throws XMLStreamException {
// The preferred URL for this dataverse, for cooking up the file access API links:
String dataverseUrl = getDataverseSiteUrl();
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();

for (FileMetadata fileMetadata : fileMetadatas) {
// We'll continue using the scheme we've used before, in DVN2-3: non-tabular files are put into otherMat,
Expand Down Expand Up @@ -1555,33 +1552,6 @@ private static void saveJsonToDisk(String datasetVersionAsJson) throws IOExcepti
Files.write(Paths.get("/tmp/out.json"), datasetVersionAsJson.getBytes());
}

/**
* The "official", designated URL of the site;
* can be defined as a complete URL; or derived from the
* "official" hostname. If none of these options is set,
* defaults to the InetAddress.getLocalHOst() and https;
*/
private static String getDataverseSiteUrl() {
String hostUrl = System.getProperty(SITE_URL);
if (hostUrl != null && !"".equals(hostUrl)) {
return hostUrl;
}
String hostName = System.getProperty(FQDN);
if (hostName == null) {
try {
hostName = InetAddress.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException e) {
hostName = null;
}
}

if (hostName != null) {
return "https://" + hostName;
}

return "http://localhost:8080";
}




Expand Down Expand Up @@ -1893,7 +1863,7 @@ private static void createVarDDI(XMLStreamWriter xmlw, DataVariable dv, FileMeta
}

private static void createFileDscr(XMLStreamWriter xmlw, DatasetVersion datasetVersion) throws XMLStreamException {
String dataverseUrl = getDataverseSiteUrl();
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();
for (FileMetadata fileMetadata : datasetVersion.getFileMetadatas()) {
DataFile dataFile = fileMetadata.getDataFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void init(ServletConfig config) throws ServletException {
}

setRepository = new DataverseXoaiSetRepository(setService);
itemRepository = new DataverseXoaiItemRepository(recordService, datasetService, systemConfig.getDataverseSiteUrl());
itemRepository = new DataverseXoaiItemRepository(recordService, datasetService, SystemConfig.getDataverseSiteUrlStatic());

repositoryConfiguration = createRepositoryConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum JvmSettings {
// GENERAL SETTINGS
VERSION(PREFIX, "version"),
BUILD(PREFIX, "build"),
FQDN(PREFIX, "fqdn"),
SITE_URL(PREFIX, "siteUrl"),

// API SETTINGS
SCOPE_API(PREFIX, "api"),
Expand Down
Loading

0 comments on commit e6c033b

Please sign in to comment.