Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add raw methods for error and activity reporting by addons. #457

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (h *Adapter) Run(addon func() error) {
}()
//
// Report addon started.
h.Load()
h.Started()
//
// Run addon.
Expand Down
67 changes: 53 additions & 14 deletions addon/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/konveyor/tackle2-hub/api"
"github.com/konveyor/tackle2-hub/binding"
"github.com/konveyor/tackle2-hub/task"
"gopkg.in/yaml.v2"
"strings"
)

//
Expand Down Expand Up @@ -67,7 +69,6 @@ func (h *Task) Variant() string {
//
// Started report addon started.
func (h *Task) Started() {
h.Load()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved Load() to adapter.Run(). Makes more sense.

h.deleteReport()
h.report.Status = task.Running
h.pushReport()
Expand Down Expand Up @@ -109,31 +110,69 @@ func (h *Task) Failed(reason string, x ...interface{}) {
// Error report addon error.
// The description can be a printf style format.
func (h *Task) Error(severity, description string, x ...interface{}) {
h.report.Status = task.Failed
description = fmt.Sprintf(description, x...)
h.report.Errors = append(
h.report.Errors,
h.RawError(
api.TaskError{
Severity: severity,
Description: description,
})
h.pushReport()
return
}

//
// Activity report addon activity.
// The description can be a printf style format.
func (h *Task) Activity(entry string, x ...interface{}) {
entry = fmt.Sprintf(entry, x...)
h.report.Activity = append(
h.report.Activity,
entry)
func (h *Task) Activity(entry string, v ...interface{}) {
entry = fmt.Sprintf(entry, v...)
h.RawActivity(entry)
return
}

//
// RawError report addon error.
func (h *Task) RawError(error ...api.TaskError) {
h.report.Status = task.Failed
for i := range error {
h.report.Errors = append(
h.report.Errors,
error[i])
Log.Info(
"Addon reported: error.",
"error",
error[i])
}
h.pushReport()
return
}

//
// RawActivity report addon activity.
func (h *Task) RawActivity(object interface{}) {
switch object.(type) {
case string:
s := object.(string)
h.RawActivity(strings.Split(s, "\n"))
case []string:
prefix := ""
list := object.([]string)
if len(list) > 1 {
prefix = "> "
}
for i := range list {
entry := prefix + list[i]
h.report.Activity = append(
h.report.Activity,
entry)
Log.Info(
"Addon reported: activity.",
"object",
entry)
}
default:
b, _ := yaml.Marshal(object)
h.RawActivity(string(b))
}
h.pushReport()
Log.Info(
"Addon reported: activity.",
"activity",
h.report.Activity)
return
}

Expand Down
2 changes: 0 additions & 2 deletions hack/cmd/addon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ type SoftError = hub.SoftError
// main
func main() {
addon.Run(func() (err error) {
_, _ = addon.Identity.List()
_, _ = addon.Identity.Get(1)
//
// Get the addon data associated with the task.
d := &Data{}
Expand Down
Loading