|
23 | 23 |
|
24 | 24 | import unittest
|
25 | 25 | from datetime import datetime
|
26 |
| -from mock import patch, mock_open |
| 26 | +from mock import patch, mock_open, Mock |
27 | 27 | from application_creator import ApplicationCreator
|
28 | 28 | from exceptiondef import FailedValidation, FailedCreation
|
29 | 29 |
|
@@ -357,13 +357,147 @@ def test_destroy_application(self, rmdir_mock, isdir_mock, put_mock, exec_ssh_mo
|
357 | 357 | put_mock.assert_any_call('oozie/v1/job/someid2?action=kill')
|
358 | 358 |
|
359 | 359 | # pylint: disable=line-too-long
|
360 |
| - @patch('subprocess.check_output') |
361 |
| - def test_get_runtime_details(self, subprocess_mock): |
362 |
| - subprocess_mock.return_value = '''Total number of applications (application-types: [] and states: [SUBMITTED, ACCEPTED, RUNNING]):1 |
363 |
| - Application-Id Application-Name Application-Type User Queue State Final-State Progress Tracking-URL |
364 |
| -application_1455877292606_13009 aname-componentA-job SPARK hdfs root.hdfs RUNNING UNDEFINED 10% http://psm-cdh-dn0:51739 |
365 |
| -application_1455877292606_13010 aname-componentC-job SPARK hdfs root.hdfs RUNNING UNDEFINED 10% http://psm-cdh-dn0:51739''' |
| 360 | + @patch('requests.get') |
| 361 | + def test_get_runtime_details(self, get_mock): |
| 362 | + rm_call = Mock() |
| 363 | + rm_call.json.return_value = { |
| 364 | + "apps": { |
| 365 | + "app": [{ |
| 366 | + "id": "application_1455877292606_13009", |
| 367 | + "user": "hdfs", |
| 368 | + "name": "aname-componentA-job", |
| 369 | + "queue": "root.users.hdfs", |
| 370 | + "state": "FINISHED", |
| 371 | + "finalStatus": "SUCCEEDED", |
| 372 | + "progress": 100.0, |
| 373 | + "trackingUI": "History", |
| 374 | + "trackingUrl": "", |
| 375 | + "diagnostics": "", |
| 376 | + "clusterId": 1479988623709, |
| 377 | + "applicationType": "MAPREDUCE", |
| 378 | + "applicationTags": "", |
| 379 | + "startedTime": 1479996060665, |
| 380 | + "finishedTime": 1479996103786, |
| 381 | + "elapsedTime": 43121, |
| 382 | + "amContainerLogs": "", |
| 383 | + "amHostHttpAddress": "", |
| 384 | + "allocatedMB": -1, |
| 385 | + "allocatedVCores": -1, |
| 386 | + "runningContainers": -1, |
| 387 | + "memorySeconds": 30600, |
| 388 | + "vcoreSeconds": 29, |
| 389 | + "preemptedResourceMB": 0, |
| 390 | + "preemptedResourceVCores": 0, |
| 391 | + "numNonAMContainerPreempted": 0, |
| 392 | + "numAMContainerPreempted": 0, |
| 393 | + "logAggregationStatus": "DISABLED" |
| 394 | + }, { |
| 395 | + "id": "application_1455877292606_13010", |
| 396 | + "user": "hdfs", |
| 397 | + "name": "aname-componentC-job", |
| 398 | + "queue": "root.users.hdfs", |
| 399 | + "state": "FINISHED", |
| 400 | + "finalStatus": "SUCCEEDED", |
| 401 | + "progress": 100.0, |
| 402 | + "trackingUI": "History", |
| 403 | + "trackingUrl": "", |
| 404 | + "diagnostics": "", |
| 405 | + "clusterId": 1479988623709, |
| 406 | + "applicationType": "MAPREDUCE", |
| 407 | + "applicationTags": "", |
| 408 | + "startedTime": 1479996060665, |
| 409 | + "finishedTime": 1479996103786, |
| 410 | + "elapsedTime": 43121, |
| 411 | + "amContainerLogs": "", |
| 412 | + "amHostHttpAddress": "", |
| 413 | + "allocatedMB": -1, |
| 414 | + "allocatedVCores": -1, |
| 415 | + "runningContainers": -1, |
| 416 | + "memorySeconds": 30600, |
| 417 | + "vcoreSeconds": 29, |
| 418 | + "preemptedResourceMB": 0, |
| 419 | + "preemptedResourceVCores": 0, |
| 420 | + "numNonAMContainerPreempted": 0, |
| 421 | + "numAMContainerPreempted": 0, |
| 422 | + "logAggregationStatus": "DISABLED" |
| 423 | + }, { |
| 424 | + "id": "application_1455877292606_13011", |
| 425 | + "user": "hdfs", |
| 426 | + "name": "aname-componentC-job", |
| 427 | + "queue": "root.users.hdfs", |
| 428 | + "state": "RUNNING", |
| 429 | + "finalStatus": "SUCCEEDED", |
| 430 | + "progress": 100.0, |
| 431 | + "trackingUI": "History", |
| 432 | + "trackingUrl": "", |
| 433 | + "diagnostics": "", |
| 434 | + "clusterId": 1479988623709, |
| 435 | + "applicationType": "MAPREDUCE", |
| 436 | + "applicationTags": "", |
| 437 | + "startedTime": 1479996060667, |
| 438 | + "finishedTime": 1479996103786, |
| 439 | + "elapsedTime": 43121, |
| 440 | + "amContainerLogs": "", |
| 441 | + "amHostHttpAddress": "", |
| 442 | + "allocatedMB": -1, |
| 443 | + "allocatedVCores": -1, |
| 444 | + "runningContainers": -1, |
| 445 | + "memorySeconds": 30600, |
| 446 | + "vcoreSeconds": 29, |
| 447 | + "preemptedResourceMB": 0, |
| 448 | + "preemptedResourceVCores": 0, |
| 449 | + "numNonAMContainerPreempted": 0, |
| 450 | + "numAMContainerPreempted": 0, |
| 451 | + "logAggregationStatus": "DISABLED" |
| 452 | + }, { |
| 453 | + "id": "application_1455877292606_13012", |
| 454 | + "user": "hdfs", |
| 455 | + "name": "aname-componentC-job", |
| 456 | + "queue": "root.users.hdfs", |
| 457 | + "state": "NOT STARTED", |
| 458 | + "finalStatus": "SUCCEEDED", |
| 459 | + "progress": 100.0, |
| 460 | + "trackingUI": "History", |
| 461 | + "trackingUrl": "", |
| 462 | + "diagnostics": "", |
| 463 | + "clusterId": 1479988623709, |
| 464 | + "applicationType": "MAPREDUCE", |
| 465 | + "applicationTags": "", |
| 466 | + "startedTime": None, |
| 467 | + "finishedTime": 1479996103786, |
| 468 | + "elapsedTime": 43121, |
| 469 | + "amContainerLogs": "", |
| 470 | + "amHostHttpAddress": "", |
| 471 | + "allocatedMB": -1, |
| 472 | + "allocatedVCores": -1, |
| 473 | + "runningContainers": -1, |
| 474 | + "memorySeconds": 30600, |
| 475 | + "vcoreSeconds": 29, |
| 476 | + "preemptedResourceMB": 0, |
| 477 | + "preemptedResourceVCores": 0, |
| 478 | + "numNonAMContainerPreempted": 0, |
| 479 | + "numAMContainerPreempted": 0, |
| 480 | + "logAggregationStatus": "DISABLED" |
| 481 | + }] |
| 482 | + } |
| 483 | + } |
| 484 | + get_mock.return_value = rm_call |
| 485 | + |
366 | 486 | creator = ApplicationCreator(self.config, self.environment, self.service)
|
367 | 487 | result = creator.get_application_runtime_details('name', self.create_data)
|
368 |
| - self.assertEqual(result, {'yarn_ids': [{'component': 'componentA', 'type': 'oozie', 'yarn-id': 'application_1455877292606_13009'}, |
369 |
| - {'component': 'componentC', 'type': 'sparkStreaming', 'yarn-id': 'application_1455877292606_13010'}]}) |
| 488 | + self.assertEqual(result, {"yarn_applications": { |
| 489 | + "oozie-componentA": { |
| 490 | + "type": "oozie", |
| 491 | + "yarn-id": "application_1455877292606_13009", |
| 492 | + "component": "componentA", |
| 493 | + "yarn-start-time": 1479996060665, |
| 494 | + "yarn-state": "FINISHED" |
| 495 | + }, |
| 496 | + "sparkStreaming-componentC": { |
| 497 | + "type": "sparkStreaming", |
| 498 | + "yarn-id": "application_1455877292606_13011", |
| 499 | + "component": "componentC", |
| 500 | + "yarn-start-time": 1479996060667, |
| 501 | + "yarn-state": "RUNNING" |
| 502 | + } |
| 503 | + }}) |
0 commit comments