From 2323912d07a33b655308f2c7be88c24b6b615492 Mon Sep 17 00:00:00 2001 From: Josh Meekhof Date: Thu, 8 Oct 2015 09:20:10 -0400 Subject: [PATCH] Fixing #535 related issues. Each of the clean_functions now searches for forests. --- deploy/lib/server_config.rb | 96 +++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/deploy/lib/server_config.rb b/deploy/lib/server_config.rb index 3e9d74ae..ea047bd1 100644 --- a/deploy/lib/server_config.rb +++ b/deploy/lib/server_config.rb @@ -555,7 +555,7 @@ def merge end return true end - + def merge_db(target_db) logger.info "Merging #{target_db} on #{@hostname}" @@ -584,19 +584,19 @@ def reindex end return true end - + def reindex_db(target_db) logger.info "Reindexing #{target_db} on #{@hostname}" r = execute_query %Q{ xquery version "1.0-ml"; - import module namespace admin = "http://marklogic.com/xdmp/admin" + import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; admin:save-configuration-without-restart( admin:database-set-reindexer-timestamp( - admin:get-configuration(), + admin:get-configuration(), xdmp:database("#{target_db}"), xdmp:request-timestamp() ) @@ -1151,7 +1151,7 @@ def mlcp jars = Dir.glob(ServerConfig.expand_path("#{mlcp_home}/lib/*.jar")) confdir = ServerConfig.expand_path("#{mlcp_home}/conf") classpath = "#{confdir}#{path_separator}#{jars.join(path_separator)}" - + vmargs = %Q{"-DCONTENTPUMP_HOME=#{mlcp_home}" -Dfile.encoding=UTF-8 -Dxcc.txn.compatible=true "-Djava.library.path=#{mlcp_home}/lib/native" #{@properties['ml.mlcp-vmargs']} } ARGV.each do |arg| @@ -1372,7 +1372,7 @@ def save_files_to_fs(target_db, target_dir) for $uri in cts:uris() order by $uri return $uri - + } catch ($ignore) { (: In case URI lexicon has not been enabled :) for $doc in collection() @@ -1529,23 +1529,23 @@ def deploy_src folders_to_ignore = @properties['ml.ignore-folders'] if @properties['ml.save-commit-info'] == 'true' - + if File.exists? ".svn" svn_info_file = File.new("#{xquery_dir}/svn-info.xml", "w") svn_info_file.puts(`svn info --xml`) svn_info_file.close @logger.info "Saved commit info as #{xquery_dir}/svn-info.xml" - + elsif File.exists? ".git" git_info_file = File.new("#{xquery_dir}/git-info.xml", "w") git_info_file.puts(`git log -1 --pretty=format:"%H%an%ai%s%b"`) git_info_file.close @logger.info "Saved commit info as #{xquery_dir}/git-info.xml" - + else @logger.warn "Only SVN and GIT supported for save-commit-info" end - + end modules_databases.each do |dest_db| @@ -1719,14 +1719,22 @@ def clean_modules if @properties['ml.test-modules-db'].present? && @properties['ml.test-modules-db'] != @properties['ml.modules-db'] logger.info "Cleaning #{@properties['ml.test-modules-db']} on #{@hostname}" - execute_query %Q{xdmp:forest-clear(xdmp:forest("#{@properties['ml.test-modules-db']}"))} + r = execute_query %Q{ + for $id in xdmp:database-forests(xdmp:database("#{@properties['ml.test-modules-db']}")) + return + try { xdmp:forest-clear($id) } catch ($ignore) { fn:concat("Skipped forest ", xdmp:forest-name($id), "..") } + } end end def clean_schemas if @properties['ml.schemas-db'] logger.info "Cleaning #{@properties['ml.schemas-db']} on #{@hostname}" - execute_query %Q{xdmp:forest-clear(xdmp:forest("#{@properties['ml.schemas-db']}"))} + r = execute_query %Q{ + for $id in xdmp:database-forests(xdmp:database("#{@properties['ml.schemas-db']}")) + return + try { xdmp:forest-clear($id) } catch ($ignore) { fn:concat("Skipped forest ", xdmp:forest-name($id), "..") } + } else logger.error "No schemas db is configured" end @@ -1735,7 +1743,11 @@ def clean_schemas def clean_triggers if @properties['ml.triggers-db'] logger.info "Cleaning #{@properties['ml.triggers-db']} on #{@hostname}" - execute_query %Q{xdmp:forest-clear(xdmp:forest("#{@properties['ml.triggers-db']}"))} + r = execute_query %Q{ + for $id in xdmp:database-forests(xdmp:database("#{@properties['ml.triggers-db']}")) + return + try { xdmp:forest-clear($id) } catch ($ignore) { fn:concat("Skipped forest ", xdmp:forest-name($id), "..") } + } else logger.error "No triggers db is configured" end @@ -2060,7 +2072,7 @@ def conditional_prop(prop, default_prop) value end - + def triggers_db_xml %Q{ @@ -2071,7 +2083,7 @@ def triggers_db_xml } end - + def triggers_assignment %Q{ @@ -2092,7 +2104,7 @@ def xdbc_server } end - + def odbc_server odbc_auth_method = conditional_prop('ml.odbc-authentication-method', 'ml.authentication-method') %Q{ @@ -2105,7 +2117,7 @@ def odbc_server } end - + def schemas_db_xml %Q{ @@ -2124,7 +2136,7 @@ def schemas_assignment } end - + def test_content_db_xml %Q{ @@ -2135,7 +2147,7 @@ def test_content_db_xml } end - + def test_content_db_assignment %Q{ @@ -2143,7 +2155,7 @@ def test_content_db_assignment } end - + def test_appserver # The modules database for the test server can be different from the app one test_modules_db = conditional_prop('ml.test-modules-db', 'ml.app-modules-db') @@ -2161,7 +2173,7 @@ def test_appserver } end - + def test_modules_db_xml %Q{ @@ -2180,7 +2192,7 @@ def test_modules_db_assignment } end - + def rest_appserver rest_modules_db = conditional_prop('ml.rest-modules-db', 'ml.app-modules-db') rest_auth_method = conditional_prop('ml.rest-authentication-method', 'ml.authentication-method') @@ -2191,10 +2203,10 @@ def rest_appserver rest_url_rewriter = @properties['ml.rest-url-rewriter'] elsif @server_version > 7 rest_url_rewriter = '/MarkLogic/rest-api/rewriter.xml' - else + else rest_url_rewriter = '/MarkLogic/rest-api/rewriter.xqy' end - + %Q{ @ml.app-name-rest @@ -2209,10 +2221,10 @@ def rest_appserver } end - + def rest_modules_db_xml rest_modules_db = conditional_prop('ml.rest-modules-db', 'ml.app-modules-db') - + %Q{ #{rest_modules_db} @@ -2222,17 +2234,17 @@ def rest_modules_db_xml } end - + def rest_modules_db_assignment rest_modules_db = conditional_prop('ml.rest-modules-db', 'ml.app-modules-db') - + %Q{ #{rest_modules_db} } end - + def ssl_certificate_xml %Q{ @@ -2254,7 +2266,7 @@ def build_config(config_files) # Build the triggers db if it is provided if @properties['ml.triggers-db'].present? - + if @properties['ml.triggers-db'] != @properties['ml.app-modules-db'] config.gsub!("@ml.triggers-db-xml", triggers_db_xml) config.gsub!("@ml.triggers-assignment", triggers_assignment) @@ -2267,7 +2279,7 @@ def build_config(config_files) %Q{ }) - + else config.gsub!("@ml.triggers-db-xml", "") config.gsub!("@ml.triggers-assignment", "") @@ -2288,7 +2300,7 @@ def build_config(config_files) # Build the schemas db if it is provided if @properties['ml.schemas-db'].present? - + if @properties['ml.schemas-db'] != @properties['ml.app-modules-db'] config.gsub!("@ml.schemas-db-xml", schemas_db_xml) config.gsub!("@ml.schemas-assignment", schemas_assignment) @@ -2316,7 +2328,7 @@ def build_config(config_files) config.gsub!("@ml.test-content-db-xml", test_content_db_xml) config.gsub!("@ml.test-content-db-assignment", test_content_db_assignment) config.gsub!("@ml.test-appserver", test_appserver) - + else config.gsub!("@ml.test-content-db-xml", "") config.gsub!("@ml.test-content-db-assignment", "") @@ -2326,10 +2338,10 @@ def build_config(config_files) # Build the test modules db if it is different from the app modules db if @properties['ml.test-modules-db'].present? && @properties['ml.test-modules-db'] != @properties['ml.app-modules-db'] - + config.gsub!("@ml.test-modules-db-xml", test_modules_db_xml) config.gsub!("@ml.test-modules-db-assignment", test_modules_db_assignment) - + else config.gsub!("@ml.test-modules-db-xml", "") config.gsub!("@ml.test-modules-db-assignment", "") @@ -2339,7 +2351,7 @@ def build_config(config_files) # Set up a REST API app server, distinct from the main application. config.gsub!("@ml.rest-appserver", rest_appserver) - + if @properties['ml.rest-modules-db'].present? && @properties['ml.rest-modules-db'] != @properties['ml.app-modules-db'] config.gsub!("@ml.rest-modules-db-xml", rest_modules_db_xml) @@ -2377,15 +2389,15 @@ def build_config(config_files) else config.gsub!("@ml.rewrite-resolves-globally", "") end - + if @properties['ml.ssl-certificate-template'].present? config.gsub!("@ml.ssl-certificate-xml", ssl_certificate_xml) else config.gsub!("@ml.ssl-certificate-xml", "") end - + replace_properties(config, File.basename(config_file)) - + # escape unresolved braces, they have special meaning in XQuery config.gsub!("{", "{{") config.gsub!("}", "}}") @@ -2395,7 +2407,7 @@ def build_config(config_files) %Q{(#{configs.join(", ")})} end - + def replace_properties(contents, name) # make sure to apply descending order to replace @ml.foo-bar before @ml.foo @properties.sort {|x,y| y <=> x}.each do |k, v| @@ -2403,11 +2415,11 @@ def replace_properties(contents, name) n = k.sub("ml.", "") contents.gsub!("@{#{n}}", v) contents.gsub!("${#{n}}", v) - + # backwards compat, old syntax: @ml.app-name contents.gsub!("@#{k}", v) end - + # warn for unresolved properties contents.scan(/[@$]\{[^}]+\}/).each do |match| logger.warn("Unresolved property #{match} in #{name}")