-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a07048
commit d6c7943
Showing
9 changed files
with
191 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
argparse==1.2.1 | ||
appdirs==1.4.2 | ||
mirakuru==0.8.2 | ||
packaging==16.8 | ||
psutil==5.1.3 | ||
wsgiref==0.1.2 | ||
pyparsing==2.1.10 | ||
requests==2.13.0 | ||
six==1.10.0 | ||
thrift==0.10.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
struct ConnParams { | ||
1: string host, | ||
2: i32 port, | ||
2: string port, | ||
} | ||
|
||
service DroidService { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,70 @@ | ||
import os | ||
|
||
from worker.emulator import Emulator | ||
from zk_client import DroidZkClient | ||
|
||
|
||
class EndpointBuilder(object): | ||
def __init__(self): | ||
self.port = os.environ.get('ADB_PORT', '5554') | ||
self.avd = os.environ.get('AVD_NAME', 'nexus6-android7') | ||
class DroidBuilder(object): | ||
def __init__(self): | ||
self.port = os.environ.get('ADB_PORT', '5554') | ||
self.avd = os.environ.get('AVD_NAME', 'nexus6-android7') | ||
|
||
def set_port(self, port): | ||
self.port = port | ||
return self | ||
def set_port(self, port): | ||
self.port = port | ||
return self | ||
|
||
def set_avd(self, avd): | ||
self.avd = avd | ||
return self | ||
def set_avd(self, avd): | ||
self.avd = avd | ||
return self | ||
|
||
def build(self): | ||
return Emulator(port=self.port, avd=self.avd) | ||
def build(self): | ||
return Emulator(port=self.port, avd=self.avd) | ||
|
||
|
||
class EndpointCoordinator(object): | ||
def __init__(self): | ||
self.instances = {} | ||
class DroidCoordinator(object): | ||
def __init__(self): | ||
self.instances = {} | ||
|
||
def set_endpoint(self, id, endpoint): | ||
self.instances[id] = endpoint | ||
def set_endpoint(self, id, endpoint): | ||
self.instances[id] = { | ||
'endpoint': endpoint, | ||
'zk_client': DroidZkClient(id), | ||
} | ||
|
||
def get_endpoint(self, id): | ||
return self.instances[id] | ||
def get_endpoint(self, id): | ||
return self.instances[id]['endpoint'] | ||
|
||
def start_all_instances(self): | ||
for instance in self.instances.values(): | ||
instance.start() | ||
def get_zk_client(self, id): | ||
return self.instances[id]['zl_client'] | ||
|
||
def get_num_endpoints(self): | ||
return len(self.instances) | ||
def get_num_endpoints(self): | ||
return len(self.instances) | ||
|
||
def start_endpoint(self, id): | ||
endpoint = self.get_endpoint(id) | ||
# Start droid | ||
endpoint.start() | ||
# Setup Zk client | ||
zk_client = self.get_zk_client(id) | ||
zk_client.setup() | ||
|
||
def iter_endpoints(self): | ||
return self.instances.iteritems() | ||
|
||
def setup(self): | ||
for instance_id, _ in self.iter_instances(): | ||
self.start_endpoint(instance_id) | ||
|
||
def stop_endpoint(self, id): | ||
endpoint = self.get_endpoint(id) | ||
# Stop droid | ||
endpoint.stop() | ||
# Setup Zk client | ||
zk_client = self.get_zk_client(id) | ||
zk_client.teardown() | ||
|
||
def teardown(self): | ||
for instance_id, _ in self.iter_instances(): | ||
self.stop_endpoint(instance_id) | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from contextlib import contextmanager | ||
|
||
from tgen.droid_service import DroidService | ||
|
||
from thrift import Thrift | ||
from thrift.transport import TSocket | ||
from thrift.transport import TTransport | ||
from thrift.protocol import TBinaryProtocol | ||
|
||
|
||
class DroidClient(object): | ||
def __init__(self, host, port): | ||
self.host = host | ||
self.port = port | ||
|
||
self.client = None | ||
|
||
@contextmanager | ||
def transport(self): | ||
transport = TSocket.TSocket(self.host, self.port) | ||
transport = TTransport.TBufferedTransport(transport) | ||
protocol = TBinaryProtocol.TBinaryProtocol(transport) | ||
self.client = DroidService.Client(protocol) | ||
transport.open() | ||
yield | ||
transport.close() | ||
self.client = None | ||
|
||
def ping(self): | ||
with self.transport(): | ||
self.client.ping() | ||
|
||
def get_package_name(self, apk_url): | ||
with self.transport(): | ||
return self.client.get_package_name(apk_url) | ||
|
||
def get_endpoint(self, endpoint_id): | ||
with self.transport(): | ||
return self.client.get_endpoint(endpoint_id) | ||
|
||
def install_apk(self, endpoint_id, apk_url): | ||
with self.transport(): | ||
return self.client.install_apk(endpoint_id, apk_url) | ||
|
||
def start_package(self, endpoint_id, package_name): | ||
with self.transport(): | ||
return self.client.start_package(endpoint_id, package_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.