@@ -20,98 +20,64 @@ class RulesTxtDeploymentService @Inject() (querqyRulesTxtGenerator: QuerqyRulesT
20
20
environment : Environment ) extends Logging {
21
21
22
22
case class RulesTxtsForSolrIndex (solrIndexId : SolrIndexId ,
23
- regularRules : RulesTxtWithFileNames ,
24
- decompoundRules : Option [RulesTxtWithFileNames ],
25
- replaceRules : Option [RulesTxtWithFileNames ]) {
23
+ regularRules : RulesTxtWithFileName ,
24
+ decompoundRules : Option [RulesTxtWithFileName ],
25
+ replaceRules : Option [RulesTxtWithFileName ]) {
26
26
27
- def regularAndDecompoundFiles : List [RulesTxtWithFileNames ] = List (regularRules) ++ decompoundRules
27
+ def regularAndDecompoundFiles : List [RulesTxtWithFileName ] = List (regularRules) ++ decompoundRules
28
28
29
- def allFiles : List [RulesTxtWithFileNames ] = regularAndDecompoundFiles ++ replaceRules
29
+ def allFiles : List [RulesTxtWithFileName ] = regularAndDecompoundFiles ++ replaceRules
30
30
31
31
}
32
32
33
- case class RulesTxtWithFileNames (content : String ,
34
- sourceFileName : String ,
35
- destinationFileName : String )
33
+ case class RulesTxtWithFileName (content : String ,
34
+ sourceFileName : String )
36
35
37
36
/**
38
37
* Generates a list of source to destination filenames containing the rules.txt(s) according to current application settings.
39
38
*
40
39
* @param solrIndexId Solr Index Id to generate the output for.
41
40
*/
42
41
// TODO evaluate, if logDebug should be used to prevent verbose logging of the whole generated rules.txt (for zip download especially)
43
- def generateRulesTxtContentWithFilenames (solrIndexId : SolrIndexId , targetSystem : String , logDebug : Boolean = true ): RulesTxtsForSolrIndex = {
42
+ def generateRulesTxtContentWithFilenames (solrIndexId : SolrIndexId , logDebug : Boolean = true ): RulesTxtsForSolrIndex = {
44
43
45
- // SMUI config for (regular) LIVE deployment
46
44
val SRC_TMP_FILE = appConfig.get[String ](" smui2solr.SRC_TMP_FILE" )
47
- val DST_CP_FILE_TO = appConfig.get[String ](" smui2solr.DST_CP_FILE_TO" )
48
45
val DO_SPLIT_DECOMPOUND_RULES_TXT = featureToggleService.getToggleRuleDeploymentSplitDecompoundRulesTxt
49
- val DECOMPOUND_RULES_TXT_DST_CP_FILE_TO = featureToggleService.getToggleRuleDeploymentSplitDecompoundRulesTxtDstCpFileTo
50
- // (additional) SMUI config for PRELIVE deployment
51
- val SMUI_DEPLOY_PRELIVE_FN_RULES_TXT = appConfig.get[String ](" smui2solr.deploy-prelive-fn-rules-txt" )
52
- val SMUI_DEPLOY_PRELIVE_FN_DECOMPOUND_TXT = appConfig.get[String ](" smui2solr.deploy-prelive-fn-decompound-txt" )
53
-
54
- // Replace rules (spelling)
55
- val EXPORT_REPLACE_RULES = featureToggleService.getToggleActivateSpelling
46
+ val DO_EXPORT_REPLACE_RULES = featureToggleService.getToggleActivateSpelling
56
47
val REPLACE_RULES_SRC_TMP_FILE = appConfig.get[String ](" smui2solr.replace-rules-tmp-file" )
57
- val REPLACE_RULES_DST_CP_FILE_TO = appConfig.get[String ](" smui2solr.replace-rules-dst-cp-file-to" )
58
- val SMUI_DEPLOY_PRELIVE_FN_REPLACE_TXT = appConfig.get[String ](" smui2solr.deploy-prelive-fn-replace-txt" )
59
48
60
49
if (logDebug) {
61
50
logger.debug(
62
51
s """ :: generateRulesTxtContentWithFilenames config
63
52
|:: SRC_TMP_FILE = $SRC_TMP_FILE
64
- |:: DST_CP_FILE_TO = $DST_CP_FILE_TO
65
53
|:: DO_SPLIT_DECOMPOUND_RULES_TXT = $DO_SPLIT_DECOMPOUND_RULES_TXT
66
- |:: DECOMPOUND_RULES_TXT_DST_CP_FILE_TO = $DECOMPOUND_RULES_TXT_DST_CP_FILE_TO
67
- |:: SMUI_DEPLOY_PRELIVE_FN_RULES_TXT = $SMUI_DEPLOY_PRELIVE_FN_RULES_TXT
68
- |:: SMUI_DEPLOY_PRELIVE_FN_DECOMPOUND_TXT = $SMUI_DEPLOY_PRELIVE_FN_DECOMPOUND_TXT
69
- |:: EXPORT_REPLACE_RULES = $EXPORT_REPLACE_RULES
54
+ |:: EXPORT_REPLACE_RULES = $DO_EXPORT_REPLACE_RULES
70
55
|:: REPLACE_RULES_SRC_TMP_FILE = $REPLACE_RULES_SRC_TMP_FILE
71
- |:: REPLACE_RULES_DST_CP_FILE_TO = $REPLACE_RULES_DST_CP_FILE_TO
72
- |:: SMUI_DEPLOY_PRELIVE_FN_REPLACE_TXT = $SMUI_DEPLOY_PRELIVE_FN_REPLACE_TXT
73
56
""" .stripMargin)
74
57
}
75
58
76
59
// generate one rules.txt by default or two separated, if decompound instructions are supposed to be split
77
60
78
- // TODO test correct generation in different scenarios (one vs. two rules.txts, etc.)
79
- val dstCpFileTo = if (targetSystem == " PRELIVE" )
80
- SMUI_DEPLOY_PRELIVE_FN_RULES_TXT
81
- else // targetSystem == "LIVE"
82
- DST_CP_FILE_TO
83
-
84
- val replaceRulesDstCpFileTo =
85
- if (targetSystem == " PRELIVE" ) SMUI_DEPLOY_PRELIVE_FN_REPLACE_TXT
86
- else REPLACE_RULES_DST_CP_FILE_TO
87
-
88
- val replaceRules =
89
- if (EXPORT_REPLACE_RULES ) {
61
+ val optReplaceRules =
62
+ if (DO_EXPORT_REPLACE_RULES ) {
90
63
val allCanonicalSpellings = searchManagementRepository.listAllSpellingsWithAlternatives(solrIndexId)
91
- Some (RulesTxtWithFileNames (
92
- QuerqyReplaceRulesGenerator .renderAllCanonicalSpellingsToReplaceRules(allCanonicalSpellings),
93
- REPLACE_RULES_SRC_TMP_FILE ,
94
- replaceRulesDstCpFileTo
95
- ))
64
+ val spellingsRendered = QuerqyReplaceRulesGenerator .renderAllCanonicalSpellingsToReplaceRules(allCanonicalSpellings)
65
+ Some (RulesTxtWithFileName (spellingsRendered, REPLACE_RULES_SRC_TMP_FILE ))
96
66
} else None
97
67
98
68
if (! DO_SPLIT_DECOMPOUND_RULES_TXT ) {
99
69
RulesTxtsForSolrIndex (solrIndexId,
100
- RulesTxtWithFileNames (querqyRulesTxtGenerator.renderSingleRulesTxt(solrIndexId), SRC_TMP_FILE , dstCpFileTo ),
70
+ RulesTxtWithFileName (querqyRulesTxtGenerator.renderSingleRulesTxt(solrIndexId), SRC_TMP_FILE ),
101
71
None ,
102
- replaceRules
72
+ optReplaceRules
103
73
)
104
74
} else {
105
- val decompoundDstCpFileTo = if (targetSystem == " PRELIVE" )
106
- SMUI_DEPLOY_PRELIVE_FN_DECOMPOUND_TXT
107
- else // targetSystem == "LIVE"
108
- DECOMPOUND_RULES_TXT_DST_CP_FILE_TO
75
+ val rulesWithoutDecompounds = querqyRulesTxtGenerator.renderSeparatedRulesTxts(solrIndexId, renderCompoundsRulesTxt = false )
76
+ val decompoundRules = querqyRulesTxtGenerator.renderSeparatedRulesTxts(solrIndexId, renderCompoundsRulesTxt = true )
109
77
RulesTxtsForSolrIndex (solrIndexId,
110
- RulesTxtWithFileNames (querqyRulesTxtGenerator.renderSeparatedRulesTxts(solrIndexId, renderCompoundsRulesTxt = false ), SRC_TMP_FILE , dstCpFileTo),
111
- Some (RulesTxtWithFileNames (querqyRulesTxtGenerator.renderSeparatedRulesTxts(solrIndexId, renderCompoundsRulesTxt = true ),
112
- SRC_TMP_FILE + " -2" , decompoundDstCpFileTo)
113
- ),
114
- replaceRules
78
+ RulesTxtWithFileName (rulesWithoutDecompounds, SRC_TMP_FILE ),
79
+ Some (RulesTxtWithFileName (decompoundRules, SRC_TMP_FILE + " -2" )),
80
+ optReplaceRules
115
81
)
116
82
}
117
83
}
@@ -123,7 +89,7 @@ class RulesTxtDeploymentService @Inject() (querqyRulesTxtGenerator: QuerqyRulesT
123
89
def validateCompleteRulesTxts (rulesTxts : RulesTxtsForSolrIndex , logDebug : Boolean = true ): List [String ] = {
124
90
val rulesValidation = rulesTxts.regularAndDecompoundFiles.flatMap { rulesFile =>
125
91
if (logDebug) {
126
- logger.debug(" :: validateCompleteRulesTxts for src = " + rulesFile.sourceFileName + " dst = " + rulesFile.destinationFileName )
92
+ logger.debug(" :: validateCompleteRulesTxts for src = " + rulesFile.sourceFileName)
127
93
logger.debug(" :: rulesTxt = <<<" + rulesFile.content + " >>>" )
128
94
}
129
95
val validationResult = querqyRulesTxtGenerator.validateQuerqyRulesTxtToErrMsg(rulesFile.content)
@@ -158,43 +124,34 @@ class RulesTxtDeploymentService @Inject() (querqyRulesTxtGenerator: QuerqyRulesT
158
124
159
125
}
160
126
161
- def interfaceSmui2SolrSh (scriptPath : String , srcTmpFile : String , dstCpFileTo : String , solrHost : String ,
162
- solrCoreName : String , decompoundDstCpFileTo : String , targetSystem : String ,
163
- replaceRulesSrcTmpFile : String , replaceRulesDstCpFileTo : String
127
+ def interfaceSmui2SolrSh (scriptPath : String ,
128
+ srcTmpFile : String ,
129
+ replaceRulesSrcTmpFile : String ,
130
+ targetSystem : String ,
131
+ solrCoreName : String
164
132
): DeploymentScriptResult = {
165
133
166
134
logger.info(
167
135
s """ :: interfaceSmui2SolrSh
168
136
|:: scriptPath = $scriptPath
169
137
|:: srcTmpFile = $srcTmpFile
170
- |:: dstCpFileTo = $dstCpFileTo
171
- |:: solrHost = $solrHost
138
+ |:: replaceRulesSrcTmpFile = $replaceRulesSrcTmpFile
172
139
|:: solrCoreName = $solrCoreName
173
- |:: decompoundDstCpFileTo = $decompoundDstCpFileTo
174
140
|:: targetSystem = $targetSystem
175
- |:: replaceRulesSrcTmpFile = $replaceRulesSrcTmpFile
176
- |:: replaceRulesDstCpFileTo = $replaceRulesDstCpFileTo
177
141
""" .stripMargin)
178
142
179
- val scriptCall =
143
+ val scriptCall = List (
180
144
// define call for regular smui2solr (default or custom script) and add parameters to the script (in expected order, see smui2solr.sh)
181
- scriptPath + " " +
145
+ scriptPath,
182
146
// SRC_TMP_FILE=$1
183
- srcTmpFile + " " +
184
- // DST_CP_FILE_TO =$2
185
- dstCpFileTo + " " +
186
- // SOLR_HOST =$3
187
- solrHost + " " +
147
+ srcTmpFile,
148
+ // REPLACE_RULES_SRC_TMP_FILE =$2
149
+ replaceRulesSrcTmpFile,
150
+ // TARGET_SYSTEM =$3
151
+ targetSystem,
188
152
// SOLR_CORE_NAME=$4
189
- solrCoreName + " " +
190
- // DECOMPOUND_DST_CP_FILE_TO=$5
191
- decompoundDstCpFileTo + " " +
192
- // TARGET_SYSTEM=$6
193
- targetSystem + " " +
194
- // REPLACE_RULES_SRC_TMP_FILE=$7
195
- replaceRulesSrcTmpFile + " " +
196
- // REPLACE_RULES_DST_CP_FILE_TO=$8
197
- replaceRulesDstCpFileTo
153
+ solrCoreName
154
+ ).mkString(" " )
198
155
199
156
interfaceDeploymentScript(scriptCall)
200
157
}
@@ -233,58 +190,37 @@ class RulesTxtDeploymentService @Inject() (querqyRulesTxtGenerator: QuerqyRulesT
233
190
else
234
191
environment.rootPath.getAbsolutePath + " /conf/smui2solr.sh"
235
192
193
+ val deployToGitConfigured = featureToggleService.getToggleRuleDeploymentGitEnabled
194
+
236
195
val srcTmpFile = rulesTxts.regularRules.sourceFileName
237
- val dstCpFileTo = rulesTxts.regularRules.destinationFileName
238
- val decompoundDstCpFileTo = if (rulesTxts.decompoundRules.isDefined)
239
- rulesTxts.decompoundRules.get.destinationFileName
240
- else
241
- " NONE"
242
-
243
- // host for (optional) core reload
244
- val SMUI_DEPLOY_PRELIVE_SOLR_HOST = appConfig.get[String ](" smui2solr.deploy-prelive-solr-host" )
245
- val SMUI_DEPLOY_LIVE_SOLR_HOST = appConfig.get[String ](" smui2solr.SOLR_HOST" )
246
- val solrHost = if (targetSystem == " PRELIVE" )
247
- if (SMUI_DEPLOY_PRELIVE_SOLR_HOST .isEmpty)
248
- " NONE"
249
- else
250
- SMUI_DEPLOY_PRELIVE_SOLR_HOST
251
- else // targetSystem == "LIVE"
252
- if (SMUI_DEPLOY_LIVE_SOLR_HOST .isEmpty)
253
- " NONE"
254
- else
255
- SMUI_DEPLOY_LIVE_SOLR_HOST
256
- // core name from repo (optional, for core reload as well)
257
196
val solrCoreName = searchManagementRepository.getSolrIndexName(rulesTxts.solrIndexId)
258
-
259
197
val replaceRulesSrcTmpFile = rulesTxts.replaceRules.map(_.sourceFileName).getOrElse(" NONE" )
260
- val replaceRulesDstCpFileTo = rulesTxts.replaceRules.map(_.destinationFileName).getOrElse(" NONE" )
261
198
262
199
// execute script
263
200
// TODO currently only git deployment for LIVE instance available
264
- val deployToGit = targetSystem.equals(" LIVE" ) && appConfig.get[String ](" smui2solr.DST_CP_FILE_TO" ).equals(" GIT" )
265
- val result = (if (! deployToGit) {
201
+ val result = if (deployToGitConfigured) {
202
+ if (targetSystem == " LIVE" ) {
203
+ logger.info(" :: executeDeploymentScript :: GIT configured calling interfaceSmui2GitSh" )
204
+ // TODO support further rule files (decompound / replace) and maybe solrCoreName and/or targetSystem for git branch?
205
+ interfaceSmui2GitSh(
206
+ environment.rootPath.getAbsolutePath + " /conf/smui2git.sh" ,
207
+ srcTmpFile,
208
+ featureToggleService.getSmuiDeploymentGitRepoUrl,
209
+ featureToggleService.getSmuiDeploymentGitFilenameCommonRulesTxt,
210
+ )
211
+ } else {
212
+ DeploymentScriptResult (exitCode = - 1 , output = " Git deployment only support for LIVE target" )
213
+ }
214
+ } else {
266
215
logger.info(s " :: executeDeploymentScript :: regular script configured calling interfaceSmui2SolrSh(scriptPath = ' $scriptPath') " )
267
216
interfaceSmui2SolrSh(
268
217
scriptPath,
269
218
srcTmpFile,
270
- dstCpFileTo,
271
- solrHost,
272
- solrCoreName,
273
- decompoundDstCpFileTo,
274
- targetSystem,
275
219
replaceRulesSrcTmpFile,
276
- replaceRulesDstCpFileTo
277
- )
278
- } else {
279
- logger.info(" :: executeDeploymentScript :: GIT configured calling interfaceSmui2GitSh" )
280
- // TODO support further rule files (decompound / replace) and maybe solrCoreName and/or targetSystem for git branch?
281
- interfaceSmui2GitSh(
282
- environment.rootPath.getAbsolutePath + " /conf/smui2git.sh" ,
283
- srcTmpFile,
284
- featureToggleService.getSmuiDeploymentGitRepoUrl,
285
- featureToggleService.getSmuiDeploymentGitFilenameCommonRulesTxt,
220
+ targetSystem,
221
+ solrCoreName
286
222
)
287
- })
223
+ }
288
224
if (result.success) {
289
225
logger.info(s " Rules.txt deployment successful: \n ${result.output}" )
290
226
} else {
@@ -323,7 +259,7 @@ class RulesTxtDeploymentService @Inject() (querqyRulesTxtGenerator: QuerqyRulesT
323
259
try {
324
260
for (index <- searchManagementRepository.listAllSolrIndexes) {
325
261
// TODO make targetSystem configurable from ApiController.downloadAllRulesTxtFiles ... go with "LIVE" from now (as there exist no different revisions of the search management content)!
326
- val rules = generateRulesTxtContentWithFilenames(index.id, " LIVE " , logDebug = false )
262
+ val rules = generateRulesTxtContentWithFilenames(index.id, logDebug = false )
327
263
zipStream.putNextEntry(new ZipEntry (s " rules_ ${index.name}.txt " ))
328
264
zipStream.write(rules.regularRules.content.getBytes(" UTF-8" ))
329
265
zipStream.closeEntry()
0 commit comments