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

Commit

Permalink
Merge pull request #784 from grtjn/762-configurable-cpf-file
Browse files Browse the repository at this point in the history
Fixed #762: Made pipeline-config.xml configurable
  • Loading branch information
RobertSzkutak authored Jun 11, 2017
2 parents fb773db + cf1bee3 commit 0c8ea68
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
6 changes: 6 additions & 0 deletions deploy/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,9 @@ application-conf-file=src/app/config/config.xqy
#
verify_retry_max=5
verify_retry_interval=10

#
# CPF Pipeline configuration file
#
# can be overridden from {env}.properties
pipeline-config-file=${basedir}/deploy/pipeline-config.xml
37 changes: 24 additions & 13 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def ServerConfig.expand_path(path)
return result
end

def ServerConfig.strip_path(path)
basepath = File.expand_path(@@path + "/..", @@context)
return path.sub(basepath + '/', '')
end

def self.jar
raise HelpException.new("jar", "You must be using JRuby to create a jar") unless RUBY_PLATFORM == "java"
begin
Expand Down Expand Up @@ -302,9 +307,9 @@ def self.initcpf
if @@is_jar
sample_config = "roxy/sample/pipeline-config.sample.xml"
else
sample_config = ServerConfig.expand_path("#{@@path}/sample/pipeline-config.sample.xml")
sample_config = ServerConfig.expand_path("#{@@path}/sample/pipeline-config.sample.xml")
end
target_config = ServerConfig.expand_path("#{@@path}/pipeline-config.xml")
target_config = ServerConfig.expand_path(ServerConfig.properties["ml.pipeline-config-file"])

force = find_arg(['--force']).present?
if !force && File.exists?(target_config)
Expand Down Expand Up @@ -1259,7 +1264,7 @@ def install
if @properties["ml.triggers-db"] then
deploy_triggers
end
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml")) then
if @properties["ml.triggers-db"] and @properties["ml.data.dir"] and File.exist?(ServerConfig.expand_path(@properties["ml.pipeline-config-file"])) then
deploy_cpf
end
deploy_content
Expand Down Expand Up @@ -2249,18 +2254,24 @@ def clean_content
end

def deploy_cpf
default_cpf_config_file = ServerConfig.expand_path(ServerConfig.properties["ml.pipeline-config-file"])
cpf_config_file = ServerConfig.expand_path(@properties["ml.pipeline-config-file"])

if @properties["ml.triggers-db"].blank? || @properties["ml.data.dir"].blank?
logger.error "To use CPF, you must define the triggers-db property in your build.properties file"
elsif !File.exist?(ServerConfig.expand_path("#{@@path}/pipeline-config.xml"))
logger.error <<-ERR.strip_heredoc
Before you can deploy CPF, you must define a configuration. Steps:
1. Run 'ml initcpf'
2. Edit deploy/pipeline-config.xml to set up your domain and pipelines
3. Run 'ml <env> deploy cpf')
ERR
logger.error "To use CPF, you must define the triggers-db property in your deploy/build.properties file"
elsif !File.exist?(cpf_config_file)
msg = "Before you can deploy CPF, you must define a configuration. Steps:"
if !File.exist?(default_cpf_config_file) && !File.exist?(cpf_config_file)
msg = msg + "\n- CPF requires a pipeline-config file, run ml initcpf to create a sample."
end
if !File.exist?(cpf_config_file) && cpf_config_file != default_cpf_config_file
msg = msg + "\n- Copy #{ServerConfig.strip_path(default_cpf_config_file)} to #{ServerConfig.strip_path(cpf_config_file)}."
end
msg = msg + "\n- Edit #{ServerConfig.strip_path(cpf_config_file)} to customize your domain and pipelines for the given environment."
logger.error msg
else
cpf_config = File.read ServerConfig.expand_path("#{@@path}/pipeline-config.xml")
replace_properties(cpf_config, "pipeline-config.xml")
cpf_config = File.read cpf_config_file
replace_properties(cpf_config, ServerConfig.strip_path(cpf_config_file))
cpf_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/cpf.xqy")
query = %Q{#{cpf_code} cpf:load-from-config(#{cpf_config})}
logger.debug(query)
Expand Down
21 changes: 12 additions & 9 deletions deploy/lib/xquery/cpf.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,18 @@ declare function cpf:install-cpf-pipelines(
</options>
)
return
xdmp:eval(
'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
declare variable $doc external;
p:insert($doc/*)',
(xs:QName("doc"), $doc),
<options xmlns="xdmp:eval">
<database>{xdmp:triggers-database()}</database>
</options>
)
if (fn:empty($doc)) then
fn:error(xs:QName("NOTFOUND"), "Pipeline config " || $uri || " not found. Did you deploy modules?")
else
xdmp:eval(
'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";
declare variable $doc external;
p:insert($doc/*)',
(xs:QName("doc"), $doc),
<options xmlns="xdmp:eval">
<database>{xdmp:triggers-database()}</database>
</options>
)
};

(:
Expand Down
2 changes: 1 addition & 1 deletion deploy/sample/pipeline-config.sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>This domain is awesome!!!</description>
<pipelines>
<!-- one <pipeline> for each cpf pipeline to install in this domain -->
<pipeline>/locaton/to/your/pipeline.xml</pipeline>
<pipeline>/location/to/your/pipeline.xml</pipeline>
</pipelines>
<system-pipelines>
<system-pipeline>Status Change Handling</system-pipeline>
Expand Down

0 comments on commit 0c8ea68

Please sign in to comment.