Changeset 3992


Ignore:
Timestamp:
Nov 22, 2007, 2:19:37 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #728: jobagent.sh should accept command status

Also made the jobagent log into it's own file (jobagent.log) instead of stdout

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/log4j.properties

    r3532 r3992  
    1616log4j.appender.migfile.layout=org.apache.log4j.PatternLayout
    1717log4j.appender.migfile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
     18
     19### Job agent log is written to jobagent.log in working directory ###
     20log4j.appender.jobagent=org.apache.log4j.FileAppender
     21log4j.appender.jobagent.File=jobagent.log
     22log4j.appender.jobagent.layout=org.apache.log4j.PatternLayout
     23log4j.appender.jobagent.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    1824
    1925### set log levels - for more verbose logging change 'info' to 'debug' ###
     
    5763# Job agent loggers
    5864# -----------------
    59 log4j.logger.net.sf.basedb.clients.jobagent=warn
     65log4j.logger.net.sf.basedb.clients.jobagent=warn, jobagent
    6066
    6167# -----------------
  • trunk/doc/src/docbook/admindoc/installation_upgrade.xml

    r3917 r3992  
    378378                agents to log on to BASE. The account is disabled by
    379379                default and must be enabled. Enable the account and
    380                 set a password. This password is set in the
     380                set a password using the BASE web interface.
     381                The same password must also be set in the
    381382                <filename>jobagent.properties</filename> file, see
    382383                item
     
    475476                  <listitem>
    476477                    <para>
    477                       <command>userfile</command>: The path to the
     478                      <command>userfiles</command>: The path to the
    478479                      directory where user files are located. This
    479480                      directory must be accessible from all job
  • trunk/doc/src/docbook/appendix/jobagent.sh.xml

    r3679 r3992  
    6565         
    6666          The default value is <filename>jobagent.properties</filename>.
     67          The classpath is not searched which means that it doesn't find
     68          the configuration file in <filename>&lt;base-dir&gt;/www/WEB-INF/classes/</filename>
     69          unless you specify the path to it.
    6770          See <xref linkend="appendix.jobagent.properties" />
    6871          for more information about job agent configuration files.
     
    150153      </listitem>
    151154    </varlistentry>
     155   
     156    <varlistentry>
     157      <term><command>status</command></term>
     158      <listitem>
     159        <para>
     160          Similar to the <command>info</command> command but with less output.
     161          The output is either <computeroutput>Running, Pauses or Stopped</computeroutput>.
     162          In case of an unexpected error, an error message may be displayed instead.
     163        </para>
     164      </listitem>
     165    </varlistentry>
    152166
    153167    <varlistentry>
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/Agent.java

    r3675 r3992  
    210210  public static final int DEFAULT_CHECK_INTERVAL = 30;
    211211 
     212  static
     213  {
     214    org.apache.log4j.LogManager.getLogger("net.sf.basedb.clients.jobagent").setAdditivity(false);
     215  }
     216 
    212217  /**
    213218    Log job agent events.
     
    548553    if (!isRunning)
    549554    {
    550       isRunning = true;
     555      // Start BASE application and login
     556      SessionControl sc = getSessionControl();;
     557      // Create executor and job queue checker
    551558      jobExecutor = createJobExecutor();
    552559      jobQueueChecker = createJobQueueChecker();
    553      
    554       // Start the BASE application in a new thread so we can return quickly
    555       Thread t = new Thread(
    556         new Runnable()
    557         {
    558           public void run()
    559           {
    560             SessionControl sc = null;
    561             try
    562             {
    563               sc = getSessionControl();
    564             }
    565             catch (Throwable t)
    566             {}
    567             if (sc == null || !sc.isLoggedIn())
    568             {
    569               stop();
    570             }
    571           }
    572         }
    573       );
    574       t.start();
     560      isRunning = true;
    575561    }
    576562  }
     
    703689  public SessionControl getSessionControl()
    704690  {
    705     try
    706     {
    707       if (sc == null)
    708       {
    709         log.info("Starting BASE application");
    710         Application.start(false);
    711         sc = Application.newSessionControl("net.sf.basedb.clients.jobagent",
    712           SocketUtil.getLocalHost().toString(), null);
    713       }
    714       if (!sc.isLoggedIn())
    715       {
    716         log.info("Logging in as user: " + login);
    717         sc.login(login, password, "Job agent running on host " + getServerName(), false);
    718       }
    719     }
    720     catch (Throwable t)
    721     {
    722       log.error(t.getMessage(), t);
     691    if (sc == null)
     692    {
     693      log.info("Starting BASE application");
     694      Application.start(false);
     695      sc = Application.newSessionControl("net.sf.basedb.clients.jobagent",
     696        SocketUtil.getLocalHost().toString(), null);
     697    }
     698    if (!sc.isLoggedIn())
     699    {
     700      log.info("Logging in as user: " + login);
     701      sc.login(login, password, "Job agent running on host " + getServerName(), false);
    723702    }
    724703    return sc;
     
    905884      executor.init(this);
    906885    }
    907     catch (Throwable t)
     886    catch (RuntimeException t)
    908887    {
    909888      log.error("Could not create job executor instance: " + executorClass.getName(), t);
    910889      executor = null;
     890      throw t;
     891    }
     892    catch (Exception e)
     893    {
     894      log.error("Could not create job executor instance: " + executorClass.getName(), e);
     895      executor = null;
     896      throw new RuntimeException(e);
    911897    }
    912898    return executor;
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/AgentController.java

    r3675 r3992  
    5151public class AgentController
    5252{
    53 
     53  static
     54  {
     55    org.apache.log4j.LogManager.getLogger("net.sf.basedb.clients.jobagent").setAdditivity(false);
     56  }
     57 
    5458  /**
    5559    Log job agent events.
     
    6064  public static void main(String[] args)
    6165  {
     66    int exitCode = 0;
    6267    CmdLine cmdLine = new CmdLine(args);
    6368    String cmd = cmdLine.getCmd();
     
    8287        printUsage();
    8388        log.debug(message, t);
    84         return;
     89        System.exit(1);
    8590      }
    8691   
     
    9297          System.out.println("Starting job agent...");
    9398          ac.startAgent();
     99          exitCode = -1; // Do not exit
    94100          System.out.println("Job agent is up and running.");
    95101        }
     
    106112          System.out.println(info.toString());
    107113        }
     114        else if ("status".equals(cmd))
     115        {
     116          String msg = "";
     117          try
     118          {
     119            JobAgentInfo info = ac.getStatus();
     120            msg += info.isPaused() ? "Paused" : "Running";
     121          }
     122          catch (ConnectException ex)
     123          {
     124            // ConnectException is expected if the agent is not running
     125            msg += "Stopped";
     126            log.debug(ex.getMessage(), ex);
     127          }
     128          catch (Throwable t)
     129          {
     130            msg += "Error (" + t.getMessage() + ")";
     131            log.error(msg, t);
     132            exitCode = 1;
     133          }
     134          System.out.println(msg);
     135        }
    108136        else if ("register".equals(cmd))
    109137        {
     
    133161      catch (Throwable t)
    134162      {
     163        exitCode = 1;
    135164        String message = "Exception when executing command " + cmd;
    136165        System.out.println(message + ": " + t.getMessage());
     
    138167      }
    139168    }
     169    if (exitCode >= 0) System.exit(exitCode);
    140170  }
    141171
     
    144174    System.out.println("Usage    : jobagent.sh [options] cmd");
    145175    System.out.println(" options : -c <configuration file>");
    146     System.out.println(" cmd     : start | stop | pause | info | register | unregister | help");
     176    System.out.println(" cmd     : start | stop | pause | info | status | register | unregister | help");
    147177  }
    148178
     
    155185    System.out.println("pause     : Pauses the job agent");
    156186    System.out.println("info      : Get info about the job agent");
     187    System.out.println("status    : Get status information about the job agent");
    157188    System.out.println("register  : Registers this job agent with the BASE server");
    158189    System.out.println("unregister: Unregisters this job agent from the BASE server");
     
    318349  }
    319350 
     351  /**
     352    Get status info about running job agent by sending an info request to the agents r
     353    emote control service. The agent may be running in this or in another virtual machine.
     354    @throws IOException If there is an error
     355    @return A <code>JobAgentInfo</code> object
     356    @see JobAgentConnection#getInfo(boolean)
     357    @since 2.5
     358  */
     359  public JobAgentInfo getStatus()
     360    throws IOException
     361  {
     362    log.info("Getting status from agent on port " + port);
     363    JobAgentConnection conn = new JobAgentConnection(port, timeout);
     364    JobAgentInfo info = null;
     365    try
     366    {
     367      log.info("Sending status command to job agent on port " + port);
     368      info = conn.getInfo(true);
     369    }
     370    finally
     371    {
     372      conn.close();
     373    }
     374    return info;
     375  }
     376
    320377  public void registerAgent()
    321378  {
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/JobQueueChecker.java

    r3675 r3992  
    7373  {
    7474    this.agent = agent;
     75   
     76    // Verify that jobagent is registered
     77    DbControl dc = null;
     78    try
     79    {
     80      SessionControl sc = agent.getSessionControl();
     81      dc = sc.newDbControl();
     82      JobAgent jobAgent = agent.getJobAgent(dc);
     83    }
     84    finally
     85    {
     86      if (dc != null) dc.close();
     87    }
    7588  }
    7689 
  • trunk/src/core/net/sf/basedb/util/jobagent/JobAgentServerConnection.java

    r3675 r3992  
    206206        catch (Throwable t)
    207207        {
    208           answer = "FAILED " + t.getClass().getName() + ": " + t.getMessage();
     208          answer = t.getMessage() + " [" + t.getClass().getName() + "]";
    209209          if (logger != null) logger.error("Eception in request handler "+ requestHandler +
    210210            ": " + t.getMessage(), t);
Note: See TracChangeset for help on using the changeset viewer.