简体   繁体   English

通过cm_api停用主机(正常)

[英]decommission host through cm_api (gracefully)

I am trying to decommission host from cloudera manager (gracefully) using cm_api. 我正在尝试使用cm_api从Cloudera Manager停用主机(正常)。 I tried following but which is deleting the role and abruptly stopping the YARN containers running on it 我尝试了以下操作,但正在删除该角色并突然停止在其上运行的YARN容器

#!/usr/bin/env python2.6
my_cluster = "cluster"
cloudera_manager = "1.2.3.4"
cloudera_username = "admin"
cloudera_password = "admin"

import time
from datetime import datetime, timedelta
from cm_api.api_client import ApiResource
from cm_api.endpoints.cms import ClouderaManager
from cm_api.endpoints.clusters import ApiCluster
from cm_api.endpoints.hosts import get_host, delete_host

api = ApiResource(cloudera_manager, username=cloudera_username, password=cloudera_password)
cl = ApiCluster(api, my_cluster)
hosts = []
roles = []
ha = get_host(api, "$INSTANCE_ID")

for r in ha.roleRefs:
    roles.append((r.serviceName, r.roleName))

for srv_name, role_name in roles:
    service = cl.get_service(srv_name)
    service.delete_role(role_name)

Does anyone know how do we decommission the host in cloudera manager using cm_api ? 有谁知道我们如何使用cm_api在cloudera Manager中停用主机?

This is because you are only deleting the role in your code. 这是因为您仅删除代码中的角色。 To decommission the host, you need to use the hosts_decommission function of the ClouderaManager class. 要停用主机,您需要使用ClouderaManager类的hosts_decommission函数。

Search for the ClouderaManager class and hosts_decommission function in this link http://cloudera.github.io/cm_api/epydoc/5.4.0/index.html 在此链接中搜索ClouderaManager类和hosts_decommission函数http://cloudera.github.io/cm_api/epydoc/5.4.0/index.html

You'll use something like the following: 您将使用类似以下内容的东西:

cm = ClouderaManager(api)
# Get all the hosts to decommission and save it in hosts array
hosts = ['host1','host2','host3']

for h in hosts:
    cm.hosts_decommission(h)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM