来自任务服务器的查询 运行 找不到文件?
query run from task server cannot find documents?
我定义了一个 XQuery,我可以从查询控制台 (QC) 运行。
我在任务服务器上设置了任务。
查询好像找不到要搜索的文件,所以我猜这一定是权限问题。
任务查询:
xquery version "1.0-ml";
import module namespace object = "http://marklogic.com/solutions/obi/object" at
"/ext/obi/lib/object-query-lib.xqy",
"/ext/obi/lib/object-service-lib.xqy",
"/ext/obi/lib/object-lib.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
declare namespace alt="http://example.com/sccs/alert";
declare namespace scc="http://example.com/sccs";
declare namespace source="http://marklogic.com/solutions/obi/source";
(: Start task :)
let $_ := xdmp:log("******* START CHECK UPDATE ALERTS TASK *********")
(: Find al active alerts :)
let $alerts := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert"),
cts:element-range-query(xs:QName("alt:status"), "=", "Active")
(:
cts:element-range-query(xs:QName("alt:device-id"), "=", $device-id)
:)
))
)/obj:object
let $update-object-content := <alert xmlns="http://example.com/sccs/alert">
<obj:property>
<status xmlns="http://example.com/sccs/alert">Inactive</status>
</obj:property>
</alert>
let $now := fn:current-dateTime()
(: minimum duration before alerts turns inactive :)
let $duration-min := xs:dayTimeDuration('PT25M0S') (: defines 30 minutes :)
(: loop over all active alerts :)
let $_ :=
for $a in $alerts
let $a-id := $a//obj:id/text()
let $s-id := $a//source:id/text()[1]
let $timestamp := xdmp:parse-dateTime('[Y0001]-[M01]-[D01]T[h01]:[m01]:[s01]',$a//scc:timestamp/text())
(: if Alert is older then $delta then set status to Inactive :)
let $delta := $now - $timestamp
let $upd := if ($delta > $duration-min) then
(
let $_ := xdmp:log(fn:concat("Update Alert ID : ",$a-id," to INACTIVE."))
let $detail-id := obj:add-details($a-id, $update-object-content, $s-id,())
return $detail-id
)
else ()
return $upd
let $_ := xdmp:log(fn:concat("DEBUG NUM ALERTS:",fn:count($alerts)))
return ()
任务定义:
<scheduled-task>
<task-path>/tasks/update-alerts-to-inactive.xqy</task-path>
<task-root>/</task-root>
<task-type>minutely</task-type>
<task-period>5</task-period>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
任务每 5 分钟检查一次警报对象是否需要设置为 "Inactive"。
从日志中 Error.txt 我可以看到任务 运行 但找不到文档。
2015-10-26 00:45:00.395 Info: TaskServer: ******* START CHECK UPDATE ALERTS TASK *********
2015-10-26 00:45:00.395 Info: TaskServer: DEBUG NUM ALERTS:0
我运行代码点根排序规则中的所有代码,但在此上下文中找不到任何关于任务服务器的内容。
documentation on permissions needed for the user to perform a task非常神秘:
In the Task User and Task Host fields, specify the user with
permission to invoke the task and the host computer on which the task
is to be invoked. If no host is specified, then the task runs on all
hosts. The user specified in the Task User field must have the
privileges required to execute the functions used in the module. See
Appendix B: Pre-defined Execute Privileges for the full list of
execute privileges.
问题:为什么应用程序用户在任务服务器上找不到文件?
更新
尝试获取 OBI 文档的权限但失败。
这是代码(根据 Dave 的建议)
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
let $o-id := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert")
))
)/obj:object/obj:id/text()
let $uri := object:master-uri($o-id)
let $res := for $perm in xdmp:document-get-permissions($uri)
let $role-name := sec:get-role-names($perm/sec:role-id)
return $role-name || ": " || $perm/sec:capability/fn:string()
let $string-uri := '/marklogic.solutions.obi/object/cec48c59-a648-4da5-a758-2b6bb4065279.xml'
return xdmp:document-get-permissions($string-uri)
我运行在 QC 上以管理员身份使用它,它 returns 空序列...
检查权限部分的最简单方法是 运行 您在查询控制台中的代码 ${app-name}-user}
。以该用户身份连接到查询控制台,或将代码包装在 xdmp:eval() 中并在选项中指定用户。我希望你会得到相同的结果。
这似乎不是执行权限的问题,因为任务确实如此 运行。
在查询控制台中,运行此代码:
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
for $perm in xdmp:document-get-permissions($uri)
let $role-name := sec:get-role-names($perm/sec:role-id)
return $role-name || ": " || $perm/sec:capability/fn:string()
...用您的目标文档之一的 URI 替换 $uri。这将告诉您哪些角色对该文档具有哪些权限。现在您可以检查 ${app-name}-user
是否具有(或继承)该角色。
我定义了一个 XQuery,我可以从查询控制台 (QC) 运行。 我在任务服务器上设置了任务。
查询好像找不到要搜索的文件,所以我猜这一定是权限问题。
任务查询:
xquery version "1.0-ml";
import module namespace object = "http://marklogic.com/solutions/obi/object" at
"/ext/obi/lib/object-query-lib.xqy",
"/ext/obi/lib/object-service-lib.xqy",
"/ext/obi/lib/object-lib.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
declare namespace alt="http://example.com/sccs/alert";
declare namespace scc="http://example.com/sccs";
declare namespace source="http://marklogic.com/solutions/obi/source";
(: Start task :)
let $_ := xdmp:log("******* START CHECK UPDATE ALERTS TASK *********")
(: Find al active alerts :)
let $alerts := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert"),
cts:element-range-query(xs:QName("alt:status"), "=", "Active")
(:
cts:element-range-query(xs:QName("alt:device-id"), "=", $device-id)
:)
))
)/obj:object
let $update-object-content := <alert xmlns="http://example.com/sccs/alert">
<obj:property>
<status xmlns="http://example.com/sccs/alert">Inactive</status>
</obj:property>
</alert>
let $now := fn:current-dateTime()
(: minimum duration before alerts turns inactive :)
let $duration-min := xs:dayTimeDuration('PT25M0S') (: defines 30 minutes :)
(: loop over all active alerts :)
let $_ :=
for $a in $alerts
let $a-id := $a//obj:id/text()
let $s-id := $a//source:id/text()[1]
let $timestamp := xdmp:parse-dateTime('[Y0001]-[M01]-[D01]T[h01]:[m01]:[s01]',$a//scc:timestamp/text())
(: if Alert is older then $delta then set status to Inactive :)
let $delta := $now - $timestamp
let $upd := if ($delta > $duration-min) then
(
let $_ := xdmp:log(fn:concat("Update Alert ID : ",$a-id," to INACTIVE."))
let $detail-id := obj:add-details($a-id, $update-object-content, $s-id,())
return $detail-id
)
else ()
return $upd
let $_ := xdmp:log(fn:concat("DEBUG NUM ALERTS:",fn:count($alerts)))
return ()
任务定义:
<scheduled-task>
<task-path>/tasks/update-alerts-to-inactive.xqy</task-path>
<task-root>/</task-root>
<task-type>minutely</task-type>
<task-period>5</task-period>
<task-database name="${content-db}"/>
<task-modules name="${app-modules-db}"/>
<task-user name="${app-name}-user"/>
</scheduled-task>
任务每 5 分钟检查一次警报对象是否需要设置为 "Inactive"。
从日志中 Error.txt 我可以看到任务 运行 但找不到文档。
2015-10-26 00:45:00.395 Info: TaskServer: ******* START CHECK UPDATE ALERTS TASK *********
2015-10-26 00:45:00.395 Info: TaskServer: DEBUG NUM ALERTS:0
我运行代码点根排序规则中的所有代码,但在此上下文中找不到任何关于任务服务器的内容。
documentation on permissions needed for the user to perform a task非常神秘:
In the Task User and Task Host fields, specify the user with permission to invoke the task and the host computer on which the task is to be invoked. If no host is specified, then the task runs on all hosts. The user specified in the Task User field must have the privileges required to execute the functions used in the module. See Appendix B: Pre-defined Execute Privileges for the full list of execute privileges.
问题:为什么应用程序用户在任务服务器上找不到文件?
更新
尝试获取 OBI 文档的权限但失败。
这是代码(根据 Dave 的建议)
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
declare namespace obj="http://marklogic.com/solutions/obi/object";
let $o-id := cts:search(
collection("object"),
cts:and-query((
cts:element-range-query(xs:QName("obj:type"), "=", "alert")
))
)/obj:object/obj:id/text()
let $uri := object:master-uri($o-id)
let $res := for $perm in xdmp:document-get-permissions($uri)
let $role-name := sec:get-role-names($perm/sec:role-id)
return $role-name || ": " || $perm/sec:capability/fn:string()
let $string-uri := '/marklogic.solutions.obi/object/cec48c59-a648-4da5-a758-2b6bb4065279.xml'
return xdmp:document-get-permissions($string-uri)
我运行在 QC 上以管理员身份使用它,它 returns 空序列...
检查权限部分的最简单方法是 运行 您在查询控制台中的代码 ${app-name}-user}
。以该用户身份连接到查询控制台,或将代码包装在 xdmp:eval() 中并在选项中指定用户。我希望你会得到相同的结果。
这似乎不是执行权限的问题,因为任务确实如此 运行。
在查询控制台中,运行此代码:
import module namespace sec="http://marklogic.com/xdmp/security" at
"/MarkLogic/security.xqy";
for $perm in xdmp:document-get-permissions($uri)
let $role-name := sec:get-role-names($perm/sec:role-id)
return $role-name || ": " || $perm/sec:capability/fn:string()
...用您的目标文档之一的 URI 替换 $uri。这将告诉您哪些角色对该文档具有哪些权限。现在您可以检查 ${app-name}-user
是否具有(或继承)该角色。