From 244c3a8eeb5135aba1c4c098adb62461752b80f7 Mon Sep 17 00:00:00 2001 From: Dominik Riemer Date: Fri, 10 Jan 2025 05:37:42 +0100 Subject: [PATCH] feat: Update asset and file directories upon restart --- .../DefaultSpCoreConfiguration.java | 4 +-- .../manager/setup/StreamPipesEnvChecker.java | 31 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/DefaultSpCoreConfiguration.java b/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/DefaultSpCoreConfiguration.java index b669b3e4b7..0514006380 100644 --- a/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/DefaultSpCoreConfiguration.java +++ b/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/DefaultSpCoreConfiguration.java @@ -40,12 +40,12 @@ public SpCoreConfiguration make() { return coreCfg; } - private String makeAssetLocation() { + public String makeAssetLocation() { return makeStreamPipesHomeLocation() + "assets"; } - private String makeFileLocation() { + public String makeFileLocation() { return makeStreamPipesHomeLocation() + "files"; } diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/StreamPipesEnvChecker.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/StreamPipesEnvChecker.java index 70e5a8aa59..0062419eb4 100644 --- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/StreamPipesEnvChecker.java +++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/StreamPipesEnvChecker.java @@ -20,10 +20,10 @@ import org.apache.streampipes.commons.environment.Environment; import org.apache.streampipes.commons.environment.Environments; +import org.apache.streampipes.model.configuration.DefaultSpCoreConfiguration; import org.apache.streampipes.model.configuration.JwtSigningMode; import org.apache.streampipes.model.configuration.LocalAuthConfig; import org.apache.streampipes.model.configuration.SpCoreConfiguration; -import org.apache.streampipes.storage.api.ISpCoreConfigurationStorage; import org.apache.streampipes.storage.management.StorageDispatcher; import org.slf4j.Logger; @@ -37,7 +37,6 @@ public class StreamPipesEnvChecker { private static final Logger LOG = LoggerFactory.getLogger(StreamPipesEnvChecker.class); - private ISpCoreConfigurationStorage configStorage; private SpCoreConfiguration coreConfig; private final Environment env; @@ -47,7 +46,7 @@ public StreamPipesEnvChecker() { } public void updateEnvironmentVariables() { - this.configStorage = StorageDispatcher + var configStorage = StorageDispatcher .INSTANCE .getNoSqlStore() .getSpCoreConfigurationStorage(); @@ -56,11 +55,29 @@ public void updateEnvironmentVariables() { this.coreConfig = configStorage.get(); LOG.info("Checking and updating environment variables..."); - updateJwtSettings(); + var shouldUpdateJwtConfig = updateJwtSettings(); + var shouldUpdateDirectoryConfig = updateDirectorySettings(); + + if (shouldUpdateJwtConfig || shouldUpdateDirectoryConfig) { + configStorage.updateElement(coreConfig); + } } } - private void updateJwtSettings() { + private boolean updateDirectorySettings() { + if (env.getCoreAssetBaseDir().exists()) { + LOG.info("Using asset directory provided by environment variable {}", + env.getCoreAssetBaseDir().getEnvVariableName()); + var defaultCoreConfig = new DefaultSpCoreConfiguration(); + coreConfig.setFilesDir(defaultCoreConfig.makeFileLocation()); + coreConfig.setAssetDir(defaultCoreConfig.makeAssetLocation()); + return true; + } else { + return false; + } + } + + private boolean updateJwtSettings() { LocalAuthConfig localAuthConfig = coreConfig.getLocalAuthConfig(); boolean incompleteConfig = false; var signingMode = env.getJwtSigningMode(); @@ -108,7 +125,9 @@ private void updateJwtSettings() { if (!incompleteConfig) { LOG.info("Updating local auth config with signing mode {}", localAuthConfig.getJwtSigningMode().name()); coreConfig.setLocalAuthConfig(localAuthConfig); - configStorage.updateElement(coreConfig); + return true; + } else { + return false; } }