简体   繁体   中英

decommission host through cm_api (gracefully)

I am trying to decommission host from cloudera manager (gracefully) using cm_api. I tried following but which is deleting the role and abruptly stopping the YARN containers running on it

#!/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 ?

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.

Search for the ClouderaManager class and hosts_decommission function in this link 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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