ConfigSnapshot
Class ConfigSnapshot

java.lang.Object
  extended by java.util.TimerTask
      extended by ConfigSnapshot.ConfigSnapshot
All Implemented Interfaces:
ConfigSnapshotOperations, iInstrumentController.InstrumentControllerOperations, java.lang.Runnable

 class ConfigSnapshot
extends java.util.TimerTask
implements iInstrumentController.InstrumentControllerOperations, ConfigSnapshotOperations

This class will be used to take snap shots of the state of the current instrument configuration which is included in the observing system which is indicated by the environment variable INSTRUMENT which is initialised as part of the setup of the observing system.

Snapshots will be taken of the instrumentation every 15 mins between the hours of 0000 and 0900 and also when the application is closed down through the use of the stopobssys scripts between these hours as well.

On start up of the application, a comparison of the existing instrument configuration and the previous snapshot will be made and if the configuration changes then it will be reported by means of an alarm in the syslog.

The application is CORBA enabled and registers itself in the name service as ConfigSnapshot/ConfigSnapshot. The details of the interface are outlined in iConfigSnapshot interface.

A client of the application is the 4MSControl panel which contains a drop down menu which is used to instruct the application to perform a instrument configuration snap shot comparison of the current instrumentation configuration and the last snapshot taken. The details of any instrument configuration mismatches will be reported accordingly. If the application is unable to perform the comparison (for example if the instrument configuration has changed for instance), the user will be notified accordingly.

The application will not take snapshots unless running on the machine which is hosting the whtics database. This is to prevent the application running on a different host computer with a different instrument configuration and polluting the snapshot information in the database on the ICS computer.

Version:
$Id
Author:
Craige Bevil

Field Summary
(package private)  org.omg.IOP.Codec codec
          A codec which will be used for converting any values to strings
private  org.omg.CosNaming.NamingContextExt ControllerNameServiceContext
          This is the context in the COS naming service into which we should store the details of mechanisms and the subactions which are associated with them
private  java.sql.Connection DBConnection
          This is used to hold a database connection to the WHT OCS postgres database where the configuration data for the mechanisms which are to be simulated is held
(package private)  java.util.Map<java.lang.String,java.lang.String> env
          These are our environment variables
(package private)  boolean FirstSnapShot
          True if this is the first snap shot to be taken.
(package private)  java.lang.String ICSHostComputer
          This is the name of the machine which is hosting the database, if we are not running on the ICS host computer then we do not perform snapshots.
(package private)  java.util.ArrayList<java.lang.String> InstrumentsInConfiguration
          These are the instruments which are associated with the camera stations which are included in the INSTRUMENT environment variable
private  java.util.Calendar LastSnapShotTime
          This is the time that the last snap shot was taken of the system
(package private)  java.lang.String LocalhostName
          This is the name of the host which we are running upon
 OCSCORBAHelper OCSCorba
          This will be used to perform a lot of the donkey work associated with setting up a CORBA application.
private  org.omg.CORBA.ORB Orb
          The CORBA request broker or ORB which will be used for handling CORBA requests
private  iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
          This is reference to the remote proxy CORBA object which will be used to access the parameter noticeboard
private  org.omg.PortableServer.POA Poa
          The portable object adapter which will be used by this class
private  org.omg.CosNaming.NamingContextExt RootNamingServiceContext
          This is a reference to the COS naming service
(package private)  java.util.HashMap<java.lang.String,SnapshotVariable> SnapshotItems
          This is a collection which contains the details of all of the variables which are to be snapshotted.
private  java.util.Timer SnapShotTimer
          This is a timer object which will be used for scheduling of the snapshots
private  MessageHandler SyslogMessageHandler
          This is a syslog object which will be used to report errors etc
 
Constructor Summary
ConfigSnapshot(java.lang.String[] args, MessageHandler SyslogMessageHandler, java.lang.String dbHost)
           
 
Method Summary
 void closeDown(java.lang.String CloseDownMessage)
          This is an obligation to the CORBA instrument controller interface which permits the application to be closed down in a controlled manner.When the application is requested to close down, it will take a snapshot of the instrument configuration before it actually shuts down
private  java.util.ArrayList<java.lang.String> getInstrumentsFromInstrumentStations()
          Break down the environment variable INSTRUMENT and then retrieves from the INSTRUMENTCAMERASTATIONS table in the whtics database, the names of the instruments which are associated with those camera stations.
 boolean handshake()
          This is an obligation to the CORBA instrument controller interface which permits a third party to ascertain if the instrument controller is responding.
static void main(java.lang.String[] args)
           
 void performConfigurationSnapshot()
          Takes a snapshot of the current configuration for the instrumentation which is configured on the current machine.
 ComparisonResult performSnapShotComparison()
          Forms a part of the IDL ConfigSnapshot interface and will result in the application verifying if the current instrument configuration differs from the previous instrument configuration which is held in the database.
 java.lang.String performSnapShotComparisonWithHTMLResponse()
          Forms a part of the IDL ConfigSnapshot interface and will result in the application verifying if the current instrument configuration differs from the previous instrument configuration which is held in the database.
private  void readSnapshotConfigurationInformation()
          Will read from the database the details of the parameters in the parameter noticeboard which need to be stored as part of this snapshot.
private  void removeOldSnapShotDataFromDatabase()
          Cleans up the database by removing snapshot data from the database which is older than 2 weeks old.
 void run()
          This is the obligation of the TimerTask interface and is called intermittingly.
 void setDebugState(boolean DebugState)
          This is an obligation to the CORBA instrument controller interface which permits the debug of the application to be enabled or disabled.
 void setTraceLevel(double TraceLevel)
          This is an obligation to the CORBA instrument controller interface which permits the trace level of the application to be set, in this application there is no different trace levels enabled.
 void verifyInstrumentConfigurationChangesOnStartup()
          Verify instrument configuration has not changed.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICSHostComputer

java.lang.String ICSHostComputer
This is the name of the machine which is hosting the database, if we are not running on the ICS host computer then we do not perform snapshots.


LocalhostName

java.lang.String LocalhostName
This is the name of the host which we are running upon


InstrumentsInConfiguration

java.util.ArrayList<java.lang.String> InstrumentsInConfiguration
These are the instruments which are associated with the camera stations which are included in the INSTRUMENT environment variable


SnapshotItems

java.util.HashMap<java.lang.String,SnapshotVariable> SnapshotItems
This is a collection which contains the details of all of the variables which are to be snapshotted.


env

java.util.Map<java.lang.String,java.lang.String> env
These are our environment variables


LastSnapShotTime

private java.util.Calendar LastSnapShotTime
This is the time that the last snap shot was taken of the system


SnapShotTimer

private final java.util.Timer SnapShotTimer
This is a timer object which will be used for scheduling of the snapshots


OCSCorba

public OCSCORBAHelper OCSCorba
This will be used to perform a lot of the donkey work associated with setting up a CORBA application.


Orb

private org.omg.CORBA.ORB Orb
The CORBA request broker or ORB which will be used for handling CORBA requests


Poa

private org.omg.PortableServer.POA Poa
The portable object adapter which will be used by this class


FirstSnapShot

boolean FirstSnapShot
True if this is the first snap shot to be taken. This is a flag which is is used to indicate whether or not we have to verify the instrument configuration when the application is started.


ControllerNameServiceContext

private org.omg.CosNaming.NamingContextExt ControllerNameServiceContext
This is the context in the COS naming service into which we should store the details of mechanisms and the subactions which are associated with them


RootNamingServiceContext

private org.omg.CosNaming.NamingContextExt RootNamingServiceContext
This is a reference to the COS naming service


DBConnection

private java.sql.Connection DBConnection
This is used to hold a database connection to the WHT OCS postgres database where the configuration data for the mechanisms which are to be simulated is held


ParameterNoticeBoard

private iParameterNoticeBoard.ParameterNoticeBoardSupplier ParameterNoticeBoard
This is reference to the remote proxy CORBA object which will be used to access the parameter noticeboard


codec

org.omg.IOP.Codec codec
A codec which will be used for converting any values to strings


SyslogMessageHandler

private MessageHandler SyslogMessageHandler
This is a syslog object which will be used to report errors etc

Constructor Detail

ConfigSnapshot

@TODO(value="Remove the call to the performSnapShotComparison at the end of the method - Change so that we will not create snapshots on any machine other than whtics - We have commented out the removal of the old snapshots")
ConfigSnapshot(java.lang.String[] args,
                         MessageHandler SyslogMessageHandler,
                         java.lang.String dbHost)
Method Detail

getInstrumentsFromInstrumentStations

private java.util.ArrayList<java.lang.String> getInstrumentsFromInstrumentStations()
Break down the environment variable INSTRUMENT and then retrieves from the INSTRUMENTCAMERASTATIONS table in the whtics database, the names of the instruments which are associated with those camera stations.

Returns:
ArrayList An array of the instrument names

verifyInstrumentConfigurationChangesOnStartup

