This page was generated
July 7, 2010
4:02 PM
XQuery Built-In and Modules Function Reference

Module: Admin Library - Forest Functions

The Admin module is an XQuery library module that allows you to script administrative tasks that you otherwise would need the Admin Interface to perform. Most functions in this library perform adminstrative tasks and therefore require the user who runs the XQuery program to have the Admin role.

Many of these functions provide new configuration information. In most cases, you must save the configuration (with admin:save-configuration, for example) in the same statement that you use the functions in order for them to take effect.

To use the Admin module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"

The library namespace prefix admin is not predefined in the server.

Function Summary
admin:forest-add-backup This function adds scheduled backup specifications for a forest to a configuration.
admin:forest-add-failover-host This function adds a failover host to the list of failover hosts for the specified forest in the specified configuration.
admin:forest-copy This function creates a new forest specification with the same settings as the forest with the specified ID.
admin:forest-create This function creates a new forest configuration.
admin:forest-delete This function deletes the configuration for the specified forest from the configuration.
admin:forest-delete-backup This function deletes scheduled backup specifications for a forest from a configuration.
admin:forest-delete-failover-host This function deletes the specified failover host(s) from the failover-host list in the specified configuration.
admin:forest-get-backups This function returns the scheduled backups for the specified forest from the configuration.
admin:forest-get-data-directory This function returns the name of the data directory of the specified forest.
admin:forest-get-enabled This function returns the enabled state of the specified forest.
admin:forest-get-failover-enable This function returns the state of whether failover is enabled for the specified forest.
admin:forest-get-failover-hosts This function returns the forest IDs of the hosts defined as failover hosts for this forest.
admin:forest-get-host This function returns the ID of the host in which the specified forest resides.
admin:forest-get-id This function returns the ID of the forest with the specified name, from the specified configuration.
admin:forest-get-name This function returns the name(s) of the specified forest(s), given the forest ID(s).
admin:forest-get-updates-allowed This function returns the state of whether updates are allowed for the specified forest.
admin:forest-monthly-backup This function constructs a monthly scheduled backup.
admin:forest-one-time-backup This function constructs a one-time backup.
admin:forest-set-enabled This function sets the enabled state for a forest configuration.
admin:forest-set-failover-enable This function sets the forest failover enabled state for a forest configuration.
admin:forest-set-host This function sets a forest configuration to a new host.
admin:forest-set-updates-allowed This function sets whether updates are allowed for a forest configuration.
admin:forest-weekly-backup This function constructs a weekly scheduled backup.
admin:get-forest-ids This function returns all the forest IDs from the configuration.
Function Detail
admin:forest-add-backup(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$backups as element(as:forest-backup)*
)  as  element(configuration)
Summary:

This function adds scheduled backup specifications for a forest to a configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The id of the forest (for example, xdmp:forest("myforest")).
$backups : The scheduled backup specification(s), typically the result of an admin:forest-one-time-backup or an admin:forest-monthly-backup or an admin:forest-weekly-backup call

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  let $config := admin:get-configuration()
  let $forest := xdmp:forest("myforest")
  let $backup := admin:forest-one-time-backup("/backup-dir",  
        xs:dateTime("2008-02-14T09:45:00"))
  return
  admin:forest-add-backup($config, $forest, $backup)
  (: returns the new configuration element -- use admin:save-configuration
     to save the changes to the configuration or pass the configuration
     to other Admin API functions to make other changes.  :)  

  

admin:forest-add-failover-host(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$hosts as xs:unsignedLong*
)  as  element(configuration)
Summary:

This function adds a failover host to the list of failover hosts for the specified forest in the specified configuration. If there are already any hosts specified, this host is added to the end of the list of failover hosts.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$hosts : The host ID(s) for the host(s) you want to restart. For example, xdmp:host() returns the ID for the current host.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-add-failover-host($config, 
      admin:forest-get-id($config, "Documents"), 
      xdmp:host("myFailoverHost"))
    
      => add the failover host "myFailoverHost" to the end of the  
         list of failover hosts

  

admin:forest-copy(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$forest-name as xs:string,
$data-directory as xs:string?
)  as  element(configuration)
Summary:

This function creates a new forest specification with the same settings as the forest with the specified ID. The new forest configuration will have the specified name. It copies the forest configuration, but does not copy the forest data.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$forest-name : The name for the new forest.
$data-directory : The optional data directory of the forest. If no directory is specified, then it will be a private forest.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  admin:forest-copy(admin:get-configuration(), xdmp:forest("myForest"),
         "myNewForest",())

  

