Skip to content

Commit 7c4ea2a

Browse files
author
B. Thomas Goodwin
committed
Merge branch 'feature-1-waveform-prop' into 'master'
Added ability to configure waveform properties Closes #1 See merge request geon/redhawk-ui/rest-python!6
2 parents 741cd53 + 579f4af commit 7c4ea2a

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

model/redhawk.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
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
3029

30+
from ossie.cf import CF
3131
from ossie.properties import __TYPE_MAP as TYPE_MAP
3232
from ossie.properties import props_from_dict, props_to_dict
3333

3434
from tornado.websocket import WebSocketClosedError
35-
from tornado import ioloop
35+
from tornado import ioloop, log
3636

3737
import collections
3838

@@ -166,6 +166,10 @@ def get_application(self, domain_name, app_id):
166166
dom = self._get_domain(domain_name)
167167
return dom.find_app(app_id)
168168

169+
def _get_application(self, domain_name, app_id):
170+
dom = self._get_domain(domain_name)
171+
return dom.find_app(app_id)
172+
169173
@background_task
170174
def get_application_list(self, domain_name):
171175
dom = self._get_domain(domain_name)
@@ -186,8 +190,18 @@ def release_application(self, domain_name, app_id):
186190
dom = self._get_domain(domain_name)
187191
return dom.release(app_id)
188192

193+
@background_task
194+
def application_configure(self, domain_name, app_id, new_properties):
195+
app = self._get_application(domain_name, app_id)
196+
props = app._getPropertySet()
197+
changes = Redhawk._get_prop_changes(props, new_properties)
198+
return app.configure(changes)
199+
189200
##############################
190201
# COMMON PROPERTIES
202+
'''
203+
Cleans out IDs being unicode, etc. since CF can't handle unicode strings.
204+
'''
191205
@staticmethod
192206
def _clean_property(property):
193207
if isinstance(property, basestring):
@@ -203,16 +217,22 @@ def _clean_property(property):
203217
# CF.Properties and dict() of { 'id': value, ... }
204218
# Use force to treat all ID matches as required changes
205219
def _get_prop_changes(current_props, new_properties, force=False):
206-
changes = {}
220+
changes = []
207221
for prop in current_props:
208222
if prop.id in new_properties:
209223
if new_properties[prop.id] != prop.queryValue() or force:
210-
changes[str(prop.id)] = prop.fromAny(
211-
prop.toAny(
212-
Redhawk._clean_property(new_properties[prop.id])
224+
changes.append(
225+
CF.DataType(
226+
prop.id,
227+
prop.toAny(
228+
Redhawk._clean_property(new_properties[prop.id])
229+
)
213230
)
214231
)
215-
return props_from_dict(changes)
232+
log.app_log.debug('Current properties: {}'.format(current_props))
233+
log.app_log.debug('New properties: {}'.format(new_properties))
234+
log.app_log.debug('Changes: {}'.format(changes))
235+
return changes
216236

217237
##############################
218238
# COMPONENT

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 = app._getPropertySet()
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 = app._getPropertySet()
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)