Esempio n. 1
0
def submit_bundle(request, doc_id):
  bundle = Bundle(document=Document2.objects.get(id=doc_id))
  ParametersFormSet = formset_factory(ParameterForm, extra=0)

  if request.method == 'POST':
    params_form = ParametersFormSet(request.POST)

    if params_form.is_valid():
      mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
      job_id = _submit_bundle(request, bundle, mapping)

      jsonify = request.POST.get('format') == 'json'
      if jsonify:
        return JsonResponse({'status': 0, 'job_id': job_id, 'type': 'bundle'}, safe=False)
      else:
        request.info(_('Bundle submitted.'))
        return redirect(reverse('oozie:list_oozie_bundle', kwargs={'job_id': job_id}))
    else:
      request.error(_('Invalid submission form: %s' % params_form.errors))
  else:
    parameters = bundle.find_all_parameters()
    initial_params = ParameterForm.get_initial_params(dict([(param['name'], param['value']) for param in parameters]))
    params_form = ParametersFormSet(initial=initial_params)

  popup = render('editor2/submit_job_popup.mako', request, {
                 'params_form': params_form,
                 'name': bundle.name,
                 'action': reverse('oozie:editor_submit_bundle',  kwargs={'doc_id': bundle.id}),
                 'return_json': request.GET.get('format') == 'json',
                 'show_dryrun': False
                }, force_template=True).content
  return JsonResponse(popup, safe=False)
Esempio n. 2
0
def copy_bundle(request):
    if request.method != 'POST':
        raise PopupException(_('A POST request is required.'))

    jobs = json.loads(request.POST.get('selection'))

    for job in jobs:
        doc2 = Document2.objects.get(type='oozie-bundle2', id=job['id'])
        doc = doc2.doc.get()

        name = doc2.name + '-copy'
        doc2 = doc2.copy(name=name, owner=request.user)

        doc.copy(content_object=doc2, name=name, owner=request.user)

        bundle = Bundle(document=doc2)
        bundle_data = bundle.get_data_for_json()
        bundle_data['name'] = name

        _import_workspace(request.fs, request.user, bundle)
        doc2.update_data(bundle_data)
        doc2.save()

    response = {}
    request.info(_('Bundle copied.') if len(jobs) > 1 else _('Bundle copied.'))

    return JsonResponse(response)
Esempio n. 3
0
def edit_bundle(request):
  bundle_id = request.GET.get('bundle')
  doc = None

  if bundle_id:
    doc = Document2.objects.get(id=bundle_id)
    bundle = Bundle(document=doc)
  else:
    bundle = Bundle()
    bundle.set_workspace(request.user)

  if USE_NEW_EDITOR.get():
    coordinators = [dict([('id', d.id), ('uuid', d.uuid), ('name', d.name)])
                      for d in Document2.objects.documents(request.user).search_documents(types=['oozie-coordinator2'])]
  else:
    coordinators = [dict([('id', d.content_object.id), ('uuid', d.content_object.uuid), ('name', d.content_object.name)])
                      for d in Document.objects.get_docs(request.user, Document2, extra='coordinator2')]

  can_edit_json = doc is None or (doc.can_write(request.user) if USE_NEW_EDITOR.get() else doc.doc.get().is_editable(request.user))
  return render('editor2/bundle_editor.mako', request, {
      'bundle_json': bundle.to_json_for_html(),
      'coordinators_json': json.dumps(coordinators, cls=JSONEncoderForHTML),
      'doc_uuid': doc.uuid if doc else '',
      'is_embeddable': request.GET.get('is_embeddable', False),
      'can_edit_json': json.dumps(can_edit_json)
  })
