Skip to content

Commit

Permalink
feat: Update asset and file directories upon restart (#3416)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer authored Jan 10, 2025
1 parent c36e260 commit bb7e39c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -47,7 +46,7 @@ public StreamPipesEnvChecker() {
}

public void updateEnvironmentVariables() {
this.configStorage = StorageDispatcher
var configStorage = StorageDispatcher
.INSTANCE
.getNoSqlStore()
.getSpCoreConfigurationStorage();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit bb7e39c

Please sign in to comment.