Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #170 from MUzairS15/error-details
Browse files Browse the repository at this point in the history
Send detailed error response to client
  • Loading branch information
Revolyssup authored Aug 26, 2022
2 parents 2144a66 + 92f5974 commit 15d6095
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace (
)

require (
github.com/layer5io/meshery-adapter-library v0.5.8
github.com/layer5io/meshery-adapter-library v0.5.9
github.com/layer5io/meshkit v0.5.32
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
github.com/layer5io/kuttl v0.4.1-0.20200806180306-b7e46afd657f/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
github.com/layer5io/meshery-adapter-library v0.5.8 h1:usu2OKaytOHRLHiLNeybX5MkQ7rMsqYzJIjvDkh7UgY=
github.com/layer5io/meshery-adapter-library v0.5.8/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
github.com/layer5io/meshery-adapter-library v0.5.9 h1:Zp79l4J8kMjML9zAQ4Xu4QiKM5q5HEGcv04Jjg+xWSA=
github.com/layer5io/meshery-adapter-library v0.5.9/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
github.com/layer5io/meshkit v0.5.32 h1:jIkQ9gKH7TPMWKbVtf6wQ+qv4553UyZ9SV4yKA2D4oo=
github.com/layer5io/meshkit v0.5.32/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
Expand Down
49 changes: 29 additions & 20 deletions osm/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/common"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshery-adapter-library/status"
internalconfig "github.com/layer5io/meshery-osm/internal/config"
"github.com/layer5io/meshkit/errors"
)

// ApplyOperation function contains the operation handlers
Expand All @@ -24,22 +26,23 @@ func (h *Handler) ApplyOperation(ctx context.Context, request adapter.OperationR
return err
}

e := &adapter.Event{
Operationid: request.OperationID,
e := &meshes.EventsResponse{
OperationId: request.OperationID,
Summary: status.Deploying,
Details: "Operation is not supported",
Component: internalconfig.ServerDefaults["type"],
ComponentName: internalconfig.ServerDefaults["name"],
}

//deployment
switch request.OperationName {
case internalconfig.OSMOperation:
go func(hh *Handler, ee *adapter.Event) {
go func(hh *Handler, ee *meshes.EventsResponse) {
version := string(operations[request.OperationName].Versions[0])
stat, err := hh.installOSM(request.IsDeleteOperation, version, request.Namespace, kubeconfigs)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s Open service mesh", stat)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s Open service mesh", stat)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("Open service mesh %s successfully", stat)
Expand All @@ -51,21 +54,20 @@ func (h *Handler) ApplyOperation(ctx context.Context, request adapter.OperationR
common.HTTPBinOperation,
common.ImageHubOperation,
common.EmojiVotoOperation:
go func(hh *Handler, ee *adapter.Event) {
go func(hh *Handler, ee *meshes.EventsResponse) {
appName := operations[request.OperationName].AdditionalProperties[common.ServiceName]
stat, err := hh.installSampleApp(request.IsDeleteOperation, request.Namespace, operations[request.OperationName].Templates, kubeconfigs)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s %s application", stat, appName)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("%s application %s successfully", appName, stat)
ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat)
hh.StreamInfo(e)
}(h, e)
case internalconfig.OSMBookStoreOperation:
go func(hh *Handler, ee *adapter.Event) {
go func(hh *Handler, ee *meshes.EventsResponse) {
version := string(operations[request.OperationName].Versions[0])
appName := operations[request.OperationName].AdditionalProperties[common.ServiceName]
stat, err := hh.installOSMBookStoreSampleApp(
Expand All @@ -75,21 +77,20 @@ func (h *Handler) ApplyOperation(ctx context.Context, request adapter.OperationR
kubeconfigs,
)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s %s application", stat, appName)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("%s application %s successfully", appName, stat)
ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat)
hh.StreamInfo(e)
}(h, e)
case common.SmiConformanceOperation:
go func(hh *Handler, ee *adapter.Event) {
go func(hh *Handler, ee *meshes.EventsResponse) {
name := operations[request.OperationName].Description
_, err := hh.RunSMITest(adapter.SMITestOptions{
Ctx: context.TODO(),
OperationID: ee.Operationid,
OperationID: ee.OperationId,
Manifest: string(operations[request.OperationName].Templates[0]),
Namespace: "meshery",
Labels: map[string]string{
Expand All @@ -98,17 +99,25 @@ func (h *Handler) ApplyOperation(ctx context.Context, request adapter.OperationR
Annotations: make(map[string]string),
})
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s test", status.Running, name)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s %s test", status.Running, name)
hh.streamErr(summary ,e, err)
return
}
ee.Summary = fmt.Sprintf("%s test %s successfully", name, status.Completed)
ee.Details = ""
hh.StreamInfo(e)
}(h, e)
default:
h.StreamErr(e, ErrOpInvalid)
h.streamErr("Invalid operation", e, ErrOpInvalid)
}
return nil
}

func(h *Handler) streamErr(summary string, e *meshes.EventsResponse, err error) {
e.Summary = summary
e.Details = err.Error()
e.ErrorCode = errors.GetCode(err)
e.ProbableCause = errors.GetCause(err)
e.SuggestedRemediation = errors.GetRemedy(err)
h.StreamErr(e, err)
}

0 comments on commit 15d6095

Please sign in to comment.