コード例 #1
0
def refresh_action_parameters(request):
  response = {'status': -1}

  try:
    coord_uuid = request.POST.get('uuid')
    workflow_doc = Document2.objects.get(type='oozie-workflow2', owner=request.user, is_managed=True, dependents__uuid__in=[coord_uuid])

    # Refresh the action parameters of a document action in case the document changed
    workflow = Workflow(document=workflow_doc, user=request.user)

    _data = workflow.get_data()
    hive_node = _data['workflow']['nodes'][3]
    query_document = Document2.objects.get_by_uuid(user=request.user, uuid=hive_node['properties']['uuid'])
    parameters = WorkflowBuilder().get_document_parameters(query_document)

    changed = set([p['value'] for p in parameters]) != set([p['value'] for p in hive_node['properties']['parameters']])

    if changed:
      hive_node['properties']['parameters'] = parameters
      workflow.data = json.dumps(_data)

      workflow_doc.update_data({'workflow': _data['workflow']})
      workflow_doc.save()

    response['status'] = 0
    response['parameters'] = parameters
    response['changed'] = changed
  except Exception, e:
    response['message'] = str(e)
コード例 #2
0
ファイル: oozie_batch.py プロジェクト: heavenlxj/hue
    def execute(self, notebook, snippet):
        # Get document from notebook
        if not notebook.get('uuid', ''):
            raise PopupException(
                _('Notebook is missing a uuid, please save the notebook before executing as a batch job.'
                  ))

        notebook_doc = Document2.objects.get_by_uuid(user=self.user,
                                                     uuid=notebook['uuid'],
                                                     perm_type='read')

        # Create a managed workflow from the notebook doc
        workflow_doc = WorkflowBuilder().create_workflow(
            document=notebook_doc,
            user=self.user,
            managed=True,
            name=_("Batch job for %s") % notebook_doc.name
            or notebook_doc.type)
        workflow = Workflow(document=workflow_doc, user=self.user)

        # Submit workflow
        job_id = _submit_workflow(user=self.user,
                                  fs=self.fs,
                                  jt=self.jt,
                                  workflow=workflow,
                                  mapping=None)

        return {
            'id': job_id,
            'has_result_set': True,
        }
コード例 #3
0
ファイル: editor2.py プロジェクト: cloudera/hue
def workflow_parameters(request):
  response = {'status': -1}

  try:
    workflow_doc = Document2.objects.get(uuid=request.GET.get('uuid') or request.GET.get('document'))

    if workflow_doc.type == 'oozie-workflow2':
      workflow = Workflow(document=workflow_doc, user=request.user)
    else:
      wf_doc = WorkflowBuilder().create_workflow(document=workflow_doc, user=request.user, managed=True)
      workflow = Workflow(data=wf_doc.data)
      wf_doc.delete()

    response['status'] = 0
    response['parameters'] = workflow.find_all_parameters(with_lib_path=False)
  except Exception, e:
    response['message'] = str(e)
コード例 #4
0
ファイル: editor2.py プロジェクト: vonkonyoung/hue
def workflow_parameters(request):
  response = {'status': -1}

  try:
    workflow_doc = Document2.objects.get(uuid=request.GET.get('uuid') or request.GET.get('document'))

    if workflow_doc.type == 'oozie-workflow2':
      workflow = Workflow(document=workflow_doc, user=request.user)
    else:
      wf_doc = WorkflowBuilder().create_workflow(document=workflow_doc, user=request.user, managed=True)
      workflow = Workflow(data=wf_doc.data)
      wf_doc.delete()

    response['status'] = 0
    response['parameters'] = workflow.find_all_parameters(with_lib_path=False)
  except Exception, e:
    response['message'] = str(e)