Esempio n. 4
0
def copy_bundle(request):
  if request.method != 'POST':
    raise PopupException(_('A POST request is required.'))

  jobs = json.loads(request.POST.get('selection'))

  for job in jobs:
    doc2 = Document2.objects.get(type='oozie-bundle2', id=job['id'])
    doc = doc2.doc.get()

    name = doc2.name + '-copy'
    doc2 = doc2.copy(name=name, owner=request.user)

    doc.copy(content_object=doc2, name=name, owner=request.user)

    bundle = Bundle(document=doc2)
    bundle_data = bundle.get_data_for_json()
    bundle_data['name'] = name

    _import_workspace(request.fs, request.user, bundle)
    doc2.update_data(bundle_data)
    doc2.save()

  response = {}
  request.info(_('Bundle copied.') if len(jobs) > 1 else _('Bundle copied.'))

  return JsonResponse(response)
Esempio n. 5
0
def submit_bundle(request, doc_id):
  bundle = Bundle(document=Document2.objects.get(id=doc_id))
  bundle._data['properties']['kickoff'] = datetime.utcnow()
  ParametersFormSet = formset_factory(ParameterForm, extra=0)

  if request.method == 'POST':
    params_form = ParametersFormSet(request.POST)

    if params_form.is_valid():
      mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
      job_id = _submit_bundle(request, bundle, mapping)

      jsonify = request.POST.get('format') == 'json'
      if jsonify:
        return JsonResponse({'status': 0, 'job_id': job_id, 'type': 'bundle'}, safe=False)
      else:
        request.info(_('Bundle submitted.'))
        return redirect(reverse('oozie:list_oozie_bundle', kwargs={'job_id': job_id}))
    else:
      request.error(_('Invalid submission form: %s' % params_form.errors))
  else:
    parameters = bundle.find_all_parameters()
    initial_params = ParameterForm.get_initial_params(dict([(param['name'], param['value']) for param in parameters]))
    params_form = ParametersFormSet(initial=initial_params)

    return render('/scheduler/submit_job_popup.mako', request, {
                 'params_form': params_form,
                 'name': bundle.name,
                 'action': reverse('oozie:editor_submit_bundle',  kwargs={'doc_id': bundle.id}),
                 'return_json': request.GET.get('format') == 'json',
                 'show_dryrun': False
                }, force_template=True)
Esempio n. 6
0
def submit_bundle(request, doc_id):
  bundle = Bundle(document=Document2.objects.get(id=doc_id))
  ParametersFormSet = formset_factory(ParameterForm, extra=0)

  if request.method == 'POST':
    params_form = ParametersFormSet(request.POST)

    if params_form.is_valid():
      mapping = dict([(param['name'], param['value']) for param in params_form.cleaned_data])
      job_id = _submit_bundle(request, bundle, mapping)

      request.info(_('Bundle submitted.'))
      return redirect(reverse('oozie:list_oozie_bundle', kwargs={'job_id': job_id}))
    else:
      request.error(_('Invalid submission form: %s' % params_form.errors))
  else:
    parameters = bundle.find_all_parameters()
    initial_params = ParameterForm.get_initial_params(dict([(param['name'], param['value']) for param in parameters]))
    params_form = ParametersFormSet(initial=initial_params)

  popup = render('editor2/submit_job_popup.mako', request, {
                 'params_form': params_form,
                 'name': bundle.name,
                 'action': reverse('oozie:editor_submit_bundle',  kwargs={'doc_id': bundle.id}),
                 'show_dryrun': False
                }, force_template=True).content
  return JsonResponse(popup, safe=False)
