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

Added support for fetching job ID in CleanoutServer #131

Merged
merged 1 commit into from
Jun 12, 2018
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
13 changes: 12 additions & 1 deletion cluster_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ type cleanOutServerRequest struct {
Server string `json:"server"`
}

type cleanOutServerResponse struct {
JobID string `json:"id"`
}

// CleanOutServer triggers activities to clean out a DBServers.
func (c *cluster) CleanOutServer(ctx context.Context, serverID string) error {
req, err := c.conn.NewRequest("POST", "_admin/cluster/cleanOutServer")
Expand All @@ -135,14 +139,21 @@ func (c *cluster) CleanOutServer(ctx context.Context, serverID string) error {
if _, err := req.SetBody(input); err != nil {
return WithStack(err)
}
applyContextSettings(ctx, req)
cs := applyContextSettings(ctx, req)
resp, err := c.conn.Do(ctx, req)
if err != nil {
return WithStack(err)
}
if err := resp.CheckStatus(200, 202); err != nil {
return WithStack(err)
}
var result cleanOutServerResponse
if err := resp.ParseBody("", &result); err != nil {
return WithStack(err)
}
if cs.JobIDResponse != nil {
*cs.JobIDResponse = result.JobID
}
return nil
}

Expand Down
15 changes: 15 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
keyFollowLeaderRedirect ContextKey = "arangodb-followLeaderRedirect"
keyDBServerID ContextKey = "arangodb-dbserverID"
keyBatchID ContextKey = "arangodb-batchID"
keyJobIDResponse ContextKey = "arangodb-jobIDResponse"
)

// WithRevision is used to configure a context to make document
Expand Down Expand Up @@ -213,6 +214,13 @@ func WithBatchID(parent context.Context, id string) context.Context {
return context.WithValue(contextOrBackground(parent), keyBatchID, id)
}

// WithJobIDResponse is used to configure a context that includes a reference to a JobID
// that is filled on a error-free response.
// This is used in cluster functions.
func WithJobIDResponse(parent context.Context, jobID *string) context.Context {
return context.WithValue(contextOrBackground(parent), keyJobIDResponse, jobID)
}

type contextSettings struct {
Silent bool
WaitForSync bool
Expand All @@ -229,6 +237,7 @@ type contextSettings struct {
FollowLeaderRedirect *bool
DBServerID string
BatchID string
JobIDResponse *string
}

// applyContextSettings returns the settings configured in the context in the given request.
Expand Down Expand Up @@ -356,6 +365,12 @@ func applyContextSettings(ctx context.Context, req Request) contextSettings {
result.BatchID = id
}
}
// JobIDResponse
if v := ctx.Value(keyJobIDResponse); v != nil {
if idRef, ok := v.(*string); ok {
result.JobIDResponse = idRef
}
}
return result
}

Expand Down