brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [04/19] brooklyn-client git commit: add catalog list for entities, locations, policies
Date Tue, 25 Oct 2016 19:10:58 GMT
add catalog list for entities, locations, policies


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

Branch: refs/heads/master
Commit: 72355dd9af88a5dfc4b35cbdbd761f907c5f2d43
Parents: b7eca93
Author: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Authored: Thu Oct 13 20:18:56 2016 +0100
Committer: Geoff Macartney <geoff.macartney@cloudsoftcorp.com>
Committed: Thu Oct 13 20:18:56 2016 +0100

----------------------------------------------------------------------
 cli/api/catalog/catalog.go   | 10 ++---
 cli/commands/catalog-list.go | 89 +++++++++++++++++++++++++++++++++++++--
 cli/commands/catalog.go      |  2 +-
 cli/models/catalog.go        | 31 ++++++--------
 4 files changed, 104 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/72355dd9/cli/api/catalog/catalog.go
----------------------------------------------------------------------
diff --git a/cli/api/catalog/catalog.go b/cli/api/catalog/catalog.go
index 3db32ce..6a017f5 100644
--- a/cli/api/catalog/catalog.go
+++ b/cli/api/catalog/catalog.go
@@ -150,15 +150,15 @@ func Policies(network *net.Network) ([]models.CatalogPolicySummary,
error) {
 	return policies, err
 }
 
