示例#1
0
文件: editor.py 项目: 18600597055/hue
def create_coordinator(request, workflow=None):
  if workflow is not None:
    coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2", workflow=workflow)
  else:
    coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2")

  enable_cron_scheduling = ENABLE_CRON_SCHEDULING.get()

  if request.method == 'POST':
    coordinator_form = CoordinatorForm(request.POST, instance=coordinator, user=request.user)

    if coordinator_form.is_valid():
      coordinator = coordinator_form.save()
      if enable_cron_scheduling:
        coordinator.cron_frequency = {'frequency': request.POST.get('cron_frequency'), 'isAdvancedCron': request.POST.get('isAdvancedCron') == 'on'}
      coordinator.save()
      Document.objects.link(coordinator, owner=coordinator.owner, name=coordinator.name, description=coordinator.description)
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}) + "#step3")
    else:
      request.error(_('Errors on the form: %s') % coordinator_form.errors)
  else:
    coordinator_form = CoordinatorForm(instance=coordinator, user=request.user)

  return render('editor/create_coordinator.mako', request, {
    'coordinator': coordinator,
    'coordinator_form': coordinator_form,
    'coordinator_frequency': json.dumps(coordinator.cron_frequency),
    'enable_cron_scheduling': enable_cron_scheduling,
  })
示例#2
0
文件: editor.py 项目: agibsonccc/hue
def create_coordinator(request, workflow=None):
    if workflow is not None:
        coordinator = Coordinator(owner=request.user,
                                  schema_version="uri:oozie:coordinator:0.1",
                                  workflow=workflow)
    else:
        coordinator = Coordinator(owner=request.user,
                                  schema_version="uri:oozie:coordinator:0.1")

    if request.method == 'POST':
        coordinator_form = CoordinatorForm(request.POST,
                                           instance=coordinator,
                                           user=request.user)

        if coordinator_form.is_valid():
            coordinator = coordinator_form.save()
            return redirect(
                reverse('oozie:edit_coordinator',
                        kwargs={'coordinator': coordinator.id}) + "#step3")
        else:
            request.error(
                _('Errors on the form: %s') % coordinator_form.errors)
    else:
        coordinator_form = CoordinatorForm(instance=coordinator,
                                           user=request.user)

    return render('editor/create_coordinator.mako', request, {
        'coordinator': coordinator,
        'coordinator_form': coordinator_form,
    })
示例#3
0
文件: editor.py 项目: 18600597055/hue
def import_coordinator(request):
  coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2")

  if request.method == 'POST':
    coordinator_form = ImportCoordinatorForm(request.POST, request.FILES, instance=coordinator, user=request.user)

    if coordinator_form.is_valid():
      coordinator_definition = coordinator_form.cleaned_data['definition_file'].read()

      try:
        _import_coordinator(coordinator=coordinator, coordinator_definition=coordinator_definition)
        coordinator.managed = True
        coordinator.name = coordinator_form.cleaned_data.get('name')
        coordinator.save()
      except Exception, e:
        request.error(_('Could not import coordinator: %s' % e))
        raise PopupException(_('Could not import coordinator.'), detail=e)

      if coordinator_form.cleaned_data.get('resource_archive'):
        # Upload resources to workspace
        source = coordinator_form.cleaned_data.get('resource_archive')
        if source.name.endswith('.zip'):
          temp_path = archive_factory(source).extract()
          request.fs.copyFromLocal(temp_path, coordinator.deployment_dir)
          shutil.rmtree(temp_path)
        else:
          Coordinator.objects.filter(id=coordinator.id).delete()
          raise PopupException(_('Archive should be a Zip.'))

      Document.objects.link(coordinator, owner=request.user, name=coordinator.name, description=coordinator.description)
      request.info(_('Coordinator imported'))
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}))

    else:
      request.error(_('Errors on the form'))
示例#4
0
文件: oozie_setup.py 项目: erickt/hue
 def _import_coordinators(self, directory):
   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, 'coordinator.zip')) as fp:
         coordinator_xml, metadata = Coordinator.decompress(fp)
       coordinator_root = etree.fromstring(coordinator_xml)
       try:
         Coordinator.objects.get(name=coordinator_root.get('name'))
       except Coordinator.DoesNotExist:
         LOG.info(_("Installing coordinator %s") % coordinator_root.get('name'))
         LOG.debug("Coordinator definition:\n%s" % coordinator_xml)
         coordinator = Coordinator(owner=self.user, is_shared=True)
         coordinator.name = coordinator_root.get('name')
         coordinator.save()
         import_coordinator_root(coordinator=coordinator, coordinator_definition_root=coordinator_root, metadata=metadata)
