如何在不符合规范的eXist实例上中止和清理应用程序安装?

时间:2017-07-16 09:42:58

标签: xquery exist-db

问题在于:

我有一个实体应用程序无法在具有默认最小内存配置的现有实例上运行。尽管如此,在安装说明中突出显示。用户不断尝试安装并因此导致其实例崩溃。为了避免让应用程序的用户感到沮丧,并试图在“RTM!”之外保持一种阳光灿烂的态度。

解决方案(目前为止)

如果cacheSize或内存低于最低要求,我修改了pre-install.xql,以便中止。

xquery version "3.0";

import module namespace xdb = "http://exist-db.org/xquery/xmldb";
import module namespace file = "http://exist-db.org/xquery/file" at "java:org.exist.xquery.modules.file.FileModule";

(: The following external variables are set by the repo:deploy function :)

(: file path pointing to the exist installation directory :)
declare variable $home external;
(: path to the directory containing the unpacked .xar package :)
declare variable $dir external;
(: the target collection into which the app is deployed :)
declare variable $target external;

(: the path to the exist-db installation :)
declare variable $exist_home as xs:string := system:get-exist-home();
(:check available memory:)
declare variable $mem-max := system:get-memory-max();
(: minimum memory requirements :)
declare variable $mem-req := 2000000000;
(: minimum cache Size:)
declare variable $cache-req := 500;

declare function local:mkcol-recursive($collection, $components) {
    if (exists($components)) then
        let $newColl := concat($collection, "/", $components[1])
        return
            (
            xdb:create-collection($collection, $components[1]),
            local:mkcol-recursive($newColl, subsequence($components, 2))
            )
    else
        ()
};

(: Helper function to recursively create a collection hierarchy. :)
declare function local:mkcol($collection, $path) {
    local:mkcol-recursive($collection, tokenize($path, "/"))
};

(: Helper function to check the instance's chacheSize. :)
declare function local:check-cache-size($path as xs:string) as xs:boolean {
    if (file:is-readable($path || "/conf.xml"))
    then
        (
        let $doc := fn:parse-xml(file:read($path || "/conf.xml"))
        return
            if (number(substring-before($doc//exist/db-connection/@cacheSize/string(), "M")) > $cache-req)
            then
                (fn:true())
            else
                (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:cache-low'), 'Your configured cacheSize is too low')))
    else
        (fn:true())
};

(: Helper function to check the instance's memory. :)
declare function local:check-mem-size($memory as xs:integer) as xs:boolean {
    if ($memory > $mem-req)
    then
        (fn:true())
    else
        (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:memory-low'), 'Your configured -xmx memory is too low'))
};

if (local:check-mem-size($mem-max) and local:check-cache-size($exist_home))
then
    (
    (: store the collection configuration :)
    local:mkcol("/db/system/config", $target),
    xdb:store-files-from-pattern(concat("/db/system/config", $target), $dir, "*.xconf"))
else
    (fn:error(fn:QName('https://github.com/duncdrum/cbdb-data', 'err:pre-crash'), 'An unknown error occured during pre-install'))

好的

应用程序在预期时在包管理器内产生可见错误,用户不再需要等待20分钟才能看到一般错误和崩溃的实例。

meh

应用程序仍然完全注册到包管理器,在部分安装后可以将其卸载。它也出现在仪表板上,虽然它已中止但它不起作用。应用程序内容部分写入db/apps/myapp

问题

是否有更好的方法可以中止(和撤消)安装?前提是必须通过仪表板的包管理器进行安装。我喜欢用户现在看到自定义错误告诉他们什么是错误的,如果这些错误发送到console:log?必须在安装后的.xql中清除安装失败的安装,还是我可以在pre-install.xql中做得更好?这个pre-install.xql中的任何其他明显的疏忽。

测试

您只需通过eXide创建一个空的存在应用程序,并将默认的pre-install.xql替换为上面的那个。将$mem-req更改为成功或错误输出您的实例。下载应用程序并尝试安装。

编辑1

根据docs“[pre-install.xql]将在任何包数据上传到数据库之前执行。”这不是我所看到的。数据已上传,这就是目前需要清理的原因。所以这实际上可能是一个错误。

编辑2

我尝试了util:logfn:trace的不同组合,然后允许我调用repo-undeploy(), repo-remove()进行清理。但我需要fn:error实际中止以防止崩溃,并向包管理器报告。所以功能请求似乎是TWTG。有没有办法将消息记录到包管理器中出现错误消息而不使用fn:error

0 个答案:

没有答案
相关问题