def resolve_relation(self, name, node_ids, is_required_for): """Resolves the task relation. :param name: the name of task :param node_ids: the ID of nodes where need to search :param is_required_for: means task from required_for section """ match_policy = NameMatchingPolicy.create(name) for node_id in node_ids: applied_tasks = set() for task_name in self.tasks_per_node[node_id]: if task_name == name: # the simple case when name of current task # is exact math to name of task that is search yield {"name": task_name, "node_id": node_id} continue # at first get the original task name, actual # when current task is part of chain original_task = self.task_processor.get_origin(task_name) if original_task in applied_tasks or \ not match_policy.match(original_task): continue applied_tasks.add(original_task) if original_task is not task_name: if is_required_for: task_name_gen = self.task_processor.get_first_task_id else: task_name_gen = self.task_processor.get_last_task_id task_name = task_name_gen(original_task) yield {"name": task_name, "node_id": node_id}
def resolve_relation(self, name, node_ids, task_resolver, excludes): """Resolves the task relation. :param name: the name of task :param node_ids: the ID of nodes where need to search :param task_resolver: the task name resolver :param excludes: the nodes to exclude """ match_policy = NameMatchingPolicy.create(name) for node_id in node_ids: applied_tasks = set() for task_name in self.tasks_connections[node_id]: if (node_id, task_name) in excludes: continue if task_name == name: # the simple case when name of current task # is exact math to name of task that is search yield task_name, node_id continue # at first get the original task name, actual # when current task is part of chain original_task = self.task_processor.get_origin(task_name) if original_task in applied_tasks or \ not match_policy.match(original_task): continue applied_tasks.add(original_task) if original_task is not task_name: task_name = task_resolver(original_task) yield task_name, node_id
def inject_configs(self, node, roles, output): node_config = output.setdefault('configuration', {}) for config in self._configs: if config.config_type == consts.OPENSTACK_CONFIG_TYPES.cluster: utils.dict_update(node_config, config.configuration, 1) elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.role: for role in roles: if NameMatchingPolicy.create(config.node_role).match(role): utils.dict_update(node_config, config.configuration, 1) elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.node: if config.node_id == node.id: utils.dict_update(node_config, config.configuration, 1)
def resolve_relation(self, name, node_ids, excludes=None): """Resolves the task relation. :param name: the name of task :param node_ids: the ID of nodes where need to search :param excludes: the nodes to exclude """ match_policy = NameMatchingPolicy.create(name) for node_id in node_ids: for task_name in self.tasks_graph.get(node_id, ()): if excludes and (task_name, node_id) in excludes: continue if match_policy.match(task_name): yield task_name, node_id
def inject_configs(self, node, output): node_config = output.setdefault('configuration', {}) for config in self._configs: if config.config_type == consts.OPENSTACK_CONFIG_TYPES.cluster: utils.dict_update(node_config, config.configuration, 1) elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.role: # (asaprykin): objects.Node.all_roles() has a side effect, # it replaces "<rolename>" with "primary-<rolename>" # in case of primary role. for role in node.all_roles: if NameMatchingPolicy.create(config.node_role).match(role): utils.dict_update(node_config, config.configuration, 1) elif config.config_type == consts.OPENSTACK_CONFIG_TYPES.node: if config.node_id == node.id: utils.dict_update(node_config, config.configuration, 1)
def resolve_relation(self, name, node_ids, is_required_for): """Resolves the task relation. :param name: the name of task :param node_ids: the ID of nodes where need to search :param is_required_for: means task from required_for section """ found = False match_policy = NameMatchingPolicy.create(name) for node_id in node_ids: applied_tasks = set() for task_name in self.tasks_per_node[node_id]: if task_name == name: # the simple case when name of current task # is exact math to name of task that is search found = True yield {"name": task_name, "node_id": node_id} continue # at first get the original task name, actual # when current task is part of chain original_task = self.task_processor.get_origin(task_name) if original_task in applied_tasks or \ not match_policy.match(original_task): continue found = True applied_tasks.add(original_task) if original_task is not task_name: if is_required_for: task_name_gen = self.task_processor.get_first_task_id else: task_name_gen = self.task_processor.get_last_task_id task_name = task_name_gen(original_task) yield {"name": task_name, "node_id": node_id} if not found: logger.warning( "Dependency '%s' cannot be resolved: " "no candidates in nodes '%s'.", name, ", ".join(six.moves.map(str, node_ids)) )