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

core: Use Runner enum type instead of string for Job model #651

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

ches
Copy link
Member

@ches ches commented Apr 26, 2020

What this PR does / why we need it:

This is refactoring aiming to remove a burden on the programmer to get something right.

#575 sought to clear up inconsistencies between uses of Runner#name() (the standard final method of java.lang.Enum that returns the value's enum constant name) and the riskily-named Runner#getName() defined in Feast for human-readable Beam Runner names.

The latter is used as runner name users can set in config (now as Runner#toString since #575). The former is used for values of the runner column of the jobs table in SQL (as it should be). But it relied on careful coding to use the right one when constructing Job instances. This is error prone, as #578 demonstrates.

There is a more robust way: use the enum instead of stringly-typed programming. It's one of the reasons we have enums ☺️

This also renames the internal identifier in the Runner definition to humanName, to distinguish it further from Enum#name().

Which issue(s) this PR fixes:

No issue. Relates to #575, #578, brought up in #650 (comment)

Does this PR introduce a user-facing change?:

NONE

feast-dev#575 sought to clear up inconsistencies between uses of `Runner#name()`
(the standard final method of `java.lang.Enum` that returns the value's
enum constant name) and the riskily-named `Runner#getName()` defined in
Feast for human-readable Beam Runner names.

The latter is used as runner name users can set in config. The former
is used for values of the runner column of the jobs table in SQL (as it
should be). But it relied on careful coding to use the right one when
constructing `Job` instances. This is error prone, as feast-dev#578 demonstrates.

There is a more robust way: use the enum instead of stringly-typed
programming. It's one of the reasons we have enums :-)

This also renames the internal identifier in the Runner definition to
`humanName`, to distinguish it further from `Enum#name()`.
@ches
Copy link
Member Author

ches commented Apr 26, 2020

/assign @woop

return r;
}
}
throw new IllegalArgumentException("Unknown value: " + runner);
throw new NoSuchElementException("Unknown Runner value: " + humanName);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt this is perhaps a more fitting exception type for this case.

Comment on lines -58 to +61
// Use Runner.name() when converting a Runner to string to assign to this property.
@Enumerated(EnumType.STRING)
@Column(name = "runner")
private String runner;
private Runner runner;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed comment sums up the motivation of the PR.

private Map<String, JobManager> jobManagers;
private final JobRepository jobRepository;
private final SpecService specService;
private final Map<Runner, JobManager> jobManagers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but I still feel like JobManager can be changed to something closer to Runner. In fact it can probably be Runner itself. Meaning this code would become private final Map<RunnerType, Runner>

@woop
Copy link
Member

woop commented Apr 27, 2020

/test test-end-to-end-batch

@woop
Copy link
Member

woop commented Apr 27, 2020

/lgtm

@woop
Copy link
Member

woop commented Apr 27, 2020

/approve

@feast-ci-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ches, woop

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@feast-ci-bot feast-ci-bot merged commit 78b6024 into feast-dev:master Apr 27, 2020
@ches ches deleted the job-runner-as-enum branch April 27, 2020 13:22
@woop woop mentioned this pull request Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants