示例#1
0
  def test_restart(self):
    resource = utils.MockResource(self, version=5)
    cluster = ApiCluster(resource, name="foo")
    resource.expect(
      method="POST",
      reqpath="/clusters/foo/commands/restart",
      data=None,
      retdata={'name' : 'foo'})
    cluster.restart();

    resource = utils.MockResource(self, version=7)
    newCluster = ApiCluster(resource, name="bar")
    data = dict()
    data['restartOnlyStaleServices'] = False
    data['redeployClientConfiguration'] = True
    resource.expect(
      method="POST",
      reqpath="/clusters/bar/commands/restart",
      data=data,
      retdata={'name' : 'bar'})
    newCluster.restart(False, True);

    resource = utils.MockResource(self, version=11)
    newCluster = ApiCluster(resource, name="bar")
    data = dict()
    data['restartOnlyStaleServices'] = False
    data['redeployClientConfiguration'] = True
    data['restartServiceNames'] = ["A", "B"]
    resource.expect(
      method="POST",
      reqpath="/clusters/bar/commands/restart",
      data=data,
      retdata={'name' : 'bar'})
    newCluster.restart(False, True, ["A", "B"]);
示例#2
0
    def test_non_empty_list_watched_directories(self):
        WATCHED_DIRS_LIST = '''{
      "items": [ {
        "path" : "/dir1"
      }, {
        "path" : "/dir2"
      } ]
    }'''

        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("GET",
                        "/cm/service/watcheddir",
                        retdata=json.loads(WATCHED_DIRS_LIST))
        responses = service.list_watched_directories()

        self.assertIsInstance(responses, ApiList)
        self.assertEquals(2, len(responses))
        response = responses[0]
        self.assertIsInstance(response, ApiWatchedDir)
        self.assertEquals("/dir1", response.path)
        response = responses[1]
        self.assertIsInstance(response, ApiWatchedDir)
        self.assertEquals("/dir2", response.path)
示例#3
0
  def test_delete_dashboard(self):
    resource = utils.MockResource(self)
    resource.expect("DELETE", "/timeseries/dashboards/oldDash",
      retdata=json.loads(TestDashboards.get_test_dashboard()),
      params=None)

    resp = delete_dashboard(resource, "oldDash")
示例#4
0
    def test_all_hosts_config(self):
        SUMMARY = """
      {
        "items" : [ {
          "name" : "blacklisted_parcel_products",
          "value" : "foo,bar"
        } ]
      }
      """
        FULL = """
      {
        "items" : [ {
          "name" : "blacklisted_parcel_products",
          "value" : "foo,bar",
          "required" : false,
          "default" : "",
          "displayName" : "Blacklisted Products",
          "description" : "Parcels for blacklisted products will not be distributed to the host, nor activated for process execution. Already distributed parcels will be undistributed. Already running process will not be affected until the next restart.",
          "validationState" : "OK"
        }, {
          "name" : "rm_enabled",
          "required" : false,
          "default" : "false",
          "displayName" : "Enable Resource Management",
          "description" : "Enables resource management for all roles on this host.",
          "validationState" : "OK",
          "validationWarningsSuppressed" : false
        } ]
      }
      """

        resource = utils.MockResource(self)
        cms = ClouderaManager(resource)

        resource.expect("GET",
                        "/cm/allHosts/config",
                        retdata=json.loads(SUMMARY))
        cfg = cms.get_all_hosts_config()
        self.assertIsInstance(cfg, dict)
        self.assertEqual(1, len(cfg))
        self.assertEqual('foo,bar', cfg.get('blacklisted_parcel_products'))

        resource.expect("GET",
                        "/cm/allHosts/config",
                        params={'view': 'full'},
                        retdata=json.loads(FULL))
        cfg = cms.get_all_hosts_config(view='full')
        self.assertIsInstance(cfg, dict)
        self.assertEqual(2, len(cfg))
        self.assertIsInstance(cfg['blacklisted_parcel_products'], ApiConfig)
        self.assertFalse(cfg['blacklisted_parcel_products'].required)
        self.assertEqual('OK', cfg['rm_enabled'].validationState)

        cfg = {'blacklisted_parcel_products': 'bar'}
        resource.expect("PUT",
                        "/cm/allHosts/config",
                        data=config_to_json(cfg),
                        retdata=json.loads(SUMMARY))
        cms.update_all_hosts_config(cfg)
