Skip to content

Commit 2ea5f85

Browse files
dimon222kevin-bates
authored andcommitted
Fix json body request apis (#78)
* Fix cluster_application_kill body * Fix test for kill * Switch away from form-data to json
1 parent 21ecb2d commit 2ea5f85

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

tests/test_application_master.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_task_attempt_state_kill(self, request_mock):
6767
self.app.task_attempt_state_kill('app_1', 'job_2', 'task_3', 'attempt_4')
6868
request_mock.assert_called_with(
6969
'/proxy/app_1/ws/v1/mapreduce/jobs/job_2/tasks/task_3/attempts/attempt_4/state',
70-
'PUT', data={'state': 'KILLED'}
70+
'PUT', json={'state': 'KILLED'}
7171
)
7272

7373
def test_task_attempt_counters(self, request_mock):

tests/test_resource_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_cluster_application_state(self, request_mock):
9797

9898
def test_cluster_application_kill(self, request_mock):
9999
self.rm.cluster_application_kill('app_1')
100-
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/state', 'PUT', data={
100+
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/state', 'PUT', json={
101101
"state": 'KILLED'
102102
})
103103

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

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

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

134134
def test_cluster_change_application_queue(self, request_mock):
135135
self.rm.cluster_change_application_queue('app_1', 'queue_1')
136-
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/queue', 'PUT', data={
136+
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/queue', 'PUT', json={
137137
"queue": 'queue_1'
138138
})
139139

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

144144
def test_cluster_change_application_priority(self, request_mock):
145145
self.rm.cluster_change_application_priority('app_1', 'priority_1')
146-
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/priority', 'PUT', data={
146+
request_mock.assert_called_with('/ws/v1/cluster/apps/app_1/priority', 'PUT', json={
147147
"priority": 'priority_1'
148148
})
149149

@@ -260,7 +260,7 @@ def test_cluster_reservations(self, request_mock):
260260

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

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

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

289289
def test_cluster_update_reservation(self, request_mock):
290290
self.rm.cluster_update_reservation({
291291
'reservation-id': 'reservation_1'
292292
})
293-
request_mock.assert_called_with('/ws/v1/cluster/reservation/update', 'POST', data={
293+
request_mock.assert_called_with('/ws/v1/cluster/reservation/update', 'POST', json={
294294
'reservation-id': 'reservation_1'
295295
})
296296

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

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

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

@@ -325,7 +325,7 @@ def test_cluster_modify_scheduler_conf_mutation(self, request_mock):
325325
'test': 'test'
326326
}
327327
})
328-
request_mock.assert_called_with('/ws/v1/cluster/scheduler-conf', 'PUT', data={
328+
request_mock.assert_called_with('/ws/v1/cluster/scheduler-conf', 'PUT', json={
329329
'queue-name': 'queue_1',
330330
'params': {
331331
'test': 'test'

yarn_api_client/application_master.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def task_attempt_state_kill(self, application_id, job_id, task_id, attempt_id):
235235
appid=application_id, jobid=job_id, taskid=task_id,
236236
attemptid=attempt_id)
237237

238-
return self.request(path, 'PUT', data=data)
238+
return self.request(path, 'PUT', json=data)
239239

240240
def task_attempt_counters(self, application_id, job_id, task_id, attempt_id):
241241
"""

yarn_api_client/resource_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def cluster_application_kill(self, application_id):
337337
path = '/ws/v1/cluster/apps/{appid}/state'.format(
338338
appid=application_id)
339339

340-
return self.request(path, 'PUT', data=data)
340+
return self.request(path, 'PUT', json=data)
341341

342342
def cluster_nodes(self, states=None):
343343
"""
@@ -394,7 +394,7 @@ def cluster_submit_application(self, data):
394394
"""
395395
path = '/ws/v1/cluster/apps'
396396

397-
return self.request(path, 'POST', data=data)
397+
return self.request(path, 'POST', json=data)
398398

399399
def cluster_new_application(self):
400400
"""
@@ -454,7 +454,7 @@ def cluster_change_application_queue(self, application_id, queue):
454454
"""
455455
path = '/ws/v1/cluster/apps/{appid}/queue'.format(appid=application_id)
456456

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

459459
def cluster_get_application_priority(self, application_id):
460460
"""
@@ -497,7 +497,7 @@ def cluster_change_application_priority(self, application_id, priority):
497497
"""
498498
path = '/ws/v1/cluster/apps/{appid}/priority'.format(appid=application_id)
499499

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

502502
def cluster_node_container_memory(self):
503503
"""
@@ -626,7 +626,7 @@ def cluster_new_delegation_token(self, renewer):
626626
"""
627627
path = '/ws/v1/cluster/delegation-token'
628628

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

631631
def cluster_renew_delegation_token(self, delegation_token):
632632
"""
@@ -708,7 +708,7 @@ def cluster_submit_reservation(self, data):
708708
"""
709709
path = '/ws/v1/cluster/reservation/submit'
710710

711-
return self.request(path, 'POST', data=data)
711+
return self.request(path, 'POST', json=data)
712712

713713
def cluster_update_reservation(self, data):
714714
"""
@@ -727,7 +727,7 @@ def cluster_update_reservation(self, data):
727727
"""
728728
path = '/ws/v1/cluster/reservation/update'
729729

730-
return self.request(path, 'POST', data=data)
730+
return self.request(path, 'POST', json=data)
731731

732732
def cluster_delete_reservation(self, reservation_id):
733733
"""
@@ -744,7 +744,7 @@ def cluster_delete_reservation(self, reservation_id):
744744
"""
745745
path = '/ws/v1/cluster/reservation/delete'
746746

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

749749
def cluster_application_timeouts(self, application_id):
750750
"""
@@ -791,7 +791,7 @@ def cluster_update_application_timeout(self, application_id, timeout_type, expir
791791
"""
792792
path = '/ws/v1/cluster/apps/{appid}/timeout'.format(appid=application_id)
793793

794-
return self.request(path, 'PUT', data={
794+
return self.request(path, 'PUT', json={
795795
"timeout": {"type": timeout_type, "expiryTime": expiry_time}
796796
})
797797

@@ -826,4 +826,4 @@ def cluster_modify_scheduler_conf_mutation(self, data):
826826
"""
827827
path = '/ws/v1/cluster/scheduler-conf'
828828

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

0 commit comments

Comments
 (0)