[
https://issues.apache.org/jira/browse/SCB-840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16581961#comment-16581961
]
ASF GitHub Bot commented on SCB-840:
------------------------------------
little-cui closed pull request #414: SCB-840 Support configable limit in
buildin quota plugin
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/414
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pkg/util/sys.go b/pkg/util/sys.go
index 17052f97..7100e2e1 100644
--- a/pkg/util/sys.go
+++ b/pkg/util/sys.go
@@ -18,6 +18,7 @@ package util
import (
"os"
+ "strconv"
"unsafe"
)
@@ -51,3 +52,16 @@ func HostName() (hostname string) {
}
return
}
+
+func GetEnvInt(name string, def int) int {
+ env, ok := os.LookupEnv(name)
+ if ok {
+ i64, err := strconv.ParseInt(env, 10, 0)
+ if err != nil {
+ Logger().Errorf(err, "get env '%s' value failed, return
default value '%d'", name, def)
+ return def
+ }
+ return int(i64)
+ }
+ return def
+}
diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go
index 852851fc..38c02e8e 100644
--- a/pkg/util/util_test.go
+++ b/pkg/util/util_test.go
@@ -17,6 +17,7 @@
package util
import (
+ "os"
"testing"
"time"
)
@@ -122,3 +123,21 @@ func TestSystemPackage(t *testing.T) {
t.Fatalf("TestSystemPackage failed")
}
}
+
+func TestGetEnvInt(t *testing.T) {
+ if GetEnvInt("a", 1) != 1 {
+ t.Fatalf("TestGetEnvInt failed")
+ }
+ os.Setenv("a", "")
+ if GetEnvInt("a", 1) != 1 {
+ t.Fatalf("TestGetEnvInt failed")
+ }
+ os.Setenv("a", "x")
+ if GetEnvInt("a", 1) != 1 {
+ t.Fatalf("TestGetEnvInt failed")
+ }
+ os.Setenv("a", "2")
+ if GetEnvInt("a", 1) != 2 {
+ t.Fatalf("TestGetEnvInt failed")
+ }
+}
diff --git a/scripts/build/tools.sh b/scripts/build/tools.sh
index 59337113..dbf609d1 100644
--- a/scripts/build/tools.sh
+++ b/scripts/build/tools.sh
@@ -126,7 +126,7 @@ package() {
}
docker_builder_pattern() {
- local dockerfile=${1:-"."}
+ local dockerfile_dir=${1:-"."}
local output=${2:-"."}
local builder_name=servicecomb/service-center:build
local
builder_path=/go/src/github.com/apache/incubator-servicecomb-service-center
@@ -138,7 +138,8 @@ docker_builder_pattern() {
set -e
- docker build -t $builder_name . -f $dockerfile/Dockerfile.build
+ cd $dockerfile_dir
+ docker build -t $builder_name . -f Dockerfile.build
docker create --name builder $builder_name
docker cp builder:$builder_path/$app $output
docker rm -f builder
diff --git a/server/infra/quota/quota.go b/server/infra/quota/quota.go
index bb37a45d..b4f8bb43 100644
--- a/server/infra/quota/quota.go
+++ b/server/infra/quota/quota.go
@@ -17,15 +17,18 @@
package quota
import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
"golang.org/x/net/context"
"strconv"
)
-var (
- DefaultSchemaQuota = 0
- DefaultTagQuota = 0
- DefaultRuleQuota = 0
+const (
+ defaultServiceLimit = 50000
+ defaultInstanceLimit = 150000
+ defaultSchemaLimit = 100
+ defaultRuleLimit = 100
+ defaultTagLimit = 100
)
const (
@@ -37,6 +40,14 @@ const (
typeEnd
)
+var (
+ DefaultServiceQuota = util.GetEnvInt("QUOTA_SERVICE",
defaultServiceLimit)
+ DefaultInstanceQuota = util.GetEnvInt("QUOTA_INSTANCE",
defaultInstanceLimit)
+ DefaultSchemaQuota = util.GetEnvInt("QUOTA_SCHEMA",
defaultSchemaLimit)
+ DefaultTagQuota = util.GetEnvInt("QUOTA_TAG", defaultTagLimit)
+ DefaultRuleQuota = util.GetEnvInt("QUOTA_RULE", defaultRuleLimit)
+)
+
type ApplyQuotaResult struct {
Reporter QuotaReporter
Err *scerr.Error
diff --git a/server/plugin/infra/quota/buildin/buildin.go
b/server/plugin/infra/quota/buildin/buildin.go
index f783725b..0ca83161 100644
--- a/server/plugin/infra/quota/buildin/buildin.go
+++ b/server/plugin/infra/quota/buildin/buildin.go
@@ -17,38 +17,19 @@
package buildin
import (
- "fmt"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/core"
-
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
- scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
-
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
mgr
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
- serviceUtil
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
- "strings"
-)
-
-const (
- SERVICE_NUM_MAX_LIMIT = 50000
- INSTANCE_NUM_MAX_LIMIT = 150000
- RULE_NUM_MAX_LIMIT_PER_SERVICE = 100
- SCHEMA_NUM_MAX_LIMIT_PER_SERVICE = 100
- TAG_NUM_MAX_LIMIT_PER_SERVICE = 100
)
func init() {
- quota.DefaultSchemaQuota = SCHEMA_NUM_MAX_LIMIT_PER_SERVICE
- quota.DefaultTagQuota = TAG_NUM_MAX_LIMIT_PER_SERVICE
- quota.DefaultRuleQuota = RULE_NUM_MAX_LIMIT_PER_SERVICE
-
mgr.RegisterPlugin(mgr.Plugin{mgr.QUOTA, "buildin", New})
}
func New() mgr.PluginInstance {
util.Logger().Infof("quota init, service: %d, instance: %d, schema:
%d/service, tag: %d/service, rule: %d/service",
- SERVICE_NUM_MAX_LIMIT, INSTANCE_NUM_MAX_LIMIT,
+ quota.DefaultServiceQuota, quota.DefaultInstanceQuota,
quota.DefaultSchemaQuota, quota.DefaultTagQuota,
quota.DefaultRuleQuota)
return &BuildInQuota{}
}
@@ -63,18 +44,8 @@ func (q *BuildInQuota) Apply4Quotas(ctx context.Context, res
*quota.ApplyQuotaRe
return df(ctx, res)
}
- data := &QuotaApplyData{
- domain: strings.Split(res.DomainProject, "/")[0],
- quotaSize: res.QuotaSize,
- }
- switch res.QuotaType {
- case quota.MicroServiceInstanceQuotaType:
- return instanceQuotaCheck(ctx, data)
- case quota.MicroServiceQuotaType:
- return serviceQuotaCheck(ctx, data)
- default:
- return ResourceLimitHandler(ctx, res)
- }
+ return CommonQuotaCheck(ctx, res, resourceQuota(res.QuotaType),
resourceLimitHandler)
+
}
//向配额中心上报配额使用量
@@ -85,165 +56,3 @@ func (q *BuildInQuota) RemandQuotas(ctx context.Context,
quotaType quota.Resourc
return
}
}
-
-func ResourceLimitHandler(ctx context.Context, res *quota.ApplyQuotaResource)
*quota.ApplyQuotaResult {
- var key string
- var max int64 = 0
- var indexer backend.Indexer
-
- domainProject := res.DomainProject
- serviceId := res.ServiceId
- switch res.QuotaType {
- case quota.RuleQuotaType:
- key = core.GenerateServiceRuleKey(domainProject, serviceId, "")
- max = int64(quota.DefaultRuleQuota)
- indexer = backend.Store().Rule()
- case quota.SchemaQuotaType:
- key = core.GenerateServiceSchemaKey(domainProject, serviceId,
"")
- max = int64(quota.DefaultSchemaQuota)
- indexer = backend.Store().Schema()
- case quota.TagQuotaType:
- applyNum := res.QuotaSize
- max = int64(quota.DefaultTagQuota)
- tags, err := serviceUtil.GetTagsUtils(ctx, domainProject,
serviceId)
- if err != nil {
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, err.Error()))
- }
- curNum := int64(len(tags))
- if curNum+applyNum > max {
- mes := fmt.Sprintf("no quota to apply %s , max quota is
%d, current used quota is %d, apply quota num is %d",
- res.QuotaType, max, curNum, applyNum)
- util.Logger().Errorf(nil, "%s, serviceId is %s", mes,
serviceId)
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrNotEnoughQuota, mes))
- }
- return quota.NewApplyQuotaResult(nil, nil)
- default:
- mes := fmt.Sprintf("not define quota type %s", res.QuotaType)
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, mes))
- }
-
- resp, err := indexer.Search(ctx,
- registry.WithStrKey(key),
- registry.WithPrefix(),
- registry.WithCountOnly())
- if err != nil {
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, err.Error()))
- }
- num := resp.Count + int64(res.QuotaSize)
- util.Logger().Debugf("resource num is %d", num)
- if num > max {
- mes := fmt.Sprintf("no quota to apply %s, max quota is %d,
current used quota is %d, apply quota num is %d",
- res.QuotaType, max, resp.Count, res.QuotaSize)
- util.Logger().Errorf(nil, "%s, serviceId %s", mes, serviceId)
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrNotEnoughQuota, mes))
- }
- return quota.NewApplyQuotaResult(nil, nil)
-}
-
-type QuotaApplyData struct {
- domain string
- project string
- domainProject string
- quotaSize int64
-}
-
-type GetCurUsedNum func(context.Context, *QuotaApplyData) (int64, error)
-type GetLimitQuota func() int64
-
-type QuotaCheckResult struct {
- IsOk bool
- CurNum int64
- Err error
-}
-
-func NewQuotaCheckResult(isOk bool, curNum int64, err error) QuotaCheckResult {
- return QuotaCheckResult{
- isOk,
- curNum,
- err,
- }
-}
-
-func quotaCheck(ctx context.Context, data *QuotaApplyData, getLimitQuota
GetLimitQuota, getCurUsedNum GetCurUsedNum) QuotaCheckResult {
- limitQuota := getLimitQuota()
- curNum, err := getCurUsedNum(ctx, data)
- if err != nil {
- return NewQuotaCheckResult(false, 0, err)
- }
- if curNum+data.quotaSize > limitQuota {
- return NewQuotaCheckResult(false, curNum, nil)
- }
- return NewQuotaCheckResult(true, curNum, nil)
-}
-
-func instanceQuotaCheck(ctx context.Context, data *QuotaApplyData)
*quota.ApplyQuotaResult {
- rst := quotaCheck(ctx, data, getInstanceMaxLimit, getAllInstancesNum)
- err := rst.Err
- if rst.Err != nil {
- util.Logger().Errorf(rst.Err, "instance quota check failed")
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, err.Error()))
- }
- if !rst.IsOk {
- mes := fmt.Sprintf("no quota to create instance, max num is %d,
curNum is %d, apply num is %d",
- getInstanceMaxLimit(), rst.CurNum, data.quotaSize)
- util.Logger().Errorf(nil, mes)
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrNotEnoughQuota, mes))
- }
- return quota.NewApplyQuotaResult(nil, nil)
-}
-
-func getInstanceMaxLimit() int64 {
- return INSTANCE_NUM_MAX_LIMIT
-}
-
-func getInstancesNum(ctx context.Context, key string) (int64, error) {
- resp, err := backend.Store().Instance().Search(ctx,
- registry.WithStrKey(key),
- registry.WithPrefix(),
- registry.WithCountOnly())
- if err != nil {
- return 0, err
- }
- return resp.Count, nil
-}
-
-func getAllInstancesNum(ctx context.Context, data *QuotaApplyData) (int64,
error) {
- key := core.GetInstanceRootKey("")
- return getInstancesNum(ctx, key)
-}
-
-func serviceQuotaCheck(ctx context.Context, data *QuotaApplyData)
*quota.ApplyQuotaResult {
- rst := quotaCheck(ctx, data, getServiceMaxLimit, getAllServicesNum)
- err := rst.Err
- if err != nil {
- util.Logger().Errorf(err, "service quota check failed")
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, err.Error()))
- }
- if !rst.IsOk {
- mes := fmt.Sprintf("no quota to create service, max quota is
%d, current used quota is %d, apply quota num is %d",
- getServiceMaxLimit(), rst.CurNum, data.quotaSize)
- util.Logger().Errorf(err, mes)
- return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrNotEnoughQuota, mes))
- }
- return quota.NewApplyQuotaResult(nil, nil)
-}
-
-func getServiceMaxLimit() int64 {
- return SERVICE_NUM_MAX_LIMIT
-}
-
-func getServicesNum(ctx context.Context, key string) (int64, error) {
- resp, err := backend.Store().Service().Search(ctx,
- registry.WithStrKey(key),
- registry.WithPrefix(),
- registry.WithCountOnly())
- if err != nil {
- return 0, err
- }
- return resp.Count, nil
-}
-
-func getAllServicesNum(ctx context.Context, data *QuotaApplyData) (int64,
error) {
- key := core.GetServiceRootKey("")
- return getServicesNum(ctx, key)
-}
diff --git a/server/plugin/infra/quota/buildin/common.go
b/server/plugin/infra/quota/buildin/common.go
new file mode 100644
index 00000000..5b269e15
--- /dev/null
+++ b/server/plugin/infra/quota/buildin/common.go
@@ -0,0 +1,108 @@
+/*
+ * 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 buildin
+
+import (
+ "fmt"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+ scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ serviceUtil
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
+ "golang.org/x/net/context"
+)
+
+type GetCurUsedNum func(context.Context, *quota.ApplyQuotaResource) (int64,
error)
+type GetLimitQuota func() int64
+
+func CommonQuotaCheck(ctx context.Context, res *quota.ApplyQuotaResource,
+ getLimitQuota GetLimitQuota, getCurUsedNum GetCurUsedNum)
*quota.ApplyQuotaResult {
+ limitQuota := getLimitQuota()
+ curNum, err := getCurUsedNum(ctx, res)
+ if err != nil {
+ util.Logger().Errorf(err, "%s quota check failed",
res.QuotaType)
+ return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrInternal, err.Error()))
+ }
+ if curNum+res.QuotaSize > limitQuota {
+ mes := fmt.Sprintf("no quota to create %s, max num is %d,
curNum is %d, apply num is %d",
+ res.QuotaType, limitQuota, curNum, res.QuotaSize)
+ util.Logger().Errorf(nil, mes)
+ return quota.NewApplyQuotaResult(nil,
scerr.NewError(scerr.ErrNotEnoughQuota, mes))
+ }
+ return quota.NewApplyQuotaResult(nil, nil)
+}
+
+func resourceQuota(t quota.ResourceType) GetLimitQuota {
+ return func() int64 {
+ switch t {
+ case quota.MicroServiceInstanceQuotaType:
+ return int64(quota.DefaultInstanceQuota)
+ case quota.MicroServiceQuotaType:
+ return int64(quota.DefaultServiceQuota)
+ case quota.RuleQuotaType:
+ return int64(quota.DefaultRuleQuota)
+ case quota.SchemaQuotaType:
+ return int64(quota.DefaultSchemaQuota)
+ case quota.TagQuotaType:
+ return int64(quota.DefaultTagQuota)
+ default:
+ return 0
+ }
+ }
+}
+
+func resourceLimitHandler(ctx context.Context, res *quota.ApplyQuotaResource)
(int64, error) {
+ var key string
+ var indexer backend.Indexer
+
+ domainProject := res.DomainProject
+ serviceId := res.ServiceId
+
+ switch res.QuotaType {
+ case quota.MicroServiceInstanceQuotaType:
+ key = core.GetInstanceRootKey("")
+ indexer = backend.Store().Instance()
+ case quota.MicroServiceQuotaType:
+ key = core.GetServiceRootKey("")
+ indexer = backend.Store().Service()
+ case quota.RuleQuotaType:
+ key = core.GenerateServiceRuleKey(domainProject, serviceId, "")
+ indexer = backend.Store().Rule()
+ case quota.SchemaQuotaType:
+ key = core.GenerateServiceSchemaKey(domainProject, serviceId,
"")
+ indexer = backend.Store().Schema()
+ case quota.TagQuotaType:
+ tags, err := serviceUtil.GetTagsUtils(ctx, domainProject,
serviceId)
+ if err != nil {
+ return 0, err
+ }
+ return int64(len(tags)), nil
+ default:
+ return 0, fmt.Errorf("not define quota type '%s'",
res.QuotaType)
+ }
+
+ resp, err := indexer.Search(ctx,
+ registry.WithStrKey(key),
+ registry.WithPrefix(),
+ registry.WithCountOnly())
+ if err != nil {
+ return 0, err
+ }
+ return resp.Count, nil
+}
diff --git a/server/plugin/infra/quota/unlimit/unlimit.go
b/server/plugin/infra/quota/unlimit/unlimit.go
index 5aa4b0b8..b640ec15 100644
--- a/server/plugin/infra/quota/unlimit/unlimit.go
+++ b/server/plugin/infra/quota/unlimit/unlimit.go
@@ -17,6 +17,7 @@
package unlimit
import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
mgr
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
"github.com/astaxie/beego"
@@ -30,6 +31,8 @@ func init() {
if quataType != "unlimit" {
return
}
+ quota.DefaultServiceQuota = 0
+ quota.DefaultInstanceQuota = 0
quota.DefaultSchemaQuota = 0
quota.DefaultTagQuota = 0
quota.DefaultRuleQuota = 0
@@ -39,6 +42,7 @@ type Unlimit struct {
}
func New() mgr.PluginInstance {
+ util.Logger().Infof("quota init, all resources are unlimited")
return &Unlimit{}
}
diff --git a/server/service/microservice_test.go
b/server/service/microservice_test.go
index 213ed4d2..edbfbdf8 100644
--- a/server/service/microservice_test.go
+++ b/server/service/microservice_test.go
@@ -20,7 +20,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
@@ -52,7 +52,7 @@ var _ = Describe("'Micro-service' service", func() {
Context("all max", func() {
It("should be passed", func() {
- size :=
buildin.SCHEMA_NUM_MAX_LIMIT_PER_SERVICE + 1
+ size := quota.DefaultSchemaQuota + 1
paths := make([]*pb.ServicePath, 0, size)
properties := make(map[string]string, size)
for i := 0; i < size; i++ {
diff --git a/server/service/rule_test.go b/server/service/rule_test.go
index 6dbe8370..051b1f47 100644
--- a/server/service/rule_test.go
+++ b/server/service/rule_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
@@ -200,7 +200,7 @@ var _ = Describe("'Rule' service", func() {
Context("when create rule out of gauge", func() {
It("should be failed", func() {
- size := buildin.RULE_NUM_MAX_LIMIT_PER_SERVICE
+ 1
+ size := quota.DefaultRuleQuota + 1
rules := make([]*pb.AddOrUpdateServiceRule, 0,
size)
for i := 0; i < size; i++ {
rules = append(rules,
&pb.AddOrUpdateServiceRule{
@@ -536,7 +536,7 @@ var _ = Describe("'Rule' service", func() {
By("rules is invalid")
var arr []string
- for i := 0; i <
buildin.RULE_NUM_MAX_LIMIT_PER_SERVICE+1; i++ {
+ for i := 0; i < quota.DefaultRuleQuota+1; i++ {
arr = append(arr, strconv.Itoa(i))
}
respAddRule, err =
serviceResource.DeleteRule(getContext(), &pb.DeleteServiceRulesRequest{
diff --git a/server/service/schema_test.go b/server/service/schema_test.go
index 2137f9da..b79ef06e 100644
--- a/server/service/schema_test.go
+++ b/server/service/schema_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
"github.com/apache/incubator-servicecomb-service-center/server/service"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -208,7 +208,7 @@ var _ = Describe("'Schema' service", func() {
})
Context("when create schemas out of gauge", func() {
- size := buildin.SCHEMA_NUM_MAX_LIMIT_PER_SERVICE + 1
+ size := quota.DefaultSchemaQuota + 1
schemaIds := make([]string, 0, size)
schemas := make([]*pb.Schema, 0, size)
for i := 0; i < size; i++ {
@@ -234,14 +234,14 @@ var _ = Describe("'Schema' service", func() {
By("batch modify schemas 2")
respCreateSchemas, err =
serviceResource.ModifySchemas(getContext(), &pb.ModifySchemasRequest{
ServiceId: serviceIdDev,
- Schemas:
schemas[:buildin.SCHEMA_NUM_MAX_LIMIT_PER_SERVICE],
+ Schemas:
schemas[:quota.DefaultSchemaQuota],
})
Expect(err).To(BeNil())
Expect(respCreateSchemas.Response.Code).To(Equal(pb.Response_SUCCESS))
By("modify one schema")
respCreateService := &pb.ModifySchemaResponse{}
- schema :=
schemas[buildin.SCHEMA_NUM_MAX_LIMIT_PER_SERVICE]
+ schema := schemas[quota.DefaultSchemaQuota]
respCreateService, err =
serviceResource.ModifySchema(getContext(), &pb.ModifySchemaRequest{
ServiceId: serviceIdDev,
SchemaId: schema.SchemaId,
diff --git a/server/service/tag_test.go b/server/service/tag_test.go
index 322ce9b1..8396eac0 100644
--- a/server/service/tag_test.go
+++ b/server/service/tag_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr
"github.com/apache/incubator-servicecomb-service-center/server/error"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
+
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
@@ -106,7 +106,7 @@ var _ = Describe("'Tag' service", func() {
Context("when request is valid", func() {
It("should be passed", func() {
By("all max")
- size := buildin.TAG_NUM_MAX_LIMIT_PER_SERVICE
+ size := quota.DefaultRuleQuota
tags := make(map[string]string, size)
for i := 0; i < size; i++ {
s := "tag" + strconv.Itoa(i)
@@ -123,7 +123,7 @@ var _ = Describe("'Tag' service", func() {
Context("when create tag out of gauge", func() {
It("should be failed", func() {
- size := buildin.TAG_NUM_MAX_LIMIT_PER_SERVICE +
1
+ size := quota.DefaultRuleQuota + 1
tags := make(map[string]string, size)
for i := 0; i < size; i++ {
s := "tag" + strconv.Itoa(i)
@@ -136,7 +136,7 @@ var _ = Describe("'Tag' service", func() {
Expect(err).To(BeNil())
Expect(respAddTags.Response.Code).To(Equal(scerr.ErrInvalidParams))
- size = buildin.TAG_NUM_MAX_LIMIT_PER_SERVICE / 2
+ size = quota.DefaultRuleQuota / 2
tags = make(map[string]string, size)
for i := 0; i < size; i++ {
s := "tag" + strconv.Itoa(i)
@@ -513,7 +513,7 @@ var _ = Describe("'Tag' service", func() {
Expect(respAddTags.Response.Code).To(Equal(scerr.ErrInvalidParams))
var arr []string
- for i := 0; i <
buildin.TAG_NUM_MAX_LIMIT_PER_SERVICE+1; i++ {
+ for i := 0; i < quota.DefaultRuleQuota+1; i++ {
arr = append(arr, strconv.Itoa(i))
}
respAddTags, err =
serviceResource.DeleteTags(getContext(), &pb.DeleteServiceTagsRequest{
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Support configable limit in buildin quota plugin
> ------------------------------------------------
>
> Key: SCB-840
> URL: https://issues.apache.org/jira/browse/SCB-840
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
> Fix For: service-center-1.1.0
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)