Beispiel #1
0
def create_coordinator_dataset(request, coordinator):
  """Returns {'status' 0/1, data:html or url}"""

  dataset = Dataset(coordinator=coordinator)
  response = {'status': -1, 'data': 'None'}

  if request.method == 'POST':
    dataset_form = DatasetForm(request.POST, instance=dataset, prefix='create')

    if dataset_form.is_valid():
      dataset_form.save()
      response['status'] = 0
      response['data'] = reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}) + "#listDataset"
      request.info(_('Dataset created'))
  else:
    ## Bad
    response['data'] = _('A POST request is required.')

  if response['status'] != 0:
    response['data'] = render('editor/create_coordinator_dataset.mako', request, {
                            'coordinator': coordinator,
                            'dataset_form': dataset_form,
                            'dataset': dataset,
                          }, force_template=True).content

  return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #2
0
def create_coordinator_dataset(request, coordinator):
    """Returns {'status' 0/1, data:html or url}"""

    dataset = Dataset(coordinator=coordinator)
    response = {'status': -1, 'data': 'None'}

    if request.method == 'POST':
        dataset_form = DatasetForm(request.POST,
                                   instance=dataset,
                                   prefix='create')

        if dataset_form.is_valid():
            dataset_form.save()
            response['status'] = 0
            response['data'] = reverse('oozie:edit_coordinator',
                                       kwargs={'coordinator': coordinator.id
                                               }) + "#listDataset"
            request.info(_('Dataset created'))
    else:
        ## Bad
        response['data'] = _('A POST request is required.')

    if response['status'] != 0:
        response['data'] = render('editor/create_coordinator_dataset.mako',
                                  request, {
                                      'coordinator': coordinator,
                                      'dataset_form': dataset_form,
                                      'dataset': dataset,
                                  },
                                  force_template=True).content

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #3
0
def edit_coordinator_dataset(request, dataset):
  """Returns HTML for modal to edit datasets"""

  response = {'status': -1, 'data': 'None'}

  if request.method == 'POST':
    dataset_form = DatasetForm(request.POST, instance=dataset, prefix='edit')

    if dataset_form.is_valid():
      dataset = dataset_form.save()
      response['status'] = 0
      response['data'] = reverse('oozie:edit_coordinator', kwargs={'coordinator': dataset.coordinator.id}) + "#listDataset"
      request.info(_('Dataset modified'))
      if dataset.start > dataset.coordinator.start:
        request.error(_('Beware: dataset start date was after the coordinator start date.'))
    else:
      response['data'] = dataset_form.errors
  else:
    dataset_form = DatasetForm(instance=dataset, prefix='edit')

  if response['status'] != 0:
    response['data'] = render('editor/edit_coordinator_dataset.mako', request, {
                          'coordinator': dataset.coordinator,
                          'dataset_form': dataset_form,
                          'dataset': dataset,
                          'path': request.path,
                        }, force_template=True).content

  return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #4
0
def create_coordinator_dataset(request, coordinator):
    """Returns {'status' 0/1, data:html or url}"""

    dataset = Dataset(coordinator=coordinator)
    response = {"status": -1, "data": "None"}

    if request.method == "POST":
        dataset_form = DatasetForm(request.POST, instance=dataset, prefix="create")

        if dataset_form.is_valid():
            dataset_form.save()
            response["status"] = 0
            response["data"] = (
                reverse("oozie:edit_coordinator", kwargs={"coordinator": coordinator.id}) + "#listDataset"
            )
            request.info(_("Dataset created"))
    else:
        ## Bad
        response["data"] = _("A POST request is required.")

    if response["status"] != 0:
        response["data"] = render(
            "editor/create_coordinator_dataset.mako",
            request,
            {"coordinator": coordinator, "dataset_form": dataset_form, "dataset": dataset},
            force_template=True,
        ).content

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #5
0
def edit_coordinator(request, coordinator):
  history = History.objects.filter(submitter=request.user, job=coordinator).order_by('-submission_date')

  DatasetFormSet = inlineformset_factory(Coordinator, Dataset, form=DatasetForm, max_num=0, can_order=False, can_delete=True)
  DataInputFormSet = inlineformset_factory(Coordinator, DataInput, form=DataInputForm, max_num=0, can_order=False, can_delete=True)
  DataInputFormSet.form = staticmethod(curry(DataInputForm, coordinator=coordinator))
  DataOutputFormSet = inlineformset_factory(Coordinator, DataOutput, form=DataOutputForm, max_num=0, can_order=False, can_delete=True)
  DataOutputFormSet.form = staticmethod(curry(DataOutputForm, coordinator=coordinator))

  dataset = Dataset(coordinator=coordinator)
  dataset_form = DatasetForm(instance=dataset, prefix='create')

  NewDataInputFormSet = inlineformset_factory(Coordinator, DataInput, form=DataInputForm, extra=0, can_order=False, can_delete=False)
  NewDataInputFormSet.form = staticmethod(curry(DataInputForm, coordinator=coordinator))
  NewDataOutputFormSet = inlineformset_factory(Coordinator, DataOutput, form=DataOutputForm, extra=0, can_order=False, can_delete=False)
  NewDataOutputFormSet.form = staticmethod(curry(DataOutputForm, coordinator=coordinator))

  if request.method == 'POST':
    coordinator_form = CoordinatorForm(request.POST, instance=coordinator, user=request.user)
    dataset_formset = DatasetFormSet(request.POST, request.FILES, instance=coordinator)
    data_input_formset = DataInputFormSet(request.POST, request.FILES, instance=coordinator)
    data_output_formset = DataOutputFormSet(request.POST, request.FILES, instance=coordinator)
    new_data_input_formset = NewDataInputFormSet(request.POST, request.FILES, instance=coordinator, prefix='input')
    new_data_output_formset = NewDataOutputFormSet(request.POST, request.FILES, instance=coordinator, prefix='output')

    if coordinator_form.is_valid() and dataset_formset.is_valid() and data_input_formset.is_valid() and data_output_formset.is_valid() \
        and new_data_input_formset.is_valid() and new_data_output_formset.is_valid():
      coordinator = coordinator_form.save()
      dataset_formset.save()
      data_input_formset.save()
      data_output_formset.save()
      new_data_input_formset.save()
      new_data_output_formset.save()

      request.info(_('Coordinator saved.'))
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}))
  else:
    coordinator_form = CoordinatorForm(instance=coordinator, user=request.user)
    dataset_formset = DatasetFormSet(instance=coordinator)
    data_input_formset = DataInputFormSet(instance=coordinator)
    data_output_formset = DataOutputFormSet(instance=coordinator)
    new_data_input_formset = NewDataInputFormSet(queryset=DataInput.objects.none(), instance=coordinator, prefix='input')
    new_data_output_formset = NewDataOutputFormSet(queryset=DataOutput.objects.none(), instance=coordinator, prefix='output')

  return render('editor/edit_coordinator.mako', request, {
    'coordinator': coordinator,
    'coordinator_form': coordinator_form,
    'dataset_formset': dataset_formset,
    'data_input_formset': data_input_formset,
    'data_output_formset': data_output_formset,
    'dataset': dataset,
    'dataset_form': dataset_form,
    'new_data_input_formset': new_data_input_formset,
    'new_data_output_formset': new_data_output_formset,
    'history': history
  })
Beispiel #6
0
def edit_coordinator_dataset(request, dataset):
  """Returns HTML for modal to edit datasets"""

  response = {'status': -1, 'data': 'None'}

  if request.method == 'POST':
    dataset_form = DatasetForm(request.POST, instance=dataset, prefix='edit')

    if dataset_form.is_valid():
      dataset = dataset_form.save()
      response['status'] = 0
      response['data'] = reverse('oozie:edit_coordinator', kwargs={'coordinator': dataset.coordinator.id}) + "#listDataset"
      request.info(_('Dataset modified'))
      if dataset.start > dataset.coordinator.start:
        request.warn(_('Beware: dataset start date was after the coordinator start date.'))
    else:
      response['data'] = dataset_form.errors
  else:
    dataset_form = DatasetForm(instance=dataset, prefix='edit')

  if response['status'] != 0:
    response['data'] = render('editor/edit_coordinator_dataset.mako', request, {
                          'coordinator': dataset.coordinator,
                          'dataset_form': dataset_form,
                          'dataset': dataset,
                          'path': request.path,
                        }, force_template=True).content

  return JsonResponse(response, safe=False)
