Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Return ResourceWrapper without pointer #407

Closed
wants to merge 6 commits into from
Closed
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
15 changes: 9 additions & 6 deletions go/tasks/plugins/webapi/agent/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@
taskTemplate.GetContainer().Args = argTemplate
}

return &ResourceMetaWrapper{
return ResourceMetaWrapper{
OutputPrefix: outputPrefix,
AgentResourceMeta: res.GetResourceMeta(),
Token: "",
TaskType: taskTemplate.Type,
}, &ResourceWrapper{State: admin.State_RUNNING}, nil
}, ResourceWrapper{State: admin.State_RUNNING}, nil
}

func (p Plugin) Get(ctx context.Context, taskCtx webapi.GetContext) (latest webapi.Resource, err error) {
metadata := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
if taskCtx.ResourceMeta() == nil {
return nil, fmt.Errorf("resource metadata is nil")
}

Check warning on line 126 in go/tasks/plugins/webapi/agent/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/agent/plugin.go#L125-L126

Added lines #L125 - L126 were not covered by tests
metadata := taskCtx.ResourceMeta().(ResourceMetaWrapper)

agent, err := getFinalAgent(metadata.TaskType, p.cfg)
if err != nil {
Expand All @@ -140,7 +143,7 @@
return nil, err
}

return &ResourceWrapper{
return ResourceWrapper{
State: res.Resource.State,
Outputs: res.Resource.Outputs,
}, nil
Expand Down Expand Up @@ -169,7 +172,7 @@
}

func (p Plugin) Status(ctx context.Context, taskCtx webapi.StatusContext) (phase core.PhaseInfo, err error) {
resource := taskCtx.Resource().(*ResourceWrapper)
resource := taskCtx.Resource().(ResourceWrapper)
taskInfo := &core.TaskInfo{}

switch resource.State {
Expand All @@ -190,7 +193,7 @@
return core.PhaseInfoUndefined, pluginErrors.Errorf(core.SystemErrorCode, "unknown execution phase [%v].", resource.State)
}

func writeOutput(ctx context.Context, taskCtx webapi.StatusContext, resource *ResourceWrapper) error {
func writeOutput(ctx context.Context, taskCtx webapi.StatusContext, resource ResourceWrapper) error {
taskTemplate, err := taskCtx.TaskReader().Read(ctx)
if err != nil {
return err
Expand Down
15 changes: 9 additions & 6 deletions go/tasks/plugins/webapi/databricks/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,15 @@
}
runID := fmt.Sprintf("%v", data["run_id"])

return &ResourceMetaWrapper{runID, p.cfg.DatabricksInstance, token},
&ResourceWrapper{StatusCode: resp.StatusCode}, nil
return ResourceMetaWrapper{runID, p.cfg.DatabricksInstance, token},
ResourceWrapper{StatusCode: resp.StatusCode}, nil
}

func (p Plugin) Get(ctx context.Context, taskCtx webapi.GetContext) (latest webapi.Resource, err error) {
exec := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
if taskCtx.ResourceMeta() == nil {
return nil, fmt.Errorf("resource meta is nil")
}

Check warning on line 156 in go/tasks/plugins/webapi/databricks/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/databricks/plugin.go#L155-L156

Added lines #L155 - L156 were not covered by tests
exec := taskCtx.ResourceMeta().(ResourceMetaWrapper)
req, err := buildRequest(get, nil, p.cfg.databricksEndpoint,
p.cfg.DatabricksInstance, exec.Token, exec.RunID, false)
if err != nil {
Expand All @@ -176,7 +179,7 @@
jobID := fmt.Sprintf("%.0f", data["job_id"])
lifeCycleState := fmt.Sprintf("%s", jobState["life_cycle_state"])
resultState := fmt.Sprintf("%s", jobState["result_state"])
return &ResourceWrapper{
return ResourceWrapper{
StatusCode: resp.StatusCode,
JobID: jobID,
LifeCycleState: lifeCycleState,
Expand Down Expand Up @@ -206,8 +209,8 @@
}

func (p Plugin) Status(ctx context.Context, taskCtx webapi.StatusContext) (phase core.PhaseInfo, err error) {
exec := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
resource := taskCtx.Resource().(*ResourceWrapper)
exec := taskCtx.ResourceMeta().(ResourceMetaWrapper)
resource := taskCtx.Resource().(ResourceWrapper)
message := resource.Message
statusCode := resource.StatusCode
jobID := resource.JobID
Expand Down
14 changes: 7 additions & 7 deletions go/tasks/plugins/webapi/snowflake/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@
queryID := fmt.Sprintf("%v", data["statementHandle"])
message := fmt.Sprintf("%v", data["message"])

return &ResourceMetaWrapper{queryID, queryInfo.Account, token},
&ResourceWrapper{StatusCode: resp.StatusCode, Message: message}, nil
return ResourceMetaWrapper{queryID, queryInfo.Account, token},
ResourceWrapper{StatusCode: resp.StatusCode, Message: message}, nil
}

func (p Plugin) Get(ctx context.Context, taskCtx webapi.GetContext) (latest webapi.Resource, err error) {
exec := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
exec := taskCtx.ResourceMeta().(ResourceMetaWrapper)
req, err := buildRequest(get, QueryInfo{}, p.cfg.snowflakeEndpoint,
exec.Account, exec.Token, exec.QueryID, false)
if err != nil {
Expand All @@ -160,7 +160,7 @@
return nil, err
}
message := fmt.Sprintf("%v", data["message"])
return &ResourceWrapper{
return ResourceWrapper{
StatusCode: resp.StatusCode,
Message: message,
}, nil
Expand All @@ -170,7 +170,7 @@
if taskCtx.ResourceMeta() == nil {
return nil
}
exec := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
exec := taskCtx.ResourceMeta().(ResourceMetaWrapper)

Check warning on line 173 in go/tasks/plugins/webapi/snowflake/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/snowflake/plugin.go#L173

Added line #L173 was not covered by tests
req, err := buildRequest(post, QueryInfo{}, p.cfg.snowflakeEndpoint,
exec.Account, exec.Token, exec.QueryID, true)
if err != nil {
Expand All @@ -187,8 +187,8 @@
}

func (p Plugin) Status(_ context.Context, taskCtx webapi.StatusContext) (phase core.PhaseInfo, err error) {
exec := taskCtx.ResourceMeta().(*ResourceMetaWrapper)
statusCode := taskCtx.Resource().(*ResourceWrapper).StatusCode
exec := taskCtx.ResourceMeta().(ResourceMetaWrapper)
statusCode := taskCtx.Resource().(ResourceWrapper).StatusCode
if statusCode == 0 {
return core.PhaseInfoUndefined, errors.Errorf(ErrSystem, "No Status field set.")
}
Expand Down
Loading