Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 6436991

Browse files
committed
First stab at #808: accept unwrapped config parts, replace ml-config.xml with ml-config/
1 parent 124990b commit 6436991

30 files changed

+710
-23
lines changed

deploy/lib/server_config.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ def self.init
293293
if !force && !force_config && File.exists?(target_config)
294294
error_msg << "ml-config.xml has already been created."
295295
else
296-
#create clean marklogic configuration file
297-
copy_file sample_config, target_config
296+
#create clean marklogic configuration file(s)
297+
FileUtils.cp_r sample_config, target_config
298298
end
299299

300300
raise HelpException.new("init", error_msg.join("\n")) if error_msg.length > 0
@@ -2865,9 +2865,22 @@ def ssl_certificate_xml
28652865
}
28662866
end
28672867

2868-
def build_config(config_files)
2868+
def build_config(config_paths)
2869+
config_files = []
2870+
config_paths.split(",").each do |config_path|
2871+
if File.directory?(config_path)
2872+
Dir.glob(File.join(config_path, '**', '*')).reject {
2873+
|p| File.directory? p
2874+
}.each do |file|
2875+
config_files.push file
2876+
end
2877+
else
2878+
config_files.push config_path
2879+
end
2880+
end
2881+
28692882
configs = []
2870-
config_files.split(",").each do |config_file|
2883+
config_files.each do |config_file|
28712884
config = File.read(config_file)
28722885

28732886
# Build the triggers db if it is provided

deploy/lib/xquery/setup.xqy

Lines changed: 104 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,67 @@ declare function setup:unique-attributes($attrs) {
450450
return map:keys($result) ! map:get($result, .)
451451
};
452452

