org.mbari.siam.configt
Class ConfigTool

java.lang.Object
  extended by org.mbari.siam.configt.ConfigTool
All Implemented Interfaces:
java.io.FilenameFilter, ServletApp, ServletWizard

public class ConfigTool
extends java.lang.Object
implements ServletWizard, java.io.FilenameFilter

PlatformConfigServlet is the main class for the SIAM configuration tool. It is based on the Jetty servlet classes, and is used in conjunction with the Jetty HTTP server and servlet container (SimpleServer.class, http://org.mortbay.org/jetty). The PlatformConfigServlet (servlet) is used to configure an MMC node via a web browser. One of the motivations for the servlet is to hide the complexity of the node configuration, which is distributed throughout a number of files on an MMC node. A web-based design makes it possible for the same configuration tool to be used either as a command-line tool (through a serial console, using text based browsers) or remotely, via the network. The servlet architecture is stateful, unlike CGI, and supports session control (not implemented yet). The configuration process consists of setting general node options (e.g., node ID, communications settings, network settings, etc.) and configuring instrument serial ports. Once the options have been set, the system configuration files, consisting of various Linux system files and Java properties files, are written by the servlet. The files affected are:

  1. siamPort.cfg
  2. siamEnv
  3. interfaces
  4. hosts
  5. hostname
  6. binRouting.sh
  7. rc.local
When the servlet's init() method is called the first time the servlet is instantiated by the server, and again whenever the user chooses to re-initialize (reload the the configuration files). On initialization, the servlet reads it's own Java properties file (configtool.properties), containing paths to the various configuration files that it manages, as well as paths to system utilities and other files. The init() method then loads Java properties files describing each of the configuration files. The properties files contain paths to templates used to edit or generate the actual config files, as well as specifying configuration items and the HTML controls used to represent them. This allows the application to be largely reconfigured without recompiling any code. Once the init() method has run, the servlet has a vector of ConfigFile objects (encapsulating configuration file specific behaviors), and a master list of all configurable items (ConfigItems). Each ConfigItem has an HTMLControl object that manages the item's value and HTML rendering (i.e., HTML form element type and properties). As the user manipulates the servlet controls (HTML form elements), the servlet's doGet() method is invoked by the server's servlet container, passing in HTTPServletRequest and HTTPServletResponse objects representing the HTTP request and response from and to the browser, respectively. The doGet() method parses the request and calls the appropriate method to maintain the servlet state and generate the appropriate HTML page. Once a group of settings (node settings or port settings) has been completed, the user is presented with a summary of settings and then presses a button to write the settings to the configuration files. The servlet then computes a number of parameters (e.g., IP addresses, etc.) based on the chosen settings and then calls the createBackup(), writeTemp() and replaceFile() methods for each ConfigFile, backing up the current configuration files and replacing them with the new versions. The contents of the configuration files are generated using templates; some are simple templates that either exist or don't, others use special tags to mark places where ConfigItem values should be inserted, and others read an existing file, adding. deleting or replacing entire lines. To Do: - Concurrency/session control - HTML output for exception handling


Field Summary
protected static org.apache.log4j.Logger _log4j
          Log4J logger
static int READY
          File write state: ready to write
static int WRITING
          File write state: write in progress
 
Constructor Summary
ConfigTool()
           
 
Method Summary
 boolean accept(java.io.File file, java.lang.String name)
          Implement JAR file filter for jarList ConfigItem.
 void back(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 void cancel(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 void configureAuxLink(java.lang.String sNodeType, java.lang.String sLinkType)
           
 void configureParentLink(java.lang.String sNodeType, java.lang.String sLinkType)
           
 ConfigItem createJarList(java.lang.String jarPath)
          Create a global (servlet level) ConfigItem; a SELECT drop box containing a list of service JAR files.
 void doConfigAction()
          After the configuration files have been written, a shell script or executable may be called to perform any special operations required.
 void finish(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 java.util.Vector getConfigFiles()
           
 ConfigItem getElement(java.lang.String name)
          Lookup ConfigItem by name.
 java.util.Vector getElements()
           
 ConfigItem getItem(java.lang.String name)
           
 java.lang.String getItemValue(java.lang.String name)
           
 java.util.Vector getPageNames()
           
 java.util.Properties getProperties()
          Fulfills ServletApp interface
 java.lang.String getSiamHome()
          Return SIAM_HOME path
 java.lang.String getValue(java.lang.String name)
          Lookup ConfigItem value by name.
 void init()
          Servlet initialization.
protected  void loadProperties()
          Load servlet configuration from configtool.properties
static void main(java.lang.String[] args)
           
 void next(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
protected  void setConfigItem(ConfigItem item, java.lang.String itemName, java.lang.String itemValue)
          Set config item with specified value, create it if it doesn't exist
 void setProgressPercent(int p)
          Set file-write progress % value
 void setProgressText(java.lang.String t)
          Set file-write progress text value
 void setServletConfigItems()
          Calculate value of global (servlet level) ConfigItems based on current configuration settings.
 void setState(java.lang.String pageID)
          Save current state and proceed to next state
 void update(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Handler for HTTP GET request
 void writeConfigFiles()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log4j

protected static org.apache.log4j.Logger _log4j
Log4J logger


READY

public static final int READY
File write state: ready to write

See Also:
Constant Field Values

WRITING

public static final int WRITING
File write state: write in progress

See Also:
Constant Field Values
Constructor Detail

ConfigTool

public ConfigTool()
Method Detail

update

public void update(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Handler for HTTP GET request

Specified by:
update in interface ServletApp
Throws:
javax.servlet.ServletException
java.io.IOException

next

public void next(javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
          throws javax.servlet.ServletException,
                 java.io.IOException
Specified by:
next in interface ServletWizard
Throws:
javax.servlet.ServletException
java.io.IOException

back

public void back(javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
          throws javax.servlet.ServletException,
                 java.io.IOException
Specified by:
back in interface ServletWizard
Throws:
javax.servlet.ServletException
java.io.IOException

cancel

public void cancel(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Specified by:
cancel in interface ServletWizard
Throws:
javax.servlet.ServletException
java.io.IOException

finish

public void finish(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Specified by:
finish in interface ServletWizard
Throws:
javax.servlet.ServletException
java.io.IOException

getPageNames

public java.util.Vector getPageNames()
Specified by:
getPageNames in interface ServletApp

getElements

public java.util.Vector getElements()
Specified by:
getElements in interface ServletApp

getConfigFiles

public java.util.Vector getConfigFiles()
Specified by:
getConfigFiles in interface ServletApp

init

public void init()
          throws javax.servlet.ServletException
Servlet initialization. Called during servlet instantiation by server's servlet container and whenever user re-initializes servlet.

Specified by:
init in interface ServletApp
Throws:
javax.servlet.ServletException

setState

public void setState(java.lang.String pageID)
Save current state and proceed to next state


loadProperties

protected void loadProperties()
                       throws java.lang.Exception
Load servlet configuration from configtool.properties

Throws:
java.lang.Exception

getSiamHome

public java.lang.String getSiamHome()
Return SIAM_HOME path


getValue

public java.lang.String getValue(java.lang.String name)
Lookup ConfigItem value by name. Note that names should be unique across ConfigFiles

Specified by:
getValue in interface ServletApp

getItemValue

public java.lang.String getItemValue(java.lang.String name)

getElement

public ConfigItem getElement(java.lang.String name)
Lookup ConfigItem by name.

Specified by:
getElement in interface ServletApp

getItem

public ConfigItem getItem(java.lang.String name)

createJarList

public ConfigItem createJarList(java.lang.String jarPath)
Create a global (servlet level) ConfigItem; a SELECT drop box containing a list of service JAR files.


setConfigItem

protected void setConfigItem(ConfigItem item,
                             java.lang.String itemName,
                             java.lang.String itemValue)
Set config item with specified value, create it if it doesn't exist


setServletConfigItems

public void setServletConfigItems()
Calculate value of global (servlet level) ConfigItems based on current configuration settings. These value of these configuration items are used by the various ConfigFiles to generate their output.


configureParentLink

public void configureParentLink(java.lang.String sNodeType,
                                java.lang.String sLinkType)
                         throws java.io.IOException,
                                java.lang.Exception
Throws:
java.io.IOException
java.lang.Exception

configureAuxLink

public void configureAuxLink(java.lang.String sNodeType,
                             java.lang.String sLinkType)
                      throws java.io.IOException,
                             java.lang.Exception
Throws:
java.io.IOException
java.lang.Exception

doConfigAction

public void doConfigAction()
After the configuration files have been written, a shell script or executable may be called to perform any special operations required. Since Runtime.exec() does not handle shell scripts, a native executable is named in the configtool.properties file that calls the script using the C system() call. The shell script name and its arguments are passed on the command line to the script runner binary. The current script sets permissions for the configuration files.


writeConfigFiles

public void writeConfigFiles()

setProgressText

public void setProgressText(java.lang.String t)
Set file-write progress text value


setProgressPercent

public void setProgressPercent(int p)
Set file-write progress % value


accept

public boolean accept(java.io.File file,
                      java.lang.String name)
Implement JAR file filter for jarList ConfigItem. Fulfills FileFilter interface.

Specified by:
accept in interface java.io.FilenameFilter

getProperties

public java.util.Properties getProperties()
Fulfills ServletApp interface

Specified by:
getProperties in interface ServletApp

main

public static void main(java.lang.String[] args)


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.