Skip to content

Commit

Permalink
Fix Settings Cache (#19053)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0164643)
  • Loading branch information
mohityadav766 committed Dec 16, 2024
1 parent 42320d7 commit d2d7212
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.openmetadata.service.exception.JsonMappingExceptionMapper;
import org.openmetadata.service.exception.OMErrorPageHandler;
import org.openmetadata.service.fernet.Fernet;
import org.openmetadata.service.governance.workflows.WorkflowHandler;
import org.openmetadata.service.jdbi3.CollectionDAO;
import org.openmetadata.service.jdbi3.EntityRepository;
import org.openmetadata.service.jdbi3.MigrationDAO;
Expand Down Expand Up @@ -173,6 +174,9 @@ public void run(OpenMetadataApplicationConfig catalogConfig, Environment environ
// Configure the Fernet instance
Fernet.getInstance().setFernetKey(catalogConfig);

// Initialize Workflow Handler
WorkflowHandler.initialize(catalogConfig);

// Init Settings Cache after repositories
SettingsCache.initialize(catalogConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void initializeNewProcessEngine(
ProcessEngineConfiguration currentProcessEngineConfiguration) {
ProcessEngines.destroy();
SystemRepository systemRepository = Entity.getSystemRepository();
WorkflowSettings workflowSettings = systemRepository.getWorkflowSettings();
WorkflowSettings workflowSettings = systemRepository.getWorkflowSettingsOrDefault();

StandaloneProcessEngineConfiguration processEngineConfiguration =
new StandaloneProcessEngineConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,7 @@ private void updateCertification() {

SystemRepository systemRepository = Entity.getSystemRepository();
AssetCertificationSettings assetCertificationSettings =
systemRepository.getAssetCertificationSettings();
systemRepository.getAssetCertificationSettingOrDefault();

String certificationLabel = updatedCertification.getTagLabel().getTagFQN();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.api.configuration.UiThemePreference;
import org.openmetadata.schema.configuration.AssetCertificationSettings;
import org.openmetadata.schema.configuration.ExecutorConfiguration;
import org.openmetadata.schema.configuration.HistoryCleanUpConfiguration;
import org.openmetadata.schema.configuration.WorkflowSettings;
import org.openmetadata.schema.email.SmtpSettings;
import org.openmetadata.schema.entity.services.ingestionPipelines.PipelineServiceClientResponse;
Expand Down Expand Up @@ -121,6 +123,17 @@ public AssetCertificationSettings getAssetCertificationSettings() {
.orElse(null);
}

public AssetCertificationSettings getAssetCertificationSettingOrDefault() {
AssetCertificationSettings assetCertificationSettings = getAssetCertificationSettings();
if (assetCertificationSettings == null) {
assetCertificationSettings =
new AssetCertificationSettings()
.withAllowedClassification("Certification")
.withValidityPeriod("P30D");
}
return assetCertificationSettings;
}

public WorkflowSettings getWorkflowSettings() {
Optional<Settings> oWorkflowSettings =
Optional.ofNullable(getConfigWithKey(SettingsType.WORKFLOW_SETTINGS.value()));
Expand All @@ -130,6 +143,17 @@ public WorkflowSettings getWorkflowSettings() {
.orElse(null);
}

public WorkflowSettings getWorkflowSettingsOrDefault() {
WorkflowSettings workflowSettings = getWorkflowSettings();
if (workflowSettings == null) {
workflowSettings =
new WorkflowSettings()
.withExecutorConfiguration(new ExecutorConfiguration())
.withHistoryCleanUpConfiguration(new HistoryCleanUpConfiguration());
}
return workflowSettings;
}

public Settings getEmailConfigInternal() {
try {
Settings setting = dao.getConfigWithKey(SettingsType.EMAIL_CONFIGURATION.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static class WorkflowDefinitionList extends ResultList<WorkflowDefinition

@Override
public void initialize(OpenMetadataApplicationConfig config) throws IOException {
WorkflowHandler.initialize(config);
repository.initSeedDataFromResources();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.openmetadata.schema.auth.JWTAuthMechanism;
import org.openmetadata.schema.auth.JWTTokenExpiry;
import org.openmetadata.schema.configuration.AssetCertificationSettings;
import org.openmetadata.schema.configuration.WorkflowSettings;
import org.openmetadata.schema.email.SmtpSettings;
import org.openmetadata.schema.entity.data.Table;
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
Expand Down Expand Up @@ -551,6 +552,48 @@ void testLineageSettings() throws HttpResponseException {
assertEquals(4, updatedLineageConfig.getDownstreamDepth());
}

@Test
void testWorkflowSettings() throws HttpResponseException {
// Retrieve the default workflow settings
Settings setting = getSystemConfig(SettingsType.WORKFLOW_SETTINGS);
WorkflowSettings workflowSettings =
JsonUtils.convertValue(setting.getConfigValue(), WorkflowSettings.class);

// Assert default values
assertEquals(50, workflowSettings.getExecutorConfiguration().getCorePoolSize());
assertEquals(1000, workflowSettings.getExecutorConfiguration().getQueueSize());
assertEquals(100, workflowSettings.getExecutorConfiguration().getMaxPoolSize());
assertEquals(20, workflowSettings.getExecutorConfiguration().getTasksDuePerAcquisition());
assertEquals(7, workflowSettings.getHistoryCleanUpConfiguration().getCleanAfterNumberOfDays());

// Update workflow settings
workflowSettings.getExecutorConfiguration().setCorePoolSize(100);
workflowSettings.getExecutorConfiguration().setQueueSize(2000);
workflowSettings.getExecutorConfiguration().setMaxPoolSize(200);
workflowSettings.getExecutorConfiguration().setTasksDuePerAcquisition(40);
workflowSettings.getHistoryCleanUpConfiguration().setCleanAfterNumberOfDays(10);

Settings updatedSetting =
new Settings()
.withConfigType(SettingsType.WORKFLOW_SETTINGS)
.withConfigValue(workflowSettings);

updateSystemConfig(updatedSetting);

// Retrieve the updated settings
Settings updatedSettings = getSystemConfig(SettingsType.WORKFLOW_SETTINGS);
WorkflowSettings updateWorkflowSettings =
JsonUtils.convertValue(updatedSettings.getConfigValue(), WorkflowSettings.class);

// Assert updated values
assertEquals(100, updateWorkflowSettings.getExecutorConfiguration().getCorePoolSize());
assertEquals(2000, updateWorkflowSettings.getExecutorConfiguration().getQueueSize());
assertEquals(200, updateWorkflowSettings.getExecutorConfiguration().getMaxPoolSize());
assertEquals(40, updateWorkflowSettings.getExecutorConfiguration().getTasksDuePerAcquisition());
assertEquals(
10, updateWorkflowSettings.getHistoryCleanUpConfiguration().getCleanAfterNumberOfDays());
}

@Test
void globalProfilerConfig(TestInfo test) throws HttpResponseException {
// Create a profiler config
Expand Down

0 comments on commit d2d7212

Please sign in to comment.