示例#5
0
 def test_update_user(self):
   res = utils.MockResource(self)
   user = ApiUser(res, "alice", roles=[ 'ROLE_LIMITED' ])
   expected = { 'name' : 'alice', 'roles' : [ 'ROLE_LIMITED'] }
   res.expect("PUT", "/users/alice", data=expected, retdata=expected)
   updated = update_user(res, user)
   self.assertTrue('ROLE_LIMITED' in updated.roles)
   self.assertEqual(1, len(updated.roles))
示例#6
0
  def test_get_dashboards(self):
    resource = utils.MockResource(self)
    resource.expect("GET", "/timeseries/dashboards",
      retdata=json.loads(TestDashboards.get_test_dashboard_list()),
      params=None)

    resp = get_dashboards(resource)
    self.assertEqual(1, len(resp))
示例#7
0
  def test_create_hdfs_tmp(self):
    resource = utils.MockResource(self)
    service = ApiService(resource, 'hdfs1', 'HDFS')
    service.__dict__['clusterRef'] = ApiClusterRef(resource, clusterName='cluster1')

    resource.expect("POST", "/clusters/cluster1/services/hdfs1/commands/hdfsCreateTmpDir",
        retdata=ApiCommand(resource).to_json_dict())
    service.create_hdfs_tmp()
示例#8
0
  def test_cancel_query(self):
    resource = utils.MockResource(self)
    service = ApiService(resource, name="bar")

    resource.expect("POST", "/cm/service/impalaQueries/randomId/cancel",
        retdata={ 'warning' : 'test' })
    resp = service.cancel_impala_query('randomId')
    self.assertEquals('test', resp.warning)
示例#9
0
    def test_revoke_admin(self):
        res = utils.MockResource(self)

        user = ApiUser(res, "alice", roles=['ROLE_ADMIN'])
        expected = {'name': 'alice', 'roles': []}
        res.expect("PUT", "/users/alice", data=expected, retdata=expected)
        updated = user.revoke_admin_role()
        self.assertEqual(0, len(updated.roles))
示例#10
0
  def test_pools_refresh(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")

    resource.expect("POST", "/clusters/foo/commands/poolsRefresh",
        data=None,
        retdata={ 'name' : 'foo'})
    cluster.pools_refresh()
示例#11
0
 def test_export_cluster_template(self):
   resource = utils.MockResource(self)
   cluster = ApiCluster(resource, name="foo")
   resource.expect(
     method="GET",
     reqpath="/clusters/foo/export",
     params=dict(exportAutoConfig=True),
     retdata=ApiClusterTemplate(resource).to_json_dict())
   cluster.export(export_auto_config=True)
示例#12
0
    def test_kill_application(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("POST",
                        "/cm/service/yarnApplications/randomId/kill",
                        retdata={'warning': 'test'})
        resp = service.kill_yarn_application('randomId')
        self.assertEquals('test', resp.warning)
示例#13
0
    def test_empty_list_watched_directories(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("GET", "/cm/service/watcheddir", retdata={"items": []})

        responses = service.list_watched_directories()
        self.assertIsInstance(responses, ApiList)
        self.assertEquals(0, len(responses))
示例#14
0
  def test_get_details(self):
    resource = utils.MockResource(self)
    service = ApiService(resource, name="bar")

    resource.expect("GET", "/cm/service/impalaQueries/randomId",
        retdata={ 'details': '' },
        params={ 'format':'text' } )
    resp = service.get_query_details('randomId')
    self.assertEquals('', resp.details)
示例#15
0
    def test_grant_admin(self):
        res = utils.MockResource(self)

        user = ApiUser(res, "alice")
        expected = {'name': 'alice', 'roles': ['ROLE_ADMIN']}
        res.expect("PUT", "/users/alice", data=expected, retdata=expected)
        updated = user.grant_admin_role()
        self.assertTrue('ROLE_ADMIN' in updated.roles)
        self.assertEqual(1, len(updated.roles))
示例#16
0
  def test_create_dashboards(self):
    resource = utils.MockResource(self)
    dashboard = ApiDashboard("newDash", "newJsonBlob")
    resource.expect("POST", "/timeseries/dashboards",
      retdata=json.loads(TestDashboards.get_test_dashboard_list()),
      params=None,
      data=[dashboard])

    resp = create_dashboards(resource, [dashboard])
    self.assertEquals(1, len(resp))
示例#17
0
  def test_update_cdh_version(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")

    data = ApiCluster(resource, name='foo', fullVersion='4.2.1')

    resource.expect("PUT", "/clusters/foo",
        data=data,
        retdata={ 'name' : 'foo'})
    cluster.update_cdh_version('4.2.1')
示例#18
0
 def test_import_cluster_v12(self):
     resource = utils.MockResource(self, version=12)
     cms = ClouderaManager(resource)
     data = ApiClusterTemplate(resource).to_json_dict()
     resource.expect(method="POST",
                     reqpath="/cm/importClusterTemplate",
                     params=dict(addRepositories=True),
                     data=data,
                     retdata=ApiCommand(resource).to_json_dict())
     cms.import_cluster_template(data, True)
示例#19
0
    def test_remove_watched_directory(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("DELETE",
                        "/cm/service/watcheddir/one_dir_path",
                        retdata={'path': 'one_dir_path'})
        response = service.remove_watched_directory("one_dir_path")
        self.assertIsInstance(response, ApiWatchedDir)
        self.assertEquals("one_dir_path", response.path)
示例#20
0
  def test_add_hosts(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")

    data = ApiList([ ApiHostRef(resource, hostId='foo') ])

    resource.expect("POST", "/clusters/foo/hosts",
        data=data,
        retdata={ 'items' : [ { 'hostId' : 'foo' } ] })
    cluster.add_hosts(['foo'])
示例#21
0
  def test_get_dashboard(self):
    resource = utils.MockResource(self)
    resource.expect("GET", "/timeseries/dashboards/myDash",
      retdata=json.loads(TestDashboards.get_test_dashboard()),
      params=None)

    resp = get_dashboard(resource, "myDash")
    self.assertIsInstance(resp, ApiDashboard)
    self.assertEqual("MyDash", resp.name)
    self.assertEqual("jsonBlob", resp.json)
示例#22
0
    def test_attributes(self):
        YARN_APPLICATION_ATTRS = '''{
      "items": [
        {
          "name": "name",
          "type": "STRING",
          "displayName": "Name",
          "supportsHistograms": true,
          "description": "Name of the YARN application. Called 'name' in searches."
        },
        {
          "name": "user",
          "type": "STRING",
          "displayName": "User",
          "supportsHistograms": true,
          "description": "The user who ran the YARN application. Called 'user' in searches."
        },
        {
          "name": "executing",
          "type": "BOOLEAN",
          "displayName": "Executing",
          "supportsHistograms": false,
          "description": "Whether the YARN application is currently executing. Called 'executing' in searches."
        }]
    }'''

        self.resource = utils.MockResource(self)
        self.resource.expect("GET",
                             "yarnApplications/attributes",
                             retdata=json.loads(YARN_APPLICATION_ATTRS))

        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("GET",
                        "/cm/service/yarnApplications/attributes",
                        retdata=json.loads(YARN_APPLICATION_ATTRS))
        resp = service.get_yarn_application_attributes()
        self.assertEquals(3, len(resp))
        attr = resp[0]
        self.assertIsInstance(attr, ApiYarnApplicationAttribute)
        self.assertEquals('name', attr.name)
        self.assertEquals(True, attr.supportsHistograms)
示例#23
0
    def test_add_watched_directory(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect("POST",
                        "/cm/service/watcheddir",
                        retdata={'path': '/dir'},
                        data={'path': '/dir'})
        response = service.add_watched_directory("/dir")
        self.assertIsInstance(response, ApiWatchedDir)
        self.assertEquals("/dir", response.path)
示例#24
0
    def test_get_yarn_applications(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        time = datetime.datetime.now()

        resource.expect("GET", "/cm/service/yarnApplications",
        retdata={ 'applications': [], 'warnings' : [] },
        params={ 'from':time.isoformat(), 'to':time.isoformat(), \
            'filter':'', 'limit':100, 'offset':0 })
        resp = service.get_yarn_applications(time, time)
        self.assertEquals(0, len(resp.applications))
示例#25
0
 def __init__(self, methodName):
     unittest.TestCase.__init__(self, methodName)
     self.resource = utils.MockResource(self)
     self.account = ApiExternalAccount(
         self.resource,
         name='test1',
         displayName='test_d1',
         typeName='AWS_ACCESS_KEY_AUTH',
         accountConfigs=ApiList([
             ApiConfig(self, "aws_access_key", "foo"),
             ApiConfig(self, "aws_secret_key", "bar")
         ]))
示例#26
0
  def test_configure_for_kerberos(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")

    data = dict()
    data['datanodeTransceiverPort'] = 23456
    data['datanodeWebPort'] = 12345

    resource.expect("POST", "/clusters/foo/commands/configureForKerberos",
        data=data,
        retdata={ 'name' : 'foo'})
    cluster.configure_for_kerberos(23456, 12345)
示例#27
0
    def test_collect_yarn_application_diagnostics(self):
        resource = utils.MockResource(self)
        service = ApiService(resource, name="bar")

        resource.expect(
            "POST",
            "/cm/service/commands/yarnApplicationDiagnosticsCollection",
            retdata={'name': 'YarnApplicationDiagnosticsCollection'})
        resp = service.collect_yarn_application_diagnostics(
            'randomId-1', 'randomId-2', 'randomId-3')

        self.assertEquals('YarnApplicationDiagnosticsCollection', resp.name)
示例#28
0
  def test_host_commission_with_start(self):
    resource = utils.MockResource(self)
    cms = ClouderaManager(resource)

    resource.expect("POST", "/cm/commands/hostsDecommission",
        data=[ "host1", "host2" ],
        retdata={})
    cms.hosts_decommission([ "host1", "host2" ])

    resource.expect("POST", "/cm/commands/hostsRecommissionWithStart",
        data=[ "host1", "host2" ],
        retdata={})
    cms.hosts_recommission_with_start([ "host1", "host2" ])
示例#29
0
  def test_upgrade_cdh(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")

    data = dict()
    data['deployClientConfig'] = False
    data['startAllServices'] = True
    data['cdhParcelVersion'] = '5.0.0.1-cdh5-1.2.3'

    resource.expect("POST", "/clusters/foo/commands/upgradeCdh",
        data=data,
        retdata={ 'name' : 'foo'})
    cluster.upgrade_cdh(False, True, data['cdhParcelVersion'])
示例#30
0
  def test_list_dfs_services(self):
    resource = utils.MockResource(self)
    cluster = ApiCluster(resource, name="foo")
    data = None
    resource.expect("GET", "/clusters/foo/dfsServices",
        data=data,
        retdata={ 'name' : 'foo'})
    cluster.list_dfs_services()

    data = None
    resource.expect("GET", "/clusters/foo/dfsServices?view=EXPORT",
        data=data,
        retdata={ 'name' : 'foo'})
    cluster.list_dfs_services(view="EXPORT")