Esempio n. 1
0
def list_oozie_workflow(request, job_id, coordinator_job_id=None):
  oozie_workflow = check_job_access_permission(request, job_id)

  oozie_coordinator = None
  if coordinator_job_id is not None:
    oozie_coordinator = check_job_access_permission(request, coordinator_job_id)

  history = History.cross_reference_submission_history(request.user, job_id, coordinator_job_id)

  hue_coord = history and history.get_coordinator() or History.get_coordinator_from_config(oozie_workflow.conf_dict)
  hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or History.get_workflow_from_config(oozie_workflow.conf_dict)

  if hue_coord: Job.objects.is_accessible_or_exception(request, hue_coord.workflow.id)
  if hue_workflow: Job.objects.is_accessible_or_exception(request, hue_workflow.id)

  parameters = oozie_workflow.conf_dict.copy()

  if hue_workflow:
    workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
  else:
    workflow_graph = Workflow.gen_status_graph_from_xml(request.user, oozie_workflow)

  return render('dashboard/list_oozie_workflow.mako', request, {
    'history': history,
    'oozie_workflow': oozie_workflow,
    'oozie_coordinator': oozie_coordinator,
    'hue_workflow': hue_workflow,
    'hue_coord': hue_coord,
    'parameters': parameters,
    'has_job_edition_permission': has_job_edition_permission,
    'workflow_graph': workflow_graph
  })
Esempio n. 2
0
    def _import_workflows(self, directory, managed=True):

        for example_directory_name in os.listdir(directory):
            if os.path.isdir(os.path.join(directory, example_directory_name)):
                with open(
                        os.path.join(directory, example_directory_name,
                                     'workflow.zip')) as fp:
                    workflow_xml, metadata = Workflow.decompress(fp)

                workflow_root = etree.fromstring(workflow_xml)

                try:
                    Workflow.objects.get(name=workflow_root.get('name'),
                                         managed=managed)
                except Workflow.DoesNotExist:
                    LOG.info(
                        _("Installing workflow %s") %
                        workflow_root.get('name'))
                    LOG.debug("Workflow definition:\n%s" % workflow_xml)
                    workflow = Workflow.objects.new_workflow(owner=self.user)
                    workflow.is_shared = True
                    workflow.managed = managed
                    workflow.name = workflow_root.get('name')
                    workflow.save()
                    Workflow.objects.initialize(workflow)
                    import_workflow_root(
                        workflow=workflow,
                        workflow_definition_root=workflow_root,
                        metadata=metadata,
                        fs=self.fs)
                    workflow.doc.all().delete(
                    )  # Delete doc as it messes up the example sharing
Esempio n. 3
0
def list_oozie_workflow(request, job_id, coordinator_job_id=None, bundle_job_id=None):
  oozie_workflow = check_job_access_permission(request, job_id)

  oozie_coordinator = None
  if coordinator_job_id is not None:
    oozie_coordinator = check_job_access_permission(request, coordinator_job_id)

  oozie_bundle = None
  if bundle_job_id is not None:
    oozie_bundle = check_job_access_permission(request, bundle_job_id)

  if oozie_coordinator is not None:
    setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
  if oozie_bundle is not None:
    setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

  history = History.cross_reference_submission_history(request.user, job_id, coordinator_job_id)

  hue_coord = history and history.get_coordinator() or History.get_coordinator_from_config(oozie_workflow.conf_dict)
  hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or History.get_workflow_from_config(oozie_workflow.conf_dict)

  if hue_coord: Job.objects.is_accessible_or_exception(request, hue_coord.workflow.id)
  if hue_workflow: Job.objects.is_accessible_or_exception(request, hue_workflow.id)

  parameters = oozie_workflow.conf_dict.copy()
  for action in oozie_workflow.actions:
    action.oozie_coordinator = oozie_coordinator
    action.oozie_bundle = oozie_bundle

  if hue_workflow:
    workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
    full_node_list = hue_workflow.node_list
  else:
    workflow_graph, full_node_list = Workflow.gen_status_graph_from_xml(request.user, oozie_workflow)

  if request.GET.get('format') == 'json':
    return_obj = {
      'id': oozie_workflow.id,
      'status':  oozie_workflow.status,
      'progress': oozie_workflow.get_progress(full_node_list),
      'graph': workflow_graph,
      'log': oozie_workflow.log,
      'actions': massaged_workflow_actions_for_json(oozie_workflow.get_working_actions(), oozie_coordinator, oozie_bundle)
    }
    return HttpResponse(encode_json_for_js(return_obj), mimetype="application/json")

  return render('dashboard/list_oozie_workflow.mako', request, {
    'history': history,
    'oozie_workflow': oozie_workflow,
    'oozie_coordinator': oozie_coordinator,
    'oozie_bundle': oozie_bundle,
    'hue_workflow': hue_workflow,
    'hue_coord': hue_coord,
    'parameters': parameters,
    'has_job_edition_permission': has_job_edition_permission,
    'workflow_graph': workflow_graph
  })
Esempio n. 4
0
def list_oozie_workflow(request, job_id, coordinator_job_id=None, bundle_job_id=None):
  oozie_workflow = check_job_access_permission(request, job_id)

  oozie_coordinator = None
  if coordinator_job_id is not None:
    oozie_coordinator = check_job_access_permission(request, coordinator_job_id)

  oozie_bundle = None
  if bundle_job_id is not None:
    oozie_bundle = check_job_access_permission(request, bundle_job_id)

  if oozie_coordinator is not None:
    setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
  if oozie_bundle is not None:
    setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

  history = History.cross_reference_submission_history(request.user, job_id, coordinator_job_id)

  hue_coord = history and history.get_coordinator() or History.get_coordinator_from_config(oozie_workflow.conf_dict)
  hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or History.get_workflow_from_config(oozie_workflow.conf_dict)

  if hue_coord: Job.objects.is_accessible_or_exception(request, hue_coord.workflow.id)
  if hue_workflow: Job.objects.is_accessible_or_exception(request, hue_workflow.id)

  parameters = oozie_workflow.conf_dict.copy()
  for action in oozie_workflow.actions:
    action.oozie_coordinator = oozie_coordinator
    action.oozie_bundle = oozie_bundle

  if hue_workflow:
    workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
    full_node_list = hue_workflow.node_list
  else:
    workflow_graph, full_node_list = Workflow.gen_status_graph_from_xml(request.user, oozie_workflow)

  if request.GET.get('format') == 'json':
    return_obj = {
      'id': oozie_workflow.id,
      'status':  oozie_workflow.status,
      'progress': oozie_workflow.get_progress(full_node_list),
      'graph': workflow_graph,
      'log': oozie_workflow.log,
      'actions': massaged_workflow_actions_for_json(oozie_workflow.get_working_actions(), oozie_coordinator, oozie_bundle)
    }
    return HttpResponse(encode_json_for_js(return_obj), mimetype="application/json")

  return render('dashboard/list_oozie_workflow.mako', request, {
    'history': history,
    'oozie_workflow': oozie_workflow,
    'oozie_coordinator': oozie_coordinator,
    'oozie_bundle': oozie_bundle,
    'hue_workflow': hue_workflow,
    'hue_coord': hue_coord,
    'parameters': parameters,
    'has_job_edition_permission': has_job_edition_permission,
    'workflow_graph': workflow_graph
  })
Esempio n. 5
0
 def _import_workflows(self, directory, managed=True):
   for example_directory_name in os.listdir(directory):
     if os.path.isdir(os.path.join(directory, example_directory_name)):
       with open(os.path.join(directory, example_directory_name, 'workflow.zip')) as fp:
         workflow_xml, metadata = Workflow.decompress(fp)
       workflow_root = etree.fromstring(workflow_xml)
       try:
         Workflow.objects.get(name=workflow_root.get('name'), managed=managed)
       except Workflow.DoesNotExist:
         LOG.info(_("Installing workflow %s") % workflow_root.get('name'))
         LOG.debug("Workflow definition:\n%s" % workflow_xml)
         workflow = Workflow.objects.new_workflow(owner=self.user)
         workflow.is_shared = True
         workflow.managed = managed
         workflow.name = workflow_root.get('name')
         workflow.save()
         Workflow.objects.initialize(workflow)
         import_workflow_root(workflow=workflow, workflow_definition_root=workflow_root, metadata=metadata, fs=self.fs)
         workflow.doc.all().delete() # Delete doc as it messes up the example sharing
Esempio n. 6
0
    def _is_workflow(self):
        from oozie.models import Workflow

        return Workflow.get_application_path_key() in self.properties
Esempio n. 7
0
def list_oozie_workflow(request, job_id):
  oozie_workflow = check_job_access_permission(request, job_id)

  oozie_coordinator = None
  if request.GET.get('coordinator_job_id'):
    oozie_coordinator = check_job_access_permission(request, request.GET.get('coordinator_job_id'))

  oozie_bundle = None
  if request.GET.get('bundle_job_id'):
    oozie_bundle = check_job_access_permission(request, request.GET.get('bundle_job_id'))

  if oozie_coordinator is not None:
    setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
  if oozie_bundle is not None:
    setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

  oozie_parent = oozie_workflow.get_parent_job_id()
  if oozie_parent:
    oozie_parent = check_job_access_permission(request, oozie_parent)

  workflow_data = None
  credentials = None
  doc = None
  hue_workflow = None
  workflow_graph = 'MISSING'  # default to prevent loading the graph tab for deleted workflows
  full_node_list = None

  if ENABLE_V2.get():
    try:
      # To update with the new History document model
      hue_coord = get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
      hue_workflow = (hue_coord and hue_coord.workflow) or get_history().get_workflow_from_config(oozie_workflow.conf_dict)

      if hue_coord and hue_coord.workflow: hue_coord.workflow.document.doc.get().can_read_or_exception(request.user)
      if hue_workflow: hue_workflow.document.doc.get().can_read_or_exception(request.user)

      if hue_workflow:
        workflow_graph = ''
        full_node_list = hue_workflow.nodes
        workflow_id = hue_workflow.id
        wid = {
          'id': workflow_id
        }
        doc = Document2.objects.get(type='oozie-workflow2', **wid)
        new_workflow = get_workflow()(document=doc)
        workflow_data = new_workflow.get_data()
        credentials = Credentials()
      else:
        # For workflows submitted from CLI or deleted in the editor
        # Until better parsing in https://issues.cloudera.org/browse/HUE-2659
        workflow_graph, full_node_list = OldWorkflow.gen_status_graph_from_xml(request.user, oozie_workflow)
    except:
      LOG.exception("Error generating full page for running workflow %s" % job_id)
  else:
    history = get_history().cross_reference_submission_history(request.user, job_id)

    hue_coord = history and history.get_coordinator() or get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
    hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or get_history().get_workflow_from_config(oozie_workflow.conf_dict)

    if hue_coord and hue_coord.workflow: Job.objects.can_read_or_exception(request, hue_coord.workflow.id)
    if hue_workflow: Job.objects.can_read_or_exception(request, hue_workflow.id)
    
    if hue_workflow:
      workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
      full_node_list = hue_workflow.node_list
    else:
      workflow_graph, full_node_list = get_workflow().gen_status_graph_from_xml(request.user, oozie_workflow)

  parameters = oozie_workflow.conf_dict.copy()

  for action in oozie_workflow.actions:
    action.oozie_coordinator = oozie_coordinator
    action.oozie_bundle = oozie_bundle


  if request.GET.get('format') == 'json':
    return_obj = {
      'id': oozie_workflow.id,
      'status':  oozie_workflow.status,
      'progress': oozie_workflow.get_progress(full_node_list),
      'graph': workflow_graph,
      'actions': massaged_workflow_actions_for_json(oozie_workflow.get_working_actions(), oozie_coordinator, oozie_bundle)
    }
    return JsonResponse(return_obj, encoder=JSONEncoderForHTML)

  oozie_slas = []
  if oozie_workflow.has_sla:
    oozie_api = get_oozie(request.user, api_version="v2")
    params = {
      'id': oozie_workflow.id,
      'parent_id': oozie_workflow.id
    }
    oozie_slas = oozie_api.get_oozie_slas(**params)

  return render('dashboard/list_oozie_workflow.mako', request, {
    'oozie_workflow': oozie_workflow,
    'oozie_coordinator': oozie_coordinator,
    'oozie_bundle': oozie_bundle,
    'oozie_parent': oozie_parent,
    'oozie_slas': oozie_slas,
    'hue_workflow': hue_workflow,
    'hue_coord': hue_coord,
    'parameters': parameters,
    'has_job_edition_permission': has_job_edition_permission,
    'workflow_graph': workflow_graph,
    'layout_json': json.dumps(workflow_data['layout'], cls=JSONEncoderForHTML) if workflow_data else '',
    'workflow_json': json.dumps(workflow_data['workflow'], cls=JSONEncoderForHTML) if workflow_data else '',
    'credentials_json': json.dumps(credentials.credentials.keys(), cls=JSONEncoderForHTML) if credentials else '',
    'workflow_properties_json': json.dumps(WORKFLOW_NODE_PROPERTIES, cls=JSONEncoderForHTML),
    'doc1_id': doc.doc.get().id if doc else -1,
    'subworkflows_json': json.dumps(_get_workflows(request.user), cls=JSONEncoderForHTML),
    'can_edit_json': json.dumps(doc is None or doc.doc.get().is_editable(request.user))
  })
