Re: [MarkLogic Dev General] trigger not getting invoked in a clustered environment

2011-09-17 Thread Danny Sokolsky
Raghu,

When you say it works in a single host, but not in a clustered environment, 
let's drill down into what has changed in your scenario.   See if you can find 
the error you are getting when it is not invoking the module.  That might 
provide a clue as to what is not working.  Here is what I would try:

1) Set up a single node cluster and ensure it is working.
2) Add another node to that same cluster and see if it still works against the 
host that it originally worked on.
3) Then try the same test using the other host as the e-node (that is, by 
executing the triggering query against the other node).

That will allow you to debug it.  If your code is in the modules database, then 
it should be accessible from anywhere in the cluster.  If, however, you have 
placed your code under the Modules directory, then you would need to duplicate 
that code in each node in the cluster.

Beyond the code being accessible from each host, I can't think of a particular 
setting that would cause it not to work on one host.  Something perhaps is 
different between your hosts that you have yet to discover.

Once again, if you are using cpf, then there are a few more dubugging 
alternatives.

-Danny

From: general-boun...@developer.marklogic.com 
[general-boun...@developer.marklogic.com] On Behalf Of Raghu 
[raghupathy.visweswa...@gmail.com]
Sent: Saturday, September 17, 2011 10:41 AM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] trigger not getting invoked in a clustered 
environment

HI Danny,

 Thanks. I've ensured that everything is in place. The same trigger 
works fine in a single host but in a clustered environment it   isn't invoking 
the module. Is there any setting which might cause this kind of behavior?

Thanks
Raghu

On Fri, Sep 16, 2011 at 9:48 PM, Danny Sokolsky 
mailto:danny.sokol...@marklogic.com>> wrote:
Hi Raghu,

Is your trigger module (/userdir/modules/xquery/migrate-helper.xqy based on the 
trigger create code you showed) loaded into the database names "Modules".  To 
check that, run (in cq for example):


fn:doc("/userdir/modules/xquery/migrate-helper.xqy ")


against the Modules database.  It should return the text of the module.


Assuming you are using CPF, in the document that is not being triggered, take a 
look at the properties:


xdmp:document-properties($uri)


where $uri is the URI of the document that did not get updated.

Those are some places to start.

-Danny

From: 
general-boun...@developer.marklogic.com
 
[mailto:general-boun...@developer.marklogic.com]
 On Behalf Of Raghu
Sent: Friday, September 16, 2011 5:58 AM
To: General MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] trigger not getting invoked in a clustered 
environment

Hi All,

  I'm having a migrator xquery which I need to invoke when a user does an 
operation and so I've used a trigger on the user's directory with infinity as 
depth. It is working fine in normal environment but it isn't invoking the 
migrator query in a clustered environment. Can somebody help me out?

PFB the trigger

import module namespace trgr="http://marklogic.com/xdmp/triggers";
at "/MarkLogic/triggers.xqy";
trgr:create-trigger("migrate folders", "migrate folders",
trgr:trigger-data-event(
trgr:directory-scope("/userdir/1234/", "infinity"),
trgr:document-content("modify"),
trgr:post-commit()),
trgr:trigger-module(xdmp:database("Modules"), "/userdir/modules/xquery/", 
"migrate-helper.xqy"),
fn:true(), xdmp:default-permissions())



Thanks in advance
Raghu

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] How to effectively pass variables by reference to an xquery function?

2011-09-17 Thread Tim Meagher
Hi Geert,

The MVC approach is ideal.  Yes, the app has evolved from a relative simple
web form to a more sophisticated state-machine driven application.  The
question is always, "At what point is the additional effort cost-effective
and necessary to enhance reusability and to reduce the time required for
maintaining the code and adding new features?"  For now I reckon what I have
is good enough, but I will keep your suggestion into mind.

~Tim

-Original Message-
From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Geert Josten
Sent: Saturday, September 17, 2011 12:53 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Tim,

I might have some other reasons to want to do things differently. Don't get
me wrong, I would have written similar code to get something working at
first. But once you start extending things, you will find this approach
limiting, and not of best design.

The most important concern is that it looks like you are mingling database
access, control flow, and presentation all in one piece of code. Moving
database knowledge into the working-value function could worsen this in
fact. I would really recommend taking an MVC kind of approach here. The
model (preferably a separate, reusable module) would also help with
shielding data access. It would hold any knowledge necessary to produce new
and database values. The main module could serve as controller in your case,
delegating between request information and model to get the model updated if
necessary. The view (another separate, reusable module) would take care of
putting values into an editable form, and showing it to the user.

