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

Cleaning NM logic #49

Merged
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
18 changes: 14 additions & 4 deletions yarn_api_client/node_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
from .errors import IllegalArgumentError
from .hadoop_conf import get_nodemanager_endpoint

LEGAL_APPLICATION_STATES = {s for s, _ in ApplicationState}


def validate_application_state(state, required=False):
if state:
if state not in LEGAL_APPLICATION_STATES:
msg = 'Application State %s is illegal' % (state,)
raise IllegalArgumentError(msg)
else:
if required:
msg = "state argument is required to be provided"
raise IllegalArgumentError(msg)


class NodeManager(BaseYarnAPI):
"""
Expand Down Expand Up @@ -52,10 +65,7 @@ def node_applications(self, state=None, user=None):
"""
path = '/ws/v1/node/apps'

legal_states = {s for s, _ in ApplicationState}
if state is not None and state not in legal_states:
msg = 'Application State %s is illegal' % (state,)
raise IllegalArgumentError(msg)
validate_application_state(state)

loc_args = (
('state', state),
Expand Down