def edit_workflow(request, workflow):
  WorkflowFormSet = inlineformset_factory(Workflow, Node, form=NodeForm, max_num=0, can_order=False, can_delete=False)
  history = History.objects.filter(submitter=request.user, job=workflow).order_by('-submission_date')

  if request.method == 'POST' and Job.objects.can_edit_or_exception(request, workflow):
    try:
      workflow_form = WorkflowForm(request.POST, instance=workflow)
      actions_formset = WorkflowFormSet(request.POST, request.FILES, instance=workflow)

      if 'clone_action' in request.POST: return clone_action(request, action=request.POST['clone_action'])
      if 'delete_action' in request.POST: return delete_action(request, action=request.POST['delete_action'])
      if 'move_up_action' in request.POST: return move_up_action(request, action=request.POST['move_up_action'])
      if 'move_down_action' in request.POST: return move_down_action(request, action=request.POST['move_down_action'])

      if workflow_form.is_valid() and actions_formset.is_valid():
        workflow = workflow_form.save()
        actions_formset.save()

        if workflow.has_cycle():
          raise PopupException(_('Sorry, this operation is not creating a cycle which would break the workflow.'))

        Workflow.objects.check_workspace(workflow, request.fs)

        request.info(_("Workflow saved!"))
        return redirect(reverse('oozie:edit_workflow', kwargs={'workflow': workflow.id}))
    except Exception, e:
      request.error(_('Sorry, this operation is not supported: %(error)s') % {'error': e})
Example #2
0
def workflow_save(request, workflow):
    if request.method != 'POST':
        raise StructuredException(code="METHOD_NOT_ALLOWED_ERROR",
                                  message=_('Must be POST request.'),
                                  error_code=405)

    json_workflow = format_dict_field_values(
        json.loads(request.POST.get('workflow')))
    json_workflow.setdefault('schema_version', workflow.schema_version)

    form = WorkflowForm(data=json_workflow)

    if not form.is_valid():
        raise StructuredException(code="INVALID_REQUEST_ERROR",
                                  message=_('Error saving workflow'),
                                  data={'errors': form.errors},
                                  error_code=400)

    json_nodes = json_workflow['nodes']
    id_map = {}
    errors = {}

    if not _validate_nodes_json(json_nodes, errors, request.user, workflow):
        raise StructuredException(code="INVALID_REQUEST_ERROR",
                                  message=_('Error saving workflow'),
                                  data={'errors': errors},
                                  error_code=400)

    workflow = _update_workflow_json(json_workflow)
    nodes = _update_workflow_nodes_json(workflow, json_nodes, id_map,
                                        request.user)

    # Update links
    index = 0
    for json_node in json_nodes:
        child_links = json_node['child_links']
        Link.objects.filter(parent=nodes[index]).delete()

        for child_link in child_links:
            link = Link()
            link.id = getattr(child_link, 'id', None)
            link.name = child_link['name']

            id = str(child_link['parent'])
            link.parent = Node.objects.get(id=id_map[id])

            id = str(child_link['child'])
            link.child = Node.objects.get(id=id_map[id])

            link.comment = child_link.get('comment', '')

            link.save()

        index += 1

    # Make sure workflow HDFS permissions are correct
    Workflow.objects.check_workspace(workflow, request.fs)

    return _workflow(request, workflow=workflow)
Example #3
0
def workflow_save(request, workflow):
    if request.method != "POST":
        raise StructuredException(code="METHOD_NOT_ALLOWED_ERROR", message=_("Must be POST request."), error_code=405)

    json_workflow = format_dict_field_values(json.loads(request.POST.get("workflow")))
    json_workflow.setdefault("schema_version", workflow.schema_version)

    form = WorkflowForm(data=json_workflow)

    if not form.is_valid():
        raise StructuredException(
            code="INVALID_REQUEST_ERROR",
            message=_("Error saving workflow"),
            data={"errors": form.errors},
            error_code=400,
        )

    json_nodes = json_workflow["nodes"]
    id_map = {}
    errors = {}

    if not _validate_nodes_json(json_nodes, errors, request.user, workflow):
        raise StructuredException(
            code="INVALID_REQUEST_ERROR", message=_("Error saving workflow"), data={"errors": errors}, error_code=400
        )

    workflow = _update_workflow_json(json_workflow)
    nodes = _update_workflow_nodes_json(workflow, json_nodes, id_map, request.user)

    # Update links
    index = 0
    for json_node in json_nodes:
        child_links = json_node["child_links"]
        Link.objects.filter(parent=nodes[index]).delete()

        for child_link in child_links:
            link = Link()
            link.id = getattr(child_link, "id", None)
            link.name = child_link["name"]

            id = str(child_link["parent"])
            link.parent = Node.objects.get(id=id_map[id])

            id = str(child_link["child"])
            link.child = Node.objects.get(id=id_map[id])

            link.comment = child_link.get("comment", "")

            link.save()

        index += 1

    # Make sure workflow HDFS permissions are correct
    Workflow.objects.check_workspace(workflow, request.fs)

    return _workflow(request, workflow=workflow)
