Skip to content

Commit fd01adc

Browse files
author
Vladimir Kotal
committed
Merge branch 'vladak-config_merge_xover'
2 parents 91f8f84 + 8c03cc1 commit fd01adc

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

tools/src/main/python/config-merge.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
"""
32-
Script for merging OpenGrok configuration
32+
Wrapper for Java program merging OpenGrok configuration.
3333
"""
3434

3535
if __name__ == '__main__':
@@ -48,12 +48,14 @@
4848
logger = logging.getLogger(os.path.basename(sys.argv[0]))
4949

5050
cmd = Java(args.options, classpath=args.jar, java=args.java,
51-
java_opts=args.java_opts,
51+
java_opts=args.java_opts, redirect_stderr=False,
5252
main_class='org.opengrok.indexer.configuration.ConfigMerge',
5353
logger=logger)
5454
cmd.execute()
5555
ret = cmd.getretcode()
5656
if ret is None or ret != 0:
57-
logger.error(cmd.getoutputstr())
57+
logger.error(cmd.geterroutput())
5858
logger.error("command failed (return code {})".format(ret))
5959
sys.exit(1)
60+
61+
print(cmd.getoutputstr())

tools/src/main/python/java.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class Java(Command):
3737
"""
3838

3939
def __init__(self, command, logger=None, main_class=None, java=None,
40-
jar=None, java_opts=None, classpath=None, env_vars=None):
40+
jar=None, java_opts=None, classpath=None, env_vars=None,
41+
redirect_stderr=True):
4142

4243
if not java:
4344
java = self.FindJava(logger)
@@ -71,7 +72,8 @@ def __init__(self, command, logger=None, main_class=None, java=None,
7172
java_command.extend(command)
7273
logger.debug("Java command: {}".format(java_command))
7374

74-
super().__init__(java_command, logger=logger, env_vars=env)
75+
super().__init__(java_command, logger=logger, env_vars=env,
76+
redirect_stderr=redirect_stderr)
7577

7678
def FindJava(self, logger):
7779
"""

tools/src/main/python/projadm.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def install_config(doit, src, dst):
103103
sys.exit(1)
104104

105105

106-
def config_refresh(doit, logger, basedir, uri, configmerge, roconfig):
106+
def config_refresh(doit, logger, basedir, uri, configmerge, jar_file,
107+
roconfig):
107108
"""
108109
Refresh current configuration file with configuration retrieved
109110
from webapp. If roconfig is not None, the current config is merged with
@@ -137,7 +138,8 @@ def config_refresh(doit, logger, basedir, uri, configmerge, roconfig):
137138
logger.info('Refreshing configuration '
138139
'(merging with read-only config)')
139140
merged_config = exec_command(doit, logger,
140-
[configmerge, roconfig, fcur.name],
141+
[configmerge, '-a', jar_file,
142+
roconfig, fcur.name],
141143
"cannot merge configuration")
142144
with tempfile.NamedTemporaryFile() as fmerged:
143145
logger.debug("Temporary file for merged config: {}".
@@ -193,8 +195,7 @@ def project_delete(logger, project, uri, doit=True, deletesource=False):
193195

194196

195197
if __name__ == '__main__':
196-
parser = argparse.ArgumentParser(description='grok configuration '
197-
'management.',
198+
parser = argparse.ArgumentParser(description='project management.',
198199
formatter_class=argparse.
199200
ArgumentDefaultsHelpFormatter)
200201
parser.add_argument('-D', '--debug', action='store_true',
@@ -204,9 +205,10 @@ def project_delete(logger, project, uri, doit=True, deletesource=False):
204205
parser.add_argument('-R', '--roconfig',
205206
help='OpenGrok read-only configuration file')
206207
parser.add_argument('-U', '--uri', default='http://localhost:8080/source',
207-
help='uri of the webapp with context path')
208+
help='URI of the webapp with context path')
208209
parser.add_argument('-c', '--configmerge',
209210
help='path to the ConfigMerge binary')
211+
parser.add_argument('--jar', help='Path to jar archive to run')
210212
parser.add_argument('-u', '--upload', action='store_true',
211213
help='Upload configuration at the end')
212214
parser.add_argument('-n', '--noop', action='store_true', default=False,
@@ -256,23 +258,32 @@ def project_delete(logger, project, uri, doit=True, deletesource=False):
256258
.format(args.base))
257259
sys.exit(1)
258260

259-
# read-only configuration file.
261+
# If read-only configuration file is specified, this means read-only
262+
# configuration will need to be merged with active webapp configuration.
263+
# This requires config merge tool to be run so couple of other things
264+
# need to be checked.
260265
if args.roconfig:
261266
if path.isfile(args.roconfig):
262267
logger.debug("Using {} as read-only config".format(args.roconfig))
263268
else:
264269
logger.error("File {} does not exist".format(args.roconfig))
265270
sys.exit(1)
266271

272+
configmerge_file = get_command(logger, args.configmerge,
273+
"config-merge.py")
274+
if configmerge_file is None:
275+
logger.error("Use the --configmerge option to specify the path to"
276+
"the config merge script")
277+
sys.exit(1)
278+
279+
if args.jar is None:
280+
logger.error('jar file needed for config merge tool, '
281+
'use --jar to specify one')
282+
sys.exit(1)
283+
267284
uri = args.uri
268285
if not uri:
269-
logger.error("uri of the webapp not specified")
270-
sys.exit(1)
271-
272-
configmerge_file = get_command(logger, args.configmerge, "ConfigMerge")
273-
if not configmerge_file:
274-
logger.error("Use the --configmerge option to specify the path to"
275-
"the ConfigMerge script")
286+
logger.error("URI of the webapp not specified")
276287
sys.exit(1)
277288

278289
lock = filelock.FileLock(os.path.join(tempfile.gettempdir(),
@@ -289,6 +300,7 @@ def project_delete(logger, project, uri, doit=True, deletesource=False):
289300
basedir=args.base,
290301
uri=uri,
291302
configmerge=configmerge_file,
303+
jar_file=args.jar,
292304
roconfig=args.roconfig)
293305
elif args.delete:
294306
for proj in args.delete:
@@ -301,12 +313,14 @@ def project_delete(logger, project, uri, doit=True, deletesource=False):
301313
basedir=args.base,
302314
uri=uri,
303315
configmerge=configmerge_file,
316+
jar_file=args.jar,
304317
roconfig=args.roconfig)
305318
elif args.refresh:
306319
config_refresh(doit=doit, logger=logger,
307320
basedir=args.base,
308321
uri=uri,
309322
configmerge=configmerge_file,
323+
jar_file=args.jar,
310324
roconfig=args.roconfig)
311325
else:
312326
parser.print_help()

0 commit comments

Comments
 (0)