Reply
Master
Posts: 377
Registered: ‎07-01-2015

CM API fails to delete host

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)

 

 

Posts: 958
Topics: 1
Kudos: 230
Solutions: 121
Registered: ‎04-22-2014

Re: CM API fails to delete host

@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).

 

 

 

 

Master
Posts: 377
Registered: ‎07-01-2015

Re: CM API fails to delete host

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
Master
Posts: 377
Registered: ‎07-01-2015

Re: CM API fails to delete host

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.
Master
Posts: 377
Registered: ‎07-01-2015

Re: CM API fails to delete host

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

Posts: 958
Topics: 1
Kudos: 230
Solutions: 121
Registered: ‎04-22-2014

Re: CM API fails to delete host

@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

Highlighted
Master
Posts: 377
Registered: ‎07-01-2015

Re: CM API fails to delete host

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)

Announcements