Skip to content

Commit

Permalink
Property configure/allocate/deallocate robustness
Browse files Browse the repository at this point in the history
Switched to returning a CF.DataType list for configure/allocate/deallocate.
This made processing parsed properties more robust overall.  Also added
debugging log statements for investigating server response in the future
since we revisit this seemingly every 6-12 months.
  • Loading branch information
btgoodwin committed Jan 23, 2018
1 parent d227d9d commit 579f4af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
42 changes: 17 additions & 25 deletions model/redhawk.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

from domain import Domain, scan_domains, ResourceNotFound

from ossie.cf import CF
from ossie.properties import __TYPE_MAP as TYPE_MAP
from ossie.properties import props_from_dict, props_to_dict

from tornado.websocket import WebSocketClosedError
from tornado import ioloop
from tornado import ioloop, log

import collections

Expand Down Expand Up @@ -192,30 +193,15 @@ def release_application(self, domain_name, app_id):
@background_task
def application_configure(self, domain_name, app_id, new_properties):
app = self._get_application(domain_name, app_id)
props = Redhawk._application_externalProps(app)

props = app._getPropertySet()
changes = Redhawk._get_prop_changes(props, new_properties)
return app.configure(changes)

'''
Helper function to streamline getting a property list similar to what one
gets from components, devices, etc.
'''
@staticmethod
def _application_externalProps(app):
props = []
for epid, t in app._externalProps.iteritems():
pid = t[0] # First item is the property id relative to the component
cid = t[1] # Second item in tuple is prefix of component identifier
for comp in app.comps:
if comp.identifier.startswith(cid):
for prop in comp._properties:
if prop.id == pid:
props.append(prop)
return props

##############################
# COMMON PROPERTIES
'''
Cleans out IDs being unicode, etc. since CF can't handle unicode strings.
'''
@staticmethod
def _clean_property(property):
if isinstance(property, basestring):
Expand All @@ -231,16 +217,22 @@ def _clean_property(property):
# CF.Properties and dict() of { 'id': value, ... }
# Use force to treat all ID matches as required changes
def _get_prop_changes(current_props, new_properties, force=False):
changes = {}
changes = []
for prop in current_props:
if prop.id in new_properties:
if new_properties[prop.id] != prop.queryValue() or force:
changes[str(prop.id)] = prop.fromAny(
prop.toAny(
Redhawk._clean_property(new_properties[prop.id])
changes.append(
CF.DataType(
prop.id,
prop.toAny(
Redhawk._clean_property(new_properties[prop.id])
)
)
)
return props_from_dict(changes)
log.app_log.debug('Current properties: {}'.format(current_props))
log.app_log.debug('New properties: {}'.format(new_properties))
log.app_log.debug('Changes: {}'.format(changes))
return changes

##############################
# COMPONENT
Expand Down
4 changes: 2 additions & 2 deletions rest/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get(self, domain_name, app_id=None):
if app_id:
app = yield self.redhawk.get_application(domain_name, app_id)
comps = yield self.redhawk.get_component_list(domain_name, app_id)
props = self.redhawk._application_externalProps(app)
props = app._getPropertySet()

info = {
'id': app._get_identifier(),
Expand Down Expand Up @@ -120,7 +120,7 @@ class ApplicationProperties(JsonHandler, PropertyHelper):
def get(self, domain, app_id):
try:
app = yield self.redhawk.get_application(domain, app_id)
props = self.redhawk._application_externalProps(app)
props = app._getPropertySet()

self._render_json({
'properties': self.format_properties(props, app.query([]))
Expand Down

0 comments on commit 579f4af

Please sign in to comment.