Permalink
Browse files

Initial import.

  • Loading branch information...
1 parent b1f626c commit 48920e40b5a8d0fc68bbc3264db7aff11491ebcf Florent Georges committed Oct 9, 2012
View
@@ -0,0 +1,37 @@
+xquery version "1.0";
+
+import module namespace cfg = "http://expath.org/ns/ml/console/config" at "lib/config.xql";
+import module namespace v = "http://expath.org/ns/ml/console/view" at "lib/view.xql";
+
+declare default element namespace "http://www.w3.org/1999/xhtml";
+
+v:console-page(
+ 'cxan',
+ 'CXAN',
+ (<p>Install packages and applications directly from CXAN into a specific
+ repository, using a package name or a CXAN ID (one or the other), and
+ optionally a version number (retrieve the latest version by default).</p>,
+ if ( cfg:is-setup() ) then
+ <form method="post" action="do-cxan.xq" enctype="multipart/form-data">
+ <span>Target repo:</span>
+ <select name="repo"> {
+ for $r in cfg:get-repos()
+ return
+ <option>{ $r/string(@name) }</option>
+ }
+ </select>
+ <br/>
+ <span>CXAN ID:</span>
+ <input type="text" name="id" size="25"/>
+ <br/>
+ <span>Name:</span>
+ <input type="text" name="name" size="50"/>
+ <br/>
+ <span>Version:</span>
+ <input type="text" name="version" size="25"/>
+ <br/>
+ <input type="submit" value="Install"/>
+ </form>
+ else
+ <p>The console has not been set up yet, please
+ <a href="setup.xq">create a repo</a> first.</p>))
View
@@ -0,0 +1,116 @@
+xquery version "1.0-ml";
+(: TODO: Version "1.0-ml" needed because of the try/catch for WebDAV app servers. To remove... :)
+
+import module namespace a = "http://expath.org/ns/ml/console/admin" at "lib/admin.xql";
+import module namespace cfg = "http://expath.org/ns/ml/console/config" at "lib/config.xql";
+import module namespace r = "http://expath.org/ns/ml/console/repo" at "lib/repo.xql";
+import module namespace v = "http://expath.org/ns/ml/console/view" at "lib/view.xql";
+
+import module namespace admin = "http://marklogic.com/xdmp/admin"
+ at "/MarkLogic/admin.xqy";
+
+declare default element namespace "http://www.w3.org/1999/xhtml";
+
+declare namespace c = "http://expath.org/ns/ml/console";
+declare namespace xdmp = "http://marklogic.com/xdmp";
+
+v:console-page(
+ 'devel',
+ 'Developement tools',
+ <wrapper>
+ <p>Some useful queries used in the implementation of the console.</p>
+ <p>You can use this page to show some useful information about your
+ MarkLogic instance. You can also inspect the code source of this page
+ to see how to retrieve the same information from within XQuery.</p>
+ <h4>Browsing a pkg dir</h4>
+ <ul> {
+ let $repo := cfg:get-repo('db-repo')
+ let $db-id := $repo/c:database/@id
+ let $root := $repo/c:root
+ let $docs :=
+ a:eval-on-database(
+ $db-id,
+ 'declare variable $path external;
+ xdmp:directory($path, "infinity")',
+ (fn:QName('', 'path'), $root))
+ (: fn:QName('', 'path'), fn:concat($root, '.expath-pkg/')) :)
+ for $d in $docs
+ return
+ <li>{ fn:document-uri($d) }</li>
+ }
+ </ul>
+ <h4>Some infos</h4>
+ <ul>
+ <li>Module database: { xdmp:databases()[xdmp:database-name(.) eq 'Modules'] }</li>
+ <li>Module root: { xdmp:modules-root() }</li>
+ <li>"Modules" DB data dir: {
+ let $config := admin:get-configuration()
+ return
+ admin:forest-get-data-directory(
+ $config,
+ admin:forest-get-id($config, "Modules"))
+ }
+ </li>
+ <li>"expath-pkg" AS module DB: {
+ let $config := admin:get-configuration()
+ let $groupid := admin:group-get-id($config, "Default")
+ return
+ admin:appserver-get-modules-database(
+ $config,
+ admin:appserver-get-id($config, $groupid, "expath-pkg"))
+ }
+ </li>
+ <li>"expath-pkg" AS root: {
+ let $config := admin:get-configuration()
+ let $groupid := admin:group-get-id($config, "Default")
+ return
+ admin:appserver-get-root(
+ $config,
+ admin:appserver-get-id($config, $groupid, "expath-pkg"))
+ }
+ </li>
+ </ul>
+ <h4>App servers</h4>
+ <ul> {
+ let $config := admin:get-configuration()
+ for $as in admin:get-appserver-ids($config)
+ return
+ <li> {
+ 'Name: ', admin:appserver-get-name($config, $as),
+ ' / ID: ', $as,
+ ' / Modules DB: ',
+ try {
+ admin:appserver-get-modules-database($config, $as)
+ }
+ catch ( $err ) {
+ (: WebDAV ASs do not have a module DB:)
+ (: TODO: How to retrieve the type of a server programmatically? :)
+ 'N/A'
+ },
+ ' / Root: ', admin:appserver-get-root($config, $as)
+ }
+ </li>
+ }
+ </ul>
+ <h4>Forests</h4>
+ <ul> {
+ for $f in xdmp:forests()
+ return
+ <li> {
+ fn:concat(xdmp:forest-name($f), ' (', xdmp:database-name(xdmp:forest-databases($f)), ')')
+ (:fn:concat(xdmp:forest-name($f), ' (', xdmp:host-name(xdmp:forest-host($f)), ' / ', xdmp:database-name(xdmp:forest-databases($f)), ')'):)
+ }
+ </li>
+ }
+ </ul>
+ <h4>Databases</h4>
+ <ul> {
+ for $db in xdmp:databases()
+ return
+ <li> {
+ xdmp:database-name($db)
+ }
+ </li>
+ }
+ </ul>
+ </wrapper>/*)
View
@@ -0,0 +1,73 @@
+xquery version "1.0";
+
+import module namespace cfg = "http://expath.org/ns/ml/console/config" at "lib/config.xql";
+import module namespace r = "http://expath.org/ns/ml/console/repo" at "lib/repo.xql";
+import module namespace t = "http://expath.org/ns/ml/console/tools" at "lib/tools.xql";
+import module namespace v = "http://expath.org/ns/ml/console/view" at "lib/view.xql";
+
+declare default element namespace "http://www.w3.org/1999/xhtml";
+
+declare namespace c = "http://expath.org/ns/ml/console";
+declare namespace http = "xdmp:http";
+declare namespace xdmp = "http://marklogic.com/xdmp";
+declare namespace zip = "xdmp:zip";
+
+declare function local:install(
+ $repo as element(c:repo),
+ $uri as xs:string
+) as element()+
+{
+ let $result := xdmp:http-get($uri)
+ let $response := $result[1]
+ let $xar := $result[2]
+ let $code := $response/xs:integer(http:code)
+ return
+ if ( $code eq 404 ) then
+ <p><b>Error</b>: There is no package at { $uri }..</p>
+ else if ( $code eq 200 ) then
+ if ( r:install($xar, $repo) ) then
+ <p>Package succesfully installed from { $uri } into { $repo/fn:string(@name) }.</p>
+ else
+ <p><b>Error</b>: Unknown error installing the package from { $uri }.
+ Does it already exist?</p>
+ else (
+ <p><b>Error</b>: CXAN server did not respond 200 Ok for the package
+ (at '{ $uri }'):</p>,
+ <pre>{ xdmp:quote($response) }</pre>
+ )
+};
+
+declare function local:do-it(
+ $repo as element(c:repo),
+ $id as xs:string?,
+ $name as xs:string?,
+ $version as xs:string?,
+ $site as xs:string?
+) as element()+
+{
+ if ( fn:exists($id) and fn:exists($name) ) then
+ <p><b>Error</b>: Both CXAN ID and package name provided: resp. '{ $id }'
+ and '{ $name }'.</p>
+ else if ( fn:empty($site) ) then
+ <p><b>Error</b>: The console seems to have not been set up yet, please
+ <a href="setup.xq">create a repo</a> first.</p>
+ else if ( fn:exists($id) ) then
+ local:install($repo, fn:concat($site, 'file?id=', $id, '&amp;version=', $version))
+ else if ( fn:exists($name) ) then
+ local:install($repo, fn:concat($site, 'file?name=', $name, '&amp;version=', $version))
+ else
+ <p><b>Error</b>: No CXAN ID nor package name provided.</p>
+};
+
+(: TODO: Check the params are there, and validate them... :)
+let $reponame := t:mandatory-field('repo')
+let $repo := cfg:get-repo($reponame)
+let $id := t:optional-field('id', ())
+let $name := t:optional-field('name', ())
+let $version := t:optional-field('version', ())
+let $site := cfg:get-config()/c:cxan/c:site
+return
+ v:console-page(
+ 'cxan',
+ 'CXAN',
+ local:do-it($repo, $id, $name, $version, $site))
View
@@ -0,0 +1,37 @@
+xquery version "1.0";
+
+import module namespace cfg = "http://expath.org/ns/ml/console/config" at "lib/config.xql";
+import module namespace r = "http://expath.org/ns/ml/console/repo" at "lib/repo.xql";
+import module namespace t = "http://expath.org/ns/ml/console/tools" at "lib/tools.xql";
+import module namespace v = "http://expath.org/ns/ml/console/view" at "lib/view.xql";
+
+declare default element namespace "http://www.w3.org/1999/xhtml";
+
+declare namespace pp = "http://expath.org/ns/repo/packages";
+
+(:
+ TODO: If on the filesystem, warn the user to delete the directory himself...!
+:)
+
+let $name := t:mandatory-field('repo')
+let $repo := cfg:get-repo($name)
+let $pkgdir := t:mandatory-field('pkg')
+let $pkg := r:get-package-by-pkgdir($pkgdir, $repo)
+return
+ v:console-page(
+ 'repo',
+ fn:concat('Repository ''', $name, ''''),
+ if ( empty($pkg) ) then (
+ <p>Package does not exist in { $pkgdir }.</p>
+ )
+ else (
+ r:delete-package($pkg, $repo)[fn:false()],
+ <p>Package { $pkg/fn:string(@name) }, version { $pkg/fn:string(@version) },
+ succesfully uninstalled from { $pkgdir }.</p>
+ ))
+(:
+ else if ( r:delete-package($pkg, $repo) ) then
+ <p>Package { $pkg/@name } / { $pkg/@version } succesfully uninstalled from { $pkgdir }.</p>
+ else
+ <p>Error while deleting package { $pkg/@name } / { $pkg/@version } from { $pkgdir }.</p>)
+:)
Oops, something went wrong.

0 comments on commit 48920e4

Please sign in to comment.