453+
declare function setup:wrap-config-fragments($fragments) {
454+
if (fn:exists($fragments)) then
455+
<configuration>
456+
<hosts xmlns="http://marklogic.com/xdmp/hosts">{
457+
setup:unique-attributes($fragments/self::ho:hosts/@*),
458+
$fragments/self::ho:hosts/*,
459+
$fragments/self::ho:host
460+
}</hosts>
461+
<assignments xmlns="http://marklogic.com/xdmp/assignments">{
462+
setup:unique-attributes($fragments/self::as:assignments/@*),
463+
$fragments/self::as:assignments/*,
464+
$fragments/self::as:assignment
465+
}</assignments>
466+
<databases xmlns="http://marklogic.com/xdmp/database">{
467+
setup:unique-attributes($fragments/self::db:databases/@*),
468+
$fragments/self::db:databases/*,
469+
$fragments/self::db:database
470+
}</databases>
471+
<certificates xmlns="http://marklogic.com/xdmp/pki">{
472+
setup:unique-attributes($fragments/self::pki:certificates/@*),
473+
$fragments/self::pki:certificates/*,
474+
$fragments/self::pki:certificate
475+
}</certificates>
476+
<roles xmlns="http://marklogic.com/xdmp/security">{
477+
setup:unique-attributes($fragments/self::sec:roles/@*),
478+
$fragments/self::sec:roles/*,
479+
$fragments/self::sec:role
480+
}</roles>
481+
<users xmlns="http://marklogic.com/xdmp/security">{
482+
setup:unique-attributes($fragments/self::sec:users/@*),
483+
$fragments/self::sec:users/*,
484+
$fragments/self::sec:user
485+
}</users>
486+
<amps xmlns="http://marklogic.com/xdmp/security">{
487+
setup:unique-attributes($fragments/self::sec:amps/@*),
488+
$fragments/self::sec:amps/*,
489+
$fragments/self::sec:amp
490+
}</amps>
491+
<privileges xmlns="http://marklogic.com/xdmp/security">{
492+
setup:unique-attributes($fragments/self::sec:privileges/@*),
493+
$fragments/self::sec:privileges/*,
494+
$fragments/self::sec:privilege
495+
}</privileges>
496+
<mimetypes xmlns="http://marklogic.com/xdmp/mimetypes">{
497+
setup:unique-attributes($fragments/self::mt:mimetypes/@*),
498+
$fragments/self::mt:mimetypes/*,
499+
$fragments/self::mt:mimetype
500+
}</mimetypes>
501+
<external-securities xmlns="http://marklogic.com/xdmp/security">{
502+
setup:unique-attributes($fragments/self::sec:external-securities/@*),
503+
$fragments/self::sec:external-securities/*,
504+
$fragments/self::sec:external-security
505+
}</external-securities>
506+
<credentials xmlns="http://marklogic.com/xdmp/security">{
507+
setup:unique-attributes($fragments/self::sec:credentials/@*),
508+
$fragments/self::sec:credentials/*
509+
}</credentials>
510+
</configuration>/*
511+
else ()
512+
};
513+
453514
(: for backwards-compatibility :)
454515
declare function setup:rewrite-config($import-configs as node()+) as element(configuration)
455516
{
@@ -464,26 +525,41 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
464525
declare function setup:rewrite-config($import-configs as node()+, $silent as xs:boolean?, $keep-comments as xs:boolean?) as element(configuration)
465526
{
466527
let $config :=
467-
element { fn:node-name($import-configs[1]) } {
468-
setup:unique-attributes($import-configs/@*),
528+
element configuration {
529+
setup:unique-attributes($import-configs/self::configuration/@*),
469530

470531
(: capture comments before gr:groups, and its older counterparts :)
471-
$import-configs/(
532+
$import-configs/self::configuration/(
472533
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
473534
)/preceding-sibling::node(),
474535

475536
<groups xmlns="http://marklogic.com/xdmp/group">{
476-
let $default-group := ($import-configs/@default-group, "Default")[1]
477-
for $group in fn:distinct-values(
478-
($import-configs/gr:groups/gr:group/gr:group-name, $import-configs/(gr:http-servers/gr:http-server, gr:xdbc-servers/gr:xdbc-server,
479-
gr:odbc-servers/gr:odbc-server, gr:task-server, db:databases/db:database)/@group, $default-group))
480-
let $http-servers := $import-configs/gr:http-servers/gr:http-server[@group = $group or ($group = $default-group and fn:empty(@group))]
481-
let $xdbc-servers := $import-configs/gr:xdbc-servers/gr:xdbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
482-
let $odbc-servers := $import-configs/gr:odbc-servers/gr:odbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
483-
let $task-server := $import-configs/gr:task-server[@group = $group or ($group = $default-group and fn:empty(@group))]
537+
let $default-group := ($import-configs/self::*:configuration/@default-group, "Default")[1]
538+
for $group in fn:distinct-values((
539+
$import-configs/descendant-or-self::gr:group/gr:group-name,
540+
$import-configs/descendant-or-self::*/(
541+
self::gr:http-server, self::gr:xdbc-server,
542+
self::gr:odbc-server, self::gr:task-server, self::db:database
543+
)/@group,
544+
$default-group
545+
))
546+
let $http-servers := $import-configs/descendant-or-self::gr:http-server[
547+
@group = $group or ( $group = $default-group and fn:empty(@group) )
548+
]
549+
let $xdbc-servers := $import-configs/descendant-or-self::gr:xdbc-server[
550+
@group = $group or ( $group = $default-group and fn:empty(@group) )
551+
]
552+
let $odbc-servers := $import-configs/descendant-or-self::gr:odbc-server[
553+
@group = $group or ( $group = $default-group and fn:empty(@group) )
554+
]
555+
let $task-server := $import-configs/descendant-or-self::gr:task-server[
556+
@group = $group or ( $group = $default-group and fn:empty(@group) )
557+
]
484558
let $servers := ($http-servers, $xdbc-servers, $odbc-servers, $task-server)
485-
let $databases := $import-configs/db:databases/db:database[@group = $group or ($group = $default-group and fn:empty(@group))]
486-
let $group-config := $import-configs/gr:groups/gr:group[gr:group-name = $group]
559+
let $databases := $import-configs/descendant-or-self::db:database[
560+
@group = $group or ( $group = $default-group and fn:empty(@group) )
561+
]
562+
let $group-config := $import-configs/descendant-or-self::gr:group[gr:group-name = $group]
487563
where fn:exists($servers | $databases | $group-config)
488564
return
489565
<group>
@@ -508,14 +584,24 @@ declare function setup:rewrite-config($import-configs as node()+, $silent as xs:
508584
}</groups>,
509585

510586
(: capture anything following gr:groups, and its older counterparts :)
511-
$import-configs/(
587+
$import-configs/self::*:configuration/(
512588
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
513589
)/following-sibling::node(),
514590

515-
(: other fragments with configuration as root :)
516-
$import-configs[fn:empty((
517-
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
518-
))]/node()
591+
(: in case of config fragments, merge and wrap them :)
592+
setup:wrap-config-fragments((
593+
(: fragments with configuration as root :)
594+
$import-configs/self::*:configuration[fn:empty((
595+
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
596+
))]/node(),
597+
598+
(: other fragments :)
599+
$import-configs[fn:not(self::*:configuration)]/(self::node() except (
600+
self::gr:groups, self::gr:group, self::gr:http-servers, self::gr:http-server,
601+
self::gr:xdbc-servers, self::gr:xdbc-server, self::gr:odbc-servers, self::gr:odbc-server,
602+
self::gr:task-server
603+
))
604+
))
519605
}
520606

521607
(: Check config on group consistency! :)

deploy/sample/build.sample.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ modules-prefix=/
3131
#
3232
# the location of your marklogic configuration file
3333
#
34-
# config.file=${basedir}/deploy/ml-config.xml
34+
config.file=${basedir}/deploy/ml-config/
3535

3636
#
3737
# the location of your triggers configuration file

0 commit comments

Comments
 (0)