Beispiel #7
0
def edit_coordinator_dataset(request, dataset):
    """Returns HTML for modal to edit datasets"""

    response = {"status": -1, "data": "None"}

    if request.method == "POST":
        dataset_form = DatasetForm(request.POST, instance=dataset, prefix="edit")

        if dataset_form.is_valid():
            dataset = dataset_form.save()
            response["status"] = 0
            response["data"] = (
                reverse("oozie:edit_coordinator", kwargs={"coordinator": dataset.coordinator.id}) + "#listDataset"
            )
            request.info(_("Dataset modified"))
            if dataset.start > dataset.coordinator.start:
                request.error(_("Beware: dataset start date was after the coordinator start date."))
        else:
            response["data"] = dataset_form.errors
    else:
        dataset_form = DatasetForm(instance=dataset, prefix="edit")

    if response["status"] != 0:
        response["data"] = render(
            "editor/edit_coordinator_dataset.mako",
            request,
            {
                "coordinator": dataset.coordinator,
                "dataset_form": dataset_form,
                "dataset": dataset,
                "path": request.path,
            },
            force_template=True,
        ).content

    return HttpResponse(json.dumps(response), mimetype="application/json")
Beispiel #8
0
def edit_coordinator_dataset(request, dataset):
    """Returns HTML for modal to edit datasets"""

    if request.method == 'POST':
        dataset_form = DatasetForm(request.POST, instance=dataset)

        if dataset_form.is_valid():
            dataset_form.save()
            request.info(_('Dataset modified'))
            return redirect(
                reverse('oozie:edit_coordinator',
                        kwargs={'coordinator': dataset.coordinator.id}))
        else:
            dataset_form = DatasetForm(request.POST, instance=dataset)
    else:
        dataset_form = DatasetForm(instance=dataset)

    return render('editor/edit_coordinator_dataset.mako',
                  request, {
                      'coordinator': dataset.coordinator,
                      'dataset_form': dataset_form,
                      'path': request.path,
                  },
                  force_template=True)
Beispiel #9
0
def edit_coordinator_dataset(request, dataset):
  """Returns HTML for modal to edit datasets"""

  if request.method == 'POST':
    dataset_form = DatasetForm(request.POST, instance=dataset)

    if dataset_form.is_valid():
      dataset_form.save()
      request.info(_('Dataset modified'));
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': dataset.coordinator.id}))
    else:
      dataset_form = DatasetForm(request.POST, instance=dataset)
  else:
    dataset_form = DatasetForm(instance=dataset)

  return render('editor/edit_coordinator_dataset.mako', request, {
    'coordinator': dataset.coordinator,
    'dataset_form': dataset_form,
    'path': request.path,
  }, force_template=True)
Beispiel #10
0
def edit_coordinator_dataset(request, dataset):
    """Returns HTML for modal to edit datasets"""

    if request.method == "POST":
        dataset_form = DatasetForm(request.POST, instance=dataset)

        if dataset_form.is_valid():
            dataset_form.save()
            request.info(_("Dataset modified"))
            return redirect(reverse("oozie:edit_coordinator", kwargs={"coordinator": dataset.coordinator.id}))
        else:
            dataset_form = DatasetForm(request.POST, instance=dataset)
    else:
        dataset_form = DatasetForm(instance=dataset)

    return render(
        "editor/edit_coordinator_dataset.mako",
        request,
        {"coordinator": dataset.coordinator, "dataset_form": dataset_form, "path": request.path},
        force_template=True,
    )
Beispiel #11
0
def edit_coordinator(request, coordinator):
    history = History.objects.filter(
        submitter=request.user, job=coordinator).order_by('-submission_date')

    DatasetFormSet = inlineformset_factory(Coordinator,
                                           Dataset,
                                           form=DatasetForm,
                                           max_num=0,
                                           can_order=False,
                                           can_delete=True)
    DataInputFormSet = inlineformset_factory(Coordinator,
                                             DataInput,
                                             form=DataInputForm,
                                             max_num=0,
                                             can_order=False,
                                             can_delete=True)
    DataInputFormSet.form = staticmethod(
        curry(DataInputForm, coordinator=coordinator))
    DataOutputFormSet = inlineformset_factory(Coordinator,
                                              DataOutput,
                                              form=DataOutputForm,
                                              max_num=0,
                                              can_order=False,
                                              can_delete=True)
    DataOutputFormSet.form = staticmethod(
        curry(DataOutputForm, coordinator=coordinator))

    dataset = Dataset(coordinator=coordinator)
    dataset_form = DatasetForm(instance=dataset, prefix='create')

    NewDataInputFormSet = inlineformset_factory(Coordinator,
                                                DataInput,
                                                form=DataInputForm,
                                                extra=0,
                                                can_order=False,
                                                can_delete=False)
    NewDataInputFormSet.form = staticmethod(
        curry(DataInputForm, coordinator=coordinator))
    NewDataOutputFormSet = inlineformset_factory(Coordinator,
                                                 DataOutput,
                                                 form=DataOutputForm,
                                                 extra=0,
                                                 can_order=False,
                                                 can_delete=False)
    NewDataOutputFormSet.form = staticmethod(
        curry(DataOutputForm, coordinator=coordinator))

    enable_cron_scheduling = ENABLE_CRON_SCHEDULING.get()

    if request.method == 'POST':
        coordinator_form = CoordinatorForm(request.POST,
                                           instance=coordinator,
                                           user=request.user)
        dataset_formset = DatasetFormSet(request.POST,
                                         request.FILES,
                                         instance=coordinator)
        data_input_formset = DataInputFormSet(request.POST,
                                              request.FILES,
                                              instance=coordinator)
        data_output_formset = DataOutputFormSet(request.POST,
                                                request.FILES,
                                                instance=coordinator)
        new_data_input_formset = NewDataInputFormSet(request.POST,
                                                     request.FILES,
                                                     instance=coordinator,
                                                     prefix='input')
        new_data_output_formset = NewDataOutputFormSet(request.POST,
                                                       request.FILES,
                                                       instance=coordinator,
                                                       prefix='output')

        if coordinator_form.is_valid() and dataset_formset.is_valid() and data_input_formset.is_valid() and data_output_formset.is_valid() \
            and new_data_input_formset.is_valid() and new_data_output_formset.is_valid():
            coordinator = coordinator_form.save()
            dataset_formset.save()
            data_input_formset.save()
            data_output_formset.save()
            new_data_input_formset.save()
            new_data_output_formset.save()
            coordinator.sla = json.loads(request.POST.get('sla'))
            if enable_cron_scheduling:
                coordinator.cron_frequency = {
                    'frequency': request.POST.get('cron_frequency'),
                    'isAdvancedCron':
                    request.POST.get('isAdvancedCron') == 'on'
                }
            coordinator.save()

            request.info(_('Coordinator saved.'))
            return redirect(
                reverse('oozie:edit_coordinator',
                        kwargs={'coordinator': coordinator.id}))
    else:
        coordinator_form = CoordinatorForm(instance=coordinator,
                                           user=request.user)
        dataset_formset = DatasetFormSet(instance=coordinator)
        data_input_formset = DataInputFormSet(instance=coordinator)
        data_output_formset = DataOutputFormSet(instance=coordinator)
        new_data_input_formset = NewDataInputFormSet(
            queryset=DataInput.objects.none(),
            instance=coordinator,
            prefix='input')
        new_data_output_formset = NewDataOutputFormSet(
            queryset=DataOutput.objects.none(),
            instance=coordinator,
            prefix='output')

    return render(
        'editor/edit_coordinator.mako', request, {
            'coordinator': coordinator,
            'coordinator_form': coordinator_form,
            'dataset_formset': dataset_formset,
            'data_input_formset': data_input_formset,
            'data_output_formset': data_output_formset,
            'dataset': dataset,
            'dataset_form': dataset_form,
            'new_data_input_formset': new_data_input_formset,
            'new_data_output_formset': new_data_output_formset,
            'history': history,
            'coordinator_frequency': json.dumps(coordinator.cron_frequency),
            'enable_cron_scheduling': enable_cron_scheduling,
        })