public void verifyInstrumentConfigurationChangesOnStartup()
Verify instrument configuration has not changed. Report any changes to the syslog. This is normally called on startup of the application which is normally when the observing system is started.


performSnapShotComparisonWithHTMLResponse

public java.lang.String performSnapShotComparisonWithHTMLResponse()
                                                           throws UnableToPerformComparison,
                                                                  InstrumentConfigurationChangedException
Forms a part of the IDL ConfigSnapshot interface and will result in the application verifying if the current instrument configuration differs from the previous instrument configuration which is held in the database.

The result is a HTML formatted string which contains the details of the comparison

Specified by:
performSnapShotComparisonWithHTMLResponse in interface ConfigSnapshotOperations
Returns:
String A HTML formatted evaluation of the snapshot comparison with the current instrument configuration.
Throws:
UnableToPerformComparison - When it unable to perform a comparison of the data in the snapshot database. If we are not running on the ICS computer this expception will be thrown.
InstrumentConfigurationChangedException - Thrown when the last snapshot instrument configuration does not correspond to the instrument configuration which we are currently using.

performSnapShotComparison

public ComparisonResult performSnapShotComparison()
                                           throws UnableToPerformComparison,
                                                  InstrumentConfigurationChangedException
Forms a part of the IDL ConfigSnapshot interface and will result in the application verifying if the current instrument configuration differs from the previous instrument configuration which is held in the database.

Specified by:
performSnapShotComparison in interface ConfigSnapshotOperations
Throws:
UnableToPerformComparison - When it unable to perform a comparison of the data in the snapshot database.
InstrumentConfigurationChangedException - Thrown when the last snapshot instrument configuration does not correspond to the instrument configuration which we are currently using.

removeOldSnapShotDataFromDatabase

private void removeOldSnapShotDataFromDatabase()
Cleans up the database by removing snapshot data from the database which is older than 2 weeks old. We only need to delete from the snapshot table as there on delete cascade constraint on all of the dependant tables.


readSnapshotConfigurationInformation

private void readSnapshotConfigurationInformation()
                                           throws UnableToGetSnapshotInformationFromDatabase
Will read from the database the details of the parameters in the parameter noticeboard which need to be stored as part of this snapshot. It uses the environment variables INSTRUMENT and CAMERA in order to determine the snap shot configuration data which needs to be read from the database.

Throws:
UnableToGetSnapshotInformationFromDatabase - Should there be any problem getting the snapshot configuration data from the ICS database on whtics.

run

@TODO(value="Uncomment the code which restricts the time that that the snapshots are taken")
public void run()
This is the obligation of the TimerTask interface and is called intermittingly. Between the hours of 0000 and 0900 the configuration of the instrumentation in the parameter noticeboard will be snap shotted to the database on the whtics.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask

performConfigurationSnapshot

public void performConfigurationSnapshot()
                                  throws UnableToTakeSnapShot
Takes a snapshot of the current configuration for the instrumentation which is configured on the current machine. This snapshot is only performed if the application is running on the whtics machine.

Specified by:
performConfigurationSnapshot in interface ConfigSnapshotOperations
Throws:
UnableToTakeSnapShot

setDebugState

public void setDebugState(boolean DebugState)
This is an obligation to the CORBA instrument controller interface which permits the debug of the application to be enabled or disabled.

Specified by:
setDebugState in interface iInstrumentController.InstrumentControllerOperations
Parameters:
DebugState - Whether or not debug should be enabled or disabled.

setTraceLevel

public void setTraceLevel(double TraceLevel)
This is an obligation to the CORBA instrument controller interface which permits the trace level of the application to be set, in this application there is no different trace levels enabled.

Specified by:
setTraceLevel in interface iInstrumentController.InstrumentControllerOperations
Parameters:
TraceLevel - The expected trace level of the application when debug is enabled.

closeDown

public void closeDown(java.lang.String CloseDownMessage)
This is an obligation to the CORBA instrument controller interface which permits the application to be closed down in a controlled manner.When the application is requested to close down, it will take a snapshot of the instrument configuration before it actually shuts down

Specified by:
closeDown in interface iInstrumentController.InstrumentControllerOperations
Parameters:
CloseDownMessage - The text of a message which is to be put into the syslog when the application closes down

handshake

public boolean handshake()
This is an obligation to the CORBA instrument controller interface which permits a third party to ascertain if the instrument controller is responding. The application should return true in the case that the application is working fine

Specified by:
handshake in interface iInstrumentController.InstrumentControllerOperations
Returns:
boolean true if the application is responding

main

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