State Machine

One of the building blocks of the BlackBadger system is the notion of a state machine. This state machine breaks up the execution of the overall system into discrete stages or states. The rules of the state machine are quite simple:

  • Rule#1 Every state execution must complete before moving onto the next
  • Rule#2 If a state fails then the whole state machine is moved to the last state
  • Rule#3 The last state is assumed to be the terminate state

BlackBadger will execute the state of each agent in parallel. The agent in turn will execute that particular state for each of the components it is managing. A state in reality is just an ANT target. This target will execute within the ANT runtime and if for any reason it does not exit cleanly that will deem the state to have failed, which in turn fails the whole state machine.

You can specify any number of states for your state machine in the main system XML file. For example, consider the example below, this defines 5 states, state1/state2/state3/state4 with the last one called laststate. In each of the component xml files you would need to provide ANT targets for each of the states you wanted to execute.

<system name="sample file">
  <states order="state1,state2,state3,state4,laststate"/>
<system>

The underlying component XML file does not have to provide an ANT target for all the states; only the ones that it is interested in providing an execution for. If a state does not exist then it is assumed to have completed successfully. A missing state will not fail the state machine.

There are 5 default states defined should you opt to not supply or add your own.

  • clean
    To be used for cleaning up any directories or log files
  • deploy
    To be used for installing or acquiring the software for the given component
  • run
    Start the execution of the underlying component
  • test
    This will run the actual test suite against the system as a whole. It is not expected that all components will implement this.
  • terminate
    Called when the state machine completes or fails. Usually designed to stop or kill any processes.

State names are case-sensitive. To avoid confusion, keep them all lower case.