diff --git a/doc/cdc-usage.md b/doc/cdc-usage.md index a2f02755..5e7b0451 100644 --- a/doc/cdc-usage.md +++ b/doc/cdc-usage.md @@ -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 @@ -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. @@ -160,7 +177,10 @@ body: **response** ```json -{} +{ + "code": 200, + "data": {} +} ``` ### pause request @@ -185,7 +205,10 @@ body: **response** ```json -{} +{ + "code": 200, + "data": {} +} ``` ### resume request @@ -210,7 +233,10 @@ body: **response** ```json -{} +{ + "code": 200, + "data": {} +} ``` ### get request @@ -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" + } + } } ``` @@ -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" + } ] + } } ``` \ No newline at end of file diff --git a/server/cdc_impl.go b/server/cdc_impl.go index cfbdeb94..66a953ac 100644 --- a/server/cdc_impl.go +++ b/server/cdc_impl.go @@ -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) { diff --git a/server/cdc_impl_test.go b/server/cdc_impl_test.go index a6364d51..85d1bf3d 100644 --- a/server/cdc_impl_test.go +++ b/server/cdc_impl_test.go @@ -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) @@ -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) }) @@ -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) }) @@ -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) }) } diff --git a/server/model/common.go b/server/model/common.go index 13b65df6..b08fdd4a 100644 --- a/server/model/common.go +++ b/server/model/common.go @@ -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 diff --git a/server/model/request/base.go b/server/model/request/base.go index ae1b769a..3879ebd8 100644 --- a/server/model/request/base.go +++ b/server/model/request/base.go @@ -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 @@ -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 { diff --git a/server/model/request/get.go b/server/model/request/get.go index 237d8225..daead069 100644 --- a/server/model/request/get.go +++ b/server/model/request/get.go @@ -22,7 +22,7 @@ type GetRequest struct { } type GetResponse struct { - Task + Task Task `json:"task" mapstructure:"task"` } type GetPositionRequest struct {