Skip to content

Commit

Permalink
[feat] use cari package's NewTask and NewTombstone functions and chan…
Browse files Browse the repository at this point in the history
…ge db name in mongo model
  • Loading branch information
robotLJW committed Dec 22, 2021
1 parent 9a3c3f9 commit 3e93ff5
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
env:
GO111MODULE: on
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.16
id: go
- name: Checkout Source
uses: actions/checkout@v2
- name: Fmt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mongo_storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
sudo docker-compose -f ./examples/dev/docker-compose.yaml up -d
sleep 20
export TEST_DB_KIND=mongo
export TEST_DB_URI=mongodb://kie:[email protected]:27017/kie
export TEST_DB_URI=mongodb://kie:[email protected]:27017/servicecomb
time go test -v $(go list ./... | grep -v etcd | grep -v third_party | grep -v examples)
- name: Build kie images
run: |
Expand Down
2 changes: 1 addition & 1 deletion build/build_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ EOM

cat <<EOM > ${release_dir}/conf/kie-conf.yaml
db:
uri: mongodb://root:[email protected]:27017/kie
uri: mongodb://root:[email protected]:27017/servicecomb
type: mongodb
poolSize: 10
ssl: false
Expand Down
2 changes: 1 addition & 1 deletion deployments/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
ports:
- 27017:27017
environment:
MONGO_INITDB_DATABASE: kie
MONGO_INITDB_DATABASE: servicecomb
MONGO_INITDB_ROOT_USERNAME: kie
MONGO_INITDB_ROOT_PASSWORD: 123
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docs/configurations/rbac.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ follow steps to enable service center [RBAC](https://service-center.readthedocs.
2.edit kie-conf.yaml
```ini
db:
uri: mongodb://kie:[email protected]:27017/kie
uri: mongodb://kie:[email protected]:27017/servicecomb
type: mongodb
rbac:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion docs/configurations/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ you can use mongo db as kie server storage to save configuration
### Example
```yaml
db:
uri: mongodb://kie:[email protected]:27017/kie
uri: mongodb://kie:[email protected]:27017/servicecomb
poolSize: 10
timeout: 5s
sslEnabled: true
Expand Down
10 changes: 5 additions & 5 deletions docs/getstarted/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use the [db init script](https://github.com/apache/servicecomb-kie/blob/master/d

```shell script
sudo docker run --name mongo -d \
-e "MONGO_INITDB_DATABASE=kie" \
-e "MONGO_INITDB_ROOT_USERNAME=root" \
-e "MONGO_INITDB_ROOT_PASSWORD=root" \
-e "MONGO_INITDB_DATABASE=servicecomb" \
-e "MONGO_INITDB_ROOT_USERNAME=kie" \
-e "MONGO_INITDB_ROOT_PASSWORD=123" \
-p 27017:27017 \
-v ./deployments/db.js:/docker-entrypoint-initdb.d/db.js:ro \
mongo:4.0
Expand All @@ -21,8 +21,8 @@ Run kie server
```shell script
sudo docker run --name kie-server -d \
-e "MONGODB_ADDR=${MONGO_IP}:27017" \
-e "MONGODB_USER=root" \
-e "MONGODB_PWD=root" \
-e "MONGODB_USER=kie" \
-e "MONGODB_PWD=123" \
-p 30110:30110 \
servicecomb/kie
```
Expand Down
2 changes: 1 addition & 1 deletion examples/dev/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ db.createUser(
roles: [
{
role: "readWrite",
db: "kie"
db: "servicecomb"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
ports:
- 27017:27017
environment:
MONGO_INITDB_DATABASE: kie
MONGO_INITDB_DATABASE: servicecomb
MONGO_INITDB_ROOT_USERNAME: kie
MONGO_INITDB_ROOT_PASSWORD: 123
volumes:
Expand Down
124 changes: 122 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/apache/servicecomb-kie

require (
github.com/emicklei/go-restful v2.12.0+incompatible
github.com/go-chassis/cari v0.5.1-0.20211127060616-302dc831a28f
github.com/go-chassis/cari v0.5.1-0.20211222030004-0bb606bff5c5
github.com/go-chassis/foundation v0.3.1-0.20210811025651-7f4d2b2b906c
github.com/go-chassis/go-archaius v1.5.2-0.20210301074935-e4694f6b077b
github.com/go-chassis/go-chassis/v2 v2.3.1-0.20211122011324-0a97efcf095b
Expand All @@ -18,4 +18,124 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

go 1.16
require (
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e // indirect
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.34.28 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cenkalti/backoff v2.0.0+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/go-chassis/go-restful-swagger20 v1.0.3 // indirect
github.com/go-chassis/kie-client v0.1.0 // indirect
github.com/go-chassis/sc-client v0.6.1-0.20210918130508-2b9daad232da // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator v9.31.0+incompatible // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/gorilla/websocket v1.4.3-0.20210424162022-e8629af678b7 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-msgpack v0.5.3 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-sockaddr v1.0.0 // indirect
github.com/hashicorp/go-syslog v1.0.0 // indirect
github.com/hashicorp/go-version v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/mdns v1.0.1 // indirect
github.com/hashicorp/memberlist v0.2.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/karlseguin/ccache/v2 v2.0.8 // indirect
github.com/klauspost/compress v1.9.5 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.26 // indirect
github.com/mitchellh/cli v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/v2 v2.305.0 // indirect
go.etcd.io/etcd/client/v3 v3.5.0 // indirect
go.etcd.io/etcd/pkg/v3 v3.5.0 // indirect
go.etcd.io/etcd/raft/v3 v3.5.0 // indirect
go.etcd.io/etcd/server/v3 v3.5.0 // indirect
go.opentelemetry.io/contrib v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 // indirect
go.opentelemetry.io/otel v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
go.opentelemetry.io/otel/metric v0.20.0 // indirect
go.opentelemetry.io/otel/sdk v0.20.0 // indirect
go.opentelemetry.io/otel/sdk/export/metric v0.20.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
go.opentelemetry.io/otel/trace v0.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apimachinery v0.17.0 // indirect
k8s.io/client-go v0.17.0 // indirect
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

go 1.17
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ github.com/go-chassis/cari v0.0.0-20201210041921-7b6fbef2df11/go.mod h1:MgtsEI0A
github.com/go-chassis/cari v0.4.0/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.0/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.1-0.20210823023004-74041d1363c4/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.1-0.20211127060616-302dc831a28f h1:H+P5YSpPaTV2wfnlYj8shLRLpSVYC9BrkVrJr+4Bcuo=
github.com/go-chassis/cari v0.5.1-0.20211127060616-302dc831a28f/go.mod h1:av/19fqwEP4eOC8unL/z67AAbFDwXUCko6SKa4Avrd8=
github.com/go-chassis/cari v0.5.1-0.20211222030004-0bb606bff5c5 h1:rlz19OM0C6oD5pUvhqpK2yzU6pyH9M+bt/mglfZrt90=
github.com/go-chassis/cari v0.5.1-0.20211222030004-0bb606bff5c5/go.mod h1:HG0Olv4sy/4e/3e9S0pofO0pzchaDjJ0hMweyFU7d5Q=
github.com/go-chassis/foundation v0.2.2-0.20201210043510-9f6d3de40234/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
github.com/go-chassis/foundation v0.2.2/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
github.com/go-chassis/foundation v0.3.0/go.mod h1:2PjwqpVwYEVaAldl5A58a08viH8p27pNeYaiE3ZxOBA=
Expand Down
18 changes: 3 additions & 15 deletions server/datasource/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/go-chassis/cari/sync"
"github.com/go-chassis/openlog"
"github.com/gofrs/uuid"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/config"
Expand Down Expand Up @@ -163,20 +162,9 @@ func ClearPart(kv *model.KVDoc) {
kv.LabelFormat = ""
}

// NewTask return task with action and datatype
func NewTask(domain, project, action, dataType string) (*sync.Task, error) {
taskId, err := uuid.NewV4()
if err != nil {
return nil, err
}
return &sync.Task{
TaskID: taskId.String(),
Action: action,
DataType: dataType,
Domain: domain,
Project: project,
Timestamp: time.Now().Unix(),
}, nil
// NewCfgTombstoneID return tombstone's resourceID, using key and labelFormat as resourceID
func NewCfgTombstoneID(key string, labelFormat string) string {
return key + "/" + labelFormat
}

// NewTombstone return tombstone with resourceType ,domain and project
Expand Down
17 changes: 8 additions & 9 deletions server/datasource/etcd/kv/kv_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func txnCreate(ctx context.Context, kv *model.KVDoc) (bool, error) {
openlog.Error("fail to marshal kv " + err.Error())
return false, err
}
task, err := datasource.NewTask(kv.Domain, kv.Project, sync.CreateAction, datasource.ConfigResource)
task, err := sync.NewTask(kv.Domain, kv.Project, sync.CreateAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
return false, err
Expand Down Expand Up @@ -148,7 +148,7 @@ func txnUpdate(ctx context.Context, kv *model.KVDoc) error {
openlog.Error(err.Error())
return err
}
task, err := datasource.NewTask(kv.Domain, kv.Project, sync.UpdateAction, datasource.ConfigResource)
task, err := sync.NewTask(kv.Domain, kv.Project, sync.UpdateAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
return err
Expand Down Expand Up @@ -243,7 +243,7 @@ func txnFindOneAndDelete(ctx context.Context, kvID, project, domain string) (*mo
openlog.Error(err.Error())
return nil, err
}
task, err := datasource.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
task, err := sync.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
return nil, err
Expand All @@ -254,9 +254,8 @@ func txnFindOneAndDelete(ctx context.Context, kvID, project, domain string) (*mo
openlog.Error("fail to marshal task" + err.Error())
return nil, err
}
tombstone := datasource.NewTombstone(domain, project, datasource.ConfigResource)
// use key and labelFormat as resourceID
tombstone.ResourceID = kvDoc.Key + "/" + kvDoc.LabelFormat
tombstone := sync.NewTombstone(domain, project, datasource.ConfigResource,
datasource.NewCfgTombstoneID(kvDoc.Key, kvDoc.LabelFormat))
tombstoneBytes, err := json.Marshal(tombstone)
if err != nil {
openlog.Error("fail to marshal tombstone" + err.Error())
Expand Down Expand Up @@ -353,16 +352,16 @@ func txnFindManyAndDelete(ctx context.Context, kvIDs []string, project, domain s
if kvDoc == nil {
continue
}
task, err := datasource.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
task, err := sync.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task")
return nil, 0, err
}
docs[successKVNum] = kvDoc
tasks[successKVNum] = task
tasks[successKVNum].Data = kvDoc
tombstones[successKVNum] = datasource.NewTombstone(domain, project, datasource.ConfigResource)
tombstones[successKVNum].ResourceID = kvDoc.Key + "/" + kvDoc.LabelFormat
tombstones[successKVNum] = sync.NewTombstone(domain, project, datasource.ConfigResource,
datasource.NewCfgTombstoneID(kvDoc.Key, kvDoc.LabelFormat))
successKVNum++
}
if successKVNum == 0 {
Expand Down
16 changes: 8 additions & 8 deletions server/datasource/mongo/kv/kv_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func txnCreate(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error) {
}
return err
}
task, err := datasource.NewTask(kv.Domain, kv.Project, sync.CreateAction, datasource.ConfigResource)
task, err := sync.NewTask(kv.Domain, kv.Project, sync.CreateAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
errAbort := taskSession.AbortTransaction(sessionContext)
Expand Down Expand Up @@ -207,7 +207,7 @@ func txnUpdate(ctx context.Context, kv *model.KVDoc) error {
openlog.Error("decode error: " + err.Error())
return err
}
task, err := datasource.NewTask(kv.Domain, kv.Project, sync.UpdateAction, datasource.ConfigResource)
task, err := sync.NewTask(kv.Domain, kv.Project, sync.UpdateAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
errAbort := taskSession.AbortTransaction(sessionContext)
Expand Down Expand Up @@ -431,7 +431,7 @@ func txnFindOneAndDelete(ctx context.Context, kvID, project, domain string) (*mo
}
return err
}
task, err := datasource.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
task, err := sync.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
if err != nil {
openlog.Error("fail to create task" + err.Error())
errAbort := taskSession.AbortTransaction(sessionContext)
Expand Down Expand Up @@ -460,8 +460,8 @@ func txnFindOneAndDelete(ctx context.Context, kvID, project, domain string) (*mo
}
return err
}
tombstone := datasource.NewTombstone(domain, project, datasource.ConfigResource)
tombstone.ResourceID = curKV.Key + "/" + curKV.LabelFormat
tombstone := sync.NewTombstone(domain, project, datasource.ConfigResource,
datasource.NewCfgTombstoneID(curKV.Key, curKV.LabelFormat))
collection = session.GetDB().Collection(session.CollectionTombstone)
_, err = collection.InsertOne(sessionContext, tombstone)
if err != nil {
Expand Down Expand Up @@ -568,10 +568,10 @@ func txnFindManyAndDelete(ctx context.Context, kvIDs []string, project, domain s
tombstonesDoc := make([]interface{}, deletedCount)
for i := 0; i < int(deletedCount); i++ {
kv := kvs[i]
task, _ := datasource.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
task, _ := sync.NewTask(domain, project, sync.DeleteAction, datasource.ConfigResource)
task.Data = kv
tombstone := datasource.NewTombstone(domain, project, datasource.ConfigResource)
tombstone.ResourceID = kv.Key + "/" + kv.LabelFormat
tombstone := sync.NewTombstone(domain, project, datasource.ConfigResource,
datasource.NewCfgTombstoneID(kv.Key, kv.LabelFormat))
tasksDoc[i] = task
tombstonesDoc[i] = tombstone
}
Expand Down
2 changes: 1 addition & 1 deletion server/datasource/mongo/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

//const for db name and collection name
const (
DBName = "kie"
DBName = "servicecomb"

CollectionLabel = "label"
CollectionKV = "kv"
Expand Down
Loading

0 comments on commit 3e93ff5

Please sign in to comment.