Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
further fixes to Issue #36
Browse files Browse the repository at this point in the history
  • Loading branch information
paxtonhare committed Oct 26, 2012
1 parent 17fd910 commit 327f937
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 54 deletions.
20 changes: 16 additions & 4 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,15 @@ def bootstrap
if (r.body.match("<error:error")) then
logger.error r.body
logger.error "... Bootstrap FAILED"
return false
else
if (r.body.match("(note: restart required)")) then
logger.warn("************************************")
logger.warn("*** RESTART OF MARKLOGIC IS REQUIRED")
logger.warn("************************************")
end
logger.info("... Bootstrap Complete")
return true
end
else
raise ExitException.new("Bootstrap requires the target environment's hostname to be defined")
Expand All @@ -342,13 +344,15 @@ def wipe
if (r.body.match("<error:error")) then
logger.error r.body
logger.error "... Wipe FAILED"
return false
else
if (r.body.match("(note: restart required)")) then
logger.warn("************************************")
logger.warn("*** RESTART OF MARKLOGIC IS REQUIRED")
logger.warn("************************************")
end
logger.info("... Wipe Complete")
return true
end
end

Expand All @@ -357,10 +361,18 @@ def validate_install
setup = open(File.expand_path('../xquery/setup.xqy', __FILE__)).readlines.join
begin
r = execute_query %Q{#{setup} setup:validate-install(#{get_config})}
logger.info(r.body)
logger.info("... Validation SUCCESS")
result = true
rescue ExitException
logger.info "code: #{r.code.to_i}"
logger.info r.body

if (r.body.match("<error:error")) then
logger.error r.body
result = false
else
logger.info("... Validation SUCCESS")
result = true
end
rescue Net::HTTPFatalError => e
logger.error e.response.body
logger.error "... Validation FAILED"
result = false
end
Expand Down
113 changes: 83 additions & 30 deletions deploy/lib/xquery/setup.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -886,60 +886,62 @@ declare function setup:configure-databases($import-config as element(configurati
for $db-config in setup:get-databases-from-config($import-config)
let $database-name := setup:get-database-name-from-database-config($db-config)
let $database := xdmp:database($database-name)

let $remove-existing-range-path-indexes :=
let $admin-config := admin:get-configuration()
let $admin-config := (: remove-existing-range-path-indexes := :)
(: wrap in try catch because this function is new to 6.0 and will fail in older version of ML :)
try
{
if (xdmp:eval('
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $database external;
let $admin-config := admin:get-configuration()
declare variable $admin-config external;
let $remove-existing-indexes :=
for $index in admin:database-get-range-path-indexes($admin-config, $database)
return
xdmp:set(
$admin-config,
admin:database-delete-range-path-index($admin-config, $database, $index))
return
admin:save-configuration-without-restart($admin-config)',
(xs:QName("database"), $database))) then
xdmp:set($restart-needed, fn:true())
else ()
$admin-config
(: admin:save-configuration-without-restart($admin-config) :)',
(xs:QName("database"), $database,
xs:QName("admin-config"), $admin-config))
}
catch($ex)
{
if ($ex/error:code = "XDMP-UNDFUN") then ()
if ($ex/error:code = "XDMP-UNDFUN") then $admin-config
else
xdmp:rethrow()
}

let $remove-existing-path-namespaces :=
let $admin-config := (: remove-existing-path-namespaces := :)
(: wrap in try catch because this function is new to 6.0 and will fail in older version of ML :)
try
{
if (xdmp:eval('
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $database external;
let $admin-config := admin:get-configuration()
declare variable $admin-config external;
let $remove-existing-indexes :=
for $index in admin:database-get-path-namespaces($admin-config, $database)
for $index at $i in admin:database-get-path-namespaces($admin-config, $database)
return
xdmp:set($admin-config, admin:database-delete-path-namespace($admin-config, $database, $index))
return
admin:save-configuration-without-restart($admin-config)',
(xs:QName("database"), $database))) then
xdmp:set($restart-needed, fn:true())
else ()
$admin-config (: admin:save-configuration-without-restart($admin-config) :)',
(xs:QName("database"), $database,
xs:QName("admin-config"), $admin-config))
}
catch($ex)
{
if ($ex/error:code = "XDMP-UNDFUN") then ()
xdmp:log($ex),
if ($ex/error:code = "XDMP-UNDFUN") then $admin-config
else if ($ex/error:code = "ADMIN-PATHNAMESPACEINUSE" and fn:not(setup:at-least-version("6.0-2"))) then
fn:error(xs:QName("VERSION_NOT_SUPPORTED"), "Roxy does not support path namespaces for this version of MarkLogic. Use 6.0-2 or later.")
else
xdmp:rethrow()
}

let $admin-config := setup:add-word-lexicons(admin:get-configuration(), $database, $db-config)
let $admin-config := setup:add-word-lexicons($admin-config, $database, $db-config)
let $admin-config := setup:add-fragment-roots($admin-config, $database, $db-config)
let $admin-config := setup:add-fragment-parents($admin-config, $database, $db-config)

Expand Down Expand Up @@ -1217,6 +1219,7 @@ declare function setup:add-field-excludes-R(
else
xdmp:eval(
'import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace db="http://marklogic.com/xdmp/database";
declare variable $e external;
admin:database-excluded-element(
Expand Down Expand Up @@ -1437,6 +1440,22 @@ declare function setup:validate-range-path-indexes(
xdmp:rethrow()
}
for $expected in $db-config/db:range-path-indexes/db:range-path-index
let $expected :=
xdmp:eval('
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare namespace db="http://marklogic.com/xdmp/database";
declare variable $database external;
declare variable $x external;
admin:database-range-path-index(
$database,
$x/db:scalar-type,
$x/db:path-expression,
$x/db:collation,
$x/db:range-value-positions,
$x/db:invalid-values)',
(xs:QName("database"), $database,
xs:QName("x"), $expected))
return
if ($existing[fn:deep-equal(., $expected)]) then ()
else
Expand Down Expand Up @@ -3815,6 +3834,31 @@ declare function setup:get-forests-per-host-from-database-config(
:: Utility functions
::)

declare function setup:at-least-version($target)
{
let $current := xdmp:version()
let $current-formatted :=
fn:concat(
fn:format-number(xs:int(fn:replace($current, "^(\d+)\..*", "$1")), "000"), (: major :)
fn:format-number(xs:int(fn:replace($current, "^\d+\.(\d+).*", "$1")), "000"), (: minor :)
fn:format-number(xs:int(fn:replace($current, "^\d+\.\d+\-(\d+).*", "$1")), "000"), (: x.x-X :)
if (fn:matches($current, "^\d+\.\d+\-\d+\.\d+")) then
fn:format-number(xs:int(fn:replace($current, "^\d+\.\d+\-\d+\.(\d+)", "$1")), "000") (: x.x-x.X :)
else "000"
)
let $target-formatted :=
fn:concat(
fn:format-number(xs:int(fn:replace($target, "^(\d+)\..*", "$1")), "000"), (: major :)
fn:format-number(xs:int(fn:replace($target, "^\d+\.(\d+).*", "$1")), "000"), (: minor :)
fn:format-number(xs:int(fn:replace($target, "^\d+\.\d+\-(\d+).*", "$1")), "000"), (: x.x-X :)
if (fn:matches($target, "^\d+\.\d+\-\d+\.\d+")) then
fn:format-number(xs:int(fn:replace($target, "^\d+\.\d+\-\d+\.(\d+)", "$1")), "000") (: x.x-x.X :)
else "000"
)
return fn:compare($current-formatted, $target-formatted) >= 0
};


declare function setup:read-config-file($filename as xs:string) as document-node()
{
xdmp:security-assert("http://marklogic.com/xdmp/privileges/admin-module-read", "execute"),
Expand Down Expand Up @@ -4306,15 +4350,24 @@ declare function setup:validation-fail($message)

declare function setup:validate-install($import-config as element(configuration))
{
setup:validate-privileges($import-config),
setup:validate-roles($import-config),
setup:validate-users($import-config),
setup:validate-mimetypes($import-config),
setup:validate-forests($import-config),
setup:validate-databases($import-config),
setup:validate-attached-forests($import-config),
setup:validate-amps($import-config),
setup:validate-database-settings($import-config),
setup:validate-databases-indexes($import-config),
setup:validate-appservers($import-config)
try
{
setup:validate-privileges($import-config),
setup:validate-roles($import-config),
setup:validate-users($import-config),
setup:validate-mimetypes($import-config),
setup:validate-forests($import-config),
setup:validate-databases($import-config),
setup:validate-attached-forests($import-config),
setup:validate-amps($import-config),
setup:validate-database-settings($import-config),
setup:validate-databases-indexes($import-config),
setup:validate-appservers($import-config)
}
catch($ex)
{
xdmp:set-response-code(500, 'Internal Server Error'),
xdmp:set-response-content-type("text/plain"),
$ex
}
};
2 changes: 0 additions & 2 deletions deploy/test/data/ml5-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,13 @@
<coordinate-system>wgs84</coordinate-system>
<point-format>point</point-format>
<range-value-positions>false</range-value-positions>
<invalid-values>reject</invalid-values>
</geospatial-element-index>
<geospatial-element-index>
<namespace-uri>http://www.marklogic.com/ns/sample</namespace-uri>
<localname>geo-element2</localname>
<coordinate-system>wgs84</coordinate-system>
<point-format>point</point-format>
<range-value-positions>false</range-value-positions>
<invalid-values>reject</invalid-values>
</geospatial-element-index>
</geospatial-element-indexes>
<geospatial-element-attribute-pair-indexes>
Expand Down
80 changes: 80 additions & 0 deletions deploy/test/data/ml5-properties/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#################################################################
# This file contains overrides to values in default.properties
# Make changes here, not in default.properties
#################################################################

#
# Admin username/password that will exist on the dev/cert/prod servers
#
user=admin
password=admin

# Your Application's name
app-name=roxy-deployer-tester

# The root of you modules database or filesystem dir
modules-root=/

#
# the location of your marklogic configuration file
#
config.file=${basedir}/deploy/test/data/ml5-config.xml

#
# Unit Testing
# Leave commented out for no unit testing
# turn these on if you are using the roxy unit tester
#
test-content-db=${app-name}-content-test
test-modules-db=${app-name}-modules-test
test-port=8902

#
# Leave commented out for default
#
schemas-db=${app-name}-schemas

#
# Leave commented out for default
# turn it on if you are using triggers or CPF
#
triggers-db=${app-name}-triggers

#
# the port that the Docs appserver is running on
# Docs appserver is required for boostrapping
# set this to 8000 for ML 4.x and 8002 for ML 5.x
# you should only override this if your Docs appserver
# is running on a funky port
#
# bootstrap-port=

#
# The ports used by your application
#
app-port=8900
xcc-port=8901

content-forests-per-host=2

#
# The authentication method used for your appserver
# application-level, basic, digest, digestbasic
#
authentication-method=digest

#
# The user used as the default user in application level authentication.
# Using the admin user as the default user is equivalent to turning security off.
#
# default-user=${app-name}-user

#
# the uris or IP addresses of your servers
# WARNING: if you are running these scripts on WINDOWS you may need to change localhost to 127.0.0.1
# There have been reported issues with dns resolution when localhost wasn't in the hosts file.
#
local-server=localhost
#dev-server=
#cert-server=
#prod-server=
Loading

0 comments on commit 327f937

Please sign in to comment.