Esempio n. 8
0
 def _is_workflow(self):
     from oozie.models import Workflow
     return Workflow.get_application_path_key() in self.properties
Esempio n. 9
0
def list_oozie_workflow(request, job_id):
    oozie_workflow = check_job_access_permission(request, job_id)

    oozie_coordinator = None
    if request.GET.get('coordinator_job_id'):
        oozie_coordinator = check_job_access_permission(
            request, request.GET.get('coordinator_job_id'))

    oozie_bundle = None
    if request.GET.get('bundle_job_id'):
        oozie_bundle = check_job_access_permission(
            request, request.GET.get('bundle_job_id'))

    if oozie_coordinator is not None:
        setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
    if oozie_bundle is not None:
        setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

    oozie_parent = oozie_workflow.get_parent_job_id()
    if oozie_parent:
        oozie_parent = check_job_access_permission(request, oozie_parent)

    workflow_data = None
    credentials = None
    doc = None
    hue_workflow = None
    workflow_graph = 'MISSING'  # default to prevent loading the graph tab for deleted workflows
    full_node_list = None

    if ENABLE_V2.get():
        try:
            # To update with the new History document model
            hue_coord = get_history().get_coordinator_from_config(
                oozie_workflow.conf_dict)
            hue_workflow = (hue_coord and hue_coord.workflow
                            ) or get_history().get_workflow_from_config(
                                oozie_workflow.conf_dict)

            if hue_coord and hue_coord.workflow:
                hue_coord.workflow.document.doc.get().can_read_or_exception(
                    request.user)
            if hue_workflow:
                hue_workflow.document.doc.get().can_read_or_exception(
                    request.user)

            if hue_workflow:
                workflow_graph = ''
                full_node_list = hue_workflow.nodes
                workflow_id = hue_workflow.id
                wid = {'id': workflow_id}
                doc = Document2.objects.get(type='oozie-workflow2', **wid)
                new_workflow = get_workflow()(document=doc)
                workflow_data = new_workflow.get_data()
                credentials = Credentials()
            else:
                # For workflows submitted from CLI or deleted in the editor
                # Until better parsing in https://issues.cloudera.org/browse/HUE-2659
                workflow_graph, full_node_list = OldWorkflow.gen_status_graph_from_xml(
                    request.user, oozie_workflow)
        except:
            LOG.exception(
                "Error generating full page for running workflow %s" % job_id)
    else:
        history = get_history().cross_reference_submission_history(
            request.user, job_id)

        hue_coord = history and history.get_coordinator() or get_history(
        ).get_coordinator_from_config(oozie_workflow.conf_dict)
        hue_workflow = (hue_coord and hue_coord.workflow) or (
            history and
            history.get_workflow()) or get_history().get_workflow_from_config(
                oozie_workflow.conf_dict)

        if hue_coord and hue_coord.workflow:
            Job.objects.can_read_or_exception(request, hue_coord.workflow.id)
        if hue_workflow:
            Job.objects.can_read_or_exception(request, hue_workflow.id)

        if hue_workflow:
            workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
            full_node_list = hue_workflow.node_list
        else:
            workflow_graph, full_node_list = get_workflow(
            ).gen_status_graph_from_xml(request.user, oozie_workflow)

    parameters = oozie_workflow.conf_dict.copy()

    for action in oozie_workflow.actions:
        action.oozie_coordinator = oozie_coordinator
        action.oozie_bundle = oozie_bundle

    if request.GET.get('format') == 'json':
        return_obj = {
            'id':
            oozie_workflow.id,
            'status':
            oozie_workflow.status,
            'progress':
            oozie_workflow.get_progress(full_node_list),
            'graph':
            workflow_graph,
            'actions':
            massaged_workflow_actions_for_json(
                oozie_workflow.get_working_actions(), oozie_coordinator,
                oozie_bundle)
        }
        return JsonResponse(return_obj, encoder=JSONEncoderForHTML)

    oozie_slas = []
    if oozie_workflow.has_sla:
        oozie_api = get_oozie(request.user, api_version="v2")
        params = {'id': oozie_workflow.id, 'parent_id': oozie_workflow.id}
        oozie_slas = oozie_api.get_oozie_slas(**params)

    return render(
        'dashboard/list_oozie_workflow.mako', request, {
            'oozie_workflow':
            oozie_workflow,
            'oozie_coordinator':
            oozie_coordinator,
            'oozie_bundle':
            oozie_bundle,
            'oozie_parent':
            oozie_parent,
            'oozie_slas':
            oozie_slas,
            'hue_workflow':
            hue_workflow,
            'hue_coord':
            hue_coord,
            'parameters':
            parameters,
            'has_job_edition_permission':
            has_job_edition_permission,
            'workflow_graph':
            workflow_graph,
            'layout_json':
            json.dumps(workflow_data['layout'], cls=JSONEncoderForHTML)
            if workflow_data else '',
            'workflow_json':
            json.dumps(workflow_data['workflow'], cls=JSONEncoderForHTML)
            if workflow_data else '',
            'credentials_json':
            json.dumps(credentials.credentials.keys(), cls=JSONEncoderForHTML)
            if credentials else '',
            'workflow_properties_json':
            json.dumps(WORKFLOW_NODE_PROPERTIES, cls=JSONEncoderForHTML),
            'doc1_id':
            doc.doc.get().id if doc else -1,
            'subworkflows_json':
            json.dumps(_get_workflows(request.user), cls=JSONEncoderForHTML),
            'can_edit_json':
            json.dumps(doc is None or doc.doc.get().is_editable(request.user))
        })
