Skip to content

Commit cedd628

Browse files
authored
Merge pull request #117 from gr455/notification-feat
Notification feature propagation
2 parents 5cd54b9 + 7e06a9a commit cedd628

File tree

6 files changed

+54
-28
lines changed

6 files changed

+54
-28
lines changed

appmesh/app_mesh.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/layer5io/meshkit/logger"
1717
"github.com/layer5io/meshkit/models"
1818
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
19+
"github.com/layer5io/meshkit/utils/events"
1920
"gopkg.in/yaml.v2"
2021
)
2122

@@ -25,24 +26,24 @@ type AppMesh struct {
2526
}
2627

2728
// New initializes AppMesh handler.
28-
func New(c meshkitCfg.Handler, l logger.Handler, kc meshkitCfg.Handler) adapter.Handler {
29+
func New(c meshkitCfg.Handler, l logger.Handler, kc meshkitCfg.Handler, e *events.EventStreamer) adapter.Handler {
2930
return &AppMesh{
3031
Adapter: adapter.Adapter{
3132
Config: c,
3233
Log: l,
3334
KubeconfigHandler: kc,
35+
EventStreamer: e,
3436
},
3537
}
3638
}
3739

3840
// ApplyOperation applies the requested operation on app-mesh
39-
func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.OperationRequest, hchan *chan interface{}) error {
41+
func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.OperationRequest) error {
4042
err := appMesh.CreateKubeconfigs(opReq.K8sConfigs)
4143
if err != nil {
4244
return err
4345
}
4446
kubeConfigs := opReq.K8sConfigs
45-
appMesh.SetChannel(hchan);
4647

4748
operations := make(adapter.Operations)
4849
err = appMesh.Config.GetObject(adapter.OperationsKey, &operations)
@@ -51,10 +52,10 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
5152
}
5253

5354
e := &meshes.EventsResponse{
54-
OperationId: opReq.OperationID,
55-
Summary: status.Deploying,
56-
Details: "Operation is not supported",
57-
Component: internalconfig.ServerConfig["type"],
55+
OperationId: opReq.OperationID,
56+
Summary: status.Deploying,
57+
Details: "Operation is not supported",
58+
Component: internalconfig.ServerConfig["type"],
5859
ComponentName: internalconfig.ServerConfig["name"],
5960
}
6061
stat := status.Deploying
@@ -65,12 +66,12 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
6566
version := string(operations[opReq.OperationName].Versions[0])
6667
if stat, err = hh.installAppMesh(opReq.IsDeleteOperation, version, opReq.Namespace, kubeConfigs); err != nil {
6768
summary := fmt.Sprintf("Error while %s AWS App mesh", stat)
68-
hh.streamErr(summary, e, err)
69+
hh.streamErr(summary, ee, err)
6970
return
7071
}
7172
ee.Summary = fmt.Sprintf("App mesh %s successfully", stat)
7273
ee.Details = fmt.Sprintf("The App mesh is now %s.", stat)
73-
hh.StreamInfo(e)
74+
hh.StreamInfo(ee)
7475
}(appMesh, e)
7576

7677
case internalconfig.LabelNamespace:
@@ -116,25 +117,25 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
116117
stat, err := hh.installSampleApp(opReq.Namespace, opReq.IsDeleteOperation, operations[opReq.OperationName].Templates, kubeConfigs)
117118
if err != nil {
118119
summary := fmt.Sprintf("Error while %s %s application", stat, appName)
119-
hh.streamErr(summary, e, err)
120+
hh.streamErr(summary, ee, err)
120121
return
121122
}
122123
ee.Summary = fmt.Sprintf("%s application %s successfully", appName, stat)
123124
ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat)
124-
hh.StreamInfo(e)
125+
hh.StreamInfo(ee)
125126
}(appMesh, e)
126127

