-
Notifications
You must be signed in to change notification settings - Fork 535
Configurable docroot via MicroProfile Config #9819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
98e5b3f
fix(ct): enable sane default for upload storage location in containers
poikilotherm d71cdf2
fix(ct,conf): switch to different approach to default upload location
poikilotherm a4ec3a6
feat(conf): introduce ConfigCheckService to validate config on startu…
poikilotherm 6999093
feat(conf): make docroot location configurable #9662
poikilotherm 0e29e3e
feat(conf): add some more details to error output if available in con…
poikilotherm 4aac8f1
fix(ct): make sure file permissions on app data volume when using com…
poikilotherm 1c256e9
refactor(conf): make docroot and uploads locations more precise and d…
poikilotherm 2913a52
refactor(conf): simplify sitemap output location lookup using new doc…
poikilotherm 554d7ce
Merge branch 'develop' into 9662-docroot-mpc
poikilotherm 1db0042
build(settings): migrate ConfigCheckService to Jakarta EE 10
poikilotherm 72722e7
refactor(collection): make logo location non-static #9662
poikilotherm 431afed
fix(webapp): revert to hardcoded default for dirs in glassfish-web.xm…
poikilotherm ec131f8
fix(settings): make ConfigCheckService use Files.exist #9662
poikilotherm 848f564
test(settings): make ConfigCheckService actually testable #9662
poikilotherm c49ee0a
test(settings): make ConfigCheckService require absolute paths #9662
poikilotherm 28ddccc
fix(test,settings): make SiteMapUtilTest use test.filesDir property
poikilotherm ba8e6d2
fix(test,settings): provide default for test.filesDir
poikilotherm 396ffff
style(settings): unify default dataverse.files dir options
poikilotherm d37eedf
docs(settings): refactor docs on the important directories and how to…
poikilotherm 880b34c
Merge branch 'develop' into 9662-docroot-mpc
poikilotherm efaf5d5
refactor(test,sitemap): make SiteMapUtilTest use better JUnit5 checks
poikilotherm 034a972
Merge branch 'develop' into 9662-docroot-mpc
poikilotherm fce664f
Merge branch 'develop' into 9662-docroot-mpc
poikilotherm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/edu/harvard/iq/dataverse/settings/ConfigCheckService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package edu.harvard.iq.dataverse.settings; | ||
|
|
||
| import edu.harvard.iq.dataverse.util.FileUtil; | ||
|
|
||
| import jakarta.annotation.PostConstruct; | ||
| import jakarta.ejb.DependsOn; | ||
| import jakarta.ejb.Singleton; | ||
| import jakarta.ejb.Startup; | ||
| import java.io.IOException; | ||
| import java.nio.file.FileSystemException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.Map; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| @Startup | ||
| @Singleton | ||
| @DependsOn("StartupFlywayMigrator") | ||
| public class ConfigCheckService { | ||
|
|
||
| private static final Logger logger = Logger.getLogger(ConfigCheckService.class.getCanonicalName()); | ||
|
|
||
| public static class ConfigurationError extends RuntimeException { | ||
| public ConfigurationError(String message) { | ||
| super(message); | ||
| } | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void startup() { | ||
| if (!checkSystemDirectories()) { | ||
| throw new ConfigurationError("Not all configuration checks passed successfully. See logs above."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * In this method, we check the existence and write-ability of all important directories we use during | ||
| * normal operations. It does not include checks for the storage system. If directories are not available, | ||
| * try to create them (and fail when not allowed to). | ||
| * | ||
| * @return True if all checks successful, false otherwise. | ||
| */ | ||
| public boolean checkSystemDirectories() { | ||
| Map<Path, String> paths = Map.of( | ||
| Path.of(JvmSettings.UPLOADS_DIRECTORY.lookup()), "temporary JSF upload space (see " + JvmSettings.UPLOADS_DIRECTORY.getScopedKey() + ")", | ||
| Path.of(FileUtil.getFilesTempDirectory()), "temporary processing space (see " + JvmSettings.FILES_DIRECTORY.getScopedKey() + ")", | ||
| Path.of(JvmSettings.DOCROOT_DIRECTORY.lookup()), "docroot space (see " + JvmSettings.DOCROOT_DIRECTORY.getScopedKey() + ")"); | ||
|
|
||
| boolean success = true; | ||
| for (Path path : paths.keySet()) { | ||
| // Check if the configured path is absolute - avoid potential problems with relative paths this way | ||
| if (! path.isAbsolute()) { | ||
| logger.log(Level.SEVERE, () -> "Configured directory " + path + " for " + paths.get(path) + " is not absolute"); | ||
| success = false; | ||
| continue; | ||
| } | ||
|
|
||
| if (! Files.exists(path)) { | ||
| try { | ||
| Files.createDirectories(path); | ||
| } catch (IOException e) { | ||
| String details; | ||
| if (e instanceof FileSystemException) { | ||
| details = ": " + e.getClass(); | ||
| } else { | ||
| details = ""; | ||
| } | ||
|
|
||
| logger.log(Level.SEVERE, () -> "Could not create directory " + path + " for " + paths.get(path) + details); | ||
| success = false; | ||
| } | ||
| } else if (!Files.isWritable(path)) { | ||
| logger.log(Level.SEVERE, () -> "Directory " + path + " for " + paths.get(path) + " exists, but is not writeable"); | ||
| success = false; | ||
| } | ||
| } | ||
| return success; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.