improvement: status is disabled by default (#137)
diff --git a/deployments/db.js b/deployments/db.js
index d150b41..a880136 100644
--- a/deployments/db.js
+++ b/deployments/db.js
@@ -50,6 +50,7 @@
bsonType: "long",
},
status: {
+ enum: [ "enabled","disabled" ],
bsonType: "string",
},
}
diff --git a/server/resource/v1/history_resource_test.go b/server/resource/v1/history_resource_test.go
index 0f8b830..6b993f1 100644
--- a/server/resource/v1/history_resource_test.go
+++ b/server/resource/v1/history_resource_test.go
@@ -20,6 +20,7 @@
"context"
"encoding/json"
"fmt"
+ common2 "github.com/apache/servicecomb-kie/pkg/common"
"io/ioutil"
"net/http"
"net/http/httptest"
@@ -39,15 +40,17 @@
func TestHistoryResource_GetRevisions(t *testing.T) {
kv := &model.KVDoc{
- Key: "test",
- Value: "revisions",
+ Key: "test",
+ Value: "revisions",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"test": "revisions",
},
Domain: "default",
Project: "history_test",
}
- kv, _ = service.KVService.Create(context.Background(), kv)
+ kv, err := service.KVService.Create(context.Background(), kv)
+ assert.NoError(t, err)
path := fmt.Sprintf("/v1/history_test/kie/revision/%s", kv.ID)
r, _ := http.NewRequest("GET", path, nil)
revision := &v1.HistoryResource{}
diff --git a/server/resource/v1/kv_resource.go b/server/resource/v1/kv_resource.go
index 6019684..7f9a4ab 100644
--- a/server/resource/v1/kv_resource.go
+++ b/server/resource/v1/kv_resource.go
@@ -52,6 +52,9 @@
domain := ReadDomain(rctx)
kv.Domain = domain.(string)
kv.Project = project
+ if kv.Status == "" {
+ kv.Status = common.StatusDisabled
+ }
err = validate.Validate(kv)
if err != nil {
WriteErrResponse(rctx, http.StatusBadRequest, err.Error())
@@ -60,7 +63,7 @@
err = quota.PreCreate("", kv.Domain, "", 1)
if err != nil {
if err == quota.ErrReached {
- openlogging.Info("can not create kv, due to quota violation")
+ openlogging.Info(fmt.Sprintf("can not create kv %s@%s, due to quota violation", kv.Key, kv.Project))
WriteErrResponse(rctx, http.StatusUnprocessableEntity, err.Error())
return
}
diff --git a/server/service/mongo/kv/kv_service.go b/server/service/mongo/kv/kv_service.go
index 0587b03..97d3c20 100644
--- a/server/service/mongo/kv/kv_service.go
+++ b/server/service/mongo/kv/kv_service.go
@@ -77,8 +77,12 @@
if err != nil {
return nil, err
}
- oldKV.Status = kv.Status
- oldKV.Value = kv.Value
+ if kv.Status != "" {
+ oldKV.Status = kv.Status
+ }
+ if kv.Value != "" {
+ oldKV.Value = kv.Value
+ }
err = updateKeyValue(ctx, oldKV)
if err != nil {
return nil, err
diff --git a/server/service/mongo/kv/kv_service_test.go b/server/service/mongo/kv/kv_service_test.go
index 0ad8fc1..4e30185 100644
--- a/server/service/mongo/kv/kv_service_test.go
+++ b/server/service/mongo/kv/kv_service_test.go
@@ -19,6 +19,7 @@
import (
"context"
+ common2 "github.com/apache/servicecomb-kie/pkg/common"
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/config"
"github.com/apache/servicecomb-kie/server/service"
@@ -50,8 +51,9 @@
kvsvc := &kv.Service{}
t.Run("put kv timeout,with labels app and service", func(t *testing.T) {
kv, err := kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
"service": "cart",
@@ -64,8 +66,9 @@
})
t.Run("put kv timeout,with labels app, service and version", func(t *testing.T) {
kv, err := kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
"service": "cart",
@@ -86,8 +89,9 @@
})
t.Run("put kv timeout,with labels app,and update value", func(t *testing.T) {
beforeKV, err := kvsvc.Create(context.Background(), &model.KVDoc{
- Key: "timeout",
- Value: "1s",
+ Key: "timeout",
+ Value: "1s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
},
@@ -115,8 +119,9 @@
kvsvc := &kv.Service{}
t.Run("create kv timeout,with labels app and service", func(t *testing.T) {
result, err := kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
"service": "utCart",
@@ -131,8 +136,9 @@
})
t.Run("create the same kv", func(t *testing.T) {
_, err := kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
"service": "utCart",
diff --git a/server/service/mongo/view/view_service_test.go b/server/service/mongo/view/view_service_test.go
index c43fce0..a87d1b6 100644
--- a/server/service/mongo/view/view_service_test.go
+++ b/server/service/mongo/view/view_service_test.go
@@ -20,6 +20,7 @@
import (
"context"
"encoding/json"
+ common2 "github.com/apache/servicecomb-kie/pkg/common"
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/config"
"github.com/apache/servicecomb-kie/server/service"
@@ -40,8 +41,9 @@
kvsvc := &kv.Service{}
t.Run("put view data", func(t *testing.T) {
kv, err := kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
"service": "cart",
@@ -54,8 +56,9 @@
assert.NotEmpty(t, kv.ID)
kv, err = kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "timeout",
- Value: "2s",
+ Key: "timeout",
+ Value: "2s",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
},
@@ -66,8 +69,9 @@
assert.NotEmpty(t, kv.ID)
kv, err = kvsvc.Create(context.TODO(), &model.KVDoc{
- Key: "retry",
- Value: "2",
+ Key: "retry",
+ Value: "2",
+ Status: common2.StatusEnabled,
Labels: map[string]string{
"app": "mall",
},