|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from pprint import pprint |
| 6 | +from unittest import TestCase |
| 7 | +from yarn_api_client.resource_manager import ResourceManager |
| 8 | + |
| 9 | +try: |
| 10 | + from urlparse import urlparse |
| 11 | +except ImportError: |
| 12 | + from urllib.parse import urlparse |
| 13 | + |
| 14 | + |
| 15 | +class ResourceManagerTestCase(TestCase): |
| 16 | + """ |
| 17 | + Integration test that, given a provided YARN ENDPOINT, |
| 18 | + execute some real scenario test against that server. |
| 19 | +
|
| 20 | + Note that, if no YARN ENDPOINT is provided, the tests |
| 21 | + are ignored. |
| 22 | + """ |
| 23 | + @classmethod |
| 24 | + def setUpClass(self): |
| 25 | + self.configured = False |
| 26 | + if os.getenv('YARN_ENDPOINT'): |
| 27 | + yarn_endpoint = os.getenv('YARN_ENDPOINT') |
| 28 | + yarn_endpoint_uri = urlparse(yarn_endpoint) |
| 29 | + |
| 30 | + if yarn_endpoint_uri.hostname and yarn_endpoint_uri.port: |
| 31 | + self.configured = True |
| 32 | + self.resourceManager = ResourceManager(yarn_endpoint_uri.hostname, yarn_endpoint_uri.port) |
| 33 | + |
| 34 | + def test_cluster_information(self): |
| 35 | + if self.configured: |
| 36 | + info = self.resourceManager.cluster_information() |
| 37 | + pprint(info.data) |
| 38 | + self.assertEqual(info.data['clusterInfo']['state'], 'STARTED') |
| 39 | + |
| 40 | + def test_cluster_metrics(self): |
| 41 | + if self.configured: |
| 42 | + metrics = self.resourceManager.cluster_metrics() |
| 43 | + pprint(metrics.data) |
| 44 | + self.assertGreater(metrics.data['clusterMetrics']['activeNodes'], 0) |
| 45 | + self.assertIsNotNone(metrics.data['clusterMetrics']['totalNodes']) |
| 46 | + |
| 47 | + def test_cluster_scheduler(self): |
| 48 | + if self.configured: |
| 49 | + scheduler = self.resourceManager.cluster_scheduler() |
| 50 | + pprint(scheduler.data) |
| 51 | + self.assertIsNotNone(scheduler.data['scheduler']['schedulerInfo']) |
| 52 | + |
| 53 | + def test_cluster_applications(self): |
| 54 | + if self.configured: |
| 55 | + apps = self.resourceManager.cluster_applications() |
| 56 | + pprint(apps.data) |
| 57 | + self.assertIsNotNone(apps.data['apps']) |
| 58 | + |
| 59 | + def test_cluster_application_state(self): |
| 60 | + if self.configured: |
| 61 | + apps = self.resourceManager.cluster_applications() |
| 62 | + appid = apps.data['apps']['app'][0]['id'] |
| 63 | + print(appid) |
| 64 | + response = self.resourceManager.cluster_application_state(appid) |
| 65 | + pprint(response.data) |
| 66 | + pprint(response.data['state']) |
| 67 | + self.assertIsNotNone(apps.data['apps']) |
| 68 | + |
| 69 | + def test_cluster_application_statistics(self): |
| 70 | + if self.configured: |
| 71 | + appstats = self.resourceManager.cluster_application_statistics() |
| 72 | + pprint(appstats.data) |
| 73 | + self.assertIsNotNone(appstats.data['appStatInfo']) |
| 74 | + |
| 75 | + def test_cluster_nodes(self): |
| 76 | + if self.configured: |
| 77 | + nodes = self.resourceManager.cluster_nodes() |
| 78 | + pprint(nodes.data) |
| 79 | + self.assertIsNotNone(nodes.data['nodes']) |
| 80 | + |
| 81 | + running_nodes = self.resourceManager.cluster_nodes(state='RUNNING', healthy='true') |
| 82 | + pprint(running_nodes.data) |
| 83 | + self.assertIsNotNone(nodes.data['nodes']) |
0 commit comments