Skip to content

Commit 66c8b16

Browse files
author
Thomas Goodwin
committed
Added 'configure' of application/waveform external properties
Closes #1 Took this as an opportunity to produce a properties list from applications that is identical to that of components and devices by iterating over the external properties and fetching them from the associated component. This simplified adding the 'configure' (HTTP PUT) to the new ApplicationProperties handler.
1 parent 741cd53 commit 66c8b16

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

model/redhawk.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Asynchronous Tornado service for REDHAWK. Maps the functions
2424
in domain.py and caches the domain object.
2525
"""
26-
import logging
2726
from _utils.tasking import background_task
2827

2928
from domain import Domain, scan_domains, ResourceNotFound
@@ -32,7 +31,7 @@
3231
from ossie.properties import props_from_dict, props_to_dict
3332

3433
from tornado.websocket import WebSocketClosedError
35-
from tornado import ioloop
34+
from tornado import ioloop, log
3635

3736
import collections
3837

@@ -166,6 +165,10 @@ def get_application(self, domain_name, app_id):
166165
dom = self._get_domain(domain_name)
167166
return dom.find_app(app_id)
168167

168+
def _get_application(self, domain_name, app_id):
169+
dom = self._get_domain(domain_name)
170+
return dom.find_app(app_id)
171+
169172
@background_task
170173
def get_application_list(self, domain_name):
171174
dom = self._get_domain(domain_name)
@@ -186,6 +189,31 @@ def release_application(self, domain_name, app_id):
186189
dom = self._get_domain(domain_name)
187190
return dom.release(app_id)
188191

192+
@background_task
193+
def application_configure(self, domain_name, app_id, new_properties):
194+
app = self._get_application(domain_name, app_id)
195+
props = Redhawk._application_externalProps(app)
196+
197+
changes = Redhawk._get_prop_changes(props, new_properties)
198+
return app.configure(changes)
199+
200+
'''
201+
Helper function to streamline getting a property list similar to what one
202+
gets from components, devices, etc.
203+
'''
204+
@staticmethod
205+
def _application_externalProps(app):
206+
props = []
207+
for epid, t in app._externalProps.iteritems():
208+
pid = t[0] # First item is the property id relative to the component
209+
cid = t[1] # Second item in tuple is prefix of component identifier
210+
for comp in app.comps:
211+
if comp.identifier.startswith(cid):
212+
for prop in comp._properties:
213+
if prop.id == pid:
214+
props.append(prop)
215+
return props
216+
189217
##############################
190218
# COMMON PROPERTIES
191219
@staticmethod

pyrest.py

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

2424
from rest.domain import DomainInfo, DomainProperties
2525
from rest.allocation import Allocations
26-
from rest.application import Applications
26+
from rest.application import Applications, ApplicationProperties
2727
from rest.component import Components, ComponentProperties
2828
from rest.devicemanager import DeviceManagers
2929
from rest.device import Devices, DeviceProperties
@@ -119,6 +119,10 @@ def __init__(self, *args, **kwargs):
119119
dict(redhawk=redhawk, kind='application')),
120120
(_APPLICATION_PATH + _ID + _BULKIO_PATH, BulkIOWebsocketHandler,
121121
dict(redhawk=redhawk, kind='application', _ioloop=_ioloop)),
122+
(_APPLICATION_PATH + _ID + _PROPERTIES_PATH + _LIST, ApplicationProperties,
123+
dict(redhawk=redhawk)),
124+
(_APPLICATION_PATH + _ID + _PROPERTIES_PATH + _ID, ApplicationProperties,
125+
dict(redhawk=redhawk)),
122126

123127
# Components
124128
(_COMPONENT_PATH + _LIST, Components, dict(redhawk=redhawk)),

rest/application.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131

3232
import json
3333

34-
3534
class Applications(JsonHandler, PropertyHelper, PortHelper):
3635
@gen.coroutine
3736
def get(self, domain_name, app_id=None):
3837
try:
3938
if app_id:
4039
app = yield self.redhawk.get_application(domain_name, app_id)
4140
comps = yield self.redhawk.get_component_list(domain_name, app_id)
41+
props = self.redhawk._application_externalProps(app)
4242

4343
info = {
4444
'id': app._get_identifier(),
4545
'name': app.name,
4646
'started': app._get_started(),
4747
'components': comps,
4848
'ports': self.format_ports(app.ports),
49-
'properties': self.format_properties(app._externalProps, app.query([]))
49+
'properties': self.format_properties(props, app.query([]))
5050
}
5151
else:
5252
apps = yield self.redhawk.get_application_list(domain_name)
@@ -114,3 +114,28 @@ def delete(self, domain_name, app_id):
114114

115115
except Exception as e:
116116
self._handle_request_exception(e)
117+
118+
class ApplicationProperties(JsonHandler, PropertyHelper):
119+
@gen.coroutine
120+
def get(self, domain, app_id):
121+
try:
122+
app = yield self.redhawk.get_application(domain, app_id)
123+
props = self.redhawk._application_externalProps(app)
124+
125+
self._render_json({
126+
'properties': self.format_properties(props, app.query([]))
127+
})
128+
except Exception as e:
129+
self._handle_request_exception(e)
130+
131+
@gen.coroutine
132+
def put(self, domain, app_id):
133+
try:
134+
data = json.loads(self.request.body)
135+
json_props = data.get('properties', [])
136+
changes = self.unformat_properties(json_props)
137+
138+
yield self.redhawk.application_configure(domain, app_id, changes)
139+
except Exception as e:
140+
self._handle_request_exception(e)
141+

0 commit comments

Comments
 (0)