Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/remove_redundent_json' into remo…
Browse files Browse the repository at this point in the history
…ve_redundent_json
  • Loading branch information
seeflood committed May 25, 2022
2 parents 384da91 + de98646 commit c15c7d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
12 changes: 6 additions & 6 deletions components/custom/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ func (r *componentRegistry) Register(kind string, fs ...*ComponentFactory) {
}
}

func (r *componentRegistry) Create(compType, name string) (Component, error) {
store, ok := r.stores[compType]
func (r *componentRegistry) Create(kind, compType string) (Component, error) {
store, ok := r.stores[kind]
if !ok {
return nil, fmt.Errorf("custom component type %s is not regsitered", compType)
return nil, fmt.Errorf("custom component kind %s is not regsitered", kind)
}
if f, ok := store[name]; ok {
r.info.LoadComponent(compType, name)
if f, ok := store[compType]; ok {
r.info.LoadComponent(kind, compType)
return f(), nil
}
return nil, fmt.Errorf("custom component %s is not regsitered", name)
return nil, fmt.Errorf("custom component %s is not regsitered", compType)
}
2 changes: 1 addition & 1 deletion pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func (m *MosnRuntime) initCustomComponents(kind2factorys map[string][]*custom.Co
}
name2Config, ok := m.runtimeConfig.CustomComponent[kind]
if !ok {
log.DefaultLogger.Errorf("[runtime] Your required component type %s is not supported.Please check your configuration", kind)
log.DefaultLogger.Errorf("[runtime] Your required component kind %s is not supported. Please check your configuration", kind)
continue
}
// 2.1. register all the factorys
Expand Down
48 changes: 21 additions & 27 deletions sdk/go-sdk/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,40 +269,34 @@ func (*testRuntimeServer) GetBulkSecret(ctx context.Context, in *runtimev1pb.Get
}

func (t *testRuntimeServer) TryLock(ctx context.Context, in *runtimev1pb.TryLockRequest) (*runtimev1pb.TryLockResponse, error) {

if len(t.lock[in.ResourceId]) == 0 {
t.lock[in.ResourceId] = in.LockOwner
resp := &runtimev1pb.TryLockResponse{
return &runtimev1pb.TryLockResponse{
Success: true,
}
return resp, nil
} else {
resp := &runtimev1pb.TryLockResponse{
Success: false,
}
return resp, nil
}, nil
}
// lock exist
return &runtimev1pb.TryLockResponse{
Success: false,
}, nil
}

func (t *testRuntimeServer) Unlock(ctx context.Context, in *runtimev1pb.UnlockRequest) (*runtimev1pb.UnlockResponse, error) {
if len(t.lock[in.ResourceId]) != 0 {
if t.lock[in.ResourceId] == in.LockOwner {
delete(t.lock, in.ResourceId)
resp := &runtimev1pb.UnlockResponse{
Status: pb.UnlockResponse_SUCCESS,
}
return resp, nil
} else {
resp := &runtimev1pb.UnlockResponse{
Status: pb.UnlockResponse_LOCK_BELONG_TO_OTHERS,
}
return resp, nil
}

} else {
resp := &runtimev1pb.UnlockResponse{
// LOCK_UNEXIST
if len(t.lock[in.ResourceId]) == 0 {
return &runtimev1pb.UnlockResponse{
Status: pb.UnlockResponse_LOCK_UNEXIST,
}
return resp, nil
}, nil
}
// SUCCESS
if t.lock[in.ResourceId] == in.LockOwner {
delete(t.lock, in.ResourceId)
return &runtimev1pb.UnlockResponse{
Status: pb.UnlockResponse_SUCCESS,
}, nil
}
// LOCK_BELONG_TO_OTHERS
return &runtimev1pb.UnlockResponse{
Status: pb.UnlockResponse_LOCK_BELONG_TO_OTHERS,
}, nil
}

0 comments on commit c15c7d1

Please sign in to comment.