-func Locations(network *net.Network) (models.CatalogLocationSummary, error) {
+func Locations(network *net.Network) ([]models.CatalogLocationSummary, error) {
 	url := "/v1/catalog/locations"
-	var catalogLocation models.CatalogLocationSummary
+	var catalogLocations []models.CatalogLocationSummary
 	body, err := network.SendGetRequest(url)
 	if err != nil {
-		return catalogLocation, err
+		return catalogLocations, err
 	}
-	err = json.Unmarshal(body, &catalogLocation)
-	return catalogLocation, err
+	err = json.Unmarshal(body, &catalogLocations)
+	return catalogLocations, err
 }
 
 func AddCatalog(network *net.Network, resource string) (string, error) {

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/72355dd9/cli/commands/catalog-list.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog-list.go b/cli/commands/catalog-list.go
index bb6efe3..5fa8414 100644
--- a/cli/commands/catalog-list.go
+++ b/cli/commands/catalog-list.go
@@ -26,6 +26,7 @@ import (
 	"github.com/apache/brooklyn-client/cli/scope"
 	"github.com/apache/brooklyn-client/cli/terminal"
 	"github.com/urfave/cli"
+	"github.com/apache/brooklyn-client/cli/models"
 )
 
 type CatalogList struct {
@@ -43,7 +44,24 @@ func (cmd *CatalogList) Metadata() command_metadata.CommandMetadata {
 		Name:        "list",
 		Description: "* List the available catalog applications",
 		Usage:       "BROOKLYN_NAME catalog list",
-		Flags:       []cli.Flag{},
+		Flags:       []cli.Flag{
+			cli.BoolFlag{
+				Name:  "applications, a",
+				Usage: "list applications (default)",
+			},
+			cli.BoolFlag{
+				Name:  "entities, e",
+				Usage: "list entities",
+			},
+			cli.BoolFlag{
+				Name:  "locations, l",
+				Usage: "list locations",
+			},
+			cli.BoolFlag{
+				Name:  "policies, p",
+				Usage: "list policies",
+			},
+		},
 	}
 }
 
@@ -51,13 +69,76 @@ func (cmd *CatalogList) Run(scope scope.Scope, c *cli.Context) {
 	if err := net.VerifyLoginURL(cmd.network); err != nil {
 		error_handler.ErrorExit(err)
 	}
-	catalog, err := catalog.Catalog(cmd.network)
+	summary, err := cmd.list(c)
 	if nil != err {
 		error_handler.ErrorExit(err)
 	}
 	table := terminal.NewTable([]string{"Id", "Name", "Description"})
-	for _, app := range catalog {
-		table.Add(app.Id, app.Name, app.Description)
+	for _, catalogItem := range summary {
+		table.Add(catalogItem.Id, catalogItem.Name, catalogItem.Description)
 	}
 	table.Print()
 }
+
+func (cmd *CatalogList) list(c *cli.Context) ([]models.IdentityDetails, error) {
+	if c.IsSet("entities") {
+		list, err := cmd.listEntities(c)
+		return list, err
+	} else if c.IsSet("locations") {
+		list, err := cmd.listLocations(c)
+		return list, err
+        } else if c.IsSet("policies") {
+		list, err := cmd.listPolicies(c)
+		return list, err
+	}
+	items, err := cmd.listCatalogItems(c)
+	return items, err
+}
+
+func (cmd *CatalogList) listPolicies(c *cli.Context) ([]models.IdentityDetails, error) {
+	policies, err := catalog.Policies(cmd.network)
+	if err != nil {
+		return nil, err
+	}
+	result := make([]models.IdentityDetails, len(policies))
+	for i, policy := range policies {
+		result[i] = policy.IdentityDetails
+	}
+	return result, nil
+}
+
+func (cmd *CatalogList) listLocations(c *cli.Context) ([]models.IdentityDetails, error) {
+	locations, err := catalog.Locations(cmd.network)
+	if err != nil {
+		return nil, err
+	}
+	result := make([]models.IdentityDetails, len(locations))
+	for i, location := range locations {
+		result[i] = location.CatalogItemSummary.IdentityDetails
+	}
+	return result, nil
+}
+
+func (cmd *CatalogList) listEntities(c *cli.Context) ([]models.IdentityDetails, error) {
+	entities, err := catalog.Entities(cmd.network)
+	if err != nil {
+		return nil, err
+	}
+	result := make([]models.IdentityDetails, len(entities))
+	for i, ent := range entities {
+		result[i] = ent.IdentityDetails
+	}
+	return result, nil
+}
+
+func (cmd *CatalogList) listCatalogItems(c *cli.Context) ([]models.IdentityDetails, error)
{
+	items, err := catalog.Catalog(cmd.network)
+	if err != nil {
+		return nil, err
+	}
+	result := make([]models.IdentityDetails, len(items))
+	for i, item := range items {
+		result[i] = item.IdentityDetails
+	}
+	return result, nil
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/72355dd9/cli/commands/catalog.go
----------------------------------------------------------------------
diff --git a/cli/commands/catalog.go b/cli/commands/catalog.go
index 7102b3a..c197c21 100644
--- a/cli/commands/catalog.go
+++ b/cli/commands/catalog.go
@@ -78,6 +78,6 @@ func (cmd *Catalog) Run(scope scope.Scope, c *cli.Context) {
 	if err := net.VerifyLoginURL(cmd.network); err != nil {
 		error_handler.ErrorExit(err)
 	}
-	fmt.Printf("Unrecognised instruction, please use one of (%s)\n", catalogCommandsUsage)
+ 	fmt.Printf("'catalog' requires one of (%s)\n", catalogCommandsUsage)
 
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/72355dd9/cli/models/catalog.go
----------------------------------------------------------------------
diff --git a/cli/models/catalog.go b/cli/models/catalog.go
index ef6dabf..ff537c8 100644
--- a/cli/models/catalog.go
+++ b/cli/models/catalog.go
@@ -18,46 +18,41 @@
  */
 package models
 
-type CatalogItemSummary struct {
+type IdentityDetails struct {
+	Id           string                 `json:"id"`
 	Name         string                 `json:"name"`
-	JavaType     string                 `json:"javaType"`
 	SymbolicName string                 `json:"symbolicName"`
 	Version      string                 `json:"version"`
-	PlanYaml     string                 `json:"planYaml"`
 	Description  string                 `json:"description"`
+}
+
+type CatalogItemSummary struct {
+	IdentityDetails
+	JavaType     string                 `json:"javaType"`
+	PlanYaml     string                 `json:"planYaml"`
 	Deprecated   bool                   `json:"deprecated"`
 	Links        map[string]interface{} `json:"links"`
-	Id           string                 `json:"id"`
 	Type         string                 `json:"type"`
 }
 
 type CatalogPolicySummary struct {
-	symbolicName string         `json:"symbolicName"`
-	version      string         `json:"version"`
-	displayName  string         `json:"name"`
+	IdentityDetails
 	javaType     string         `json:"javaType"`
 	planYaml     string         `json:"planYaml"`
-	description  string         `json:"description"`
 	iconUrl      string         `json:"iconUrl"`
 	deprecated   bool           `json:"deprecated"`
 	links        map[string]URI `json:"links"`
 }
 
+
 type CatalogLocationSummary struct {
+	CatalogItemSummary
+	IconUrl     string                 `json:"iconUrl"`
 }
 
 type CatalogEntitySummary struct {
-	symbolicName string                 `json:"symbolicName"`
-	version      string                 `json:"version"`
-	displayName  string                 `json:"name"`
-	javaType     string                 `json:"javaType"`
-	planYaml     string                 `json:"planYaml"`
-	description  string                 `json:"description"`
+	CatalogItemSummary
 	Config       []ConfigSummary        `json:"config"`
 	Effectors    []EffectorSummary      `json:"effectors"`
 	Sensors      []SensorSummary        `json:"sensors"`
-	Deprecated   bool                   `json:"deprecated"`
-	Links        map[string]interface{} `json:"links"`
-	Id           string                 `json:"id"`
-	Type         string                 `json:"type"`
 }


Mime
View raw message