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

fix(databricks): Check the response body before unmarshal #5226

Merged
merged 4 commits into from
Apr 12, 2024
Merged
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
16 changes: 13 additions & 3 deletions flyteplugins/go/tasks/plugins/webapi/databricks/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,14 @@ func (p Plugin) sendRequest(method string, databricksJob map[string]interface{},
return nil, err
}
var data map[string]interface{}
err = json.Unmarshal(responseBody, &data)
if err != nil {
return nil, fmt.Errorf("failed to parse response with err: [%v]", err)

if len(responseBody) != 0 {
err = json.Unmarshal(responseBody, &data)
if err != nil {
return nil, fmt.Errorf("failed to parse response with err: [%v]", err)
}
}

if resp.StatusCode != http.StatusOK {
message := ""
if v, ok := data["message"]; ok {
Expand All @@ -259,10 +263,16 @@ func (p Plugin) Status(ctx context.Context, taskCtx webapi.StatusContext) (phase
taskInfo := createTaskInfo(exec.RunID, jobID, exec.DatabricksInstance)
switch lifeCycleState {
// Job response format. https://docs.databricks.com/en/workflows/jobs/jobs-2.0-api.html#runlifecyclestate
case "QUEUED":
return core.PhaseInfoQueued(time.Now(), core.DefaultPhaseVersion, message), nil
case "PENDING":
return core.PhaseInfoInitializing(time.Now(), core.DefaultPhaseVersion, message, taskInfo), nil
case "RUNNING":
fallthrough
case "BLOCKED":
fallthrough
case "WAITING_FOR_RETRY":
fallthrough
case "TERMINATING":
return core.PhaseInfoRunning(core.DefaultPhaseVersion, taskInfo), nil
case "TERMINATED":
Expand Down
Loading