Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

CM API fails to delete host

CM API fails to delete host

Master Collaborator

Hi Cloudera, 

 I am trying to remove couple of hosts from the ClouderaManager using the cm api, but it fails on this error:

Is there any workaround for this? Thanks

 

 

  File "/usr/lib/python2.7/site-packages/cm_api/api_client.py", line 163, in delete_host
    return hosts.delete_host(self, host_id)
  File "/usr/lib/python2.7/site-packages/cm_api/endpoints/hosts.py", line 63, in delete_host
    return call(resource_root.delete, "%s/%s" % (HOSTS_PATH, host_id), ApiHost)
  File "/usr/lib/python2.7/site-packages/cm_api/endpoints/types.py", line 139, in call
    ret = method(path, params=params)
  File "/usr/lib/python2.7/site-packages/cm_api/resource.py", line 134, in delete
    return self.invoke("DELETE", relpath, params)
  File "/usr/lib/python2.7/site-packages/cm_api/resource.py", line 73, in invoke
    headers=headers)
  File "/usr/lib/python2.7/site-packages/cm_api/http_client.py", line 183, in execute
    raise self._exc_class(ex)
cm_api.api_client.ApiException: Cannot delete or update a parent row: a foreign key constraint fails (`scm_kgaiv2iis6jf08ak9iukknhhrm`.`CLIENT_CONFIGS_TO_HOSTS`, CONSTRAINT `FK_CLIENT_CFG2HOST_HOST` FOREIGN KEY (`HOST_ID`) REFERENCES `HOSTS` (`HOST_ID`)) (error 400)

 

 

6 REPLIES 6

Re: CM API fails to delete host

Super Guru

@Tomas79,

 

Odd that this is coming out of the database layer, but I think it is telling you that there are roles or configurations that apply to that host.  Perhaps they need to be deleted first.  Since CLIENT_CONFIGS_TO_HOSTS is referenced, it appears that one of your client configs is still assigned to that host.

 

I would recommend removing all roles from that host first.  I think that should clear up this problem since the constraint should be removed once the client configuration no longer applies to that host (all gateway roles have been removed).

 

 

 

 

Re: CM API fails to delete host

Master Collaborator
I thought I was doing so, removing the gateway roles and then removing the hosts.
I will test it out once more, will remove all the roles, refresh client libraries and then delete the hosts

Re: CM API fails to delete host

Master Collaborator
I double checked it:
- stopped clouder-scm-agent on the two hosts
- removed all roles from the host(s)
- re-deployed client configurations

CM reports on red on those two hosts (because agent stop), no stale config on cluster, and it still fails with this error message.

Re: CM API fails to delete host

Super Guru

@Tomas79,

 

I don't know then.  If you cannot remove the host from Cloudera Manager, either, it seems something has gone awry in the db.

In that case, it may be necessary to modify the DB itself.

Since the constriant violation indicates that the CLIENT_CONFIGS_TO_HOSTS table 

 

- Stop Cloudera Manager (service cloudera-scm-server stop)

back up your database! so you can recover

- find your host_id.  You can do so with a query like:

 

sql> select HOST_ID from HOSTS where NAME='<your host name>';

 

- Use that host_id to locate the rows in CLIENT_CONFIGS_TO_HOSTS:

 

sql> select * from CLIENT_CONFIGS_TO_HOSTS where HOST_ID='<value from first query>';

 

set that result aside for reference if needed

 

- delete the rows for the host id:

 

sql> delete from CLIENT_CONFIGS_TO_HOSTS where HOST_ID='<value from first query>';

 

- start Cloudera Manager (service cloudera-scm-server start)

- try deleting again.

 

NOTE:  I really don't know if this is all that is needed or why it would be needed.  Hopefully the above steps will get you by the hurdle

Re: CM API fails to delete host

Master Collaborator

Update: I can delete (remove from ClouderaManager) the host via ClouderaManager UI, but cant delete it via python:

 

>>> hostNames=['ip-10-85-150-40.eu-west-1.compute.internal']

>>> for host in hostNames:
... h = [x for x in cm.api.get_all_hosts() if x.ipAddress == socket.gethostbyname( host )][0]
... cm.api.delete_host( h.hostId )
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/usr/lib/python2.7/site-packages/cm_api/api_client.py", line 163, in delete_host
return hosts.delete_host(self, host_id)
File "/usr/lib/python2.7/site-packages/cm_api/endpoints/hosts.py", line 63, in delete_host
return call(resource_root.delete, "%s/%s" % (HOSTS_PATH, host_id), ApiHost)
File "/usr/lib/python2.7/site-packages/cm_api/endpoints/types.py", line 139, in call
ret = method(path, params=params)
File "/usr/lib/python2.7/site-packages/cm_api/resource.py", line 134, in delete
return self.invoke("DELETE", relpath, params)
File "/usr/lib/python2.7/site-packages/cm_api/resource.py", line 73, in invoke
headers=headers)
File "/usr/lib/python2.7/site-packages/cm_api/http_client.py", line 183, in execute
raise self._exc_class(ex)
cm_api.api_client.ApiException: Cannot delete or update a parent row: a foreign key constraint fails (`scm_q79c2v5h5u00ja02nkkjechiat`.`CLIENT_CONFIGS_TO_HOSTS`, CONSTRAINT `FK_CLIENT_CFG2HOST_HOST` FOREIGN KEY (`HOST_ID`) REFERENCES `HOSTS` (`HOST_ID`)) (error 400)

Re: CM API fails to delete host

Master Collaborator

@bgooley how can I delete the client config related to this host via python cm_api?