Skip to content

Commit ecbb4b0

Browse files
author
B. Thomas Goodwin
committed
Merge branch 'fix-bulkio-and-tests' into 'master'
Fix bulkio and tests See merge request !3
2 parents 6822ba4 + 2a1ce9a commit ecbb4b0

27 files changed

Lines changed: 676 additions & 387 deletions

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

5-
Contains the REDHAWK python implementation of the generic REST API.
5+
Contains the REDHAWK python implementation of the generic [REST API](http://geontech.github.io/rest-python).
66

77
Please visit [the Wiki](https://github.com/Geontech/rest-python/wiki) for more detailed instructions on the changes made to this repository and how it can be used for development of external control interfaces, data bridges, and graphical user interfaces without having to install REDHAWK on the target system.
88

@@ -36,3 +36,7 @@ can be found at `deploy/rest-python-supervisor.conf`.
3636

3737
Once running the REST Interface can be tested at `http://localhost:<desired_port>/rh/rest/domains`.
3838

39+
## Deploying Applications
40+
41+
You can either install your application in `apps` for REST-Python to serve them, or deploy them with a separate server (e.g., NodeJS). REST-Python supports cross-domain responses to REST and Websocket requests to facilitate dual- or multi-server configurations to completely decouple the REDHAWK environment from the web application environment. (See [Docker-REDHAWK's](http://github.com/GeonTech/docker-redhawk) `geontech/redhawk-webserver` image.)
42+

docker-compose.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
version: "3"
2+
volumes:
3+
sdrroot:
4+
rf_snapshots:
5+
6+
services:
7+
# OmniORB services
8+
omni:
9+
image: geontech/redhawk-omniserver
10+
hostname: omni
11+
ports:
12+
- "2809:2809"
13+
- "11169:11169"
14+
15+
# Standard REDHAWK SDR Domain
16+
domain:
17+
image: geontech/redhawk-domain
18+
depends_on:
19+
- omni
20+
environment:
21+
- DOMAINNAME=REDHAWK_DEV
22+
- OMNISERVICEIP=omni
23+
volumes:
24+
- sdrroot:/var/redhawk/sdr
25+
26+
# Standard GPP
27+
gpp:
28+
image: geontech/redhawk-gpp
29+
depends_on:
30+
- domain
31+
environment:
32+
- DOMAINNAME=REDHAWK_DEV
33+
- NODENAME=GPP_Node
34+
- GPPNAME=GPP
35+
- OMNISERVICEIP=omni
36+
37+
# FEI FileReader Device runner mounted to the snapshot.
38+
fei_file_reader:
39+
image: geontech/redhawk-fei-filereader
40+
build: http://github.com/GeonTech/FEI_FileReader.git
41+
environment:
42+
- DOMAINNAME=REDHAWK_DEV
43+
- NODENAME=FEI_FR_Node
44+
- OMNISERVICEIP=omni
45+
volumes:
46+
- rf_snapshots:/var/rf_snapshots
47+
48+
# REST-Python Unit Under Test (UUT)
49+
rest:
50+
image: geontech/redhawk-webserver
51+
depends_on:
52+
- domain
53+
- gpp
54+
- fei_file_reader
55+
environment:
56+
- OMNISERVICEIP=omni
57+
ports:
58+
- "8080:8080"
59+
# 1. Mount the external rest-python
60+
# 2. Share SDRROOT with the Domain for access to standard components in sandbox
61+
# 3. Share RF_Snapshots with the FEI FileReader
62+
volumes:
63+
- ./:/opt/rest-python
64+
- sdrroot:/var/redhawk/sdr
65+
- rf_snapshots:/var/rf_snapshots
66+
command: [bash, -l, -c, /opt/rest-python/test.sh]

rest/allocation.py

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,51 @@
3535
class Allocations(JsonHandler, PropertyHelper):
3636
@gen.coroutine
3737
def get(self, domain_name, allocation_id=None):
38-
39-
if allocation_id:
40-
allocation = yield self.redhawk.get_allocation(domain_name, allocation_id)
41-
42-
info = {
43-
'id': allocation.allocationID,
44-
'deviceId': allocation.allocatedDevice._get_identifier(),
45-
'deviceManagerId': allocation.allocationDeviceManager._get_identifier(),
46-
'properties': self.format_properties(allocation.allocationProperties),
47-
'sourceId': allocation.sourceID
48-
}
49-
else:
50-
allocations = yield self.redhawk.get_allocation_list(domain_name)
51-
52-
info = {'allocations': allocations}
53-
54-
self._render_json(info)
38+
try:
39+
if allocation_id:
40+
allocation = yield self.redhawk.get_allocation(domain_name, allocation_id)
41+
42+
info = {
43+
'id': allocation.allocationID,
44+
'deviceId': allocation.allocatedDevice._get_identifier(),
45+
'deviceManagerId': allocation.allocationDeviceManager._get_identifier(),
46+
'properties': self.format_properties(allocation.allocationProperties),
47+
'sourceId': allocation.sourceID
48+
}
49+
else:
50+
allocations = yield self.redhawk.get_allocation_list(domain_name)
51+
52+
info = {'allocations': allocations}
53+
54+
self._render_json(info)
55+
except Exception as e:
56+
self._handle_request_exception(e)
5557

5658
@gen.coroutine
57-
def post(self, domain_name, allocation_id=None):
58-
data = json.loads(self.request.body)
59-
json_device_ids = data.get('deviceIds', [])
60-
json_props = data.get('properties', [])
61-
json_source_id = data.get('sourceId', '')
62-
props = self.unformat_properties_without_query(json_props)
63-
64-
if not allocation_id:
65-
allocation_id = data.get('allocationId', '')
59+
def post(self, domain_name, *args):
60+
try:
61+
data = json.loads(self.request.body)
62+
json_device_ids = data.get('deviceIds', [])
63+
json_props = data.get('properties', [])
64+
json_source_id = data.get('sourceId', '')
65+
props = self.unformat_properties_without_query(json_props)
6666

67-
allocation_id = yield self.redhawk.allocate(domain_name, allocation_id, json_device_ids, props, json_source_id)
68-
allocations = yield self.redhawk.get_allocation_list(domain_name)
67+
if 'allocationId' in data:
68+
allocation_id = data['allocationId']
69+
else:
70+
raise Exception('ALLOCATION_ID is required for allocations.')
6971

70-
self._render_json({'allocated': allocation_id, 'allocations': allocations})
72+
allocation_id = yield self.redhawk.allocate(domain_name, allocation_id, json_device_ids, props, json_source_id)
73+
allocations = yield self.redhawk.get_allocation_list(domain_name)
7174

72-
@gen.coroutine
73-
def delete(self, domain_name, allocation_id=None):
75+
self._render_json({'allocated': allocation_id, 'allocations': allocations})
7476

75-
if allocation_id:
76-
yield self.redhawk.deallocate(domain_name, [allocation_id])
77-
allocations = yield self.redhawk.get_allocation_list(domain_name)
77+
except Exception as e:
78+
self._handle_request_exception(e)
7879

79-
info = {
80-
'deallocated': [allocation_id],
81-
'allocations': allocations
82-
}
83-
else:
80+
@gen.coroutine
81+
def delete(self, domain_name, *args):
82+
try:
8483
data = json.loads(self.request.body)
8584
allocation_ids = data.get('allocationIds', [])
8685

@@ -92,4 +91,7 @@ def delete(self, domain_name, allocation_id=None):
9291
'allocations': allocations
9392
}
9493

95-
self._render_json(info)
94+
self._render_json(info)
95+
96+
except Exception as e:
97+
self._handle_request_exception(e)

rest/application.py

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,83 @@
3535
class Applications(JsonHandler, PropertyHelper, PortHelper):
3636
@gen.coroutine
3737
def get(self, domain_name, app_id=None):
38+
try:
39+
if app_id:
40+
app = yield self.redhawk.get_application(domain_name, app_id)
41+
comps = yield self.redhawk.get_component_list(domain_name, app_id)
42+
43+
info = {
44+
'id': app._get_identifier(),
45+
'name': app.name,
46+
'started': app._get_started(),
47+
'components': comps,
48+
'ports': self.format_ports(app.ports),
49+
'properties': self.format_properties(app._externalProps, app.query([]))
50+
}
51+
else:
52+
apps = yield self.redhawk.get_application_list(domain_name)
53+
wfs = yield self.redhawk.get_available_applications(domain_name)
3854

39-
if app_id:
40-
app = yield self.redhawk.get_application(domain_name, app_id)
41-
comps = yield self.redhawk.get_component_list(domain_name, app_id)
42-
43-
info = {
44-
'id': app._get_identifier(),
45-
'name': app.name,
46-
'started': app._get_started(),
47-
'components': comps,
48-
'ports': self.format_ports(app.ports),
49-
'properties': self.format_properties(app._externalProps, app.query([]))
50-
}
51-
else:
52-
apps = yield self.redhawk.get_application_list(domain_name)
53-
wfs = yield self.redhawk.get_available_applications(domain_name)
54-
55-
info = {'applications': apps, 'waveforms': wfs}
55+
info = {'applications': apps, 'waveforms': wfs}
5656

57-
self._render_json(info)
57+
self._render_json(info)
58+
except Exception as e:
59+
self._handle_request_exception(e)
5860

5961
@gen.coroutine
6062
def post(self, domain_name, app_id=None):
61-
data = json.loads(self.request.body)
63+
try:
64+
data = json.loads(self.request.body)
6265

63-
if app_id:
64-
app = yield self.redhawk.get_application(domain_name, app_id)
66+
if app_id:
67+
app = yield self.redhawk.get_application(domain_name, app_id)
6568

66-
started = data['started']
67-
if started:
68-
app.start()
69+
started = data['started']
70+
if started:
71+
app.start()
72+
else:
73+
app.stop()
74+
75+
self._render_json({'id': app_id, 'started': app._get_started()})
6976
else:
70-
app.stop()
77+
app_name = str(data['name'])
7178

72-
self._render_json({'id': app_id, 'started': app._get_started()})
73-
else:
74-
app_name = str(data['name'])
79+
app_id = yield self.redhawk.launch_application(domain_name, app_name)
80+
apps = yield self.redhawk.get_application_list(domain_name)
7581

76-
app_id = yield self.redhawk.launch_application(domain_name, app_name)
77-
apps = yield self.redhawk.get_application_list(domain_name)
82+
if 'started' in data and data['started']:
83+
app = yield self.redhawk.get_application(domain_name, app_id)
84+
app.start()
7885

79-
if 'started' in data and data['started']:
80-
app = yield self.redhawk.get_application(domain_name, app_id)
81-
app.start()
86+
self._render_json({'launched': app_id, 'applications': apps})
8287

83-
self._render_json({'launched': app_id, 'applications': apps})
88+
except Exception as e:
89+
self._handle_request_exception(e)
8490

8591
@gen.coroutine
8692
def put(self, domain_name, app_id=None):
87-
data = json.loads(self.request.body)
93+
try:
94+
data = json.loads(self.request.body)
8895

89-
app = yield self.redhawk.get_application(domain_name, app_id)
96+
app = yield self.redhawk.get_application(domain_name, app_id)
9097

91-
started = data['started']
92-
if started:
93-
app.start()
94-
else:
95-
app.stop()
98+
started = data['started']
99+
if started:
100+
app.start()
101+
else:
102+
app.stop()
96103

97-
self._render_json({'id': app_id, 'started': app._get_started()})
104+
self._render_json({'id': app_id, 'started': app._get_started()})
105+
except Exception as e:
106+
self._handle_request_exception(e)
98107

99108
@gen.coroutine
100109
def delete(self, domain_name, app_id):
101-
yield self.redhawk.release_application(domain_name, app_id)
102-
apps = yield self.redhawk.get_application_list(domain_name)
110+
try:
111+
yield self.redhawk.release_application(domain_name, app_id)
112+
apps = yield self.redhawk.get_application_list(domain_name)
103113

104-
self._render_json({'released': app_id, 'applications': apps})
114+
self._render_json({'released': app_id, 'applications': apps})
115+
116+
except Exception as e:
117+
self._handle_request_exception(e)

0 commit comments

Comments
 (0)