Пример #1
0
def import_workflow_root(workflow,
                         workflow_definition_root,
                         metadata=None,
                         fs=None):
    try:
        xslt_definition_fh = open(
            "%(xslt_dir)s/workflow.xslt" %
            {'xslt_dir': os.path.join(DEFINITION_XSLT_DIR.get(), 'workflows')})

        tag = etree.QName(workflow_definition_root.tag)
        schema_version = tag.namespace

        # 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
        parser = etree.XMLParser(resolve_entities=False)
        xslt = etree.parse(xslt_definition_fh, parser=parser)
        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)
        _assign_workflow_properties(workflow, workflow_definition_root,
                                    schema_version)
        if metadata:
            _process_metadata(workflow, metadata)

        # Update workflow attributes
        workflow.schema_version = schema_version
        workflow.name = workflow_definition_root.get('name')
        workflow.save()
    except:
        LOG.exception('failed to import workflow root')
        raise
Пример #2
0
def import_workflow_root(workflow, workflow_definition_root, metadata=None, fs=None):
    try:
        xslt_definition_fh = open(
            "%(xslt_dir)s/workflow.xslt" % {"xslt_dir": os.path.join(DEFINITION_XSLT_DIR.get(), "workflows")}
        )

        tag = etree.QName(workflow_definition_root.tag)
        schema_version = tag.namespace

        # 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)
        _assign_workflow_properties(workflow, workflow_definition_root, schema_version)
        if metadata:
            _process_metadata(workflow, metadata)

        # Update workflow attributes
        workflow.schema_version = schema_version
        workflow.name = workflow_definition_root.get("name")
        workflow.save()
    except:
        LOG.exception("failed to import workflow root")

        workflow.delete(skip_trash=True)
        raise