Skip to content

Commit

Permalink
apiv2(ticdc): refine open api v2 status code (#8409)
Browse files Browse the repository at this point in the history
close #8408
  • Loading branch information
sdojjy authored Mar 6, 2023
1 parent 66aaf04 commit 7cb9371
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 51 deletions.
16 changes: 8 additions & 8 deletions cdc/api/v2/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *OpenAPIV2) createChangefeed(c *gin.Context) {
log.Info("Create changefeed successfully!",
zap.String("id", info.ID),
zap.String("changefeed", infoStr))
c.JSON(http.StatusCreated, toAPIModel(info,
c.JSON(http.StatusOK, toAPIModel(info,
info.StartTs, info.StartTs,
nil, true))
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func (h *OpenAPIV2) verifyTable(c *gin.Context) {
// @Produce json
// @Param changefeed_id path string true "changefeed_id"
// @Param changefeedConfig body ChangefeedConfig true "changefeed config"
// @Success 202 {object} ChangeFeedInfo
// @Success 200 {object} ChangeFeedInfo
// @Failure 500,400 {object} model.HTTPError
// @Router /api/v2/changefeeds/{changefeed_id} [put]
func (h *OpenAPIV2) updateChangefeed(c *gin.Context) {
Expand Down Expand Up @@ -484,7 +484,7 @@ func (h *OpenAPIV2) getChangeFeed(c *gin.Context) {
// @Accept json
// @Produce json
// @Param changefeed_id path string true "changefeed_id"
// @Success 204
// @Success 200 {object} EmptyResponse
// @Failure 500,400 {object} model.HTTPError
// @Router /api/v2/changefeeds/{changefeed_id} [delete]
func (h *OpenAPIV2) deleteChangefeed(c *gin.Context) {
Expand All @@ -498,7 +498,7 @@ func (h *OpenAPIV2) deleteChangefeed(c *gin.Context) {
_, err := h.capture.StatusProvider().GetChangeFeedStatus(ctx, changefeedID)
if err != nil {
if cerror.ErrChangeFeedNotExists.Equal(err) {
c.Status(http.StatusNoContent)
c.JSON(http.StatusOK, &EmptyResponse{})
return
}
_ = c.Error(err)
Expand Down Expand Up @@ -535,7 +535,7 @@ func (h *OpenAPIV2) deleteChangefeed(c *gin.Context) {
_ = c.Error(err)
return
}
c.Status(http.StatusNoContent)
c.JSON(http.StatusOK, &EmptyResponse{})
}

// todo: remove this API
Expand Down Expand Up @@ -597,7 +597,7 @@ func (h *OpenAPIV2) getChangeFeedMetaInfo(c *gin.Context) {
// @Produce json
// @Param changefeed_id path string true "changefeed_id"
// @Param resumeConfig body ResumeChangefeedConfig true "resume config"
// @Success 202
// @Success 200 {object} EmptyResponse
// @Failure 500,400 {object} model.HTTPError
// @Router /api/v2/changefeeds/{changefeed_id}/resume [post]
func (h *OpenAPIV2) resumeChangefeed(c *gin.Context) {
Expand Down Expand Up @@ -685,7 +685,7 @@ func (h *OpenAPIV2) resumeChangefeed(c *gin.Context) {
_ = c.Error(err)
return
}
c.Status(http.StatusOK)
c.JSON(http.StatusOK, &EmptyResponse{})
}

// pauseChangefeed handles pause changefeed request
Expand All @@ -696,7 +696,7 @@ func (h *OpenAPIV2) resumeChangefeed(c *gin.Context) {
// @Accept json
// @Produce json
// @Param changefeed_id path string true "changefeed_id"
// @Success 202 {object} EmptyResponse
// @Success 200 {object} EmptyResponse
// @Failure 500,400 {object} model.HTTPError
// @Router /api/v2/changefeeds/{changefeed_id}/pause [post]
func (h *OpenAPIV2) pauseChangefeed(c *gin.Context) {
Expand Down
6 changes: 3 additions & 3 deletions cdc/api/v2/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestCreateChangefeed(t *testing.T) {
mysqlSink, err = util.MaskSinkURI(mysqlSink)
require.Nil(t, err)
require.Equal(t, mysqlSink, resp.SinkURI)
require.Equal(t, http.StatusCreated, w.Code)
require.Equal(t, http.StatusOK, w.Code)
}

func TestGetChangeFeed(t *testing.T) {
Expand Down Expand Up @@ -801,7 +801,7 @@ func TestDeleteChangefeed(t *testing.T) {
req, _ = http.NewRequestWithContext(context.Background(), remove.method,
fmt.Sprintf(remove.url, validID), nil)
router.ServeHTTP(w, req)
require.Equal(t, http.StatusNoContent, w.Code)
require.Equal(t, http.StatusOK, w.Code)

// case 3: query changefeed error
statusProvider.EXPECT().GetChangeFeedStatus(gomock.Any(), gomock.Any()).Return(
Expand All @@ -824,7 +824,7 @@ func TestDeleteChangefeed(t *testing.T) {
req, _ = http.NewRequestWithContext(context.Background(), remove.method,
fmt.Sprintf(remove.url, validID), nil)
router.ServeHTTP(w, req)
require.Equal(t, http.StatusNoContent, w.Code)
require.Equal(t, http.StatusOK, w.Code)

// case 5: remove changefeed failed
statusProvider.EXPECT().GetChangeFeedStatus(gomock.Any(), gomock.Any()).AnyTimes().Return(
Expand Down
4 changes: 2 additions & 2 deletions cdc/api/v2/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// @Tags owner,v2
// @Accept json
// @Produce json
// @Success 202 {object} EmptyResponse
// @Success 200 {object} EmptyResponse
// @Failure 500,400 {object} model.HTTPError
// @Router /api/v2/owner/resign [post]
func (h *OpenAPIV2) resignOwner(c *gin.Context) {
Expand All @@ -34,5 +34,5 @@ func (h *OpenAPIV2) resignOwner(c *gin.Context) {
o.AsyncStop()
}

c.JSON(http.StatusAccepted, &EmptyResponse{})
c.JSON(http.StatusOK, &EmptyResponse{})
}
4 changes: 2 additions & 2 deletions cdc/api/v2/unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (h *OpenAPIV2) ResolveLock(c *gin.Context) {
_ = c.Error(err)
return
}
c.Status(http.StatusNoContent)
c.JSON(http.StatusOK, &EmptyResponse{})
}

// DeleteServiceGcSafePoint Delete CDC service GC safepoint in PD
Expand All @@ -125,7 +125,7 @@ func (h *OpenAPIV2) DeleteServiceGcSafePoint(c *gin.Context) {
if err != nil {
_ = c.Error(err)
}
c.Status(http.StatusNoContent)
c.JSON(http.StatusOK, &EmptyResponse{})
}

func (h *OpenAPIV2) withUpstreamConfig(c context.Context,
Expand Down
26 changes: 16 additions & 10 deletions docs/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,8 @@ var doc = `{
}
],
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.ChangeFeedInfo"
}
Expand Down Expand Up @@ -911,8 +911,11 @@ var doc = `{
}
],
"responses": {
"204": {
"description": ""
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
},
"400": {
"description": "Bad Request",
Expand Down Expand Up @@ -953,8 +956,8 @@ var doc = `{
}
],
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
Expand Down Expand Up @@ -1007,8 +1010,11 @@ var doc = `{
}
],
"responses": {
"202": {
"description": ""
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
},
"400": {
"description": "Bad Request",
Expand Down Expand Up @@ -1114,8 +1120,8 @@ var doc = `{
],
"summary": "Notify the owner to resign",
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
Expand Down
26 changes: 16 additions & 10 deletions docs/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,8 @@
}
],
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.ChangeFeedInfo"
}
Expand Down Expand Up @@ -892,8 +892,11 @@
}
],
"responses": {
"204": {
"description": ""
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
},
"400": {
"description": "Bad Request",
Expand Down Expand Up @@ -934,8 +937,8 @@
}
],
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
Expand Down Expand Up @@ -988,8 +991,11 @@
}
],
"responses": {
"202": {
"description": ""
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
},
"400": {
"description": "Bad Request",
Expand Down Expand Up @@ -1095,8 +1101,8 @@
],
"summary": "Notify the owner to resign",
"responses": {
"202": {
"description": "Accepted",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v2.EmptyResponse"
}
Expand Down
24 changes: 14 additions & 10 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,10 @@ paths:
produces:
- application/json
responses:
"204":
description: ""
"200":
description: OK
schema:
$ref: '#/definitions/v2.EmptyResponse'
"400":
description: Bad Request
schema:
Expand Down Expand Up @@ -1193,8 +1195,8 @@ paths:
produces:
- application/json
responses:
"202":
description: Accepted
"200":
description: OK
schema:
$ref: '#/definitions/v2.ChangeFeedInfo'
"400":
Expand Down Expand Up @@ -1223,8 +1225,8 @@ paths:
produces:
- application/json
responses:
"202":
description: Accepted
"200":
description: OK
schema:
$ref: '#/definitions/v2.EmptyResponse'
"400":
Expand Down Expand Up @@ -1259,8 +1261,10 @@ paths:
produces:
- application/json
responses:
"202":
description: ""
"200":
description: OK
schema:
$ref: '#/definitions/v2.EmptyResponse'
"400":
description: Bad Request
schema:
Expand Down Expand Up @@ -1330,8 +1334,8 @@ paths:
produces:
- application/json
responses:
"202":
description: Accepted
"200":
description: OK
schema:
$ref: '#/definitions/v2.EmptyResponse'
"400":
Expand Down
12 changes: 6 additions & 6 deletions tests/integration_tests/http_api_tls/util/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def create_changefeed_v2():
data = json.dumps(data)
headers = {"Content-Type": "application/json"}
resp = rq.post(url, data=data, headers=headers, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.created
assert resp.status_code == rq.codes.ok

# create changefeed 2
data = {
Expand All @@ -404,7 +404,7 @@ def create_changefeed_v2():
data = json.dumps(data)
headers = {"Content-Type": "application/json"}
resp = rq.post(url, data=data, headers=headers, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.created
assert resp.status_code == rq.codes.ok

# create changefeed fail because sink_uri is invalid
data = json.dumps({
Expand Down Expand Up @@ -445,13 +445,13 @@ def unsafe_apis():
headers = {"Content-Type": "application/json"}
resp = rq.delete(url, data=data, headers=headers, cert=CERT, verify=VERIFY)
print("status code", resp.status_code)
assert resp.status_code == 204
assert resp.status_code == rq.codes.ok

data = json.dumps({})
headers = {"Content-Type": "application/json"}
resp = rq.delete(url, data=data, headers=headers, cert=CERT, verify=VERIFY)
print("status code", resp.status_code)
assert resp.status_code == 204
assert resp.status_code == rq.codes.ok
print("pass test: delete service_gc_safepoint")

# create changefeed fail because sink_uri is invalid
Expand All @@ -467,7 +467,7 @@ def delete_changefeed_v2():
# remove changefeed
url = BASE_URL0_V2+"/changefeeds/changefeed-test4"
resp = rq.delete(url, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.no_content
assert resp.status_code == rq.codes.ok

# check if remove changefeed success
url = BASE_URL0+"/changefeeds/changefeed-test4"
Expand All @@ -482,7 +482,7 @@ def delete_changefeed_v2():
# test remove changefeed not exists
url = BASE_URL0_V2+"/changefeeds/changefeed-not-exists"
resp = rq.delete(url, cert=CERT, verify=VERIFY)
assert (resp.status_code == rq.codes.no_content)
assert (resp.status_code == rq.codes.ok)

print("pass test: remove changefeed v2")

Expand Down

0 comments on commit 7cb9371

Please sign in to comment.