Skip to content

Commit

Permalink
first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
dscape committed May 18, 2010
1 parent feb0a3e commit b963502
Show file tree
Hide file tree
Showing 22 changed files with 4,892 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib-installer/attach-forest.xqy
@@ -0,0 +1,16 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

let $config := admin:database-attach-forest(
admin:get-configuration(), xdmp:database($ai:name), xdmp:forest($ai:name))
return ( admin:save-configuration($config),
<div class="message">
A Database and Forest called {$ai:name} attached together successfully
</div> )
17 changes: 17 additions & 0 deletions lib-installer/create-database.xqy
@@ -0,0 +1,17 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

let $config := admin:database-create(admin:get-configuration(), $ai:name, xdmp:database("Security"), xdmp:database("Schemas"))
return
(
admin:save-configuration($config)
,
<div class="message">A Database called {$ai:name} created successfully</div>
)
17 changes: 17 additions & 0 deletions lib-installer/create-forest.xqy
@@ -0,0 +1,17 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

let $config := admin:forest-create(admin:get-configuration(), $ai:name, xdmp:host(), ())
return
(
admin:save-configuration($config)
,
<div class="message">A Forest called {$ai:name} created successfully</div>
)
24 changes: 24 additions & 0 deletions lib-installer/create-http-server.xqy
@@ -0,0 +1,24 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;
declare variable $ai:port as xs:string external;
declare variable $ai:nodb as xs:boolean external;

(: Apps/usr :)
let $config := admin:get-configuration()
let $db := if ($ai:nodb) then "Documents" else $ai:name
let $groupid := admin:group-get-id($config, "Default")
let $new-config := admin:http-server-create($config, $groupid, $ai:name,
fn:concat("Apps/usr/",$ai:name), xs:unsignedLong($ai:port), 0, xdmp:database($db) )
return
(
admin:save-configuration($new-config)
,
<div class="message">An HTTP Server called {$ai:name} with root {$ai:name} on port {$ai:port} created successfully</div>
)
45 changes: 45 additions & 0 deletions lib-installer/default.xqy
@@ -0,0 +1,45 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)
xquery version "1.0-ml";

let $doctype := '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
let $html :=
<html>
<head>
<title>API Application Setup</title>
<script language="javascript" src="js/prototype.js" type="text/javascript">{" "}</script>
<script type="text/javascript" language="javascript">
//<![CDATA[
function install() {
var name = document.getElementById('name').value;
var port = document.getElementById('port').value;
var url = '/api-installer/api-setup-run.xqy?app=' + name + ':' + port;
new Ajax.Updater('results', '/api-installer/get-spinner.xqy', {asynchronous:true});
new Ajax.Updater('results', url, {asynchronous:true});
}
//]]>
</script>
</head>
<body>
<div style="font-weight:bold; font-size: 120%; text-align:center; padding: 20px;">API Search Install and Setup</div>
<div>
<span>Name: </span>
<input type="textbox" id="name" />
<span>Port: </span>
<input type="textbox" id="port" />
<input type="submit" value="Install" onClick="install()"/>
<div id="results" style="padding: 20px; border: 1px solid #DDD; width: 500px; font-style: italic; margin-top: 20px;">{"<Current Progress>"}</div>
</div>
</body>
</html>

return
(
xdmp:set-response-content-type("text/html; charset=utf-8"),
$doctype,
$html
)

20 changes: 20 additions & 0 deletions lib-installer/delete-database.xqy
@@ -0,0 +1,20 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

try {
let $config := admin:get-configuration()
let $config := admin:database-delete($config, xdmp:database($ai:name))
return admin:save-configuration($config)
} catch ($e) {
<div class="error-delete-database">
<h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}
20 changes: 20 additions & 0 deletions lib-installer/delete-forest.xqy
@@ -0,0 +1,20 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

try {
let $config := admin:get-configuration()
let $config := admin:forest-delete($config, admin:forest-get-id($config, $ai:name), fn:true())
return admin:save-configuration($config)
} catch ($e) {
<div class="error-delete-forest">
<h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}
25 changes: 25 additions & 0 deletions lib-installer/delete-http-server.xqy
@@ -0,0 +1,25 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

try {
let $config := admin:get-configuration()
let $groupid := admin:group-get-id($config, "Default")
let $config := admin:appserver-delete($config, admin:appserver-get-id($config, $groupid, $ai:name) )
return
(
admin:save-configuration($config),
xdmp:sleep(15000)
)
} catch ($e) {
<div class="error-delete-http-server">
<h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}
20 changes: 20 additions & 0 deletions lib-installer/detach-forest.xqy
@@ -0,0 +1,20 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