admin:forest-create(
$config as element(configuration),
$forest-name as xs:string,
$host-id as xs:unsignedLong,
$data-directory as xs:string?
)  as  element(configuration)
Summary:

This function creates a new forest configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-name : The name of the forest. The must be unique for all forests in the cluster.
$host-id : The ID of the host (for example, xdmp:host() for the current host.
$data-directory : The optional data directory of the forest. If no directory is specified, then it will be a private forest.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  admin:forest-create(admin:get-configuration(), "newForest", xdmp:host(), ())

  

admin:forest-delete(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$delete-data as xs:boolean
)  as  element(configuration)
Summary:

This function deletes the configuration for the specified forest from the configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$delete-data : If set to true, deletes the data directory as well as the configuration (Note: all documents in the forest will be permanently deleted). If set to false, deletes only the configuration information, leaving the forest data in the data directory on disk.

Usage Notes:

Any forest whose ID you pass into this function must not be attached to a database when the transaction begins, otherwise an exception is thrown. If you need to detach the forest, do so in a separate transaction before using them in this function.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-delete($config, admin:forest-get-id($config, "Documents"), 
      fn:false())
    
      => deletes the forest configuration for the forest
         named "Documents"

  

admin:forest-delete-backup(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$blackouts as element(as:forest-backup)*
)  as  element(configuration)
Summary:

This function deletes scheduled backup specifications for a forest from a configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The id of the forest (for example, xdmp:forest("myforest")).
$blackouts : The scheduled backup(s) to delete. Typically, the result of an admin:forest-get-backups call.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  let $config  := admin:get-configuration()
  let $forest  := xdmp:forest("Documents")
  let $backups := admin:forest-get-backups($config, $forest)[1 to 3]
  return
  admin:forest-delete-backup($config, $forest, $backups)
  (: returns the new configuration element -- use admin:save-configuration
     to save the changes to the configuration or pass the configuration
     to other Admin API functions to make other changes.  :)  

  

admin:forest-delete-failover-host(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$hosts as xs:unsignedLong*
)  as  element(configuration)
Summary:

This function deletes the specified failover host(s) from the failover-host list in the specified configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$hosts : The host ID(s) for the host(s) you want to restart. For example, xdmp:host() returns the ID for the current host.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-delete-failover-host($config, 
      admin:forest-get-id($config, "Documents"), 
      xdmp:host("myFailoverHost"))
    
      => deletes the failover host "myFailoverHost" from the  
         list of failover hosts

  

admin:forest-get-backups(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  element(as:forest-backup)*
Summary:

This function returns the scheduled backups for the specified forest from the configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The id of the forest (for example, xdmp:forest("myforest")).

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  let $config := admin:get-configuration()
  return
  admin:forest-get-backups($config, xdmp:forest("myforest") )
  (: returns the scheduled backups for the forest :)

  

admin:forest-get-data-directory(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:string
Summary:

This function returns the name of the data directory of the specified forest.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-get-data-directory($config, 
         admin:forest-get-id($config, "test"))

  

admin:forest-get-enabled(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:boolean
Summary:

This function returns the enabled state of the specified forest.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-get-enabled($config, admin:forest-get-id($config, "test"))
  		  
  

admin:forest-get-failover-enable(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:boolean
Summary:

This function returns the state of whether failover is enabled for the specified forest.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-get-failover-enable($config, 
         admin:forest-get-id($config, "test"))

  

admin:forest-get-failover-hosts(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:unsignedLong*
Summary:

This function returns the forest IDs of the hosts defined as failover hosts for this forest. The order in which the hosts IDs are returned is significant, with the first ID being the primary host, the second (if there is one) being the secondary, and so on.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-get-failover-hosts($config, 
         admin:forest-get-id($config, "test"))

  

admin:forest-get-host(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:unsignedLong
Summary:

This function returns the ID of the host in which the specified forest resides.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  admin:forest-get-host(admin:get-configuration(), xdmp:forest("myForest"))

  => the ID of the host that services the forest named "myForest"
  

admin:forest-get-id(
$config as element(configuration),
$forest-name as xs:string
)  as  xs:unsignedLong
Summary:

This function returns the ID of the forest with the specified name, from the specified configuration. The difference between this function and xdmp:forest is that the ID from this function can come from a forest that has not yet been saved (that is, from a forest that has been created in the same query with the Admin library but has not yet been saved to the cluster configuration files).

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-name : The name of the forest.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  admin:forest-get-id(admin:get-configuration(), "myForest")
  

admin:forest-get-name(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:string
Summary:

This function returns the name(s) of the specified forest(s), given the forest ID(s).

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. If the ID does not correspond to a valid forest ID, then an exception is thrown.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  admin:forest-get-name(admin:get-configuration(), 18220031759147104956)
  

admin:forest-get-updates-allowed(
$config as element(configuration),
$forest-id as xs:unsignedLong
)  as  xs:boolean
Summary:

This function returns the state of whether updates are allowed for the specified forest.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-get-updates-allowed($config, 
         admin:forest-get-id($config, "test"))

  

admin:forest-monthly-backup(
$backup-dir as xs:string,
$backup-day-month as xs:unsignedInt,
$start-time as xs:time
)  as  element(as:forest-backup)
Summary:

This function constructs a monthly scheduled backup.

Parameters:
$backup-dir : The directory where the backup will be saved to.
$backup-day-month : The day of the month the backup will happen (between 1 and 31)
$start-time : A time for the scheduled backup to start.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  admin:forest-monthly-backup("/backup-dir", 1
        xs:time("09:45:00"))
  (: returns the monthly backup specification :)

  

admin:forest-one-time-backup(
$backup-dir as xs:string,
$start as xs:dateTime
)  as  element(as:forest-backup)
Summary:

This function constructs a one-time backup.

Parameters:
$backup-dir : The directory where the backup will be saved to.
$start : The starting dateTime of the scheduled backup.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  admin:forest-one-time-backup("/backup-dir",  
        xs:dateTime("2008-02-14T09:45:00"))
  (: returns the one-time backup :)
  

  

admin:forest-set-enabled(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$value as xs:boolean
)  as  element(configuration)
Summary:

This function sets the enabled state for a forest configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$value : The new state of the forest, for example fn:true() for enabled, fn:false() for disabled.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-set-enabled($config, admin:forest-get-id($config, "Documents"), 
      fn:false())
    
  => sets the forest named "Documents" to the disabled state
  

admin:forest-set-failover-enable(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$value as xs:boolean
)  as  element(configuration)
Summary:

This function sets the forest failover enabled state for a forest configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$value : The new failover-enable state of the forest, for example fn:true() for enabled, fn:false() for disabled.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-set-failover-enabled($config, 
      admin:forest-get-id($config, "Documents"), 
      fn:true())
    
      => sets the failover state of the forest named "Documents" to 
         the enabled state
  

admin:forest-set-host(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$value as xs:unsignedLong
)  as  element(configuration)
Summary:

This function sets a forest configuration to a new host.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$value : The host ID of the new host.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-set-host($config, admin:forest-get-id($config, "Documents"), 
              xdmp:host("myNewHost"))
  

admin:forest-set-updates-allowed(
$config as element(configuration),
$forest-id as xs:unsignedLong,
$value as xs:boolean
)  as  element(configuration)
Summary:

This function sets whether updates are allowed for a forest configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.
$forest-id : The ID of the forest. For example, xdmp:forest("myForest") specified the ID for a forest named "myForest".
$value : The new updates-allowed state of the forest, for example fn:true() for allowed, fn:false() for not allowed.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:forest-set-updates-allowed($config, 
      admin:forest-get-id($config, "Documents"), 
      fn:true())
    
      => sets the updates-allowed state of the forest named "Documents" to 
         the true state
  

admin:forest-weekly-backup(
$backup-dir as xs:string,
$days as xs:string+,
$start-time as xs:time
)  as  element(as:forest-backup)
Summary:

This function constructs a weekly scheduled backup.

Parameters:
$backup-dir : The directory where the backup will be saved to.
$days : The day(s) of the week. Must be a sequence of zero or more of monday, tuesday, wednesday, thusday, friday, saturday, sunday.
$start-time : A time for the scheduled backup to start.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";
    
  admin:forest-weekly-backup("/backup-dir", "monday", 
        xs:time("09:45:00"))
  (: returns the weekly backup specification :)

  

admin:get-forest-ids(
$config as element(configuration)
)  as  xs:unsignedLong*
Summary:

This function returns all the forest IDs from the configuration.

Parameters:
$config : A configuration specification, typically as returned from one of the Admin module functions.

Example:
  xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()
  return
  admin:get-forest-ids($config)
  (: returns the IDs of all the forests :)