def get_stack_version_before_packages_installed(self): """ This works in a lazy way (calculates the version first time and stores it). If you need to recalculate the version explicitly set: Script.stack_version_from_distro_select = None before the call. However takes a bit of time, so better to avoid. :return: stack version including the build number. e.g.: 2.3.4.0-1234. """ # preferred way is to get the actual selected version of current component component_name = self.get_component_name() if not Script.stack_version_from_distro_select and component_name: from resource_management.libraries.functions import stack_select Script.stack_version_from_distro_select = stack_select.get_stack_version_before_install( component_name) # If <stack-selector-tool> has not yet been done (situations like first install), # we can use <stack-selector-tool> version itself. # Wildcards cause a lot of troubles with installing packages, if the version contains wildcards we should try to specify it. if not Script.stack_version_from_distro_select or '*' in Script.stack_version_from_distro_select: # FIXME: this method is not reliable to get stack-selector-version # as if there are multiple versions installed with different <stack-selector-tool>, we won't detect the older one (if needed). Script.stack_version_from_distro_select = packages_analyzer.getInstalledPackageVersion( stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME)) return Script.stack_version_from_distro_select
def get_stack_version_before_packages_installed(self): """ This works in a lazy way (calculates the version first time and stores it). If you need to recalculate the version explicitly set: Script.stack_version_from_distro_select = None before the call. However takes a bit of time, so better to avoid. :return: stack version including the build number. e.g.: 2.3.4.0-1234. """ # preferred way is to get the actual selected version of current component component_name = self.get_component_name() if not Script.stack_version_from_distro_select and component_name: from resource_management.libraries.functions import stack_select Script.stack_version_from_distro_select = stack_select.get_stack_version_before_install(component_name) # If <stack-selector-tool> has not yet been done (situations like first install), # we can use <stack-selector-tool> version itself. # Wildcards cause a lot of troubles with installing packages, if the version contains wildcards we should try to specify it. if not Script.stack_version_from_distro_select or '*' in Script.stack_version_from_distro_select: # FIXME: this method is not reliable to get stack-selector-version # as if there are multiple versions installed with different <stack-selector-tool>, we won't detect the older one (if needed). Script.stack_version_from_distro_select = packages_analyzer.getInstalledPackageVersion( stack_tools.get_stack_tool_package(stack_tools.STACK_SELECTOR_NAME)) return Script.stack_version_from_distro_select
def get_stack_version_before_packages_installed(self): """ This works in a lazy way (calculates the version first time and stores it). If you need to recalculate the version explicitly set: Script.stack_version_from_distro_select = None before the call. However takes a bit of time, so better to avoid. :return: stack version including the build number. e.g.: 2.3.4.0-1234. """ # preferred way is to get the actual selected version of current component component_name = self.get_component_name() if not Script.stack_version_from_distro_select and component_name: from resource_management.libraries.functions import stack_select Script.stack_version_from_distro_select = stack_select.get_stack_version_before_install( component_name) # If <stack-selector-tool> has not yet been done (situations like first install), # we can use <stack-selector-tool> version itself. if not Script.stack_version_from_distro_select: Script.stack_version_from_distro_select = packages_analyzer.getInstalledPackageVersion( stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME)) return Script.stack_version_from_distro_select
def install_packages(self, package_list): """ Actually install the packages using the package manager. :param package_list: List of package names to install :return: Returns 0 if no errors were found, and 1 otherwise. """ ret_code = 0 config = self.get_config() agent_stack_retry_on_unavailability = cbool(config['hostLevelParams']['agent_stack_retry_on_unavailability']) agent_stack_retry_count = cint(config['hostLevelParams']['agent_stack_retry_count']) # Install packages packages_were_checked = False stack_selector_package = stack_tools.get_stack_tool_package(stack_tools.STACK_SELECTOR_NAME) try: Package(stack_selector_package, action="upgrade", retry_on_repo_unavailability=agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count ) packages_installed_before = [] allInstalledPackages(packages_installed_before) packages_installed_before = [package[0] for package in packages_installed_before] packages_were_checked = True filtered_package_list = self.filter_package_list(package_list) for package in filtered_package_list: name = self.format_package_name(package['name']) Package(name, action="upgrade", # this enables upgrading non-versioned packages, despite the fact they exist. Needed by 'mahout' which is non-version but have to be updated retry_on_repo_unavailability=agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count ) except Exception, err: ret_code = 1 Logger.logger.exception("Package Manager failed to install packages. Error: {0}".format(str(err))) # Remove already installed packages in case of fail if packages_were_checked and packages_installed_before: packages_installed_after = [] allInstalledPackages(packages_installed_after) packages_installed_after = [package[0] for package in packages_installed_after] packages_installed_before = set(packages_installed_before) new_packages_installed = [package for package in packages_installed_after if package not in packages_installed_before] if OSCheck.is_ubuntu_family(): package_version_string = self.repository_version.replace('.', '-') else: package_version_string = self.repository_version.replace('-', '_') package_version_string = package_version_string.replace('.', '_') for package in new_packages_installed: if package_version_string and (package_version_string in package): Package(package, action="remove")
def actionexecute(self, env): config = Script.get_config() structured_output = {} version = config['commandParams']['version'] self.stack_tool_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) versions_to_remove = self.get_lower_versions(version) for low_version in versions_to_remove: self.remove_stack_version(structured_output, low_version)
def install_packages(): import params if params.host_sys_prepped: return packages = ['unzip', 'curl'] if params.stack_version_formatted != "" and compare_versions( params.stack_version_formatted, '2.2') >= 0: stack_selector_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) packages.append(stack_selector_package) Package(packages, retry_on_repo_unavailability=params. agent_stack_retry_on_unavailability, retry_count=params.agent_stack_retry_count)
def install_packages(self, package_list): """ Actually install the packages using the package manager. :param package_list: List of package names to install :return: Returns 0 if no errors were found, and 1 otherwise. """ ret_code = 0 config = self.get_config() agent_stack_retry_on_unavailability = cbool( config['ambariLevelParams']['agent_stack_retry_on_unavailability']) agent_stack_retry_count = cint( config['ambariLevelParams']['agent_stack_retry_count']) # Install packages packages_were_checked = False packages_installed_before = [] stack_selector_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) try: # install the stack-selector; we need to supply the action as "upgrade" here since the normal # install command will skip if the package is already installed in the system. # This is required for non-versioned components, like stack-select, since each version of # the stack comes with one. Also, scope the install by repository since we need to pick a # specific repo that the stack-select tools are coming out of in case there are multiple # patches installed repositories = config['repositoryFile']['repositories'] command_repos = CommandRepository(config['repositoryFile']) repository_ids = [ repository['repoId'] for repository in repositories ] repos_to_use = {} for repo_id in repository_ids: if repo_id in self.repo_files: repos_to_use[repo_id] = self.repo_files[repo_id] self.repo_mgr.upgrade_package( stack_selector_package, RepoCallContext(ignore_errors=False, use_repos=repos_to_use, retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count)) packages_installed_before = self.repo_mgr.installed_packages() packages_installed_before = [ package[0] for package in packages_installed_before ] packages_were_checked = True filtered_package_list = self.filter_package_list(package_list) try: available_packages_in_repos = self.repo_mgr.get_available_packages_in_repos( command_repos) except Exception: available_packages_in_repos = [] installation_context = RepoCallContext( ignore_errors=False, retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count) for package in filtered_package_list: name = self.get_package_from_available( package['name'], available_packages_in_repos) # This enables upgrading non-versioned packages, despite the fact they exist. # Needed by 'mahout' which is non-version but have to be updated self.repo_mgr.upgrade_package(name, installation_context) except Exception as err: ret_code = 1 Logger.logger.error( "Package Manager failed to install packages: {0}".format( str(err))) # Remove already installed packages in case of fail if packages_were_checked and packages_installed_before: packages_installed_after = self.repo_mgr.installed_packages() packages_installed_after = [ package[0] for package in packages_installed_after ] packages_installed_before = set(packages_installed_before) new_packages_installed = [ package for package in packages_installed_after if package not in packages_installed_before ] if OSCheck.is_ubuntu_family(): package_version_string = self.repository_version.replace( '.', '-') else: package_version_string = self.repository_version.replace( '-', '_') package_version_string = package_version_string.replace( '.', '_') for package in new_packages_installed: if package_version_string and (package_version_string in package): self.repo_mgr.remove_package(package, RepoCallContext()) if not self.repo_mgr.verify_dependencies(): ret_code = 1 Logger.logger.error("Failure while verifying dependencies") Logger.logger.error( "*******************************************************************************" ) Logger.logger.error( "Manually verify and fix package dependencies and then re-run install_packages" ) Logger.logger.error( "*******************************************************************************" ) # Compute the actual version in order to save it in structured out try: if ret_code == 0: self.compute_actual_version() else: self.check_partial_install() except Fail as err: ret_code = 1 Logger.logger.exception( "Failure while computing actual version. Error: {0}".format( str(err))) return ret_code
def install_packages(self, package_list): """ Actually install the packages using the package manager. :param package_list: List of package names to install :return: Returns 0 if no errors were found, and 1 otherwise. """ ret_code = 0 config = self.get_config() agent_stack_retry_on_unavailability = cbool( config['hostLevelParams']['agent_stack_retry_on_unavailability']) agent_stack_retry_count = cint( config['hostLevelParams']['agent_stack_retry_count']) # Install packages packages_were_checked = False stack_selector_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) try: Package(stack_selector_package, action="upgrade", retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count) packages_installed_before = [] allInstalledPackages(packages_installed_before) packages_installed_before = [ package[0] for package in packages_installed_before ] packages_were_checked = True filtered_package_list = self.filter_package_list(package_list) try: available_packages_in_repos = packages_analyzer.get_available_packages_in_repos( config['repositoryFile']['repositories']) except Exception: available_packages_in_repos = [] for package in filtered_package_list: name = self.get_package_from_available( package['name'], available_packages_in_repos) Package( name, action= "upgrade", # this enables upgrading non-versioned packages, despite the fact they exist. Needed by 'mahout' which is non-version but have to be updated retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count) except Exception as err: ret_code = 1 Logger.logger.exception( "Package Manager failed to install packages. Error: {0}". format(str(err))) # Remove already installed packages in case of fail if packages_were_checked and packages_installed_before: packages_installed_after = [] allInstalledPackages(packages_installed_after) packages_installed_after = [ package[0] for package in packages_installed_after ] packages_installed_before = set(packages_installed_before) new_packages_installed = [ package for package in packages_installed_after if package not in packages_installed_before ] if OSCheck.is_ubuntu_family(): package_version_string = self.repository_version.replace( '.', '-') else: package_version_string = self.repository_version.replace( '-', '_') package_version_string = package_version_string.replace( '.', '_') for package in new_packages_installed: if package_version_string and (package_version_string in package): Package(package, action="remove") if not verifyDependencies(): ret_code = 1 Logger.logger.error("Failure while verifying dependencies") Logger.logger.error( "*******************************************************************************" ) Logger.logger.error( "Manually verify and fix package dependencies and then re-run install_packages" ) Logger.logger.error( "*******************************************************************************" ) # Compute the actual version in order to save it in structured out try: if ret_code == 0: self.compute_actual_version() else: self.check_partial_install() except Fail as err: ret_code = 1 Logger.logger.exception( "Failure while computing actual version. Error: {0}".format( str(err))) return ret_code