diff --git a/models/events/build.go b/models/events/build.go index b196938d..9215597e 100644 --- a/models/events/build.go +++ b/models/events/build.go @@ -1,11 +1,18 @@ package events import ( + "encoding/json" "time" "github.com/gofrs/uuid" + "gorm.io/gorm" ) +func (e *Event) BeforeCreate(tx *gorm.DB) (err error) { + e.ID, _ = uuid.NewV4() + return +} + type EventBuilder struct { event Event } @@ -40,8 +47,9 @@ func (e *EventBuilder) WithAction(eventAction string) *EventBuilder { return e } -func (e *EventBuilder) WithMetadata(metadata interface{}) *EventBuilder { - e.event.Metadata = metadata +func (e *EventBuilder) WithMetadata(metadata map[string]interface{}) *EventBuilder { + b, _ := json.Marshal(metadata) + e.event.Metadata = b return e } @@ -50,6 +58,11 @@ func (e *EventBuilder) WithSeverity(severity EventSeverity) *EventBuilder { return e } +func (e *EventBuilder) WithStatus(status string) *EventBuilder { + e.event.Status = status + return e +} + func (e *EventBuilder) FromUser(id uuid.UUID) *EventBuilder { e.event.UserID = &id return e diff --git a/models/events/events.go b/models/events/events.go index fa53cf91..95a6a12f 100644 --- a/models/events/events.go +++ b/models/events/events.go @@ -49,12 +49,15 @@ type Event struct { // Metadata Contains meaningful information, specific to the type of event. // Structure of metadata can be different for different events. - Metadata interface{} `db:"metadata" json:"metadata"` + Metadata []byte `db:"metadata" json:"metadata"` OperationID OperationID `db:"operation_id" json:"operation_id"` // Severity A set of seven standard event levels. Severity EventSeverity `db:"severity" json:"severity"` - SystemID SystemID `db:"system_id" json:"system_id"` + + // Status Status for the event. + Status string `db:"status" json:"status"` + SystemID SystemID `db:"system_id" json:"system_id"` // UpdatedAt Timestamp when the resource was updated. UpdatedAt UpdatedAt `db:"updated_at" json:"updated_at"` @@ -64,6 +67,22 @@ type Event struct { // EventSeverity A set of seven standard event levels. type EventSeverity string +// EventsFilter defines model for events_filter. +type EventsFilter struct { + Action []string `json:"action"` + Category []string `json:"category"` + Limit int `json:"limit"` + Offset int `json:"offset"` + + // Order order of sort asc/desc, default is asc + Order string `json:"order"` + Provider []string `json:"provider"` + Severity []string `json:"severity"` + + // SortOn Field on which records are sorted + SortOn string `json:"sort_on"` +} + // ID defines model for id. type ID = uuid.UUID @@ -81,10 +100,3 @@ type UpdatedAt = time.Time // UserID defines model for user_uuid. type UserID = uuid.UUID - -// EventsFilter defines model for eventsFilter. -type EventsFilter struct { - Action []string `json:"action"` - Category []string `json:"category"` - Provider []string `json:"provider"` -} \ No newline at end of file diff --git a/models/meshmodel/registry/host.go b/models/meshmodel/registry/host.go index 6101459c..1a1abab7 100644 --- a/models/meshmodel/registry/host.go +++ b/models/meshmodel/registry/host.go @@ -3,7 +3,6 @@ package registry import ( "errors" "fmt" - "strings" "time" "github.com/google/uuid" @@ -67,15 +66,15 @@ func (ah ArtifactHub) HandleDependents(comp v1alpha1.Component, kc *kubernetes.C }) if err != nil { if !isDeploy { - summary = fmt.Sprintf("error undeploying dependent resources for %s, please proceed with manual uninstall or try again: %s", strings.TrimSuffix(comp.Spec.Type, ".K8s"), comp.Name) + summary = fmt.Sprintf("error undeploying dependent helm chart for %s, please proceed with manual uninstall or try again", comp.Name) } else { - summary = fmt.Sprintf("error deploying dependent resources for %s, please procced with manual install or try again: %s", strings.TrimSuffix(comp.Spec.Type, ".K8s"), comp.Name) + summary = fmt.Sprintf("error deploying dependent helm chart for %s, please procced with manual install or try again", comp.Name) } } else { if !isDeploy { - summary = fmt.Sprintf("Undeployed helm chart%s: %s", strings.TrimSuffix(comp.Spec.Type, ".K8s"), comp.Name) + summary = fmt.Sprintf("Undeployed dependent helm chart for %s", comp.Name) } else { - summary = fmt.Sprintf("Deployed helm chart%s: %s", strings.TrimSuffix(comp.Spec.Type, ".K8s"), comp.Name) + summary = fmt.Sprintf("Deployed dependent helm chart for %s", comp.Name) } } }