def stop_management_service(api_client, api_host): api_instance = cm_client.MgmtServiceResourceApi(api_client) try: # Stop the Cloudera Management Services. print(f'Stopping Cloudera Management Service on {api_host}', end='') api_response = api_instance.stop_command() while True: print('.', end='', flush=True) time.sleep(1) api_response = api_instance.read_service(view='summary') if api_response.service_state == 'STOPPED': print('\nStopped.', flush=True) break except ApiException as e: print(f'Exception while calling MgmtServiceResourceApi->stop_command/read_service: {e}')
# Configure Hosts with property needed by SMM host_api = cm_client.AllHostsResourceApi(api_client) message = 'updating CM Agent safety valve for SMM' body = cm_client.ApiConfigList( ) # ApiConfigList | Configuration changes. (optional) body.items = [ cm_client.ApiConfig( name="host_agent_safety_valve", value="kafka_broker_topic_partition_metrics_for_smm_enabled=true") ] cmd = host_api.update_config(message=message, body=body) # create MGMT/CMS mgmt_api = cm_client.MgmtServiceResourceApi(api_client) api_service = cm_client.ApiService() api_service.roles = [ cm_client.ApiRole(type='SERVICEMONITOR'), cm_client.ApiRole(type='HOSTMONITOR'), cm_client.ApiRole(type='EVENTSERVER'), cm_client.ApiRole(type='ALERTPUBLISHER') ] mgmt_api.auto_assign_roles() # needed? mgmt_api.auto_configure() # needed? mgmt_api.setup_cms(body=api_service) cmd = mgmt_api.start_command() wait(cmd)
def mgmt_api(self): if self._mgmt_api is None: self._mgmt_api = cm_client.MgmtServiceResourceApi(self.api_client) return self._mgmt_api
def setupCMS(): service_name = 'mgmt' service_type = 'MGMT'.upper() api_instance = cm_client.MgmtServiceResourceApi(api_client) services_instance = cm_client.MgmtServiceResourceApi(api_client) mgmt_role_instance = cm_client.MgmtRolesResourceApi(api_client) rcg_instance = cm_client.MgmtRoleConfigGroupsResourceApi(api_client) services_instance.setup_cms( body=cm_client.ApiService(name=service_name, type=service_type, display_name='Cloudera Management Service')) host_id = getattr(get_host_resource(hostname), 'host_id', None) role_list = [] for role_type in [ "REPORTSMANAGER", "EVENTSERVER", "HOSTMONITOR", "ALERTPUBLISHER", "SERVICEMONITOR" ]: role_name = service_name + "-" + role_type + "-" + hashlib.md5( hostname.encode('utf-8')).hexdigest() role_list.append({ "name": role_name, "type": role_type, "hostRef": { "hostId": host_id } }) body = cm_client.ApiRoleList(role_list) api_response = mgmt_role_instance.create_roles(body=body) api_response = rcg_instance.read_role_config_groups() for rcg in api_response.items: if rcg.role_type == 'REPORTSMANAGER': rcg_instance.update_config(rcg.name, message=None, body=cm_client.ApiConfigList([{ 'name': 'headlamp_database_host', 'value': hostname }, { 'name': 'headlamp_database_name', 'value': 'rman' }, { 'name': 'headlamp_database_user', 'value': 'rman' }, { 'name': 'headlamp_database_password', 'value': 'supersecret1' }, { 'name': 'headlamp_database_type', 'value': 'postgresql' }])) services_instance.start_command()