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

Configure triggers #109

Closed
dmcassel opened this issue Jun 8, 2013 · 15 comments
Closed

Configure triggers #109

dmcassel opened this issue Jun 8, 2013 · 15 comments
Assignees
Milestone

Comments

@dmcassel
Copy link
Collaborator

dmcassel commented Jun 8, 2013

Figure out a good way to include triggers in the deploy process and implement it.

@adamfowleruk
Copy link

+1 on this too. Many of my demos make extensive use of triggers. Having this would simplify sharing demos and remove misconfiguration issues.

@peetkes
Copy link
Contributor

peetkes commented Mar 19, 2014

+1 on this. We have a customer who uses roxy for dev and deploy and they are starting to implement triggers.

@grtjn
Copy link
Contributor

grtjn commented Mar 19, 2014

Hmm, interesting. You could mimic at least part by pushing trigger xml docs into the Triggers database, but can imagine that is a bit of a hassle.. ;-)

+1

@dmcassel
Copy link
Collaborator Author

Not yet implemented, but you can do it in deploy/app_specific.rb. Here's an example:

def create_alerting_triggers()
  r = execute_query %Q{
    import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
    import module namespace trgr = "http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy";

    if (alert:config-get("http://sample.com/audit/alert")) then ()
    else
      let $config :=
        alert:make-config(
          "http://sample.com/audit/alert",
          "Sample Change Alerting",
          "Alerting configuration for Sample",
          <alert:options/>)
      return
        alert:config-insert($config);


    import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
    import module namespace trgr = "http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy";

    if (alert:config-get-trigger-ids(alert:config-get("http://sample.com/audit/alert"))) then ()
    else
      let $uri := "http://sample.com/audit/alert"
      let $trigger-ids :=
          alert:create-triggers(
            $uri,
            trgr:trigger-data-event(
              trgr:directory-scope("/ItemInfo/", "1"),
              trgr:document-content(("modify")),
              trgr:pre-commit()))
      let $config := alert:config-set-trigger-ids(alert:config-get($uri), $trigger-ids)
      return
        alert:config-insert($config);

    import module namespace alert = "http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";
    import module namespace trgr = "http://marklogic.com/xdmp/triggers" at "/MarkLogic/triggers.xqy";

    if (alert:get-actions("http://sample.com/audit/alert", ("*"))) then ()
    else
      let $uri := "http://sample.com/audit/alert"
      let $action-add-mailfile :=
        alert:make-action(
          "add-to-inbox",
          "Add Audit Event to the User Inbox",
          xdmp:modules-database(),
          xdmp:modules-root(),
          "/lib/add-to-inbox.xqy",
          <alert:options/>
        )
      return
        alert:action-insert($uri, $action-add-mailfile)
  },
  { :app_name => @properties["ml.app-name"] }
end

@grtjn
Copy link
Contributor

grtjn commented May 19, 2014

Here an example for plain triggers:

class ServerConfig
  alias_method :original_deploy_modules, :deploy_modules
  def deploy_modules()
    original_deploy_modules

    r = execute_query(%Q{
        xquery version "1.0-ml";

        import module namespace trgr="http://marklogic.com/xdmp/triggers" 
           at "/MarkLogic/triggers.xqy";

        xdmp:log("Installing triggers.."),

        try {
          trgr:remove-trigger("CreateTrigger"),
          trgr:remove-trigger("ModifyTrigger")
        } catch ($ignore) {
        };


        xquery version "1.0-ml";

        import module namespace trgr="http://marklogic.com/xdmp/triggers" 
           at "/MarkLogic/triggers.xqy";

        trgr:create-trigger("CreateTrigger", "Trigger to enrich XML ingested via MLCP", 
          trgr:trigger-data-event(
            trgr:directory-scope("/ingest/", "1"),
            trgr:document-content("create"),
            trgr:pre-commit()
          ),
          trgr:trigger-module(xdmp:modules-database(), "/", "/triggers/enrich-xml.xqy"),
          fn:true(),
          xdmp:default-permissions(),
          fn:false()
        ),

        trgr:create-trigger("ModifyTrigger", "Trigger to enrich XML ingested via MLCP", 
          trgr:trigger-data-event(
            trgr:directory-scope("/ingest/", "1"),
            trgr:document-content("modify"),
            trgr:pre-commit()
          ),
          trgr:trigger-module(xdmp:modules-database(), "/", "/triggers/enrich-xml.xqy"),
          fn:true(),
          xdmp:default-permissions(),
          fn:false()
        )
      },
      :app_name => @properties["ml.app-name"]
    )
  end
end

@dmcassel
Copy link
Collaborator Author

I just added both of these samples to the Adding Custom Build Steps wiki.

@eouthwaite
Copy link

Could Richard's method be implemented as standard ?
https://rclayton.silvrback.com/writing-and-deploying-triggers-in-marklogic-roxy

@grtjn
Copy link
Contributor

grtjn commented Jun 30, 2015

I would prefer going even a step further, and taking deployment of CPF as example:

ml local deploy triggers
ml local clean triggers

and while at it:

ml local deploy alerts
ml local clean alerts

The idea would be to record essential settings in some XML config, and have that interpreted and executed. The syntax could be close to the real XML syntax of triggers/alerts inside the database. I expect that to be less error prone..

A bit more involved, but will add it to the wishlist of release 1.7.3

@grtjn grtjn added this to the 1.7.3 milestone Jun 30, 2015
@dmcassel
Copy link
Collaborator Author

dmcassel commented Jul 1, 2015

+1 on adding commands for triggers and alerts

@peetkes
Copy link
Contributor

peetkes commented Jul 1, 2015

At last!!! +1!

@grtjn
Copy link
Contributor

grtjn commented Sep 17, 2015

Sorry guys, pushing away for the time being..

@grtjn grtjn modified the milestones: 1.7.4, 1.7.3 Sep 17, 2015
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 4, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 4, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 4, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 4, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 4, 2016
@dmcassel
Copy link
Collaborator Author

dmcassel commented Mar 4, 2016

@adamfowleruk @peetkes @eouthwaite I implemented deploying and removing (cleaning) triggers. Testers welcome.

@dmcassel
Copy link
Collaborator Author

dmcassel commented Mar 4, 2016

If this approach looks good, alerts could be added to the same file (triggers-config.xml) or to a file that is specific to alerts.

@dmcassel dmcassel self-assigned this Mar 4, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 8, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 8, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 8, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 8, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 9, 2016
By calling functions, mistakes in the configuration XML will trigger
more specific errors.
@dmcassel
Copy link
Collaborator Author

Added a wiki describing the new feature (currently in a PR).

@dmcassel dmcassel modified the milestones: 1.7.3, 1.7.4 Mar 10, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 22, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 22, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Mar 22, 2016
dmcassel added a commit to dmcassel/roxy that referenced this issue Apr 4, 2016
@dmcassel
Copy link
Collaborator Author

dmcassel commented Apr 4, 2016

fixed in dev

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants