This wiki is obsolete, see the NorduGrid web pages for up to date information.

ARC Compute Clients/Java examples

From NorduGrid
Jump to navigationJump to search

The following page contains examples on how to write Java programs interfacing the libarcclient to do submission and management of jobs. The examples are specifically for use with ARC release 11.05.

When compiling and running the classpath should at least contain the path to the JAR archive containing the Java classes used to interface the language bindings, e.g. $ARC_LOCATION/lib/java/arc.jar. When running the programs, the directory containing the language bindings in form of a library should be specified. This can be done by setting either the library path environment variable (Linux: LD_LIBRARY_PATH, Windows: PATH, Mac OS X: DYLD_LIBRARY_PATH), or the java.library.path system property. The library is normally located in the $ARC_LOCATION/lib/java directory.

Job submission

The code example below shows how to submit a "Hello World" job to a specified Computing Element.

import nordugrid.arc.*;

public class arcsub
  public static void main(String[] args)

    // Setup logging.
    // Possible log-levels: FATAL, ERROR, WARNING, INFO, VERBOSE and DEBUG.
    new Logger(Logger.getRootLogger(), "arcsub");
    Logger.getRootLogger().addDestination(new LogStream_ostream(arc.getStdout()));

    // Initialise the UserConfig object.
    // This object holds various attributes, including proxy location and selected services.
    UserConfig usercfg = new UserConfig("");

    // Convert the commandline arguments to a StringList object.
    StringList clusters = new StringList();
    for (int i = 0; i < args.length; i++) {

     * Clear selected services. Default services might have been set from loading the system
     * user configuration file ($ARC_LOCATION/etc/arc/client.conf) or the user configuration
     * file ($HOME/~arc/client.conf).
    // Set the selected services, e.g. the arguments specified on the command line.
    // A information service can also be added (ServiceType.INDEX).
    usercfg.AddServices(clusters, ServiceType.COMPUTING);

    // Initialise TargetGenerator object.
    TargetGenerator targen = new TargetGenerator(usercfg);
    // Fetch information about services and create ExecutionTargets from these (CEs).
    targen.GetTargets(0, 1);

    // Create job description.
    // Set the executable.
    ExecutableType exe = new ExecutableType();

    // Set arguments to the executable.
    StringList arguments = new StringList();
    arguments.add("Hello World");

    ApplicationType app = new ApplicationType();
    // Set standard output file.

    JobDescription job = new JobDescription();
    // Job description created.

    // Print job description in XRSL format to screen.
    // Supported formats: XRSL, ARCJSDL, JDL.

    // Get list of collected targets.
    ExecutionTargetList targets = targen.FoundTargets();

    // Loop over targets.
    for (ExecutionTargetListIteratorHandler it = new ExecutionTargetListIteratorHandler(targets.begin());
         !it.equal(targets.end()); {
      // Get submitter object from target.
      Submitter submitter = it.pointer().GetSubmitter(usercfg);
      // Try to submitting to target.
      URL submitted = submitter.Submit(job, it.pointer());

      if (submitted.toBool()) {
        // If successful write job id.
      else {
        System.out.println("Unable to submit to " + it.pointer().getUrl());

The class should be used as follows:

$ java arcsub ARC0:ldap://,Mds-vo-name=local,o=grid

which submits a hello world job to the Grid-Manager at
Note that it is the information endpoint which should be specified. For submission to:

  • Grid-Manager use ARC0 prefix,
  • A-REX use ARC1 prefix,
  • CREAM use CREAM prefix,
  • UNICORE use UNICORE prefix.