Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

api: add support for deleting apps #327

Merged
merged 5 commits into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions api/models/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
type Apps []*App

var (
ErrAppsAlreadyExists = errors.New("App already exists")
ErrAppsCreate = errors.New("Could not create app")
ErrAppsUpdate = errors.New("Could not update app")
ErrAppsRemoving = errors.New("Could not remove app from datastore")
ErrAppsGet = errors.New("Could not get app from datastore")
ErrAppsList = errors.New("Could not list apps from datastore")
ErrAppsAlreadyExists = errors.New("App already exists")
ErrAppsMissingNew = errors.New("Missing new application")
ErrAppsNotFound = errors.New("App not found")
ErrAppsNothingToUpdate = errors.New("Nothing to update")
ErrAppsMissingNew = errors.New("Missing new application")
ErrAppsRemoving = errors.New("Could not remove app from datastore")
ErrAppsPendingRoutes = errors.New("App with pending routes")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by pending routes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just mean it has routes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this just mean it has routes?

Gonna improve the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ErrAppsUpdate = errors.New("Could not update app")
ErrUsableImage = errors.New("Image not found")
)

Expand Down
14 changes: 13 additions & 1 deletion api/server/apps_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@ func handleAppDelete(c *gin.Context) {
log := common.Logger(ctx)

appName := c.Param("app")
err := Api.Datastore.RemoveApp(appName)

routes, err := Api.Datastore.GetRoutesByApp(appName, &models.RouteFilter{})
if err != nil {
log.WithError(err).Debug(models.ErrAppsRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
return
}

if len(routes) > 0 {
log.WithError(err).Debug(models.ErrAppsPendingRoutes)
c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsPendingRoutes))
return
}

if err := Api.Datastore.RemoveApp(appName); err != nil {
log.WithError(err).Debug(models.ErrAppsRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsRemoving))
return
}

c.JSON(http.StatusOK, gin.H{"message": "App deleted"})
}
18 changes: 16 additions & 2 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ swagger: '2.0'
info:
title: IronFunctions
description: The open source serverless platform.
version: "0.1.0"
version: "0.1.17"
# the domain of the service
host: "127.0.0.1:8080"
# array of all schemes that your API supports
Expand Down Expand Up @@ -67,6 +67,20 @@ paths:


/apps/{app}:
delete:
summary: "Delete an app."
description: "Delete an app."
tags:
- Apps
parameters:
- name: app
in: path
description: Name of the app.
required: true
type: string
responses:
200:
description: Apps successfully deleted.
get:
summary: "Get information for a app."
description: "This gives more details about a app, such as statistics."
Expand Down Expand Up @@ -232,7 +246,7 @@ paths:
type: string
responses:
200:
description: Route successfully deleted. Deletion succeeds even on routes that do not exist.
description: Route successfully deleted.

/tasks:
get:
Expand Down
39 changes: 34 additions & 5 deletions fn/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -64,12 +65,17 @@ func apps() cli.Command {
},
},
},
{
Name: "delete",
Usage: "delete an app",
Action: a.delete,
},
},
}
}

func (a *appsCmd) list(c *cli.Context) error {
if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -95,7 +101,7 @@ func (a *appsCmd) create(c *cli.Context) error {
return errors.New("error: app creating takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -117,7 +123,7 @@ func (a *appsCmd) configList(c *cli.Context) error {
return errors.New("error: app description takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -157,7 +163,7 @@ func (a *appsCmd) configSet(c *cli.Context) error {
return errors.New("error: application configuration setting takes three arguments: an app name, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -191,7 +197,7 @@ func (a *appsCmd) configUnset(c *cli.Context) error {
return errors.New("error: application configuration setting takes three arguments: an app name, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -234,3 +240,26 @@ func (a *appsCmd) storeApp(appName string, config map[string]string) error {
}
return nil
}

func (a *appsCmd) delete(c *cli.Context) error {
appName := c.Args().First()
if appName == "" {
return errors.New("error: deleting an app takes one argument, an app name")
}

if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

resp, err := a.AppsAppDelete(appName)
if err != nil {
return fmt.Errorf("error deleting app: %v", err)
}

if resp.StatusCode == http.StatusBadRequest {
return errors.New("could not delete this application - pending routes")
}

fmt.Println(appName, "deleted")
return nil
}
2 changes: 1 addition & 1 deletion fn/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (p publishcmd) dockerpush(ff *funcfile) error {
}

func (p *publishcmd) route(path string, ff *funcfile) error {
if err := resetBasePath(&p.Configuration); err != nil {
if err := resetBasePath(p.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down
14 changes: 7 additions & 7 deletions fn/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (a *routesCmd) list(c *cli.Context) error {
return errors.New("error: routes listing takes one argument, an app name")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (a *routesCmd) call(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a route")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func (a *routesCmd) create(c *cli.Context) error {
return errors.New("error: routes creation takes three arguments: an app name, a route path and an image")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -253,7 +253,7 @@ func (a *routesCmd) delete(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a path")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand All @@ -273,7 +273,7 @@ func (a *routesCmd) configList(c *cli.Context) error {
return errors.New("error: route configuration description takes two arguments: an app name and a route")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -314,7 +314,7 @@ func (a *routesCmd) configSet(c *cli.Context) error {
return errors.New("error: route configuration setting takes four arguments: an app name, a route, a key and a value")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down Expand Up @@ -354,7 +354,7 @@ func (a *routesCmd) configUnset(c *cli.Context) error {
return errors.New("error: route configuration setting takes four arguments: an app name, a route and a key")
}

if err := resetBasePath(&a.Configuration); err != nil {
if err := resetBasePath(a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}

Expand Down