# Salt Master Floscript

house master

framer masterudpstack be active first setup
    # Begin the pre-flight checks
    frame setup
        enter
            do salt raet cleanup
            do salt raet road stack setup per inode ".salt.road.manor"
            do salt raet manor lane setup per inode ".salt.lane.manor"
            do salt raet process manager setup
        go zmqstart
        go spawnmaint

    frame zmqstart
        # Start the zmq ret port if configured
        let me if .salt.etc.zmq_behavior
        do salt zmq setup at enter
        bid start zmqret
        go spawnmaint

    # Create the maintanence frame
    frame spawnmaint
        enter
            do salt raet maint fork
        go spawnworkers

    # Start forking master workers
    frame spawnworkers
        enter
            do salt raet worker fork
        go spawnreactor
        go spawneventreturn
        go startengines
        go start

    frame spawnreactor
        let me if .salt.etc.reactor
        enter
            do salt raet reactor fork
        go spawneventreturn
        go startengines
        go start

    frame spawneventreturn
        let me if .salt.etc.event_return
        enter
            do salt raet event return fork
        go startengines
        go start

    frame startengines
        let me if .salt.etc.engines
        enter
            do salt raet setup engines
        go start

    frame start
        # Start the message receive framer
        bid start inbound
        # Start the cluster bootstrap framer
        bid start bootstrap
        # Start the message receive framer
        bid start uxdrouter
        # Start the event framer
        bid start events
        # Start the presence framer
        bid start presence
        # Start the publish framer
        bid start publish
        # Start the manage framer
        bid start manager
        # Start the outbound framer
        bid start outbound
        exit
            do salt raet road stack closer per inode ".salt.road.manor."
            do salt raet lane stack closer per inode ".salt.lane.manor."

#########################################
# Main RAET Behaviors                   #
#########################################

# Inbound framer
framer inbound be inactive first start
    frame start
        do salt raet road stack service rx
        do salt raet lane stack service rx

# Bootstrap framer
framer bootstrap be inactive first setup
    frame setup
        enter
            do salt raet road clustered per inode ".salt.road.manor."

        go clustermaster
        go quit

    frame clustermaster
        let if salt.road.manor.cluster.clustered
        print Setting Up Master Cluster ....
        do salt raet road usher master setup per inode ".salt.road.manor."
        go join

    frame join
        print Joining...
        enter
            do salt raet road stack joiner per inode ".salt.road.manor."
        recur
            do salt raet road stack joined per inode ".salt.road.manor."
            do salt raet road stack rejected per inode ".salt.road.manor."

        go next if joined in .salt.road.manor.status
        #go abort if rejected in .salt.road.manor.status

    frame joined
        print Joined
        go next if elapsed >= 0.5

    frame allow
        print Allowing...
        enter
            do salt raet road stack allower per inode ".salt.road.manor."
        recur
            do salt raet road stack allowed per inode ".salt.road.manor."

        go next if allowed in .salt.road.manor.status

    frame allowed
        print Allowed
        go next

    frame clustering
        print Cluster Setup ...
        do salt raet road cluster load setup
        go next

    frame quit
        bid stop me

    frame abort
        bid stop all

# Router framer
framer uxdrouter be inactive first start
    frame start
        do salt raet router master

# Event bus framer
framer events be inactive first start
    frame start
        do salt raet eventer master
        do salt raet stats eventer master

# Presence framer
framer presence be inactive first start
    frame start
       go multiheaded
       go raet

    frame raet
       do salt raet presenter

    frame multiheaded
        let me if .salt.etc.zmq_behavior
        do salt zmq crypticle setup at enter
        do salt zmq publisher
        do salt raet presenter




# Publisher framer
framer publish be inactive first setup
    frame setup
        go dummy_publisher
        go raet_publisher
    frame dummy_publisher
        let me if .salt.etc.dummy_pub
        do salt dummy publisher
    frame raet_publisher
        do salt raet publisher

# Manager framer
framer manager be inactive first start at 10.0
    frame start
         do salt raet road stack manager per inode ".salt.road.manor"

# Outbound framer
framer outbound be inactive first start
    frame start
        do salt raet lane stack service tx
        do salt raet road stack service tx

#########################################
# Main ZMQ Behaviors                    #
#########################################

framer zmqret be inactive first start
    frame start
        enter
            do salt zmq ret fork
