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 committed Oct 8, 2015
1 parent ce106ea commit 73a96c0
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 @@ -554,7 +554,7 @@ def merge
end
return true
end

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

Expand Down Expand Up @@ -583,19 +583,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 @@ -1150,7 +1150,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 @@ -1367,7 +1367,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 @@ -1524,23 +1524,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 @@ -1714,14 +1714,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 @@ -1730,7 +1738,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 @@ -2055,7 +2067,7 @@ def conditional_prop(prop, default_prop)

value
end

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

def triggers_assignment
%Q{
<assignment>
Expand All @@ -2087,7 +2099,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 @@ -2100,7 +2112,7 @@ def odbc_server
</odbc-server>
}
end

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

def test_content_db_xml
%Q{
<database import="@ml.content-db">
Expand All @@ -2130,15 +2142,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 @@ -2156,7 +2168,7 @@ def test_appserver
</http-server>
}
end

def test_modules_db_xml
%Q{
<database import="@ml.modules-db">
Expand All @@ -2175,7 +2187,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 @@ -2186,10 +2198,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 @@ -2204,10 +2216,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 @@ -2217,17 +2229,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 @@ -2249,7 +2261,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 @@ -2262,7 +2274,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 @@ -2283,7 +2295,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 @@ -2311,7 +2323,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 @@ -2321,10 +2333,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 @@ -2334,7 +2346,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 @@ -2372,15 +2384,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 @@ -2390,19 +2402,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 73a96c0

Please sign in to comment.