def stop_recording(recording_id): updated_recording = flask.current_app.system_control_service.stop_recording(recording_id) if updated_recording is None: flask.abort(404) return flask.make_response( json.dumps(util.deep_asdict(updated_recording)), 200)
def recording_details(recording_id): recording = flask.current_app.system_control_service.get_recording( recording_id) if recording is not None: return flask.make_response( json.dumps(util.deep_asdict(recording)), 200) else: flask.abort(404)
def start_recording(): recording_config = domain.RecordingConfig( gateway_recording_configs=map( jem_data.dal.json_marshalling.unmarshall_gateway_recording_config, flask.request.json)) try: updated_recording = flask.current_app.system_control_service.start_recording(recording_config) return flask.make_response(json.dumps(util.deep_asdict(updated_recording)), 201) except jem_exceptions.SystemConflict, e: flask.abort(409)
def create(self, recording): '''Inserts a new recording, and creates a collection for its results. ''' data = util.deep_asdict(recording) self._collection.insert(data) new_id = str(data['_id']) try: self._db.create_collection('archive-%s' % new_id) except pymongo.errors.CollectionInvalid, e: raise jem_exceptions.PersistenceException(str(e))
def _insert_into_collection(msgs, mongo_collection): '''Write a bunch of messages to the given collection. Massages the data into the form expected to be stored. Ie, if the domain model changes, then this step keeps backward-compatibility. ''' ds = [util.deep_asdict(msg) for msg in msgs] # Rename a few fields, and promote some data up a level. for d in ds: d['device'] = d['table_addr']['device_addr'] d['device']['gateway'] = d['device']['gateway_addr'] del d['device']['gateway_addr'] d['table_id'] = d['table_addr']['id'] del d['table_addr'] mongo_collection.insert(ds)
def _merge_config_with_defaults(config): config = config[:] default_device_configs = devices.ALL for gateway in config: for device in gateway['devices']: if device['type'] not in default_device_configs: raise ValidationException( "Unknown device type: %s" % device['type']) table_defaults = dict( (t['id'], t) for t in util.deep_asdict( default_device_configs[device['type']])) table_overrides = dict( (t['id'], t) for t in device.get('tables', [])) _merge_tables(table_defaults, table_overrides) device['tables'] = table_defaults.values() gateways = _unmarshall_gateways(config) return gateways
def _raw_a40_tables(): return util.deep_asdict(devices.A40)