Example #4
0
def edit_workflow(request, workflow):
    WorkflowFormSet = inlineformset_factory(Workflow,
                                            Node,
                                            form=NodeForm,
                                            max_num=0,
                                            can_order=False,
                                            can_delete=False)
    history = History.objects.filter(submitter=request.user,
                                     job=workflow).order_by('-submission_date')

    if request.method == 'POST' and Job.objects.can_edit_or_exception(
            request, workflow):
        try:
            workflow_form = WorkflowForm(request.POST, instance=workflow)
            actions_formset = WorkflowFormSet(request.POST,
                                              request.FILES,
                                              instance=workflow)

            if 'clone_action' in request.POST:
                return clone_action(request,
                                    action=request.POST['clone_action'])
            if 'delete_action' in request.POST:
                return delete_action(request,
                                     action=request.POST['delete_action'])
            if 'move_up_action' in request.POST:
                return move_up_action(request,
                                      action=request.POST['move_up_action'])
            if 'move_down_action' in request.POST:
                return move_down_action(
                    request, action=request.POST['move_down_action'])

            if workflow_form.is_valid() and actions_formset.is_valid():
                workflow = workflow_form.save()
                actions_formset.save()

                if workflow.has_cycle():
                    raise PopupException(
                        _('Sorry, this operation is not creating a cycle which would break the workflow.'
                          ))

                Workflow.objects.check_workspace(workflow, request.fs)

                request.info(_("Workflow saved!"))
                return redirect(
                    reverse('oozie:edit_workflow',
                            kwargs={'workflow': workflow.id}))
        except Exception, e:
            request.error(
                _('Sorry, this operation is not supported: %(error)s') %
                {'error': e})
Example #5
0
File: api.py Project: bugcy013/hue
def workflow_save(request, workflow):
  if request.method != 'POST':
    raise StructuredException(code="METHOD_NOT_ALLOWED_ERROR", message=_('Must be POST request.'), error_code=405)

  json_workflow = format_dict_field_values(json.loads(str(request.POST.get('workflow'))))
  json_workflow.setdefault('schema_version', workflow.schema_version)

  form = WorkflowForm(data=json_workflow)

  if not form.is_valid():
    raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving workflow'), data={'errors': form.errors}, error_code=400)

  json_nodes = json_workflow['nodes']
  id_map = {}
  errors = {}

  if not _validate_nodes_json(json_nodes, errors, request.user, workflow):
    raise StructuredException(code="INVALID_REQUEST_ERROR", message=_('Error saving workflow'), data={'errors': errors}, error_code=400)

  workflow = _update_workflow_json(json_workflow)
  nodes = _update_workflow_nodes_json(workflow, json_nodes, id_map, request.user)

  # Update links
  index = 0
  for json_node in json_nodes:
    child_links = json_node['child_links']
    Link.objects.filter(parent=nodes[index]).delete()

    for child_link in child_links:
      link = Link()
      link.id = getattr(child_link, 'id', None)
      link.name = child_link['name']

      id = str(child_link['parent'])
      link.parent = Node.objects.get(id=id_map[id])

      id = str(child_link['child'])
      link.child = Node.objects.get(id=id_map[id])

      link.comment = child_link.get('comment', '')

      link.save()

    index += 1

  # Make sure workflow HDFS permissions are correct
  Workflow.objects.check_workspace(workflow, request.fs)

  return _workflow(request, workflow=workflow)
Example #6
0
def edit_workflow(request, workflow):
    history = History.objects.filter(submitter=request.user,
                                     job=workflow).order_by('-submission_date')
    workflow_form = WorkflowForm(instance=workflow)
    user_can_access_job = workflow.is_accessible(request.user)
    user_can_edit_job = workflow.is_editable(request.user)

    return render(
        'editor/edit_workflow.mako', request, {
            'workflow_form':
            workflow_form,
            'workflow':
            workflow,
            'history':
            history,
            'user_can_access_job':
            user_can_access_job,
            'user_can_edit_job':
            user_can_edit_job,
            'job_properties':
            extract_field_data(workflow_form['job_properties']),
            'link_form':
            LinkForm(),
            'default_link_form':
            DefaultLinkForm(action=workflow.start),
            'node_form':
            NodeForm(),
            'action_forms':
            [(node_type, design_form_by_type(node_type, request.user,
                                             workflow)())
             for node_type in ACTION_TYPES.iterkeys()]
        })
