-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9819 from poikilotherm/9662-docroot-mpc
Configurable docroot via MicroProfile Config
- Loading branch information
Showing
17 changed files
with
351 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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.