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

Commit 2a95596

Browse files
committed
First stab at #808: accept unwrapped config parts, replace ml-config.xml with ml-config/
1 parent 7713c43 commit 2a95596

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
@@ -308,8 +308,8 @@ def self.init
308308
if !force && !force_config && File.exists?(target_config)
309309
error_msg << "ml-config.xml has already been created."
310310
else
311-
#create clean marklogic configuration file
312-
copy_file sample_config, target_config
311+
#create clean marklogic configuration file(s)
312+
FileUtils.cp_r sample_config, target_config
313313
end
314314

315315
raise HelpException.new("init", error_msg.join("\n")) if error_msg.length > 0
@@ -2890,9 +2890,22 @@ def ssl_certificate_xml
28902890
}
28912891
end
28922892

2893-
def build_config(config_files)
2893+
def build_config(config_paths)
2894+
config_files = []
2895+
config_paths.split(",").each do |config_path|
2896+
if File.directory?(config_path)
2897+
Dir.glob(File.join(config_path, '**', '*')).reject {
2898+
|p| File.directory? p
2899+
}.each do |file|
2900+
config_files.push file
2901+
end
2902+
else
2903+
config_files.push config_path
2904+
end
2905+
end
2906+
28942907
configs = []
2895-
config_files.split(",").each do |config_file|
2908+
config_files.each do |config_file|
28962909
config = File.read(config_file)
28972910

28982911
# 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
@@ -566,6 +566,67 @@ declare function setup:unique-attributes($attrs) {
566566
return map:keys($result) ! map:get($result, .)
567567
};
568568

