Skip to content

Commit

Permalink
Merge 014e259 into e083e75
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang committed Jan 22, 2020
2 parents e083e75 + 014e259 commit 1c9612e
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 129 deletions.
1 change: 0 additions & 1 deletion build/docker/server/Dockerfile
Expand Up @@ -15,7 +15,6 @@

FROM ubuntu:19.04

RUN apt-get update && apt-get install -y net-tools
RUN mkdir -p /etc/servicecomb-kie/
RUN mkdir -p /opt/servicecomb-kie/conf

Expand Down
2 changes: 1 addition & 1 deletion deployments/db.js
Expand Up @@ -28,7 +28,7 @@ db.createUser(
}
);
db.createCollection("counter");
db.counter.insertOne( { name:"revision_counter",count: 1 } );
db.counter.insertOne( { name:"revision_counter",count: 1,domain:"default" } );
db.createCollection( "kv", {
validator: { $jsonSchema: {
bsonType: "object",
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.rst
Expand Up @@ -7,3 +7,4 @@ User guides

configurations/storage
configurations/registry
configurations/long_polling
36 changes: 36 additions & 0 deletions docs/configurations/long_polling.md
@@ -0,0 +1,36 @@
# Long polling
*experimental*

Kie leverage gossip protocol to broad cast cluster events. if client use query parameter "?wait=5s" to poll key value,
this polling will become long polling and if there is key value change events,
server will response key values to client.

kie must join to a cluster and listen to peer events

start first node
```shell script
./kie --name=kie0 --listen-peer-addr=10.1.1.11:5000
```

start another node
```shell script
./kie --name=kie1 --listen-peer-addr=10.1.1.12:5000 --peer-addr=10.1.1.11:5000
```

### event payload and trigger condition

condition: key value put or delete

payload:
```go
{
"Key": "timeout",
"Action": "put",
"Labels": {
"app": "default",
"service": "order"
},
"DomainID": "default",
"Project": "default"
}
```
9 changes: 4 additions & 5 deletions docs/configurations/registry.md
@@ -1,19 +1,18 @@
# Registry
kie server is able to register to a registry, so that other client is able to discover it registry service.
# Use discovery service
kie server is able to register to a discovery service, so that other client is able to discover it registry service.
by default registry feature is disabled.
```yaml
cse:
service:
registry:
disabled: true
...
```
For example, kie is able to register to ServiceComb service center.


### Options
the function is powered by go-chassis in chassis.yaml file
refer to https://docs.go-chassis.com/user-guides/registry.html
this feature is powered by go-chassis,
refer to https://docs.go-chassis.com/user-guides/registry.html to know how to use

### Example
Register to ServiceComb service center
Expand Down
2 changes: 1 addition & 1 deletion docs/configurations/storage.md
Expand Up @@ -22,7 +22,7 @@ you can use mongo db as kie server storage to save configuration
db:
uri: mongodb://kie:123@127.0.0.1:27017/kie
poolSize: 10
timeout: 5m
timeout: 5s
sslEnabled: true
rootCAFile: /opt/kie/ca.crt
```
Expand Down
34 changes: 5 additions & 29 deletions docs/development-guide/build.md
@@ -1,40 +1,16 @@
# Build
# How to Build

Download and run mongodb,
see [MongoDB Community Edition Installation Tutorials](https://docs.mongodb.com/manual/installation/#mongodb-community-edition-installation-tutorials)

Write a script to create a user
```shell script
cat <<EOM > native_db.js
db.createUser(
{
user: "root",
pwd: "root",
roles:[
{
role: "readWrite",
db: "kie"
}
]
}
);
EOM
```

Exec native_db.js
```shell script bash
mongo 127.0.0.1/kie native_db.js
```
Download init and run mongodb as mentioned in get started section

Build serivcecomb-kie binary

```shell script bash
cd ${servicecomb_root_path}
cd ${project_root_path}
build/build_binary.sh
```

This will build 4 packages for 4 different platforms in ${servicecomb_root_path}/release/kie directory.
Choose the right one and unzip and run it.
This will build 4 packages for different platforms in ${servicecomb_root_path}/release/kie directory.
Choose the right one, unzip and run it.
For Example:
```shell script bash
cd ${servicecomb_root_path}/release/kie
Expand Down
1 change: 1 addition & 0 deletions docs/get-started.rst
Expand Up @@ -6,3 +6,4 @@ Get started
:glob:

getstarted/install.md
getstarted/verify.md
69 changes: 5 additions & 64 deletions docs/getstarted/install.md
Expand Up @@ -3,32 +3,16 @@
### With docker
Run mongodb server

write a script to create a user
```shell script
cat <<EOM > db.js
db.createUser(
{
user: "root",
pwd: "root",
roles:[
{
role: "readWrite",
db: "kie"
}
]
}
);
EOM
```
use the [db init script](https://github.com/apache/servicecomb-kie/blob/master/deployments/db.js)

```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" \
-p 27017:27017 \
-v ${PWD}/db.js:/docker-entrypoint-initdb.d/db.js:ro \
mongo:3.4
-v ./deployments/db.js:/docker-entrypoint-initdb.d/db.js:ro \
mongo:4.0
```
```shell script
export MONGO_IP=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' mongo`
Expand All @@ -43,32 +27,6 @@ sudo docker run --name kie-server -d \
servicecomb/kie
```

Put a key
```shell script
curl -X PUT \
http://127.0.0.1:30110/v1/default/kie/kv/ingressRule.http \
-H 'Content-Type: application/json' \
-d '{
"value":"some rule",
"type": "yaml",
"labels":{"app":"default"}
}'
```

response is
```json
{
"_id": "5d6f27c5a1b287c5074e4538",
"label_id": "5d6f27c5a1b287c5074e4537",
"key": "ingressRule.http",
"value": "rule",
"value_type": "text",
"labels": {
"app": "default"
},
"revision": 1
}
```

### Run locally with Docker compose

Expand All @@ -88,27 +46,10 @@ it will launch 3 components
Download and run mongodb,
see [MongoDB Community Edition Installation Tutorials](https://docs.mongodb.com/manual/installation/#mongodb-community-edition-installation-tutorials)

Write a script to create a user
```shell script
cat <<EOM > native_db.js
db.createUser(
{
user: "root",
pwd: "root",
roles:[
{
role: "readWrite",
db: "kie"
}
]
}
);
EOM
```

Exec native_db.js
use the [db init script](https://github.com/apache/servicecomb-kie/blob/master/deployments/db.js)
```shell script bash
mongo 127.0.0.1/kie native_db.js
mongo 127.0.0.1/kie db.js
```

Download the binary of kie, see https://apache.org/dyn/closer.cgi/servicecomb/servicecomb-kie/0.1.0/
Expand Down
30 changes: 30 additions & 0 deletions docs/getstarted/verify.md
@@ -0,0 +1,30 @@
# After running
Put a key
```shell script
curl -X PUT \
http://127.0.0.1:30110/v1/default/kie/kv/ingressRule \
-H 'Content-Type: application/json' \
-d '{
"value":"some rule",
"type": "yaml",
"labels":{"app":"default"}
}'
```

response is
```json
{
"id": "05529229-efc3-49ca-a765-05759b23ab28",
"label_id": "e7faac8e-053e-4906-99ab-989f61febe74",
"key": "ingressRule",
"value": "some rule",
"value_type": "text",
"create_revision": 13,
"update_revision": 13,
"labels": {
"app": "default"
}
}
```

the api docs is http://127.0.0.1:30110/apidocs.json
45 changes: 32 additions & 13 deletions docs/intro/concepts.md
@@ -1,27 +1,46 @@
# Concepts

### Labels
key value must belong to a identical label,
### labels
key value must belong to an identical label,
a labels is equivalent to a map, it is represent as a json object
```json
{
"app": "some_app",
"service": "payment",
"service": "web",
"environment": "production",
"version": "1.0.1"
}
```
for each unique label map, kie will generate a label id for it and produce a db record.
### key value
A key is usually related to some function in your program, let's say a new web UI should enable or not.
the labels is just like a map to tell you where this program located in. the map says,
it is located in production environment,the version is 1.0.1
A key value is usually a snippet configuration for your component, let's say a web UI widget should be enabled or not.
But usually, a component has different version and deployed in different environments.
the labels is indicates where this component located in.
below the labels indicates it is located in production environment,the version is 1.0.1
```json
{
"value":"true",
"labels":{
"service": "web-console",
"environment": "production",
"version": "1.0.1"
}
"id": "05529229-efc3-49ca-a765-05759b23ab28",
"label_id": "e7faac8e-053e-4906-99ab-989f61febe74",
"key": "enable_a_function",
"value": "true",
"value_type": "text",
"create_revision": 13,
"update_revision": 13,
"labels": {
"app": "some_app",
"service": "web",
"environment": "production",
"version": "1.0.1"
}
}
```
```

### revision
kie holds a global revision number it starts from 1,
each creation or update action of key value record will cause the increasing of this revision number,
key value has a immutable attribute "create_revision" when first created.
after each modify, "update_revision" will increase.
kie leverage this revision to reduce network cost,
when client polling for key values, it can give a revision number "?revision=200" in query parameter,
server side compare current revision with it , if they are the same, server will only return http status 304 to client.
at each query server will return current revision to client with response header "X-Kie-Revision"
2 changes: 0 additions & 2 deletions go.mod
Expand Up @@ -11,8 +11,6 @@ require (
github.com/golang/snappy v0.0.1 // indirect
github.com/hashicorp/mdns v1.0.1 // indirect
github.com/hashicorp/serf v0.8.5
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/satori/go.uuid v1.2.0
github.com/stretchr/testify v1.4.0
github.com/urfave/cli v1.20.0
Expand Down
6 changes: 3 additions & 3 deletions server/resource/v1/common.go
Expand Up @@ -146,12 +146,12 @@ func getLabels(rctx *restful.Context) (map[string]string, error) {
}
return labels, nil
}
func isRevised(ctx context.Context, revStr string) (bool, error) {
func isRevised(ctx context.Context, revStr, domain string) (bool, error) {
rev, err := strconv.ParseInt(revStr, 10, 64)
if err != nil {
return false, ErrInvalidRev
}
latest, err := service.RevisionService.GetRevision(ctx)
latest, err := service.RevisionService.GetRevision(ctx, domain)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func queryAndResponse(rctx *restful.Context,
WriteErrResponse(rctx, http.StatusInternalServerError, err.Error(), common.ContentTypeText)
return
}
rev, err := service.RevisionService.GetRevision(rctx.Ctx)
rev, err := service.RevisionService.GetRevision(rctx.Ctx, domain.(string))
if err != nil {
WriteErrResponse(rctx, http.StatusInternalServerError, err.Error(), common.ContentTypeText)
return
Expand Down
2 changes: 1 addition & 1 deletion server/resource/v1/kv_resource.go
Expand Up @@ -152,7 +152,7 @@ func returnData(rctx *restful.Context, domain interface{}, project string, label
}
rctx.WriteHeader(http.StatusNotModified)
} else {
revised, err := isRevised(rctx.Ctx, revStr)
revised, err := isRevised(rctx.Ctx, revStr, domain.(string))
if err != nil {
if err == ErrInvalidRev {
WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), common.ContentTypeText)
Expand Down

0 comments on commit 1c9612e

Please sign in to comment.