Browse Source

Merge pull request #26 from denismakogon/better-logging

Issue #13: Improve logging in controllers
Derek Schultz 2 years ago
parent
commit
c7f89ebb7e

+ 61
- 26
picasso/api/controllers/apps.py View File

@@ -38,19 +38,20 @@ class AppV1Controller(controller.ServiceController):
38 38
         - application/json
39 39
         responses:
40 40
             "200":
41
-                description: successful operation. Return "apps" JSON
41
+                description: Successful operation\
42 42
             "401":
43
-                description: Not authorized.
43
+                description: Not authorized
44 44
         """
45 45
         c = config.Config.config_instance()
46 46
         log, fnclient = c.logger, c.functions_client
47 47
         project_id = request.match_info.get('project_id')
48
-        log.info("Listing apps for project: {}".format(project_id))
48
+        log.info("[{}] - Listing apps".format(project_id))
49 49
         stored_apps = await app_model.Apps.find_by(project_id=project_id)
50 50
         final = []
51 51
         for app in stored_apps:
52 52
             fn_app = await fnclient.apps.show(app.name, loop=c.event_loop)
53 53
             final.append(app_view.AppView(app, fn_app).view())
54
+        log.info("[{}] - Apps found: {}".format(project_id, final))
54 55
         return web.json_response(
55 56
             data={
56 57
                 self.controller_name: final,
@@ -80,9 +81,9 @@ class AppV1Controller(controller.ServiceController):
80 81
                 type: string
81 82
         responses:
82 83
             "200":
83
-                description: successful operation. Return "app" JSON
84
+                description: Successful operation
84 85
             "401":
85
-                description: Not authorized.
86
+                description: Not authorized
86 87
             "409":
87 88
                 description: App exists
88 89
         """
@@ -90,13 +91,15 @@ class AppV1Controller(controller.ServiceController):
90 91
         log, fnclient = c.logger, c.functions_client
91 92
         project_id = request.match_info.get('project_id')
92 93
         data = await request.json()
93
-        log.info("Creating an app for project: {} with data {}"
94
+        log.info("[{}] - Creating app with data '{}'"
94 95
                  .format(project_id, str(data)))
95 96
         app_name = "{}-{}".format(
96 97
             data["app"]["name"],
97 98
             project_id)[:30]
98 99
 
99 100
         if await app_model.Apps.exists(app_name, project_id):
101
+            log.info("[{}] - Similar app was found, "
102
+                     "aborting".format(project_id))
100 103
             return web.json_response(data={
101 104
                 "error": {
102 105
                     "message": "App {0} already exists".format(app_name)
@@ -104,13 +107,14 @@ class AppV1Controller(controller.ServiceController):
104 107
             }, status=409)
105 108
 
106 109
         fn_app = await fnclient.apps.create(app_name, loop=c.event_loop)
110
+        log.debug("[{}] - Fn app created".format(project_id))
107 111
         stored_app = await app_model.Apps(
108 112
             name=app_name, project_id=project_id,
109 113
             description=data["app"].get(
110 114
                 "description",
111 115
                 "App for project {}".format(
112 116
                     project_id))).save()
113
-
117
+        log.debug("[{}] - App created".format(project_id))
114 118
         return web.json_response(
115 119
             data={
116 120
                 "app": app_view.AppView(stored_app, fn_app).view(),
@@ -129,9 +133,9 @@ class AppV1Controller(controller.ServiceController):
129 133
         - application/json
130 134
         responses:
131 135
             "200":
132
-                description: successful operation. Return "app" JSON
136
+                description: Successful operation
133 137
             "401":
134
-                description: Not authorized.
138
+                description: Not authorized
135 139
             "404":
136 140
                 description: App not found
137 141
         """
@@ -139,10 +143,12 @@ class AppV1Controller(controller.ServiceController):
139 143
         log, fnclient = c.logger, c.functions_client
140 144
         project_id = request.match_info.get('project_id')
141 145
         app = request.match_info.get('app')
142
-        log.info("Requesting an app for project: {} with name {}"
146
+        log.info("[{}] - Searching for app with name {}"
143 147
                  .format(project_id, app))
144 148
 
145 149
         if not (await app_model.Apps.exists(app, project_id)):
150
+            log.info("[{}] - App not found, "
151
+                     "aborting".format(project_id))
146 152
             return web.json_response(data={
147 153
                 "error": {
148 154
                     "message": "App {0} not found".format(app),
@@ -151,7 +157,18 @@ class AppV1Controller(controller.ServiceController):
151 157
 
152 158
         stored_app = (await app_model.Apps.find_by(
153 159
             project_id=project_id, name=app)).pop()
154
-        fn_app = await fnclient.apps.show(app, loop=c.event_loop)
160
+        try:
161
+            fn_app = await fnclient.apps.show(app, loop=c.event_loop)
162
+            log.debug("[{}] - Fn app '{}' found".format(project_id, app))
163
+        except Exception as ex:
164
+            log.error("[{}] - Fn app '{}' was not found."
165
+                      "Reason: \n{}".format(project_id, app, str(ex)))
166
+            return web.json_response(data={
167
+                "error": {
168
+                    "message": getattr(ex, "reason", str(ex)),
169
+                }
170
+            }, status=getattr(ex, "status", 500))
171
+        log.debug("[{}] - App '{}' found".format(project_id, app))
155 172
         return web.json_response(
156 173
             data={
157 174
                 "app": app_view.AppView(stored_app, fn_app).view(),
@@ -171,29 +188,34 @@ class AppV1Controller(controller.ServiceController):
171 188
         - application/json
172 189
         responses:
173 190
             "200":
174
-                description: successful operation. Return "app" JSON
191
+                description: Successful operation
175 192
             "401":
176
-                description: Not authorized.
193
+                description: Not authorized
177 194
             "404":
178 195
                 description: App not found
179 196
         """
197
+        c = config.Config.config_instance()
198
+        log, fnclient = c.logger, c.functions_client
180 199
         project_id = request.match_info.get('project_id')
181 200
         app_name = request.match_info.get('app')
182 201
         data = await request.json()
183
-
202
+        log.info("[{}] - Setting up update procedure "
203
+                 "with data '{}'".format(project_id, data))
184 204
         if not (await app_model.Apps.exists(app_name, project_id)):
205
+            log.info("[{}] - App not found, "
206
+                     "aborting".format(project_id))
185 207
             return web.json_response(data={
186 208
                 "error": {
187 209
                     "message": "App {0} not found".format(app_name),
188 210
                 }
189 211
             }, status=404)
190 212
 
191
-        c = config.Config.config_instance()
192
-        fnclient = c.functions_client
193 213
         try:
194 214
             fn_app = await fnclient.apps.update(
195 215
                 app_name, loop=c.event_loop, **data)
196 216
         except Exception as ex:
217
+            log.info("[{}] - Unable to update app, "
218
+                     "aborting. Reason: \n{}".format(project_id, str(ex)))
197 219
             return web.json_response(data={
198 220
                 "error": {
199 221
                     "message": getattr(ex, "reason", str(ex)),
@@ -202,8 +224,8 @@ class AppV1Controller(controller.ServiceController):
202 224
 
203 225
         stored_app = (await app_model.Apps.find_by(
204 226
             project_id=project_id, name=app_name)).pop()
205
-        c.logger.info("Updating app {} for project: {} with data {}"
206
-                      .format(app_name, project_id, str(data)))
227
+        log.info("[{}] - Updating app {} with data {}"
228
+                 .format(project_id, app_name, str(data)))
207 229
         return web.json_response(
208 230
             data={
209 231
                 "app": app_view.AppView(stored_app, fn_app).view(),
@@ -223,27 +245,39 @@ class AppV1Controller(controller.ServiceController):
223 245
         - application/json
224 246
         responses:
225 247
             "200":
226
-                description: successful operation. Return empty JSON
248
+                description: Successful operation
227 249
             "401":
228
-                description: Not authorized.
250
+                description: Not authorized
229 251
             "404":
230
-                description: App does not exist
252
+                description: App not found
231 253
         """
232 254
         project_id = request.match_info.get('project_id')
233 255
         app = request.match_info.get('app')
234 256
         c = config.Config.config_instance()
235
-        fnclient = c.functions_client
257
+        log, fnclient = c.logger, c.functions_client
236 258
         if not (await app_model.Apps.exists(app, project_id)):
259
+            log.info("[{}] - App not found, "
260
+                     "aborting".format(project_id))
237 261
             return web.json_response(data={
238 262
                 "error": {
239 263
                     "message": "App {0} not found".format(app),
240 264
                 }
241 265
             }, status=404)
242
-
243
-        fn_app = await fnclient.apps.show(app, loop=c.event_loop)
244
-        fn_app_routes = await fn_app.routes.list(loop=c.event_loop)
266
+        try:
267
+            fn_app = await fnclient.apps.show(app, loop=c.event_loop)
268
+            fn_app_routes = await fn_app.routes.list(loop=c.event_loop)
269
+        except Exception as ex:
270
+            log.info("[{}] - Unable to get app, "
271
+                     "aborting. Reason: \n{}".format(project_id, str(ex)))
272
+            return web.json_response(data={
273
+                "error": {
274
+                    "message": getattr(ex, "reason", str(ex)),
275
+                }
276
+            }, status=getattr(ex, "status", 500))
245 277
 
246 278
         if fn_app_routes:
279
+            log.info("[{}] - App has routes, unable to delete it, "
280
+                     "aborting".format(project_id))
247 281
             return web.json_response(data={
248 282
                 "error": {
249 283
                     "message": ("Unable to delete app {} "
@@ -253,8 +287,9 @@ class AppV1Controller(controller.ServiceController):
253 287
 
254 288
         await app_model.Apps.delete(
255 289
             project_id=project_id, name=app)
290
+        log.debug("[{}] - App model entry gone".format(project_id))
256 291
         await fnclient.apps.delete(app, loop=c.event_loop)
257
-
292
+        log.debug("[{}] - Fn app deleted".format(project_id))
258 293
         return web.json_response(
259 294
             data={
260 295
                 "message": "App successfully deleted",

+ 90
- 55
picasso/api/controllers/routes.py View File

@@ -41,21 +41,23 @@ class AppRouteV1Controller(controller.ServiceController):
41 41
         - application/json
42 42
         responses:
43 43
             "200":
44
-                description: Successful operation. Return "routes" JSON
44
+                description: Successful operation
45 45
             "401":
46
-                description: Not authorized.
46
+                description: Not authorized
47 47
             "404":
48
-                description: App does not exist
48
+                description: App not found
49 49
         """
50 50
         c = config.Config.config_instance()
51 51
         log, fnclient = c.logger, c.functions_client
52 52
         project_id = request.match_info.get('project_id')
53 53
         app = request.match_info.get('app')
54 54
 
55
-        log.info("Listing app {} routes for project: {}."
55
+        log.info("[{}] - Listing app '{}' routes"
56 56
                  .format(app, project_id))
57 57
 
58 58
         if not (await app_model.Apps.exists(app, project_id)):
59
+            log.info("[{}] - App not found, "
60
+                     "aborting".format(project_id))
59 61
             return web.json_response(data={
60 62
                 "error": {
61 63
                     "message": "App {0} not found".format(app),
@@ -64,16 +66,16 @@ class AppRouteV1Controller(controller.ServiceController):
64 66
 
65 67
         fn_app_routes = (await (await fnclient.apps.show(
66 68
             app, loop=c.event_loop)).routes.list(loop=c.event_loop))
67
-
69
+        log.debug("[{}] - Fn routes found".format(project_id))
68 70
         for fn_route in fn_app_routes:
69 71
             stored_route = (await app_model.Routes.find_by(
70 72
                 app_name=app,
71 73
                 project_id=project_id,
72 74
                 path=fn_route.path)).pop()
75
+            log.debug("[{}] - App route '{}' model "
76
+                      "found".format(project_id, fn_route.path))
73 77
             setattr(fn_route, "is_public", stored_route.public)
74 78
 
75
-        log.info("Listing app {} routes for project: {}."
76
-                 .format(app, project_id))
77 79
         return web.json_response(data={
78 80
             "routes": app_view.AppRouteView(project_id,
79 81
                                             app,
@@ -109,11 +111,11 @@ class AppRouteV1Controller(controller.ServiceController):
109 111
                 type: boolean
110 112
         responses:
111 113
             "200":
112
-                description: Successful operation. Return "route" JSON
114
+                description: Successful operation
113 115
             "401":
114
-                description: Not authorized.
116
+                description: Not authorized
115 117
             "404":
116
-                description: App does not exist
118
+                description: App not found
117 119
             "409":
118 120
                 description: App route exists
119 121
         """
@@ -123,6 +125,8 @@ class AppRouteV1Controller(controller.ServiceController):
123 125
         app = request.match_info.get('app')
124 126
 
125 127
         if not (await app_model.Apps.exists(app, project_id)):
128
+            log.info("[{}] - App not found, "
129
+                     "aborting".format(project_id))
126 130
             return web.json_response(data={
127 131
                 "error": {
128 132
                     "message": "App {0} not found".format(app),
@@ -137,6 +141,8 @@ class AppRouteV1Controller(controller.ServiceController):
137 141
         try:
138 142
             fn_app = await fnclient.apps.show(app, loop=c.event_loop)
139 143
         except Exception as ex:
144
+            log.info("[{}] - App not found, "
145
+                     "aborting".format(project_id))
140 146
             return web.json_response(data={
141 147
                 "error": {
142 148
                     "message": getattr(ex, "reason", str(ex)),
@@ -145,6 +151,9 @@ class AppRouteV1Controller(controller.ServiceController):
145 151
 
146 152
         try:
147 153
             await fn_app.routes.show(path, loop=c.event_loop)
154
+            log.info("[{}] - Unable to create route. "
155
+                     "App route '{}' already "
156
+                     "exists, aborting".format(project_id, path))
148 157
             return web.json_response(data={
149 158
                 "error": {
150 159
                     "message": (
@@ -154,6 +163,8 @@ class AppRouteV1Controller(controller.ServiceController):
154 163
                 }
155 164
             }, status=409)
156 165
         except Exception as ex:
166
+            log.error("[{}] - Unable to create route. "
167
+                      "Reason:\n{}".format(project_id, str(ex)))
157 168
             if getattr(ex, "status", 500) != 404:
158 169
                 return web.json_response(data={
159 170
                     "error": {
@@ -161,27 +172,34 @@ class AppRouteV1Controller(controller.ServiceController):
161 172
                     }
162 173
                 }, status=getattr(ex, "status", 500))
163 174
 
164
-        new_fn_route = (await fn_app.routes.create(
165
-            **data, loop=c.event_loop))
166
-
167
-        stored_route = await app_model.Routes(
168
-            app_name=app,
169
-            project_id=project_id,
170
-            path=new_fn_route.path,
171
-            is_public=is_public).save()
172
-
173
-        log.info("Creating new route in app {} "
174
-                 "for project: {} with data {}"
175
-                 .format(app, project_id, str(data)))
176
-
177
-        setattr(new_fn_route, "is_public", stored_route.public)
178
-        view = app_view.AppRouteView(
179
-            project_id, app, [new_fn_route]).view_one()
180
-
181
-        return web.json_response(data={
182
-            "route": view,
183
-            "message": "App route successfully created"
184
-        }, status=200)
175
+        try:
176
+            new_fn_route = (await fn_app.routes.create(
177
+                **data, loop=c.event_loop))
178
+            log.debug("[{}] - Fn app created with data "
179
+                      "'{}'".format(project_id, str(data)))
180
+            stored_route = await app_model.Routes(
181
+                app_name=app,
182
+                project_id=project_id,
183
+                path=new_fn_route.path,
184
+                is_public=is_public).save()
185
+
186
+            setattr(new_fn_route, "is_public", stored_route.public)
187
+            view = app_view.AppRouteView(
188
+                project_id, app, [new_fn_route]).view_one()
189
+            log.info("[{}] - App created with data "
190
+                     "'{}'".format(project_id, str(view)))
191
+            return web.json_response(data={
192
+                "route": view,
193
+                "message": "App route successfully created"
194
+            }, status=200)
195
+        except Exception as ex:
196
+            log.error("[{}] - Reason:\n{}".format(project_id, str(ex)))
197
+            if getattr(ex, "status", 500) != 404:
198
+                return web.json_response(data={
199
+                    "error": {
200
+                        "message": getattr(ex, "reason", str(ex)),
201
+                    }
202
+                }, status=getattr(ex, "status", 500))
185 203
 
186 204
     @requests.api_action(
187 205
         method='GET', route='{project_id}/apps/{app}/routes/{route}')
@@ -195,13 +213,13 @@ class AppRouteV1Controller(controller.ServiceController):
195 213
         - application/json
196 214
         responses:
197 215
             "200":
198
-                description: Successful operation. Return "route" JSON
216
+                description: Successful operation
199 217
             "401":
200
-                description: Not authorized.
218
+                description: Not authorized
201 219
             "404":
202
-                description: App does not exist
220
+                description: App not found
203 221
             "404":
204
-                description: App route does not exist
222
+                description: App route not found
205 223
         """
206 224
         c = config.Config.config_instance()
207 225
         log, fnclient = c.logger, c.functions_client
@@ -210,6 +228,8 @@ class AppRouteV1Controller(controller.ServiceController):
210 228
         path = request.match_info.get('route')
211 229
 
212 230
         if not (await app_model.Apps.exists(app, project_id)):
231
+            log.info("[{}] - App not found, "
232
+                     "aborting".format(project_id))
213 233
             return web.json_response(data={
214 234
                 "error": {
215 235
                     "message": "App {0} not found".format(app),
@@ -221,14 +241,16 @@ class AppRouteV1Controller(controller.ServiceController):
221 241
             route = await fn_app.routes.show(
222 242
                 "/{}".format(path), loop=c.event_loop)
223 243
         except Exception as ex:
244
+            log.error("[{}] - Exception while attempting get route info. "
245
+                      "Reason:\n{}".format(project_id, str(ex)))
224 246
             return web.json_response(data={
225 247
                 "error": {
226 248
                     "message": getattr(ex, "reason", str(ex)),
227 249
                 }
228 250
             }, status=getattr(ex, "status", 500))
229 251
 
230
-        log.info("Requesting route {} in app {} for project: {}"
231
-                 .format(path, app, project_id))
252
+        log.info("[{}] - Requesting route '{}' in app '{}'"
253
+                 .format(project_id, path, app, ))
232 254
 
233 255
         stored_route = (await app_model.Routes.find_by(
234 256
             app_name=app,
@@ -237,10 +259,14 @@ class AppRouteV1Controller(controller.ServiceController):
237 259
 
238 260
         setattr(route, "is_public", stored_route.public)
239 261
 
262
+        view = app_view.AppRouteView(
263
+            project_id, app, [route]).view_one()
264
+
265
+        log.info("[{}] - Route found with data "
266
+                 "'{}'".format(project_id, view))
267
+
240 268
         return web.json_response(data={
241
-            "route": app_view.AppRouteView(project_id,
242
-                                           app,
243
-                                           [route]).view_one(),
269
+            "route": view,
244 270
             "message": "App route successfully loaded"
245 271
         }, status=200)
246 272
 
@@ -256,9 +282,9 @@ class AppRouteV1Controller(controller.ServiceController):
256 282
         - application/json
257 283
         responses:
258 284
             "200":
259
-                description: Successful operation. Return empty JSON
285
+                description: Successful operation
260 286
             "401":
261
-                description: Not authorized.
287
+                description: Not authorized
262 288
             "404":
263 289
                 description: App does not exist
264 290
             "404":
@@ -274,6 +300,8 @@ class AppRouteV1Controller(controller.ServiceController):
274 300
                  .format(path, app, project_id))
275 301
 
276 302
         if not (await app_model.Apps.exists(app, project_id)):
303
+            log.info("[{}] - App not found, "
304
+                     "aborting".format(project_id))
277 305
             return web.json_response(data={
278 306
                 "error": {
279 307
                     "message": "App {0} not found".format(app),
@@ -285,6 +313,8 @@ class AppRouteV1Controller(controller.ServiceController):
285 313
             route = await fn_app.routes.update(
286 314
                 "/{}".format(path), loop=c.event_loop, **data)
287 315
         except Exception as ex:
316
+            log.error("[{}] - Unable to update app. "
317
+                      "Reason:\n{}".format(project_id, str(ex)))
288 318
             return web.json_response(data={
289 319
                 "error": {
290 320
                     "message": getattr(ex, "reason", str(ex)),
@@ -298,11 +328,12 @@ class AppRouteV1Controller(controller.ServiceController):
298 328
 
299 329
         setattr(route, "is_public", stored_route.public)
300 330
 
331
+        view = app_view.AppRouteView(
332
+            project_id, app, [route]).view_one()
333
+        log.info("[{}] - App route update. "
334
+                 "Route data: {}".format(project_id, view))
301 335
         return web.json_response(data={
302
-            "route": app_view.AppRouteView(project_id,
303
-                                           app,
304
-                                           [route]).view_one(),
305
-
336
+            "route": view,
306 337
             "message": "Route successfully updated",
307 338
         }, status=200)
308 339
 
@@ -318,23 +349,25 @@ class AppRouteV1Controller(controller.ServiceController):
318 349
         - application/json
319 350
         responses:
320 351
             "200":
321
-                description: Successful operation. Return empty JSON
352
+                description: Successful operation
322 353
             "401":
323
-                description: Not authorized.
354
+                description: Not authorized
324 355
             "404":
325
-                description: App does not exist
356
+                description: App not found
326 357
             "404":
327
-                description: App route does not exist
358
+                description: App route not found
328 359
         """
329 360
         c = config.Config.config_instance()
330 361
         log, fnclient = c.logger, c.functions_client
331 362
         project_id = request.match_info.get('project_id')
332 363
         app = request.match_info.get('app')
333
-        path = request.match_info.get('route')
334
-        log.info("Deleting route {} in app {} for project: {}"
335
-                 .format(path, app, project_id))
364
+        path = "/{}".format(request.match_info.get('route'))
365
+        log.info("[{}] - Deleting app '{}' route '{}'"
366
+                 .format(project_id, app, path))
336 367
 
337 368
         if not (await app_model.Apps.exists(app, project_id)):
369
+            log.info("[{}] - App not found, "
370
+                     "aborting".format(project_id))
338 371
             return web.json_response(data={
339 372
                 "error": {
340 373
                     "message": "App {0} not found".format(app),
@@ -343,10 +376,12 @@ class AppRouteV1Controller(controller.ServiceController):
343 376
 
344 377
         try:
345 378
             fn_app = await fnclient.apps.show(app, loop=c.event_loop)
346
-            await fn_app.routes.show("/{}".format(path), loop=c.event_loop)
347
-            await fn_app.routes.delete("/{}".format(path), loop=c.event_loop)
379
+            await fn_app.routes.show(path, loop=c.event_loop)
380
+            await fn_app.routes.delete(path, loop=c.event_loop)
348 381
             await app_model.Routes.delete(project_id=project_id, app_name=app)
349 382
         except Exception as ex:
383
+            log.error("[{}] - Unable to delete app route '{}'. "
384
+                      "Reason:\n{}".format(project_id, path, str(ex)))
350 385
             return web.json_response(data={
351 386
                 "error": {
352 387
                     "message": getattr(ex, "reason", str(ex)),

+ 12
- 5
picasso/api/controllers/runnable.py View File

@@ -25,7 +25,7 @@ class RunnableMixin(object):
25 25
 
26 26
     async def run(self, request, **kwargs):
27 27
         c = config.Config.config_instance()
28
-        fnclient = c.functions_client
28
+        log, fnclient = c.logger, c.functions_client
29 29
         app = request.match_info.get('app')
30 30
         path = "/{}".format(request.match_info.get('route'))
31 31
 
@@ -43,6 +43,8 @@ class RunnableMixin(object):
43 43
             result = await fn_app.routes.execute(
44 44
                 path, loop=c.event_loop, **data)
45 45
         except Exception as ex:
46
+            log.error("Unable to execute route. "
47
+                      "Reason:\n{}".format(str(ex)))
46 48
             return web.json_response(data={
47 49
                 "error": {
48 50
                     "message": getattr(ex, "reason", str(ex)),
@@ -82,12 +84,13 @@ class PublicRunnableV1Controller(controller.ServiceController,
82 84
         - application/json
83 85
         responses:
84 86
             "200":
85
-                description: successful operation. Return "runnable" JSON
87
+                description: Successful operation
86 88
             "404":
87
-                description: App does not exist
89
+                description: App not found
88 90
             "403":
89 91
                 description: Unable to execute private route
90 92
         """
93
+        log = config.Config.config_instance().logger
91 94
         app = request.match_info.get('app')
92 95
         path = "/{}".format(request.match_info.get('route'))
93 96
         routes = await app_model.Routes.find_by(
@@ -102,6 +105,7 @@ class PublicRunnableV1Controller(controller.ServiceController,
102 105
         route = routes.pop()
103 106
 
104 107
         if not route.public:
108
+            log.info("Unable to execute private route '{}'".format(path))
105 109
             return web.json_response(data={
106 110
                 "error": {
107 111
                     "message": "Unable to execute private "
@@ -132,18 +136,21 @@ class RunnableV1Controller(controller.ServiceController,
132 136
         - application/json
133 137
         responses:
134 138
             "401":
135
-                description: Not authorized.
139
+                description: Not authorized
136 140
             "200":
137
-                description: successful operation. Return "runnable" JSON
141
+                description: Successful operation
138 142
             "404":
139 143
                 description: App not found
140 144
             "404":
141 145
                 description: App route not found
142 146
         """
147
+        log = config.Config.config_instance().logger
143 148
         app = request.match_info.get('app')
144 149
         project_id = request.match_info.get('project_id')
145 150
 
146 151
         if not (await app_model.Apps.exists(app, project_id)):
152
+            log.info("[{}] - App not found, "
153
+                     "aborting".format(project_id))
147 154
             return web.json_response(data={
148 155
                 "error": {
149 156
                     "message": "App {0} not found".format(app),

+ 11
- 11
picasso/common/persistence.py View File

@@ -28,9 +28,9 @@ class BaseDatabaseModel(object):
28 28
 
29 29
     def __init__(self, **kwargs):
30 30
         logger = config.Config.config_instance().logger
31
-        logger.info("Attempting to create object class instance "
32
-                    "'{}' with attributes '{}'"
33
-                    .format(str(self.__class__), str(kwargs)))
31
+        logger.debug("Attempting to create object class instance "
32
+                     "'{}' with attributes '{}'"
33
+                     .format(str(self.__class__), str(kwargs)))
34 34
         self.id = uuid.uuid4().hex
35 35
         self.created_at = str(datetime.datetime.now())
36 36
         self.updated_at = str(datetime.datetime.now())
@@ -44,13 +44,13 @@ class BaseDatabaseModel(object):
44 44
             self.table_name,
45 45
             str(tuple([getattr(self, clmn) for clmn in self.columns]))
46 46
         )
47
-        logger.info("Attempting to save object '{}' "
48
-                    "using SQL query: {}".format(self.table_name, insert))
47
+        logger.debug("Attempting to save object '{}' "
48
+                     "using SQL query: {}".format(self.table_name, insert))
49 49
         async with pool.acquire() as conn:
50 50
             async with conn.cursor() as cur:
51 51
                 await cur.execute(insert)
52 52
                 await conn.commit()
53
-        logger.info("Object saved.")
53
+        logger.debug("Object saved.")
54 54
         return self
55 55
 
56 56
     @classmethod
@@ -59,13 +59,13 @@ class BaseDatabaseModel(object):
59 59
         logger, pool = c.logger, c.connection.pool
60 60
         delete = cls.DELETE.format(
61 61
             cls.table_name, cls.__define_where(**kwargs))
62
-        logger.info("Attempting to delete object '{}' "
63
-                    "using SQL query: {}".format(cls.table_name, delete))
62
+        logger.debug("Attempting to delete object '{}' "
63
+                     "using SQL query: {}".format(cls.table_name, delete))
64 64
         async with pool.acquire() as conn:
65 65
             async with conn.cursor() as cur:
66 66
                 await cur.execute(delete)
67 67
                 await conn.commit()
68
-        logger.info("Object gone.")
68
+        logger.debug("Object gone.")
69 69
 
70 70
     # async def update(self, **kwargs):
71 71
     #     async with config.Connection.from_class().acquire() as conn:
@@ -99,8 +99,8 @@ class BaseDatabaseModel(object):
99 99
         where = cls.__define_where(**kwargs)
100 100
         select = cls.SELECT.format(
101 101
             cls.table_name, where)
102
-        logger.info("Attempting to find object(s) '{}' "
103
-                    "using SQL : {}".format(cls.table_name, select))
102
+        logger.debug("Attempting to find object(s) '{}' "
103
+                     "using SQL : {}".format(cls.table_name, select))
104 104
         async with pool.acquire() as conn:
105 105
             async with conn.cursor() as cur:
106 106
                 await cur.execute(select)

+ 15
- 0
picasso/models/app.py View File

@@ -27,6 +27,15 @@ class Apps(persistence.BaseDatabaseModel):
27 27
         "name"
28 28
     )
29 29
 
30
+    def __str__(self):
31
+        return ("<App name={name} ID={id} "
32
+                "description={description} "
33
+                "project_id={project_id}>".format(
34
+                    name=self.name,
35
+                    description=self.description,
36
+                    id=self.id,
37
+                    project_id=self.project_id))
38
+
30 39
 
31 40
 class Routes(persistence.BaseDatabaseModel):
32 41
 
@@ -43,3 +52,9 @@ class Routes(persistence.BaseDatabaseModel):
43 52
     @property
44 53
     def public(self):
45 54
         return True if self.is_public else False
55
+
56
+    def __str__(self):
57
+        return ("<App route path={path} project_id={project_id} "
58
+                "app={app_name} is_public={is_public} >".format(
59
+                    path=self.path, project_id=self.project_id,
60
+                    app_name=self.app_name, is_public=self.public))

Loading…
Cancel
Save