Esempio n. 7
0
def copy_document(request):
    uuid = json.loads(request.POST.get('uuid'), '""')

    if not uuid:
        raise PopupException(_('copy_document requires uuid'))

    document = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)

    if document.type == 'directory':
        raise PopupException(_('Directory copy is not supported'))

    name = document.name + '-copy'

    # Make the copy of the new Document
    copy_document = document.copy(name=name, owner=request.user)

    # Import workspace for all oozie jobs
    if document.type == 'oozie-workflow2' or document.type == 'oozie-bundle2' or document.type == 'oozie-coordinator2':
        from oozie.models2 import Workflow, Coordinator, Bundle, _import_workspace
        # Update the name field in the json 'data' field
        if document.type == 'oozie-workflow2':
            workflow = Workflow(document=document)
            workflow.update_name(name)
            workflow.update_uuid(copy_document.uuid)
            _import_workspace(request.fs, request.user, workflow)
            copy_document.update_data(
                {'workflow': workflow.get_data()['workflow']})
            copy_document.save()

        if document.type == 'oozie-bundle2' or document.type == 'oozie-coordinator2':
            if document.type == 'oozie-bundle2':
                bundle_or_coordinator = Bundle(document=document)
            else:
                bundle_or_coordinator = Coordinator(document=document)
            json_data = bundle_or_coordinator.get_data_for_json()
            json_data['name'] = name
            json_data['uuid'] = copy_document.uuid
            copy_document.update_data(json_data)
            copy_document.save()
            _import_workspace(request.fs, request.user, bundle_or_coordinator)
    elif document.type == 'search-dashboard':
        from dashboard.models import Collection2
        collection = Collection2(request.user, document=document)
        collection.data['collection']['label'] = name
        collection.data['collection']['uuid'] = copy_document.uuid
        copy_document.update_data(
            {'collection': collection.data['collection']})
        copy_document.save()
    # Keep the document and data in sync
    else:
        copy_data = copy_document.data_dict
        if 'name' in copy_data:
            copy_data['name'] = name
        if 'uuid' in copy_data:
            copy_data['uuid'] = copy_document.uuid
        copy_document.update_data(copy_data)
        copy_document.save()

    return JsonResponse({'status': 0, 'document': copy_document.to_dict()})
Esempio n. 8
0
def copy_bundle(request):
  if request.method != 'POST':
    raise PopupException(_('A POST request is required.'))

  jobs = json.loads(request.POST.get('selection'))

  for job in jobs:
    doc2 = Document2.objects.get(type='oozie-bundle2', id=job['id'])
    
    name = doc2.name + '-copy'
    copy_doc = doc2.doc.get().copy(name=name, owner=request.user)
  
    doc2.pk = None
    doc2.id = None
    doc2.uuid = str(uuid.uuid4())
    doc2.name = name
    doc2.owner = request.user    
    doc2.save()
  
    doc2.doc.all().delete()
    doc2.doc.add(copy_doc)
    
    bundle_data = Bundle(document=doc2).get_data_for_json()
    bundle_data['name'] = name
    doc2.update_data(bundle_data)
    doc2.save()

  response = {}  
  request.info(_('Bundle copied.') if len(jobs) > 1 else _('Bundle copied.'))

  return JsonResponse(response)
Esempio n. 9
0
def edit_bundle(request):
    bundle_id = request.GET.get('bundle')
    doc = None

    if bundle_id:
        doc = Document2.objects.get(id=bundle_id)
        bundle = Bundle(document=doc)
    else:
        bundle = Bundle()
        bundle.set_workspace(request.user)

    coordinators = [
        dict([('id', d.content_object.id), ('uuid', d.content_object.uuid),
              ('name', d.content_object.name)])
        for d in Document.objects.get_docs(
            request.user, Document2, extra='coordinator2')
    ]

    return render(
        'editor2/bundle_editor.mako', request, {
            'bundle_json':
            bundle.to_json_for_html(),
            'coordinators_json':
            json.dumps(coordinators, cls=JSONEncoderForHTML),
            'doc1_id':
            doc.doc.get().id if doc else -1,
            'can_edit_json':
            json.dumps(doc is None or doc.doc.get().is_editable(request.user))
        })
Esempio n. 10
0
def edit_bundle(request):
  bundle_id = request.GET.get('bundle')
  doc = None

  if bundle_id:
    doc = Document2.objects.get(id=bundle_id)
    bundle = Bundle(document=doc)
  else:
    bundle = Bundle()
    bundle.set_workspace(request.user)

  if USE_NEW_EDITOR.get():
    coordinators = [dict([('id', d.id), ('uuid', d.uuid), ('name', d.name)])
                      for d in Document2.objects.documents(request.user).search_documents(types=['oozie-coordinator2'])]
  else:
    coordinators = [dict([('id', d.content_object.id), ('uuid', d.content_object.uuid), ('name', d.content_object.name)])
                      for d in Document.objects.get_docs(request.user, Document2, extra='coordinator2')]

  can_edit_json = doc is None or (doc.can_write(request.user) if USE_NEW_EDITOR.get() else doc.doc.get().is_editable(request.user))
  return render('editor2/bundle_editor.mako', request, {
      'bundle_json': bundle.to_json_for_html(),
      'coordinators_json': json.dumps(coordinators, cls=JSONEncoderForHTML),
      'doc_uuid': doc.uuid if doc else '',
      'is_embeddable': request.GET.get('is_embeddable', False),
      'can_edit_json': json.dumps(can_edit_json)
  })
