Skip to content

Commit

Permalink
Fixing marklogic-community#535 related issues.
Browse files Browse the repository at this point in the history
Each of the clean_functions now searches for forests.
  • Loading branch information
jmeekhof authored and grtjn committed Jan 28, 2016
1 parent bb73315 commit 2323912
Showing 1 changed file with 54 additions and 42 deletions.
96 changes: 54 additions & 42 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def merge
end
return true
end

def merge_db(target_db)
logger.info "Merging #{target_db} on #{@hostname}"

Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:"<entry><id>%H</id><author>%an</author><date>%ai</date><subject>%s</subject><body>%b</body></entry>"`)
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|
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -2060,7 +2072,7 @@ def conditional_prop(prop, default_prop)

value
end

def triggers_db_xml
%Q{
<database>
Expand All @@ -2071,7 +2083,7 @@ def triggers_db_xml
</database>
}
end

def triggers_assignment
%Q{
<assignment>
Expand All @@ -2092,7 +2104,7 @@ def xdbc_server
</xdbc-server>
}
end

def odbc_server
odbc_auth_method = conditional_prop('ml.odbc-authentication-method', 'ml.authentication-method')
%Q{
Expand All @@ -2105,7 +2117,7 @@ def odbc_server
</odbc-server>
}
end

def schemas_db_xml
%Q{
<database>
Expand All @@ -2124,7 +2136,7 @@ def schemas_assignment
</assignment>
}
end

def test_content_db_xml
%Q{
<database import="@ml.content-db">
Expand All @@ -2135,15 +2147,15 @@ def test_content_db_xml
</database>
}
end

def test_content_db_assignment
%Q{
<assignment>
<forest-name>@ml.test-content-db</forest-name>
</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')
Expand All @@ -2161,7 +2173,7 @@ def test_appserver
</http-server>
}
end

def test_modules_db_xml
%Q{
<database import="@ml.modules-db">
Expand All @@ -2180,7 +2192,7 @@ def test_modules_db_assignment
</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')
Expand All @@ -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{
<http-server import="@ml.app-name">
<http-server-name>@ml.app-name-rest</http-server-name>
Expand All @@ -2209,10 +2221,10 @@ def rest_appserver
</http-server>
}
end

def rest_modules_db_xml
rest_modules_db = conditional_prop('ml.rest-modules-db', 'ml.app-modules-db')

%Q{
<database>
<database-name>#{rest_modules_db}</database-name>
Expand All @@ -2222,17 +2234,17 @@ def rest_modules_db_xml
</database>
}
end

def rest_modules_db_assignment
rest_modules_db = conditional_prop('ml.rest-modules-db', 'ml.app-modules-db')

%Q{
<assignment>
<forest-name>#{rest_modules_db}</forest-name>
</assignment>
}
end

def ssl_certificate_xml
%Q{
<certificate>
Expand All @@ -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)
Expand All @@ -2267,7 +2279,7 @@ def build_config(config_files)
%Q{
<triggers-database name="@ml.triggers-db"/>
})

else
config.gsub!("@ml.triggers-db-xml", "")
config.gsub!("@ml.triggers-assignment", "")
Expand All @@ -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)
Expand Down Expand Up @@ -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", "")
Expand All @@ -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", "")
Expand All @@ -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)
Expand Down Expand Up @@ -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!("}", "}}")
Expand All @@ -2395,19 +2407,19 @@ 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|
# new property syntax: @{app-name} or ${app-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}")
Expand Down

0 comments on commit 2323912

Please sign in to comment.