From 5a81a049556c7645dde2f0e85dcbd4a65cad14fc Mon Sep 17 00:00:00 2001 From: Rob Szkutak Date: Fri, 3 Feb 2017 00:33:48 -0600 Subject: [PATCH 01/11] Update version --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 6a126f40..50049fa5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.7.5 +April-2017-dev From 7cfc4d654e0fb1cdaf3a3657ff5dda6725a54951 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Fri, 10 Feb 2017 13:46:21 +0000 Subject: [PATCH 02/11] issue #736: fix CTRL-EXT from a filesystem modules DB --- src/app/config/config.xqy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/config/config.xqy b/src/app/config/config.xqy index cf078fb2..098d0973 100644 --- a/src/app/config/config.xqy +++ b/src/app/config/config.xqy @@ -68,7 +68,7 @@ declare variable $c:ROXY-ROUTES := : : *********************************************** :) -declare variable $c:CTRL-EXT := ("@ml.controller-ext", $def:CTRL-EXT)[1]; +declare variable $c:CTRL-EXT := ("@ml.controller-ext", $def:CTRL-EXT)[fn:not(. eq "@ml.controller-ext")][1]; (: : *********************************************** From b1f85f645d4614da1f35e0f981c028b167625874 Mon Sep 17 00:00:00 2001 From: Elijah Bernstein-Cooper Date: Fri, 10 Feb 2017 11:58:47 -0600 Subject: [PATCH 03/11] retrieval of existing roles/users outside loop create-roles and create-users previously retrieved existing users and roles within the loop iterating over roles/users to create now existing roles/users are retrieved outside the iteration. only the role/user names are retrieved. --- deploy/lib/xquery/setup.xqy | 51 ++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/deploy/lib/xquery/setup.xqy b/deploy/lib/xquery/setup.xqy index f4b58b8b..cc1bf46a 100644 --- a/deploy/lib/xquery/setup.xqy +++ b/deploy/lib/xquery/setup.xqy @@ -4742,6 +4742,10 @@ declare function setup:validate-external-security( declare function setup:create-roles( $import-config as element(configuration)) { + (: get the existing role names from the default security DB :) + let $existing-role-names := setup:get-existing-role-names() + return + (: Create all missing roles :) for $role in $import-config/sec:roles/sec:role let $role-name as xs:string := $role/sec:role-name @@ -4754,7 +4758,7 @@ declare function setup:create-roles( return (: if the role exists, then don't create it :) - if (setup:get-roles(())/sec:role[sec:role-name = $role-name]) then () + if ($existing-role-names[. = $role-name]) then () else ( xdmp:eval( @@ -4911,6 +4915,10 @@ declare function setup:create-roles( declare function setup:validate-roles( $import-config as element(configuration)) { + (: get the existing role names from the default security DB :) + let $existing-role-names := setup:get-existing-role-names() + return + for $role in $import-config/sec:roles/sec:role let $role-name as xs:string := $role/sec:role-name let $description as xs:string? := $role/sec:description @@ -4921,7 +4929,7 @@ declare function setup:validate-roles( let $privileges as element(sec:privilege)* := $role/sec:privileges/sec:privilege let $amps as element(sec:amp)* := $role/sec:amps/* let $external-names as xs:string* := $role/sec:external-names/sec:external-name - let $match := setup:get-roles(())/sec:role[sec:role-name = $role-name] + let $match := $existing-role-names[. = $role-name] return if ($match) then if ($match/sec:role-name != $role-name or @@ -4964,6 +4972,11 @@ declare function setup:associate-users-with-roles($import-config as element(conf declare function setup:create-users($import-config as element(configuration)) { + (: get the existing user names from the default security DB :) + let $existing-user-names := setup:get-existing-user-names() + return + + (: Create all missing users :) for $user in $import-config/sec:users/sec:user let $user-name as xs:string := $user/sec:user-name let $description as xs:string? := $user/sec:description @@ -4978,7 +4991,7 @@ declare function setup:create-users($import-config as element(configuration)) different-transaction return - if (setup:get-users(())/sec:user[sec:user-name = $user-name]) then + if ($existing-user-names[. = $user-name]) then ( xdmp:eval( 'import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; @@ -5088,6 +5101,10 @@ declare function setup:create-users($import-config as element(configuration)) declare function setup:validate-users($import-config as element(configuration)) { + (: get the existing user names from the default security DB :) + let $existing-user-names := setup:get-existing-user-names() + return + for $user in $import-config/sec:users/sec:user let $user-name as xs:string := $user/sec:user-name let $description as xs:string? := $user/sec:description @@ -5096,7 +5113,7 @@ declare function setup:validate-users($import-config as element(configuration)) let $permissions as element(sec:permission)* := $user/sec:permissions/* let $collections as xs:string* := $user/sec:collections/* let $external-names as xs:string* := $user/sec:external-names/sec:external-name - let $match := setup:get-users(())/sec:user[sec:user-name = $user-name] + let $match := $existing-user-names[. = $user-name] return if ($match) then if ($match/sec:description != $description or @@ -5451,6 +5468,19 @@ declare function setup:get-privilege-by-name($name as xs:string) as element(sec: ) }; +(: Gets the user names from the default security database :) +declare function setup:get-existing-user-names() as element(sec:user-name)* { + let $user-names := + xdmp:eval( + 'import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; + /sec:user', + (), + + {$default-security} + )/sec:user-name + return $user-names +}; + declare function setup:get-users-by-name($names as xs:string*) as element(sec:users)? { let $ids := for $name in $names @@ -5530,6 +5560,19 @@ declare function setup:get-user-id($user-name as xs:string) as xs:unsignedLong? ) }; +(: Gets the role names from the default security database :) +declare function setup:get-existing-role-names() as element(sec:role-name)* { + let $role-names := + xdmp:eval( + 'import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; + /sec:role', + (), + + {$default-security} + )/sec:role-name + return $role-names +}; + declare function setup:get-roles-by-name($roles as xs:string*) as element(sec:roles)? { let $ids := for $role in $roles From 585ea92f75069b19dc332b2483533f9ff9b50e3f Mon Sep 17 00:00:00 2001 From: Elijah Bernstein-Cooper Date: Fri, 10 Feb 2017 12:37:50 -0600 Subject: [PATCH 04/11] fixed mistake in validate-roles/users providing the entire role/user element instead of just the name --- deploy/lib/xquery/setup.xqy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deploy/lib/xquery/setup.xqy b/deploy/lib/xquery/setup.xqy index cc1bf46a..569ec320 100644 --- a/deploy/lib/xquery/setup.xqy +++ b/deploy/lib/xquery/setup.xqy @@ -4916,7 +4916,7 @@ declare function setup:validate-roles( $import-config as element(configuration)) { (: get the existing role names from the default security DB :) - let $existing-role-names := setup:get-existing-role-names() + let $existing-roles := setup:get-roles(()) return for $role in $import-config/sec:roles/sec:role @@ -4929,7 +4929,7 @@ declare function setup:validate-roles( let $privileges as element(sec:privilege)* := $role/sec:privileges/sec:privilege let $amps as element(sec:amp)* := $role/sec:amps/* let $external-names as xs:string* := $role/sec:external-names/sec:external-name - let $match := $existing-role-names[. = $role-name] + let $match := $existing-roles/sec:role[sec:role-name = $role-name] return if ($match) then if ($match/sec:role-name != $role-name or @@ -5101,8 +5101,8 @@ declare function setup:create-users($import-config as element(configuration)) declare function setup:validate-users($import-config as element(configuration)) { - (: get the existing user names from the default security DB :) - let $existing-user-names := setup:get-existing-user-names() + (: get the existing users from the default security DB :) + let $existing-users := setup:get-users(()) return for $user in $import-config/sec:users/sec:user @@ -5113,7 +5113,7 @@ declare function setup:validate-users($import-config as element(configuration)) let $permissions as element(sec:permission)* := $user/sec:permissions/* let $collections as xs:string* := $user/sec:collections/* let $external-names as xs:string* := $user/sec:external-names/sec:external-name - let $match := $existing-user-names[. = $user-name] + let $match := $existing-users/sec:user[sec:user-name = $user-name] return if ($match) then if ($match/sec:description != $description or From 2bf982efb2490a5766fe89afe01bf80ca4fb78f3 Mon Sep 17 00:00:00 2001 From: Elijah Bernstein-Cooper Date: Fri, 10 Feb 2017 13:23:35 -0600 Subject: [PATCH 05/11] removed unneeded FLWOR statements, fixed indent address comments from pull request 739 --- deploy/lib/xquery/setup.xqy | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/deploy/lib/xquery/setup.xqy b/deploy/lib/xquery/setup.xqy index 569ec320..eef44208 100644 --- a/deploy/lib/xquery/setup.xqy +++ b/deploy/lib/xquery/setup.xqy @@ -4744,7 +4744,6 @@ declare function setup:create-roles( { (: get the existing role names from the default security DB :) let $existing-role-names := setup:get-existing-role-names() - return (: Create all missing roles :) for $role in $import-config/sec:roles/sec:role @@ -4917,7 +4916,6 @@ declare function setup:validate-roles( { (: get the existing role names from the default security DB :) let $existing-roles := setup:get-roles(()) - return for $role in $import-config/sec:roles/sec:role let $role-name as xs:string := $role/sec:role-name @@ -4974,7 +4972,6 @@ declare function setup:create-users($import-config as element(configuration)) { (: get the existing user names from the default security DB :) let $existing-user-names := setup:get-existing-user-names() - return (: Create all missing users :) for $user in $import-config/sec:users/sec:user @@ -5103,7 +5100,6 @@ declare function setup:validate-users($import-config as element(configuration)) { (: get the existing users from the default security DB :) let $existing-users := setup:get-users(()) - return for $user in $import-config/sec:users/sec:user let $user-name as xs:string := $user/sec:user-name @@ -5564,12 +5560,12 @@ declare function setup:get-user-id($user-name as xs:string) as xs:unsignedLong? declare function setup:get-existing-role-names() as element(sec:role-name)* { let $role-names := xdmp:eval( - 'import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; + 'import module namespace sec="http://marklogic.com/xdmp/security" at "/MarkLogic/security.xqy"; /sec:role', - (), - - {$default-security} - )/sec:role-name + (), + + {$default-security} + )/sec:role-name return $role-names }; From 197cdc502e5b1aa3b2c485490410a71172336644 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Mon, 13 Feb 2017 09:47:35 +0000 Subject: [PATCH 06/11] issue #740: make -EXT work from modules and filesystem --- src/app/config/config.xqy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/config/config.xqy b/src/app/config/config.xqy index 098d0973..b6ce69f7 100644 --- a/src/app/config/config.xqy +++ b/src/app/config/config.xqy @@ -68,7 +68,7 @@ declare variable $c:ROXY-ROUTES := : : *********************************************** :) -declare variable $c:CTRL-EXT := ("@ml.controller-ext", $def:CTRL-EXT)[fn:not(. eq "@ml.controller-ext")][1]; +declare variable $c:CTRL-EXT := ("@ml.controller-ext", $def:CTRL-EXT)[fn:not(. eq "@" || "ml.controller-ext")][1]; (: : *********************************************** From f718809e407e7d97c01d7da9b25ce9ff46d70855 Mon Sep 17 00:00:00 2001 From: Dave Cassel Date: Tue, 14 Feb 2017 15:04:27 -0500 Subject: [PATCH 07/11] #733 corrected invalid-values default; addressed missed case --- deploy/lib/xquery/setup.xqy | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/deploy/lib/xquery/setup.xqy b/deploy/lib/xquery/setup.xqy index eef44208..2e2176ef 100644 --- a/deploy/lib/xquery/setup.xqy +++ b/deploy/lib/xquery/setup.xqy @@ -72,6 +72,11 @@ declare variable $replicating-map-file := "/roxy/status/cleanup/replicating-map. declare variable $replicating-map-file-internal := "/roxy/status/cleanup/replicating-map-internal.xml"; declare variable $replicating-map := map:map(); +(: Several functions take an optional invalid-values parameter. Use this as the + : default value when it's not provided. + :) +declare variable $default-invalid-values := "reject"; + declare variable $group-settings := list-cache-size @@ -2258,7 +2263,7 @@ declare function setup:validated-range-element-indexes( $index-config/db:localname/fn:string(.), fn:string($index-config/db:collation[../db:scalar-type = 'string']), ($index-config/db:range-value-positions/xs:boolean(.), false())[1], - ($index-config/db:invalid-values, "reject")[1] + ($index-config/db:invalid-values, $default-invalid-values)[1] ) else xdmp:apply( @@ -2320,7 +2325,7 @@ declare function setup:validated-range-element-attribute-indexes( $index-config/db:localname/fn:string(.), fn:string($index-config/db:collation[../db:scalar-type = 'string']), ($index-config/db:range-value-positions/xs:boolean(.), false())[1], - ($index-config/db:invalid-values, "reject")[1] + ($index-config/db:invalid-values, $default-invalid-values)[1] ) else xdmp:apply( @@ -2449,7 +2454,7 @@ declare function setup:add-range-path-indexes( $index/db:path-expression, $index/db:collation, $index/db:range-value-positions, - $index/db:invalid-values + ($index/db:invalid-values, $default-invalid-values)[1] ) )" ) @@ -2478,6 +2483,7 @@ declare function setup:validate-range-path-indexes( declare namespace db="http://marklogic.com/xdmp/database"; declare variable $database external; declare variable $x external; + declare variable $default-invalid-values external; admin:database-range-path-index( $database, @@ -2485,9 +2491,10 @@ declare function setup:validate-range-path-indexes( $x/db:path-expression, fn:string($x/db:collation[../db:scalar-type = "string"]), $x/db:range-value-positions, - $x/db:invalid-values)', + ($x/db:invalid-values, $default-invalid-values)[1])', (xs:QName("database"), $database, - xs:QName("x"), $expected)) + xs:QName("x"), $expected, + xs:QName("default-invalid-values"), $default-invalid-values)) return if ($existing[fn:deep-equal(., $expected)]) then () else @@ -2689,7 +2696,7 @@ declare function setup:add-range-field-indexes-helper( $index/db:field-name, ($index/db:collation/fn:string(), "")[1], (: ML6 requires xs:string; later requires xs:string? :) $index/db:range-value-positions, - $index/db:invalid-values + ($index/db:invalid-values, $default-invalid-values)[1] ) else admin:database-range-field-index( @@ -2738,7 +2745,7 @@ declare function setup:add-geospatial-element-indexes( $index/db:coordinate-system, $index/db:range-value-positions, ($index/db:point-format, "point")[1], - ($index/db:invalid-values, "ignore")[1] + ($index/db:invalid-values, $default-invalid-values)[1] ) else admin:database-geospatial-element-index( @@ -2792,7 +2799,7 @@ declare function setup:add-geospatial-element-attribute-pair-indexes( $index/db:longitude-localname, $index/db:coordinate-system, $index/db:range-value-positions, - ($index/db:invalid-values, "ignore")[1] + ($index/db:invalid-values, $default-invalid-values)[1] ) else admin:database-geospatial-element-attribute-pair-index( @@ -2849,7 +2856,7 @@ declare function setup:add-geospatial-element-pair-indexes( $index/db:longitude-localname, $index/db:coordinate-system, $index/db:range-value-positions, - ($index/db:invalid-values, "ignore")[1] + ($index/db:invalid-values, $default-invalid-values)[1] ) else admin:database-geospatial-element-pair-index( @@ -2905,7 +2912,7 @@ declare function setup:add-geospatial-element-child-indexes( $index/db:coordinate-system, $index/db:range-value-positions, ($index/db:point-format, "point")[1], - ($index/db:invalid-values, "ignore")[1] + ($index/db:invalid-values, $default-invalid-values)[1] ) else admin:database-geospatial-element-child-index( From 2f921abb97bc99ca8ad8a3b64a7d447c44382d30 Mon Sep 17 00:00:00 2001 From: Dino Bagayaua Date: Sat, 15 Apr 2017 13:22:56 +0800 Subject: [PATCH 08/11] add feature to load multiple custom configuration files --- deploy/lib/server_config.rb | 52 ++++++++++++++++++++++++++- deploy/sample/build.sample.properties | 7 ++++ src/app/config/custom-config.xqy | 22 ++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/app/config/custom-config.xqy diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index 037b3d87..d01a238f 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -1046,6 +1046,8 @@ def deploy deploy_triggers when 'rest-config' deploy_rest_config + when 'config' + deploy_config else raise HelpException.new("deploy", "Invalid WHAT") end @@ -1863,12 +1865,12 @@ def modules_databases def deploy_modules deploy_src() deploy_rest() + deploy_config() end def deploy_src test_dir = @properties['ml.xquery-test.dir'] xquery_dir = @properties['ml.xquery.dir'] - # modules_db = @properties['ml.modules-db'] app_config_file = File.join xquery_dir, "/app/config/config.xqy" test_config_file = File.join test_dir, "/test-config.xqy" load_html_as_xml = @properties['ml.load-html-as-xml'] @@ -1971,6 +1973,54 @@ def deploy_src end end + def deploy_config + xquery_dir = @properties['ml.xquery.dir'] + app_configs = @properties['ml.application-conf-file'] + total_count = 0 + + modules_databases.each do |dest_db| + if dest_db == "filesystem" + logger.info "Skipping deployment of configurations to #{dest_db}.." + break + end + + src_permissions = permissions(@properties['ml.app-role'], Roxy::ContentCapability::ERU) + + if ['rest', 'hybrid'].include? @properties["ml.app-type"] + # This app uses the REST API, so grant permissions to the rest roles. This allows REST extensions to call + # modules not deployed through the REST API. + # These roles are present in MarkLogic 6+. + src_permissions.push permissions('rest-admin', Roxy::ContentCapability::RU) + src_permissions.push permissions('rest-extension-user', Roxy::ContentCapability::EXECUTE) + src_permissions.flatten! + end + + @logger.debug("source permissions: #{src_permissions}") + + if app_configs.present? + logger.info "Deploying application configurations" + app_configs.split(',').each do |item| + buffer = File.read item + replace_properties(buffer, File.basename(item)) + item_name = item + if item.start_with?("src/") + item_name = item[4, item.length] + end + item_name = '/' + item_name + logger.info "deploying application configuration #{item} with name #{item_name} on #{dest_db}" + total_count += xcc.load_buffer item_name, + buffer, + :db => dest_db, + :add_prefix => File.join(@properties["ml.modules-root"], "app/config/"), + :permissions => src_permissions + end + logger.info "Done deploying application configurations" + end + + logger.info "\nLoaded #{total_count} #{pluralize(total_count, "document", "documents")} from #{xquery_dir} to #{xcc.hostname}:#{xcc.port}/#{dest_db} at #{DateTime.now.strftime('%m/%d/%Y %I:%M:%S %P')}\n" + end + end + def deploy_rest # Deploy options, extensions to the REST API server if ['rest', 'hybrid'].include? @properties["ml.app-type"] diff --git a/deploy/sample/build.sample.properties b/deploy/sample/build.sample.properties index 33d0cf6b..d56af4e9 100644 --- a/deploy/sample/build.sample.properties +++ b/deploy/sample/build.sample.properties @@ -208,3 +208,10 @@ mlcp-vmargs=-Xmx512m # enable the following to save and upload svn/git commit info upon deploy modules save-commit-info=false + +# enable the following to add custom configuration files +# contents of the files will be replaces with data from the +# properties files. +# +# multiple configuration files can be loaded by separating it with comma. +# application-conf-file=src/app/config/custom-config.xqy \ No newline at end of file diff --git a/src/app/config/custom-config.xqy b/src/app/config/custom-config.xqy new file mode 100644 index 00000000..094aa519 --- /dev/null +++ b/src/app/config/custom-config.xqy @@ -0,0 +1,22 @@ +(: +Copyright 2012-2015 MarkLogic Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +:) +xquery version "1.0-ml"; + +module namespace c = "http://marklogic.com/roxy/application-config"; + +(: configured at deploy time by Roxy deployer :) +declare variable $c:app-name := "@ml.app-name"; + From 81ae329334c979b8e2707888b8150f488b533064 Mon Sep 17 00:00:00 2001 From: Dino Bagayaua Date: Thu, 20 Apr 2017 20:32:14 +0800 Subject: [PATCH 09/11] fix comments --- deploy/sample/build.sample.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/sample/build.sample.properties b/deploy/sample/build.sample.properties index d56af4e9..a356b931 100644 --- a/deploy/sample/build.sample.properties +++ b/deploy/sample/build.sample.properties @@ -209,7 +209,7 @@ mlcp-vmargs=-Xmx512m # enable the following to save and upload svn/git commit info upon deploy modules save-commit-info=false -# enable the following to add custom configuration files +# Enable the following to add custom configuration files # contents of the files will be replaces with data from the # properties files. # From 6051878277c3cf48ab4d6be24bfda8c8abe1574d Mon Sep 17 00:00:00 2001 From: Dino Bagayaua Date: Tue, 25 Apr 2017 23:31:46 +0800 Subject: [PATCH 10/11] implement review points --- deploy/default.properties | 5 + deploy/lib/server_config.rb | 98 +++++++------------ deploy/sample/build.sample.properties | 11 ++- .../sample}/custom-config.xqy | 0 4 files changed, 45 insertions(+), 69 deletions(-) rename {src/app/config => deploy/sample}/custom-config.xqy (100%) diff --git a/deploy/default.properties b/deploy/default.properties index 80d9e6ff..36262fac 100755 --- a/deploy/default.properties +++ b/deploy/default.properties @@ -260,3 +260,8 @@ http.retry-count=3 http.open-timeout=5 http.read-timeout=300 http.retry-delay=15 + +# +# Application configuration files +# +application-conf-file=src/app/config/config.xqy diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index d01a238f..bf3e378a 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -248,6 +248,10 @@ def self.init properties_file.gsub!(/error-handler=\/roxy\/error.xqy/, "error-handler=/MarkLogic/rest-api/error-handler.xqy") end + if app_type == "mvc" + properties_file.gsub!(/application-conf-file=deploy\/sample\/custom-config.xqy/, 'application-conf-file=src/app/config/config.xqy,deploy/sample/custom-config.xqy') + end + # replace the text =random with a random string o = (33..126).to_a properties_file.gsub!(/=random/) do |match| @@ -1046,8 +1050,6 @@ def deploy deploy_triggers when 'rest-config' deploy_rest_config - when 'config' - deploy_config else raise HelpException.new("deploy", "Invalid WHAT") end @@ -1865,13 +1867,12 @@ def modules_databases def deploy_modules deploy_src() deploy_rest() - deploy_config() end def deploy_src test_dir = @properties['ml.xquery-test.dir'] xquery_dir = @properties['ml.xquery.dir'] - app_config_file = File.join xquery_dir, "/app/config/config.xqy" + app_configs = @properties['ml.application-conf-file'] test_config_file = File.join test_dir, "/test-config.xqy" load_html_as_xml = @properties['ml.load-html-as-xml'] load_js_as_binary = @properties['ml.load-js-as-binary'] @@ -1898,6 +1899,7 @@ def deploy_src end + total_count = 0 modules_databases.each do |dest_db| if dest_db == "filesystem" logger.info "Skipping deployment of src to #{dest_db}.." @@ -1906,7 +1908,6 @@ def deploy_src ignore_us = [] ignore_us << "^#{test_dir}.*$" unless test_dir.blank? || deploy_tests?(dest_db) - ignore_us << "^#{app_config_file}$" ignore_us << "^#{test_config_file}$" ignore_us << "^#{folders_to_ignore}$" unless folders_to_ignore.blank? @@ -1921,7 +1922,34 @@ def deploy_src src_permissions.flatten! end - @logger.debug("source permissions: #{src_permissions}") + @logger.debug "source permissions: #{src_permissions}" + if app_configs.present? + logger.debug "Deploying application configurations" + + app_configs.split(',').each do |item| + buffer = File.read item + replace_properties(buffer, File.basename(item)) + + item_name = item + prefix = '/' + if item_name === 'src/app/config/config.xqy' + item_name = '/config.xqy' + ignore_us << '/app/config/config.xqy' + prefix = 'app/config/' + elsif item.start_with?("src/") + item_name = '/' + item[4, item.length] + ignore_us << item_name + end + + logger.debug "deploying application configuration #{item} with name #{item_name} on #{dest_db}" + total_count += xcc.load_buffer item_name, + buffer, + :db => dest_db, + :add_prefix => File.join(@properties["ml.modules-root"], prefix), + :permissions => src_permissions + end + logger.debug "Done deploying application configurations" + end total_count = load_data xquery_dir, :add_prefix => @properties["ml.modules-prefix"], @@ -1933,16 +1961,6 @@ def deploy_src :load_css_as_binary => load_css_as_binary, :permissions => src_permissions - if File.exist? app_config_file - buffer = File.read app_config_file - replace_properties(buffer, File.basename(app_config_file)) - - total_count += xcc.load_buffer "/config.xqy", - buffer, - :db => dest_db, - :add_prefix => File.join(@properties["ml.modules-root"], "app/config"), - :permissions => src_permissions - end if deploy_tests?(dest_db) && File.exist?(test_config_file) buffer = File.read test_config_file @@ -1973,54 +1991,6 @@ def deploy_src end end - def deploy_config - xquery_dir = @properties['ml.xquery.dir'] - app_configs = @properties['ml.application-conf-file'] - total_count = 0 - - modules_databases.each do |dest_db| - if dest_db == "filesystem" - logger.info "Skipping deployment of configurations to #{dest_db}.." - break - end - - src_permissions = permissions(@properties['ml.app-role'], Roxy::ContentCapability::ERU) - - if ['rest', 'hybrid'].include? @properties["ml.app-type"] - # This app uses the REST API, so grant permissions to the rest roles. This allows REST extensions to call - # modules not deployed through the REST API. - # These roles are present in MarkLogic 6+. - src_permissions.push permissions('rest-admin', Roxy::ContentCapability::RU) - src_permissions.push permissions('rest-extension-user', Roxy::ContentCapability::EXECUTE) - src_permissions.flatten! - end - - @logger.debug("source permissions: #{src_permissions}") - - if app_configs.present? - logger.info "Deploying application configurations" - app_configs.split(',').each do |item| - buffer = File.read item - replace_properties(buffer, File.basename(item)) - item_name = item - if item.start_with?("src/") - item_name = item[4, item.length] - end - item_name = '/' + item_name - logger.info "deploying application configuration #{item} with name #{item_name} on #{dest_db}" - total_count += xcc.load_buffer item_name, - buffer, - :db => dest_db, - :add_prefix => File.join(@properties["ml.modules-root"], "app/config/"), - :permissions => src_permissions - end - logger.info "Done deploying application configurations" - end - - logger.info "\nLoaded #{total_count} #{pluralize(total_count, "document", "documents")} from #{xquery_dir} to #{xcc.hostname}:#{xcc.port}/#{dest_db} at #{DateTime.now.strftime('%m/%d/%Y %I:%M:%S %P')}\n" - end - end - def deploy_rest # Deploy options, extensions to the REST API server if ['rest', 'hybrid'].include? @properties["ml.app-type"] diff --git a/deploy/sample/build.sample.properties b/deploy/sample/build.sample.properties index a356b931..92850dca 100644 --- a/deploy/sample/build.sample.properties +++ b/deploy/sample/build.sample.properties @@ -209,9 +209,10 @@ mlcp-vmargs=-Xmx512m # enable the following to save and upload svn/git commit info upon deploy modules save-commit-info=false -# Enable the following to add custom configuration files -# contents of the files will be replaces with data from the -# properties files. # -# multiple configuration files can be loaded by separating it with comma. -# application-conf-file=src/app/config/custom-config.xqy \ No newline at end of file +# Application configuration files +# +# Assign a comma separated custom configuration files relative to root folder. +# +# Contents of the files will be replaced with data from the properties files. +application-conf-file=deploy/sample/custom-config.xqy \ No newline at end of file diff --git a/src/app/config/custom-config.xqy b/deploy/sample/custom-config.xqy similarity index 100% rename from src/app/config/custom-config.xqy rename to deploy/sample/custom-config.xqy From 62412bd23880aabcee92daece91bfcb8b811ce7e Mon Sep 17 00:00:00 2001 From: Dino Bagayaua Date: Wed, 26 Apr 2017 13:44:40 +0800 Subject: [PATCH 11/11] implemented based on review points --- deploy/lib/server_config.rb | 21 +++++++++++++++------ deploy/sample/build.sample.properties | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index bf3e378a..d2b79854 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -186,22 +186,26 @@ def self.init sample_properties = "roxy/sample/build.sample.properties" sample_options = "roxy/sample/all.sample.xml" sample_rest_properties = "roxy/sample/properties.sample.xml" + sample_app_config = "roxy/deploy/sample/custom-config.xqy" else - sample_config = ServerConfig.expand_path("#{@@path}/sample/ml-config.sample.xml") - sample_properties = ServerConfig.expand_path("#{@@path}/sample/build.sample.properties") + sample_config = ServerConfig.expand_path("#{@@path}/sample/ml-config.sample.xml") + sample_properties = ServerConfig.expand_path("#{@@path}/sample/build.sample.properties") sample_options = ServerConfig.expand_path("#{@@path}/sample/all.sample.xml") sample_rest_properties = ServerConfig.expand_path("#{@@path}/sample/properties.sample.xml") + sample_app_config = ServerConfig.expand_path("#{@@path}/sample/custom-config.xqy") end # output files build_properties = ServerConfig.expand_path("#{@@path}/build.properties") options_file = ServerConfig.expand_path("#{@@path}/../rest-api/config/options/all.xml") rest_properties = ServerConfig.expand_path("#{@@path}/../rest-api/config/properties.xml") + app_config = ServerConfig.expand_path("#{@@path}/../src/config/config.xqy") # dirs to create rest_ext_dir = ServerConfig.expand_path("#{@@path}/../rest-api/ext") rest_transforms_dir = ServerConfig.expand_path("#{@@path}/../rest-api/transforms") options_dir = ServerConfig.expand_path("#{@@path}/../rest-api/config/options") + config_dir = ServerConfig.expand_path("#{@@path}/../src/config") # get supplied options force = find_arg(['--force']).present? @@ -248,10 +252,6 @@ def self.init properties_file.gsub!(/error-handler=\/roxy\/error.xqy/, "error-handler=/MarkLogic/rest-api/error-handler.xqy") end - if app_type == "mvc" - properties_file.gsub!(/application-conf-file=deploy\/sample\/custom-config.xqy/, 'application-conf-file=src/app/config/config.xqy,deploy/sample/custom-config.xqy') - end - # replace the text =random with a random string o = (33..126).to_a properties_file.gsub!(/=random/) do |match| @@ -262,6 +262,10 @@ def self.init # Update properties file to set server-version to value specified on command-line properties_file.gsub!(/server-version=6/, "server-version=#{server_version}") + if ["rest", "bare"].include? app_type + properties_file.gsub!(/application-conf-file=src\/app\/config\/config.xqy/, 'application-conf-file=src/config/config.xqy') + end + # save the replacements open(build_properties, 'w') {|f| f.write(properties_file) } end @@ -275,6 +279,11 @@ def self.init copy_file sample_rest_properties, rest_properties end + if ["rest", "bare"].include? app_type + FileUtils.mkdir_p config_dir + copy_file sample_app_config, app_config + end + target_config = ServerConfig.expand_path(ServerConfig.properties["ml.config.file"]) if !force && !force_config && File.exists?(target_config) diff --git a/deploy/sample/build.sample.properties b/deploy/sample/build.sample.properties index 92850dca..a5ed7c4d 100644 --- a/deploy/sample/build.sample.properties +++ b/deploy/sample/build.sample.properties @@ -215,4 +215,4 @@ save-commit-info=false # Assign a comma separated custom configuration files relative to root folder. # # Contents of the files will be replaced with data from the properties files. -application-conf-file=deploy/sample/custom-config.xqy \ No newline at end of file +application-conf-file=src/app/config/config.xqy