MIP - How to make a module

Modules are the basic building blocks of MIP. This tutorial will walk through a simple example that can be expanded upon and used as a reference guide to creating your own modules.

Each module is related to the following components:

Package

Each module in MIP is a part of a package. Packages provide a way to “group” related modules and make a prioritization scheme for each “group”. To learn how to create a package please read the how to make a package tutorial.

Parent

Additionally, each module produces information for a parent. The parent / module (child) relationship allows for a heirarchy in producing information.

Parent's Unique ID

By design, MIP supports multiple parents. To distinguish between each parent instance, the module is passed the Parent's Unique ID.

Cluster

Cluster names are used to make relationships and bindings in MIP. This information is used by MIP Integrator and the MIP Producer's. (Note: Clusters are actually related to Packages, but each module is a part of a package, so naturally modules are associated with Clusters) For a more in depth explanation of the Cluster name abstraction and their use please review the how to make a package tutorial.

Additionally MIP uses the following variables to reference locations: (these variables are located in the $configdir/source.pl file)

$mipdir

This is the directory with the 'mip' executable. (and supporting perl files)

$configdir

This directory contains the configuration files for mip and its packages.

$moduledir

This directory contains the installed modules and packages for mip.

What exactly is a module? Essentially a MIP module is an executable program that can accept 3 parameters in the following order:

./module-name "$cluster" "$uid" "$configdir"
  • “$cluster” is the Cluster name abstraction that the module is producing information for.
  • “$uid” is the Parent's Unique ID.
  • “$configdir” is MIP's $configdir directory.

This is to allow access to the package configuration file or MIP's configuration file.

Modules don't necessarily need to use all 3 parameters, but the information is available just in case. In addition, modules are placed in a specific location in the MIP infrastructure:

$moduledir/"Package Name"/"Parent"/"module-name"
  • “$moduledir” is MIP's $moduledir directory found in $configdir/source.pl.
  • “Package Name” is the name of the package the module is a part of.
  • “Parent” is the name of the parent the module is associated with.
  • “module-name” is the module executable.

Below is a simple example to expand upon. This example is written in perl, but any language can be used.

Assume there is a package named “Site” that has a Parent named “ComputingElement”. Let us name our module “Example.pl”. We will place our module in the following location:

$moduledir/Site/ComputingElement/Example.pl

Our example module needs to collect and output the following information:

  • Name - Name of the Computing Element
  • HostName - Fully Qualified Domain Name (FQDN) of the Computing Element
  • GateKeeperPort - Port the GateKeeper is running on

We will start with “Name”. Assume the Name of the Computing Element is the same as the Unique ID of the Computing Element. Remember from above: The Parents Unique ID is the second command-line argument passed to the module. So the start of the script will look like this:

#!/usr/bin/perl -w
use strict;

my $clustername=$ARGV[0]; # Get cluster name
my $parentuid=$ARGV[1];   # Get Parent Unique ID
my $configdir=$ARGV[2];   # Get MIP configuration directory

print "<Name>$parentuid</Name>\n";

Next we will get the “HostName” or the FQDN of the Computing Element. Add to the script these following lines:

use Sys::Hostname; # Perl library to get hostname
my $hostname=hostname(); # Function to get hostname
print "<HostName>$hostname</HostName>\n";

Lastly we will get the GateKeeperPort. Let us say the port number is in the package's configuration file, which is also written in perl. Assume the example configuration file is named “example-conf.pl” and is located in the $configdir. It contains the following information:

ConfigInfo      => 'Some configuration information',
GateKeeperPort  => 2119,
MoreInfo        => 'More configuration information',

To extract the last part of information we will add the last snippit of code. Keeping in mind that $configdir is passed as the third command-line argument to each module.

my %config=do "$configdir/example-conf.pl"; # Read the configuration file into a hash
my $GateKeeperPort=$config{GateKeeperPort}; # Retrieve the information from the hash
print "<GateKeeperPort>$GateKeeperPort</GateKeeperPort>\n";

Now that all the information has been collected and output our module is complete. Below the code for the example module has been combined for your convenience.

#!/usr/bin/perl -w
use Sys::Hostname; # Perl library to get hostname
use strict;

my $clustername=$ARGV[0]; # Get cluster name
my $parentuid=$ARGV[1];   # Get Parent Unique ID
my $configdir=$ARGV[2];   # Get MIP configuration directory

my $hostname=hostname(); # Function to get hostname

my %config=do "$configdir/example-conf.pl"; # Read the configuration file into a hash
my $GateKeeperPort=$config{GateKeeperPort}; # Retrieve the information from the hash

print "<GateKeeperPort>$GateKeeperPort</GateKeeperPort>\n";
print "<Name>$parentuid</Name>\n";
print "<HostName>$hostname</HostName>\n";

For more information please follow the Instructions and How to link.