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

Commit 0c8ea68

Browse files
Merge pull request #784 from grtjn/762-configurable-cpf-file
Fixed #762: Made pipeline-config.xml configurable
2 parents fb773db + cf1bee3 commit 0c8ea68

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
@@ -279,3 +279,9 @@ application-conf-file=src/app/config/config.xqy
279279
#
280280
verify_retry_max=5
281281
verify_retry_interval=10
282+
283+
#
284+
# CPF Pipeline configuration file
285+
#
286+
# can be overridden from {env}.properties
287+
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)
@@ -1259,7 +1264,7 @@ def install
12591264
if @properties["ml.triggers-db"] then
12601265
deploy_triggers
12611266
end
1262-
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml")) then
1267+
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path(@properties["ml.pipeline-config-file"])) then
12631268
deploy_cpf
12641269
end
12651270
deploy_content
@@ -2249,18 +2254,24 @@ def clean_content
22492254
end
22502255

22512256
def deploy_cpf
2257+
default_cpf_config_file = ServerConfig.expand_path(ServerConfig.properties["ml.pipeline-config-file"])
2258+
cpf_config_file = ServerConfig.expand_path(@properties["ml.pipeline-config-file"])
2259+
22522260
if @properties["ml.triggers-db"].blank? || @properties["ml.data.dir"].blank?
2253-
logger.error "To use CPF, you must define the triggers-db property in your build.properties file"
2254-
elsif !File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml"))
2255-
logger.error <<-ERR.strip_heredoc
2256-
Before you can deploy CPF, you must define a configuration. Steps:
2257-
1. Run 'ml initcpf'
2258-
2. Edit deploy/pipeline-config.xml to set up your domain and pipelines
2259-
3. Run 'ml <env> deploy cpf')
2260-
ERR
2261+
logger.error "To use CPF, you must define the triggers-db property in your deploy/build.properties file"
2262+
elsif !File.exist?(cpf_config_file)
2263+
msg = "Before you can deploy CPF, you must define a configuration. Steps:"
2264+
if !File.exist?(default_cpf_config_file) && !File.exist?(cpf_config_file)
2265+
msg = msg + "\n- CPF requires a pipeline-config file, run ml initcpf to create a sample."
2266+
end
2267+
if !File.exist?(cpf_config_file) && cpf_config_file != default_cpf_config_file
2268+
msg = msg + "\n- Copy #{ServerConfig.strip_path(default_cpf_config_file)} to #{ServerConfig.strip_path(cpf_config_file)}."
2269+
end
2270+
msg = msg + "\n- Edit #{ServerConfig.strip_path(cpf_config_file)} to customize your domain and pipelines for the given environment."
2271+
logger.error msg
22612272
else
2262-
cpf_config = File.read ServerConfig.expand_path("#{@@path}/pipeline-config.xml")
2263-
replace_properties(cpf_config, "pipeline-config.xml")
2273+
cpf_config = File.read cpf_config_file
2274+
replace_properties(cpf_config, ServerConfig.strip_path(cpf_config_file))
22642275
cpf_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/cpf.xqy")
22652276
query = %Q{#{cpf_code} cpf:load-from-config(#{cpf_config})}
22662277
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)