Esempio n. 10
0
def list_oozie_workflow(request, job_id):
    oozie_workflow = check_job_access_permission(request, job_id)

    oozie_coordinator = None
    if request.GET.get('coordinator_job_id'):
        oozie_coordinator = check_job_access_permission(
            request, request.GET.get('coordinator_job_id'))

    oozie_bundle = None
    if request.GET.get('bundle_job_id'):
        oozie_bundle = check_job_access_permission(
            request, request.GET.get('bundle_job_id'))

    if oozie_coordinator is not None:
        setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
    if oozie_bundle is not None:
        setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

    if ENABLE_V2.get():
        # To update with the new History document model
        hue_coord = get_history().get_coordinator_from_config(
            oozie_workflow.conf_dict)
        hue_workflow = (hue_coord and hue_coord.workflow
                        ) or get_history().get_workflow_from_config(
                            oozie_workflow.conf_dict)

        if hue_coord and hue_coord.workflow:
            hue_coord.workflow.document.doc.get().can_read_or_exception(
                request.user)
        if hue_workflow:
            hue_workflow.document.doc.get().can_read_or_exception(request.user)

        if hue_workflow:
            workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
            full_node_list = hue_workflow.nodes
        else:
            workflow_graph, full_node_list = '', None
    else:
        history = get_history().cross_reference_submission_history(
            request.user, job_id)

        hue_coord = history and history.get_coordinator() or get_history(
        ).get_coordinator_from_config(oozie_workflow.conf_dict)
        hue_workflow = (hue_coord and hue_coord.workflow) or (
            history and
            history.get_workflow()) or get_history().get_workflow_from_config(
                oozie_workflow.conf_dict)

        if hue_coord and hue_coord.workflow:
            Job.objects.can_read_or_exception(request, hue_coord.workflow.id)
        if hue_workflow:
            Job.objects.can_read_or_exception(request, hue_workflow.id)

        if hue_workflow:
            workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
            full_node_list = hue_workflow.node_list
        else:
            workflow_graph, full_node_list = Workflow.gen_status_graph_from_xml(
                request.user, oozie_workflow)

    parameters = oozie_workflow.conf_dict.copy()

    for action in oozie_workflow.actions:
        action.oozie_coordinator = oozie_coordinator
        action.oozie_bundle = oozie_bundle

    if request.GET.get('format') == 'json':
        return_obj = {
            'id':
            oozie_workflow.id,
            'status':
            oozie_workflow.status,
            'progress':
            oozie_workflow.get_progress(full_node_list),
            'graph':
            workflow_graph,
            'actions':
            massaged_workflow_actions_for_json(
                oozie_workflow.get_working_actions(), oozie_coordinator,
                oozie_bundle)
        }
        return JsonResponse(return_obj, encoder=JSONEncoderForHTML)

    oozie_slas = []
    if oozie_workflow.has_sla:
        oozie_api = get_oozie(request.user, api_version="v2")
        params = {'id': oozie_workflow.id, 'parent_id': oozie_workflow.id}
        oozie_slas = oozie_api.get_oozie_slas(**params)

    return render(
        'dashboard/list_oozie_workflow.mako', request, {
            'oozie_workflow': oozie_workflow,
            'oozie_coordinator': oozie_coordinator,
            'oozie_bundle': oozie_bundle,
            'oozie_slas': oozie_slas,
            'hue_workflow': hue_workflow,
            'hue_coord': hue_coord,
            'parameters': parameters,
            'has_job_edition_permission': has_job_edition_permission,
            'workflow_graph': workflow_graph
        })
