-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nested state machines #366
Comments
Possible solutionsGeneric assumption in searching for solution: we don't want to overcomplicate State Machine (we will use SM abbreviation) of existing devices. Analized solutions:
1. Interactive command injecting it's states into SMSince command knows it's states it might inject them into SM of hosting device. benefits
drawbacks
2. Interactive command being SM but not being deviceMoler devices use https://github.com/pytransitions/transitions as machinery to implement their SMs. Implementation is a bit tricky since we want:
goto_state() is not the must for interactive commands. Currently envisioned SM for interactive command is simple, just 3 states: NOT_STARTED, INTERACTIVE, END. Of cause, in future, there might appear interactive commands with more states. However, it looks like they might be implemented in pure pytransition API. That would constitute new type of SM, different from SM of devices. Such SM would work as sub-SM inside current state of device SM. Device would treat it as running command. Interactive command would be still conceptually a command, however, more complicated one. benefits
drawbacks
3. Interactive command firing new moler device (which already is SM)Firing interactive command would create new device being SM (in same form as current SMs of moler). Hosting device would go into "transparent mode". So, conceptually hosting device would tread interactive command as single state being nested SM with its own states. That would not require to modify states of hosting device but would require to refactor its code. Since interactive command may happen in multiple states device must be able to programmatically jump into "virtual state" of running interactive command. Reusing current SM for interactive cmd (on example of openssl):
benefits
drawbacks
|
DecisionSelecting solution 3 as most beneficial even if it requires refactoring code of moler devices SM. |
Required changes in moler devices SMMajority of changes will happen inside moler/device/textualdevice.py self.current_stateIt is property of Like: We don't want to use This returned value doesn't come from prompts observers detection, nor from states listed on hosting device SM configuration. It is just returned when device detects "I'm working in transparent mode". So, we will need new member: state namesNested SM will see something like |
Prompt observersThey will work as they are. We will not add nested SM prompts (like Nested SM will have prompt observers only for own prompts (like So, we need to change prompt observers callback
Need change in
|
Handling newlinesIf we jump between states of current moler device it checks what type of newline is defined per state. Since it may happen then local console has different line endings then remote console. However, as we think about host SM and nested SM, they both share same connection. Nested SM being interactive command runs inside same shell of some device. In most cases they would share same newline. But nested SM should not know from which state it starts (from which console). So, as a default "newline of current console" should be passed down from hosting SM into nested SM. It is also possible that nested SM changes mode of that console handling and uses different newline. But in such case nested SM knows it from its internal code.
|
|
|
|
device removalAll devices have API The consequence of caching is that device with same name point to same device object inside factory cache. If you want to use same name to refer another device you need to uncache it first.
|
Why we need it?
If we face interactive command like openssl:
https://www.openssl.org/docs/manmaster/man1/openssl.html
https://wiki.openssl.org/index.php/Command_Line_Utilities (search "interactive mode")
then we may end up with something that may be started in multiple states of typical Moler device. openssl may run inside UNIX_LOCAL, PROXY_PC, UNIX_REMOTE.
Moreover, running interactive command introduces its own prompt (OpenSSL> for example). It finishes running openssl command but after it you can't run normal linux commands, just those of openssl. So, it constitutes state of device State Machine. We might introduce new state into existing devices but:
Concluding: such solution would generate exponential effort, unreadable code and maintenance nightmare.
Comments following below are results of days lasting discussions and analysis. It will discuss:
The text was updated successfully, but these errors were encountered: