Skip to content

Commit 7a2eefd

Browse files
authored
fix: fix legacy issues of #549 (#604)
Signed-off-by: seeflood <[email protected]>
1 parent 37312d8 commit 7a2eefd

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

components/custom/registry.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ func (r *componentRegistry) Register(kind string, fs ...*ComponentFactory) {
6464
}
6565
}
6666

67-
func (r *componentRegistry) Create(compType, name string) (Component, error) {
68-
store, ok := r.stores[compType]
67+
func (r *componentRegistry) Create(kind, compType string) (Component, error) {
68+
store, ok := r.stores[kind]
6969
if !ok {
70-
return nil, fmt.Errorf("custom component type %s is not regsitered", compType)
70+
return nil, fmt.Errorf("custom component kind %s is not regsitered", kind)
7171
}
72-
if f, ok := store[name]; ok {
73-
r.info.LoadComponent(compType, name)
72+
if f, ok := store[compType]; ok {
73+
r.info.LoadComponent(kind, compType)
7474
return f(), nil
7575
}
76-
return nil, fmt.Errorf("custom component %s is not regsitered", name)
76+
return nil, fmt.Errorf("custom component %s is not regsitered", compType)
7777
}

pkg/runtime/runtime.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ func (m *MosnRuntime) initCustomComponents(kind2factorys map[string][]*custom.Co
586586
}
587587
name2Config, ok := m.runtimeConfig.CustomComponent[kind]
588588
if !ok {
589-
log.DefaultLogger.Errorf("[runtime] Your required component type %s is not supported.Please check your configuration", kind)
589+
log.DefaultLogger.Errorf("[runtime] Your required component kind %s is not supported. Please check your configuration", kind)
590590
continue
591591
}
592592
// 2.1. register all the factorys

sdk/go-sdk/client/client_test.go

+21-27
Original file line numberDiff line numberDiff line change
@@ -269,40 +269,34 @@ func (*testRuntimeServer) GetBulkSecret(ctx context.Context, in *runtimev1pb.Get
269269
}
270270

271271
func (t *testRuntimeServer) TryLock(ctx context.Context, in *runtimev1pb.TryLockRequest) (*runtimev1pb.TryLockResponse, error) {
272-
273272
if len(t.lock[in.ResourceId]) == 0 {
274273
t.lock[in.ResourceId] = in.LockOwner
275-
resp := &runtimev1pb.TryLockResponse{
274+
return &runtimev1pb.TryLockResponse{
276275
Success: true,
277-
}
278-
return resp, nil
279-
} else {
280-
resp := &runtimev1pb.TryLockResponse{
281-
Success: false,
282-
}
283-
return resp, nil
276+
}, nil
284277
}
278+
// lock exist
279+
return &runtimev1pb.TryLockResponse{
280+
Success: false,
281+
}, nil
285282
}
286283

287284
func (t *testRuntimeServer) Unlock(ctx context.Context, in *runtimev1pb.UnlockRequest) (*runtimev1pb.UnlockResponse, error) {
288-
if len(t.lock[in.ResourceId]) != 0 {
289-
if t.lock[in.ResourceId] == in.LockOwner {
290-
delete(t.lock, in.ResourceId)
291-
resp := &runtimev1pb.UnlockResponse{
292-
Status: pb.UnlockResponse_SUCCESS,
293-
}
294-
return resp, nil
295-
} else {
296-
resp := &runtimev1pb.UnlockResponse{
297-
Status: pb.UnlockResponse_LOCK_BELONG_TO_OTHERS,
298-
}
299-
return resp, nil
300-
}
301-
302-
} else {
303-
resp := &runtimev1pb.UnlockResponse{
285+
// LOCK_UNEXIST
286+
if len(t.lock[in.ResourceId]) == 0 {
287+
return &runtimev1pb.UnlockResponse{
304288
Status: pb.UnlockResponse_LOCK_UNEXIST,
305-
}
306-
return resp, nil
289+
}, nil
307290
}
291+
// SUCCESS
292+
if t.lock[in.ResourceId] == in.LockOwner {
293+
delete(t.lock, in.ResourceId)
294+
return &runtimev1pb.UnlockResponse{
295+
Status: pb.UnlockResponse_SUCCESS,
296+
}, nil
297+
}
298+
// LOCK_BELONG_TO_OTHERS
299+
return &runtimev1pb.UnlockResponse{
300+
Status: pb.UnlockResponse_LOCK_BELONG_TO_OTHERS,
301+
}, nil
308302
}

0 commit comments

Comments
 (0)