Skip to content

Commit

Permalink
marklogic-community#109 changes to include triggers in self-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcassel committed Mar 22, 2016
1 parent 3725f06 commit 5ed45f4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 49 deletions.
84 changes: 38 additions & 46 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,6 @@ def clean
clean_content
when 'modules'
clean_modules
when 'triggers'
clean_triggers
when 'schemas'
clean_schemas
when 'cpf'
Expand Down Expand Up @@ -1400,6 +1398,44 @@ def settings
return true
end

def deploy_triggers
logger.info "Deploying Triggers"
if !@properties["ml.triggers-db"]
raise ExitException.new("Deploy triggers requires a triggers database")
end

target_config = ServerConfig.expand_path(ServerConfig.properties["ml.triggers.file"])

if !File.exist?(target_config)
logger.error <<-ERR.strip_heredoc
Before you can deploy triggers, you must define a configuration. Steps:
1. Copy deploy/sample/triggers-config.sample.xml to #{target_config}
The location of this file is controlled by the triggers.file property.
2. Edit #{target_config} to specify your trigger(s)
3. Run 'ml <env> deploy triggers')
ERR
return false
else
triggers_config = File.read target_config
replace_properties(triggers_config, target_config)
triggers_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/triggers.xqy")
query = %Q{#{triggers_code} triggers:load-from-config(#{triggers_config})}
logger.debug(query)
r = execute_query(query, :db_name => @properties["ml.triggers-db"])
return true
end
end

def clean_triggers
if @properties['ml.triggers-db']
triggers_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/triggers.xqy")
r = execute_query %Q{#{triggers_code} triggers:clean-triggers()}, :db_name => @properties["ml.triggers-db"]
return true
else
logger.error "No triggers db is configured"
end
end

private

def filter_to_newer_files(files, options)
Expand Down Expand Up @@ -1815,19 +1851,6 @@ def clean_schemas
end
end

def clean_triggers
if @properties['ml.triggers-db']
logger.info "Cleaning #{@properties['ml.triggers-db']} on #{@hostname}"
r = execute_query %Q{
for $id in xdmp:database-forests(xdmp:database("#{@properties['ml.triggers-db']}"))
return
try { xdmp:forest-clear($id) } catch ($ignore) { fn:concat("Skipped forest ", xdmp:forest-name($id), "..") }
}
else
logger.error "No triggers db is configured"
end
end

def deploy_content
count = load_data @properties["ml.data.dir"],
:remove_prefix => @properties["ml.data.dir"],
Expand Down Expand Up @@ -1872,37 +1895,6 @@ def clean_cpf
r = execute_query %Q{#{cpf_code} cpf:clean-cpf()}, :db_name => @properties["ml.content-db"]
end

def deploy_triggers
logger.info "Deploying Triggers"
if !@properties["ml.triggers-db"]
raise ExitException.new("Deploy triggers requires a triggers database")
end

target_config = ServerConfig.expand_path(ServerConfig.properties["ml.triggers.file"])

if !File.exist?(target_config)
logger.error <<-ERR.strip_heredoc
Before you can deploy triggers, you must define a configuration. Steps:
1. Copy deploy/sample/triggers-config.sample.xml to #{target_config}
The location of this file is controlled by the triggers.file property.
2. Edit #{target_config} to specify your trigger(s)
3. Run 'ml <env> deploy triggers')
ERR
else
triggers_config = File.read target_config
replace_properties(triggers_config, target_config)
triggers_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/triggers.xqy")
query = %Q{#{triggers_code} triggers:load-from-config(#{triggers_config})}
logger.debug(query)
r = execute_query(query, :db_name => @properties["ml.triggers-db"])
end
end

def clean_triggers
triggers_code = File.read ServerConfig.expand_path("#{@@path}/lib/xquery/triggers.xqy")
r = execute_query %Q{#{triggers_code} triggers:clean-triggers()}, :db_name => @properties["ml.triggers-db"]
end

def xcc
@xcc ||=
begin
Expand Down
2 changes: 1 addition & 1 deletion deploy/lib/xquery/setup.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ declare function setup:create-forests-from-config(
let $data-directory as xs:string? := $forest-config/as:data-directory[fn:string-length(fn:string(.)) > 0]
let $hosts := admin:group-get-host-ids(admin:get-configuration(), $group-id)
let $host-name as xs:string? := $forest-config/as:host-name[fn:string-length(fn:string(.)) > 0]
let $host-id := if ($host-name) then xdmp:host($host-name) else $hosts[1]
let $host-id := if ($host-name) then xdmp:host($host-name) else ($hosts, $default-host)[1]
let $hostnr := fn:index-of($hosts, $host-id)
let $replica-names as xs:string* := $forest-config/as:replica-names/as:replica-name[fn:string-length(fn:string(.)) > 0]
let $replicas :=
Expand Down
2 changes: 1 addition & 1 deletion deploy/test/data/ml6-properties/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ schemas-db=${app-name}-schemas
# Leave commented out for default
# turn it on if you are using triggers or CPF
#
#triggers-db=${app-name}-triggers
triggers-db=${app-name}-triggers

#
# the port that the Docs appserver is running on
Expand Down
2 changes: 1 addition & 1 deletion deploy/test/data/ml7-properties/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ schemas-db=${app-name}-schemas
# Leave commented out for default
# turn it on if you are using triggers or CPF
#
#triggers-db=${app-name}-triggers
triggers-db=${app-name}-triggers

#
# the port that the Docs appserver is running on
Expand Down
6 changes: 6 additions & 0 deletions deploy/test/test_server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@
})

@s.bootstrap.must_equal true
# sleep(10)
@s.validate_install.must_equal true
end
end

it "should deploy triggers" do
@s.deploy_triggers.must_equal true
@s.clean_triggers.must_equal true
end

after do
@logger.info "Wiping self-test deployment.."
@s.wipe
Expand Down

0 comments on commit 5ed45f4

Please sign in to comment.