You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by gi...@git.apache.org on 2017/09/14 21:36:51 UTC

[GitHub] mdeuser commented on a change in pull request #2604: Give more information in CLI Activation lists

mdeuser commented on a change in pull request #2604: Give more information in CLI Activation lists
URL: https://github.com/apache/incubator-openwhisk/pull/2604#discussion_r139015669
 
 

 ##########
 File path: tools/cli/go-whisk/whisk/activation.go
 ##########
 @@ -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, "/")
 
 Review comment:
   move this logic inside the if block (under line 148)..?
 
----------------------------------------------------------------
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