From 78f2d51bfadedb6688672a633c083d8b4cb002a2 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Mon, 11 Sep 2017 12:25:32 +0300 Subject: [PATCH] Implementing force delete for apps Deployment-Impact: DB schema changed API Impact: HTTP DELETE /apps/{app} accepts query parameters: /apps/{app}?force=True Closes: #302 --- api/datastore/sql/sql.go | 5 +++-- api/server/apps_delete.go | 15 +++++++++++---- docs/swagger.yml | 12 +++++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/api/datastore/sql/sql.go b/api/datastore/sql/sql.go index c2e61325f..a7ba76ce8 100644 --- a/api/datastore/sql/sql.go +++ b/api/datastore/sql/sql.go @@ -610,8 +610,9 @@ func (ds *sqlStore) GetLog(ctx context.Context, appName, callID string) (*models } return &models.CallLog{ - CallID: callID, - Log: log, + CallID: callID, + Log: log, + AppName: appName, }, nil } diff --git a/api/server/apps_delete.go b/api/server/apps_delete.go index 708a4dc65..a572ee5fa 100644 --- a/api/server/apps_delete.go +++ b/api/server/apps_delete.go @@ -7,6 +7,7 @@ import ( "github.com/fnproject/fn/api/common" "github.com/fnproject/fn/api/models" "github.com/gin-gonic/gin" + "strconv" ) func (s *Server) handleAppDelete(c *gin.Context) { @@ -21,10 +22,16 @@ func (s *Server) handleAppDelete(c *gin.Context) { handleErrorResponse(c, err) return } - //TODO allow this? #528 - if len(routes) > 0 { - handleErrorResponse(c, models.ErrDeleteAppsWithRoutes) - return + forceDelete, _ := strconv.ParseBool(c.Query("force")) + if !forceDelete { + if len(routes) > 0 { + handleErrorResponse(c, models.ErrDeleteAppsWithRoutes) + return + } + } else { + s.Datastore.BatchDeleteLogs(ctx, app.Name) + s.Datastore.BatchDeleteCalls(ctx, app.Name) + s.Datastore.BatchDeleteRoutes(ctx, app.Name) } err = s.FireBeforeAppDelete(ctx, app) diff --git a/docs/swagger.yml b/docs/swagger.yml index d91e8e53a..7b149a4c7 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -73,11 +73,17 @@ paths: tags: - Apps parameters: - - name: app - in: path + - in: path + name: app description: Name of the app. required: true - type: string + schema: + type: string + - in: query + name: force + schema: + type: bool + description: Query parameter that enables force delete for app responses: 200: description: Apps successfully deleted.