Alert.png The wiki is deprecated and due to be decommissioned by the end of September 2022.
The content is being migrated to other supports, new updates will be ignored and lost.
If needed you can get in touch with EGI SDIS team using operations @ egi.eu.

Difference between revisions of "USG Using AMGA Metadata Catalog"

From EGIWiki
Jump to navigation Jump to search
(Created page with "{{Template:Op menubar}} {{Template:Doc_menubar}} {{TOC_right}} ---- <<  EGI User Start Guide ---- Category:Operations_Manuals")
 
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
----
----


This document has the goal of providing basic information on the usage of the AMGA Metadata Catalog.
<div class="sect2" title="Introduction"><div class="titlepage"><div><div>
=== Introduction  ===
</div></div></div>
The <span class="emphasis">''AMGA Metadata Catalog''</span> is the EGI <span class="emphasis">''gLite''</span> service that allows metadata handling on the grid. The main usage can be as a "Front-end" file metadata service, providing means of describing and discovering data files required by users and their jobs. It can also be used as a Grid-Enabled Database for applications that require to structure their data, proving a database-like service supporting Grid Security features (X509 Proxies and the VOMS authentication and authorization system). Finally, an additional feature allows the accessing of existing relational databases from a grid environment (<span class="emphasis">''Worker Nodes''</span>, <span class="emphasis">''User Interface''</span>, etc), which enables the addition of Grid Security to existing DBs.
Users and applications can interact with an AMGA server using <span class="emphasis">''command''
</span>
    line tools'':''
