Skip to content

Commit

Permalink
Fix json body request apis (#78)
Browse files Browse the repository at this point in the history
* Fix cluster_application_kill body
* Fix test for kill
* Switch away from form-data to json
  • Loading branch information
dimon222 authored and kevin-bates committed Jan 11, 2020
1 parent 21ecb2d commit 2ea5f85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tests/test_application_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_task_attempt_state_kill(self, request_mock):
self.app.task_attempt_state_kill('app_1', 'job_2', 'task_3', 'attempt_4')
request_mock.assert_called_with(
'/proxy/app_1/ws/v1/mapreduce/jobs/job_2/tasks/task_3/attempts/attempt_4/state',
'PUT', data={'state': 'KILLED'}
'PUT', json={'state': 'KILLED'}
)

def test_task_attempt_counters(self, request_mock):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_cluster_application_state(self, request_mock):

def test_cluster_application_kill(self, request_mock):
self.rm.cluster_application_kill('app_1')
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/state', 'PUT', data={
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/state', 'PUT', json={
"state": 'KILLED'
})

Expand All @@ -119,7 +119,7 @@ def test_cluster_node(self, request_mock):

def test_cluster_submit_application(self, request_mock):
self.rm.cluster_submit_application({"application-name": "dummy_application"})
request_mock.assert_called_with('/ws/v1/cluster/apps', 'POST', data={
request_mock.assert_called_with('/ws/v1/cluster/apps', 'POST', json={
"application-name": "dummy_application"
})

Expand All @@ -133,7 +133,7 @@ def test_cluster_get_application_queue(self, request_mock):

def test_cluster_change_application_queue(self, request_mock):
self.rm.cluster_change_application_queue('app_1', 'queue_1')
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/queue', 'PUT', data={
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/queue', 'PUT', json={
"queue": 'queue_1'
})

Expand All @@ -143,7 +143,7 @@ def test_cluster_get_application_priority(self, request_mock):

def test_cluster_change_application_priority(self, request_mock):
self.rm.cluster_change_application_priority('app_1', 'priority_1')
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/priority', 'PUT', data={
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/priority', 'PUT', json={
"priority": 'priority_1'
})

Expand Down Expand Up @@ -260,7 +260,7 @@ def test_cluster_reservations(self, request_mock):

