You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/10/25 19:10:57 UTC
[03/19] brooklyn-client git commit: Add catalog delete
Add catalog delete
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/b7eca931
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/b7eca931
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/b7eca931
Branch: refs/heads/master
Commit: b7eca9314ebf2c8e5efe81f2c23d6db97790b70d
Parents: 16eff1b
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Wed Oct 12 20:11:11 2016 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Wed Oct 12 20:11:11 2016 +0100
----------------------------------------------------------------------
cli/commands/catalog.go | 4 +++
cli/commands/delete-catalog-application.go | 34 +++++++++++++++++++++++++
cli/error_handler/error.go | 4 +++
cli/net/net.go | 34 ++++++++++++++++++++-----
4 files changed, 70 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/b7eca931/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index 6cfc324..7102b3a 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -39,14 +39,17 @@ func NewCatalog(network *net.Network) (cmd *Catalog) {
cmd.network = network
cmd.catalogCommands = map[string]command.Command {
ListCatalogCommand: NewCatalogList(cmd.network),
+ DeleteCatalogCommand: NewDeleteCatalogApplication(cmd.network),
}
return
}
const ListCatalogCommand = "list"
+const DeleteCatalogCommand = "delete"
var catalogCommands = []string{
ListCatalogCommand,
+ DeleteCatalogCommand,
}
var catalogCommandsUsage = strings.Join(catalogCommands, " | ")
@@ -66,6 +69,7 @@ func (cmd *Catalog) Metadata() command_metadata.CommandMetadata {
Flags: []cli.Flag{},
Operands: []command_metadata.CommandMetadata{
cmd.SubCommand(ListCatalogCommand).Metadata(),
+ cmd.SubCommand(DeleteCatalogCommand).Metadata(),
},
}
}
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/b7eca931/cli/commands/delete-catalog-application.go
----------------------------------------------------------------------
diff --git a/cli/commands/delete-catalog-application.go b/cli/commands/delete-catalog-application.go
index fd8ac3b..ef8c561 100644
--- a/cli/commands/delete-catalog-application.go
+++ b/cli/commands/delete-catalog-application.go
@@ -20,6 +20,12 @@ package commands
import (
"github.com/apache/brooklyn-client/cli/net"
+ "github.com/apache/brooklyn-client/cli/command_metadata"
+ "github.com/urfave/cli"
+ "github.com/apache/brooklyn-client/cli/scope"
+ "github.com/apache/brooklyn-client/cli/error_handler"
+ "strings"
+ "github.com/apache/brooklyn-client/cli/api/catalog"
)
type DeleteCatalogApplication struct {
@@ -31,3 +37,31 @@ func NewDeleteCatalogApplication(network *net.Network) (cmd *DeleteCatalogApplic
cmd.network = network
return
}
+
+func (cmd *DeleteCatalogApplication) Metadata() command_metadata.CommandMetadata {
+ return command_metadata.CommandMetadata{
+ Name: "delete",
+ Description: "delete the given catalog application",
+ Usage: "BROOKLYN_NAME catalog delete [APPLICATION_ID:VERSION]",
+ Flags: []cli.Flag{},
+ }
+}
+
+func (cmd *DeleteCatalogApplication) Run(scope scope.Scope, c *cli.Context) {
+ if err := net.VerifyLoginURL(cmd.network); err != nil {
+ error_handler.ErrorExit(err)
+ }
+ if len(c.Args()) != 1 {
+ error_handler.ErrorExit("command requires single argument APPLICATION_ID:VERSION")
+ }
+ appVersion := strings.Split(c.Args().First(), ":")
+ if len(appVersion) != 2 {
+ error_handler.ErrorExit("command requires single argument APPLICATION_ID:VERSION")
+ }
+ appId := appVersion[0]
+ version := appVersion[1]
+ _, err := catalog.DeleteApplicationWithVersion(cmd.network, appId, version)
+ if nil != err {
+ error_handler.ErrorExit(err)
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/b7eca931/cli/error_handler/error.go
----------------------------------------------------------------------
diff --git a/cli/error_handler/error.go b/cli/error_handler/error.go
index 8238c2b..e1f768a 100644
--- a/cli/error_handler/error.go
+++ b/cli/error_handler/error.go
@@ -21,6 +21,7 @@ package error_handler
import (
"fmt"
"os"
+ "github.com/apache/brooklyn-client/cli/net"
)
const CLIUsageErrorExitCode int = 1
@@ -29,6 +30,9 @@ const CLITrapErrorCode int = 3
func ErrorExit(errorvalue interface{}, errorcode ...int) {
switch errorvalue.(type) {
+ case net.HttpError:
+ httpError := errorvalue.(net.HttpError)
+ fmt.Fprintln(os.Stderr, httpError.Body)
case error:
fmt.Fprintln(os.Stderr, errorvalue)
case string:
http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/b7eca931/cli/net/net.go
----------------------------------------------------------------------
diff --git a/cli/net/net.go b/cli/net/net.go
index b35a6c3..b47d75a 100644
--- a/cli/net/net.go
+++ b/cli/net/net.go
@@ -84,10 +84,21 @@ func makeError(resp *http.Response, code int, body []byte) error {
Status: resp.Status,
Headers: resp.Header,
}
- details := make(map[string]string)
+ return makeErrorBody(theError, body)
+}
+
+func makeSimpleError(code int, body []byte) error {
+ theError := HttpError{
+ Code: code,
+ }
+ return makeErrorBody(theError, body)
+}
+
+func makeErrorBody(theError HttpError, body []byte) error {
+ details := make(map[string]interface{})
if err := json.Unmarshal(body, &details); nil == err {
if message, ok := details["message"]; ok {
- theError.Body = message
+ theError.Body = message.(string)
return theError
}
}
@@ -96,20 +107,25 @@ func makeError(resp *http.Response, code int, body []byte) error {
}
func (net *Network) SendRequest(req *http.Request) ([]byte, error) {
+ body, _, err := net.SendRequestGetStatusCode(req)
+ return body, err
+}
+
+func (net *Network) SendRequestGetStatusCode(req *http.Request) ([]byte, int, error) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: net.SkipSslChecks},
}
client := &http.Client{Transport: tr}
resp, err := client.Do(req)
if err != nil {
- return nil, err
+ return nil, 0, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if code, failed := unsuccessful(resp.Status); failed {
- return nil, makeError(resp, code, body)
+ return nil, 0, makeError(resp, code, body)
}
- return body, err
+ return body, resp.StatusCode, err
}
const httpSuccessSeriesFrom = 200
@@ -136,7 +152,13 @@ func (net *Network) SendGetRequest(url string) ([]byte, error) {
func (net *Network) SendDeleteRequest(url string) ([]byte, error) {
req := net.NewDeleteRequest(url)
- body, err := net.SendRequest(req)
+ body, code, err := net.SendRequestGetStatusCode(req)
+ if nil != err {
+ return nil, err
+ }
+ if code != http.StatusNoContent {
+ return nil, makeSimpleError(code, body)
+ }
return body, err
}