declare namespace ai="api-install";
declare variable $ai:name as xs:string external;

try {
let $config := admin:get-configuration()
let $config := admin:database-detach-forest($config, xdmp:database($ai:name), xdmp:forest($ai:name) )
return admin:save-configuration($config)
} catch ($e) {
<div class="error-detach-forest">
<h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}
8 changes: 8 additions & 0 deletions lib-installer/get-spinner.xqy
@@ -0,0 +1,8 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)
xquery version "1.0-ml";

declare namespace htm="http://www.w3.org/1999/xhtml";

<img src="/api-installer/images/spinner.gif"/>
10 changes: 10 additions & 0 deletions lib-installer/hooks/install/incommit.xqy
@@ -0,0 +1,10 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

(: dont remove (or change) this file
: this is the default trigger, user can pass another that will
: override this
:)
xquery version "1.0-ml";
()
10 changes: 10 additions & 0 deletions lib-installer/hooks/install/precommit.xqy
@@ -0,0 +1,10 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

(: dont remove (or change) this file
: this is the default trigger, user can pass another that will
: override this
:)
xquery version "1.0-ml";
()
11 changes: 11 additions & 0 deletions lib-installer/hooks/uninstall/incommit.xqy
@@ -0,0 +1,11 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

(: dont remove (or change) this file
: this is the default trigger, user can pass another that will
: override this
:)

xquery version "1.0-ml";
()
11 changes: 11 additions & 0 deletions lib-installer/hooks/uninstall/precommit.xqy
@@ -0,0 +1,11 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

(: dont remove (or change) this file
: this is the default trigger, user can pass another that will
: override this
:)

xquery version "1.0-ml";
()
Binary file added lib-installer/images/spinner.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions lib-installer/install.xqy
@@ -0,0 +1,33 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)
xquery version "1.0-ml";
declare namespace ai="api-install";

try {
let $app := xdmp:get-request-field("app")
let $name := fn:substring-before($app, ":")
let $port := fn:substring-after($app, ":")
let $noappserver := xdmp:get-request-field("noappserver")
let $nodb := xdmp:get-request-field("nodb")
let $_ :=
xdmp:log(fn:concat("Installing ", $name, " on port ", $port,
". NoAppServer set to ", $noappserver, ". NoDB set to ", $nodb, "."))
let $args-name := (xs:QName("ai:name"), $name)
let $args-port := ($args-name, xs:QName("ai:port"), $port)
let $args-nodb := ($args-port, xs:QName("ai:nodb"), fn:boolean($nodb))
return (
xdmp:invoke("hooks/install/precommit.xqy", $args-port),
if ($nodb) then () else xdmp:invoke("create-forest.xqy", $args-name),
if ($nodb) then () else xdmp:invoke("create-database.xqy", $args-name),
if ($nodb) then () else xdmp:invoke("attach-forest.xqy", $args-name),
if ($noappserver) then () else xdmp:invoke("create-http-server.xqy", $args-nodb),
xdmp:invoke("hooks/install/incommit.xqy", $args-port),
<div> Click
<a href="{fn:concat('http://localhost:', $port)}">here</a> to continue...
</div> )
} catch ($e) {
<div> <h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}
27 changes: 27 additions & 0 deletions lib-installer/install.xqy~
@@ -0,0 +1,27 @@
(:
: Copyright 2010 Mark Logic Corporation. All Rights Reserved.
:)

xquery version "1.0-ml";
declare namespace ai="api-install";

try {
let $app := xdmp:get-request-field("app")
let $name := fn:substring-before($app, ":")
let $port := fn:substring-after($app, ":")
let $noappserver := xdmp:get-request-field("noappserver")
return (
xdmp:invoke("hooks/install/precommit.xqy", (xs:QName("ai:name"), $name, xs:QName("ai:port"), $port)),
xdmp:invoke("create-forest.xqy", (xs:QName("ai:name"), $name)),
xdmp:invoke("create-database.xqy", (xs:QName("ai:name"), $name)),
xdmp:invoke("attach-forest.xqy", (xs:QName("ai:name"), $name)),
if ($noappserver) then () else xdmp:invoke("create-http-server.xqy", (xs:QName("ai:name"), $name, xs:QName("ai:port"), $port)),
xdmp:invoke("hooks/install/incommit.xqy", (xs:QName("ai:name"), $name, xs:QName("ai:port"), $port)),
<div> Click
<a href="{fn:concat('http://localhost:', $port)}">here</a> to continue...
</div> )
} catch ($e) {
<div> <h3>Error</h3>
<div class="error-stack-trace"> { $e } </div>
</div>
}

0 comments on commit b963502

Please sign in to comment.