You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/12/10 13:09:37 UTC
[GitHub] rabbah closed pull request #2604: Give more information in CLI Activation lists
rabbah closed pull request #2604: Give more information in CLI Activation lists
URL: https://github.com/apache/incubator-openwhisk/pull/2604
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/docs/apigateway.md b/docs/apigateway.md
index 609656d4e8..beaafb742f 100644
--- a/docs/apigateway.md
+++ b/docs/apigateway.md
@@ -149,6 +149,8 @@ Action: deleteBooks
URL: https://${APIHOST}:9001/api/21ef035/club/books
```
+**Note**: You can order the list of APIs alphabetically (by order of `Base Path`, then `Path`, and then `Verb`) by using the flag `--order`. Furthermore, you can sort by action name alphabetically using `--order` in conjunction with `--order-action`. For a detailed example, see [listing actions](./actions.md#listing-actions)
+
Now just for fun let's add a new book `JavaScript: The Good Parts` with a HTTP __POST__
```
curl -X POST -d '{"name":"JavaScript: The Good Parts", "isbn":"978-0596517748"}' https://${APIHOST}:9001/api/21ef035/club/books
diff --git a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
index 200d7a114f..1d455c6b49 100644
--- a/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
+++ b/tests/src/test/scala/apigw/healthtests/ApiGwEndToEndTests.scala
@@ -173,4 +173,5 @@ class ApiGwEndToEndTests
)
}
}
+
}
diff --git a/tools/cli/go-whisk-cli/commands/activation.go b/tools/cli/go-whisk-cli/commands/activation.go
index 59e84fe82b..0189af93e2 100644
--- a/tools/cli/go-whisk-cli/commands/activation.go
+++ b/tools/cli/go-whisk-cli/commands/activation.go
@@ -93,6 +93,7 @@ var activationListCmd = &cobra.Command{
if options.Docs == true {
printFullActivationList(activations)
} else {
+ activations = makeListableActs(activations)
printList(activations, false) // Default sorting for Activations are by creation time, hence sortByName is always false
}
@@ -100,6 +101,31 @@ var activationListCmd = &cobra.Command{
},
}
+func makeListableActs(activations []whisk.Activation) []whisk.Activation {
+ maxEntityLength := len("name")
+ for i := range activations {
+ if len(activations[i].Name) > maxEntityLength {
+ maxEntityLength = len(activations[i].Name)
+ }
+ }
+ if maxEntityLength > 50 {
+ maxEntityLength = 50
+ }
+ for i, activation := range activations {
+ activationInfo, _, err := client.Activations.Get(activation.ActivationID)
+ if err != nil {}
+ activations[i].Status = activationInfo.Status
+ activations[i].Start = activationInfo.Start
+ activations[i].End = activationInfo.End
+ activations[i].Duration = activationInfo.Duration
+ activations[i].Response.Status = activationInfo.Response.Status
+ activations[i].Cause = activationInfo.Cause
+ activations[i].EntityType = activationInfo.EntityType
+ activations[i].BufferSize = maxEntityLength
+ }
+ return activations
+}
+
var activationGetCmd = &cobra.Command{
Use: "get (ACTIVATION_ID | --last) [FIELD_FILTER]",
Short: wski18n.T("get activation"),
diff --git a/tools/cli/go-whisk-cli/commands/api.go b/tools/cli/go-whisk-cli/commands/api.go
index bd60492ff4..8cb9d6a557 100644
--- a/tools/cli/go-whisk-cli/commands/api.go
+++ b/tools/cli/go-whisk-cli/commands/api.go
@@ -41,6 +41,8 @@ const (
formatOptionYaml = "yaml"
formatOptionJson = "json"
+
+ orderActionFlag = "a"
)
var apiCmd = &cobra.Command{
diff --git a/tools/cli/go-whisk-cli/commands/flags.go b/tools/cli/go-whisk-cli/commands/flags.go
index 15f9ed46c0..19cb1a1e5c 100644
--- a/tools/cli/go-whisk-cli/commands/flags.go
+++ b/tools/cli/go-whisk-cli/commands/flags.go
@@ -120,6 +120,7 @@ type Flags struct {
basepath string
apiname string
configfile string
+ orderAction bool
resptype string
}
}
diff --git a/tools/cli/go-whisk/whisk/action.go b/tools/cli/go-whisk/whisk/action.go
index 8b17d23617..40ed5caf13 100644
--- a/tools/cli/go-whisk/whisk/action.go
+++ b/tools/cli/go-whisk/whisk/action.go
@@ -22,9 +22,9 @@ import (
"net/http"
"errors"
"net/url"
- "strings"
"../wski18n"
+ "strings"
)
type ActionService struct {
@@ -42,6 +42,7 @@ type Action struct {
Error string `json:"error,omitempty"`
Code int `json:"code,omitempty"`
Publish *bool `json:"publish,omitempty"`
+ Flag string
}
type Exec struct {
diff --git a/tools/cli/go-whisk/whisk/activation.go b/tools/cli/go-whisk/whisk/activation.go
index c36cdbec54..924226bd89 100644
--- a/tools/cli/go-whisk/whisk/activation.go
+++ b/tools/cli/go-whisk/whisk/activation.go
@@ -23,6 +23,10 @@ import (
"errors"
"net/url"
"../wski18n"
+ "time"
+ "strconv"
+ "regexp"
+ "strings"
)
type ActivationService struct {
@@ -43,6 +47,8 @@ type Activation struct {
Logs []string `json:"logs"`
Annotations KeyValueArr `json:"annotations"`
Publish *bool `json:"publish,omitempty"`
+ BufferSize int `json:",omitempty"`
+ EntityType string `json:"entityType"`
}
type Response struct {
@@ -80,14 +86,74 @@ func(activation Activation) Compare(sortable Sortable) (bool) {
// ToHeaderString() returns the header for a list of activations
func(activation Activation) ToHeaderString() string {
- return fmt.Sprintf("%s\n", "activations")
+ defaultHeader := fmt.Sprintf(
+ "%-32s %-"+strconv.Itoa(activation.BufferSize)+"s %-7s %-9s %-10s %-8s %-13s %s\n",
+ "activation id",
+ "name",
+ "type",
+ "start date",
+ "start time",
+ "end time",
+ "duration (ms)",
+ "status")
+ return fmt.Sprintf("%s\n%s", "activations", defaultHeader)
}
+//func getLargestAction(activations []Activation)
+
// ToSummaryRowString() returns a compound string of required parameters for printing
// from CLI command `wsk activation list`.
// ***Method of type Sortable***
func(activation Activation) ToSummaryRowString() string {
- return fmt.Sprintf("%s %-20s\n", activation.ActivationID, activation.Name)
+ // Convert time from milliseconds into human readable format
+ start := time.Unix(activation.Start / 1000, 0)
+ end := time.Unix(activation.End / 1000, 0)
+ name := getEntityName(activation.Annotations, activation.Name)
+ if len(name) > 50 {
+ name = name[:47] + "..."
+ }
+
+ return fmt.Sprintf("%-32s %-"+strconv.Itoa(activation.BufferSize)+"s %-7s %9s %10s %8s %13v %v\n",
+ activation.ActivationID,
+ name,
+ activation.EntityType,
+ start.Format("2006-01-02"), // Formatted Start date
+ start.Format("15:04:05"), // Formatted Start time
+ formatEndTime(end, activation.EntityType), // Formatted End Time
+ formatDuration(activation.Duration, activation.EntityType),
+ activation.Response.Status)
+}
+
+func formatEndTime(end time.Time, entityType string) string {
+ if entityType == "action" {
+ return end.Format("15:04:05")
+ }
+ return "--:--:--"
+}
+
+func formatDuration(duration int64, entityType string) string {
+ if entityType == "action" {
+ return fmt.Sprintf("%v", duration)
+ }
+ return "-"
+}
+
+func getEntityName(annotations KeyValueArr, name string) string {
+ var entityName []string
+ var entityPath string
+ delimiter := regexp.MustCompile("/")
+
+ for i := range annotations {
+ if annotations[i].Key == "path" {
+ entityPath = annotations[i].Value.(string)
+ }
+ }
+ if entityPath != "" && len(delimiter.FindAllString(entityPath, -1)) > 1 {
+ entityName = strings.Split(entityPath, "/")
+ return strings.Join(entityName[1:], "/")
+ }
+
+ return name
}
func (s *ActivationService) List(options *ActivationListOptions) ([]Activation, *http.Response, error) {
diff --git a/tools/cli/go-whisk/whisk/api.go b/tools/cli/go-whisk/whisk/api.go
index cc11118dcc..e34d9f9e23 100644
--- a/tools/cli/go-whisk/whisk/api.go
+++ b/tools/cli/go-whisk/whisk/api.go
@@ -179,6 +179,7 @@ var ApiVerbs map[string]bool = map[string]bool {
const (
Overwrite = true
DoNotOverwrite = false
+ orderActionFlag = "n"
)
/////////////////
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services