コード例 #5
0
ファイル: oozie_batch.py プロジェクト: dulems/hue-1
    def execute(self, notebook, snippet):
        # Get document from notebook
        if not notebook.get('uuid', ''):
            raise PopupException(
                _('Notebook is missing a uuid, please save the notebook before executing as a batch job.'
                  ))

        if notebook['type'] == 'notebook' or notebook['type'] == 'query-java':
            # Convert notebook to workflow
            workflow_doc = WorkflowBuilder().create_notebook_workflow(
                notebook=notebook,
                user=self.user,
                managed=True,
                name=_("%s for %s") % (OozieApi.BATCH_JOB_PREFIX,
                                       notebook['name'] or notebook['type']))
            workflow = Workflow(document=workflow_doc, user=self.user)
        else:
            notebook_doc = Document2.objects.get_by_uuid(user=self.user,
                                                         uuid=notebook['uuid'],
                                                         perm_type='read')
            # Create a managed workflow from the notebook doc
            workflow_doc = WorkflowBuilder().create_workflow(
                document=notebook_doc,
                user=self.user,
                managed=True,
                name=_("Batch job for %s") %
                (notebook_doc.name or notebook_doc.type))
            workflow = Workflow(document=workflow_doc, user=self.user)

        # Submit workflow
        job_id = _submit_workflow(user=self.user,
                                  fs=self.fs,
                                  jt=self.jt,
                                  workflow=workflow,
                                  mapping=None)

        return {
            'id': job_id,
            'has_result_set': True,
        }
コード例 #6
0
def edit_coordinator(request):
    coordinator_id = request.GET.get('coordinator', request.GET.get('uuid'))
    doc = None
    workflow_uuid = None

    if coordinator_id:
        cid = {}
        if coordinator_id.isdigit():
            cid['id'] = coordinator_id
        else:
            cid['uuid'] = coordinator_id
        doc = Document2.objects.get(**cid)
        coordinator = Coordinator(document=doc)
    else:
        coordinator = Coordinator()
        coordinator.set_workspace(request.user)

    # Automatically create the workflow of a scheduled document
    # To move to save coordinator
    document_uuid = request.GET.get('document')
    if document_uuid:
        # Has already a workflow managing the query for this user?
        workflows = Document2.objects.filter(
            type='oozie-workflow2',
            owner=request.user,
            is_managed=True,
            dependencies__uuid__in=[document_uuid])
        if workflows.exists():
            workflow_doc = workflows.get()
        else:
            document = Document2.objects.get_by_uuid(user=request.user,
                                                     uuid=document_uuid)
            workflow_doc = WorkflowBuilder().create_workflow(document=document,
                                                             user=request.user,
                                                             managed=True)
            if doc:
                doc.dependencies.add(workflow_doc)
        workflow_uuid = workflow_doc.uuid
        coordinator.data['name'] = _('Schedule of %s') % workflow_doc.name
    elif request.GET.get('workflow'):
        workflow_uuid = request.GET.get('workflow')

    if workflow_uuid:
        coordinator.data['properties']['workflow'] = workflow_uuid

    api = get_oozie(request.user)
    credentials = Credentials()

    try:
        credentials.fetch(api)
    except Exception, e:
        LOG.error(smart_str(e))
コード例 #7
0
    def run_morphline(self, collection_name, morphline, input_path):
        workspace_path = self._upload_workspace(morphline)

        snippet_properties = {
            u'files': [{
                u'path': u'%s/log4j.properties' % workspace_path,
                u'type': u'file'
            }, {
                u'path': u'%s/morphline.conf' % workspace_path,
                u'type': u'file'
            }],
            u'class':
            u'org.apache.solr.hadoop.MapReduceIndexerTool',
            u'app_jar':
            CONFIG_INDEXER_LIBS_PATH.get(),
            u'arguments': [
                u'--morphline-file',
                u'morphline.conf',
                u'--output-dir',
                u'${nameNode}/user/%s/indexer' % self.username,
                u'--log4j',
                u'log4j.properties',
                u'--go-live',
                u'--zk-host',
                zkensemble(),
                u'--collection',
                collection_name,
                u'${nameNode}%s' % input_path,
            ],
            u'archives': [],
        }

        notebook = make_notebook(
            name='Indexer',
            editor_type='java',
            snippet_properties=snippet_properties).get_data()
        notebook_doc, created = _save_notebook(notebook, self.user)

        workflow_doc = WorkflowBuilder().create_workflow(
            document=notebook_doc,
            user=self.user,
            managed=True,
            name=_("Batch job for %s") % notebook_doc.name)
        workflow = Workflow(document=workflow_doc, user=self.user)

        job_id = _submit_workflow(user=self.user,
                                  fs=self.fs,
                                  jt=self.jt,
                                  workflow=workflow,
                                  mapping=None)

        return job_id