From 2f921abb97bc99ca8ad8a3b64a7d447c44382d30 Mon Sep 17 00:00:00 2001 From: Dino Bagayaua Date: Sat, 15 Apr 2017 13:22:56 +0800 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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