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

Commit cf1bee3

Browse files
committed
Fixed #762: Made pipeline-config.xml configurable
1 parent 8b3ac5d commit cf1bee3

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

deploy/default.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,9 @@ application-conf-file=src/app/config/config.xqy
276276
#
277277
verify_retry_max=5
278278
verify_retry_interval=10
279+
280+
#
281+
# CPF Pipeline configuration file
282+
#
283+
# can be overridden from {env}.properties
284+
pipeline-config-file=${basedir}/deploy/pipeline-config.xml

deploy/lib/server_config.rb

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ def ServerConfig.expand_path(path)
147147
return result
148148
end
149149

150+
def ServerConfig.strip_path(path)
151+
basepath = File.expand_path(@@path + "/..", @@context)
152+
return path.sub(basepath + '/', '')
153+
end
154+
150155
def self.jar
151156
raise HelpException.new("jar", "You must be using JRuby to create a jar") unless RUBY_PLATFORM == "java"
152157
begin
@@ -302,9 +307,9 @@ def self.initcpf
302307
if @@is_jar
303308
sample_config = "roxy/sample/pipeline-config.sample.xml"
304309
else
305-
sample_config = ServerConfig.expand_path("#{@@path}/sample/pipeline-config.sample.xml")
310+
sample_config = ServerConfig.expand_path("#{@@path}/sample/pipeline-config.sample.xml")
306311
end
307-
target_config = ServerConfig.expand_path("#{@@path}/pipeline-config.xml")
312+
target_config = ServerConfig.expand_path(ServerConfig.properties["ml.pipeline-config-file"])
308313

309314
force = find_arg(['--force']).present?
310315
if !force && File.exists?(target_config)
@@ -1194,7 +1199,7 @@ def install
11941199
if @properties["ml.triggers-db"] then
11951200
deploy_triggers
11961201
end
1197-
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml")) then
1202+
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path(@properties["ml.pipeline-config-file"])) then
11981203
deploy_cpf
11991204
end
12001205
deploy_content
@@ -2182,18 +2187,24 @@ def clean_content
21822187
end
21832188

21842189
def deploy_cpf
2190+
default_cpf_config_file = ServerConfig.expand_path(ServerConfig.properties["ml.pipeline-config-file"])
2191+
cpf_config_file = ServerConfig.expand_path(@properties["ml.pipeline-config-file"])
2192+
21852193
if @properties["ml.triggers-db"].blank? || @properties["ml.data.dir"].blank?
2186-
logger.error "To use CPF, you must define the triggers-db property in your build.properties file"
2187-
elsif !File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml"))
2188-
logger.error <<-ERR.strip_heredoc
2189-
Before you can deploy CPF, you must define a configuration. Steps:
2190-
1. Run 'ml initcpf'
2191-
2. Edit deploy/pipeline-config.xml to set up your domain and pipelines
2192-
3. Run 'ml <env> deploy cpf')
2193-
ERR
2194+
logger.error "To use CPF, you must define the triggers-db property in your deploy/build.properties file"
2195+
elsif !File.exist?(cpf_config_file)
2196+
msg = "Before you can deploy CPF, you must define a configuration. Steps:"
2197+
if !File.exist?(default_cpf_config_file) && !File.exist?(cpf_config_file)
2198+
msg = msg + "\n- CPF requires a pipeline-config file, run ml initcpf to create a sample."
2199+
end
2200+
if !File.exist?(cpf_config_file) && cpf_config_file != default_cpf_config_file
2201+
msg = msg + "\n- Copy #{ServerConfig.strip_path(default_cpf_config_file)} to #{ServerConfig.strip_path(cpf_config_file)}."
2202+
end
2203+
msg = msg + "\n- Edit #{ServerConfig.strip_path(cpf_config_file)} to customize your domain and pipelines for the given environment."
2204+
logger.error msg
21942205
else
2195-
cpf_config = File.read ServerConfig.expand_path("#{@@path}/pipeline-config.xml")
2196-
replace_properties(cpf_config, "pipeline-config.xml")
2206+
cpf_config = File.read cpf_config_file
2207+
replace_properties(cpf_config, ServerConfig.strip_path(cpf_config_file))
21972208
cpf_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/cpf.xqy")
21982209
query = %Q{#{cpf_code} cpf:load-from-config(#{cpf_config})}
21992210
logger.debug(query)

deploy/lib/xquery/cpf.xqy

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,18 @@ declare function cpf:install-cpf-pipelines(
195195
</options>
196196
)
197197
return
198-
xdmp:eval(
199-
'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
200-
declare variable $doc external;
201-
p:insert($doc/*)',
202-
(xs:QName("doc"), $doc),
203-
<options xmlns="xdmp:eval">
204-
<database>{xdmp:triggers-database()}</database>
205-
</options>
206-
)
198+
if (fn:empty($doc)) then
199+
fn:error(xs:QName("NOTFOUND"), "Pipeline config " || $uri || " not found. Did you deploy modules?")
200+
else
201+
xdmp:eval(
202+
'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
203+
declare variable $doc external;
204+
p:insert($doc/*)',
205+
(xs:QName("doc"), $doc),
206+
<options xmlns="xdmp:eval">
207+
<database>{xdmp:triggers-database()}</database>
208+
</options>
209+
)
207210
};
208211

209212
(:

deploy/sample/pipeline-config.sample.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<description>This domain is awesome!!!</description>
77
<pipelines>
88
<!-- one <pipeline> for each cpf pipeline to install in this domain -->
9-
<pipeline>/locaton/to/your/pipeline.xml</pipeline>
9+
<pipeline>/location/to/your/pipeline.xml</pipeline>
1010
</pipelines>
1111
<system-pipelines>
1212
<system-pipeline>Status Change Handling</system-pipeline>

0 commit comments

Comments
 (0)