Esempio n. 11
0
def list_oozie_workflow(request, job_id):
  oozie_workflow = check_job_access_permission(request, job_id)

  oozie_coordinator = None
  if request.GET.get('coordinator_job_id'):
    oozie_coordinator = check_job_access_permission(request, request.GET.get('coordinator_job_id'))

  oozie_bundle = None
  if request.GET.get('bundle_job_id'):
    oozie_bundle = check_job_access_permission(request, request.GET.get('bundle_job_id'))

  if oozie_coordinator is not None:
    setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
  if oozie_bundle is not None:
    setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)

  if ENABLE_V2.get():
    # To update with the new History document model
    hue_coord = get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
    hue_workflow = (hue_coord and hue_coord.workflow) or get_history().get_workflow_from_config(oozie_workflow.conf_dict)
  
    if hue_coord and hue_coord.workflow: hue_coord.workflow.document.doc.get().can_read_or_exception(request.user)
    if hue_workflow: hue_workflow.document.doc.get().can_read_or_exception(request.user)
    
    if hue_workflow:
      workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
      full_node_list = hue_workflow.nodes
    else:
      workflow_graph, full_node_list = '', None    
  else:
    history = get_history().cross_reference_submission_history(request.user, job_id)

    hue_coord = history and history.get_coordinator() or get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
    hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or get_history().get_workflow_from_config(oozie_workflow.conf_dict)

    if hue_coord and hue_coord.workflow: Job.objects.can_read_or_exception(request, hue_coord.workflow.id)
    if hue_workflow: Job.objects.can_read_or_exception(request, hue_workflow.id)
    
    if hue_workflow:
      workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
      full_node_list = hue_workflow.node_list
    else:
      workflow_graph, full_node_list = Workflow.gen_status_graph_from_xml(request.user, oozie_workflow)

  parameters = oozie_workflow.conf_dict.copy()

  for action in oozie_workflow.actions:
    action.oozie_coordinator = oozie_coordinator
    action.oozie_bundle = oozie_bundle


  if request.GET.get('format') == 'json':
    return_obj = {
      'id': oozie_workflow.id,
      'status':  oozie_workflow.status,
      'progress': oozie_workflow.get_progress(full_node_list),
      'graph': workflow_graph,
      'actions': massaged_workflow_actions_for_json(oozie_workflow.get_working_actions(), oozie_coordinator, oozie_bundle)
    }
    return JsonResponse(return_obj, encoder=JSONEncoderForHTML)

  oozie_slas = []
  if oozie_workflow.has_sla:
    oozie_api = get_oozie(request.user, api_version="v2")
    params = {
      'id': oozie_workflow.id,
      'parent_id': oozie_workflow.id
    }
    oozie_slas = oozie_api.get_oozie_slas(**params)

  return render('dashboard/list_oozie_workflow.mako', request, {
    'oozie_workflow': oozie_workflow,
    'oozie_coordinator': oozie_coordinator,
    'oozie_bundle': oozie_bundle,
    'oozie_slas': oozie_slas,
    'hue_workflow': hue_workflow,
    'hue_coord': hue_coord,
    'parameters': parameters,
    'has_job_edition_permission': has_job_edition_permission,
    'workflow_graph': workflow_graph
  })
