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

Add RestartTask function #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,18 @@ func (c *Client) ResumeConnector(name string) (*http.Response, error) {
return c.doRequest("PUT", path, nil, nil)
}

// RestartConnector restarts a connector and its tasks.
// RestartConnector restarts a connector
//
// See http://docs.confluent.io/current/connect/userguide.html#post--connectors-(string-name)-restart
func (c *Client) RestartConnector(name string) (*http.Response, error) {
path := fmt.Sprintf("connectors/%v/restart", name)
return c.doRequest("POST", path, nil, nil)
}

// RestartTask restarts a connector's task by task id
//
// See https://docs.confluent.io/current/connect/references/restapi.html#post--connectors-(string-name)-tasks-(int-taskid)-restart
func (c *Client) RestartTask(name string, id int) (*http.Response, error) {
path := fmt.Sprintf("connectors/%v/tasks/%v/restart", name, id)
return c.doRequest("POST", path, nil, nil)
}
84 changes: 84 additions & 0 deletions connectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,88 @@ var _ = Describe("Connector Lifecycle", func() {
})
})
})

Describe("RestartTask", func() {
var statusCode int
taskID := 0

BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyHeader(jsonAcceptHeader),
ghttp.RespondWithPtr(&statusCode, nil),
),
)
})

Context("when existing connector name is given", func() {
BeforeEach(func() {
statusCode = http.StatusOK
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/connectors/local-file-source/tasks/0/restart"),
),
)
})

It("restarts connector", func() {
resp, err := client.RestartTask("local-file-source", taskID)
Expect(err).NotTo(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
})

Context("when rebalance is in process", func() {
BeforeEach(func() {
statusCode = http.StatusConflict
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/connectors/local-file-source/tasks/0/restart"),
),
)
})

It("returns error with a conflict response", func() {
resp, err := client.RestartTask("local-file-source", taskID)
Expect(err).To(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusConflict))
})
})
})

Context("when nonexisting connector name is given", func() {
BeforeEach(func() {
// The API actually throws a 500 on POST to nonexistent
statusCode = http.StatusInternalServerError
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/connectors/local-file-source/tasks/0/restart"),
),
)
})

It("returns error with a server error response", func() {
resp, err := client.RestartTask("local-file-source", taskID)
Expect(err).To(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
})
})

Context("when nonexisting task id is given", func() {
BeforeEach(func() {
// The API actually throws a 500 on POST to nonexistent
statusCode = http.StatusInternalServerError
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/connectors/local-file-source/tasks/5/restart"),
),
)
})

It("returns error with a server error response", func() {
resp, err := client.RestartTask("local-file-source", 5)
Expect(err).Should(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
})
})
})
})