The main logic could look something like this:

let $action := xdmp:get-request-field("action")

let $type := xdmp:get-request-field("type") let $id :=
xdmp:get-request-field("id")

let $changed-values:= map:map()
let $get-changed-values :=
for $n in xdmp:get-request-field-names()
where not($n = ('action', 'id', 'type'))
return map:put($changed-values, $n, xdmp:get-request-field($n))

let $is-saved :=
if ($action = "Save") then
m:update-model($type, $id, $changed-values)
else false()

let $show-values :=
if ($action = "Save") then
$changed-values
else if ($action = "New") then
m:get-new-values($type, $id)
else
m:get-db-values($type, $id)

return
v:show-form($type, $id, $is-saved, $show-values)

Kind regards,
Geert

-Oorspronkelijk bericht-
Van: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] Namens Tim Meagher
Verzonden: donderdag 15 september 2011 19:45
Aan: 'General MarkLogic Developer Discussion'
Onderwerp: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Geert,

I don't need to build the XML document if no changes occurred, unless I do
it exclusively to perform a deep equal.  Also, there are some updated status
values (save date, save name, etc) that would cause a deep-equal to fail.

That's very perceptive of you to notice that I don't need to perform a
database fetch if the action is New.  I haven't figured out how to pass in
the document nodepath to query the database within the function without a
nice juicy if-else action as a function of the request field name.  Any
suggestions?

Thanks!

Tim

-Original Message-
From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Geert Josten
Sent: Thursday, September 15, 2011 1:19 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Tim,

I think I understand why you put all that $action and if logic inside the
function, but I also think your problem could be less complex if you didn't.

Next to this, you are checking for changes for each value individually. But
how about building your XML first, and simply doing a deep-equal to compare
it with the database doc? If your form-values cover most of your XML, and
the XML isn't very big, that could work equally fast.

You don't need the db-values by the way if $action is 'New', so you could
save yourself the effort looking for them in that case. But only if you put
the if logic outside the function. ;-) (or the logic to retrieve them inside
the function..)

HTH!

Kind regards,
Geert

-Oorspronkelijk bericht-
Van: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] Namens Tim Meagher
Verzonden: donderdag 15 september 2011 17:33
Aan: 'General MarkLogic Developer Discussion'
Onderwerp: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Geert,

It makes sense, but I'd like to 

Re: [MarkLogic Dev General] trigger not getting invoked in a clustered environment

2011-09-17 Thread Raghu
HI Danny,

 Thanks. I've ensured that everything is in place. The same
trigger works fine in a single host but in a clustered environment it
isn't invoking the module. Is there any setting which might cause this kind
of behavior?

Thanks
Raghu

On Fri, Sep 16, 2011 at 9:48 PM, Danny Sokolsky <
danny.sokol...@marklogic.com> wrote:

> Hi Raghu,
>
> Is your trigger module (/userdir/modules/xquery/migrate-helper.xqy based on
> the trigger create code you showed) loaded into the database names
> "Modules".  To check that, run (in cq for example):
>
>
> fn:doc("/userdir/modules/xquery/migrate-helper.xqy ")
>
>
> against the Modules database.  It should return the text of the module.
>
>
> Assuming you are using CPF, in the document that is not being triggered,
> take a look at the properties:
>
>
> xdmp:document-properties($uri)
>
>
> where $uri is the URI of the document that did not get updated.
>
> Those are some places to start.
>
> -Danny
>
> From: general-boun...@developer.marklogic.com [mailto:
> general-boun...@developer.marklogic.com] On Behalf Of Raghu
> Sent: Friday, September 16, 2011 5:58 AM
> To: General MarkLogic Developer Discussion
> Subject: [MarkLogic Dev General] trigger not getting invoked in a clustered
> environment
>
> Hi All,
>
>   I'm having a migrator xquery which I need to invoke when a user does
> an operation and so I've used a trigger on the user's directory with
> infinity as depth. It is working fine in normal environment but it isn't
> invoking the migrator query in a clustered environment. Can somebody help me
> out?
>
> PFB the trigger
>
> import module namespace trgr="http://marklogic.com/xdmp/triggers";
> at "/MarkLogic/triggers.xqy";
> trgr:create-trigger("migrate folders", "migrate folders",
> trgr:trigger-data-event(
> trgr:directory-scope("/userdir/1234/", "infinity"),
> trgr:document-content("modify"),
> trgr:post-commit()),
> trgr:trigger-module(xdmp:database("Modules"), "/userdir/modules/xquery/",
> "migrate-helper.xqy"),
> fn:true(), xdmp:default-permissions())
>
>
>
> Thanks in advance
> Raghu
>
> ___
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
___
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


