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

Commit 27216b5

Browse files
committed
First stab at #808: accept unwrapped config parts, replace ml-config.xml with ml-config/
1 parent 592fd2a commit 27216b5

30 files changed

+712
-25
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: 106 additions & 20 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
{
@@ -580,28 +641,43 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
580641
declare function setup:rewrite-config($import-configs as node()+, $properties as map:map, $silent as xs:boolean?, $keep-comments as xs:boolean?) as element(configuration)
581642
{
582643
let $config :=
583-
element { fn:node-name($import-configs[1]) } {
584-
setup:unique-attributes($import-configs/@*),
644+
element configuration {
645+
setup:unique-attributes($import-configs/self::configuration/@*),
585646

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

591652
<groups xmlns="http://marklogic.com/xdmp/group">{
592-
$import-configs/gr:groups/@*,
593-
594-
let $default-group := ($import-configs/@default-group, "Default")[1]
595-
for $group in fn:distinct-values(
596-
($import-configs/gr:groups/gr:group/gr:group-name, $import-configs/(gr:http-servers/gr:http-server, gr:xdbc-servers/gr:xdbc-server,
597-
gr:odbc-servers/gr:odbc-server, gr:task-server, db:databases/db:database)/@group, $default-group))
598-
let $http-servers := $import-configs/gr:http-servers/gr:http-server[@group = $group or ($group = $default-group and fn:empty(@group))]
599-
let $xdbc-servers := $import-configs/gr:xdbc-servers/gr:xdbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
600-
let $odbc-servers := $import-configs/gr:odbc-servers/gr:odbc-server[@group = $group or ($group = $default-group and fn:empty(@group))]
601-
let $task-server := $import-configs/gr:task-server[@group = $group or ($group = $default-group and fn:empty(@group))]
653+
setup:unique-attributes($import-configs/gr:groups/@*),
654+
655+
let $default-group := ($import-configs/self::*:configuration/@default-group, "Default")[1]
656+
for $group in fn:distinct-values((
657+
$import-configs/descendant-or-self::gr:group/gr:group-name,
658+
$import-configs/descendant-or-self::*/(
659+
self::gr:http-server, self::gr:xdbc-server,
660+
self::gr:odbc-server, self::gr:task-server, self::db:database
661+
)/@group,
662+
$default-group
663+
))
664+
let $http-servers := $import-configs/descendant-or-self::gr:http-server[
665+
@group = $group or ( $group = $default-group and fn:empty(@group) )
666+
]
667+
let $xdbc-servers := $import-configs/descendant-or-self::gr:xdbc-server[
668+
@group = $group or ( $group = $default-group and fn:empty(@group) )
669+
]
670+
let $odbc-servers := $import-configs/descendant-or-self::gr:odbc-server[
671+
@group = $group or ( $group = $default-group and fn:empty(@group) )
672+
]
673+
let $task-server := $import-configs/descendant-or-self::gr:task-server[
674+
@group = $group or ( $group = $default-group and fn:empty(@group) )
675+
]
602676
let $servers := ($http-servers, $xdbc-servers, $odbc-servers, $task-server)
603-
let $databases := $import-configs/db:databases/db:database[@group = $group or ($group = $default-group and fn:empty(@group))]
604-
let $group-config := $import-configs/gr:groups/gr:group[gr:group-name = $group]
677+
let $databases := $import-configs/descendant-or-self::db:database[
678+
@group = $group or ( $group = $default-group and fn:empty(@group) )
679+
]
680+
let $group-config := $import-configs/descendant-or-self::gr:group[gr:group-name = $group]
605681
where fn:exists($servers | $databases | $group-config)
606682
return
607683
<group>
@@ -626,14 +702,24 @@ declare function setup:rewrite-config($import-configs as node()+, $properties as
626702
}</groups>,
627703

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

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

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