def test_cluster_new_delegation_token(self, request_mock):
self.rm.cluster_new_delegation_token('renewer_1')
request_mock.assert_called_with('/ws/v1/cluster/delegation-token', 'POST', data={
request_mock.assert_called_with('/ws/v1/cluster/delegation-token', 'POST', json={
"renewer": "renewer_1"
})

Expand All @@ -282,21 +282,21 @@ def test_cluster_new_reservation(self, request_mock):

def test_cluster_submit_reservation(self, request_mock):
self.rm.cluster_submit_reservation({'reservation-id': 'reservation_1'})
request_mock.assert_called_with('/ws/v1/cluster/reservation/submit', 'POST', data={
request_mock.assert_called_with('/ws/v1/cluster/reservation/submit', 'POST', json={
'reservation-id': 'reservation_1'
})

def test_cluster_update_reservation(self, request_mock):
self.rm.cluster_update_reservation({
'reservation-id': 'reservation_1'
})
request_mock.assert_called_with('/ws/v1/cluster/reservation/update', 'POST', data={
request_mock.assert_called_with('/ws/v1/cluster/reservation/update', 'POST', json={
'reservation-id': 'reservation_1'
})

def test_cluster_delete_reservation(self, request_mock):
self.rm.cluster_delete_reservation('reservation_1')
request_mock.assert_called_with('/ws/v1/cluster/reservation/delete', 'POST', data={
request_mock.assert_called_with('/ws/v1/cluster/reservation/delete', 'POST', json={
'reservation-id': 'reservation_1'
})

Expand All @@ -310,7 +310,7 @@ def test_cluster_application_timeout(self, request_mock):

def test_cluster_update_application_timeout(self, request_mock):
self.rm.cluster_update_application_timeout('app_1', 'LIFETIME', '2016-12-05T22:51:00.104+0530')
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/timeout', 'PUT', data={
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/timeout', 'PUT', json={
'timeout': {'type': 'LIFETIME', 'expiryTime': '2016-12-05T22:51:00.104+0530'}
})

Expand All @@ -325,7 +325,7 @@ def test_cluster_modify_scheduler_conf_mutation(self, request_mock):
'test': 'test'
}
})
request_mock.assert_called_with('/ws/v1/cluster/scheduler-conf', 'PUT', data={
request_mock.assert_called_with('/ws/v1/cluster/scheduler-conf', 'PUT', json={
'queue-name': 'queue_1',
'params': {
'test': 'test'
Expand Down
2 changes: 1 addition & 1 deletion yarn_api_client/application_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def task_attempt_state_kill(self, application_id, job_id, task_id, attempt_id):
appid=application_id, jobid=job_id, taskid=task_id,
attemptid=attempt_id)

return self.request(path, 'PUT', data=data)
return self.request(path, 'PUT', json=data)

def task_attempt_counters(self, application_id, job_id, task_id, attempt_id):
"""
Expand Down
20 changes: 10 additions & 10 deletions yarn_api_client/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def cluster_application_kill(self, application_id):
path = '/ws/v1/cluster/apps/{appid}/state'.format(
appid=application_id)

return self.request(path, 'PUT', data=data)
return self.request(path, 'PUT', json=data)

def cluster_nodes(self, states=None):
"""
Expand Down Expand Up @@ -394,7 +394,7 @@ def cluster_submit_application(self, data):
"""
path = '/ws/v1/cluster/apps'

return self.request(path, 'POST', data=data)
return self.request(path, 'POST', json=data)

def cluster_new_application(self):
"""
Expand Down Expand Up @@ -454,7 +454,7 @@ def cluster_change_application_queue(self, application_id, queue):
"""
path = '/ws/v1/cluster/apps/{appid}/queue'.format(appid=application_id)

return self.request(path, 'PUT', data={"queue": queue})
return self.request(path, 'PUT', json={"queue": queue})

def cluster_get_application_priority(self, application_id):
"""
Expand Down Expand Up @@ -497,7 +497,7 @@ def cluster_change_application_priority(self, application_id, priority):
"""
path = '/ws/v1/cluster/apps/{appid}/priority'.format(appid=application_id)

return self.request(path, 'PUT', data={"priority": priority})
return self.request(path, 'PUT', json={"priority": priority})

def cluster_node_container_memory(self):
"""
Expand Down Expand Up @@ -626,7 +626,7 @@ def cluster_new_delegation_token(self, renewer):
"""
path = '/ws/v1/cluster/delegation-token'

return self.request(path, 'POST', data={"renewer": renewer})
return self.request(path, 'POST', json={"renewer": renewer})

def cluster_renew_delegation_token(self, delegation_token):
"""
Expand Down Expand Up @@ -708,7 +708,7 @@ def cluster_submit_reservation(self, data):
"""
path = '/ws/v1/cluster/reservation/submit'

return self.request(path, 'POST', data=data)
return self.request(path, 'POST', json=data)

def cluster_update_reservation(self, data):
"""
Expand All @@ -727,7 +727,7 @@ def cluster_update_reservation(self, data):
"""
path = '/ws/v1/cluster/reservation/update'

return self.request(path, 'POST', data=data)
return self.request(path, 'POST', json=data)

def cluster_delete_reservation(self, reservation_id):
"""
Expand All @@ -744,7 +744,7 @@ def cluster_delete_reservation(self, reservation_id):
"""
path = '/ws/v1/cluster/reservation/delete'

return self.request(path, 'POST', data={'reservation-id': reservation_id})
return self.request(path, 'POST', json={'reservation-id': reservation_id})

def cluster_application_timeouts(self, application_id):
"""
Expand Down Expand Up @@ -791,7 +791,7 @@ def cluster_update_application_timeout(self, application_id, timeout_type, expir
"""
path = '/ws/v1/cluster/apps/{appid}/timeout'.format(appid=application_id)

return self.request(path, 'PUT', data={
return self.request(path, 'PUT', json={
"timeout": {"type": timeout_type, "expiryTime": expiry_time}
})

Expand Down Expand Up @@ -826,4 +826,4 @@ def cluster_modify_scheduler_conf_mutation(self, data):
"""
path = '/ws/v1/cluster/scheduler-conf'

return self.request(path, 'PUT', data=data)
return self.request(path, 'PUT', json=data)

0 comments on commit 2ea5f85

Please sign in to comment.