<div class="itemizedlist">
*<code class="code">mdcli/mdclient</code> available for Scientic Linux flavours (they can be built easily to other platforms)
*<code class="code">mdjavacli/mdjavaclient</code>, the Java versions of the previous one that allows the interaction from any platform
</div>
or through <span class="emphasis">''APIs''</span>, available for:
<div class="itemizedlist">
*C++
*Java
*Python
*Perl
*PHP
</div>
Some of the <code class="code">mdcli/mdclient</code> command line tools are explained below.
</div><div class="sect2" title="AMGA Metadata Basic Concepts"><div class="titlepage"><div><div>
=== AMGA Metadata Basic Concepts  ===
</div></div></div>
There are certain fundamental concepts which must be understood when dealing with AMGA
<div class="itemizedlist">
*<span class="bold">'''Entry'''</span> - it is the representation of the real world entity which we are attaching metadata to in order to describe it
*<span class="bold">'''Attribute'''</span> - key/value pair. It has:
<div class="itemizedlist">
*<span class="emphasis">''Type''</span> - The type (int, float, string, etc...)
**<span class="emphasis">''Name/Key''</span> - The name of the attribute
**<span class="emphasis">''Value''</span> - The value of an entry's attribute
</div>
*<span class="bold">'''Schema'''</span> - A set of attributes
*<span class="bold">'''Collection'''</span> - A set of entries associated with a schema
*<span class="bold">'''Metadata'''</span> - The list of attributes (including their values) associated with entries
</div>
If we want to make an analogy with the RDBMS world, we have the following:
<div class="itemizedlist">
*schema = table schema
*collection = database table
*attribute = schema column
*entry = table row/record
</div>
By analogy with a file system, we have:
<div class="itemizedlist">
*collection = directory
*entry = file
</div>
<span class="bold">'''In the AMGA help and documentation, often directory is used to refer to collection, as file refers to entry'''</span>
<span class="emphasis">''Example: Metadata for movies''</span>
Movie files (<span class="emphasis">''entries''</span>) could be saved on Grid <span class="emphasis">''Storage Elements''</span> and registered into a <span class="emphasis">''File Catalogue''</span>. We want to add <span class="emphasis">''metadata''</span> to describe the movie content. A possible <span class="emphasis">''schema''</span> could be:
<div class="itemizedlist">
*<code class="code">Title</code> -- varchar
*<code class="code">Runtime</code> -- int
*<code class="code">Cast</code> -- varchar
*<code class="code">LFN</code> -- varchar
</div>
We can use the GUID of the file as the <span class="emphasis">''entry''</span> name.
A <span class="emphasis">''collection''</span> named <code class="code">movies</code> of an AMGA server could be the repository of the movies' metadata and will allow to find the movies satisfying users' queries.
</div><div class="sect2" title="Accessing AMGA from the command line"><div class="titlepage"><div><div>
=== Accessing AMGA from the command line  ===
</div></div></div>
To start using AMGA from the command line, you need to use either <code class="code">mdcli</code> or <code class="code">mdclient</code> executables. They have to be installed, together with the required libraries, into a <span class="emphasis">''User Interface''</span> (and on the <span class="emphasis">''Worker Nodes''</span> of the sites where you plan to run jobs that will access AMGA). These do not come by default within the standard gLite <span class="emphasis">''UserInterface''</span> and <span class="emphasis">''WorkerNodes''</span> packages (on gLite 3.1 they should be available), so you need to install them manually.
You can download RPMs for SLC here:
<div class="itemizedlist">
*[http://amga.web.cern.ch/amga/downloads/glite-amga-cli-1.3.0-1.SLC4.i386.rpm http://amga.web.cern.ch/amga/downloads/glite-amga-cli-1.3.0-1.SLC4.i386.rpm] for SLC4 systems
*[http://amga.web.cern.ch/amga/downloads/glite-amga-cli-1.3.0-1.i386.rpm http://amga.web.cern.ch/amga/downloads/glite-amga-cli-1.3.0-1.i386.rpm] for SLC3 systems
</div>
Once installed, you need to properly configure the configuration file: <code class="code">$HOME/.mdclient.config</code>. A template of this file can be found in <code class="code">$GLITE_INSTALLATION/etc/mdclient.config</code>. This also behaves as a system wide configuration file, useful in a multi-user system (like on Worker Nodes) and it will be read by the AMGA clients if the $HOME/.mdclient.config does not exist.
The relevant values of the mdclient.config are the following:
<pre class="program">Host = amga.ct.infn.it
Port = 8822
Login = NULL
PermissionMask = rwx
GroupMask = r-x
Home = /gilda
UseSSL = yes
AuthenticateWithCertificate = 1
UseGridProxy = 1
VerifyServerCert = 0
</pre>
where
<div class="itemizedlist">
*
<span class="emphasis">''Host''</span> defines the AMGA server you want to use. You can use amga.ct.infn.it for the purpose of testing (installed as part of the EGEE GILDA training infrastructure
*
<span class="emphasis">''Port''</span> defines the port where the AMGA server daemon is listening. It should not changed
*
<span class="emphasis">''Login''</span> defines the credential to be used to authenticated within the AMGA catalog. You can use:
*
your <code class="code">username</code>, if you have requested one to AMGA server administrator providing him your Grid Certificate Distinguish Name (DN)
*
or use <code class="code">NULL</code>, to be authenticated as a generic VO user (given the fact that your VO is supported by the AMGA server you are going to use)
*
The AMGA server in the GILDA training infrastructure supports the following VOs: <code class="code">gilda, eela, eumed, euchina, cometa</code>. Please contact the amga.ct.inf n.it sysadmins (tony.calanducci [at] ct.infn.it) to request support for your VO or to get a personal account. Soon a registration page will be availabe at: [https://amga.ct.infn.it:8443/register https://amga.ct.infn.it:8443/register]
*
Please take a look at the AMGA documentation [http://amga.web.cern.ch/amga/mdclient_config.html here] for all the available options of the <code class="code">.mdclient.config</code> file.
*
The options on the previous example were set up to be authenticated as a generic VO user using your Grid Proxy. Be sure to initialize your proxy with the proper command:
</div><pre class="response">-bash-2.05b$ voms-proxy-init --voms gilda
Enter GRID pass phrase:
Your identity: /C=IT/O=GILDA/OU=Personal Certificate/L=INFN Catania/CN=Tony Calanducci/Email=tony.calanducci@ct.infn.it
Creating temporary proxy ............................................................................. Done
Contacting  voms.ct.infn.it:15001 [/C=IT/O=INFN/OU=Host/L=Catania/CN=voms.ct.infn.it] "gilda" Done
Creating proxy ...................................... Done
Your proxy is valid until Sun Feb  3 08:04:46 2008
</pre>
Once everything has been set up properly, start the AMGA <code class="code">mdclient</code>&nbsp;:
<pre class="response">-bash-2.05b$ mdclient
Connecting to amga.ct.infn.it:8822...
ARDA Metadata Server 1.3.0
Query&gt;
</pre>
This is an interactive shell similar to <code class="code">mysql o psql</code> that allows to issue AMGA commands to the server. The other AMGA executable that comes with the RPM, <code class="code">mdcli</code>, provides the very same functionality, but it executes ONLY one command at time, passed as command line parameter, and immediately exits. This is quite useful in bash script to be run on Worker Nodes that needs to interact with the metadata catalog.
</div><div class="sect2" title="Basic commands"><div class="titlepage"><div><div>
=== Basic commands  ===
</div></div></div>
It is possible to get help anytime on the client just using the <code class="code">'help'</code> command.
<span class="emphasis">''Try the <code class="code">help</code> command''</span>
<pre class="response">Query&gt; help
&gt;&gt; help [topic]
&gt;&gt; Displays help on a command or a topic.
&gt;&gt; Valid topics are: help metadata metadata-optional directory replication constraints entry group acl index schema sequence user view site replicas ticket /
capabilities commands
Query&gt;
</pre>
Commands are grouped by topic. You can get the list of valid commands for each topic, typing: <code class="code">help [topic]</code>
The list of valid topics is:
<div class="itemizedlist">
*
help
*
metadata
*
metadata-optional
*
directory
*
replication
*
entry
*
group
*
acl
*
index
*
schema
*
sequence
*
user
*
view
*
ticket
*
commands
</div>
<span class="emphasis">''Try the use of <code class="code">help</code> command with any topic''</span>
<code class="code">Query&gt; help entry</code>
</div><div class="sect2" title="mdclient general commands"><div class="titlepage"><div><div>
=== <code class="code">mdclient</code> general commands  ===
</div></div></div>
The following tables gives a brief description of the general use commands.
<div class="informaltable">
{| border="1"
|-
| <code class="code">createdir path [options]</code>
| Create a new <code class="code">collection</code>. It can inherit (using the <code class="code">inherit</code> option) the schema associated to the upper level collection
|-
| <code class="code">rm pattern</code>
| Remove the entries corresponding to the given pattern
|-
| <code class="code">dir collection</code>
| List the content (entries, subcollections, sequences, indexes) of the given collection
|-
| <code class="code">listentries collection</code>
| List the entries only of the given collection
|-
| <code class="code">stat pattern</code>
| Show the statistics of an entry or collection
|-
| <code class="code">chown file owner</code>
| Change the ownership of an entry or collection
|-
| <code class="code">chmod file rights</code>
| Change the access mode of an entry or collection
|-
| <code class="code">rmdir collection</code>
| Remove a collection
|-
| <code class="code">dump collection</code>
| Make a recursive dump starting from a given collection, (the default is: '/')
|-
| <code class="code">pwd</code>
| Prints the current collection
|-
| <code class="code">whoami</code>
| Prints the current user
|-
| <code class="code">cd collection</code>
| Change the current collection
|}
</div><div class="sect3" title="General commands examples:"><div class="titlepage"><div><div>
==== General commands examples:  ====
</div></div></div>
<code class="code">Query&gt; whoami</code>
<pre class="response">&gt;&gt; gilda
</pre>
<code class="code">Query&gt; pwd</code>
<pre class="response">&gt;&gt; /
</pre>
<code class="code">Query&gt; cd /gilda</code>
<code class="code">Query&gt; cd tony</code>
<code class="code">Query&gt; pwd</code>
<pre class="response">&gt;&gt; /gilda/tony/
</pre>
<code class="code">Query&gt; dir</code>
<pre class="response">&gt;&gt; /gilda/tony/seq2
&gt;&gt; sequence
&gt;&gt; /gilda/tony/seconda
&gt;&gt; collection
&gt;&gt; /gilda/tony/v1
&gt;&gt; collection
&gt;&gt; /gilda/tony/v2
&gt;&gt; collection
&gt;&gt; /gilda/tony/view1
&gt;&gt; view
&gt;&gt; /gilda/tony/aentry
&gt;&gt; entry
&gt;&gt; /gilda/tony/14
&gt;&gt; entry
&gt;&gt; /gilda/tony/15
&gt;&gt; entry
&gt;&gt; /gilda/tony/16
&gt;&gt; entry
&gt;&gt; /gilda/tony/17
&gt;&gt; entry
&gt;&gt; /gilda/tony/18
&gt;&gt; entry
&gt;&gt; /gilda/tony/20
&gt;&gt; entry
</pre>
<code class="code">Query&gt; listentries</code>
<pre class="response">&gt;&gt; /gilda/tony/aentry
&gt;&gt; /gilda/tony/14
&gt;&gt; /gilda/tony/15
&gt;&gt; /gilda/tony/16
&gt;&gt; /gilda/tony/17
&gt;&gt; /gilda/tony/18
&gt;&gt; /gilda/tony/20
</pre>
<code class="code">Query&gt; cd seconda</code>
<code class="code">Query&gt; dir</code>
<pre class="response">&gt;&gt; /gilda/tony/seconda/2
&gt;&gt; entry
</pre>
<code class="code">Query&gt; rm *</code>
<code class="code">Query&gt; cd ..</code>
<code class="code">Query&gt; pwd</code>
<pre class="response">&gt;&gt; /gilda/tony/</pre>
<code class="code">Query&gt; rmdir seconda</code>
</div></div><div class="sect2" title="Handling schemas and attributes"><div class="titlepage"><div><div>
=== Handling schemas and attributes  ===
</div></div></div>
Once a <span class="emphasis">''collection''</span> has been created, its <span class="emphasis">''schema''</span> should be defined, adding one or more <span class="emphasis">''attributes''</span>. As illustrated in the basic concept section, each attribute is defined by its <span class="emphasis">''name''</span> and its <span class="emphasis">''type''</span>.
The command to add a new attribute to a collection schema is the following:
<code class="code">addattr dir attribute_name type</code> where:
<div class="itemizedlist">
*
<code class="code">dir</code> is the collection/directory you are adding the attribute to. You can use relative or absolute path to refer to it.
*
<code class="code">attribute_name</code> is the name you want to give to the attribute you are adding
*
<code class="code">type</code> specifies what kind of values the attribute is able to contain
</div>
AMGA valid <span class="emphasis">''attribute types''</span> and their corresponding types used in the internal AMGA back-end are shown in the following table:
<div class="informaltable">
{| border="1"
|-
! AMGA
! PostgreSQL
! MySQL
! Oracle
! SQLite
! Python
|-
| int
| integer
| int
| number(38)
| int
| int
|-
| float
| double precision
| double precision
| float
| float
| float
|-
| varchar(n)
| character varying(n)
| character varying(n)
| varchar2(n)
| varchar(n)
| string
|-
| timestamp
| timestamp w/o TZ
| datetime
| timestamp(6)
| unsupported
| time(unsupported)
|-
| text
| text
| text
| long
| text
| string
|-
| numeric(p,s)
| numeric(p.s)
| numeric(p.s)
| numeric(p.s)
| numeric(p.s)
| float
|}
</div>
The AMGA server uses internally a relational database to store all the users' metadata. It can use almost any RDBMS that has an ODBC driver. Most of the installations use PostgreSQL and MySQL. If the types indicated in the first column are used to define attributes, metadata can be moved and replicated easily among AMGA servers that use different DB backends. If you don't mind to metadata portability between servers, you can also use all the specific data types of a given DB back-end (we have tried GIS datatypes and Network datatypes of PostgreSQL, for example). To find out which database back-end a given AMGA server is employing, you can use the command <code class="code">backend</code>:
<pre class="response">Query&gt; backend
&gt;&gt; PostgreSQL
</pre>
To remove an attribute from a collection schema, the following command is used:
<code class="code">removeattr dir attribute_name</code>
To inspect the schema of a given collection (or of an entry), use:
<code class="code">listattr dir/entry</code>
<div class="sect3" title="Schema population example:"><div class="titlepage"><div><div>
==== Schema population example:  ====
</div></div></div>
Let's create a <span class="emphasis">''movies''</span> collection and define its schema, adding the following attributes: <span class="emphasis">''title, runtime,''
</span>
    cast, LFN, to_remove'' (one of them will be removed):''
<pre class="response">Query&gt; createdir /gilda/movies
Query&gt; addattr /gilda/movies title varchar(50)
Query&gt; addattr /gilda/movies runtime int
Query&gt; addattr /gilda/movies cast text
Query&gt; addattr /gilda/movies LFN varchar
Query&gt; addattr /gilda/movies to_remove float
Query&gt; listattr /gilda/movies
&gt;&gt; title
&gt;&gt; varchar(50)
&gt;&gt; runtime
&gt;&gt; int
&gt;&gt; cast
&gt;&gt; text
&gt;&gt; LFN
&gt;&gt; varchar
&gt;&gt; to_remove
&gt;&gt; float
Query&gt; cd /gilda/movies
Query&gt; removeattr . to_remove
Query&gt; listattr .
&gt;&gt; title
&gt;&gt; varchar(50)
&gt;&gt; runtime
&gt;&gt; int
&gt;&gt; cast
&gt;&gt; text
&gt;&gt; LFN
&gt;&gt; varchar
</pre></div></div><div class="sect2" title="Handling entries and metadata"><div class="titlepage"><div><div>
=== Handling entries and metadata  ===
</div></div></div>
Once the schema of a collection has been defined, it is possible to add new <span class="emphasis">''entries''</span>. <span class="bold">'''Each entry must have an <span class="emphasis">''entry name''</span>'''</span>. You can think of entry names as primary keys of a database table. Entry names are unique. According to your purposes, you could have different options. To mention some examples, GUIDs (Globally Unique Identifiers) could be an option if you are adding metadata to files, the final part of JOB IDs ('/' can't be part of entry names) if you are adding metadata to running jobs, or simply an incremental integer number. You may use any appropriate entry name to better describe your entities. If you want to use an incremental integer as entry name, AMGA <span class="bold">'''sequences'''</span> can be very useful. You can define one or more sequences for a given collection, but those will not generate by themselves new numbers unless you explicitly request it.
<pre class="command">Query&gt; help sequence
&gt;&gt; sequence_create name dir [increment] [start value]
&gt;&gt;  Creates a new sequences with given name in the given directory.
&gt;&gt; sequence_next sequence
&gt;&gt;  Gets the next value from a sequence.
&gt;&gt; sequence_remove sequence
&gt;&gt;  Deletes a sequence.
Query&gt;
</pre><div class="sect3" title="Sequence examples"><div class="titlepage"><div><div>
==== Sequence examples  ====
</div></div></div>
Create a sequence for the <span class="emphasis">''movies''</span> collection and get the next sequence id:
<pre class="response">Query&gt; pwd
&gt;&gt; /gilda/movies/
Query&gt; sequence_create id /gilda/movies
Query&gt; dir
&gt;&gt; /gilda/movies/id
&gt;&gt; sequence
Query&gt; sequence_next /gilda/movies/id
&gt;&gt; 1
Query&gt; sequence_next /gilda/movies/id
&gt;&gt; 2
Query&gt; sequence_next /gilda/movies/id
&gt;&gt; 3
</pre>
Once decided how to handle entry names, we can actually start <span class="bold">'''adding or removing entries'''</span>. Four commands are available for that purpose:
<div class="informaltable">
{| border="1"
|-
| <code class="code">addentries entry1...</code>
| <span class="emphasis">''Adds one or more entries (also across collections)''</span>
|-
| <code class="code">addentry entry [attribute_name value]...</code>
| <span class="emphasis">''Adds one new entry and initializes one or more attributes''</span>
|-
| <code class="code">removeentries entry1...</code>
| <span class="emphasis">''Removes one or more entries (also across collections)''</span>
|-
| <code class="code">rm [-rf] pattern [condition]</code>
| <span class="emphasis">''Removes entries matching pattern/condition''</span>
|}
</div></div><div class="sect3" title="Entry creation and deletion examples"><div class="titlepage"><div><div>
==== Entry creation and deletion examples  ====
</div></div></div>
Let's add 2 entries with valid attributes and 3 empty entries, then delete the last two:
<pre class="response">Query&gt; pwd
&gt;&gt; /gilda/movies/
Query&gt; sequence_next id
&gt;&gt; 4
Query&gt; addentry 4 title 'Spiderman 3' runtime 120 cast 'Kirsten Dunst, Tobey Maguire' LFN 'lfn:/grid/gilda/movies/spiderman.mov'
Query&gt; sequence_next id
&gt;&gt; 5
Query&gt; addentry 5 title 'Pretty Woman' runtime 95 cast 'Julia Roberts, Richard Gere' LFN 'lfn:/grid/gilda/movies/prettywoman.mov'
Query&gt; sequence_next id
&gt;&gt; 6
Query&gt; addentries 6 7 8
Query&gt; dir
&gt;&gt; /gilda/movies/id
&gt;&gt; sequence
&gt;&gt; /gilda/movies/4
&gt;&gt; entry
&gt;&gt; /gilda/movies/5
&gt;&gt; entry
&gt;&gt; /gilda/movies/6
&gt;&gt; entry
&gt;&gt; /gilda/movies/7
&gt;&gt; entry
&gt;&gt; /gilda/movies/8
&gt;&gt; entry
Query&gt; removeentries 7 8
Query&gt; dir
&gt;&gt; /gilda/movies/id
&gt;&gt; sequence
&gt;&gt; /gilda/movies/4
&gt;&gt; entry
&gt;&gt; /gilda/movies/5
&gt;&gt; entry
&gt;&gt; /gilda/movies/6
&gt;&gt; entry
</pre><div class="informaltable">
{| border="1"
|-
| <code class="code">addentries entry1...</code>
| <span class="emphasis">''Adds one or more entries (also across collections)''</span>
|-
| <code class="code">addentry entry [attribute_name value]...</code>
| <span class="emphasis">''Adds one new entry and initializes one or more attributes''</span>
|-
| <code class="code">removeentries entry1...</code>
| <span class="emphasis">''Removes one or more entries (also across collections)''</span>
|-
| <code class="code">rm [-rf] pattern [condition]</code>
| <span class="emphasis">''Removes entries matching pattern/condition''</span>
|}
</div>
There are three more useful commands for handling the value of attributes:
<div class="informaltable">
{| border="1"
|-
| <code class="code">getattr pattern attribute1 attribute2 ...</code>
| <span class="emphasis">'' Returns the values of the attributes for all files matching pattern''</span>
|-
| <code class="code">setattr entry attribute value [attribute value]...</code>
| <span class="emphasis">'' Sets given attributes to specified values for all entries matching entry''</span>
|-
| <code class="code">clearattr entry attribute</code>
| <span class="emphasis">''Sets the attribute to NULL for all entries matching entry pattern.''</span>
|}
</div>
Let's use the previous command to set and get entry attributes'values:
<pre class="response">Query&gt; pwd
&gt;&gt; /gilda/movies/
Query&gt; getattr * title
&gt;&gt; 4
&gt;&gt; Spiderman 3
&gt;&gt; 5
&gt;&gt; Pretty Woman
&gt;&gt; 6
&gt;&gt;
Query&gt; getattr 6 title
&gt;&gt; 6
&gt;&gt;
Query&gt; setattr 6 title 'Armageddon'
Query&gt; setattr 6 runtime 150 cast 'Bruce Willis, Ben Affleck' LFN 'lfn:/grid/gilda/movies/armageddon.mov'
Query&gt; getattr /gilda/movies/ title LFN cast
&gt;&gt; 4
&gt;&gt; Spiderman 3
&gt;&gt; lfn:/grid/gilda/movies/spiderman.mov
&gt;&gt; Kirsten Dunst, Tobey Maguire
&gt;&gt; 5
&gt;&gt; Pretty Woman
&gt;&gt; lfn:/grid/gilda/movies/prettywoman.mov
&gt;&gt; Julia Roberts, Richard Gere
&gt;&gt; 6
&gt;&gt; Armageddon
&gt;&gt; lfn:/grid/gilda/movies/armageddon.mov
&gt;&gt; Bruce Willis, Ben Affleck
</pre></div></div><div class="sect2" title="Querying metadata"><div class="titlepage"><div><div>
=== Querying metadata  ===
</div></div></div>
Finally, after we have created a collection, defined its schema, added entries with their attribute values to it, we can issue a query to get back the information we need.
The most used command to issue queries is <span class="bold">'''<code class="code">selectattr</code>'''</span>. Its syntax is as follows:
<pre class="programlisting">selectattr collection_name:attribute_name... condition
</pre>
which returns the values of given attributes for all files matching the condition where:
<div class="itemizedlist">
*
<code class="code">collection_name</code> specifies the path of the attribute's collection we want to print out. If it's in current collection, the '.' (dot) is mandatory. If more than one attribute will follow and they are in the same collection of the first one, the collection_name can be omitted
*
<code class="code">attribute_name</code> specifies the attribute whose values we want to print out
*
<code class="code">condition</code> specifies a condition on attributes to filter the result set. Logical (and/or/not), comparison, aggregation operators can be used. Joins (inner, outer, left, right) between schemas are allowed. Limit,order,distinct,group are also available. [http://amga.web.cern.ch/amga/queries.html Here] you can find a summary of all the available operators and options. If you don't want to give any condition, use a pair of ''(single quotes).''
</div>
A simpler query command is <span class="bold">'''<code class="code">find</code>'''</span>:
<code class="code">find pattern condition</code>
It returns only the names of the entries that match the pattern and satisfy the condition.
<div class="sect3" title="Some examples of queries:"><div class="titlepage"><div><div>
==== Some examples of queries:  ====
</div></div></div>
To print the titles and the LFNs of all the movies whose runtime is greater than 80 minutes:
<pre class="response">Query&gt; selectattr /gilda/movies:title LFN 'runtime &gt; 80'
&gt;&gt; Spiderman 3
&gt;&gt; lfn:/grid/gilda/movies/spiderman.mov
&gt;&gt; Pretty Woman
&gt;&gt; lfn:/grid/gilda/movies/prettywoman.mov
&gt;&gt; Armageddon
&gt;&gt; lfn:/grid/gilda/movies/armageddon.mov
</pre>
To print the titles and the runtime of the movies where Julia Roberts performed:
<pre class="response">Query&gt; pwd
&gt;&gt; /
Query&gt; cd /gilda/movies
Query&gt; pwd
&gt;&gt; /gilda/movies/
Query&gt; selectattr .:title runtime 'like(cast, "Julia%")'
&gt;&gt; Pretty Woman
&gt;&gt; 95
</pre>
To issue the last query example using find:
<pre class="response">Query&gt; find /gilda/movies/ 'like(cast, "Julia%")'
&gt;&gt; 5
Query&gt; getattr 5 title runtime
&gt;&gt; 5
&gt;&gt; Pretty Woman
&gt;&gt; 95
</pre></div></div><div class="sect2" title="More documentation"><div class="titlepage"><div><div>
=== More documentation  ===
</div></div></div><div class="itemizedlist">
*[http://amga.web.cern.ch/amga/ AMGA homepage]
*[http://amga.web.cern.ch/amga/downloads/amga-manual_1_3_0.pdf AMGA User's and Administrator's Manual(PDF)]
*[https://grid.ct.infn.it/twiki/bin/view/GILDA/AMGAHandsOn From the GILDA Twiki: Metadata - Introduction to AMGA]
*[https://grid.ct.infn.it/twiki/bin/view/GILDA/AMGAAdv From the GILDA Twiki: AMGA Advanced usage]
*[https://grid.ct.infn.it/twiki/bin/view/GILDA/AMGADBaccess From the GILDA Twiki: Accessing pre-existing databases through AMGA]
</div></div>
[[Category:Operations_Manuals]]
[[Category:Operations_Manuals]]

Latest revision as of 17:28, 10 January 2013

Main EGI.eu operations services Support Documentation Tools Activities Performance Technology Catch-all Services Resource Allocation Security


Documentation menu: Home Manuals Procedures Training Other Contact For: VO managers Administrators




<<  EGI User Start Guide


This document has the goal of providing basic information on the usage of the AMGA Metadata Catalog.

Introduction

The AMGA Metadata Catalog is the EGI gLite service that allows metadata handling on the grid. The main usage can be as a "Front-end" file metadata service, providing means of describing and discovering data files required by users and their jobs. It can also be used as a Grid-Enabled Database for applications that require to structure their data, proving a database-like service supporting Grid Security features (X509 Proxies and the VOMS authentication and authorization system). Finally, an additional feature allows the accessing of existing relational databases from a grid environment (Worker Nodes, User Interface, etc), which enables the addition of Grid Security to existing DBs.

Users and applications can interact with an AMGA server using command

   line tools:
  • mdcli/mdclient available for Scientic Linux flavours (they can be built easily to other platforms)
  • mdjavacli/mdjavaclient, the Java versions of the previous one that allows the interaction from any platform

or through APIs, available for:

  • C++
  • Java
  • Python
  • Perl
  • PHP

Some of the mdcli/mdclient command line tools are explained below.

AMGA Metadata Basic Concepts

There are certain fundamental concepts which must be understood when dealing with AMGA

  • Entry - it is the representation of the real world entity which we are attaching metadata to in order to describe it
  • Attribute - key/value pair. It has:
  • Type - The type (int, float, string, etc...)
    • Name/Key - The name of the attribute
    • Value - The value of an entry's attribute
  • Schema - A set of attributes
  • Collection - A set of entries associated with a schema
  • Metadata - The list of attributes (including their values) associated with entries

If we want to make an analogy with the RDBMS world, we have the following:

  • schema = table schema
  • collection = database table
  • attribute = schema column
  • entry = table row/record

By analogy with a file system, we have:

  • collection = directory
  • entry = file

In the AMGA help and documentation, often directory is used to refer to collection, as file refers to entry

Example: Metadata for movies

Movie files (entries) could be saved on Grid Storage Elements and registered into a File Catalogue. We want to add metadata to describe the movie content. A possible schema could be:

  • Title -- varchar
  • Runtime -- int
  • Cast -- varchar
  • LFN -- varchar

We can use the GUID of the file as the entry name.

A collection named movies of an AMGA server could be the repository of the movies' metadata and will allow to find the movies satisfying users' queries.

Accessing AMGA from the command line

To start using AMGA from the command line, you need to use either mdcli or mdclient executables. They have to be installed, together with the required libraries, into a User Interface (and on the Worker Nodes of the sites where you plan to run jobs that will access AMGA). These do not come by default within the standard gLite UserInterface and WorkerNodes packages (on gLite 3.1 they should be available), so you need to install them manually.

You can download RPMs for SLC here:

Once installed, you need to properly configure the configuration file: $HOME/.mdclient.config. A template of this file can be found in $GLITE_INSTALLATION/etc/mdclient.config. This also behaves as a system wide configuration file, useful in a multi-user system (like on Worker Nodes) and it will be read by the AMGA clients if the $HOME/.mdclient.config does not exist.

The relevant values of the mdclient.config are the following:

Host = amga.ct.infn.it
Port = 8822
Login = NULL
PermissionMask = rwx
GroupMask = r-x
Home = /gilda
UseSSL = yes
AuthenticateWithCertificate = 1
UseGridProxy = 1
VerifyServerCert = 0

where

Host defines the AMGA server you want to use. You can use amga.ct.infn.it for the purpose of testing (installed as part of the EGEE GILDA training infrastructure

Port defines the port where the AMGA server daemon is listening. It should not changed

Login defines the credential to be used to authenticated within the AMGA catalog. You can use:

your username, if you have requested one to AMGA server administrator providing him your Grid Certificate Distinguish Name (DN)

or use NULL, to be authenticated as a generic VO user (given the fact that your VO is supported by the AMGA server you are going to use)

The AMGA server in the GILDA training infrastructure supports the following VOs: gilda, eela, eumed, euchina, cometa. Please contact the amga.ct.inf n.it sysadmins (tony.calanducci [at] ct.infn.it) to request support for your VO or to get a personal account. Soon a registration page will be availabe at: https://amga.ct.infn.it:8443/register

Please take a look at the AMGA documentation here for all the available options of the .mdclient.config file.

The options on the previous example were set up to be authenticated as a generic VO user using your Grid Proxy. Be sure to initialize your proxy with the proper command:

-bash-2.05b$ voms-proxy-init --voms gilda
Enter GRID pass phrase:
Your identity: /C=IT/O=GILDA/OU=Personal Certificate/L=INFN Catania/CN=Tony Calanducci/Email=tony.calanducci@ct.infn.it
Creating temporary proxy ............................................................................. Done
Contacting  voms.ct.infn.it:15001 [/C=IT/O=INFN/OU=Host/L=Catania/CN=voms.ct.infn.it] "gilda" Done
Creating proxy ...................................... Done
Your proxy is valid until Sun Feb  3 08:04:46 2008

Once everything has been set up properly, start the AMGA mdclient :

-bash-2.05b$ mdclient
Connecting to amga.ct.infn.it:8822...
ARDA Metadata Server 1.3.0
Query>

This is an interactive shell similar to mysql o psql that allows to issue AMGA commands to the server. The other AMGA executable that comes with the RPM, mdcli, provides the very same functionality, but it executes ONLY one command at time, passed as command line parameter, and immediately exits. This is quite useful in bash script to be run on Worker Nodes that needs to interact with the metadata catalog.

Basic commands

It is possible to get help anytime on the client just using the 'help' command.

Try the help command

Query> help
>> help [topic]
>> Displays help on a command or a topic.
>> Valid topics are: help metadata metadata-optional directory replication constraints entry group acl index schema sequence user view site replicas ticket /
capabilities commands
Query>

Commands are grouped by topic. You can get the list of valid commands for each topic, typing: help [topic]

The list of valid topics is:

help

metadata

metadata-optional

directory

replication

entry

group

acl

index

schema

sequence

user

view

ticket

commands

Try the use of help command with any topic

Query> help entry

mdclient general commands

The following tables gives a brief description of the general use commands.

createdir path [options] Create a new collection. It can inherit (using the inherit option) the schema associated to the upper level collection
rm pattern Remove the entries corresponding to the given pattern
dir collection List the content (entries, subcollections, sequences, indexes) of the given collection
listentries collection List the entries only of the given collection
stat pattern Show the statistics of an entry or collection
chown file owner Change the ownership of an entry or collection
chmod file rights Change the access mode of an entry or collection
rmdir collection Remove a collection
dump collection Make a recursive dump starting from a given collection, (the default is: '/')
pwd Prints the current collection
whoami Prints the current user
cd collection Change the current collection

General commands examples:

Query> whoami

>> gilda

Query> pwd

>> /

Query> cd /gilda

Query> cd tony

Query> pwd

>> /gilda/tony/

Query> dir

>> /gilda/tony/seq2
>> sequence
>> /gilda/tony/seconda
>> collection
>> /gilda/tony/v1
>> collection
>> /gilda/tony/v2
>> collection
>> /gilda/tony/view1
>> view
>> /gilda/tony/aentry
>> entry
>> /gilda/tony/14
>> entry
>> /gilda/tony/15
>> entry
>> /gilda/tony/16
>> entry
>> /gilda/tony/17
>> entry
>> /gilda/tony/18
>> entry
>> /gilda/tony/20
>> entry

Query> listentries

>> /gilda/tony/aentry
>> /gilda/tony/14
>> /gilda/tony/15
>> /gilda/tony/16
>> /gilda/tony/17
>> /gilda/tony/18
>> /gilda/tony/20

Query> cd seconda

Query> dir

>> /gilda/tony/seconda/2
>> entry

Query> rm *

Query> cd ..

Query> pwd

>> /gilda/tony/

Query> rmdir seconda

Handling schemas and attributes

Once a collection has been created, its schema should be defined, adding one or more attributes. As illustrated in the basic concept section, each attribute is defined by its name and its type.

The command to add a new attribute to a collection schema is the following:

addattr dir attribute_name type where:

dir is the collection/directory you are adding the attribute to. You can use relative or absolute path to refer to it.

attribute_name is the name you want to give to the attribute you are adding

type specifies what kind of values the attribute is able to contain

AMGA valid attribute types and their corresponding types used in the internal AMGA back-end are shown in the following table:

AMGA PostgreSQL MySQL Oracle SQLite Python
int integer int number(38) int int
float double precision double precision float float float
varchar(n) character varying(n) character varying(n) varchar2(n) varchar(n) string
timestamp timestamp w/o TZ datetime timestamp(6) unsupported time(unsupported)
text text text long text string
numeric(p,s) numeric(p.s) numeric(p.s) numeric(p.s) numeric(p.s) float

The AMGA server uses internally a relational database to store all the users' metadata. It can use almost any RDBMS that has an ODBC driver. Most of the installations use PostgreSQL and MySQL. If the types indicated in the first column are used to define attributes, metadata can be moved and replicated easily among AMGA servers that use different DB backends. If you don't mind to metadata portability between servers, you can also use all the specific data types of a given DB back-end (we have tried GIS datatypes and Network datatypes of PostgreSQL, for example). To find out which database back-end a given AMGA server is employing, you can use the command backend:

Query> backend
>> PostgreSQL

To remove an attribute from a collection schema, the following command is used:

removeattr dir attribute_name

To inspect the schema of a given collection (or of an entry), use:

listattr dir/entry

Schema population example:

Let's create a movies collection and define its schema, adding the following attributes: title, runtime,

   cast, LFN, to_remove (one of them will be removed):
Query> createdir /gilda/movies
Query> addattr /gilda/movies title varchar(50)
Query> addattr /gilda/movies runtime int
Query> addattr /gilda/movies cast text
Query> addattr /gilda/movies LFN varchar
Query> addattr /gilda/movies to_remove float
Query> listattr /gilda/movies
>> title
>> varchar(50)
>> runtime
>> int
>> cast
>> text
>> LFN
>> varchar
>> to_remove
>> float
Query> cd /gilda/movies
Query> removeattr . to_remove
Query> listattr .
>> title
>> varchar(50)
>> runtime
>> int
>> cast
>> text
>> LFN
>> varchar

Handling entries and metadata

Once the schema of a collection has been defined, it is possible to add new entries. Each entry must have an entry name. You can think of entry names as primary keys of a database table. Entry names are unique. According to your purposes, you could have different options. To mention some examples, GUIDs (Globally Unique Identifiers) could be an option if you are adding metadata to files, the final part of JOB IDs ('/' can't be part of entry names) if you are adding metadata to running jobs, or simply an incremental integer number. You may use any appropriate entry name to better describe your entities. If you want to use an incremental integer as entry name, AMGA sequences can be very useful. You can define one or more sequences for a given collection, but those will not generate by themselves new numbers unless you explicitly request it.

Query> help sequence
>> sequence_create name dir [increment] [start value]
>>   Creates a new sequences with given name in the given directory.
>> sequence_next sequence
>>   Gets the next value from a sequence.
>> sequence_remove sequence
>>   Deletes a sequence.
Query>

Sequence examples

Create a sequence for the movies collection and get the next sequence id:

Query> pwd
>> /gilda/movies/
Query> sequence_create id /gilda/movies
Query> dir
>> /gilda/movies/id
>> sequence
Query> sequence_next /gilda/movies/id
>> 1
Query> sequence_next /gilda/movies/id
>> 2
Query> sequence_next /gilda/movies/id
>> 3

Once decided how to handle entry names, we can actually start adding or removing entries. Four commands are available for that purpose:

addentries entry1... Adds one or more entries (also across collections)
addentry entry [attribute_name value]... Adds one new entry and initializes one or more attributes
removeentries entry1... Removes one or more entries (also across collections)
rm [-rf] pattern [condition] Removes entries matching pattern/condition

Entry creation and deletion examples

Let's add 2 entries with valid attributes and 3 empty entries, then delete the last two:

Query> pwd
>> /gilda/movies/
Query> sequence_next id
>> 4
Query> addentry 4 title 'Spiderman 3' runtime 120 cast 'Kirsten Dunst, Tobey Maguire' LFN 'lfn:/grid/gilda/movies/spiderman.mov'
Query> sequence_next id
>> 5
Query> addentry 5 title 'Pretty Woman' runtime 95 cast 'Julia Roberts, Richard Gere' LFN 'lfn:/grid/gilda/movies/prettywoman.mov'
Query> sequence_next id
>> 6
Query> addentries 6 7 8
Query> dir
>> /gilda/movies/id
>> sequence
>> /gilda/movies/4
>> entry
>> /gilda/movies/5
>> entry
>> /gilda/movies/6
>> entry
>> /gilda/movies/7
>> entry
>> /gilda/movies/8
>> entry
Query> removeentries 7 8
Query> dir
>> /gilda/movies/id
>> sequence
>> /gilda/movies/4
>> entry
>> /gilda/movies/5
>> entry
>> /gilda/movies/6
>> entry
addentries entry1... Adds one or more entries (also across collections)
addentry entry [attribute_name value]... Adds one new entry and initializes one or more attributes
removeentries entry1... Removes one or more entries (also across collections)
rm [-rf] pattern [condition] Removes entries matching pattern/condition

There are three more useful commands for handling the value of attributes:

getattr pattern attribute1 attribute2 ... Returns the values of the attributes for all files matching pattern
setattr entry attribute value [attribute value]... Sets given attributes to specified values for all entries matching entry
clearattr entry attribute Sets the attribute to NULL for all entries matching entry pattern.

Let's use the previous command to set and get entry attributes'values:

Query> pwd
>> /gilda/movies/
Query> getattr * title
>> 4
>> Spiderman 3
>> 5
>> Pretty Woman
>> 6
>>
Query> getattr 6 title
>> 6
>>
Query> setattr 6 title 'Armageddon'
Query> setattr 6 runtime 150 cast 'Bruce Willis, Ben Affleck' LFN 'lfn:/grid/gilda/movies/armageddon.mov'
Query> getattr /gilda/movies/ title LFN cast
>> 4
>> Spiderman 3
>> lfn:/grid/gilda/movies/spiderman.mov
>> Kirsten Dunst, Tobey Maguire
>> 5
>> Pretty Woman
>> lfn:/grid/gilda/movies/prettywoman.mov
>> Julia Roberts, Richard Gere
>> 6
>> Armageddon
>> lfn:/grid/gilda/movies/armageddon.mov
>> Bruce Willis, Ben Affleck

Querying metadata

Finally, after we have created a collection, defined its schema, added entries with their attribute values to it, we can issue a query to get back the information we need.

The most used command to issue queries is selectattr. Its syntax is as follows:

selectattr collection_name:attribute_name... condition

which returns the values of given attributes for all files matching the condition where:

collection_name specifies the path of the attribute's collection we want to print out. If it's in current collection, the '.' (dot) is mandatory. If more than one attribute will follow and they are in the same collection of the first one, the collection_name can be omitted

attribute_name specifies the attribute whose values we want to print out

condition specifies a condition on attributes to filter the result set. Logical (and/or/not), comparison, aggregation operators can be used. Joins (inner, outer, left, right) between schemas are allowed. Limit,order,distinct,group are also available. Here you can find a summary of all the available operators and options. If you don't want to give any condition, use a pair of (single quotes).

A simpler query command is find:

find pattern condition

It returns only the names of the entries that match the pattern and satisfy the condition.

Some examples of queries:

To print the titles and the LFNs of all the movies whose runtime is greater than 80 minutes:

Query> selectattr /gilda/movies:title LFN 'runtime > 80'
>> Spiderman 3
>> lfn:/grid/gilda/movies/spiderman.mov
>> Pretty Woman
>> lfn:/grid/gilda/movies/prettywoman.mov
>> Armageddon
>> lfn:/grid/gilda/movies/armageddon.mov

To print the titles and the runtime of the movies where Julia Roberts performed:

Query> pwd
>> /
Query> cd /gilda/movies
Query> pwd
>> /gilda/movies/
Query> selectattr .:title runtime 'like(cast, "Julia%")'
>> Pretty Woman
>> 95

To issue the last query example using find:

Query> find /gilda/movies/ 'like(cast, "Julia%")'
>> 5
Query> getattr 5 title runtime
>> 5
>> Pretty Woman
>> 95