127128
case common.CustomOperation:
128129
go func(hh *AppMesh, ee *meshes.EventsResponse) {
129130
stat, err := hh.applyCustomOperation(opReq.Namespace, opReq.CustomBody, opReq.IsDeleteOperation, kubeConfigs)
130131
if err != nil {
131132
summary := fmt.Sprintf("Error while %s custom operation", stat)
132-
hh.streamErr(summary, e, err)
133+
hh.streamErr(summary, ee, err)
133134
return
134135
}
135136
ee.Summary = fmt.Sprintf("Manifest %s successfully", status.Deployed)
136137
ee.Details = ""
137-
hh.StreamInfo(e)
138+
hh.StreamInfo(ee)
138139
}(appMesh, e)
139140
default:
140141
appMesh.streamErr("Invalid operation", e, ErrOpInvalid)
@@ -189,8 +190,8 @@ func (appMesh *AppMesh) CreateKubeconfigs(kubeconfigs []string) error {
189190
}
190191

191192
// ProcessOAM handles the grpc invocation for handling OAM objects
192-
func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest, hchan *chan interface{}) (string, error) {
193-
appMesh.SetChannel(hchan)
193+
func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMRequest) (string, error) {
194+
194195
err := appMesh.CreateKubeconfigs(oamReq.K8sConfigs)
195196
if err != nil {
196197
return "", err
@@ -245,11 +246,11 @@ func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMReques
245246
return msg1 + "\n" + msg2, nil
246247
}
247248

248-
func(appMesh *AppMesh) streamErr(summary string, e *meshes.EventsResponse, err error) {
249+
func (appMesh *AppMesh) streamErr(summary string, e *meshes.EventsResponse, err error) {
249250
e.Summary = summary
250251
e.Details = err.Error()
251252
e.ErrorCode = errors.GetCode(err)
252253
e.ProbableCause = errors.GetCause(err)
253254
e.SuggestedRemediation = errors.GetRemedy(err)
254255
appMesh.StreamErr(e, err)
255-
}
256+
}

appmesh/oam.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/google/uuid"
8+
"github.com/layer5io/meshery-adapter-library/meshes"
9+
"github.com/layer5io/meshery-app-mesh/internal/config"
710
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
811
"gopkg.in/yaml.v2"
912
)
@@ -15,29 +18,49 @@ type CompHandler func(*AppMesh, v1alpha1.Component, bool, []string) (string, err
1518
func (appMesh *AppMesh) HandleComponents(comps []v1alpha1.Component, isDel bool, kubeconfigs []string) (string, error) {
1619
var errs []error
1720
var msgs []string
18-
21+
stat1 := "deploying"
22+
stat2 := "deployed"
23+
if isDel {
24+
stat1 = "removing"
25+
stat2 = "removed"
26+
}
1927
compFuncMap := map[string]CompHandler{
2028
"AppMesh": handleComponentAppMesh,
2129
}
2230

2331
for _, comp := range comps {
32+
ee := &meshes.EventsResponse{
33+
OperationId: uuid.New().String(),
34+
Component: config.ServerConfig["type"],
35+
ComponentName: config.ServerConfig["name"],
36+
}
2437
fnc, ok := compFuncMap[comp.Spec.Type]
2538
if !ok {
2639
msg, err := handleAppMeshCoreComponent(appMesh, comp, isDel, "", "", kubeconfigs)
2740
if err != nil {
41+
ee.Summary = fmt.Sprintf("Error while %s %s", stat1, comp.Spec.Type)
42+
appMesh.streamErr(ee.Summary, ee, err)
2843
errs = append(errs, err)
2944
continue
3045
}
46+
ee.Summary = fmt.Sprintf("%s %s successfully", comp.Spec.Type, stat2)
47+
ee.Details = fmt.Sprintf("The %s is now %s.", comp.Spec.Type, stat2)
48+
appMesh.StreamInfo(ee)
3149

3250
msgs = append(msgs, msg)
3351
continue
3452
}
3553

3654
msg, err := fnc(appMesh, comp, isDel, kubeconfigs)
3755
if err != nil {
56+
ee.Summary = fmt.Sprintf("Error while %s %s", stat1, comp.Spec.Type)
57+
appMesh.streamErr(ee.Summary, ee, err)
3858
errs = append(errs, err)
3959
continue
4060
}
61+
ee.Summary = fmt.Sprintf("%s %s %s successfully", comp.Name, comp.Spec.Type, stat2)
62+
ee.Details = fmt.Sprintf("The %s %s is now %s.", comp.Name, comp.Spec.Type, stat2)
63+
appMesh.StreamInfo(ee)
4164

4265
msgs = append(msgs, msg)
4366
}

appmesh/oam/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
var (
1414
basePath, _ = os.Getwd()
15+
// WorkloadPath contains the path to the workload schemas and definitions directory
1516
WorkloadPath = filepath.Join(basePath, "templates", "oam", "workloads")
1617
// traitPath = filepath.Join(basePath, "templates", "oam", "traits")
1718
pathSets = []schemaDefinitionPathSet{}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ replace (
1010
)
1111

1212
require (
13-
github.com/layer5io/meshery-adapter-library v0.5.9
14-
github.com/layer5io/meshkit v0.5.32
13+
github.com/google/uuid v1.3.0
14+
github.com/layer5io/meshery-adapter-library v0.5.10
15+
github.com/layer5io/meshkit v0.5.37
1516
github.com/layer5io/service-mesh-performance v0.3.4
1617
gopkg.in/yaml.v2 v2.4.0
1718
k8s.io/apimachinery v0.23.5
@@ -63,7 +64,6 @@ require (
6364
github.com/google/go-cmp v0.5.8 // indirect
6465
github.com/google/gofuzz v1.2.0 // indirect
6566
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
66-
github.com/google/uuid v1.3.0 // indirect
6767
github.com/googleapis/gnostic v0.5.5 // indirect
6868
github.com/gorilla/mux v1.8.0 // indirect
6969
github.com/gosuri/uitable v0.0.4 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,10 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
852852
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
853853
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
854854
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
855-
github.com/layer5io/meshery-adapter-library v0.5.9 h1:Zp79l4J8kMjML9zAQ4Xu4QiKM5q5HEGcv04Jjg+xWSA=
856-
github.com/layer5io/meshery-adapter-library v0.5.9/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
857-
github.com/layer5io/meshkit v0.5.32 h1:jIkQ9gKH7TPMWKbVtf6wQ+qv4553UyZ9SV4yKA2D4oo=
858-
github.com/layer5io/meshkit v0.5.32/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
855+
github.com/layer5io/meshery-adapter-library v0.5.10 h1:Qgr6vDx2s10mkhtk7Mnz5I73m/9yf2yyjCkPMeB4jmA=
856+
github.com/layer5io/meshery-adapter-library v0.5.10/go.mod h1:Sg6WNN82uRo2kiFDEMc/LM/AJ/Pu6ZmBZGbFxZuC7zc=
857+
github.com/layer5io/meshkit v0.5.37 h1:EO0wXAI+eqAm+4uKSzFd50rDkr6nqQ17m1j0wmv9hQA=
858+
github.com/layer5io/meshkit v0.5.37/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
859859
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
860860
github.com/layer5io/service-mesh-performance v0.3.4 h1:aw/elsx0wkry7SyiQRIj31wW7TPCP4YfhINdNOLXVg8=
861861
github.com/layer5io/service-mesh-performance v0.3.4/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/layer5io/meshery-app-mesh/build"
1818
"github.com/layer5io/meshery-app-mesh/internal/config"
1919
"github.com/layer5io/meshkit/logger"
20+
"github.com/layer5io/meshkit/utils/events"
2021

2122
// "github.com/layer5io/meshkit/tracing"
2223
"github.com/layer5io/meshery-app-mesh/appmesh/oam"
@@ -91,13 +92,13 @@ func main() {
9192
// log.Err("Tracing Init Failed", err.Error())
9293
// os.Exit(1)
9394
// }
94-
95+
e := events.NewEventStreamer()
9596
// Initialize Handler intance
96-
handler := appmesh.New(cfg, log, kubeconfigHandler)
97+
handler := appmesh.New(cfg, log, kubeconfigHandler, e)
9798
handler = adapter.AddLogger(log, handler)
9899

99100
service.Handler = handler
100-
service.Channel = make(chan interface{}, 10)
101+
service.EventStreamer = e
101102
service.StartedAt = time.Now()
102103
service.Version = version
103104
service.GitSHA = gitsha

0 commit comments

Comments
 (0)