In this tutorial, we will create a CycleServer plugin from scratch that allow us to submit custom Condor jobs directly from CycleServer. This will be done in two steps:

  1. Create a custom HTML form that integrates directly into CycleServer’s Submit Jobs page
  2. Create a custom Python script that processes data from that form and submits a job to Condor

Prerequisites

This tutorial assumes that you have CycleServer installed and running, and that you have read and write access to CycleServer’s install directory.

You will also need to have a basic working knowledge of HTML, JavaScript and Python.

Directory Layout

All CycleServer plugins are stored under the plugins/ directory in CycleServer’s base install directory (link to more info). For this tutorial, we will store our plugins under the directory tutorial/simple_submit.

By the end of this tutorial, we will have created the following directory structure:

plugins/
tutorial/
simple_submit/
submit.cfg
submit.py
ui.cfg
ui/
plugin.html

Submit Job Form

In this section, we will create a new form that shows up as a new tab under CycleServer’s Submit
Jobs
page.

HTML Form:

First, we need to create a new HTML file named plugin.html in the directory tutorial/simple_submit/ui containing the following text:

<div>
  <h2>Please enter your Condor submit description below:</h2>
  <form method="POST" enctype="multipart/form-data"
      action="/tutorial/simple_submit/submit" id="simple_submit"
      onsubmit="return validateInput(this);">

      <textarea name="submit_desc" rows="10" cols="50" id="submit_desc">
      executable = /path/to/hello.sh
      universe = vanilla
      transfer_files  = ALWAYS
      queue
      </textarea>
      <div class="button-row">
          <input id="submitButton" type="submit" value="Submit" class="button" />
      </div>
  </form>
  <script type="text/javascript">
  <!--
  function validateInput(form) {
    // Validate submit description
    if (document.getElementById("submit_desc").text == "") {
      alert("Please enter a submit description");
      return false;
    }
    // All OK
    return true;
  }
  -->
  </script>
</div>

This file contains the HTML and JavaScript code that lets users enter the text of the Condor submit description and then POST``s it to the plugin ``tutorial.simple_submit.submit.

Configuration File:

Next, we need to create the configuration file for the HTML form above, so CycleServer knows to insert it inside a new tab on the Submit Jobs page.

In the directory tutorial/simple_submit, create a file named ui.cfg containing the following text:

WebContent=static
PluginType=condor.submit.submission_type
Description=Form for submitting a Condor job
DisplayOrder=2000
DisplayName=Simple Submit
  • The WebContent property instructs CycleServer to treat the contents of the ui directory as
    static files served up over HTTP.
  • The PluginType causes CycleServer to look for a file named plugin.html in the ui
    subdirectory and insert it as a new tab on the Submit Jobs page.
  • The DisplayOrder property determines what order the tabs should appear in.
  • The DisplayName property determines the title of the tab.

Job Submission

We now need to write the plugin that will handle the POST from the form above and submit a new job to Condor.

Python Script

In the directory tutorial/simple_submit, create a file named submit.py containing the following text:

from application import logger
from condor import submit

def post(request, response):
  contents = request.parameter("submit_desc")
  # Create the ID used for the submission
  id = submit.createNewId()
  # create the submission object and initialize it
  sub = submit.Submission(contents, id)
  sub.description = "Simple submit tutorial"
  # get the pool/group parameters
  targets = submit.getTargets()
  if targets and len(targets) > 0:
      sub.poolId = int(targets[0]["pool"].getAsString("id"))
      sub.group = targets[0]["group"].getAsString("name")
  # submit to CycleServer
  logger.info("Submitting job %s" % str(id))
  sub.submit()
  # Success, redirect to jobs page
  logger.info("Job submitted successfully")
  response.redirect("/jobs/job_summary.s?scope=user")

Configuration File:

In the directory tutorial/simple_submit, create a file named submit.cfg containing the following text:

WebContent=dynamic

The first line instructs CycleServer to treat the contents of the corresponding file submit.py as an executable script.

You can now submit an arbitrary job by navigating to the Submit Jobs page, selecting the Simple
Submit
tab, entering your submit description and clicking on the Submit button.