Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a database in marklogic from a script

Tags:

marklogic

We have started a new project that uses marklogic to store documents. To get the app running, we need to create a database, a forest, new users and setup an XDBC server. It is quite easy to do it from the web admin tool provided by Marklogic, but to run it from a continuous integration server we need to automate it. Is there any way to do it from the command line (like the sqlcmd.exe for sqlserver or sql plus in oracle) ??

like image 833
uttamkini Avatar asked Apr 08 '12 14:04

uttamkini


People also ask

How do I create a MarkLogic database?

Navigate to http://localhost:8000/appservices to access the Application Services page. The Database section provides you with access to all of the databases in your MarkLogic Server and enables you to create a new database, configure a database, or delete a database.

What database does MarkLogic use?

MarkLogic uses RDF triples to provide semantics for ease of storing metadata and querying. Unlike other NoSQL databases, MarkLogic maintains ACID consistency for transactions.

How is data stored in MarkLogic?

MarkLogic fuses together database internals, search-style indexing, and application server behaviors into a unified system. It uses XML and JSON documents as its data model, and stores the documents within a transactional repository.

How many content database does a typical MarkLogic application need?

Three Databases are created by default, Security Database, Schema Database and Documents Database.


2 Answers

As long as you are using MarkLogic 5.x, the easiest thing to do would be to use the Configuration Manager. This web based tool allows you to export the entire DB and app server configuration to a single xml file which can be version controlled. It can also then be imported to completely setup or reconfigure your MarkLogic instance.

In order to use this as part of continuous integration, you would have to script the import of the configuration. You could create an http server that has one endpoint which invokes the configuration API to do the loading, as documente here: http://community.marklogic.com/pubs/5.0/apidocs/package-api.html. This https based service could easily be invoked via ANT or any other CI tool.

Alternatively, especially if you are not yet running on 5.x, you could script the entire process instead of using a configuration package. All of the admin tasks are documented here: http://community.marklogic.com/pubs/5.0/books/adminAPI.pdf. You would then have to write all of the code necessary to configure your database, app servers, etc. and then expose it via an http server as described above.

like image 128
Clark Richey Avatar answered Sep 27 '22 16:09

Clark Richey


Thanks to Clark Richey's help, I might have found out a way of automating the configuration of the MarkLogic server 5.x (though by no means straightforward).

For example if you want to automate the creation of an xdbc server, Go the query console of an instance where a manually configured xdbc server exists.Use the following xquery to generate a package file for the xdbc server(in my case called sample-server).

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

let $my-package := package:create()

return package:add-appserver($my-package, "Default", "sample-server")

You would now see a package xml which contains all the information needed to create and configure the xdbc server. Save this in a file or on your clipboard. Now go to the query console of the marklogic instance that you want to configure. Use the following xquery to actually install it on the instance.

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

let $package := {paste the package xml you saved in file/clipboard step1}

return package:install($package)

You will now a get an xml result which says that the package has been written.

Now for the all important step of automating this in my CI environment. I would write a an custom ant/nant task (or in my specific case a powershell cmdlet) which reads the configuration file from a file system, connects to ML using XCC (and admin credentials, because stuff like creating databases and app servers need it) and then executes the very same xquery defined above. I can then version control the configuration file in my source control and that way I can automate the creation/configuration of databases on a fresh install of ML without any manual intervention. Any other better ways of doing it ??

like image 27
uttamkini Avatar answered Sep 27 '22 17:09

uttamkini