Esempio n. 11
0
def edit_bundle(request):
  bundle_id = request.GET.get('bundle')
  doc = None

  if bundle_id:
    doc = Document2.objects.get(id=bundle_id)
    bundle = Bundle(document=doc)
  else:
    bundle = Bundle()
    bundle.set_workspace(request.user)

  coordinators = [dict([('id', d.content_object.id), ('uuid', d.content_object.uuid), ('name', d.content_object.name)])
                      for d in Document.objects.get_docs(request.user, Document2, extra='coordinator2')]

  return render('editor2/bundle_editor.mako', request, {
      'bundle_json': bundle.to_json_for_html(),
      'coordinators_json': json.dumps(coordinators, cls=JSONEncoderForHTML),
      'doc1_id': doc.doc.get().id if doc else -1,
      'can_edit_json': json.dumps(doc is None or doc.doc.get().is_editable(request.user))
  })
Esempio n. 12
0
File: api2.py Progetto: cloudera/hue
def copy_document(request):
  uuid = json.loads(request.POST.get('uuid'), '""')

  if not uuid:
    raise PopupException(_('copy_document requires uuid'))


  # Document2 and Document model objects are linked and both are saved when saving
  document = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
  # Document model object
  document1 = document.doc.get()

  if document.type == 'directory':
    raise PopupException(_('Directory copy is not supported'))

  name = document.name + '-copy'

  # Make the copy of the Document2 model object
  copy_document = document.copy(name=name, owner=request.user)
  # Make the copy of Document model object too
  document1.copy(content_object=copy_document, name=name, owner=request.user)

  # Import workspace for all oozie jobs
  if document.type == 'oozie-workflow2' or document.type == 'oozie-bundle2' or document.type == 'oozie-coordinator2':
    from oozie.models2 import Workflow, Coordinator, Bundle, _import_workspace
    # Update the name field in the json 'data' field
    if document.type == 'oozie-workflow2':
      workflow = Workflow(document=document)
      workflow.update_name(name)
      workflow.update_uuid(copy_document.uuid)
      _import_workspace(request.fs, request.user, workflow)
      copy_document.update_data({'workflow': workflow.get_data()['workflow']})
      copy_document.save()

    if document.type == 'oozie-bundle2' or document.type == 'oozie-coordinator2':
      if document.type == 'oozie-bundle2':
        bundle_or_coordinator = Bundle(document=document)
      else:
        bundle_or_coordinator = Coordinator(document=document)
      json_data = bundle_or_coordinator.get_data_for_json()
      json_data['name'] = name
      json_data['uuid'] = copy_document.uuid
      copy_document.update_data(json_data)
      copy_document.save()
      _import_workspace(request.fs, request.user, bundle_or_coordinator)
  elif document.type == 'search-dashboard':
    from dashboard.models import Collection2
    collection = Collection2(request.user, document=document)
    collection.data['collection']['label'] = name
    collection.data['collection']['uuid'] = copy_document.uuid
    copy_document.update_data({'collection': collection.data['collection']})
    copy_document.save()
  # Keep the document and data in sync
  else:
    copy_data = copy_document.data_dict
    if 'name' in copy_data:
      copy_data['name'] = name
    if 'uuid' in copy_data:
      copy_data['uuid'] = copy_document.uuid
    copy_document.update_data(copy_data)
    copy_document.save()

  return JsonResponse({
    'status': 0,
    'document': copy_document.to_dict()
  })