Community Articles
Find and share helpful community-sourced technical articles
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)
Disclaimer: This article is based on my personal experience and knowledge. Don't take it as a standard guidelines, understand the concept and modify it for your environmental best practices and use case.

Ambari unofficially supports a curl command which will help deleting the old stacks and packages from each of the host .

the script is described in https://issues.apache.org/jira/browse/AMBARI-18435 and also in the article : https://community.hortonworks.com/articles/202904/how-to-remove-all-previous-version-hdp-directories...

But this above script doesn't work in ambari-2.7.3 version.

Root cause : the script will fail with below exception :

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 119, in <module>
    RemovePreviousStacks().execute()
  File "/usr/lib/ambari-agent/lib/resource_management/libraries/script/script.py", line 352, in execute
    method(env)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 49, in actionexecute
    self.remove_stack_version(structured_output, low_version)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 54, in remove_stack_version
    packages_to_remove = self.get_packages_to_remove(version)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 77, in get_packages_to_remove
    all_installed_packages = self.pkg_provider.all_installed_packages()
AttributeError: 'YumManager' object has no attribute 'all_installed_packages'

this was due to fix of : https://issues.apache.org/jira/browse/AMBARI-21738 ( https://github.com/apache/ambari/commit/e7c4ed761072256dabd881242a0eea40d94cf8af) the fix is not handled properly in remove_previous_stacks.py

Workaround :

1) go to each ambari-agent node and edit the file remove_previous_stacks.py

[root@asn1 current]#vi /var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py

2) go to line : 77

edit the line from :

all_installed_packages = self.pkg_provider.all_installed_packages()

to

all_installed_packages = self.pkg_provider.installed_packages()

3) retry the operation via curl again

ex:

curl 'http://asn1.openstacklocal:8080/api/v1/clusters/asnaik/requests' -u admin:admin -H "X-Requested-By: ambari" -X POST -d'{"RequestInfo":{"context":"remove_previous_stacks", "action" : "remove_previous_stacks", "parameters" : {"version":"3.0.1.1-84"}}, "Requests/resource_filters": [{"hosts":"asn1.openstacklocal"}]}'

The Operation has to be success now. If you are facing any issue please comment in this thread and tag me

Please upvote this article if you find this helpful

533 Views
Comments
New Contributor

Thanks Akhil

New Contributor

In my case, I get a different error:

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 119, in <module>
    RemovePreviousStacks().execute()
  File "/usr/lib/ambari-agent/lib/resource_management/libraries/script/script.py", line 352, in execute
    method(env)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 49, in actionexecute
    self.remove_stack_version(structured_output, low_version)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 53, in remove_stack_version
    self.check_no_symlink_to_version(structured_output, version)
  File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 94, in check_no_symlink_to_version
    raise Fail("{0} contains symlink to version for remove! {1}".format(stack_root_current, version))
resource_management.core.exceptions.Fail: /usr/hdp/current/ contains symlink to version for remove! 3.0.1.0-187

Do you have any solution for this error?

Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎12-20-2018 06:09 PM
Updated by:
 
Contributors
Top Kudoed Authors