569+
declare function setup:wrap-config-fragments($fragments) {
570+
if (fn:exists($fragments)) then
571+
<configuration>
572+
<hosts xmlns="http://marklogic.com/xdmp/hosts">{
573+
setup:unique-attributes($fragments/self::ho:hosts/@*),
574+
$fragments/self::ho:hosts/*,
575+
$fragments/self::ho:host
576+
}</hosts>
577+
<assignments xmlns="http://marklogic.com/xdmp/assignments">{
578+
setup:unique-attributes($fragments/self::as:assignments/@*),
579+
$fragments/self::as:assignments/*,
580+
$fragments/self::as:assignment
581+
}</assignments>
582+
<databases xmlns="http://marklogic.com/xdmp/database">{
583+
setup:unique-attributes($fragments/self::db:databases/@*),
584+
$fragments/self::db:databases/*,
585+
$fragments/self::db:database
586+
}</databases>
587+
<certificates xmlns="http://marklogic.com/xdmp/pki">{
588+
setup:unique-attributes($fragments/self::pki:certificates/@*),
589+
$fragments/self::pki:certificates/*,
590+
$fragments/self::pki:certificate
591+
}</certificates>
592+
<roles xmlns="http://marklogic.com/xdmp/security">{
593+
setup:unique-attributes($fragments/self::sec:roles/@*),
594+
$fragments/self::sec:roles/*,
595+
$fragments/self::sec:role
596+
}</roles>
597+
<users xmlns="http://marklogic.com/xdmp/security">{
598+
setup:unique-attributes($fragments/self::sec:users/@*),
599+
$fragments/self::sec:users/*,
600+
$fragments/self::sec:user
601+
}</users>
602+
<amps xmlns="http://marklogic.com/xdmp/security">{
603+
setup:unique-attributes($fragments/self::sec:amps/@*),
604+
$fragments/self::sec:amps/*,
605+
$fragments/self::sec:amp
606+
}</amps>
607+
<privileges xmlns="http://marklogic.com/xdmp/security">{
608+
setup:unique-attributes($fragments/self::sec:privileges/@*),
609+
$fragments/self::sec:privileges/*,
610+
$fragments/self::sec:privilege
611+
}</privileges>
612+
<mimetypes xmlns="http://marklogic.com/xdmp/mimetypes">{
613+
setup:unique-attributes($fragments/self::mt:mimetypes/@*),
614+
$fragments/self::mt:mimetypes/*,
615+
$fragments/self::mt:mimetype
616+
}</mimetypes>
617+
<external-securities xmlns="http://marklogic.com/xdmp/security">{
618+
setup:unique-attributes($fragments/self::sec:external-securities/@*),
619+
$fragments/self::sec:external-securities/*,
620+
$fragments/self::sec:external-security
621+
}</external-securities>
622+
<credentials xmlns="http://marklogic.com/xdmp/security">{
623+
setup:unique-attributes($fragments/self::sec:credentials/@*),
624+
$fragments/self::sec:credentials/*
625+
}</credentials>
626+
</configuration>/*
627+
else ()
628+
};
629+
569630
(: for backwards-compatibility :)
570631
declare function setup:rewrite-config($import-configs as node()+, $properties as map:map) as element(configuration)
571632
{
@@ -581,28 +642,43 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
581642
{
582643
let $import-configs := setup:process-conditionals($import-configs, $properties)
583644
let $config :=
584-
element { fn:node-name($import-configs[1]) } {
585-
setup:unique-attributes($import-configs/@*),
645+
element configuration {
646+
setup:unique-attributes($import-configs/self::configuration/@*),
586647

587648
(: capture comments before gr:groups, and its older counterparts :)
588-
$import-configs/(
649+
$import-configs/self::configuration/(
589650
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
590651
)/preceding-sibling::node(),
591652

592653
<groups xmlns="http://marklogic.com/xdmp/group">{
593654
setup:unique-attributes($import-configs/gr:groups/@*),
594655

595-
let $default-group := ($import-configs/@default-group, "Default")[1]
596-
for $group in fn:distinct-values(
597-
($import-configs/gr:groups/gr:group/gr:group-name, $import-configs/(gr:http-servers/gr:http-server, gr:xdbc-servers/gr:xdbc-server,
598-
gr:odbc-servers/gr:odbc-server, gr:task-server, db:databases/db:database)/@group, $default-group))
599-
let $http-servers := $import-configs/gr:http-servers/gr:http-server[@group = $group or ($group = $default-group and fn:empty(@group))]
600-
let $xdbc-servers := $import-configs/gr:xdbc-servers/gr:xdbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
601-
let $odbc-servers := $import-configs/gr:odbc-servers/gr:odbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
602-
let $task-server := $import-configs/gr:task-server[@group = $group or ($group = $default-group and fn:empty(@group))]
656+
let $default-group := ($import-configs/self::*:configuration/@default-group, "Default")[1]
657+
for $group in fn:distinct-values((
658+
$import-configs/descendant-or-self::gr:group/gr:group-name,
659+
$import-configs/descendant-or-self::*/(
660+
self::gr:http-server, self::gr:xdbc-server,
661+
self::gr:odbc-server, self::gr:task-server, self::db:database
662+
)/@group,
663+
$default-group
664+
))
665+
let $http-servers := $import-configs/descendant-or-self::gr:http-server[
666+
@group = $group or ( $group = $default-group and fn:empty(@group) )
667+
]
668+
let $xdbc-servers := $import-configs/descendant-or-self::gr:xdbc-server[
669+
@group = $group or ( $group = $default-group and fn:empty(@group) )
670+
]
671+
let $odbc-servers := $import-configs/descendant-or-self::gr:odbc-server[
672+
@group = $group or ( $group = $default-group and fn:empty(@group) )
673+
]
674+
let $task-server := $import-configs/descendant-or-self::gr:task-server[
675+
@group = $group or ( $group = $default-group and fn:empty(@group) )
676+
]
603677
let $servers := ($http-servers, $xdbc-servers, $odbc-servers, $task-server)
604-
let $databases := $import-configs/db:databases/db:database[@group = $group or ($group = $default-group and fn:empty(@group))]
605-
let $group-config := $import-configs/gr:groups/gr:group[gr:group-name = $group]
678+
let $databases := $import-configs/descendant-or-self::db:database[
679+
@group = $group or ( $group = $default-group and fn:empty(@group) )
680+
]
681+
let $group-config := $import-configs/descendant-or-self::gr:group[gr:group-name = $group]
606682
where fn:exists($servers | $databases | $group-config)
607683
return
608684
<group>
@@ -627,14 +703,24 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
627703
}</groups>,
628704

629705
(: capture anything following gr:groups, and its older counterparts :)
630-
$import-configs/(
706+
$import-configs/self::*:configuration/(
631707
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
632708
)/following-sibling::node(),
633709

634-
(: other fragments with configuration as root :)
635-
$import-configs[fn:empty((
636-
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
637-
))]/node()
710+
(: in case of config fragments, merge and wrap them :)
711+
setup:wrap-config-fragments((
712+
(: fragments with configuration as root :)
713+
$import-configs/self::*:configuration[fn:empty((
714+
gr:groups, gr:http-servers, gr:xdbc-servers, gr:odbc-servers, gr:task-server
715+
))]/node(),
716+
717+
(: other fragments :)
718+
$import-configs[fn:not(self::*:configuration)]/(self::node() except (
719+
self::gr:groups, self::gr:group, self::gr:http-servers, self::gr:http-server,
720+
self::gr:xdbc-servers, self::gr:xdbc-server, self::gr:odbc-servers, self::gr:odbc-server,
721+
self::gr:task-server
722+
))
723+
))
638724
}
639725

640726
(: 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)