Skip to content
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

feat: Update asset and file directories upon restart #3416

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading