Stf: What happens when you click "stop using" on one specified device?

Created on 17 Sep 2015  路  19Comments  路  Source: openstf/stf

Hi ,

Can you give some instruction about what happens when user click "stop using" on one specified device?

I can't see any request in the network. I tried to update the owner to null in device table, and UI seems to that device was released. But when I chose to use this device again, it can't show any device UI in control tab. I only need disconnect and reconnect this device again, it can work well again.

So it need your instruction about what happens when user click "stop using" on one specified device?
I want to release this device after use logout.

Thanks
Luis

Most helpful comment

@luisxiaomai

I tried to put the whole event cycle in diagram. If you read Simo's explanation with this image, It will be easy to understand.

stf-architecture

All 19 comments

The request goes through WebSockets. If you look at the picture here, the message flows as follows:

  1. Browser sends a WebSocket message
  2. One of the websocket units receives the message and translates it to Protocol Buffers
  3. The websocket unit sends the message via PUSH to the app side triproxy's PULL
  4. The app side triproxy takes the message as-is and randomly forwards it via DEALER to one of the processor DEALERs
  5. The processor doesn't do anything yet (although it could if necessary), it simply forwards the message via DEALER to the device side triproxy's DEALER
  6. The triproxy takes the message as-is and uses PUB to publish the message the the device's channel (which is included in the message)
  7. The dev unit that is listening on that channel receives the message via its SUB.
  8. If the device is in a group, it leaves that group (and clears its in-memory state)
  9. The dev sends a GroupLeave message and sends it via PUSH to the device side triproxy
  10. The triproxy takes the message as-is and randomly forwards it to one of the processor's DEALEREs
  11. The processor receives the message, reads it, and modifies the database to remove the owner from that device
  12. The processor forwards the message via DEALER to the app side triproxy's DEALER
  13. The triproxy receives the message and PUBs it to all the websocket units
  14. All the websocket units receive information that the device no longer has an owner
  15. The websocket units emit a WebSocket message to all the connected browsers
  16. The browsers receive the message, update their internal state in JavaScript and re-render the UI if necessary

I'll admit that's a bit complicated, but it makes the system more scalable since you can easily increase the number of processors, websockets, and if necessary, triproxies as well. Nearly all internal communication in STF works this way.

If you remove the owner directly from the database, you skip step 8, and the device doesn't know it's no longer supposed to be in a group, since that information is also stored locally in memory. It will time out (i.e. automatically leave the group) after 15 minutes of inactivity, though, so it should eventually become usable.

Thanks for your rich answer. So if I want to logout with releasing the occupied devices, I need simulate above process? Can you share some stf code snippet which were used for 'stop using' action.

Thats a great life cycle explanation, Simo. I think, it would be great if you can write a document explaining STF architecture to speed up contribution from others.

@luisxiaomai

I tried to put the whole event cycle in diagram. If you read Simo's explanation with this image, It will be easy to understand.

stf-architecture

@vbanthia good job. BTW, you lost stf device. stf-device should inside stf-provider.

Also we don't actually use RotationWatcher.apk in STF. It's a companion program for minicap in case you want to use it by itself :) Otherwise it's very nice.

Nice graph, perhaps we could add it to README or DEPLOYMENT.

Really great diagram, gives a good overview of how the services interact.
I'd be very interested as well in an explanation of how to claim/release devices, as well as getting the adb connection string without having a browser involved.

@sorccu, @gunta @vbanthia @codeskyblue I read the front end code. When user clicks the "stop using" on one using device, browser sends the websocket message which is triggered by pure front end code, I want to know how I can simulate this in backend because I want to release all current user using devices when user session timeout or user logout.

so this question has already been resolved? I meet the same problem now @sorccu, @gunta @vbanthia @codeskyblue

my user always close the browser directly, so the other user must wait for the device to be timeout

@LiufxLucky365 having to wait for timeout is a different issue, open a new ticket for it.

open a new ? but my problem is the same with luisxiaomai , when my user logout, the other users cannot use that device until timeout.

BTW, #152 can you cost some time to answer me ? Thanks

@LiufxLucky365 actually its a different problem.
A) luisxiaomai wants a way to stop all the devices on user logout (we don't have a sign-out UI yet).

B) You want to stop the devices being used by your users because they close the browser directly.

Adding logout support will not fix your issue because your users will still be closing the browser directly, thus not logout.
What could fix the issue for your users could be: 1) lower the timeout to something like 30 seconds, or 2) add an option to release the devices on window.close.

@gunta Thanks for your help, that's helpful.

I think if i can supply some big 'logout' button, they would like to click it. But like luisxiaomai, how I can simulate this in backend. Now what i do is that when user logout, update the device owner as 'null', then wait the device to timeout. Is there another better way to release the device ?

BTW, where can i set the timeout option ?

Thanks

provider unit has timeout option, by default it is 15mins. So device will be released automatically after 15mins if kept idle. If you are running stf local then you can set it using --group-timeout options

stf local --group-timeout 60

If you are running using docker then you will have to set this option in provider unit.

Is there another better way to release the device ?

I don't think there is any better way but there is an easter egg. Just press Konami code when you are on device list { up up down down left right left right enter }. You will see a dialogue which will make you "admin" and then you can steal anyone's device. But do remember _with great power comes great responsibility_. So use it wisely.

@LiufxLucky365 @gunta @vbanthia , my question is not to provide a logout function. My question is how I can simulate "release devices" in backend, whatever I want to do this when I logout or my trial time is over. I want to implement this similar features.

I have a similar need. The primary need of my stakeholders is to get adb connection strings as easily as possible. So getting a list of devices (and whether they are claimed or not), claiming devices and releasing devices should ideally be done purely through API.
Trying to get some node knowledge in order to dive in and figure it out myself, but any pointers would be appreciated.

@luisxiaomai Have you implemented that features now ?

There is a similar issue, https://github.com/openstf/stf/issues/38

I started implementing RESTful devices/:serial/reserve & devices/:serial/release endpoints. But found its too complex because STF uses websocket for most of the client-server communication (which is good because it makes it real time app). And also, it checks xcrf token in each request which makes it kind of more difficult to create stateless apis. So I kind of gave up in between.

If anyone wants to give it a try, I can write what approach I was using but I will suggest to get it reviewed from STF developers before any implementation.

Authorisation

  • Every request to stf-app unit (api provider) goes through auth middleware which checks for valid session-id. If your request does not have a session id, it will redirect it to auth server to create a new session. So you need to modify this auth middleware such that it can forward request even it has only jwt token
  • Next step will be to develop a feature which can provide users their jwt token. Best way would be to create a section in "Setting" tab and show users their jwt token like github.
  • Next, you need to get rid of csrf checking for RESTful apis. One way to do is check csrf after RESTful api section.

After this you will be able to access all STF apis from any http client library using command line.

Implement reserve/release endpoints

  • You will be going to implements these new endpoints in stf-app unit
  • For this just mimic the websocket unit and do the same things what websocket unit does when it gets reserve and release messages.
  • You need to add app side push sockets and push group.join and group.kick messages to processor and inform all the websocket subscriber about the event so that people who are using web browser can also be updated.
  • For remote debugging you need to send connect.start message to server and get remote debug url.

Implement client

Last part being implement a good stf command line client which can use these endpoints easily.

I hope this will help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sunraych picture Sunraych  路  4Comments

habeebshk picture habeebshk  路  4Comments

KevinChann picture KevinChann  路  3Comments

ghost picture ghost  路  7Comments

vovinio picture vovinio  路  5Comments