def load_available_packages(self): from ambari_commons.repo_manager import ManagerFactory if self.available_packages_in_repos: return self.available_packages_in_repos config = self.get_config() service_name = config['serviceName'] if 'serviceName' in config else None repos = CommandRepository(config['repositoryFile']) from resource_management.libraries.functions import lzo_utils # remove repos with 'GPL' tag when GPL license is not approved repo_tags_to_skip = set() if not lzo_utils.is_gpl_license_accepted(): repo_tags_to_skip.add("GPL") repos.items = [r for r in repos.items if not (repo_tags_to_skip & r.tags)] repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Command repositories: {0}".format(", ".join(repo_ids))) repos.items = [x for x in repos.items if (not x.applicable_services or service_name in x.applicable_services) ] applicable_repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Applicable repositories: {0}".format(", ".join(applicable_repo_ids))) pkg_provider = ManagerFactory.get() try: self.available_packages_in_repos = pkg_provider.get_available_packages_in_repos(repos) except Exception as err: Logger.exception("Unable to load available packages") self.available_packages_in_repos = [] return self.available_packages_in_repos
def load_available_packages(self): from ambari_commons.repo_manager import ManagerFactory if self.available_packages_in_repos: return self.available_packages_in_repos config = self.get_config() service_name = config['serviceName'] if 'serviceName' in config else None repos = CommandRepository(config['repositoryFile']) repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Command repositories: {0}".format(", ".join(repo_ids))) repos.items = [x for x in repos.items if (not x.applicable_services or service_name in x.applicable_services) ] applicable_repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Applicable repositories: {0}".format(", ".join(applicable_repo_ids))) pkg_provider = ManagerFactory.get() try: self.available_packages_in_repos = pkg_provider.get_available_packages_in_repos(repos) except Exception as err: Logger.exception("Unable to load available packages") self.available_packages_in_repos = [] return self.available_packages_in_repos
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']) command_repos.items = [x for x in command_repos.items if not x.applicable_services] 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