Exemple #1
0
def _set_coordinator_properties(coordinator, root, namespace):
  """
  Get coordinator properties from coordinator XML

  Set properties on ``coordinator`` with attributes from XML etree ``root``.
  """
  coordinator.name = root.get('name')
  coordinator.timezone = root.get('timezone')
  coordinator.start = oozie_to_django_datetime(root.get('start'))
  coordinator.end = oozie_to_django_datetime(root.get('end'))
  coordinator.frequency_unit, coordinator.frequency_number = oozie_to_hue_frequency(root.get('frequency'))
Exemple #2
0
def _set_controls(bundle, root, namespace):
  """
  Get controls from bundle XML

  Set properties on ``bundle`` with controls from XML etree ``root``.
  """
  namespaces = {
    'n': namespace
  }
  controls = root.xpath('n:controls', namespaces=namespaces)[0]
  kick_off_time = controls.xpath('n:kick-off-time', namespaces=namespaces)
  if kick_off_time:
    bundle.kick_off_time = oozie_to_django_datetime(kick_off_time[0].text)
Exemple #3
0
def _reconcile_datasets(coordinator, objects, root, namespace):
  """
  Reconcile datasets, datainputs, and dataoutputs.
  datasets and tied to datainputs and dataoutputs.
  Other dataset properties are set from XML tree.

  ``coordinator`` is used for look ups and creating relevant objects.
  ``objects`` should be transformed from XSLTs and loaded via django deserializers.
  ``root`` is the element root of the coordinator (lxml).
  ``namespace`` defines the XML coordinator namespace and schema version.
  """
  namespaces = {
    'n': namespace
  }
  datasets = {}
  datainputs = []
  dataoutputs = []
  coordinator.save()

  for obj in objects:
    obj.object.coordinator = coordinator
    if isinstance(obj.object, Dataset):
      obj.object.pk = None
      obj.object.save()
      dataset_elements = root.xpath('//n:dataset[@name="%s"]' % obj.object.name, namespaces=namespaces)
      for dataset_element in dataset_elements:
        obj.object.start = oozie_to_django_datetime(dataset_element.get('initial-instance'))
      datasets[obj.object.name] = obj.object
      obj.object.save()
    elif isinstance(obj.object, DataInput):
      datainputs.append(obj.object)
    elif isinstance(obj.object, DataOutput):
      dataoutputs.append(obj.object)

  for datainput in datainputs:
    datainput_elements = root.xpath('//n:data-in[@name="%s"]' % datainput.name, namespaces=namespaces)
    for datainput_element in datainput_elements:
      datainput.dataset = datasets[datainput_element.get('dataset')]
    datainput.pk = None
    datainput.save()

  for dataoutput in dataoutputs:
    dataoutput_elements = root.xpath('//n:data-out[@name="%s"]' % dataoutput.name, namespaces=namespaces)
    for dataoutput_element in dataoutput_elements:
      dataoutput.dataset = datasets[dataoutput_element.get('dataset')]
    dataoutput.pk = None
    dataoutput.save()