Re: [MarkLogic Dev General] How to effectively pass variables by reference to an xquery function?

2011-09-17 Thread Geert Josten
Hi Tim,

I might have some other reasons to want to do things differently. Don't get me 
wrong, I would have written similar code to get something working at first. But 
once you start extending things, you will find this approach limiting, and not 
of best design.

The most important concern is that it looks like you are mingling database 
access, control flow, and presentation all in one piece of code. Moving 
database knowledge into the working-value function could worsen this in fact. I 
would really recommend taking an MVC kind of approach here. The model 
(preferably a separate, reusable module) would also help with shielding data 
access. It would hold any knowledge necessary to produce new and database 
values. The main module could serve as controller in your case, delegating 
between request information and model to get the model updated if necessary. 
The view (another separate, reusable module) would take care of putting values 
into an editable form, and showing it to the user.

The main logic could look something like this:

let $action := xdmp:get-request-field("action")

let $type := xdmp:get-request-field("type")
let $id := xdmp:get-request-field("id")

let $changed-values:= map:map()
let $get-changed-values :=
for $n in xdmp:get-request-field-names()
where not($n = ('action', 'id', 'type'))
return map:put($changed-values, $n, xdmp:get-request-field($n))

let $is-saved :=
if ($action = "Save") then
m:update-model($type, $id, $changed-values)
else false()

let $show-values :=
if ($action = "Save") then
$changed-values
else if ($action = "New") then
m:get-new-values($type, $id)
else
m:get-db-values($type, $id)

return
v:show-form($type, $id, $is-saved, $show-values)

Kind regards,
Geert

-Oorspronkelijk bericht-
Van: general-boun...@developer.marklogic.com 
[mailto:general-boun...@developer.marklogic.com] Namens Tim Meagher
Verzonden: donderdag 15 september 2011 19:45
Aan: 'General MarkLogic Developer Discussion'
Onderwerp: Re: [MarkLogic Dev General] How to effectively pass variables by 
reference to an xquery function?

Hi Geert,

I don't need to build the XML document if no changes occurred, unless I do
it exclusively to perform a deep equal.  Also, there are some updated status
values (save date, save name, etc) that would cause a deep-equal to fail.

That's very perceptive of you to notice that I don't need to perform a
database fetch if the action is New.  I haven't figured out how to pass in
the document nodepath to query the database within the function without a
nice juicy if-else action as a function of the request field name.  Any
suggestions?

Thanks!

Tim

-Original Message-
From: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] On Behalf Of Geert Josten
Sent: Thursday, September 15, 2011 1:19 PM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Tim,

I think I understand why you put all that $action and if logic inside the
function, but I also think your problem could be less complex if you didn't.

Next to this, you are checking for changes for each value individually. But
how about building your XML first, and simply doing a deep-equal to compare
it with the database doc? If your form-values cover most of your XML, and
the XML isn't very big, that could work equally fast.

You don't need the db-values by the way if $action is 'New', so you could
save yourself the effort looking for them in that case. But only if you put
the if logic outside the function. ;-) (or the logic to retrieve them inside
the function..)

HTH!

Kind regards,
Geert

-Oorspronkelijk bericht-
Van: general-boun...@developer.marklogic.com
[mailto:general-boun...@developer.marklogic.com] Namens Tim Meagher
Verzonden: donderdag 15 september 2011 17:33
Aan: 'General MarkLogic Developer Discussion'
Onderwerp: Re: [MarkLogic Dev General] How to effectively pass variables by
reference to an xquery function?

Hi Geert,

It makes sense, but I'd like to call just one function that receives
multiple parameters:

- existing database value
- request field name
- action
- new value

When invoked, the function uses the action to determine what value should be
assigned to a local variable and sets a status if the values differ.  So
rewriting my example we have:

xquery version "1.0-ml";

declare namespace t = "test";
declare variable $t:changed := false();

declare function t:working-value($action, $db-value, $request-field,
$new-value)
{
let $form-value := 
if ($action eq ("Get", "Save")) then
xdmp:get-request-field($request-field) else ()
return
if ($action eq "New") then $new-value
else if ($action eq "Retrieve") then (
$db-value,
if (not($t:changed) and $db-value n