This page was generated
August  8,  2011
2:23  AM
XQuery Built-In and Modules Function Reference

Module: Admin Library - Actions 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:get-configuration Loads the admin configuration into memory for use by other functions in the Admin module.
admin:restart-hosts This function restarts MarkLogic Server for the specified hosts.
admin:save-configuration This function saves a configuration specification to the cluster configuration files.
admin:save-configuration-without-restart This function saves a configuration specification to the cluster configuration files, without restarting MarkLogic Server.
Function Detail
admin:get-configuration(  ) as  element(configuration)
Summary:

Loads the admin configuration into memory for use by other functions in the Admin module.

Required Privilege:

http://marklogic.com/xdmp/privileges/admin-module-read

Usage Notes:

The configuration is loaded into memory only as it is needed, so it might not contain the entire configuration at any given moment. It loads only the parts of the configuration that are needed at the time they are needed to perform other Admin module operations that specified in the XQuery request. Therefore, if you execute the function without calling any other Admin module functions, it will return the empty sequence (because it never needed any of the config information to perform any of the Admin module operations).

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:database-get-range-element-indexes($config, 
                           xdmp:database("Documents") )

  => The xml for any element range indexes in the "Documents"
     database, for example:
   <range-element-index xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	                xmlns="http://marklogic.com/xdmp/database">
      <scalar-type>date</scalar-type>
      <collation/>
      <namespace-uri>mynamespace</namespace-uri>
      <localname>myelementname</localname>
      <range-value-positions>false</range-value-positions>
   </range-element-index>
  

admin:restart-hosts(
$hosts as xs:unsignedLong*
)  as   empty-sequence()
Summary:

This function restarts MarkLogic Server for the specified hosts.

Parameters:
$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:
(: 
  This query restarts all hosts in the cluster.  Note that
  it will restart the host in which the query is run, too.
:)
xquery version "1.0-ml";

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

let $hostids := 
   for $id in xdmp:host-status(xdmp:host())
                               /host:hosts//host:host/host:host-id
   return fn:data($id)
return
admin:restart-hosts($hostids)
  

admin:save-configuration(
$config as element(configuration)
)  as   empty-sequence()
Summary:

This function saves a configuration specification to the cluster configuration files. It restarts MarkLogic Server for "cold" administrative tasks only (for example, for App Server port assignment changes). If you do not want those "cold" administrative tasks to automatically restart MarkLogic Server, use admin:save-configuration-without-restart instead.

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

Required Privilege:

http://marklogic.com/xdmp/privileges/admin-module-write

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 $spec := admin:forest-set-enabled($config, 
    xdmp:forest("myForest"), fn:true() )
  return
  admin:save-configuration($spec)
  

admin:save-configuration-without-restart(
$config as element(configuration)
)  as   xs:unsignedLong*
Summary:

This function saves a configuration specification to the cluster configuration files, without restarting MarkLogic Server. If you use this function to save any changes that require a server restart ("cold" changes such as App Server port assignment changes), then the changes will not take effect until the next time MarkLogic Server restarts (although they will be saved in the configuration). If you want MarkLogic Server to automatically restart when needed, use admin:save-configuration instead.

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

Required Privilege:

http://marklogic.com/xdmp/privileges/admin-module-write

Usage Notes:

The return value is a list of the host IDs that need to be restarted in order for the changes to take effect.

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 $spec := admin:forest-set-enabled($config, 
    xdmp:forest("myForest"), fn:true() )
  return
  admin:save-configuration-without-restart($spec)