Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/dubbo-admin/dubbo-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ console:
password: dubbo@2025
expirationTime: 3600
store:
type: mysql
address: xx
type: memory
discovery:
- type: nacos
id: nacos-44.33
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package errors
package bizerror

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/handler/configurator_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ConfiguratorSearch(ctx consolectx.Context) gin.HandlerFunc {
pageData, err = manager.PageListByIndexes[*meshresource.DynamicConfigResource](
ctx.ResourceManager(),
meshresource.DynamicConfigKind,
map[string]interface{}{
map[string]string{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没觉得这个改动有多大意义

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是因为client go 的index接口中使用的是string类型,在上层将interface改为string有助于上层使用索引时知道这个特性

index.ByMeshIndex: req.Mesh,
},
req.PageReq,
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/handler/tag_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TagRuleSearch(ctx consolectx.Context) gin.HandlerFunc {
pageData, err = manager.PageListByIndexes[*meshresource.TagRouteResource](
ctx.ResourceManager(),
meshresource.TagRouteKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
},
req.PageReq)
Expand Down
10 changes: 5 additions & 5 deletions pkg/console/service/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func GetApplicationDetail(ctx consolectx.Context, req *model.ApplicationDetailRe
instanceResources, err := manager.ListByIndexes[*meshresource.InstanceResource](
ctx.ResourceManager(),
meshresource.InstanceKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
index.ByInstanceAppNameIndex: req.AppName,
},
Expand All @@ -61,7 +61,7 @@ func GetAppInstanceInfo(ctx consolectx.Context, req *model.ApplicationTabInstanc
pageData, err := manager.PageListByIndexes[*meshresource.InstanceResource](
ctx.ResourceManager(),
meshresource.InstanceKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
index.ByInstanceAppNameIndex: req.AppName,
},
Expand Down Expand Up @@ -117,7 +117,7 @@ func getAppProvideServiceInfo(ctx consolectx.Context, req *model.ApplicationServ
pageData, err := manager.PageListByIndexes[*meshresource.ServiceProviderMetadataResource](
ctx.ResourceManager(),
meshresource.ServiceProviderMetadataKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
index.ByServiceProviderAppName: req.AppName,
},
Expand Down Expand Up @@ -160,7 +160,7 @@ func getAppConsumeServiceInfo(ctx consolectx.Context, req *model.ApplicationServ
pageData, err := manager.PageListByIndexes[*meshresource.ServiceConsumerMetadataResource](
ctx.ResourceManager(),
meshresource.ServiceConsumerMetadataKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
index.ByServiceConsumerAppName: req.AppName,
},
Expand Down Expand Up @@ -239,7 +239,7 @@ func searchApplications(
pageData, err = manager.PageListByIndexes[*meshresource.ApplicationResource](
ctx.ResourceManager(),
meshresource.ApplicationKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: mesh,
},
pageReq,
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/service/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func SearchInstances(ctx consolectx.Context, req *model.SearchInstanceReq) (*mod
pageData, err = manager.PageListByIndexes[*meshresource.InstanceResource](
ctx.ResourceManager(),
meshresource.InstanceKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
},
req.PageReq)
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func SearchServices(ctx consolectx.Context, req *model.ServiceSearchReq) (*model
pageData, err = manager.PageListByIndexes[*meshresource.ServiceResource](
ctx.ResourceManager(),
meshresource.ServiceKind,
map[string]interface{}{
map[string]string{
index.ByMeshIndex: req.Mesh,
},
req.PageReq,
Expand Down
6 changes: 0 additions & 6 deletions pkg/core/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ import (
"github.com/pkg/errors"

"github.com/apache/dubbo-admin/pkg/config/app"
_ "github.com/apache/dubbo-admin/pkg/console"
_ "github.com/apache/dubbo-admin/pkg/core/discovery"
_ "github.com/apache/dubbo-admin/pkg/core/engine"
_ "github.com/apache/dubbo-admin/pkg/core/events"
"github.com/apache/dubbo-admin/pkg/core/logger"
_ "github.com/apache/dubbo-admin/pkg/core/manager"
"github.com/apache/dubbo-admin/pkg/core/runtime"
_ "github.com/apache/dubbo-admin/pkg/core/store"
"github.com/apache/dubbo-admin/pkg/diagnostics"
)

Expand Down
14 changes: 10 additions & 4 deletions pkg/store/memory/memory.go → pkg/core/bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
* limitations under the License.
*/

package memory
package bootstrap

import _ "k8s.io/client-go/tools/cache"

// TODO implement memory resource store, refer to client-go cache.Store
import (
_ "github.com/apache/dubbo-admin/pkg/console"
_ "github.com/apache/dubbo-admin/pkg/core/discovery"
_ "github.com/apache/dubbo-admin/pkg/core/engine"
_ "github.com/apache/dubbo-admin/pkg/core/events"
_ "github.com/apache/dubbo-admin/pkg/core/manager"
_ "github.com/apache/dubbo-admin/pkg/core/store"
_ "github.com/apache/dubbo-admin/pkg/store/memory"
)
8 changes: 4 additions & 4 deletions pkg/core/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ type ReadOnlyResourceManager interface {
// GetByKey returns the resource with the given resource key
GetByKey(rk model.ResourceKind, key string) (r model.Resource, exist bool, err error)
// ListByIndexes returns the resources with the given indexes, indexes is a map of index name and index value
ListByIndexes(rk model.ResourceKind, indexes map[string]interface{}) ([]model.Resource, error)
ListByIndexes(rk model.ResourceKind, indexes map[string]string) ([]model.Resource, error)
// PageListByIndexes page list the resources with the given indexes, indexes is a map of index name and index value
PageListByIndexes(rk model.ResourceKind, indexes map[string]interface{}, pr model.PageReq) (*model.PageData[model.Resource], error)
PageListByIndexes(rk model.ResourceKind, indexes map[string]string, pr model.PageReq) (*model.PageData[model.Resource], error)
// PageSearchResourceByConditions page fuzzy search resource by conditions, conditions cannot be empty
// TODO support multiple conditions
PageSearchResourceByConditions(rk model.ResourceKind, conditions []string, pr model.PageReq) (*model.PageData[model.Resource], error)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (rm *resourcesManager) GetByKey(rk model.ResourceKind, key string) (r model
return item.(model.Resource), exist, err
}

func (rm *resourcesManager) ListByIndexes(rk model.ResourceKind, indexes map[string]interface{}) ([]model.Resource, error) {
func (rm *resourcesManager) ListByIndexes(rk model.ResourceKind, indexes map[string]string) ([]model.Resource, error) {
rs, err := rm.StoreRouter.ResourceKindRoute(rk)
if err != nil {
return nil, err
Expand All @@ -88,7 +88,7 @@ func (rm *resourcesManager) ListByIndexes(rk model.ResourceKind, indexes map[str

func (rm *resourcesManager) PageListByIndexes(
rk model.ResourceKind,
indexes map[string]interface{},
indexes map[string]string,
pr model.PageReq) (*model.PageData[model.Resource], error) {

rs, err := rm.StoreRouter.ResourceKindRoute(rk)
Expand Down
14 changes: 7 additions & 7 deletions pkg/core/manager/manager_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package manager
import (
"reflect"

"github.com/apache/dubbo-admin/pkg/common/errors"
"github.com/apache/dubbo-admin/pkg/common/bizerror"
"github.com/apache/dubbo-admin/pkg/core/resource/model"
)

Expand All @@ -35,13 +35,13 @@ func GetByKey[T model.Resource](rm ReadOnlyResourceManager, rk model.ResourceKin
typedResource, ok := resource.(T)
if !ok {
var zero T
return zero, false, errors.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
return zero, false, bizerror.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
}
return typedResource, true, nil
}

// ListByIndexes is a helper function of ResourceManager.ListByIndexes
func ListByIndexes[T model.Resource](rm ReadOnlyResourceManager, rk model.ResourceKind, indexes map[string]interface{}) ([]T, error) {
func ListByIndexes[T model.Resource](rm ReadOnlyResourceManager, rk model.ResourceKind, indexes map[string]string) ([]T, error) {
resources, err := rm.ListByIndexes(rk, indexes)
if err != nil {
return nil, err
Expand All @@ -51,7 +51,7 @@ func ListByIndexes[T model.Resource](rm ReadOnlyResourceManager, rk model.Resour
for i, resource := range resources {
typedResource, ok := resource.(T)
if !ok {
return nil, errors.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
return nil, bizerror.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
}
typedResources[i] = typedResource
}
Expand All @@ -63,7 +63,7 @@ func ListByIndexes[T model.Resource](rm ReadOnlyResourceManager, rk model.Resour
func PageListByIndexes[T model.Resource](
rm ReadOnlyResourceManager,
rk model.ResourceKind,
indexes map[string]interface{},
indexes map[string]string,
pr model.PageReq) (*model.PageData[T], error) {

pageData, err := rm.PageListByIndexes(rk, indexes, pr)
Expand All @@ -75,7 +75,7 @@ func PageListByIndexes[T model.Resource](
for i, resource := range pageData.Data {
typedResource, ok := resource.(T)
if !ok {
return nil, errors.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
return nil, bizerror.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
}
typedResources[i] = typedResource
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func PageSearchResourceByConditions[T model.Resource](
for i, resource := range pageData.Data {
typedResource, ok := resource.(T)
if !ok {
return nil, errors.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
return nil, bizerror.NewAssertionError(rk, reflect.TypeOf(typedResource).Name())
}
typedResources[i] = typedResource
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/core/store/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package store
import (
"fmt"

"github.com/apache/dubbo-admin/pkg/config/store"
storecfg "github.com/apache/dubbo-admin/pkg/config/store"
"github.com/apache/dubbo-admin/pkg/core/resource/model"
)

Expand All @@ -37,13 +37,13 @@ func FactoryRegistry() Registry {
// Factory is the interface for create a specific type of ManagedResourceStore
type Factory interface {
// Support returns true if the factory supports the given type in config
Support(store.Type) bool
Support(storecfg.Type) bool
// New returns a new ManagedResourceStore for the model.ResourceKind using the given config
New(model.ResourceKind, *store.Config) (ManagedResourceStore, error)
New(model.ResourceKind, *storecfg.Config) (ManagedResourceStore, error)
}

type Registry interface {
GetStoreFactory(store.Type) (Factory, error)
GetStoreFactory(storecfg.Type) (Factory, error)
}

type RegistryMutator interface {
Expand All @@ -66,7 +66,7 @@ func newStoreFactoryRegistry() MutableRegistry {
factories: make([]Factory, 0),
}
}
func (s *storeFactoryRegistry) GetStoreFactory(t store.Type) (Factory, error) {
func (s *storeFactoryRegistry) GetStoreFactory(t storecfg.Type) (Factory, error) {
for _, factory := range s.factories {
if factory.Support(t) {
return factory, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/store/index/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/duke-git/lancet/v2/slice"
"k8s.io/client-go/tools/cache"

"github.com/apache/dubbo-admin/pkg/common/errors"
"github.com/apache/dubbo-admin/pkg/common/bizerror"
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
)

Expand All @@ -41,7 +41,7 @@ func init() {
func ByMesh(obj interface{}) ([]string, error) {
r, ok := obj.(coremodel.Resource)
if !ok {
return nil, errors.NewAssertionError("Resource", reflect.TypeOf(obj).Name())
return nil, bizerror.NewAssertionError("Resource", reflect.TypeOf(obj).Name())
}
return []string{r.MeshName()}, nil
}
6 changes: 3 additions & 3 deletions pkg/core/store/index/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"k8s.io/client-go/tools/cache"

"github.com/apache/dubbo-admin/pkg/common/errors"
"github.com/apache/dubbo-admin/pkg/common/bizerror"
meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
)

Expand All @@ -41,7 +41,7 @@ func init() {
func byInstanceAppName(obj interface{}) ([]string, error) {
instance, ok := obj.(*meshresource.InstanceResource)
if !ok {
return nil, errors.NewAssertionError(meshresource.InstanceKind, reflect.TypeOf(obj).Name())
return nil, bizerror.NewAssertionError(meshresource.InstanceKind, reflect.TypeOf(obj).Name())
}
if instance.Spec == nil {
return []string{}, nil
Expand All @@ -52,7 +52,7 @@ func byInstanceAppName(obj interface{}) ([]string, error) {
func byIp(obj interface{}) ([]string, error) {
instance, ok := obj.(*meshresource.InstanceResource)
if !ok {
return nil, errors.NewAssertionError(meshresource.InstanceKind, reflect.TypeOf(obj).Name())
return nil, bizerror.NewAssertionError(meshresource.InstanceKind, reflect.TypeOf(obj).Name())
}
if instance.Spec == nil {
return []string{}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/store/index/service_consumer_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"k8s.io/client-go/tools/cache"

"github.com/apache/dubbo-admin/pkg/common/errors"
"github.com/apache/dubbo-admin/pkg/common/bizerror"
meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
)

Expand All @@ -39,7 +39,7 @@ func init() {
func byServiceConsumerAppName(obj interface{}) ([]string, error) {
metadata, ok := obj.(*meshresource.ServiceConsumerMetadataResource)
if !ok {
return nil, errors.NewAssertionError(meshresource.ServiceConsumerMetadataKind, reflect.TypeOf(obj).Name())
return nil, bizerror.NewAssertionError(meshresource.ServiceConsumerMetadataKind, reflect.TypeOf(obj).Name())
}
if metadata == nil {
return []string{}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/store/index/service_provider_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"k8s.io/client-go/tools/cache"

"github.com/apache/dubbo-admin/pkg/common/errors"
"github.com/apache/dubbo-admin/pkg/common/bizerror"
meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
)

Expand All @@ -39,7 +39,7 @@ func init() {
func byServiceProviderAppName(obj interface{}) ([]string, error) {
metadata, ok := obj.(*meshresource.ServiceProviderMetadataResource)
if !ok {
return nil, errors.NewAssertionError(meshresource.ServiceProviderMetadataKind, reflect.TypeOf(obj))
return nil, bizerror.NewAssertionError(meshresource.ServiceProviderMetadataKind, reflect.TypeOf(obj).Name())
}
if metadata.Spec == nil {
return []string{}, nil
Expand Down
8 changes: 6 additions & 2 deletions pkg/core/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ import (
// ResourceStore expanded the interface of cache.Indexer and cache.Store
type ResourceStore interface {
Indexer
ListByIndexes(indexes map[string]interface{}) ([]model.Resource, error)
// GetByKeys get resources by keys, return list of resource.
// if a resource of specified key doesn't exist in the store, resource list will not include it
GetByKeys(keys []string) ([]model.Resource, error)
// ListByIndexes list resources by indexes, indexes is map of index name and index value
ListByIndexes(indexes map[string]string) ([]model.Resource, error)
// PageListByIndexes list resources by indexes pageable, indexes is map of index name and index value
PageListByIndexes(indexes map[string]interface{}, pq model.PageReq) (*model.PageData[model.Resource], error)
PageListByIndexes(indexes map[string]string, pq model.PageReq) (*model.PageData[model.Resource], error)
}

// ManagedResourceStore includes both functional interfaces and lifecycle interfaces
Expand Down
40 changes: 40 additions & 0 deletions pkg/store/memory/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package memory

import (
storecfg "github.com/apache/dubbo-admin/pkg/config/store"
coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
"github.com/apache/dubbo-admin/pkg/core/store"
)

func init() {
store.RegisterFactory(&storeFactory{})
}

type storeFactory struct{}

var _ store.Factory = &storeFactory{}

func (sf *storeFactory) Support(s storecfg.Type) bool {
return s == storecfg.Memory
}

func (sf *storeFactory) New(_ coremodel.ResourceKind, _ *storecfg.Config) (store.ManagedResourceStore, error) {
return NewMemoryResourceStore(), nil
}
Loading
Loading