|
9 | 9 | */ |
10 | 10 | package org.openmrs.module.initializer; |
11 | 11 |
|
| 12 | +import static org.openmrs.module.initializer.InitializerConstants.MODULE_ARTIFACT_ID; |
| 13 | +import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_ENABLED; |
| 14 | +import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_LEVEL; |
| 15 | +import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_LOCATION; |
| 16 | +import static org.openmrs.module.initializer.InitializerConstants.PROPS_STARTUP_LOAD_DISABLED; |
| 17 | +import static org.openmrs.module.initializer.InitializerConstants.PROPS_STARTUP_LOAD_FAIL_ON_ERROR; |
| 18 | +import static org.openmrs.module.initializer.api.utils.Utils.getPropertyValue; |
| 19 | + |
12 | 20 | import java.io.IOException; |
13 | 21 | import java.nio.file.Path; |
14 | 22 | import java.nio.file.Paths; |
|
24 | 32 | import org.slf4j.Logger; |
25 | 33 | import org.slf4j.LoggerFactory; |
26 | 34 |
|
27 | | -import static org.openmrs.module.initializer.InitializerConstants.MODULE_ARTIFACT_ID; |
28 | | -import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_ENABLED; |
29 | | -import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_LEVEL; |
30 | | -import static org.openmrs.module.initializer.InitializerConstants.PROPS_LOGGING_LOCATION; |
31 | | -import static org.openmrs.module.initializer.InitializerConstants.PROPS_STARTUP_LOAD_DISABLED; |
32 | | -import static org.openmrs.module.initializer.InitializerConstants.PROPS_STARTUP_LOAD_FAIL_ON_ERROR; |
33 | | -import static org.openmrs.module.initializer.api.utils.Utils.getPropertyValue; |
34 | | - |
35 | 35 | /** |
36 | 36 | * This class contains the logic that is run every time this module is either started or shutdown |
37 | 37 | */ |
@@ -76,47 +76,27 @@ public void started() { |
76 | 76 | InitializerMessageSource messageSource = getInitializerMessageSource(); |
77 | 77 | Context.getMessageSourceService().setActiveMessageSource(messageSource); |
78 | 78 |
|
79 | | - String startupLoadingMode = getInitializerService().getInitializerConfig().getStartupLoadingMode(); |
| 79 | + getInitializerService().migrateChecksumsFromFilesToDB(); |
80 | 80 |
|
| 81 | + String startupLoadingMode = getInitializerConfig().getStartupLoadingMode(); |
81 | 82 | if (PROPS_STARTUP_LOAD_DISABLED.equalsIgnoreCase(startupLoadingMode)) { |
82 | 83 | log.info("OpenMRS config loading process disabled at initializer startup"); |
83 | 84 | } else { |
84 | 85 | boolean throwError = PROPS_STARTUP_LOAD_FAIL_ON_ERROR.equalsIgnoreCase(startupLoadingMode); |
85 | | - boolean lockAquired = false; |
86 | | - String lockName = "initializer"; |
87 | 86 |
|
88 | 87 | try { |
89 | | - log.info("Waiting for initializer lock..."); |
90 | | - getInitializerService().acquireLockOrWait(lockName, 15 * 60 * 1000); // 15 minutes |
91 | | - lockAquired = true; |
92 | | - |
93 | | - // Check if config changed |
94 | | - if (!getInitializerService().isConfigChanged()) { |
95 | | - log.info("No config changes... skipping initializer"); |
96 | | - return; |
97 | | - } |
98 | | - |
99 | | - // Run Initializer |
100 | | - log.info("OpenMRS config loading process started..."); |
101 | 88 | getInitializerService().loadUnsafe(true, throwError); |
102 | | - |
103 | | - // Save new checksums |
104 | | - getInitializerService().updateChecksums(); |
105 | | - log.info("OpenMRS config loading process completed."); |
106 | 89 | } |
107 | 90 | catch (Exception e) { |
108 | | - log.error("Initializer failed", e); |
109 | 91 | throw new ModuleException("An error occurred loading initializer configuration", e); |
110 | 92 | } |
111 | | - finally { |
112 | | - if (lockAquired) { |
113 | | - getInitializerService().releaseLock(lockName); |
114 | | - log.info("Initializer lock released"); |
115 | | - } |
116 | | - } |
117 | 93 | } |
118 | 94 | } |
119 | 95 |
|
| 96 | + protected InitializerConfig getInitializerConfig() { |
| 97 | + return getInitializerService().getInitializerConfig(); |
| 98 | + } |
| 99 | + |
120 | 100 | protected InitializerService getInitializerService() { |
121 | 101 | return Context.getService(InitializerService.class); |
122 | 102 | } |
|
0 commit comments