Installing and Configuring LDDTool

From The SBN Wiki
Revision as of 15:29, 19 January 2017 by Raugh (talk | contribs) (→‎Part List)
Jump to navigation Jump to search

LDDTool is the Java-based tool that takes an input XML document (using the <Ingest_LDD> structure foudn in the PDS4 master schema) and converts it into the various types of structured files used to define, document, and use a local data dictionary in PDS4 labels. This tool is available from the PDS4 software page, https://pds.nasa.gov/pds4/software/index.shtml, under the title "Local Data Dictionary Tool".

These pages are in the process of being updated for the latest release. Note well the problem indicated under Testing the Installation - this is where the updating had to pause until the testing problems mentioned there could be solved.

Update for tool version 7.0.1: Begun 2017-01-18, A. Raugh


Introduction

A local data dictionary is a set of schema files that define a namespace that is under the control of someone other than the PDS4 managers. It includes the PDS discipline dictionaries for things like display orientation and geometry, as well as node- and mission-specific dictionaries. There are web-based and GUI-based tools in development at various places to help users who prefer to do dictionary development in an web/GUI environment - ask your friendly, neighborhood PDS node consultant what's currently available if that's what you're looking for. These pages are for the roll-your-own crowd that either prefers or has no choice but to work at the command line and see how the sausage is made.

Caveat Usor

Be advised: There is a fair amount of hands-on setup work required to get the LDDTool working in your local environment the way you want it to. And because this tool is updated for each new model release and to accomodate the sometimes complex needs of the discipline dictionaries still in development, you may well have to repeat this process with some variations with each new release. We'll try to keep this page updated to reflect the latest version of the tool. Feel free to add additional information about LDDTool versions or OS versions not specifically mentioned here. Contact Anne Raugh at the Small Bodies Node for permission to edit this Wiki if you don't have it already. Thanks!


Goal

Our goal in this set of pages is to start with the LDDTool installation package and end up with the tool installed for general use on the target system. "General use" in this case means you can invoke the tool in any directory where you happen to be working with a command line that looks something like this:

    % lddtool -lp <input_file>

Part List

To run the LDDTool locally, you'll need the following:

  • Java 1.6 or later. Type "java -version" at your command line to see what version of Java, if any, you have available. If you don't have Java installed, or want to work with a later version, you'll usually need administrator privileges on your computer to download and install a newer version from the Oracle web site https://java.com/download. Java 1.7 and later includes a handy feature that will help with configuration later on, so if you're still running a (relatively) ancient version, you now have one more reason to upgrade.
  • A text editor that can handle simple text files for batch processing without filling them up with stupid control characters. On linux-based systems, things like vi, pico, or gedit will work; from the Windows DOS command line, you can use the edit command on older systems (pre-Windows7), or Notepad (which can be invoked from the Windows command line as notepad) on newer ones.
  • An XML editor, while optional, will make editing the output schema files easier, and you'll probably want one for creating the input file anyway. A schema-aware editor like Eclipse (open source) or oXygen (commercial) can be very handy for one-off file creation and editing. For the minor fix-up editing needed in the LDDTool output schemas, though, you can use the same simple text editor you used to edit the batch file or command wrapper.

General Procedure

Here's the general procedure for setting up the tool:

  1. Unzip the LDDTool package.
  2. Move the directories you actually need to run the tool to a permanent location.
  3. Edit the wrapper script for the local environment.
  4. Install the wrapper script.
  5. Test the installation with the supplied sample files.
  6. Rejoice in the knowledge of a job well done.

Procedure

Unzip the LDDTool Package

