Exemplo n.º 1
0
def import_workflow(workflow, workflow_definition, schema_version=0.4):
  xslt_definition_fh = open("%(xslt_dir)s/%(schema_version)s/workflow.xslt" % {
    'xslt_dir': DEFINITION_XSLT_DIR.get(),
    'schema_version': schema_version
  })

  # Remove namespace from definition
  workflow_definition = re.sub(r'\s*xmlns=".*?"', '', workflow_definition, count=1)

  # Parse Workflow Definition
  xml = etree.fromstring(workflow_definition)

  # Get XSLT
  xslt = etree.parse(xslt_definition_fh)
  xslt_definition_fh.close()
  transform = etree.XSLT(xslt)

  # Transform XML using XSLT
  root = transform(xml)

  # Resolve workflow dependencies and node types and link dependencies
  _save_nodes(workflow, root)
  _save_links(workflow, xml)

  # Update schema_version
  workflow.schema_version = "uri:oozie:workflow:%s" % schema_version
  workflow.save()
Exemplo n.º 2
0
def import_workflow(workflow, workflow_definition, fs=None):
  """
  Import workflow takes 7 steps:
  1. Perform XSLT.
  2. Verify schema version.
  3. Prepare nodes for importing.
  4. Preprocess nodes before importing.
  5. Save nodes after they've been processed.
  6. Save links after the nodes have been added.
  7. Post process the workflow.

  Most logic is in steps 3, 4, and 6, 7.
  """
  xslt_definition_fh = open("%(xslt_dir)s/workflow.xslt" % {
    'xslt_dir': DEFINITION_XSLT_DIR.get()
  })

  # Parse Workflow Definition
  workflow_definition_root = etree.fromstring(workflow_definition)

  if workflow_definition_root is None:
    raise RuntimeError(_("Could not find any nodes in Workflow definition. Maybe it's malformed?"))

  ns = workflow_definition_root.tag[:-12] # Remove workflow-app from tag in order to get proper namespace prefix
  schema_version = ns and ns[1:-1] or None

  # Ensure namespace exists
  if schema_version not in OOZIE_NAMESPACES:
    raise RuntimeError(_("Tag with namespace %(namespace)s is not valid. Please use one of the following namespaces: %(namespaces)s") % {
      'namespace': workflow_definition_root.tag,
      'namespaces': ', '.join(OOZIE_NAMESPACES)
    })

  # Get XSLT
  xslt = etree.parse(xslt_definition_fh)
  xslt_definition_fh.close()
  transform = etree.XSLT(xslt)

  # Transform XML using XSLT
  transformed_root = transform(workflow_definition_root)

  # Resolve workflow dependencies and node types and link dependencies
  nodes = _prepare_nodes(workflow, transformed_root)
  _preprocess_nodes(workflow, transformed_root, workflow_definition_root, nodes, fs)
  _save_nodes(workflow, nodes)
  _save_links(workflow, workflow_definition_root)
  _postprocess_workflow(workflow)

  # Update schema_version
  workflow.schema_version = schema_version
  workflow.save()
Exemplo n.º 3
0
def import_workflow(workflow, workflow_definition, fs=None):
    xslt_definition_fh = open("%(xslt_dir)s/workflow.xslt" %
                              {'xslt_dir': DEFINITION_XSLT_DIR.get()})

    # Parse Workflow Definition
    workflow_definition_root = etree.fromstring(workflow_definition)

    if workflow_definition_root is None:
        raise RuntimeError(
            _("Could not find any nodes in Workflow definition. Maybe it's malformed?"
              ))

    ns = workflow_definition_root.tag[:
                                      -12]  # Remove workflow-app from tag in order to get proper namespace prefix
    schema_version = ns and ns[1:-1] or None

    # Ensure namespace exists
    if schema_version not in OOZIE_NAMESPACES:
        raise RuntimeError(
            _("Tag with namespace %(namespace)s is not valid. Please use one of the following namespaces: %(namespaces)s"
              ) % {
                  'namespace': workflow_definition_root.tag,
                  'namespaces': ', '.join(OOZIE_NAMESPACES)
              })

    # Get XSLT
    xslt = etree.parse(xslt_definition_fh)
    xslt_definition_fh.close()
    transform = etree.XSLT(xslt)

    # Transform XML using XSLT
    transformed_root = transform(workflow_definition_root)

    # Resolve workflow dependencies and node types and link dependencies
    nodes = _prepare_nodes(workflow, transformed_root)
    _preprocess_nodes(workflow, transformed_root, workflow_definition_root,
                      nodes, fs)
    _save_nodes(workflow, nodes)
    _save_links(workflow, workflow_definition_root)

    # Update schema_version
    workflow.schema_version = schema_version
    workflow.save()
Exemplo n.º 4
0
def import_workflow(workflow, workflow_definition, fs=None):
  xslt_definition_fh = open("%(xslt_dir)s/workflow.xslt" % {
    'xslt_dir': DEFINITION_XSLT_DIR.get()
  })

  # Parse Workflow Definition
  workflow_definition_root = fromstring(workflow_definition)


  if workflow_definition_root is None:
    raise RuntimeError(_("Could not find any nodes in Workflow definition. Maybe it's malformed?"))

  ns = workflow_definition_root.tag[:-12] # Remove workflow-app from tag in order to get proper namespace prefix
  schema_version = ns and ns[1:-1] or None

  # Ensure namespace exists
  if schema_version not in OOZIE_NAMESPACES:
    raise RuntimeError(_("Tag with namespace %(namespace)s is not valid. Please use one of the following namespaces: %(namespaces)s") % {
      'namespace': workflow_definition_root.tag,
      'namespaces': ', '.join(OOZIE_NAMESPACES)
    })

  # Get XSLT
  xslt = parse(xslt_definition_fh)
  xslt_definition_fh.close()
  transform = etree.XSLT(xslt)

  # Transform XML using XSLT
  transformed_root = transform(workflow_definition_root)

  # Resolve workflow dependencies and node types and link dependencies
  nodes = _prepare_nodes(workflow, transformed_root)
  _preprocess_nodes(workflow, transformed_root, workflow_definition_root, nodes, fs)
  _save_nodes(workflow, nodes)
  _save_links(workflow, workflow_definition_root)

  # Update schema_version
  workflow.schema_version = schema_version
  workflow.save()