New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure triggers #109

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

Comments

Projects
None yet
5 participants
@dmcassel
Member

dmcassel commented Jun 8, 2013

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

@adamfowleruk

This comment has been minimized.

Show comment
Hide comment
@adamfowleruk

adamfowleruk Jul 18, 2013

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

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

@peetkes

This comment has been minimized.

Show comment
Hide comment
@peetkes

peetkes Mar 19, 2014

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@grtjn

grtjn Mar 19, 2014

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Mar 19, 2014

Member

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
Member

dmcassel commented Mar 19, 2014

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

This comment has been minimized.

Show comment
Hide comment
@grtjn

grtjn May 19, 2014

Contributor

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
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

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel May 19, 2014

Member

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

Member

dmcassel commented May 19, 2014

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

@eouthwaite

This comment has been minimized.

Show comment
Hide comment
@grtjn

This comment has been minimized.

Show comment
Hide comment
@grtjn

grtjn Jun 30, 2015

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Jul 1, 2015

Member

+1 on adding commands for triggers and alerts

Member

dmcassel commented Jul 1, 2015

+1 on adding commands for triggers and alerts

@peetkes

This comment has been minimized.

Show comment
Hide comment
@peetkes

peetkes Jul 1, 2015

Contributor

At last!!! +1!

Contributor

peetkes commented Jul 1, 2015

At last!!! +1!

@grtjn

This comment has been minimized.

Show comment
Hide comment
@grtjn

grtjn Sep 17, 2015

Contributor

Sorry guys, pushing away for the time being..

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

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Mar 4, 2016

Member

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

Member

dmcassel commented Mar 4, 2016

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

@dmcassel

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Mar 4, 2016

Member

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.

Member

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

#109 call functions instead of relying on correct XML
By calling functions, mistakes in the configuration XML will trigger
more specific errors.
@dmcassel

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Mar 10, 2016

Member

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

Member

dmcassel commented Mar 10, 2016

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

This comment has been minimized.

Show comment
Hide comment
@dmcassel

dmcassel Apr 4, 2016

Member

fixed in dev

Member

dmcassel commented Apr 4, 2016

fixed in dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment