github.com/polarismesh/polaris@v1.17.8/store/discover_api.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package store
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/polarismesh/polaris/common/model"
    24  )
    25  
    26  // NamingModuleStore Service discovery, governance center module storage interface
    27  type NamingModuleStore interface {
    28  	// ServiceStore 服务接口
    29  	ServiceStore
    30  	// InstanceStore 实例接口
    31  	InstanceStore
    32  	// RoutingConfigStore 路由配置接口
    33  	RoutingConfigStore
    34  	// L5Store L5扩展接口
    35  	L5Store
    36  	// RateLimitStore 限流规则接口
    37  	RateLimitStore
    38  	// CircuitBreakerStore 熔断规则接口
    39  	CircuitBreakerStore
    40  	// ToolStore 函数及工具接口
    41  	ToolStore
    42  	// UserStore 用户接口
    43  	UserStore
    44  	// GroupStore 用户组接口
    45  	GroupStore
    46  	// StrategyStore 鉴权策略接口
    47  	StrategyStore
    48  	// RoutingConfigStoreV2 路由策略 v2 接口
    49  	RoutingConfigStoreV2
    50  	// FaultDetectRuleStore fault detect rule interface
    51  	FaultDetectRuleStore
    52  }
    53  
    54  // ServiceStore 服务存储接口
    55  type ServiceStore interface {
    56  	// AddService 保存一个服务
    57  	AddService(service *model.Service) error
    58  
    59  	// DeleteService 删除服务
    60  	DeleteService(id, serviceName, namespaceName string) error
    61  
    62  	// DeleteServiceAlias 删除服务别名
    63  	DeleteServiceAlias(name string, namespace string) error
    64  
    65  	// UpdateServiceAlias 修改服务别名
    66  	UpdateServiceAlias(alias *model.Service, needUpdateOwner bool) error
    67  
    68  	// UpdateService 更新服务
    69  	UpdateService(service *model.Service, needUpdateOwner bool) error
    70  
    71  	// UpdateServiceToken 更新服务token
    72  	UpdateServiceToken(serviceID string, token string, revision string) error
    73  
    74  	// GetSourceServiceToken 获取源服务的token信息
    75  	GetSourceServiceToken(name string, namespace string) (*model.Service, error)
    76  
    77  	// GetService 根据服务名和命名空间获取服务的详情
    78  	GetService(name string, namespace string) (*model.Service, error)
    79  
    80  	// GetServiceByID 根据服务ID查询服务详情
    81  	GetServiceByID(id string) (*model.Service, error)
    82  
    83  	// GetServices 根据相关条件查询对应服务及数目
    84  	GetServices(serviceFilters, serviceMetas map[string]string, instanceFilters *InstanceArgs, offset, limit uint32) (
    85  		uint32, []*model.Service, error)
    86  
    87  	// GetServicesCount 获取所有服务总数
    88  	GetServicesCount() (uint32, error)
    89  
    90  	// GetMoreServices 获取增量services
    91  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
    92  	GetMoreServices(mtime time.Time, firstUpdate, disableBusiness, needMeta bool) (map[string]*model.Service, error)
    93  
    94  	// GetServiceAliases 获取服务别名列表
    95  	GetServiceAliases(filter map[string]string, offset uint32, limit uint32) (uint32, []*model.ServiceAlias, error)
    96  
    97  	// GetSystemServices 获取系统服务
    98  	GetSystemServices() ([]*model.Service, error)
    99  
   100  	// GetServicesBatch 批量获取服务id、负责人等信息
   101  	GetServicesBatch(services []*model.Service) ([]*model.Service, error)
   102  }
   103  
   104  // InstanceStore 实例存储接口
   105  type InstanceStore interface {
   106  	// AddInstance 增加一个实例
   107  	AddInstance(instance *model.Instance) error
   108  
   109  	// BatchAddInstances 增加多个实例
   110  	BatchAddInstances(instances []*model.Instance) error
   111  
   112  	// UpdateInstance 更新实例
   113  	UpdateInstance(instance *model.Instance) error
   114  
   115  	// DeleteInstance 删除一个实例,实际是把valid置为false
   116  	DeleteInstance(instanceID string) error
   117  
   118  	// BatchDeleteInstances 批量删除实例,flag=1
   119  	BatchDeleteInstances(ids []interface{}) error
   120  
   121  	// CleanInstance 清空一个实例,真正删除
   122  	CleanInstance(instanceID string) error
   123  
   124  	// BatchGetInstanceIsolate 检查ID是否存在,并且返回存在的ID,以及ID的隔离状态
   125  	BatchGetInstanceIsolate(ids map[string]bool) (map[string]bool, error)
   126  
   127  	// GetInstancesBrief 获取实例关联的token
   128  	GetInstancesBrief(ids map[string]bool) (map[string]*model.Instance, error)
   129  
   130  	// GetInstance 查询一个实例的详情,只返回有效的数据
   131  	GetInstance(instanceID string) (*model.Instance, error)
   132  
   133  	// GetInstancesCount 获取有效的实例总数
   134  	GetInstancesCount() (uint32, error)
   135  
   136  	// GetInstancesCountTx 获取有效的实例总数
   137  	GetInstancesCountTx(tx Tx) (uint32, error)
   138  
   139  	// GetInstancesMainByService 根据服务和Host获取实例(不包括metadata)
   140  	GetInstancesMainByService(serviceID, host string) ([]*model.Instance, error)
   141  
   142  	// GetExpandInstances 根据过滤条件查看实例详情及对应数目
   143  	GetExpandInstances(
   144  		filter, metaFilter map[string]string, offset uint32, limit uint32) (uint32, []*model.Instance, error)
   145  
   146  	// GetMoreInstances 根据mtime获取增量instances,返回所有store的变更信息
   147  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
   148  	GetMoreInstances(tx Tx, mtime time.Time, firstUpdate, needMeta bool, serviceID []string) (map[string]*model.Instance, error)
   149  
   150  	// SetInstanceHealthStatus 设置实例的健康状态
   151  	SetInstanceHealthStatus(instanceID string, flag int, revision string) error
   152  
   153  	// BatchSetInstanceHealthStatus 批量设置实例的健康状态
   154  	BatchSetInstanceHealthStatus(ids []interface{}, healthy int, revision string) error
   155  
   156  	// BatchSetInstanceIsolate 批量修改实例的隔离状态
   157  	BatchSetInstanceIsolate(ids []interface{}, isolate int, revision string) error
   158  
   159  	// AppendInstanceMetadata 追加实例 metadata
   160  	BatchAppendInstanceMetadata(requests []*InstanceMetadataRequest) error
   161  
   162  	// RemoveInstanceMetadata 删除实例指定的 metadata
   163  	BatchRemoveInstanceMetadata(requests []*InstanceMetadataRequest) error
   164  }
   165  
   166  // L5Store L5扩展存储接口
   167  type L5Store interface {
   168  	// GetL5Extend 获取扩展数据
   169  	GetL5Extend(serviceID string) (map[string]interface{}, error)
   170  
   171  	// SetL5Extend 设置meta里保存的扩展数据,并返回剩余的meta
   172  	SetL5Extend(serviceID string, meta map[string]interface{}) (map[string]interface{}, error)
   173  
   174  	// GenNextL5Sid 获取module
   175  	GenNextL5Sid(layoutID uint32) (string, error)
   176  
   177  	// GetMoreL5Extend 获取增量数据
   178  	GetMoreL5Extend(mtime time.Time) (map[string]map[string]interface{}, error)
   179  
   180  	// GetMoreL5Routes 获取Route增量数据
   181  	GetMoreL5Routes(flow uint32) ([]*model.Route, error)
   182  
   183  	// GetMoreL5Policies 获取Policy增量数据
   184  	GetMoreL5Policies(flow uint32) ([]*model.Policy, error)
   185  
   186  	// GetMoreL5Sections 获取Section增量数据
   187  	GetMoreL5Sections(flow uint32) ([]*model.Section, error)
   188  
   189  	// GetMoreL5IPConfigs 获取IP Config增量数据
   190  	GetMoreL5IPConfigs(flow uint32) ([]*model.IPConfig, error)
   191  }
   192  
   193  // RoutingConfigStore 路由配置表的存储接口
   194  type RoutingConfigStore interface {
   195  	// CreateRoutingConfig 新增一个路由配置
   196  	CreateRoutingConfig(conf *model.RoutingConfig) error
   197  	// UpdateRoutingConfig 更新一个路由配置
   198  	UpdateRoutingConfig(conf *model.RoutingConfig) error
   199  	// DeleteRoutingConfig 删除一个路由配置
   200  	DeleteRoutingConfig(serviceID string) error
   201  	// DeleteRoutingConfigTx 删除一个路由配置
   202  	DeleteRoutingConfigTx(tx Tx, serviceID string) error
   203  	// GetRoutingConfigsForCache 通过mtime拉取增量的路由配置信息
   204  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
   205  	GetRoutingConfigsForCache(mtime time.Time, firstUpdate bool) ([]*model.RoutingConfig, error)
   206  	// GetRoutingConfigWithService 根据服务名和命名空间拉取路由配置
   207  	GetRoutingConfigWithService(name string, namespace string) (*model.RoutingConfig, error)
   208  	// GetRoutingConfigWithID 根据服务ID拉取路由配置
   209  	GetRoutingConfigWithID(id string) (*model.RoutingConfig, error)
   210  	// GetRoutingConfigs 查询路由配置列表
   211  	GetRoutingConfigs(filter map[string]string, offset uint32, limit uint32) (uint32, []*model.ExtendRoutingConfig, error)
   212  }
   213  
   214  // RateLimitStore 限流规则的存储接口
   215  type RateLimitStore interface {
   216  	// CreateRateLimit 新增限流规则
   217  	CreateRateLimit(limiting *model.RateLimit) error
   218  
   219  	// UpdateRateLimit 更新限流规则
   220  	UpdateRateLimit(limiting *model.RateLimit) error
   221  
   222  	// EnableRateLimit 启用限流规则
   223  	EnableRateLimit(limit *model.RateLimit) error
   224  
   225  	// DeleteRateLimit 删除限流规则
   226  	DeleteRateLimit(limiting *model.RateLimit) error
   227  
   228  	// GetExtendRateLimits 根据过滤条件拉取限流规则
   229  	GetExtendRateLimits(query map[string]string, offset uint32, limit uint32) (uint32, []*model.ExtendRateLimit, error)
   230  
   231  	// GetRateLimitWithID 根据限流ID拉取限流规则
   232  	GetRateLimitWithID(id string) (*model.RateLimit, error)
   233  
   234  	// GetRateLimitsForCache 根据修改时间拉取增量限流规则及最新版本号
   235  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
   236  	GetRateLimitsForCache(mtime time.Time, firstUpdate bool) ([]*model.RateLimit, error)
   237  }
   238  
   239  // CircuitBreakerStore 熔断规则的存储接口
   240  type CircuitBreakerStore interface {
   241  	// CreateCircuitBreakerRule create general circuitbreaker rule
   242  	CreateCircuitBreakerRule(cbRule *model.CircuitBreakerRule) error
   243  	// UpdateCircuitBreakerRule update general circuitbreaker rule
   244  	UpdateCircuitBreakerRule(cbRule *model.CircuitBreakerRule) error
   245  	// DeleteCircuitBreakerRule delete general circuitbreaker rule
   246  	DeleteCircuitBreakerRule(id string) error
   247  	// HasCircuitBreakerRule check circuitbreaker rule exists
   248  	HasCircuitBreakerRule(id string) (bool, error)
   249  	// HasCircuitBreakerRuleByName check circuitbreaker rule exists for name
   250  	HasCircuitBreakerRuleByName(name string, namespace string) (bool, error)
   251  	// HasCircuitBreakerRuleByNameExcludeId check circuitbreaker rule exists for name not this id
   252  	HasCircuitBreakerRuleByNameExcludeId(name string, namespace string, id string) (bool, error)
   253  	// GetCircuitBreakerRules get all circuitbreaker rules by query and limit
   254  	GetCircuitBreakerRules(
   255  		filter map[string]string, offset uint32, limit uint32) (uint32, []*model.CircuitBreakerRule, error)
   256  	// GetCircuitBreakerRulesForCache get increment circuitbreaker rules
   257  	GetCircuitBreakerRulesForCache(mtime time.Time, firstUpdate bool) ([]*model.CircuitBreakerRule, error)
   258  	// EnableCircuitBreakerRule enable specific circuitbreaker rule
   259  	EnableCircuitBreakerRule(cbRule *model.CircuitBreakerRule) error
   260  }
   261  
   262  // ClientStore store interface for client info
   263  type ClientStore interface {
   264  	// BatchAddClients insert the client info
   265  	BatchAddClients(clients []*model.Client) error
   266  	// BatchDeleteClients delete the client info
   267  	BatchDeleteClients(ids []string) error
   268  	// GetMoreClients 根据mtime获取增量clients,返回所有store的变更信息
   269  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
   270  	GetMoreClients(mtime time.Time, firstUpdate bool) (map[string]*model.Client, error)
   271  }
   272  
   273  // RoutingConfigStoreV2 路由配置表的存储接口
   274  type RoutingConfigStoreV2 interface {
   275  	// EnableRouting 设置路由规则是否启用
   276  	EnableRouting(conf *model.RouterConfig) error
   277  	// CreateRoutingConfigV2 新增一个路由配置
   278  	CreateRoutingConfigV2(conf *model.RouterConfig) error
   279  	// CreateRoutingConfigV2Tx 新增一个路由配置
   280  	CreateRoutingConfigV2Tx(tx Tx, conf *model.RouterConfig) error
   281  	// UpdateRoutingConfigV2 更新一个路由配置
   282  	UpdateRoutingConfigV2(conf *model.RouterConfig) error
   283  	// UpdateRoutingConfigV2Tx 更新一个路由配置
   284  	UpdateRoutingConfigV2Tx(tx Tx, conf *model.RouterConfig) error
   285  	// DeleteRoutingConfigV2 删除一个路由配置
   286  	DeleteRoutingConfigV2(serviceID string) error
   287  	// GetRoutingConfigsV2ForCache 通过mtime拉取增量的路由配置信息
   288  	// 此方法用于 cache 增量更新,需要注意 mtime 应为数据库时间戳
   289  	GetRoutingConfigsV2ForCache(mtime time.Time, firstUpdate bool) ([]*model.RouterConfig, error)
   290  	// GetRoutingConfigV2WithID 根据服务ID拉取路由配置
   291  	GetRoutingConfigV2WithID(id string) (*model.RouterConfig, error)
   292  	// GetRoutingConfigV2WithIDTx 根据服务ID拉取路由配置
   293  	GetRoutingConfigV2WithIDTx(tx Tx, id string) (*model.RouterConfig, error)
   294  }
   295  
   296  // FaultDetectRuleStore store api for the fault detector config
   297  type FaultDetectRuleStore interface {
   298  	// CreateFaultDetectRule create fault detect rule
   299  	CreateFaultDetectRule(conf *model.FaultDetectRule) error
   300  
   301  	// UpdateFaultDetectRule update fault detect rule
   302  	UpdateFaultDetectRule(conf *model.FaultDetectRule) error
   303  
   304  	// DeleteFaultDetectRule delete fault detect rule
   305  	DeleteFaultDetectRule(id string) error
   306  
   307  	// HasFaultDetectRule check fault detect rule exists
   308  	HasFaultDetectRule(id string) (bool, error)
   309  
   310  	// HasFaultDetectRuleByName check fault detect rule exists by name
   311  	HasFaultDetectRuleByName(name string, namespace string) (bool, error)
   312  
   313  	// HasFaultDetectRuleByNameExcludeId check fault detect rule exists by name not this id
   314  	HasFaultDetectRuleByNameExcludeId(name string, namespace string, id string) (bool, error)
   315  
   316  	// GetFaultDetectRules get all fault detect rules by query and limit
   317  	GetFaultDetectRules(filter map[string]string, offset uint32, limit uint32) (uint32, []*model.FaultDetectRule, error)
   318  
   319  	// GetFaultDetectRulesForCache get increment fault detect rules
   320  	GetFaultDetectRulesForCache(mtime time.Time, firstUpdate bool) ([]*model.FaultDetectRule, error)
   321  }