brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] brooklyn-client git commit: show bundle info and message when doing `catalog add`
Date Tue, 06 Jun 2017 15:55:28 GMT
Repository: brooklyn-client
Updated Branches:
  refs/heads/master 41edfec78 -> 005bd109b


show bundle info and message when doing `catalog add`

also supports backwards compatibility as only some API methods support the detail


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/a245052a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/a245052a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/a245052a

Branch: refs/heads/master
Commit: a245052a7e22e426fde4d0c1e1d62fd7105bacc2
Parents: 41edfec
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Jun 5 13:35:02 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Jun 5 14:04:47 2017 +0100

----------------------------------------------------------------------
 cli/api/catalog/catalog.go  | 26 ++++++++++++++++++--------
 cli/commands/catalog-add.go | 11 +++++++++--
 cli/models/catalog.go       |  9 ++++++++-
 3 files changed, 35 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/a245052a/cli/api/catalog/catalog.go
----------------------------------------------------------------------
diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go
index 108cf4b..d8132ca 100644
--- a/cli/api/catalog/catalog.go
+++ b/cli/api/catalog/catalog.go
@@ -215,9 +215,10 @@ func ZipResource(resource string) (*bytes.Buffer, error) {
 	return buf, err;
 }
 
-func AddCatalog(network *net.Network, resource string) (map[string]models.CatalogEntitySummary,
error) {
+func AddCatalog(network *net.Network, resource string) (*models.CatalogBundleAddResult, error)
{
 	urlString := "/v1/catalog"
-	var entities map[string]models.CatalogEntitySummary
+	urlStringWithDetail := urlString + "?detail=true"
+	var result models.CatalogBundleAddResult
 
 	//Force auto-detect by default
 	contentType := "application/octet-stream"
@@ -255,19 +256,25 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo
 			if err != nil {
 				return nil, err
 			}
-			body, err := network.SendPostRequestWithContentType(urlString, buf.Bytes(), "application/x-zip")
+			body, err := network.SendPostRequestWithContentType(urlStringWithDetail, buf.Bytes(),
"application/x-zip")
 			if err != nil {
 				return nil, err
 			}
-			err = json.Unmarshal(body, &entities)
-			return entities, err
+			err = json.Unmarshal(body, &result)
+			if result.Code == "" {
+				// older version of server, doesn't support detail
+				err = json.Unmarshal(body, &result.Types)
+			}
+			return &result, err
 		} else {
 			extension := filepath.Ext(resource)
 			lowercaseExtension := strings.ToLower(extension)
 			if lowercaseExtension == ".zip" {
 				contentType = "application/x-zip"
+				urlString = urlStringWithDetail
 			} else if lowercaseExtension == ".jar" {
 				contentType = "application/x-jar"
+				urlString = urlStringWithDetail
 			}
 		}
 
@@ -277,9 +284,12 @@ func AddCatalog(network *net.Network, resource string) (map[string]models.Catalo
 	if err != nil {
 		return nil, err
 	}
-	err = json.Unmarshal(body, &entities)
-
-	return entities, err
+	err = json.Unmarshal(body, &result)
+	if result.Code == "" {
+		// detail API not supported, just store the types
+		err = json.Unmarshal(body, &result.Types)
+	}
+	return &result, err
 }
 
 func GetLocation(network *net.Network, locationId string) (models.CatalogItemSummary, error)
{

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/a245052a/cli/commands/catalog-add.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-add.go b/cli/commands/catalog-add.go
index 0f67152..2e633ff 100644
--- a/cli/commands/catalog-add.go
+++ b/cli/commands/catalog-add.go
@@ -58,7 +58,14 @@ func (cmd *CatalogAdd) Run(scope scope.Scope, c *cli.Context) {
 	if nil != err {
 		error_handler.ErrorExit(err)
 	}
-	for id, _ := range create {
-		fmt.Println(id)
+	if "" != create.Message {
+		fmt.Println(create.Message)
+		for id, _ := range create.Types {
+			fmt.Printf("* %s\n", id)
+		}
+	} else {
+		for id, _ := range create.Types {
+			fmt.Println(id)
+		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/a245052a/cli/models/catalog.go
----------------------------------------------------------------------
diff --git a/cli/models/catalog.go b/cli/models/catalog.go
index edc6b0e..be6c443 100644
--- a/cli/models/catalog.go
+++ b/cli/models/catalog.go
@@ -54,6 +54,13 @@ type CatalogEntitySummary struct {
 	Sensors      []SensorSummary       `json:"sensors"`
 }
 
+type CatalogBundleAddResult struct {
+	Message      string                `json:"message"`
+	Bundle       string                `json:"bundle"`
+	Code         string                `json:"code"`
+	Types        map[string]CatalogItemSummary `json:"types"`
+}
+
 func createTableWithIdentityDetails(item IdentityDetails) (terminal.Table) {
 	table := terminal.NewTable([]string{"Id:", item.Id})
 	table.Add("Version:", item.Version)
@@ -184,4 +191,4 @@ func displayAsJson(v interface{}, jsonPath string) (err error) {
 		return eval.Error
 	}
 	return nil
-}
\ No newline at end of file
+}


Mime
View raw message