Esempio n. 12
0
def list_oozie_workflow(request, job_id):
    oozie_workflow = check_job_access_permission(request, job_id)

    oozie_coordinator = None
    if request.GET.get("coordinator_job_id"):
        oozie_coordinator = check_job_access_permission(request, request.GET.get("coordinator_job_id"))

    oozie_bundle = None
    if request.GET.get("bundle_job_id"):
        oozie_bundle = check_job_access_permission(request, request.GET.get("bundle_job_id"))

    if oozie_coordinator is not None:
        setattr(oozie_workflow, "oozie_coordinator", oozie_coordinator)
    if oozie_bundle is not None:
        setattr(oozie_workflow, "oozie_bundle", oozie_bundle)

    oozie_parent = oozie_workflow.get_parent_job_id()
    if oozie_parent:
        oozie_parent = check_job_access_permission(request, oozie_parent)

    workflow_data = None
    credentials = None
    doc = None
    hue_workflow = None
    workflow_graph = "MISSING"  # default to prevent loading the graph tab for deleted workflows
    full_node_list = None

    if ENABLE_V2.get():
        try:
            # To update with the new History document model
            hue_coord = get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
            hue_workflow = (hue_coord and hue_coord.workflow) or get_history().get_workflow_from_config(
                oozie_workflow.conf_dict
            )

            if hue_coord and hue_coord.workflow:
                hue_coord.workflow.document.doc.get().can_read_or_exception(request.user)
            if hue_workflow:
                hue_workflow.document.doc.get().can_read_or_exception(request.user)

            if hue_workflow:
                workflow_graph = ""
                full_node_list = hue_workflow.nodes
                workflow_id = hue_workflow.id
                wid = {"id": workflow_id}
                doc = Document2.objects.get(type="oozie-workflow2", **wid)
                new_workflow = get_workflow()(document=doc)
                workflow_data = new_workflow.get_data()
                credentials = Credentials()
            else:
                # For workflows submitted from CLI or deleted in the editor
                # Until better parsing in https://issues.cloudera.org/browse/HUE-2659
                workflow_graph, full_node_list = OldWorkflow.gen_status_graph_from_xml(request.user, oozie_workflow)
        except:
            LOG.exception("Error generating full page for running workflow %s" % job_id)
    else:
        history = get_history().cross_reference_submission_history(request.user, job_id)

        hue_coord = (
            history and history.get_coordinator() or get_history().get_coordinator_from_config(oozie_workflow.conf_dict)
        )
        hue_workflow = (
            (hue_coord and hue_coord.workflow)
            or (history and history.get_workflow())
            or get_history().get_workflow_from_config(oozie_workflow.conf_dict)
        )

        if hue_coord and hue_coord.workflow:
            Job.objects.can_read_or_exception(request, hue_coord.workflow.id)
        if hue_workflow:
            Job.objects.can_read_or_exception(request, hue_workflow.id)

        if hue_workflow:
            workflow_graph = hue_workflow.gen_status_graph(oozie_workflow)
            full_node_list = hue_workflow.node_list
        else:
            workflow_graph, full_node_list = get_workflow().gen_status_graph_from_xml(request.user, oozie_workflow)

    parameters = oozie_workflow.conf_dict.copy()

    for action in oozie_workflow.actions:
        action.oozie_coordinator = oozie_coordinator
        action.oozie_bundle = oozie_bundle

    if request.GET.get("format") == "json":
        return_obj = {
            "id": oozie_workflow.id,
            "status": oozie_workflow.status,
            "progress": oozie_workflow.get_progress(full_node_list),
            "graph": workflow_graph,
            "actions": massaged_workflow_actions_for_json(
                oozie_workflow.get_working_actions(), oozie_coordinator, oozie_bundle
            ),
        }
        return JsonResponse(return_obj, encoder=JSONEncoderForHTML)

    oozie_slas = []
    if oozie_workflow.has_sla:
        oozie_api = get_oozie(request.user, api_version="v2")
        params = {"id": oozie_workflow.id, "parent_id": oozie_workflow.id}
        oozie_slas = oozie_api.get_oozie_slas(**params)

    return render(
        "dashboard/list_oozie_workflow.mako",
        request,
        {
            "oozie_workflow": oozie_workflow,
            "oozie_coordinator": oozie_coordinator,
            "oozie_bundle": oozie_bundle,
            "oozie_parent": oozie_parent,
            "oozie_slas": oozie_slas,
            "hue_workflow": hue_workflow,
            "hue_coord": hue_coord,
            "parameters": parameters,
            "has_job_edition_permission": has_job_edition_permission,
            "workflow_graph": workflow_graph,
            "layout_json": json.dumps(workflow_data["layout"], cls=JSONEncoderForHTML) if workflow_data else "",
            "workflow_json": json.dumps(workflow_data["workflow"], cls=JSONEncoderForHTML) if workflow_data else "",
            "credentials_json": json.dumps(credentials.credentials.keys(), cls=JSONEncoderForHTML)
            if credentials
            else "",
            "workflow_properties_json": json.dumps(WORKFLOW_NODE_PROPERTIES, cls=JSONEncoderForHTML),
            "doc1_id": doc.doc.get().id if doc else -1,
            "subworkflows_json": json.dumps(_get_workflows(request.user), cls=JSONEncoderForHTML),
            "can_edit_json": json.dumps(doc is None or doc.doc.get().is_editable(request.user)),
        },
    )