Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the empty field in the response #22

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 65 additions & 29 deletions doc/cdc-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@ All http APIs need to comply with the following rules:
}
```

Different requests are distinguished by `request_type`, which currently includes: create, delete, pause, resume, get and list. If the request fails, a non-200 http status code will be returned.
Different requests are distinguished by `request_type`, which currently includes: create, delete, pause, resume, get and list.

The format response is:

```json
{
"code": 200,
"message": "",
"data": {}
}
```

If the request fails, the code is not 200, and the error message will be displayed in the `message` field; if the request is successful, the returned data is in data field

### create request

Expand Down Expand Up @@ -133,7 +145,12 @@ body:
After success, the task_id will be returned, such as:

```json
{"task_id":"6623ae52d35842a5a2c9d89b16ed7aa1"}
{
"code": 200,
"data": {
"task_id":"6623ae52d35842a5a2c9d89b16ed7aa1"
}
}
```

If there is an exception, an http error will appear.
Expand All @@ -160,7 +177,10 @@ body:
**response**

```json
{}
{
"code": 200,
"data": {}
}
```

### pause request
Expand All @@ -185,7 +205,10 @@ body:
**response**

```json
{}
{
"code": 200,
"data": {}
}
```

### resume request
Expand All @@ -210,7 +233,10 @@ body:
**response**

```json
{}
{
"code": 200,
"data": {}
}
```

### get request
Expand All @@ -236,18 +262,25 @@ body:

```json
{
"task_id":"4d458a58b0f74e85b842b1244dc69546",
"Milvus_connect_param":{
"host":"localhost",
"port":19530,
"connect_timeout":10
},
"collection_infos":[
"code": 200,
"data": {
"Task": {
"collection_infos": [
{
"name":"*"
"name": "*"
}
],
"state":"Running"
],
"milvus_connect_param": {
"connect_timeout": 10,
"enable_tls": true,
"host": "localhost",
"port": 19541
},
"reason": "manually pause through http interface",
"state": "Paused",
"task_id": "728070fdf999499da869fc3a896217b0"
}
}
}
```

Expand All @@ -271,21 +304,24 @@ body:

```json
{
"code": 200,
"data": {
"tasks": [
{
"task_id": "4d458a58b0f74e85b842b1244dc69546",
"Milvus_connect_param": {
"host": "localhost",
"port": 19530,
"connect_timeout": 10
},
"collection_infos": [
{
"name": "*"
}
],
"state": "Running"
}
{
"task_id": "728070fdf999499da869fc3a896217b0",
"milvus_connect_param": {
"host": "localhost",
"port": 19541,
"connect_timeout": 10
},
"collection_infos": [
{
"name": "*"
}
],
"state": "Running"
}
]
}
}
```
3 changes: 3 additions & 0 deletions server/cdc_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ func (e *MetaCDC) Resume(req *request.ResumeRequest) (*request.ResumeResponse, e
}

func (e *MetaCDC) Get(req *request.GetRequest) (*request.GetResponse, error) {
if req.TaskID == "" {
return nil, servererror.NewClientError("task_id is empty")
}
taskInfo, err := store.GetTaskInfo(e.metaStoreFactory.GetTaskInfoMetaStore(context.Background()), req.TaskID)
if err != nil {
if errors.Is(err, servererror.NotFoundErr) {
Expand Down
14 changes: 10 additions & 4 deletions server/cdc_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ func TestTaskPosition(t *testing.T) {
}

func TestGet(t *testing.T) {
t.Run("empty task", func(t *testing.T) {
metaCDC := &MetaCDC{}
_, err := metaCDC.Get(&request.GetRequest{TaskID: ""})
assert.Error(t, err)
})

t.Run("err", func(t *testing.T) {
metaCDC := &MetaCDC{}
factory := mocks.NewMetaStoreFactory(t)
Expand All @@ -719,7 +725,7 @@ func TestGet(t *testing.T) {
factory.EXPECT().GetTaskInfoMetaStore(mock.Anything).Return(store).Once()
store.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("test")).Once()

_, err := metaCDC.Get(&request.GetRequest{})
_, err := metaCDC.Get(&request.GetRequest{TaskID: "test"})
assert.Error(t, err)
})

Expand All @@ -732,7 +738,7 @@ func TestGet(t *testing.T) {
factory.EXPECT().GetTaskInfoMetaStore(mock.Anything).Return(store).Once()
store.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).Return([]*meta.TaskInfo{}, nil).Once()

_, err := metaCDC.Get(&request.GetRequest{})
_, err := metaCDC.Get(&request.GetRequest{TaskID: "test"})
assert.Error(t, err)
})

Expand All @@ -750,9 +756,9 @@ func TestGet(t *testing.T) {
},
}, nil)

resp, err := metaCDC.Get(&request.GetRequest{})
resp, err := metaCDC.Get(&request.GetRequest{TaskID: "test"})
assert.NoError(t, err)
assert.Equal(t, "1", resp.TaskID)
assert.Equal(t, "1", resp.Task.TaskID)
})
}

Expand Down
4 changes: 2 additions & 2 deletions server/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package model
type MilvusConnectParam struct {
Host string `json:"host" mapstructure:"host"`
Port int `json:"port" mapstructure:"port"`
Username string `json:"username,omitempty" mapstructure:"username"`
Password string `json:"password,omitempty" mapstructure:"password"`
Username string `json:"username,omitempty" mapstructure:"username,omitempty"`
Password string `json:"password,omitempty" mapstructure:"password,omitempty"`
EnableTLS bool `json:"enable_tls" mapstructure:"enable_tls"`
IgnorePartition bool `json:"ignore_partition" mapstructure:"ignore_partition"`
// ConnectTimeout unit: s
Expand Down
6 changes: 3 additions & 3 deletions server/model/request/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type CDCRequest struct {

type CDCResponse struct {
Code int `json:"code" mapstructure:"code"`
Message string `json:"message" mapstructure:"message"`
Data map[string]any `json:"data" mapstructure:"data"`
Message string `json:"message,omitempty" mapstructure:"message,omitempty"`
Data map[string]any `json:"data,omitempty" mapstructure:"data,omitempty"`
}

// Task some info can be showed about the task
Expand All @@ -48,7 +48,7 @@ type Task struct {
MilvusConnectParam model.MilvusConnectParam `json:"milvus_connect_param" mapstructure:"milvus_connect_param"`
CollectionInfos []model.CollectionInfo `json:"collection_infos" mapstructure:"collection_infos"`
State string `json:"state" mapstructure:"state"`
LastPauseReason string `json:"reason" mapstructure:"reason"`
LastPauseReason string `json:"reason,omitempty" mapstructure:"reason,omitempty"`
}

func GetTask(taskInfo *meta.TaskInfo) Task {
Expand Down
2 changes: 1 addition & 1 deletion server/model/request/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type GetRequest struct {
}

type GetResponse struct {
Task
Task Task `json:"task" mapstructure:"task"`
}

type GetPositionRequest struct {
Expand Down
Loading