Use any standard ZIP tool (unzip on linux-based systems; the Extract All option in Windows Explorer) to extract the files from the ZIP package. For the tar file, use the z option to uncompress while you extract. You should end up with a directory with a name that starts with lddtool- and ends with the version number of the tool. As of this writing, the latest version of the tool is 7.0.1, so the delivery package unpacks into a directory call lddtool-7.0.1. On a Windows system, by default this directory will be underneath a directory with the same name as the ZIP package, less the ".zip" extension. You can unpack it anywhere - we'll move the stuff we need to a new home once we've picked one out. If you haven't inspected previous LDDTool delivery packages, you should probably take a few minutes to familiarize yourself with the contents.

Here's what you'll find in the unpacked directory:

Executables

The executable elements of the package include:

bin/
You'll actually only need one of the files from this directory, but you'll have to carry the directory along nonetheless. We'll be modifying one of these scripts to work on your local system, and then installing just that modified file into an LDDTool-specific bin/ directory.
The runapp/ subdirectory contains some batch files that, depending on your system, could be used to run the tool on some of the example input files provided.
Data/
At least one of these files is referenced directly by the LDDTool java code, so it needs to be present.
lib/
This directory contains only the DMDocument.jar jar file, which contains the actual Java code.

Documentation

The doc subdirectory contains an HTML directory tree. Point your browser to the index.html file to see it in its intended format. There are brief summary instructions for installation and usage in the nominal case.

Examples

This directory contains sets of input/output files produced by LDDTool. They are undocumented, but at least if you run the usual lddtool -lp command on the IngestLDDTool_*.xml you should get output very similar to the file set here. We'll use one of these for testing the installation. Apart from that, they may be useful examples for how to code some of the more specific, more complex behaviour found in the more intricate discipline dictionaries.

Peanuts

Like packing peanuts, these files are included in the ZIP but are not, as far as I have found, particularly useful once the package is opened:

  • LICENSE.txt: Standard boilerplate license (JPL employees produced this code, and JPL is part of the California Institute of Technology)
  • README.txt: This file just directs you to the doc/index.html file.
  • runapp.bat: A Windows-style batch file that demonstrates how to invoke an executable in the bin directory for the sample file IngestLDDTool.xml. It will not run out of the box - you must configure the lddtool.bat file it invokes first, and then make this file executable. It is not generally configurable as is because input and output file names are hard-coded.
  • Schemas/: This directory contains copies of the last few releases of schema files for the core PDS4 namespace. I'm not sure why it's here; the tool seems to run fine if this directory is expunged. Could be handy if you don't already have a schema tree but want to use a schema-aware editor to create your LDDTool input file.

Install the Executable and Support Directories

Unless you're seriously hardcore, you will be running LDDTool by invoking a wrapper script (or batch file). This script sets up some environment variables and then calls Java with the appropriate options and arguments to invoke the DMDocument.jar file with the options and arguments passed on from the wrapper script.

Note: The classes in the DMDocument.jar file read all the environment variables set by the wrapper script/batch file, and also contain hard-coded references to the Data subdirectory in the installation tree. So wherever you install LDDTool, you're going to need to preserve the delivery tree structure for the bin/, lib/, and Data/ subdirectories - and the wrapper script must be physically located in that bin/ directory.

Choosing an Installation Location

On linux-based multi-user systems, you can install LDDTool for general use by all users either by installing into one of the standard locations (/usr/share, for example), or in shared disk space. If the latter, users wanting to execute LDDTool will likely have to add the appropriate location to their $PATH setting. Alternately, you can install it into your own ~/bin/ directory for personal use. Note that if you haven't created or used a personal ~/bin/ directory before, you may have to add it to your $PATH to use it.

In any event, on a linux-based system you will ultimately have to choose one of these options:

  1. Add the lddtool-[version]/bin directory to your $PATH; which requires editing your shell resource file; or
  2. Create a link to lddtool-[version]/bin/lddtool in a directory already in your $PATH, which requires an additional edit to the lddtool wrapper script; or
  3. Type the full, absolute path to the lddtool script every time you want to run it.


On Windows systems, you can install LDDTool into the "Program Files\" directory for general use (this may require admin privileges), or in your own directory space for personal use. You will likely have to modify %PATH% setting information to make the lddtool.bat executable visible to users without requiring a complete path specification to run the batch file. More on that later.

What to Copy/Move

Create a directory in your chosen installation location to hold the LDDTool tree. You can name this lddtool, or include a version number, or rename it anything convenient. The name of this directory is not significant to the code.

Under this directory, copy over the entire contents of the lib/ and Data/ directories from the installation package. You will also need to create a bin/ directory, into which you should copy either the lddtool linux script or the lddtool.bat Windows batch file, as appropriate for your environment. For linux users, you will likely also have to make the lddtool script executable.

At this point you may also want to copy over the contents of the doc/ directory, for easy reference. I also copy the AAREADME.TXT file from the root of the install package into this directory, just in case I want to find it again later.

Edit the Wrapper Script/Batch File

The lddtool script (linux) or lddtool.bat file (Windows) is used to run the tool. This file will need to be edited to conform to the installation environment. Any simple text editor can do the job.

The first line you'll need to change is the one that contains the definition of the JAVA_HOME environment variable. Finding the right value for and then setting this variable can be difficult, especially for folks who are not Java programmers. Since you'll need to do this a lot for other PDS-provided PDS4 tools, we've put the info into a separate page for consistent referencing:

Linux users note: The lddtool wrapper script is written to be run in the Bourne shell, so use Bourne shell syntax to set JAVA_HOME in the script, regardless of what your login shell is.

At this point, Windows users should be done.

If you are working on a linux-based system and are planning to add the lddtool-[version]/bin directory to your $PATH, make the lddtool file executable and you're done.

That just leaves linux-based folks who want to add lddtool to an existing bin/ directory. A few more steps are involved, here:

  1. You'll need to edit one additional line in the lddtool wrapper - the line beginning "export PARENT_DIR" (line 34 in the current distribution). Replace the back ticks (`) and everything inside them with the absolute path to the LDDTool installation directory (without ticks or quotes).
  2. Make the lddtool wrapper executable.
  3. Create a link in the existing bin/ directory to the lddtool wrapper executable.

And now you're done as well.

Once you have had some experience with running LDDTool and tried out some of the other options available (see the "Operations" document supplied in the ZIP package), you may want to further modify the script or batch file to automatically include certain options, provide a standard output file redirect, and otherwise customize tool behaviour. Knock yourself out.

Install the Wrapper Script/Batch File

The first step for installing the wrapper is a simple matter of copying to the installation bin/ directory (if it isn't there already). On linux-based systems, you will also likely have to change the script permissions to make it executable by those allowed to execute it.

You can, of course, always execute the script/batch file by using its full, absolute path on the command line. For ease of use, though, most people prefer to have their executables available in their path. Unfortunately, because of the hard-coded references in the LDDTool code, you can't just copy the script or batch file into a directory already in your path. But you can add the LDDTool bin/ directory to your path, or in linux-based systems you have the option of defining an alias to the physical location in an existing path directory.

Setting Windows %PATH%

If you only want to add the lddtool.bat location to your path temporarily, say for testing, you can enter something like this at the command prompt:

    C:>set PATH=%PATH%;C:\Users\LDDTool\bin

where C:\Users\LDDTool\bin should be replaced with whatever the full path is to your LDDTool bin/ directory. This appends the path you provide to the current value of the %PATH% variable.


If you'd like to add the LDDTool path to your default PATH once and for all, you can follow the instructions on this page for your particular flavor of Windows:


Setting Linux-based $PATH

The method used for adding a directory to your current PATH varies based on the shell you use. The Bourne shell requires an assignment followed by an export command to make the new path visible to programs you run:

   % PATH=$PATH:/usr/share/LDDTool/bin
   % export PATH

or this shortcut should also work:

   % export PATH=$PATH:/usr/share/LDDTool/bin

where /usr/share/LDDTool/bin is replaced with the full path to the LDDTool installation tree bin/ directory.

For C-shell and related shells, use a setenv command:

   % setenv PATH $PATH":/usr/share/LDDTool/bin"

or the set command:

  % set PATH=($PATH /usr/share/LDDTool/bin)

For either type of shell, you can do this at the command line before beginning your work with LDDTool, or you can add the lines to your shell resource file so it's already there every time you log on.

If you don't know what any of this means, it is time to seek out your friendly, neighborhood Linux programmer and ask, or try Googling "Setting environment variables" for your particular operating system.

Linux Alternative to Extending $PATH: Links

So far, at least, as long as the lddtool script is physically located in the LDDTool installation tree as described previously, you can create a link to the script from some more convenient place so that you don't have to modify your $PATH just to run lddtool. You'll need to have write permission to some directory already in your path. You can do this in your own ~/bin/ directory, for example (assuming it's already in your path).

To do this, simply create a link to the lddtool script from the directory already in your path. Say, for example, that the LDDTool tree is in your home directory and is called LDDTool:

   % ls ~/LDDTool
   bin            Data           doc            lib

Create a link to the ~/LDDTool/bin/lddtool file in the ~/bin/ directory thus:

   % cd ~/bin
   % ln ~/LDDtool/bin/lddtool


If you want to start using lddtool immediately in the same shell window, you will have to source your shell resource file to force it to re-read your path contents. Apart from that rare circumstance, lddtool should be in your path every time you start a new shell from now on.

A similar method can be employed (by users with sufficient privileges) to create a link in an existing system bin/ directory for general use.


Mac Users Note

Mac users should be aware of a minor but possibly annoying detail when defining aliases. The Mac flavor of Linux, while allowing mixed-case file names, does not consider case significant when comparing file names. So if, for example, you decided to install LDDTool into ~/bin/LDDTool, and then tried to create a link called "lddtool" to ~/bin/LDDtool/bin/lddtool in the same directory, you'd get an error message telling you a file by that name already exists.

To get around this you can, of course, move the LDDTool tree; or you can give the link a different name using the second argument to the "ln" command:

   % ln ~/bin/LDDTool/bin/lddtool makeldd

Now to invoke the lddtool script, you would use the makeldd alias, e.g.:

   % makeldd -lp IngestLDDtool.xml

I haven't actually tested whether or not you can rename the LDDTool directory itself. If you do try that and have anything to report, let me know...

Test the Installation

Once you think you've got the LDDTool executables tucked into their homes, you should test the installation and configuration. Fortunately, the sample files provided in the ZIP package work well for performing a basic aliveness test.

Running LDDTool on the Sample File

NOTE: The following instructions won't work. The file referenced is no longer included in the delivery package, and the provided examples do not appear to be reproducible using the current version of the executable. I will gin up a simple example file to use for testing and post it here. Watch this space.

In the top level directory of the package you'll see a file called IngestLDDTool.xml, along with a bunch of other files with similar, but longer, names and a variety of extensions. These were all output as a result of running lddtool on the IngestLDDTool.xml file. You should probably save these files for comparison to the ones you're about to create, especially if you're not familiar with the usual output from lddtool, which is fairly verbose and contains debug information (beta-test code, remember).

If you've got the executables, paths, and any aliases properly set up, then you should be able to copy the IngestLDDTool.xml file anywhere, with any name (that ends in ".xml") and still run this test.

The basic command line, in either linux or Windows, to reproduce the files included in the ZIP package is this:

   lddtool -lp IngestLDDTool.xml > list.txt

(If you've renamed things then of course use the names you've created, not the names above.) This command redirects the rather long listing produced even by successful runs into the "list.txt" file. You can omit this, if you like, in which case the messages will be dumped to the screen; or you can give a different file name. The output files will be written into the current working directory, so linux users make sure you have write permission in that directory before running the test.

Expected Results

The example lddtool command, above, will generate a total of six output files in addition to the list.txt output. The file names for five of them are created by taking the input file name and appending namespace and version identifiers found inside the IngestLDDTool.xml file. The file names will all be the same, but will have different extensions. Here are those extensions, in approximate order of usefulness:

  • .xsd: This is the XML Schema file that you will reference in your labels when you want to use classes from this dictionary.
  • .sch: This is the Schematron file that you will also reference in your labels when you want to use classes from this dictionary.
  • .csv: This is a CSV-formatted summary of the dictionary contents. You might find this a useful way to review the results if you're averse to reading schema and don't have labels already written to exercise the newly-produced schemas. You might also find this to be a useful file for passing to reviewers who want to see class and attribute definitions - though maybe with a little editing first.
  • .xml: This is a label for the XML Schema and Schematron files; probably only useful as a template. SBN strongly recommends that rather than creating a label from scratch each time, you modify an existing label at reasonable intervals in order to maintain a <Modification_History> within the label that accurately reflects the development history of the dictionary (as any other product label should for an archival product). At the very least, the schema label should be modified to identify the unique origin and application of the dictionary files it describes. Trying to get the unmodified label produced here through an SBN review is unlikely to be successful.
  • .txt: A detailed listing of program settings, messages, and dictionary content. Might be useful for debugging subtle definition issues. In general, SBN recommends you avoid subtlety in dictionary definitions.
  • PDS4SchematronRules.pins: Some sort of encoding of PDS4 Schematron rules into a structured text file. No idea why this is generated or what it might be used for.

Checking for Success

Unfortunately, there is no big, friendly, "You Succeeded!" (or "Thanks for trying!") message when the program completes.

The first thing to check is the program output listing. The last line of the "list.txt" file, or the last line on your screen if you didn't redirect output, should be this:

   >>info    - LDDTOOL Exit

This indicates at least some measure of success. The file will contain a LOT (several hundred lines) of warning messages about various override conditions. This is normal. It should not contain any error messages (lines beginning with ">>error"). These indicate some sort of failure.

At this point linux-based users can make good use of diff to check for any substantive variation between the files just produced and those that came in the ZIP package. If they are identical +/- date- and system-specific notations, then you can consider the test a success. Windows users without software with a "diff" feature can check file sizes and eyeball the contents in any plain text editor (NotePad or WordPad will work in a pinch).

Once you've verified expected output, you should be ready to run lddtool on you own input files.

Common Failures

The common failures encountered at this point come from system references not resolving. Here are the most likely suspects:

Cannot find DMDocument jar file in [some directory]

This error is reported back to the command line by the lddtool wrapper, which checks for the existence of the DMDocument.jar file before invoking java on it. If you haven't previously set PARENT_DIR in the wrapper to point to the LDDTool installation directory, do so (in some environments this may be required even if you're using the default configuration). If you have already modified PARENT_DIR, search it for typos. The PARENT_DIR directory must contain a lib/ subdirectory, which in turn must contain the DMDocument.jar file.
You'll also get this message if there is a typo in the lib/ subdirectory name or DMDocument.jar name (case counts).

>>error - Required data file was not found: [some path to an XML file]

This will show up as the last line in your listing if you forgot to include the Data/ subdirectory of the LDDTool distribution in your installation LDDTool directory tree. Spelling and case count, so if you're on a linux-based system and accidentally changed "Data" to "data", for example, you'll get this message.

/bin/java: No such file or directory (This is the linux version of this error)

Messages like this are reported to the command line and indicate that the JAVA_HOME setting either failed or points to the wrong place. If there's a typo in the JAVA_HOME setting, you might also see characters before "/bin/java" indicating what the script thinks JAVA_HOME was set to. The JAVA_HOME directory must contain a bin/ subdirectory, which in turn must contain the java executable.

[usage info dump]

If you get a dump of lddtool usage information when you run the test command on the example file, look at the very top - there's probably an error waiting for you. Make sure you spelled the input file name correctly and included the required "-lp" option set.

Rejoice