Exemplo n.º 1
0
    def _create_coordinator_xml(self, coord_configs, config_filter=None,
                                appname='coord'):
        doc = xml.Document()

        # Create the <coordinator-app> base element
        coord = doc.createElement('coordinator-app')
        coord.attributes['name'] = appname
        coord.attributes['start'] = "${start}"
        coord.attributes['end'] = "${end}"
        coord.attributes['frequency'] = "${frequency}"
        coord.attributes['timezone'] = 'UTC'
        coord.attributes['xmlns'] = 'uri:oozie:coordinator:0.2'

        doc.appendChild(coord)

        action = doc.createElement('action')
        workflow = doc.createElement('workflow')
        coord.appendChild(action)
        action.appendChild(workflow)
        x.add_text_element_to_tag(doc, "workflow", 'app-path',
                                  "${workflowAppUri}")
        configuration = doc.createElement('configuration')
        workflow.appendChild(configuration)

        default_configs = []
        if config_filter is not None:
            default_configs = [cfg['name'] for cfg in config_filter]

        for name in sorted(coord_configs):
            if name in default_configs or config_filter is None:
                x.add_property_to_configuration(doc, name, coord_configs[name])

        # Return newly created XML
        return doc.toprettyxml(indent="  ")
Exemplo n.º 2
0
    def _create_coordinator_xml(self, coord_configs, config_filter=None,
                                appname='coord'):
        doc = xml.Document()

        # Create the <coordinator-app> base element
        coord = doc.createElement('coordinator-app')
        coord.attributes['name'] = appname
        coord.attributes['start'] = "${start}"
        coord.attributes['end'] = "${end}"
        coord.attributes['frequency'] = "${frequency}"
        coord.attributes['timezone'] = 'UTC'
        coord.attributes['xmlns'] = 'uri:oozie:coordinator:0.2'

        doc.appendChild(coord)

        action = doc.createElement('action')
        workflow = doc.createElement('workflow')
        coord.appendChild(action)
        action.appendChild(workflow)
        x.add_text_element_to_tag(doc, "workflow", 'app-path',
                                  "${workflowAppUri}")
        configuration = doc.createElement('configuration')
        workflow.appendChild(configuration)

        default_configs = []
        if config_filter is not None:
            default_configs = [cfg['name'] for cfg in config_filter]

        for name in sorted(coord_configs):
            if name in default_configs or config_filter is None:
                x.add_property_to_configuration(doc, name, coord_configs[name])

        # Return newly created XML
        return doc.toprettyxml(indent="  ")
Exemplo n.º 3
0
    def test_add_property_to_configuration(self):
        doc = self.create_default_doc()
        x.add_properties_to_configuration(doc, 'test', {
            '': 'empty1',
            None: 'empty2'
        })
        self.assertEqual(
            doc.toprettyxml(indent="  "), """<?xml version="1.0" ?>
<test>
  <configuration/>
</test>
""")

        test_conf = {'name1': 'value1', 'name2': 'value2'}
        x.add_properties_to_configuration(doc, 'test', test_conf)

        self.assertEqual(
            doc.toprettyxml(indent="  "), """<?xml version="1.0" ?>
<test>
  <configuration>
    <property>
      <name>name2</name>
      <value>value2</value>
    </property>
    <property>
      <name>name1</name>
      <value>value1</value>
    </property>
  </configuration>
</test>
""")
        x.add_property_to_configuration(doc, 'name3', 'value3')
        self.assertEqual(
            doc.toprettyxml(indent="  "), """<?xml version="1.0" ?>
<test>
  <configuration>
    <property>
      <name>name2</name>
      <value>value2</value>
    </property>
    <property>
      <name>name1</name>
      <value>value1</value>
    </property>
    <property>
      <name>name3</name>
      <value>value3</value>
    </property>
  </configuration>
</test>
""")
Exemplo n.º 4
0
    def test_add_property_to_configuration(self):
        doc = self.create_default_doc()
        x.add_properties_to_configuration(doc, 'test', {'': 'empty1',
                                                        None: 'empty2'})
        self.assertEqual(doc.toprettyxml(indent="  "),
                         """<?xml version="1.0" ?>
<test>
  <configuration/>
</test>
""")

        test_conf = {'name1': 'value1', 'name2': 'value2'}
        x.add_properties_to_configuration(doc, 'test', test_conf)

        self.assertEqual(doc.toprettyxml(indent="  "),
                         """<?xml version="1.0" ?>
<test>
  <configuration>
    <property>
      <name>name2</name>
      <value>value2</value>
    </property>
    <property>
      <name>name1</name>
      <value>value1</value>
    </property>
  </configuration>
</test>
""")
        x.add_property_to_configuration(doc, 'name3', 'value3')
        self.assertEqual(doc.toprettyxml(indent="  "),
                         """<?xml version="1.0" ?>
<test>
  <configuration>
    <property>
      <name>name2</name>
      <value>value2</value>
    </property>
    <property>
      <name>name1</name>
      <value>value1</value>
    </property>
    <property>
      <name>name3</name>
      <value>value3</value>
    </property>
  </configuration>
</test>
""")