def createFSMInstance(self, machineName, currentStateName=None, instanceName=None, data=None, method='GET', obj=None, headers=None): """ Creates an FSMContext instance with non-initialized data @param machineName: the name of FSMContext to instantiate, as defined in fsm.yaml @param currentStateName: the name of the state to place the FSMContext into @param instanceName: the name of the current instance @param data: a dict or FSMContext @param method: 'GET' or 'POST' @param obj: an object that the FSMContext can operate on @param headers: a dict of X-Fantasm request headers to pass along in Tasks @raise UnknownMachineError: if machineName is unknown @raise UnknownStateError: is currentState name is not None and unknown in machine with name machineName @return: an FSMContext instance """ try: machineConfig = self.config.machines[machineName] except KeyError: raise UnknownMachineError(machineName) initialState = self.machines[machineName][ constants.MACHINE_STATES_ATTRIBUTE][ machineConfig.initialState.name] try: currentState = self.pseudoInits[machineName] if currentStateName: currentState = self.machines[machineName][ constants.MACHINE_STATES_ATTRIBUTE][currentStateName] except KeyError: raise UnknownStateError(machineName, currentStateName) retryOptions = self._buildRetryOptions(machineConfig) url = machineConfig.url queueName = machineConfig.queueName return FSMContext( initialState, currentState=currentState, machineName=machineName, instanceName=instanceName, retryOptions=retryOptions, url=url, queueName=queueName, data=data, contextTypes=machineConfig.contextTypes, method=method, persistentLogging=( machineConfig.logging == constants.LOGGING_PERSISTENT), obj=obj, headers=headers)
def getMachineConfig(request): """ Returns the machine configuration specified by a URI in a HttpReuest @param request: an HttpRequest @return: a config._machineConfig instance """ # parse out the machine-name from the path {mount-point}/fsm/{machine-name}/startState/event/endState/ # NOTE: /startState/event/endState/ is optional machineName = getMachineNameFromRequest(request) # load the configuration, lookup the machine-specific configuration # FIXME: sort out a module level cache for the configuration - it must be sensitive to YAML file changes # for developer-time experience currentConfig = config.currentConfiguration() try: machineConfig = currentConfig.machines[machineName] return machineConfig except KeyError: raise UnknownMachineError(machineName)