示例#5
0
def create_coordinator(request, workflow=None):
  if workflow is not None:
    coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2", coordinatorworkflow=workflow)
  else:
    coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2")

  enable_cron_scheduling = ENABLE_CRON_SCHEDULING.get()

  if request.method == 'POST':
    coordinator_form = CoordinatorForm(request.POST, instance=coordinator, user=request.user)

    if coordinator_form.is_valid():
      coordinator = coordinator_form.save()
      if enable_cron_scheduling:
        coordinator.cron_frequency = {'frequency': request.POST.get('cron_frequency'), 'isAdvancedCron': request.POST.get('isAdvancedCron') == 'on'}
      coordinator.save()
      Document.objects.link(coordinator, owner=coordinator.owner, name=coordinator.name, description=coordinator.description)
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}) + "#step3")
    else:
      request.error(_('Errors on the form: %s') % coordinator_form.errors)
  else:
    coordinator_form = CoordinatorForm(instance=coordinator, user=request.user)

  return render('editor/create_coordinator.mako', request, {
    'coordinator': coordinator,
    'coordinator_form': coordinator_form,
    'coordinator_frequency': json.dumps(coordinator.cron_frequency),
    'enable_cron_scheduling': enable_cron_scheduling,
  })
示例#6
0
    def _import_coordinators(self, directory):

        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,
                                     'coordinator.zip')) as fp:
                    coordinator_xml, metadata = Coordinator.decompress(fp)

                coordinator_root = etree.fromstring(coordinator_xml)

                try:
                    Coordinator.objects.get(name=coordinator_root.get('name'))
                except Coordinator.DoesNotExist:
                    LOG.info(
                        _("Installing coordinator %s") %
                        coordinator_root.get('name'))
                    LOG.debug("Coordinator definition:\n%s" % coordinator_xml)
                    coordinator = Coordinator(owner=self.user, is_shared=True)
                    coordinator.name = coordinator_root.get('name')
                    coordinator.save()
                    import_coordinator_root(
                        coordinator=coordinator,
                        coordinator_definition_root=coordinator_root,
                        metadata=metadata)
示例#7
0
def import_coordinator(request):
  coordinator = Coordinator(owner=request.user, schema_version="uri:oozie:coordinator:0.2")

  if request.method == 'POST':
    coordinator_form = ImportCoordinatorForm(request.POST, request.FILES, instance=coordinator, user=request.user)

    if coordinator_form.is_valid():
      coordinator_definition = coordinator_form.cleaned_data['definition_file'].read()

      try:
        _import_coordinator(coordinator=coordinator, coordinator_definition=coordinator_definition)
        coordinator.managed = True
        coordinator.name = coordinator_form.cleaned_data.get('name')
        coordinator.save()
      except Exception, e:
        request.error(_('Could not import coordinator: %s' % e))
        raise PopupException(_('Could not import coordinator.'), detail=e)

      if coordinator_form.cleaned_data.get('resource_archive'):
        # Upload resources to workspace
        source = coordinator_form.cleaned_data.get('resource_archive')
        if source.name.endswith('.zip'):
          temp_path = archive_factory(source).extract()
          request.fs.copyFromLocal(temp_path, coordinator.deployment_dir)
          shutil.rmtree(temp_path)
        else:
          Coordinator.objects.filter(id=coordinator.id).delete()
          raise PopupException(_('Archive should be a Zip.'))

      Document.objects.link(coordinator, owner=request.user, name=coordinator.name, description=coordinator.description)
      request.info(_('Coordinator imported'))
      return redirect(reverse('oozie:edit_coordinator', kwargs={'coordinator': coordinator.id}))

    else:
      request.error(_('Errors on the form'))
示例#8
0
    def _is_coordinator(self):
        from oozie.models import Coordinator

        return Coordinator.get_application_path_key() in self.properties
示例#9
0
 def _is_coordinator(self):
     from oozie.models import Coordinator
     return Coordinator.get_application_path_key() in self.properties