def has_prepare(self):
     prepare_node = xml_utils.find_node_by_tag(self.mapper.oozie_node,
                                               "prepare")
     if prepare_node:
         delete_nodes = xml_utils.find_nodes_by_tag(prepare_node, "delete")
         mkdir_nodes = xml_utils.find_node_by_tag(prepare_node, "mkdir")
         if delete_nodes or mkdir_nodes:
             return True
     return False
Пример #2
0
    def test_parse_job_xml_and_configuration_minimal_green_path(
            self, extract_properties_from_configuration_node_mock,
            extract_properties_from_job_xml_nodes_mock):
        # language=XML
        action_node_str = """
<action name="action">
    <job-xml>AAA.xml</job-xml>
    <configuration>
        <property>
            <name>KEY1</name>
            <value>VALUE1</value>
        </property>
    </configuration>
</action>
"""
        action_node: ET.Element = cast(ET.Element,
                                       ET.fromstring(action_node_str))
        mapper = self._get_action_mapper(action_node)

        mapper.on_parse_node()

        config_node = find_node_by_tag(action_node, TAG_CONFIGURATION)
        extract_properties_from_configuration_node_mock.assert_called_once_with(
            config_node=config_node)

        job_xml_nodes = find_nodes_by_tag(action_node, TAG_JOB_XML)
        extract_properties_from_job_xml_nodes_mock.assert_called_once_with(
            input_directory_path="/tmp/input_directory_path",
            job_xml_nodes=job_xml_nodes)

        self.assertEqual({
            "KEY1": "VALUE1",
            "KEY2": "VALUE2"
        }, mapper.props.action_node_properties)
 def parse_prepare_node(self) -> Tuple[List[str], List[str]]:
     """
     <prepare>
         <delete path="[PATH]"/>
         ...
         <mkdir path="[PATH]"/>
         ...
     </prepare>
     """
     delete_paths = []
     mkdir_paths = []
     prepare_node = xml_utils.find_node_by_tag(self.mapper.oozie_node,
                                               "prepare")
     if prepare_node:
         # If there exists a prepare node, there will only be one, according
         # to oozie xml schema
         for node in prepare_node:
             node_path = normalize_path(node.attrib["path"],
                                        props=self.mapper.props)
             if node.tag == "delete":
                 delete_paths.append(node_path)
             elif node.tag == "mkdir":
                 mkdir_paths.append(node_path)
             else:
                 raise Exception(f"Unknown XML node in prepare: {node.tag}")
     return delete_paths, mkdir_paths
Пример #4
0
    def _parse_config(self):
        job_xml_nodes = find_nodes_by_tag(self.oozie_node, TAG_JOB_XML)
        job_xml_properties = extract_properties_from_job_xml_nodes(
            job_xml_nodes=job_xml_nodes,
            input_directory_path=self.input_directory_path)
        self.props.action_node_properties.update(job_xml_properties)

        configuration_node = find_node_by_tag(self.oozie_node,
                                              TAG_CONFIGURATION)
        if configuration_node is not None:
            conf_node_properties = extract_properties_from_configuration_node(
                config_node=configuration_node)
            self.props.action_node_properties.update(conf_node_properties)