|
35 | 35 | class Applications(JsonHandler, PropertyHelper, PortHelper): |
36 | 36 | @gen.coroutine |
37 | 37 | 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) |
38 | 54 |
|
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} |
56 | 56 |
|
57 | | - self._render_json(info) |
| 57 | + self._render_json(info) |
| 58 | + except Exception as e: |
| 59 | + self._handle_request_exception(e) |
58 | 60 |
|
59 | 61 | @gen.coroutine |
60 | 62 | def post(self, domain_name, app_id=None): |
61 | | - data = json.loads(self.request.body) |
| 63 | + try: |
| 64 | + data = json.loads(self.request.body) |
62 | 65 |
|
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) |
65 | 68 |
|
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()}) |
69 | 76 | else: |
70 | | - app.stop() |
| 77 | + app_name = str(data['name']) |
71 | 78 |
|
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) |
75 | 81 |
|
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() |
78 | 85 |
|
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}) |
82 | 87 |
|
83 | | - self._render_json({'launched': app_id, 'applications': apps}) |
| 88 | + except Exception as e: |
| 89 | + self._handle_request_exception(e) |
84 | 90 |
|
85 | 91 | @gen.coroutine |
86 | 92 | def put(self, domain_name, app_id=None): |
87 | | - data = json.loads(self.request.body) |
| 93 | + try: |
| 94 | + data = json.loads(self.request.body) |
88 | 95 |
|
89 | | - app = yield self.redhawk.get_application(domain_name, app_id) |
| 96 | + app = yield self.redhawk.get_application(domain_name, app_id) |
90 | 97 |
|
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() |
96 | 103 |
|
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) |
98 | 107 |
|
99 | 108 | @gen.coroutine |
100 | 109 | 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) |
103 | 113 |
|
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