コード例 #1
0
def submit_schedule(request, doc_id):
  interface = request.GET.get('interface', request.POST.get('interface', 'beat'))

  if doc_id.isdigit():
    coordinator = Coordinator(document=Document2.objects.get(id=doc_id))
  else:
    coordinator = Coordinator(document=Document2.objects.get_by_uuid(user=request.user, uuid=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])
      mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
      jsonify = request.POST.get('format') == 'json'
      try:
        job_id = get_api(request, interface).submit_schedule(request, coordinator, mapping)
      except Exception as e:
        message = force_unicode(str(e))
        return JsonResponse({'status': -1, 'message': message}, safe=False)
      if jsonify:
        schedule_type = 'celery-beat' if interface == 'beat' else 'schedule'
        return JsonResponse({'status': 0, 'job_id': job_id, 'type': schedule_type}, safe=False)
      else:
        request.info(_('Schedule submitted.'))
        return redirect(reverse('oozie:list_oozie_coordinator', kwargs={'job_id': job_id}))
    else:
      request.error(_('Invalid submission form: %s') % params_form.errors)
  else:
    parameters = coordinator.find_all_parameters() if interface == 'oozie' else []
    initial_params = ParameterForm.get_initial_params(dict([(param['name'], param['value']) for param in parameters]))
    params_form = ParametersFormSet(initial=initial_params)

  popup = render(
      'scheduler/submit_job_popup.mako',
      request, {
          'params_form': params_form,
          'name': coordinator.name,
          'action': '/scheduler/api/schedule/submit/%s' % coordinator.id,
          'show_dryrun': False,
          'return_json': request.GET.get('format') == 'json',
          'interface': interface
      },
      force_template=True
  ).content

  return JsonResponse(popup, safe=False)
コード例 #2
0
def submit_schedule(request, doc_id):
    interface = request.GET.get('interface', request.POST.get('interface'),
                                'oozie')
    if doc_id.isdigit():
        coordinator = Coordinator(document=Document2.objects.get(id=doc_id))
    else:
        coordinator = Coordinator(document=Document2.objects.get_by_uuid(
            user=request.user, uuid=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])
            mapping['dryrun'] = request.POST.get('dryrun_checkbox') == 'on'
            jsonify = request.POST.get('format') == 'json'
            try:
                job_id = get_api(request, interface).submit_schedule(
                    request, coordinator, mapping)
            except Exception, e:
                message = force_unicode(str(e))
                return JsonResponse({
                    'status': -1,
                    'message': message
                },
                                    safe=False)
            if jsonify:
                return JsonResponse(
                    {
                        'status': 0,
                        'job_id': job_id,
                        'type': 'schedule'
                    },
                    safe=False)
            else:
                request.info(_('Schedule submitted.'))
                return redirect(
                    reverse('oozie:list_oozie_coordinator',
                            kwargs={'job_id': job_id}))
        else:
            request.error(
                _('Invalid submission form: %s') % params_form.errors)