Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Louapre authored and jmeekhof committed Oct 7, 2015
1 parent 6e510bb commit a0d294c
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions deploy/lib/server_config.rb
Expand Up @@ -514,18 +514,14 @@ def execute_query(query, properties = {})
end

def restart
group = nil
ARGV.each do |arg|
# Exclude any argument passed from command line.
if ! arg.match("^-")
group = arg
end
group = ARGV.shift
# Exclude any argument passed from command line.
if group.index("-") == 0
group = nil
end

if group && group == "cluster"
logger.info "Restarting MarkLogic Server cluster of #{@hostname}"
elsif group
logger.info "Restarting MarkLogic Server group #{group}"
if group
logger.info "Restarting MarkLogic Server group #{group} on #{@hostname}"
else
# restarting partial cluster unsafe when working with multiple groups
#logger.info "Restarting MarkLogic Server group of #{@hostname}"
Expand Down Expand Up @@ -554,7 +550,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 +579,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 +1146,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 +1363,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 +1520,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 @@ -2048,7 +2044,7 @@ def conditional_prop(prop, default_prop)

value
end

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

def triggers_assignment
%Q{
<assignment>
Expand All @@ -2080,7 +2076,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 @@ -2093,7 +2089,7 @@ def odbc_server
</odbc-server>
}
end

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

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

def test_modules_db_xml
%Q{
<database import="@ml.modules-db">
Expand All @@ -2168,7 +2164,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 @@ -2179,10 +2175,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 @@ -2197,10 +2193,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 @@ -2210,17 +2206,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 @@ -2242,7 +2238,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 @@ -2255,7 +2251,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 @@ -2276,7 +2272,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 @@ -2304,7 +2300,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 @@ -2314,10 +2310,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 @@ -2327,7 +2323,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 @@ -2365,15 +2361,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 @@ -2383,19 +2379,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 a0d294c

Please sign in to comment.