Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 2f921ab

Browse files
committed
add feature to load multiple custom configuration files
1 parent 7bc489b commit 2f921ab

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

deploy/lib/server_config.rb

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,8 @@ def deploy
10461046
deploy_triggers
10471047
when 'rest-config'
10481048
deploy_rest_config
1049+
when 'config'
1050+
deploy_config
10491051
else
10501052
raise HelpException.new("deploy", "Invalid WHAT")
10511053
end
@@ -1863,12 +1865,12 @@ def modules_databases
18631865
def deploy_modules
18641866
deploy_src()
18651867
deploy_rest()
1868+
deploy_config()
18661869
end
18671870

18681871
def deploy_src
18691872
test_dir = @properties['ml.xquery-test.dir']
18701873
xquery_dir = @properties['ml.xquery.dir']
1871-
# modules_db = @properties['ml.modules-db']
18721874
app_config_file = File.join xquery_dir, "/app/config/config.xqy"
18731875
test_config_file = File.join test_dir, "/test-config.xqy"
18741876
load_html_as_xml = @properties['ml.load-html-as-xml']
@@ -1971,6 +1973,54 @@ def deploy_src
19711973
end
19721974
end
19731975

1976+
def deploy_config
1977+
xquery_dir = @properties['ml.xquery.dir']
1978+
app_configs = @properties['ml.application-conf-file']
1979+
total_count = 0
1980+
1981+
modules_databases.each do |dest_db|
1982+
if dest_db == "filesystem"
1983+
logger.info "Skipping deployment of configurations to #{dest_db}.."
1984+
break
1985+
end
1986+
1987+
src_permissions = permissions(@properties['ml.app-role'], Roxy::ContentCapability::ERU)
1988+
1989+
if ['rest', 'hybrid'].include? @properties["ml.app-type"]
1990+
# This app uses the REST API, so grant permissions to the rest roles. This allows REST extensions to call
1991+
# modules not deployed through the REST API.
1992+
# These roles are present in MarkLogic 6+.
1993+
src_permissions.push permissions('rest-admin', Roxy::ContentCapability::RU)
1994+
src_permissions.push permissions('rest-extension-user', Roxy::ContentCapability::EXECUTE)
1995+
src_permissions.flatten!
1996+
end
1997+
1998+
@logger.debug("source permissions: #{src_permissions}")
1999+
2000+
if app_configs.present?
2001+
logger.info "Deploying application configurations"
2002+
app_configs.split(',').each do |item|
2003+
buffer = File.read item
2004+
replace_properties(buffer, File.basename(item))
2005+
item_name = item
2006+
if item.start_with?("src/")
2007+
item_name = item[4, item.length]
2008+
end
2009+
item_name = '/' + item_name
2010+
logger.info "deploying application configuration #{item} with name #{item_name} on #{dest_db}"
2011+
total_count += xcc.load_buffer item_name,
2012+
buffer,
2013+
:db => dest_db,
2014+
:add_prefix => File.join(@properties["ml.modules-root"], "app/config/"),
2015+
:permissions => src_permissions
2016+
end
2017+
logger.info "Done deploying application configurations"
2018+
end
2019+
2020+
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"
2021+
end
2022+
end
2023+
19742024
def deploy_rest
19752025
# Deploy options, extensions to the REST API server
19762026
if ['rest', 'hybrid'].include? @properties["ml.app-type"]

deploy/sample/build.sample.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,10 @@ mlcp-vmargs=-Xmx512m
208208

209209
# enable the following to save and upload svn/git commit info upon deploy modules
210210
save-commit-info=false
211+
212+
# enable the following to add custom configuration files
213+
# contents of the files will be replaces with data from the
214+
# properties files.
215+
#
216+
# multiple configuration files can be loaded by separating it with comma.
217+
# application-conf-file=src/app/config/custom-config.xqy

src/app/config/custom-config.xqy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(:
2+
Copyright 2012-2015 MarkLogic Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
:)
16+
xquery version "1.0-ml";
17+
18+
module namespace c = "http://marklogic.com/roxy/application-config";
19+
20+
(: configured at deploy time by Roxy deployer :)
21+
declare variable $c:app-name := "@ml.app-name";
22+

0 commit comments

Comments
 (0)