Example #7
0
def create_workflow(request):
    workflow = Workflow.objects.new_workflow(request.user)

    if request.method == "POST":
        workflow_form = WorkflowForm(request.POST, instance=workflow)

        if workflow_form.is_valid():
            wf = workflow_form.save()
            Workflow.objects.initialize(wf, request.fs)
            return redirect(reverse("oozie:edit_workflow", kwargs={"workflow": workflow.id}))
        else:
            request.error(_("Errors on the form: %s") % workflow_form.errors)
    else:
        workflow_form = WorkflowForm(instance=workflow)

    return render("editor/create_workflow.mako", request, {"workflow_form": workflow_form, "workflow": workflow})
Example #8
0
def create_workflow(request):
  workflow = Workflow.objects.new_workflow(request.user)

  if request.method == 'POST':
    workflow_form = WorkflowForm(request.POST, instance=workflow)

    if workflow_form.is_valid():
      wf = workflow_form.save()
      wf.managed = True
      Workflow.objects.initialize(wf, request.fs)
      return redirect(reverse('oozie:edit_workflow', kwargs={'workflow': workflow.id}))
  else:
    workflow_form = WorkflowForm(instance=workflow)

  return render('editor/create_workflow.mako', request, {
    'workflow_form': workflow_form,
    'workflow': workflow,
  })
Example #9
0
def edit_workflow(request, workflow):
    history = History.objects.filter(submitter=request.user,
                                     job=workflow).order_by('-submission_date')
    workflow_form = WorkflowForm(instance=workflow)
    user_can_access_job = workflow.can_read(request.user)
    user_can_edit_job = workflow.is_editable(request.user)
    oozie_api = get_oozie(request.user)
    credentials = Credentials()
    credentials.fetch(oozie_api)

    return render(
        'editor/edit_workflow.mako', request, {
            'oozie_api':
            oozie_api,
            'workflow_form':
            workflow_form,
            'workflow':
            workflow,
            'history':
            history,
            'user_can_access_job':
            user_can_access_job,
            'user_can_edit_job':
            user_can_edit_job,
            'job_properties':
            extract_field_data(workflow_form['job_properties']),
            'link_form':
            LinkForm(),
            'default_link_form':
            DefaultLinkForm(action=workflow.start),
            'node_form':
            NodeForm(),
            'action_forms':
            [(node_type, design_form_by_type(node_type, request.user,
                                             workflow)())
             for node_type in ACTION_TYPES.keys()],
            'credentials':
            json.dumps(list(credentials.credentials.keys()))
        })
Example #10
0
def create_workflow(request):
  workflow = Workflow.objects.new_workflow(request.user)

  if request.method == 'POST':
    workflow_form = WorkflowForm(request.POST, instance=workflow)

    if workflow_form.is_valid():
      wf = workflow_form.save()
      wf.managed = True
      Workflow.objects.initialize(wf, request.fs)
      return redirect(reverse('oozie:edit_workflow', kwargs={'workflow': workflow.id}))
  else:
    workflow_form = WorkflowForm(instance=workflow)

  return render('editor/create_workflow.mako', request, {
    'workflow_form': workflow_form,
    'workflow': workflow,
  })
Example #11
0
                    raise PopupException(
                        _('Sorry, this operation is not creating a cycle which would break the workflow.'
                          ))

                Workflow.objects.check_workspace(workflow, request.fs)

                request.info(_("Workflow saved!"))
                return redirect(
                    reverse('oozie:edit_workflow',
                            kwargs={'workflow': workflow.id}))
        except Exception, e:
            request.error(
                _('Sorry, this operation is not supported: %(error)s') %
                {'error': e})

    workflow_form = WorkflowForm(instance=workflow)
    actions_formset = WorkflowFormSet(instance=workflow)

    graph_options = {}
    user_can_edit_job = workflow.is_editable(request.user)
    if not user_can_edit_job:
        graph_options = {
            'template': 'editor/gen/workflow-graph-readonly.xml.mako'
        }

    graph = workflow.gen_graph(actions_formset.forms, **graph_options)

    return render(
        'editor/edit_workflow.mako', request, {
            'workflow_form': workflow_form,
            'workflow': workflow,